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

[material-ui][Alert] Deprecate components and componentsProps props #40681

Merged
merged 16 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
13 changes: 10 additions & 3 deletions docs/pages/material-ui/api/alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
"name": "shape",
"description": "{ CloseButton?: elementType, CloseIcon?: elementType }"
},
"default": "{}"
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slots</code> prop instead. This prop will be removed in v7."
},
"componentsProps": {
"type": { "name": "shape", "description": "{ closeButton?: object, closeIcon?: object }" },
"default": "{}"
"default": "{}",
"deprecated": true,
"deprecationInfo": "use the <code>slotProps</code> prop instead. This prop will be removed in v7."
},
"icon": { "type": { "name": "node" } },
"iconMapping": {
Expand All @@ -44,7 +48,10 @@
"default": "'success'"
},
"slotProps": {
"type": { "name": "shape", "description": "{ closeButton?: object, closeIcon?: object }" },
"type": {
"name": "shape",
"description": "{ closeButton?: func<br>&#124;&nbsp;object, closeIcon?: func<br>&#124;&nbsp;object }"
},
"default": "{}"
},
"slots": {
Expand Down
12 changes: 4 additions & 8 deletions docs/translations/api-docs/alert/alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
"color": {
"description": "The color of the component. Unless provided, the value is taken from the <code>severity</code> prop. It supports both default and custom theme colors, which can be added as shown in the <a href=\"https://mui.com/material-ui/customization/palette/#custom-colors\">palette customization guide</a>."
},
"components": {
"description": "The components used for each slot inside.<br>This prop is an alias for the <code>slots</code> prop. It&#39;s recommended to use the <code>slots</code> prop instead."
},
"components": { "description": "The components used for each slot inside." },
"componentsProps": {
"description": "The extra props for the slot components. You can override the existing props or add new ones.<br>This prop is an alias for the <code>slotProps</code> prop. It&#39;s recommended to use the <code>slotProps</code> prop instead, as <code>componentsProps</code> will be deprecated in the future."
"description": "The extra props for the slot components. You can override the existing props or add new ones."
},
"icon": {
"description": "Override the icon displayed before the children. Unless provided, the icon is mapped to the value of the <code>severity</code> prop. Set to <code>false</code> to remove the <code>icon</code>."
Expand All @@ -33,11 +31,9 @@
"description": "The severity of the alert. This defines the color and icon used."
},
"slotProps": {
"description": "The extra props for the slot components. You can override the existing props or add new ones.<br>This prop is an alias for the <code>componentsProps</code> prop, which will be deprecated in the future."
},
"slots": {
"description": "The components used for each slot inside.<br>This prop is an alias for the <code>components</code> prop, which will be deprecated in the future."
"description": "The extra props for the slot components. You can override the existing props or add new ones."
},
"slots": { "description": "The components used for each slot inside." },
"sx": {
"description": "The system prop that allows defining system overrides as well as additional CSS styles."
},
Expand Down
29 changes: 19 additions & 10 deletions packages/mui-material/src/Alert/Alert.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import { SxProps } from '@mui/system';
import { IconButtonProps, InternalStandardProps as StandardProps, SvgIconProps, Theme } from '..';
import { PaperProps } from '../Paper';
import { AlertClasses } from './alertClasses';
import { SlotProps } from '../utils/types';

export type AlertColor = 'success' | 'info' | 'warning' | 'error';

export interface AlertPropsVariantOverrides {}

export interface AlertPropsColorOverrides {}

export interface AlertCloseButtonSlotPropsOverrides {}

export interface AlertCloseIconSlotPropsOverrides {}
DiegoAndai marked this conversation as resolved.
Show resolved Hide resolved

export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
/**
* The action to display. It renders after the message, at the end of the alert.
Expand All @@ -36,8 +41,7 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
/**
* The components used for each slot inside.
*
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
* @deprecated use the `slots` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand All @@ -49,8 +53,7 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand Down Expand Up @@ -98,19 +101,23 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `componentsProps` prop, which will be deprecated in the future.
*
* @default {}
*/
slotProps?: {
closeButton?: IconButtonProps;
closeIcon?: SvgIconProps;
closeButton?: SlotProps<
React.ElementType<IconButtonProps>,
AlertCloseButtonSlotPropsOverrides,
AlertOwnerState
>;
closeIcon?: SlotProps<
React.ElementType<SvgIconProps>,
AlertCloseIconSlotPropsOverrides,
AlertOwnerState
>;
};
/**
* The components used for each slot inside.
*
* This prop is an alias for the `components` prop, which will be deprecated in the future.
*
* @default {}
*/
slots?: {
Expand All @@ -123,6 +130,8 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
sx?: SxProps<Theme>;
}

export interface AlertOwnerState extends AlertProps {}

/**
*
* Demos:
Expand Down
47 changes: 30 additions & 17 deletions packages/mui-material/src/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { unstable_composeClasses as composeClasses } from '@mui/base/composeClas
import { darken, lighten } from '@mui/system';
import styled from '../styles/styled';
import useThemeProps from '../styles/useThemeProps';
import useSlot from '../utils/useSlot';
import capitalize from '../utils/capitalize';
import Paper from '../Paper';
import alertClasses, { getAlertUtilityClass } from './alertClasses';
Expand Down Expand Up @@ -167,11 +168,29 @@ const Alert = React.forwardRef(function Alert(inProps, ref) {

const classes = useUtilityClasses(ownerState);

const AlertCloseButton = slots.closeButton ?? components.CloseButton ?? IconButton;
const AlertCloseIcon = slots.closeIcon ?? components.CloseIcon ?? CloseIcon;
const externalForwardedProps = {
slots: {
closeButton: components.CloseButton,
closeIcon: components.CloseIcon,
...slots,
},
slotProps: {
...componentsProps,
...slotProps,
},
};

const [CloseButtonSlot, closeButtonProps] = useSlot('closeButton', {
elementType: IconButton,
externalForwardedProps,
ownerState,
});

const closeButtonProps = slotProps.closeButton ?? componentsProps.closeButton;
const closeIconProps = slotProps.closeIcon ?? componentsProps.closeIcon;
const [CloseIconSlot, closeIconProps] = useSlot('closeIcon', {
elementType: CloseIcon,
externalForwardedProps,
ownerState,
});

return (
<AlertRoot
Expand All @@ -197,16 +216,16 @@ const Alert = React.forwardRef(function Alert(inProps, ref) {
) : null}
{action == null && onClose ? (
<AlertAction ownerState={ownerState} className={classes.action}>
<AlertCloseButton
<CloseButtonSlot
size="small"
aria-label={closeText}
title={closeText}
color="inherit"
onClick={onClose}
{...closeButtonProps}
>
<AlertCloseIcon fontSize="small" {...closeIconProps} />
</AlertCloseButton>
<CloseIconSlot fontSize="small" {...closeIconProps} />
</CloseButtonSlot>
</AlertAction>
) : null}
</AlertRoot>
Expand Down Expand Up @@ -253,8 +272,7 @@ Alert.propTypes /* remove-proptypes */ = {
/**
* The components used for each slot inside.
*
* This prop is an alias for the `slots` prop.
* It's recommended to use the `slots` prop instead.
* @deprecated use the `slots` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand All @@ -266,8 +284,7 @@ Alert.propTypes /* remove-proptypes */ = {
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `slotProps` prop.
* It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
* @deprecated use the `slotProps` prop instead. This prop will be removed in v7.
*
* @default {}
*/
Expand Down Expand Up @@ -316,19 +333,15 @@ Alert.propTypes /* remove-proptypes */ = {
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* This prop is an alias for the `componentsProps` prop, which will be deprecated in the future.
*
* @default {}
*/
slotProps: PropTypes.shape({
closeButton: PropTypes.object,
closeIcon: PropTypes.object,
closeButton: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
closeIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
}),
/**
* The components used for each slot inside.
*
* This prop is an alias for the `components` prop, which will be deprecated in the future.
*
* @default {}
*/
slots: PropTypes.shape({
Expand Down
13 changes: 7 additions & 6 deletions packages/mui-material/src/Alert/Alert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ describe('<Alert />', () => {
testDeepOverrides: { slotName: 'message', slotClassName: classes.message },
testLegacyComponentsProp: true,
slots: {
closeButton: {},
closeIcon: {},
closeButton: {
expectedClassName: classes.closeButton,
},
closeIcon: {
expectedClassName: classes.closeIcon,
},
},
skip: [
'componentsProp',
'slotPropsCallback', // not supported yet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

],
skip: ['componentsProp'],
}));

describe('prop: square', () => {
Expand Down