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

[joy-ui] Add Snackbar component #38801

Merged
merged 68 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
a29a4b2
Joy UI Snackbar initial start
ZeeshanTamboli Sep 4, 2023
c9565fa
add color, size and variant props
ZeeshanTamboli Sep 5, 2023
78b8fe5
add other props
ZeeshanTamboli Sep 5, 2023
4519020
add anchorOrigin and other props
ZeeshanTamboli Sep 5, 2023
30e0818
anchorOrigin class names
ZeeshanTamboli Sep 5, 2023
332f1f3
add styles
ZeeshanTamboli Sep 5, 2023
6b86512
add click away listener
ZeeshanTamboli Sep 5, 2023
601fbc5
do not close on blur
ZeeshanTamboli Sep 5, 2023
be4da8d
remove unneeded styles
ZeeshanTamboli Sep 5, 2023
732c646
add positioned snackbar demo
ZeeshanTamboli Sep 5, 2023
f59072c
generate proptypes
ZeeshanTamboli Sep 5, 2023
82ac9d7
change w3 aria link
ZeeshanTamboli Sep 5, 2023
1dc7154
import React
ZeeshanTamboli Sep 5, 2023
3d89466
yarn docs:api
ZeeshanTamboli Sep 5, 2023
5137c6b
remove planned tag from Snackbar
ZeeshanTamboli Sep 5, 2023
33c72ee
improve styles
ZeeshanTamboli Sep 5, 2023
94a2e4b
add default value to slots
ZeeshanTamboli Sep 6, 2023
0d5173e
update positioned snackbar demo
ZeeshanTamboli Sep 6, 2023
5850daa
add snackbar with decorators demo
ZeeshanTamboli Sep 6, 2023
69667db
yarn proptypes
ZeeshanTamboli Sep 6, 2023
7d6e6f2
add color inversion feature
ZeeshanTamboli Sep 7, 2023
0ca4344
add colorContext class
ZeeshanTamboli Sep 7, 2023
c7a79fc
Revert "add colorContext class"
ZeeshanTamboli Sep 7, 2023
8855c32
add new feature tag
ZeeshanTamboli Sep 7, 2023
c17486f
Merge branch 'master' into joy-ui-snackbar
ZeeshanTamboli Sep 27, 2023
ac67ec1
fix displaying postioned snackbars
ZeeshanTamboli Sep 28, 2023
734f8ac
Add defaultanimation and demo on how to add custom animation
ZeeshanTamboli Sep 29, 2023
ed5447a
Add JoySnackbar in theme
ZeeshanTamboli Sep 29, 2023
463981b
Merge branch 'master' into joy-ui-snackbar
ZeeshanTamboli Sep 29, 2023
dbdee1e
add code quote
ZeeshanTamboli Sep 29, 2023
2881cc9
Merge branch 'master' of https://github.com/mui/material-ui into joy-…
siriwatknp Oct 5, 2023
a710021
Stray design tweaks to the demos
zanivan Oct 5, 2023
42ced1b
Run yarn docs:typescript:formatted
zanivan Oct 5, 2023
240a825
Fix imports
zanivan Oct 5, 2023
cbaf73f
refine snackbar styles and logic
siriwatknp Oct 6, 2023
0d6ec9e
Merge branch 'joy-ui-snackbar' of github.com:ZeeshanTamboli/material-…
siriwatknp Oct 6, 2023
90c0ae1
add icons to position demo
siriwatknp Oct 6, 2023
26f437d
add variant demo
siriwatknp Oct 6, 2023
8d02dd9
add sizes and colors demo
siriwatknp Oct 6, 2023
04bb8ee
add hide duration demo
siriwatknp Oct 6, 2023
76f5c08
remove duplicate style
ZeeshanTamboli Oct 6, 2023
7478fba
update proptypes and API docs
ZeeshanTamboli Oct 6, 2023
c57233f
fix lint
ZeeshanTamboli Oct 6, 2023
13e66e0
add onUnmount prop
siriwatknp Oct 6, 2023
7299b92
add more demos
siriwatknp Oct 6, 2023
b845562
add clickAway Snackbar slot in extendTheme spec
ZeeshanTamboli Oct 6, 2023
43964cd
update demos
siriwatknp Oct 6, 2023
3d2ce74
add ts demos
siriwatknp Oct 6, 2023
ae9c8df
run scripts
siriwatknp Oct 6, 2023
24679b4
resolve conflicts
ZeeshanTamboli Oct 6, 2023
e40be2a
add describeConformance tests
ZeeshanTamboli Oct 6, 2023
b9080f5
fix duplicate declaration
ZeeshanTamboli Oct 6, 2023
4e1243a
fix lint
ZeeshanTamboli Oct 6, 2023
bb24b3f
fix CI
ZeeshanTamboli Oct 6, 2023
4831291
add more tests
ZeeshanTamboli Oct 6, 2023
2b7b7dc
Merge branch 'master' of https://github.com/mui/material-ui into joy-…
siriwatknp Oct 9, 2023
b6a97c7
esolve conflicts
ZeeshanTamboli Oct 12, 2023
82568b7
fix demos
siriwatknp Oct 13, 2023
796f97a
fix: open at exiting bug
siriwatknp Oct 13, 2023
f6a387d
Merge branch 'master' of https://github.com/mui/material-ui into joy-…
siriwatknp Oct 23, 2023
ac8680e
make open prop required
ZeeshanTamboli Oct 23, 2023
d9d313e
Merge branch 'master' into joy-ui-snackbar
ZeeshanTamboli Oct 23, 2023
f84eb60
update demos as suggested
siriwatknp Oct 23, 2023
c843595
run scripts
siriwatknp Oct 23, 2023
f377ac8
Merge branch 'joy-ui-snackbar' of https://github.com/ZeeshanTamboli/m…
ZeeshanTamboli Oct 23, 2023
63c8139
Decrement the duration counter by 100ms
ZeeshanTamboli Oct 23, 2023
36a078a
Small text adjustments
zanivan Oct 23, 2023
42f0ebb
Tweaks to the Colors demo
zanivan Oct 23, 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
65 changes: 65 additions & 0 deletions docs/data/joy/components/snackbar/CustomAnimatedSnackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import Button from '@mui/joy/Button';
import Snackbar from '@mui/joy/Snackbar';
import { keyframes } from '@mui/system';

