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

[Snackbar] Display stacked Snackbars #31991

Open
wants to merge 144 commits into
base: v5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
6c80b50
docs: update snackbar doc
ZeeshanTamboli Feb 24, 2022
d28bb6a
feat: SnackbarProvider, SnackbarContext
ZeeshanTamboli Mar 23, 2022
f753ed0
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Mar 23, 2022
8e55d6c
feat: showSnackbar method
ZeeshanTamboli Mar 24, 2022
d332156
feat: useSnackbars and rename files and component
ZeeshanTamboli Mar 24, 2022
a600d59
feat: add exports
ZeeshanTamboli Mar 24, 2022
d28a42b
fix: types
ZeeshanTamboli Mar 24, 2022
0ede87c
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Mar 24, 2022
b582bae
fix: change showSnackbar return type
ZeeshanTamboli Mar 24, 2022
fae6898
feat: add random id for snackbar key
ZeeshanTamboli Mar 24, 2022
5bdbcdc
feat: ShowSnackbarProps
ZeeshanTamboli Mar 24, 2022
6a13d39
add TransitionGroup
ZeeshanTamboli Mar 26, 2022
8aa57cc
feat: SnackbarContainer
ZeeshanTamboli Mar 26, 2022
7ca818c
fix: snackbarStyles type
ZeeshanTamboli Mar 26, 2022
a82421f
fix: rename SnackbarContainer to SnackbarsContainer
ZeeshanTamboli Mar 26, 2022
bd7c8c4
fix: snackbar style for theme.breakpoint.up
ZeeshanTamboli Mar 30, 2022
63501e2
feat: move snackbarStyles to its own file to avoid declaring in decla…
ZeeshanTamboli Mar 30, 2022
0086925
fix: snackbars anchorOrigin position
ZeeshanTamboli Mar 30, 2022
b272f09
feat: give individual snackbars anchorOrigin props more priority over…
ZeeshanTamboli Mar 31, 2022
23935c5
docs: add multiple snackbars demo
ZeeshanTamboli Mar 31, 2022
bd0db9a
yarn docs:typescript:formatted
ZeeshanTamboli Mar 31, 2022
3c687a1
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Mar 31, 2022
e60ceac
fix: remove TransitionComponent from ownerState
ZeeshanTamboli Mar 31, 2022
688e36b
feat: transitionDuration in SnackbarsProvider
ZeeshanTamboli Mar 31, 2022
d9bf887
feat: TransitionProps in SnackbarsProvider
ZeeshanTamboli Mar 31, 2022
afdd1b2
fix: sort props alphabetically
ZeeshanTamboli Mar 31, 2022
1785984
feat: add ClickAwayListenerProps and ContentProps in SnackbarsProvider
ZeeshanTamboli Mar 31, 2022
cf547c0
feat: autoHideDuration prop functionality
ZeeshanTamboli Apr 1, 2022
8eeae1b
fix: do not mutate array
ZeeshanTamboli Apr 2, 2022
f3536a9
feat: remove snackbar from state on exit
ZeeshanTamboli Apr 2, 2022
1dc1390
add default null for autoHideDuration prop
ZeeshanTamboli Apr 4, 2022
dc2331d
docs: update Multiple Snackbars demo
ZeeshanTamboli Apr 4, 2022
670f716
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 4, 2022
9a24fcc
yarn proptypes
ZeeshanTamboli Apr 4, 2022
e360e09
feat(SnackbarsProvier): add content prop
ZeeshanTamboli Apr 5, 2022
1086a60
feat: SnackbarContentType
ZeeshanTamboli Apr 5, 2022
d57e540
feat: add action prop
ZeeshanTamboli Apr 5, 2022
122dff7
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 5, 2022
3b7e90e
fix: dupicate styles
ZeeshanTamboli Apr 5, 2022
bc19dd1
feat: move to lab
ZeeshanTamboli Apr 5, 2022
b92931f
feat: move docs to lab
ZeeshanTamboli Apr 5, 2022
7124db1
fix: remove multiple snacbars preview
ZeeshanTamboli Apr 5, 2022
77e0481
yarn proptypes
ZeeshanTamboli Apr 5, 2022
02734e5
yarn docs:typescript:formatted
ZeeshanTamboli Apr 5, 2022
b4808f8
yarn proptypes
ZeeshanTamboli Apr 5, 2022
d0fd454
docs: multiple snackbars
ZeeshanTamboli Apr 5, 2022
e7170e9
yarn prettier
ZeeshanTamboli Apr 5, 2022
fa61982
yarn docs:api
ZeeshanTamboli Apr 5, 2022
d0da930
yarn docs:i18n
ZeeshanTamboli Apr 5, 2022
9c8b5fa
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 6, 2022
d28fae1
fix: action prop and handleClose
ZeeshanTamboli Apr 6, 2022
3458f8c
fix: do not pass content prop to snackbar component
ZeeshanTamboli Apr 6, 2022
a895a49
docs: improve multiple snackbars docs
ZeeshanTamboli Apr 6, 2022
c7ebc1d
yarn docs:typescript:formatted
ZeeshanTamboli Apr 6, 2022
2b58f86
docs: add back Frequency section with link to multiple snackbars
ZeeshanTamboli Apr 6, 2022
eaba9b3
fix: add typescript-to-proptypes-ignore comment
ZeeshanTamboli Apr 7, 2022
9546696
fix: change action proptype to node or func
ZeeshanTamboli Apr 7, 2022
3195cb6
yarn docs:api
ZeeshanTamboli Apr 7, 2022
7ef15fb
yarn prettier
ZeeshanTamboli Apr 7, 2022
26e9eec
fix: snackbar center positioning
ZeeshanTamboli Apr 7, 2022
c425974
docs: new line for each sentence
ZeeshanTamboli Apr 8, 2022
1ebce80
fix: use theme.spacing()
ZeeshanTamboli Apr 8, 2022
a139c46
docs: update doc
ZeeshanTamboli Apr 8, 2022
78b86af
docs: add react-multiple-snackbars page
ZeeshanTamboli Apr 8, 2022
3ce90e3
merge master branch and resolve conflicts
ZeeshanTamboli Apr 8, 2022
d70b550
yarn docs:api
ZeeshanTamboli Apr 8, 2022
231e037
docs: fix links
ZeeshanTamboli Apr 8, 2022
c9cce00
docs: update docs
ZeeshanTamboli Apr 8, 2022
5f611e5
docs: fix links
ZeeshanTamboli Apr 8, 2022
0506454
yarn docs:i18n
ZeeshanTamboli Apr 8, 2022
7fd0c71
yarn proptypes && yarn docs:api
ZeeshanTamboli Apr 8, 2022
e8cda2f
reverted 5f611e5ac9f9366684a6a66b21df0db5d243802b
ZeeshanTamboli Apr 8, 2022
cab67c6
yarn docs:api
ZeeshanTamboli Apr 8, 2022
f549fff
docs: fix autogeneration of link to multiple snackbars by ignoring to…
ZeeshanTamboli Apr 9, 2022
5a73828
feat: add closeSnackbar in ref for accessing in SnackbarsProvider
ZeeshanTamboli Apr 11, 2022
168e13e
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 11, 2022
4278b7c
feat: change default limit to 3
ZeeshanTamboli Apr 11, 2022
c2fff6f
docs: improve multiple snackbars docs
ZeeshanTamboli Apr 12, 2022
e0da52e
yarn docs:api
ZeeshanTamboli Apr 12, 2022
9cb9fdf
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 12, 2022
f43a409
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 12, 2022
4f5a29d
test: add limit test case
ZeeshanTamboli Apr 13, 2022
abf56e0
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 13, 2022
e711d31
test: add precedence test
ZeeshanTamboli Apr 13, 2022
6553a0e
test: closing each individual snackbars
ZeeshanTamboli Apr 13, 2022
d2eb822
fix: rename to TestApp
ZeeshanTamboli Apr 13, 2022
e8553b0
yarn docs:api
ZeeshanTamboli Apr 14, 2022
15ae19b
yarn docs:i18n
ZeeshanTamboli Apr 14, 2022
15fe439
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Apr 26, 2022
e82780f
docs: minimum 1 snackbar in maximum snackbars demo
ZeeshanTamboli Apr 26, 2022
bacec0b
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli May 5, 2022
50f04c9
change slide direction from transitioned snackbars
danilo-leal May 19, 2022
a32c9d8
remove contained variant from counter buttons
danilo-leal May 19, 2022
ae33aba
simplify demo
danilo-leal May 19, 2022
ea1388f
copywriting revision
danilo-leal May 19, 2022
911d1ca
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli May 19, 2022
636cac4
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli May 20, 2022
cb4e626
edit Snackbar documention
danilo-leal May 20, 2022
e3c9792
change to "Stacked snackbars"
danilo-leal May 20, 2022
7801857
further changing the page name
danilo-leal May 20, 2022
9ac8398
again further changing
danilo-leal May 20, 2022
981f842
copywriting in Props Priority
danilo-leal May 20, 2022
eabd044
Merge branch 'issue-1824-stacking-snackbar' of https://github.com/Zee…
danilo-leal May 20, 2022
dc0885c
fix: remove rtl related logic similar to #32808
ZeeshanTamboli May 20, 2022
8a87c6f
test: ignore stacked snackbars in visual regression tests for faster …
ZeeshanTamboli May 20, 2022
60364a3
yarn docs:api
ZeeshanTamboli May 20, 2022
f0247af
yarn docs:i18n
ZeeshanTamboli May 20, 2022
b6fbf61
change pathname
ZeeshanTamboli May 20, 2022
27e793a
test: change describe block title
ZeeshanTamboli May 20, 2022
4d3a097
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli May 23, 2022
0663a7d
fix: description spacing
ZeeshanTamboli May 23, 2022
481305c
test: add replaceComponentLinks test assertion for stacked snackbars
ZeeshanTamboli May 23, 2022
8c913e5
refactor: rename showSnackbar and closeSnackbar methods to show and c…
ZeeshanTamboli May 23, 2022
a2ee475
mention Material Design guideline not "approving" the stacked behavior
danilo-leal May 23, 2022
7a351f6
add demo of Stacked Snackbars in Snackbar article and remove notistac…
danilo-leal May 23, 2022
b94cd19
don't use "simple"
danilo-leal May 23, 2022
0e7d897
fix: distinguish action prop in stacked snackbars and SnackbarContent
ZeeshanTamboli May 24, 2022
bc72c94
refactor: rename SimpleSnackbars demo files to BasicStackedSnackbars
ZeeshanTamboli May 24, 2022
5496cb6
Sam's review
danilo-leal May 24, 2022
4882987
Merge branch 'issue-1824-stacking-snackbar' of https://github.com/Zee…
danilo-leal May 24, 2022
eb36a0b
fix: desctructure action prop to not spread it to Snackbar component
ZeeshanTamboli May 24, 2022
7c0fb1c
Merge branch 'issue-1824-stacking-snackbar' of https://github.com/Zee…
ZeeshanTamboli May 24, 2022
834bf99
refactor: improve stacked snackbars context error message and use Mui…
ZeeshanTamboli May 24, 2022
4ba165f
yarn extract-error-codes
ZeeshanTamboli May 24, 2022
55bb567
yarn prettier
ZeeshanTamboli May 24, 2022
5123db6
prettier ignore error-codes.json file
ZeeshanTamboli May 24, 2022
2812d69
Revert "prettier ignore error-codes.json file"
ZeeshanTamboli May 24, 2022
81bed3b
ignore docs/public/static/error-codes.json file in prettier script
ZeeshanTamboli May 24, 2022
b9ca745
docs: add missing sentence
ZeeshanTamboli May 25, 2022
b396612
Update docs/data/material/components/stacked-snackbars/stacked-snackb…
ZeeshanTamboli May 25, 2022
9927608
add spacing
ZeeshanTamboli May 25, 2022
b0f9bee
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Jun 7, 2022
401ca85
remove notistack dependency from docs and also from configurations
ZeeshanTamboli Jun 7, 2022
38d0b07
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Jun 28, 2022
c171a60
merge master branch and resolve conflicts
ZeeshanTamboli Jan 31, 2023
ed9ae54
yarn install
ZeeshanTamboli Jan 31, 2023
018124e
remove integration notistack demo files and prettier script file
ZeeshanTamboli Jan 31, 2023
e92aa0a
fix lint issues
ZeeshanTamboli Jan 31, 2023
146e2c3
load docs
ZeeshanTamboli Jan 31, 2023
a767a41
export type
ZeeshanTamboli Jan 31, 2023
2fcc5fe
remove stacked-snackbars.js file
ZeeshanTamboli Jan 31, 2023
f7d5326
resolve conflict
ZeeshanTamboli Feb 21, 2023
a2eff6b
Merge branch 'master' into issue-1824-stacking-snackbar
ZeeshanTamboli Feb 22, 2023
67e94e0
move stacked snackbar docs from lab to material ui
ZeeshanTamboli Feb 22, 2023
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
37 changes: 20 additions & 17 deletions docs/data/material/components/snackbars/snackbars.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ They may contain a text action, but no icons. You can use them to display notifi

