Skip to content

Commit

Permalink
[material-ui][Alert] Update TypeScript types to allow color override …
Browse files Browse the repository at this point in the history
…types to be added to `iconMapping` and `severity` props (#40551)

Co-authored-by: ZeeshanTamboli <zeeshan.tamboli@gmail.com>
  • Loading branch information
2metres and ZeeshanTamboli committed Jan 17, 2024
1 parent d3cf1c9 commit 664e9b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/pages/material-ui/api/alert.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"role": { "type": { "name": "string" }, "default": "'alert'" },
"severity": {
"type": {
"name": "enum",
"description": "'error'<br>&#124;&nbsp;'info'<br>&#124;&nbsp;'success'<br>&#124;&nbsp;'warning'"
"name": "union",
"description": "'error'<br>&#124;&nbsp;'info'<br>&#124;&nbsp;'success'<br>&#124;&nbsp;'warning'<br>&#124;&nbsp;string"
},
"default": "'success'"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/mui-material/src/Alert/Alert.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
* The severity of the alert. This defines the color and icon used.
* @default 'success'
*/
severity?: AlertColor;
severity?: OverridableStringUnion<AlertColor, AlertPropsColorOverrides>;
/**
* Override the icon displayed before the children.
* Unless provided, the icon is mapped to the value of the `severity` prop.
Expand All @@ -80,7 +80,9 @@ export interface AlertProps extends StandardProps<PaperProps, 'variant'> {
* If you wish to change this mapping, you can provide your own.
* Alternatively, you can use the `icon` prop to override the icon displayed.
*/
iconMapping?: Partial<Record<AlertColor, React.ReactNode>>;
iconMapping?: Partial<
Record<OverridableStringUnion<AlertColor, AlertPropsColorOverrides>, React.ReactNode>
>;
/**
* Callback fired when the component requests to be closed.
* When provided and no `action` prop is set, a close icon button is displayed that triggers the callback when clicked.
Expand Down
5 changes: 4 additions & 1 deletion packages/mui-material/src/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ Alert.propTypes /* remove-proptypes */ = {
* The severity of the alert. This defines the color and icon used.
* @default 'success'
*/
severity: PropTypes.oneOf(['error', 'info', 'success', 'warning']),
severity: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['error', 'info', 'success', 'warning']),
PropTypes.string,
]),
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
Expand Down

0 comments on commit 664e9b7

Please sign in to comment.