const inAnimation = keyframes`
0% {
transform: scale(0);
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
`;

const outAnimation = keyframes`
0% {
transform: scale(1);
opacity: 1;
}
100% {
transform: scale(0);
opacity: 0;
}
`;

export default function CustomAnimatedSnackbar() {
const [open, setOpen] = React.useState(false);

const animationDuration = 600;

const handleClick = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

return (
<div>
<Button variant="outlined" color="neutral" onClick={handleClick}>
Show Snackbar
</Button>
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
open={open}
onClose={handleClose}
autoHideDuration={4000}
animationDuration={animationDuration}
sx={{
...(open && {
animation: `${inAnimation} ${animationDuration}ms forwards`,
}),
...(!open && {
animation: `${outAnimation} ${animationDuration}ms forwards`,
}),
}}
>
I love this animation!
</Snackbar>
</div>
);
}
65 changes: 65 additions & 0 deletions docs/data/joy/components/snackbar/CustomAnimatedSnackbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import Button from '@mui/joy/Button';
import Snackbar from '@mui/joy/Snackbar';
import { keyframes } from '@mui/system';

const inAnimation = keyframes`
0% {
transform: scale(0);
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
`;

const outAnimation = keyframes`
0% {
transform: scale(1);
opacity: 1;
}
100% {
transform: scale(0);
opacity: 0;
}
`;

export default function CustomAnimatedSnackbar() {
const [open, setOpen] = React.useState(false);

const animationDuration = 600;

const handleClick = () => {
setOpen(true);
};

const handleClose = () => {
setOpen(false);
};

return (
<div>
<Button variant="outlined" color="neutral" onClick={handleClick}>
Show Snackbar
</Button>
<Snackbar
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
open={open}
onClose={handleClose}
autoHideDuration={4000}
animationDuration={animationDuration}
sx={{
...(open && {
animation: `${inAnimation} ${animationDuration}ms forwards`,
}),
...(!open && {
animation: `${outAnimation} ${animationDuration}ms forwards`,
}),
}}
>
I love this animation!
</Snackbar>
</div>
);
}
105 changes: 105 additions & 0 deletions docs/data/joy/components/snackbar/PositionedSnackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import * as React from 'react';
import Grid from '@mui/joy/Grid';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Snackbar from '@mui/joy/Snackbar';
import NorthWestIcon from '@mui/icons-material/NorthWest';
import NorthEastIcon from '@mui/icons-material/NorthEast';
import NorthIcon from '@mui/icons-material/North';
import SouthIcon from '@mui/icons-material/South';
import SouthEastIcon from '@mui/icons-material/SouthEast';
import SouthWestIcon from '@mui/icons-material/SouthWest';

