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

[docs][base] Move styles to the bottom of demos code for Snackbar #36719

Merged
merged 3 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
152 changes: 76 additions & 76 deletions docs/data/base/components/snackbar/TransitionComponentSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,82 @@ import CheckRoundedIcon from '@mui/icons-material/CheckRounded';
import CloseIcon from '@mui/icons-material/Close';
import Snackbar from '@mui/base/Snackbar';

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>
);
}

const blue = {
50: '#F0F7FF',
100: '#DAECFF',
Expand Down Expand Up @@ -85,79 +161,3 @@ const positioningStyles = {
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>
);
}
152 changes: 76 additions & 76 deletions docs/data/base/components/snackbar/TransitionComponentSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,82 @@ import CloseIcon from '@mui/icons-material/Close';
import Snackbar from '@mui/base/Snackbar';
import { SnackbarCloseReason } from '@mui/base/useSnackbar';

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>
);
}

const blue = {
50: '#F0F7FF',
100: '#DAECFF',
Expand Down Expand Up @@ -86,79 +162,3 @@ const positioningStyles = {
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>
);
}
54 changes: 27 additions & 27 deletions docs/data/base/components/snackbar/UnstyledSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@ import * as React from 'react';
import { styled, keyframes, css } from '@mui/system';
import Snackbar from '@mui/base/Snackbar';

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

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

setOpen(false);
};

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

return (
<React.Fragment>
<button type="button" onClick={handleClick}>
Open snackbar
</button>
<StyledSnackbar open={open} autoHideDuration={5000} onClose={handleClose}>
Hello World
</StyledSnackbar>
</React.Fragment>
);
}

const blue = {
50: '#F0F7FF',
400: '#3399FF',
Expand Down Expand Up @@ -48,30 +75,3 @@ const StyledSnackbar = styled(Snackbar)(
transition: transform 0.2s ease-out;
`,
);

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

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

setOpen(false);
};

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

return (
<React.Fragment>
<button type="button" onClick={handleClick}>
Open snackbar
</button>
<StyledSnackbar open={open} autoHideDuration={5000} onClose={handleClose}>
Hello World
</StyledSnackbar>
</React.Fragment>
);
}
Loading