Skip to content

Commit

Permalink
Allow overriding styles of Material Snackbar (#545)
Browse files Browse the repository at this point in the history
* Pass className down to snackbar content

* Add MuiContent-variant classname

* Export MaterialDesignContent component

* Update typedocs

* Minor
  • Loading branch information
iamhosseindhv authored Mar 5, 2023
1 parent 4014a05 commit e9772a2
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 4 deletions.
3 changes: 1 addition & 2 deletions examples/custom-snackbar-example-2/src/ReportComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const useStyles = makeStyles(() => ({
}
},
card: {
backgroundColor: "#fddc6c",
width: "100%"
},
typography: {
Expand Down Expand Up @@ -76,7 +75,7 @@ const ReportComplete = forwardRef<HTMLDivElement, ReportCompleteProps>(

return (
<SnackbarContent ref={ref} className={classes.root}>
<Card className={classes.card}>
<Card className={classes.card} style={{ backgroundColor: "#fddc6c" }}>
<CardActions classes={{ root: classes.actionRoot }}>
<Typography variant="body2" className={classes.typography}>
{props.message}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as SnackbarProvider, enqueueSnackbar, closeSnackbar } from './S
export { default as SnackbarContent } from './SnackbarContent';
export { default as useSnackbar } from './useSnackbar';
export { default as Transition } from './transitions/Transition';
export { default as MaterialDesignContent } from './ui/MaterialDesignContent';
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,7 @@ export declare const SnackbarContent: (
) => React.ReactElement<any, any>;

export declare const Transition: React.JSXElementConstructor<TransitionComponentProps>;

export declare const MaterialDesignContent: (
props: CustomContentProps & React.RefAttributes<HTMLDivElement>
) => React.ReactElement<any, any>;
15 changes: 13 additions & 2 deletions src/ui/MaterialDesignContent/MaterialDesignContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ const classes = makeStyles({
});

const MaterialDesignContent = forwardRef<HTMLDivElement, CustomContentProps>((props, forwardedRef) => {
const { id, message, action: componentOrFunctionAction, iconVariant, variant, hideIconVariant, style } = props;
const {
id,
message,
action: componentOrFunctionAction,
iconVariant,
variant,
hideIconVariant,
style,
className,
} = props;

const icon = iconVariant[variant];

Expand All @@ -66,9 +75,11 @@ const MaterialDesignContent = forwardRef<HTMLDivElement, CustomContentProps>((pr
style={style}
className={clsx(
ComponentClasses.MuiContent,
ComponentClasses.MuiContentVariant(variant),
classes.root,
{ [classes.lessPadding]: !hideIconVariant && icon },
classes[variant]
classes[variant],
className
)}
>
<div id="notistack-snackbar" className={classes.message}>
Expand Down
1 change: 1 addition & 0 deletions src/utils/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export const ComponentClasses = {
Snackbar: 'notistack-Snackbar',
CollapseWrapper: 'notistack-CollapseWrapper',
MuiContent: 'notistack-MuiContent',
MuiContentVariant: (variant: string) => `notistack-MuiContent-${variant}`,
};
93 changes: 93 additions & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8168,6 +8168,98 @@
}
}
},
{
"id": 333,
"name": "MaterialDesignContent",
"kind": 32,
"kindString": "Variable",
"flags": {
"isExported": true,
"isConst": true
},
"sources": [
{
"fileName": "src/types.ts",
"line": 428,
"character": 42
}
],
"type": {
"type": "reflection",
"declaration": {
"id": 334,
"name": "__type",
"kind": 65536,
"kindString": "Type literal",
"flags": {
"isExported": true
},
"signatures": [
{
"id": 335,
"name": "__call",
"kind": 4096,
"kindString": "Call signature",
"flags": {
"isExported": true
},
"parameters": [
{
"id": 336,
"name": "props",
"kind": 32768,
"kindString": "Parameter",
"flags": {
"isExported": true
},
"type": {
"type": "intersection",
"types": [
{
"type": "reference",
"id": 321,
"name": "CustomContentProps"
},
{
"type": "reference",
"typeArguments": [
{
"type": "reference",
"name": "HTMLDivElement"
}
],
"name": "RefAttributes"
}
]
}
}
],
"type": {
"type": "reference",
"typeArguments": [
{
"type": "intrinsic",
"name": "any"
},
{
"type": "intrinsic",
"name": "any"
}
],
"name": "ReactElement"
}
}
],
"sources": [
{
"fileName": "src/types.ts",
"line": 428,
"character": 43
}
]
}
}
},
{
"id": 328,
"name": "SnackbarContent",
Expand Down Expand Up @@ -8473,6 +8565,7 @@
"title": "Variables",
"kind": 32,
"children": [
333,
328,
332,
327,
Expand Down

0 comments on commit e9772a2

Please sign in to comment.