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

[SnackbarUnstyled] Create component and useSnackbar hook #33227

Merged
merged 86 commits into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
80ae697
SnackbarUnstyled initial commit
ZeeshanTamboli Jun 9, 2022
93faaf9
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 9, 2022
4a723e6
fix api description
ZeeshanTamboli Jun 9, 2022
47a69a4
add some more props
ZeeshanTamboli Jun 9, 2022
9aa17ff
remove children prop description
ZeeshanTamboli Jun 10, 2022
f1d12be
add className in root props
ZeeshanTamboli Jun 10, 2022
d579e80
add some props
ZeeshanTamboli Jun 10, 2022
c38b6ee
add other event handlers
ZeeshanTamboli Jun 10, 2022
1a78db1
support event handler callbacks from componentsProps.root
ZeeshanTamboli Jun 13, 2022
22700a0
add other logic
ZeeshanTamboli Jun 13, 2022
0946e49
add ref
ZeeshanTamboli Jun 13, 2022
adac738
add snackbarUnstyled classes
ZeeshanTamboli Jun 15, 2022
aba8c13
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 15, 2022
06a8e06
add SnackbarUnstyled describeConformanceUnstyled
ZeeshanTamboli Jun 15, 2022
d002a6f
yarn proptypes
ZeeshanTamboli Jun 15, 2022
6a18a21
setup docs
ZeeshanTamboli Jun 15, 2022
7c35ec2
add Basic usage docs
ZeeshanTamboli Jun 16, 2022
53ee0a8
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 17, 2022
28e45ab
children prop should accept string
ZeeshanTamboli Jun 17, 2022
0df128b
yarn proptypes
ZeeshanTamboli Jun 17, 2022
dd3714d
add Transition component demo
ZeeshanTamboli Jun 20, 2022
e53ba67
improve SnackbarUnstyled types
ZeeshanTamboli Jun 20, 2022
8d3a9f7
refactor MUI Snackbar types to use types from SnackbarUnstyled
ZeeshanTamboli Jun 20, 2022
873ee49
migrate MUI Core Snackbar component to use SnackbarUnstyled
ZeeshanTamboli Jun 20, 2022
d315491
fix types
ZeeshanTamboli Jun 20, 2022
93b1260
yarn docs:i18n
ZeeshanTamboli Jun 20, 2022
5626d6e
fix warning and add docs
ZeeshanTamboli Jun 20, 2022
7db2c89
yarn docs:typescript:formatted
ZeeshanTamboli Jun 20, 2022
29ddf1b
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 20, 2022
5e0eb9f
add OverrideableComponent
ZeeshanTamboli Jun 20, 2022
73404d6
fix types
ZeeshanTamboli Jun 20, 2022
31d7bb9
fix style identation
ZeeshanTamboli Jun 20, 2022
79dbfb3
customize simple snackbar
danilo-leal Jun 23, 2022
4274c96
customizing the second demo
danilo-leal Jun 23, 2022
74b9fe5
typescript:formatted
danilo-leal Jun 23, 2022
19cec80
resolve conflicts
ZeeshanTamboli Jun 23, 2022
a9d6dba
fix transition animation in demo
ZeeshanTamboli Jun 23, 2022
db26c45
revert changes in Material UI Snackbar component
ZeeshanTamboli Jun 24, 2022
b183f15
add useSnackbar hook
ZeeshanTamboli Jun 24, 2022
6b48905
add useSnackbar demo
ZeeshanTamboli Jun 24, 2022
63b5d45
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 24, 2022
f8fc88f
fix transition type
ZeeshanTamboli Jun 24, 2022
c079bd7
use Partial type instead
ZeeshanTamboli Jun 24, 2022
9b0b01d
allow componentsProps callback and ownerState propagation
ZeeshanTamboli Jun 27, 2022
769f592
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jun 27, 2022
f808f10
fix type
ZeeshanTamboli Jun 27, 2022
be61bbf
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Jul 14, 2022
703581e
useSlotProps for Transition component as well
ZeeshanTamboli Jul 14, 2022
11ba396
pass getTransitionProps to getSlotProps
ZeeshanTamboli Jul 14, 2022
a83e744
remove exited from dependency array
ZeeshanTamboli Jul 14, 2022
1166248
Update packages/mui-base/src/SnackbarUnstyled/useSnackbar.ts
ZeeshanTamboli Jul 15, 2022
fec6230
resolve PR review changes
ZeeshanTamboli Jul 15, 2022
14f01fc
yarn proptypes && yarn docs:api
ZeeshanTamboli Jul 15, 2022
6a69771
remove Transition component and update demos
ZeeshanTamboli Jul 15, 2022
8139c92
add return type of getRootProps
ZeeshanTamboli Jul 15, 2022
eb36dcf
add SnackbarUnstyled tests
ZeeshanTamboli Jul 15, 2022
8ef2dd8
export UseSnackbarRootSlotOwnProps
ZeeshanTamboli Jul 15, 2022
3790d12
Merge branch 'master' into issue/27170-unstyled-snackbar
mnajdova Aug 11, 2022
263024c
Improve event handlers, resolve clickAwayListenerProps
mnajdova Aug 11, 2022
db053f3
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Aug 12, 2022
7004d42
yarn proptypes && yarn docs:api
ZeeshanTamboli Aug 12, 2022
88075fd
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Aug 15, 2022
4c4716f
make the tests pass by passing props for event handlers
ZeeshanTamboli Aug 15, 2022
a23b408
docs: implement slide transition with react-transition-grou
ZeeshanTamboli Aug 15, 2022
4433dc1
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Aug 15, 2022
c315679
snackbar doc structure draft
samuelsycamore Aug 16, 2022
f2352c8
snackbar content first pass
samuelsycamore Aug 16, 2022
4e99697
content second pass
samuelsycamore Aug 17, 2022
3026d27
fix copypasta
samuelsycamore Aug 17, 2022
07512b2
tweak frontmatter and tiny tense change
samuelsycamore Aug 17, 2022
d4585a0
introduce hook demo
samuelsycamore Aug 17, 2022
b4a091e
docs: class -> className
ZeeshanTamboli Aug 17, 2022
62645e9
fix URL to ClickAwayListener component
ZeeshanTamboli Aug 17, 2022
735c41e
docs: remove redundant line
ZeeshanTamboli Aug 17, 2022
a89fedc
expand basics section
samuelsycamore Aug 17, 2022
5104048
typo
samuelsycamore Aug 17, 2022
7cf394a
clarify what clickawaylistener does
samuelsycamore Aug 17, 2022
fccce93
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Aug 25, 2022
eb5bbf2
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Aug 25, 2022
6b57a10
yarn docs:api
ZeeshanTamboli Aug 25, 2022
e782ff3
change className signature pattern
ZeeshanTamboli Sep 22, 2022
f12673b
use optional chaining operator
ZeeshanTamboli Sep 22, 2022
9408a8b
Merge branch 'master' into issue/27170-unstyled-snackbar
ZeeshanTamboli Sep 22, 2022
28e7553
remove unnecessary type
ZeeshanTamboli Sep 22, 2022
0a1e8ef
yarn docs:api
ZeeshanTamboli Sep 22, 2022
6cb3dad
remove md specs and mention of position
samuelsycamore Oct 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
163 changes: 163 additions & 0 deletions docs/data/base/components/snackbar/TransitionComponentSnackbar.js
@@ -0,0 +1,163 @@
import * as React from 'react';
import { Transition } from 'react-transition-group';
import { styled } from '@mui/system';
import CheckRoundedIcon from '@mui/icons-material/CheckRounded';
import CloseIcon from '@mui/icons-material/Close';
import SnackbarUnstyled from '@mui/base/SnackbarUnstyled';