export default function PositionedSnackbar() {
const [state, setState] = React.useState({
open: false,
vertical: 'top',
horizontal: 'center',
});
const { vertical, horizontal, open } = state;

const handleClick = (newState) => () => {
setState({ ...newState, open: true });
};

const handleClose = () => {
setState({ ...state, open: false });
};

const buttons = (
<React.Fragment>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button
variant="plain"
startDecorator={<NorthIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'center' })}
sx={{ flexDirection: 'column', gap: 1, '--Button-gap': 0 }}
>
Top Center
</Button>
</Box>
<Grid container justifyContent="center">
<Grid xs={6}>
<Button
variant="plain"
startDecorator={<NorthWestIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'left' })}
>
Top Left
</Button>
</Grid>
<Grid xs={6} textAlign="right" sx={{ mb: 2 }}>
<Button
variant="plain"
endDecorator={<NorthEastIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'right' })}
>
Top Right
</Button>
</Grid>
<Grid xs={6}>
<Button
variant="plain"
startDecorator={<SouthWestIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'left' })}
>
Bottom Left
</Button>
</Grid>
<Grid xs={6} textAlign="right">
<Button
variant="plain"
endDecorator={<SouthEastIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'right' })}
>
Bottom Right
</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button
variant="plain"
endDecorator={<SouthIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'center' })}
sx={{ flexDirection: 'column', gap: 1, '--Button-gap': 0 }}
>
Bottom Center
</Button>
</Box>
</React.Fragment>
);

return (
<Box sx={{ width: 500 }}>
{buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
key={vertical + horizontal}
>
I love snacks
</Snackbar>
</Box>
);
}
109 changes: 109 additions & 0 deletions docs/data/joy/components/snackbar/PositionedSnackbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import * as React from 'react';
import Grid from '@mui/joy/Grid';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Snackbar, { SnackbarOrigin } from '@mui/joy/Snackbar';
import NorthWestIcon from '@mui/icons-material/NorthWest';
import NorthEastIcon from '@mui/icons-material/NorthEast';
import NorthIcon from '@mui/icons-material/North';
import SouthIcon from '@mui/icons-material/South';
import SouthEastIcon from '@mui/icons-material/SouthEast';
import SouthWestIcon from '@mui/icons-material/SouthWest';

interface State extends SnackbarOrigin {
open: boolean;
}

export default function PositionedSnackbar() {
const [state, setState] = React.useState<State>({
open: false,
vertical: 'top',
horizontal: 'center',
});
const { vertical, horizontal, open } = state;

const handleClick = (newState: SnackbarOrigin) => () => {
setState({ ...newState, open: true });
};

const handleClose = () => {
setState({ ...state, open: false });
};

const buttons = (
<React.Fragment>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button
variant="plain"
startDecorator={<NorthIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'center' })}
sx={{ flexDirection: 'column', gap: 1, '--Button-gap': 0 }}
>
Top Center
</Button>
</Box>
<Grid container justifyContent="center">
<Grid xs={6}>
<Button
variant="plain"
startDecorator={<NorthWestIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'left' })}
>
Top Left
</Button>
</Grid>
<Grid xs={6} textAlign="right" sx={{ mb: 2 }}>
<Button
variant="plain"
endDecorator={<NorthEastIcon />}
onClick={handleClick({ vertical: 'top', horizontal: 'right' })}
>
Top Right
</Button>
</Grid>
<Grid xs={6}>
<Button
variant="plain"
startDecorator={<SouthWestIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'left' })}
>
Bottom Left
</Button>
</Grid>
<Grid xs={6} textAlign="right">
<Button
variant="plain"
endDecorator={<SouthEastIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'right' })}
>
Bottom Right
</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button
variant="plain"
endDecorator={<SouthIcon />}
onClick={handleClick({ vertical: 'bottom', horizontal: 'center' })}
sx={{ flexDirection: 'column', gap: 1, '--Button-gap': 0 }}
>
Bottom Center
</Button>
</Box>
</React.Fragment>
);

return (
<Box sx={{ width: 500 }}>
{buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
key={vertical + horizontal}
>
I love snacks
</Snackbar>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
key={vertical + horizontal}
>
I love snacks
</Snackbar>
Loading