Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Remove all .defaultProps usages #16542

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions docs/src/modules/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ NextComposed.propTypes = {
// https://nextjs.org/docs/#with-link
function Link(props) {
const {
activeClassName,
activeClassName = 'active',
className: classNameProps,
innerRef,
naked,
Expand Down Expand Up @@ -72,10 +72,6 @@ Link.propTypes = {
}).isRequired,
};

Link.defaultProps = {
activeClassName: 'active',
};

const RouterLink = withRouter(Link);

export default React.forwardRef((props, ref) => <RouterLink {...props} innerRef={ref} />);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const styles = theme => ({
});

function Paper(props) {
const { background, classes, className, padding, ...other } = props;
const { background = 'light', classes, className, padding = false, ...other } = props;
return (
<MuiPaper
elevation={0}
Expand All @@ -45,9 +45,4 @@ Paper.propTypes = {
padding: PropTypes.bool,
};

Paper.defaultProps = {
background: 'light',
padding: false,
};

export default withStyles(styles)(Paper);
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function TextField(props) {
...InputPropsOther
} = {},
InputLabelProps,
noBorder,
size,
noBorder = false,
size = 'medium',
SelectProps,
...other
} = props;
Expand Down Expand Up @@ -118,9 +118,4 @@ TextField.propTypes = {
size: PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']),
};

TextField.defaultProps = {
noBorder: false,
size: 'medium',
};

export default withStyles(styles)(TextField);
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const variantMapping = {
};

function Typography(props) {
const { children, classes, marked, variant, ...other } = props;
const { children, classes, marked = false, variant, ...other } = props;

return (
<MuiTypography variantMapping={variantMapping} variant={variant} {...other}>
Expand All @@ -65,8 +65,4 @@ Typography.propTypes = {
variant: PropTypes.string,
};

Typography.defaultProps = {
marked: false,
};

export default withStyles(styles)(Typography);
13 changes: 8 additions & 5 deletions examples/nextjs/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ NextComposed.propTypes = {
// A styled version of the Next.js Link component:
// https://nextjs.org/docs/#with-link
function Link(props) {
const { activeClassName, router, className: classNameProps, innerRef, naked, ...other } = props;
const {
activeClassName = 'active',
router,
className: classNameProps,
innerRef,
naked,
...other
} = props;

const className = clsx(classNameProps, {
[activeClassName]: router.pathname === props.href && activeClassName,
Expand All @@ -52,10 +59,6 @@ Link.propTypes = {
}).isRequired,
};

Link.defaultProps = {
activeClassName: 'active',
};

const RouterLink = withRouter(Link);

export default React.forwardRef((props, ref) => <RouterLink {...props} innerRef={ref} />);
4 changes: 0 additions & 4 deletions packages/material-ui-docs/src/NProgressBar/NProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,4 @@ if (process.env.NODE_ENV !== 'production') {
NProgressBar.propTypes = exactProp(NProgressBar.propTypes);
}

NProgressBar.defaultProps = {
children: null,
};

export default NProgressBar;
15 changes: 5 additions & 10 deletions packages/material-ui-lab/src/ToggleButton/ToggleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ const ToggleButton = React.forwardRef(function ToggleButton(props, ref) {
children,
classes,
className,
disabled,
disableFocusRipple,
disabled = false,
disableFocusRipple = false,
disableRipple = false,
onChange,
onClick,
selected,
size,
size = 'medium',
value,
...other
} = props;
Expand Down Expand Up @@ -126,6 +127,7 @@ const ToggleButton = React.forwardRef(function ToggleButton(props, ref) {
onClick={handleChange}
onChange={onChange}
value={value}
disableRipple={disableRipple}
{...other}
>
<span className={classes.label}>{children}</span>
Expand Down Expand Up @@ -183,11 +185,4 @@ ToggleButton.propTypes = {
value: PropTypes.any.isRequired,
};

ToggleButton.defaultProps = {
disabled: false,
disableFocusRipple: false,
disableRipple: false,
size: 'medium',
};

export default withStyles(styles, { name: 'MuiToggleButton' })(ToggleButton);
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ export const styles = theme => ({
});

const ToggleButtonGroup = React.forwardRef(function ToggleButton(props, ref) {
const { children, className, classes, exclusive, onChange, size, value, ...other } = props;
const {
children,
className,
classes,
exclusive = false,
onChange,
size = 'medium',
value,
...other
} = props;

const handleChange = (event, buttonValue) => {
if (!onChange) {
Expand Down Expand Up @@ -110,9 +119,4 @@ ToggleButtonGroup.propTypes = {
value: PropTypes.any,
};

ToggleButtonGroup.defaultProps = {
exclusive: false,
size: 'medium',
};

export default withStyles(styles, { name: 'MuiToggleButtonGroup' })(ToggleButtonGroup);
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ export const StylesContext = React.createContext(defaultOptions);
let injectFirstNode;

function StylesProvider(props) {
const { children, injectFirst, ...localOptions } = props;
const { children, injectFirst = false, disableGeneration = false, ...localOptions } = props;

const outerOptions = React.useContext(StylesContext);
const context = { ...outerOptions, ...localOptions };
const context = { ...outerOptions, disableGeneration, ...localOptions };

warning(
typeof window !== 'undefined' || context.sheetsManager,
Expand Down Expand Up @@ -124,9 +124,4 @@ if (process.env.NODE_ENV !== 'production') {
StylesProvider.propTypes = exactProp(StylesProvider.propTypes);
}

StylesProvider.defaultProps = {
disableGeneration: false,
injectFirst: false,
};

export default StylesProvider;
61 changes: 44 additions & 17 deletions packages/material-ui/src/Hidden/Hidden.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,54 @@ import HiddenCss from './HiddenCss';
* Responsively hides children based on the selected implementation.
*/
function Hidden(props) {
const { implementation, ...other } = props;
const {
implementation = 'js',
lgDown = false,
lgUp = false,
mdDown = false,
mdUp = false,
smDown = false,
smUp = false,
xlDown = false,
xlUp = false,
xsDown = false,
xsUp = false,
...other
} = props;

if (implementation === 'js') {
return <HiddenJs {...other} />;
return (
<HiddenJs
lgDown={lgDown}
lgUp={lgUp}
mdDown={mdDown}
mdUp={mdUp}
smDown={smDown}
smUp={smUp}
xlDown={xlDown}
xlUp={xlUp}
xsDown={xsDown}
xsUp={xsUp}
{...other}
/>
);
}

return <HiddenCss {...other} />;
return (
<HiddenCss
lgDown={lgDown}
lgUp={lgUp}
mdDown={mdDown}
mdUp={mdUp}
smDown={smDown}
smUp={smUp}
xlDown={xlDown}
xlUp={xlUp}
xsDown={xsDown}
xsUp={xsUp}
{...other}
/>
);
}

Hidden.propTypes = {
Expand Down Expand Up @@ -91,18 +132,4 @@ Hidden.propTypes = {
xsUp: PropTypes.bool,
};

Hidden.defaultProps = {
implementation: 'js',
lgDown: false,
lgUp: false,
mdDown: false,
mdUp: false,
smDown: false,
smUp: false,
xlDown: false,
xlUp: false,
xsDown: false,
xsUp: false,
};

export default Hidden;
18 changes: 5 additions & 13 deletions packages/material-ui/src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const styles = theme => {
const Snackbar = React.forwardRef(function Snackbar(props, ref) {
const {
action,
anchorOrigin: { vertical, horizontal },
anchorOrigin: { vertical, horizontal } = { vertical: 'bottom', horizontal: 'center' },
autoHideDuration,
children,
classes,
Expand All @@ -117,7 +117,10 @@ const Snackbar = React.forwardRef(function Snackbar(props, ref) {
open,
resumeHideDuration,
TransitionComponent = Grow,
transitionDuration,
transitionDuration = {
enter: duration.enteringScreen,
exit: duration.leavingScreen,
},
TransitionProps,
...other
} = props;
Expand Down Expand Up @@ -383,15 +386,4 @@ Snackbar.propTypes = {
TransitionProps: PropTypes.object,
};

Snackbar.defaultProps = {
anchorOrigin: {
vertical: 'bottom',
horizontal: 'center',
},
transitionDuration: {
enter: duration.enteringScreen,
exit: duration.leavingScreen,
},
};

export default withStyles(styles, { flip: false, name: 'MuiSnackbar' })(Snackbar);
2 changes: 1 addition & 1 deletion pages/api/snackbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Snackbar from '@material-ui/core/Snackbar';
| Name | Type | Default | Description |
|:-----|:-----|:--------|:------------|
| <span class="prop-name">action</span> | <span class="prop-type">node</span> | | The action to display. |
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: enum:&nbsp;'left'&nbsp;&#124;<br>&nbsp;'center'&nbsp;&#124;<br>&nbsp;'right'<br>, vertical: enum:&nbsp;'top'&nbsp;&#124;<br>&nbsp;'bottom'<br> }</span> | <span class="prop-default">{ vertical: 'bottom', horizontal: 'center',}</span> | The anchor of the `Snackbar`. |
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: enum:&nbsp;'left'&nbsp;&#124;<br>&nbsp;'center'&nbsp;&#124;<br>&nbsp;'right'<br>, vertical: enum:&nbsp;'top'&nbsp;&#124;<br>&nbsp;'bottom'<br> }</span> | <span class="prop-default">{ vertical: 'bottom', horizontal: 'center' }</span> | The anchor of the `Snackbar`. |
| <span class="prop-name">autoHideDuration</span> | <span class="prop-type">number</span> | | The number of milliseconds to wait before automatically calling the `onClose` function. `onClose` should then set the state of the `open` prop to hide the Snackbar. This behavior is disabled by default with the `null` value. |
| <span class="prop-name">children</span> | <span class="prop-type">element</span> | | Replace the `SnackbarContent` component. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
Expand Down