{{"component": "modules/components/ComponentLinkHeader.js"}}

**Frequency**: Only one snackbar may be displayed at a time.
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved

## Simple snackbars
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved

A basic snackbar that aims to reproduce Google Keep's snackbar behavior.
Expand All @@ -40,6 +38,26 @@ You can control the position of the snackbar by specifying the `anchorOrigin` pr

{{"demo": "PositionedSnackbar.js"}}

## Stacked snackbars

The `Snackbar` component doesn't yet support displaying multiple stacked snackbars out of the box.
However, there are currently two complementary alternatives to do that:

### Lab's stacked snackbars

We have been developing a native component to support this use case and [we've made it available in the lab](/material-ui/react-stacked-snackbars/) to gather feedback for its first versions and general API design.

### notistack

![stars](https://img.shields.io/github/stars/iamhosseindhv/notistack.svg?style=social&label=Stars)
![npm downloads](https://img.shields.io/npm/dm/notistack.svg)

This example demonstrates how to use [notistack](https://github.com/iamhosseindhv/notistack).
notistack has an **imperative API** that makes it easy to display snackbars, without having to handle their open/close state.
It also enables you to **stack** them on top of one another (although this is discouraged by the Material Design guidelines).

{{"demo": "IntegrationNotistack.js", "defaultCodeOpen": false}}
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved

## Message Length

Some snackbars with varying message length.
Expand Down Expand Up @@ -88,21 +106,6 @@ Other examples:

{{"demo": "DirectionSnackbar.js"}}

## Complementary projects

For more advanced use cases you might be able to take advantage of:

### notistack

![stars](https://img.shields.io/github/stars/iamhosseindhv/notistack.svg?style=social&label=Stars)
![npm downloads](https://img.shields.io/npm/dm/notistack.svg)

This example demonstrates how to use [notistack](https://github.com/iamhosseindhv/notistack).
notistack has an **imperative API** that makes it easy to display snackbars, without having to handle their open/close state.
It also enables you to **stack** them on top of one another (although this is discouraged by the Material Design guidelines).

{{"demo": "IntegrationNotistack.js", "defaultCodeOpen": false}}

## Accessibility

(WAI-ARIA: https://www.w3.org/TR/wai-aria-1.1/#alert)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import SnackbarsProvider from '@mui/lab/SnackbarsProvider';
import useSnackbars from '@mui/lab/useSnackbars';
import Button from '@mui/material/Button';
import MuiAlert from '@mui/material/Alert';
import Stack from '@mui/material/Stack';

const Alert = React.forwardRef(function Alert(props, ref) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

function MyApp() {
const snackbars = useSnackbars();

return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Button
variant="outlined"
onClick={() =>
snackbars.showSnackbar({
content: (key) => (
<Alert
onClose={snackbars.closeSnackbar(key)}
severity="success"
sx={{ width: '100%' }}
>
This is a success message!
</Alert>
),
})
}
>
Open success snackbar
</Button>
<Alert severity="success">This is a success message!</Alert>
</Stack>
);
}

export default function CustomizedSnackbars() {
return (
<SnackbarsProvider autoHideDuration={4000}>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from 'react';
import SnackbarsProvider from '@mui/lab/SnackbarsProvider';
import useSnackbars from '@mui/lab/useSnackbars';
import Button from '@mui/material/Button';
import MuiAlert, { AlertProps } from '@mui/material/Alert';
import Stack from '@mui/material/Stack';

const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
props,
ref,
) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

function MyApp() {
const snackbars = useSnackbars();

return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Button
variant="outlined"
onClick={() =>
snackbars.showSnackbar({
content: (key: string) => (
<Alert
onClose={snackbars.closeSnackbar(key)}
severity="success"
sx={{ width: '100%' }}
>
This is a success message!
</Alert>
),
})
}
>
Open success snackbar
</Button>
<Alert severity="success">This is a success message!</Alert>
</Stack>
);
}

export default function CustomizedSnackbars() {
return (
<SnackbarsProvider autoHideDuration={4000}>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<SnackbarsProvider autoHideDuration={4000}>
<MyApp />
</SnackbarsProvider>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from 'react';
import SnackbarsProvider from '@mui/lab/SnackbarsProvider';
import Button from '@mui/material/Button';
import useSnackbars from '@mui/lab/useSnackbars';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';

function MyApp() {
const snackbars = useSnackbars();

return (
<React.Fragment>
<Button onClick={() => snackbars.showSnackbar({ message: 'Note Archived' })}>
Show Snackbar 1 with same action
</Button>
<Button onClick={() => snackbars.showSnackbar({ message: 'I love snacks' })}>
Show Snackbar 2 with same action
</Button>
</React.Fragment>
);
}

export default function GlobalActionSnackbars() {
const snackbarRef = React.useRef(null);

return (
<SnackbarsProvider
ref={snackbarRef}
autoHideDuration={4000}
action={(key) => (
<React.Fragment>
<Button
color="secondary"
size="small"
onClick={snackbarRef.current.closeSnackbar(key)}
>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={snackbarRef.current.closeSnackbar(key)}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
)}
>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from 'react';
import SnackbarsProvider, { CloseSnackbarRef } from '@mui/lab/SnackbarsProvider';
import Button from '@mui/material/Button';
import useSnackbars from '@mui/lab/useSnackbars';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';

function MyApp() {
const snackbars = useSnackbars();

return (
<React.Fragment>
<Button onClick={() => snackbars.showSnackbar({ message: 'Note Archived' })}>
Show Snackbar 1 with same action
</Button>
<Button onClick={() => snackbars.showSnackbar({ message: 'I love snacks' })}>
Show Snackbar 2 with same action
</Button>
</React.Fragment>
);
}

export default function GlobalActionSnackbars() {
const snackbarRef = React.useRef<CloseSnackbarRef>(null);

return (
<SnackbarsProvider
ref={snackbarRef}
autoHideDuration={4000}
action={(key) => (
<React.Fragment>
<Button
color="secondary"
size="small"
onClick={snackbarRef.current!.closeSnackbar(key)}
>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={snackbarRef.current!.closeSnackbar(key)}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
)}
>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import SnackbarsProvider from '@mui/lab/SnackbarsProvider';
import Button from '@mui/material/Button';
import useSnackbars from '@mui/lab/useSnackbars';
import MuiAlert from '@mui/material/Alert';

const Alert = React.forwardRef(function Alert(props, ref) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

function MyApp() {
const snackbars = useSnackbars();

return (
<React.Fragment>
<Button onClick={() => snackbars.showSnackbar()}>
Show Snackbar 1 with same content
</Button>
<Button onClick={() => snackbars.showSnackbar()}>
Show Snackbar 2 with same content
</Button>
</React.Fragment>
);
}

export default function GlobalContentSnackbars() {
const snackbarRef = React.useRef(null);

return (
<SnackbarsProvider
ref={snackbarRef}
autoHideDuration={4000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
content={(key) => (
<Alert
onClose={snackbarRef.current.closeSnackbar(key)}
severity="warning"
sx={{ width: '100%' }}
>
This is a warning message!
</Alert>
)}
>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as React from 'react';
import SnackbarsProvider, { CloseSnackbarRef } from '@mui/lab/SnackbarsProvider';
import Button from '@mui/material/Button';
import useSnackbars from '@mui/lab/useSnackbars';
import MuiAlert, { AlertProps } from '@mui/material/Alert';

const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
props,
ref,
) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

function MyApp() {
const snackbars = useSnackbars();

return (
<React.Fragment>
<Button onClick={() => snackbars.showSnackbar()}>
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
Show Snackbar 1 with same content
</Button>
<Button onClick={() => snackbars.showSnackbar()}>
Show Snackbar 2 with same content
</Button>
</React.Fragment>
);
}

export default function GlobalContentSnackbars() {
const snackbarRef = React.useRef<CloseSnackbarRef>(null);

return (
<SnackbarsProvider
ref={snackbarRef}
autoHideDuration={4000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
content={(key) => (
<Alert
onClose={snackbarRef.current!.closeSnackbar(key)}
severity="warning"
sx={{ width: '100%' }}
>
This is a warning message!
</Alert>
)}
>
<MyApp />
</SnackbarsProvider>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<SnackbarsProvider
ref={snackbarRef}
autoHideDuration={4000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
content={(key) => (
<Alert
onClose={snackbarRef.current!.closeSnackbar(key)}
severity="warning"
sx={{ width: '100%' }}
>
This is a warning message!
</Alert>
)}
>
<MyApp />
</SnackbarsProvider>
Loading