const blue = {
50: '#F0F7FF',
100: '#DAECFF',
400: '#3399FF',
600: '#0072E5',
900: '#003A75',
};

const grey = {
200: '#E0E3E7',
800: '#2D3843',
};

const StyledSnackbar = styled(SnackbarUnstyled)`
position: fixed;
z-index: 5500;
display: flex;
bottom: 16px;
right: 16px;
max-width: 560px;
min-width: 300px;
`;

const SnackbarContent = styled('div')(
({ theme }) => `
display: flex;
overflow: hidden;
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[400]};
box-shadow: ${
theme.palette.mode === 'dark'
? `0 5px 13px -3px rgba(0,0,0,0.4)`
: `0 5px 13px -3px ${grey[200]}`
};
padding: 0.875rem;
color: ${theme.palette.mode === 'dark' ? '#fff' : blue[900]};
font-family: IBM Plex Sans, sans-serif;
font-weight: 500;
text-align: start;
position: relative;

& .snackbar-message {
flex: 1 1 0%;
max-width: 100%;
}

& .snackbar-title {
line-height: 1.5rem;
margin-right: 0.5rem;
}

& .snackbar-description {
line-height: 1.5rem;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? blue[100] : grey[800]};
}

& .snackbar-close-icon {
cursor: pointer;
font-size: 10px;
position: absolute;
top: 0.725rem;
right: 0.725rem;
width: 1.25rem;
height: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
}
`,
);

const positioningStyles = {
entering: 'translateX(0)',
entered: 'translateX(0)',
exiting: 'translateX(500px)',
exited: 'translateX(500px)',
unmounted: 'translateX(500px)',
};

