-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui][Alert] Add ability to override slot props (#42787)
Co-authored-by: ZeeshanTamboli <[email protected]>
- Loading branch information
1 parent
d238f98
commit 5a2327f
Showing
3 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/mui-material/test/typescript/moduleAugmentation/alertCustomSlotProps.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react'; | ||
import Alert from '@mui/material/Alert'; | ||
import { IconButton, IconButtonProps, svgIconClasses } from '@mui/material'; | ||
|
||
declare module '@mui/material/Alert' { | ||
interface AlertCloseButtonSlotPropsOverrides { | ||
iconSize: 'small' | 'medium'; | ||
} | ||
} | ||
|
||
type MyIconButtonProps = IconButtonProps< | ||
'button', | ||
{ | ||
iconSize?: 'small' | 'medium'; | ||
} | ||
>; | ||
|
||
const MyIconButton = ({ iconSize, ...rest }: MyIconButtonProps) => { | ||
return ( | ||
<IconButton | ||
{...rest} | ||
sx={{ | ||
// whatever customization based on iconSize | ||
[`.${svgIconClasses.root}`]: { | ||
fontSize: iconSize === 'small' ? '1rem' : '1.5rem', | ||
}, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
<Alert | ||
severity="success" | ||
slots={{ | ||
closeButton: MyIconButton, | ||
}} | ||
slotProps={{ | ||
closeButton: { | ||
iconSize: 'medium', | ||
}, | ||
}} | ||
> | ||
Here is a gentle confirmation that your action was successful. | ||
</Alert>; |
4 changes: 4 additions & 0 deletions
4
packages/mui-material/test/typescript/moduleAugmentation/alertCustomSlotProps.tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../../../../tsconfig.json", | ||
"files": ["alertCustomSlotProps.spec.tsx"] | ||
} |