Skip to content

Commit

Permalink
[core] Add createMuiStrictModeTheme (#20523)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Apr 17, 2020
1 parent e7ffe6b commit 241c802
Show file tree
Hide file tree
Showing 30 changed files with 234 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppDrawerNavItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from 'clsx';
import { makeStyles } from '@material-ui/core/styles';
import ListItem from '@material-ui/core/ListItem';
import Button from '@material-ui/core/Button';
import Collapse from '@material-ui/core/Collapse';
import { unstable_StrictModeCollapse as Collapse } from '@material-ui/core/Collapse';
import Link from 'docs/src/modules/components/Link';

const useStyles = makeStyles((theme) => ({
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSelector, useDispatch } from 'react-redux';
import { withStyles, fade } from '@material-ui/core/styles';
import IconButton from '@material-ui/core/IconButton';
import useMediaQuery from '@material-ui/core/useMediaQuery';
import Collapse from '@material-ui/core/Collapse';
import { unstable_StrictModeCollapse as Collapse } from '@material-ui/core/Collapse';
import NoSsr from '@material-ui/core/NoSsr';
import EditIcon from '@material-ui/icons/Edit';
import CodeIcon from '@material-ui/icons/Code';
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/DemoLanguages.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Fade from '@material-ui/core/Fade';
import { unstable_StrictModeFade as Fade } from '@material-ui/core/Fade';
import ToggleButton from '@material-ui/lab/ToggleButton';
import ToggleButtonGroup from '@material-ui/lab/ToggleButtonGroup';
import { JavaScript as JavaScriptIcon, TypeScript as TypeScriptIcon } from '@material-ui/docs';
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Tooltip from '@material-ui/core/Tooltip';
import IconButton from '@material-ui/core/IconButton';
import Badge from '@material-ui/core/Badge';
import Popper from '@material-ui/core/Popper';
import Grow from '@material-ui/core/Grow';
import { unstable_StrictModeGrow as Grow } from '@material-ui/core/Grow';
import Paper from '@material-ui/core/Paper';
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import List from '@material-ui/core/List';
Expand Down
10 changes: 9 additions & 1 deletion docs/src/modules/components/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React from 'react';
import PropTypes from 'prop-types';
import {
ThemeProvider as MuiThemeProvider,
createMuiTheme,
createMuiTheme as createLegacyModeTheme,
unstable_createMuiStrictModeTheme as createStrictModeTheme,
darken,
} from '@material-ui/core/styles';
import { useSelector } from 'react-redux';
Expand Down Expand Up @@ -97,6 +98,13 @@ if (process.env.NODE_ENV !== 'production') {

const useEnhancedEffect = typeof window === 'undefined' ? React.useEffect : React.useLayoutEffect;

let createMuiTheme;
if (process.env.REACT_MODE === 'legacy') {
createMuiTheme = createLegacyModeTheme;
} else {
createMuiTheme = createStrictModeTheme;
}

export function ThemeProvider(props) {
const { children } = props;

Expand Down
1 change: 1 addition & 0 deletions packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
},
"dependencies": {
"@babel/runtime": "^7.4.4",
"@material-ui/react-transition-group": "^4.2.0",
"@material-ui/styles": "^4.9.10",
"@material-ui/system": "^4.9.10",
"@material-ui/types": "^5.0.1",
Expand Down
6 changes: 4 additions & 2 deletions packages/material-ui/src/Backdrop/Backdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ const Backdrop = React.forwardRef(function Backdrop(props, ref) {
invisible = false,
open,
transitionDuration,
// eslint-disable-next-line react/prop-types
TransitionComponent = Fade,
...other
} = props;

return (
<Fade in={open} timeout={transitionDuration} {...other}>
<TransitionComponent in={open} timeout={transitionDuration} {...other}>
<div
data-mui-test="Backdrop"
className={clsx(
Expand All @@ -53,7 +55,7 @@ const Backdrop = React.forwardRef(function Backdrop(props, ref) {
>
{children}
</div>
</Fade>
</TransitionComponent>
);
});

Expand Down
6 changes: 4 additions & 2 deletions packages/material-ui/src/Collapse/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
onExiting,
style,
timeout = duration.standard,
// eslint-disable-next-line react/prop-types
TransitionComponent = Transition,
...other
} = props;
const theme = useTheme();
Expand Down Expand Up @@ -153,7 +155,7 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
};

return (
<Transition
<TransitionComponent
in={inProp}
onEnter={handleEnter}
onEntered={handleEntered}
Expand Down Expand Up @@ -186,7 +188,7 @@ const Collapse = React.forwardRef(function Collapse(props, ref) {
</div>
</Component>
)}
</Transition>
</TransitionComponent>
);
});

Expand Down
23 changes: 23 additions & 0 deletions packages/material-ui/src/Collapse/StrictModeCollapse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { Transition } from '@material-ui/react-transition-group';
import { useForkRef } from '../utils';
import Collapse from './Collapse';

/**
* @ignore - internal component.
*/
const StrictModeCollapse = React.forwardRef(function StrictModeCollapse(props, forwardedRef) {
const domRef = React.useRef(null);
const ref = useForkRef(domRef, forwardedRef);

return (
<Collapse
{...props}
findDOMNode={() => domRef.current}
ref={ref}
TransitionComponent={Transition}
/>
);
});

export default StrictModeCollapse;
2 changes: 1 addition & 1 deletion packages/material-ui/src/Collapse/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Collapse';
export { default, default as unstable_StrictModeCollapse } from './Collapse';
export * from './Collapse';
2 changes: 2 additions & 0 deletions packages/material-ui/src/Collapse/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default } from './Collapse';
// eslint-disable-next-line camelcase
export { default as unstable_StrictModeCollapse } from './StrictModeCollapse';
6 changes: 4 additions & 2 deletions packages/material-ui/src/Drawer/Drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ const Drawer = React.forwardRef(function Drawer(props, ref) {
open = false,
PaperProps = {},
SlideProps,
// eslint-disable-next-line react/prop-types
TransitionComponent = Slide,
transitionDuration = defaultTransitionDuration,
variant = 'temporary',
...other
Expand Down Expand Up @@ -157,15 +159,15 @@ const Drawer = React.forwardRef(function Drawer(props, ref) {
}

const slidingDrawer = (
<Slide
<TransitionComponent
in={open}
direction={oppositeDirection[anchor]}
timeout={transitionDuration}
appear={mounted.current}
{...SlideProps}
>
{drawer}
</Slide>
</TransitionComponent>
);

if (variant === 'persistent') {
Expand Down
6 changes: 4 additions & 2 deletions packages/material-ui/src/Fade/Fade.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const Fade = React.forwardRef(function Fade(props, ref) {
onEnter,
onExit,
style,
// eslint-disable-next-line react/prop-types
TransitionComponent = Transition,
timeout = defaultTimeout,
...other
} = props;
Expand Down Expand Up @@ -72,7 +74,7 @@ const Fade = React.forwardRef(function Fade(props, ref) {
};

return (
<Transition
<TransitionComponent
appear
in={inProp}
onEnter={handleEnter}
Expand All @@ -93,7 +95,7 @@ const Fade = React.forwardRef(function Fade(props, ref) {
...childProps,
});
}}
</Transition>
</TransitionComponent>
);
});

Expand Down
23 changes: 23 additions & 0 deletions packages/material-ui/src/Fade/StrictModeFade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { Transition } from '@material-ui/react-transition-group';
import { useForkRef } from '../utils';
import Fade from './Fade';

/**
* @ignore - internal component.
*/
const StrictModeFade = React.forwardRef(function StrictModeFade(props, forwardedRef) {
const domRef = React.useRef(null);
const ref = useForkRef(domRef, forwardedRef);

return (
<Fade
{...props}
findDOMNode={() => domRef.current}
ref={ref}
TransitionComponent={Transition}
/>
);
});

export default StrictModeFade;
2 changes: 1 addition & 1 deletion packages/material-ui/src/Fade/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Fade';
export { default, default as unstable_StrictModeFade } from './Fade';
export * from './Fade';
2 changes: 2 additions & 0 deletions packages/material-ui/src/Fade/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default } from './Fade';
// eslint-disable-next-line camelcase
export { default as unstable_StrictModeFade } from './StrictModeFade';
16 changes: 13 additions & 3 deletions packages/material-ui/src/Grow/Grow.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ const styles = {
* It uses [react-transition-group](https://github.com/reactjs/react-transition-group) internally.
*/
const Grow = React.forwardRef(function Grow(props, ref) {
const { children, in: inProp, onEnter, onExit, style, timeout = 'auto', ...other } = props;
const {
children,
in: inProp,
onEnter,
onExit,
style,
timeout = 'auto',
// eslint-disable-next-line react/prop-types
TransitionComponent = Transition,
...other
} = props;
const timer = React.useRef();
const autoTimeout = React.useRef();
const handleRef = useForkRef(children.ref, ref);
Expand Down Expand Up @@ -114,7 +124,7 @@ const Grow = React.forwardRef(function Grow(props, ref) {
}, []);

return (
<Transition
<TransitionComponent
appear
in={inProp}
onEnter={handleEnter}
Expand All @@ -137,7 +147,7 @@ const Grow = React.forwardRef(function Grow(props, ref) {
...childProps,
});
}}
</Transition>
</TransitionComponent>
);
});

Expand Down
23 changes: 23 additions & 0 deletions packages/material-ui/src/Grow/StrictModeGrow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { Transition } from '@material-ui/react-transition-group';
import { useForkRef } from '../utils';
import Grow from './Grow';

/**
* @ignore - internal component.
*/
const StrictModeGrow = React.forwardRef(function StrictModeGrow(props, forwardedRef) {
const domRef = React.useRef(null);
const ref = useForkRef(domRef, forwardedRef);

return (
<Grow
{...props}
findDOMNode={() => domRef.current}
ref={ref}
TransitionComponent={Transition}
/>
);
});

export default StrictModeGrow;
2 changes: 1 addition & 1 deletion packages/material-ui/src/Grow/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Grow';
export { default, default as unstable_StrictModeGrow } from './Grow';
export * from './Grow';
2 changes: 2 additions & 0 deletions packages/material-ui/src/Grow/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default } from './Grow';
// eslint-disable-next-line camelcase
export { default as unstable_StrictModeGrow } from './StrictModeGrow';
6 changes: 4 additions & 2 deletions packages/material-ui/src/Slide/Slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const Slide = React.forwardRef(function Slide(props, ref) {
onExited,
style,
timeout = defaultTimeout,
// eslint-disable-next-line react/prop-types
TransitionComponent = Transition,
...other
} = props;

Expand Down Expand Up @@ -202,7 +204,7 @@ const Slide = React.forwardRef(function Slide(props, ref) {
}, [inProp, updatePosition]);

return (
<Transition
<TransitionComponent
onEnter={handleEnter}
onEntering={handleEntering}
onExit={handleExit}
Expand All @@ -223,7 +225,7 @@ const Slide = React.forwardRef(function Slide(props, ref) {
...childProps,
});
}}
</Transition>
</TransitionComponent>
);
});