export default function TransitionComponentSnackbar() {
const [open, setOpen] = React.useState(false);
const [exited, setExited] = React.useState(true);
const nodeRef = React.useRef(null);

const handleClose = (_, reason) => {
if (reason === 'clickaway') {
return;
}

setOpen(false);
};

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

const handleOnEnter = () => {
setExited(false);
};

const handleOnExited = () => {
setExited(true);
};

return (
<React.Fragment>
<button type="button" onClick={handleClick}>
Open snackbar
</button>
<StyledSnackbar
autoHideDuration={5000}
open={open}
onClose={handleClose}
exited={exited}
>
<Transition
timeout={{ enter: 400, exit: 400 }}
in={open}
appear
unmountOnExit
onEnter={handleOnEnter}
onExited={handleOnExited}
nodeRef={nodeRef}
>
{(status) => (
<SnackbarContent
style={{
transform: positioningStyles[status],
transition: 'transform 300ms ease',
}}
ref={nodeRef}
>
<CheckRoundedIcon
sx={{
flexShrink: 0,
marginRight: '0.75rem',
width: '1.25rem',
height: '1.5rem',
}}
/>
<div className="snackbar-message">
<div className="snackbar-title">Notifications sent</div>
<div className="snackbar-description">
All your notifications were sent to the desired address.
</div>
</div>
<CloseIcon onClick={handleClose} className="snackbar-close-icon" />
</SnackbarContent>
)}
</Transition>
</StyledSnackbar>
</React.Fragment>
);
}
163 changes: 163 additions & 0 deletions docs/data/base/components/snackbar/TransitionComponentSnackbar.tsx
@@ -0,0 +1,163 @@
import * as React from 'react';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I have copied the design for this demo from Chakra UI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @danilo-leal maybe we want to re-adjust the styles so that we have our own instead of copied from another library :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done some tinkering on the demos there 👌

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @danilo-leal ! Can you also take a look at the third demo I added now for the useSnackbar hook? Perhaps you want to tweak it as well.

import { Transition } from 'react-transition-group';
import { styled } from '@mui/system';
import CheckRoundedIcon from '@mui/icons-material/CheckRounded';
import CloseIcon from '@mui/icons-material/Close';
import SnackbarUnstyled, { SnackbarCloseReason } from '@mui/base/SnackbarUnstyled';

const blue = {
50: '#F0F7FF',
100: '#DAECFF',
400: '#3399FF',
600: '#0072E5',
900: '#003A75',
};

const grey = {
200: '#E0E3E7',
800: '#2D3843',
};

const StyledSnackbar = styled(SnackbarUnstyled)`
position: fixed;
z-index: 5500;
display: flex;
bottom: 16px;
right: 16px;
max-width: 560px;
min-width: 300px;
`;

const SnackbarContent = styled('div')(
({ theme }) => `
display: flex;
overflow: hidden;
background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[50]};
border-radius: 8px;
border: 1px solid ${theme.palette.mode === 'dark' ? blue[600] : blue[400]};
box-shadow: ${
theme.palette.mode === 'dark'
? `0 5px 13px -3px rgba(0,0,0,0.4)`
: `0 5px 13px -3px ${grey[200]}`
};
padding: 0.875rem;
color: ${theme.palette.mode === 'dark' ? '#fff' : blue[900]};
font-family: IBM Plex Sans, sans-serif;
font-weight: 500;
text-align: start;
position: relative;

& .snackbar-message {
flex: 1 1 0%;
max-width: 100%;
}

& .snackbar-title {
line-height: 1.5rem;
margin-right: 0.5rem;
}

& .snackbar-description {
line-height: 1.5rem;
font-weight: 400;
color: ${theme.palette.mode === 'dark' ? blue[100] : grey[800]};
}

& .snackbar-close-icon {
cursor: pointer;
font-size: 10px;
position: absolute;
top: 0.725rem;
right: 0.725rem;
width: 1.25rem;
height: 1.5rem;
display: flex;
align-items: center;
justify-content: center;
}
`,
);

const positioningStyles = {
entering: 'translateX(0)',
entered: 'translateX(0)',
exiting: 'translateX(500px)',
exited: 'translateX(500px)',
unmounted: 'translateX(500px)',
};

export default function TransitionComponentSnackbar() {
const [open, setOpen] = React.useState(false);
const [exited, setExited] = React.useState(true);
const nodeRef = React.useRef(null);

const handleClose = (_: any, reason: SnackbarCloseReason) => {
if (reason === 'clickaway') {
return;
}

setOpen(false);
};

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

const handleOnEnter = () => {
setExited(false);
};

const handleOnExited = () => {
setExited(true);
};

return (
<React.Fragment>
<button type="button" onClick={handleClick}>
Open snackbar
</button>
<StyledSnackbar
autoHideDuration={5000}
open={open}
onClose={handleClose}
exited={exited}
>
<Transition
timeout={{ enter: 400, exit: 400 }}
in={open}
appear
unmountOnExit
onEnter={handleOnEnter}
onExited={handleOnExited}
nodeRef={nodeRef}
>
{(status) => (
<SnackbarContent
style={{
transform: positioningStyles[status],
transition: 'transform 300ms ease',
}}
ref={nodeRef}
>
<CheckRoundedIcon
sx={{
flexShrink: 0,
marginRight: '0.75rem',
width: '1.25rem',
height: '1.5rem',
}}
/>
<div className="snackbar-message">
<div className="snackbar-title">Notifications sent</div>
<div className="snackbar-description">
All your notifications were sent to the desired address.
</div>
</div>
<CloseIcon onClick={handleClose} className="snackbar-close-icon" />
</SnackbarContent>
)}
</Transition>
</StyledSnackbar>
</React.Fragment>
);
}