Expand Down
23 changes: 23 additions & 0 deletions packages/material-ui/src/Slide/StrictModeSlide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { Transition } from '@material-ui/react-transition-group';
import { useForkRef } from '../utils';
import Slide from './Slide';

/**
* @ignore - internal component.
*/
const StrictModeSlide = React.forwardRef(function StrictModeSlide(props, forwardedRef) {
const domRef = React.useRef(null);
const ref = useForkRef(domRef, forwardedRef);

return (
<Slide
{...props}
findDOMNode={() => domRef.current}
ref={ref}
TransitionComponent={Transition}
/>
);
});

export default StrictModeSlide;
2 changes: 1 addition & 1 deletion packages/material-ui/src/Slide/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Slide';
export { default, default as unstable_StrictModeSlide } from './Slide';
export * from './Slide';
2 changes: 2 additions & 0 deletions packages/material-ui/src/Slide/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { default } from './Slide';
// eslint-disable-next-line camelcase
export { default as unstable_StrictModeSlide } from './StrictModeSlide';
23 changes: 23 additions & 0 deletions packages/material-ui/src/Zoom/StrictModeZoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import { Transition } from '@material-ui/react-transition-group';
import { useForkRef } from '../utils';
import Zoom from './Zoom';

/**
* @ignore - internal component.
*/
const StrictModeZoom = React.forwardRef(function StrictModeZoom(props, forwardedRef) {
const domRef = React.useRef(null);
const ref = useForkRef(domRef, forwardedRef);

return (
<Zoom
{...props}
findDOMNode={() => domRef.current}
ref={ref}
TransitionComponent={Transition}
/>
);
});

export default StrictModeZoom;
Loading

0 comments on commit 241c802

Please sign in to comment.