/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/data/material/components/snackbars/PositionedSnackbar.js
72 строки
2 KB
Diego Andai
[material-ui][Grid2] Rename to Grid (#45381)
24 фев 2025, 21:01
Не верифицирован
24 фев 2025, 21:01
f0de39a
Код
Авторство
О чём код?
import * as React from 'react'; import Grid from '@mui/material/Grid'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Snackbar from '@mui/material/Snackbar'; 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 onClick={handleClick({ vertical: 'top', horizontal: 'center' })}> Top-Center </Button> </Box> <Grid container sx={{ justifyContent: 'center' }}> <Grid size={6}> <Button onClick={handleClick({ vertical: 'top', horizontal: 'left' })}> Top-Left </Button> </Grid> <Grid sx={{ textAlign: 'right' }} size={6}> <Button onClick={handleClick({ vertical: 'top', horizontal: 'right' })}> Top-Right </Button> </Grid> <Grid size={6}> <Button onClick={handleClick({ vertical: 'bottom', horizontal: 'left' })}> Bottom-Left </Button> </Grid> <Grid sx={{ textAlign: 'right' }} size={6}> <Button onClick={handleClick({ vertical: 'bottom', horizontal: 'right' })}> Bottom-Right </Button> </Grid> </Grid> <Box sx={{ display: 'flex', justifyContent: 'center' }}> <Button onClick={handleClick({ vertical: 'bottom', horizontal: 'center' })}> Bottom-Center </Button> </Box> </React.Fragment> ); return ( <Box sx={{ width: 500 }}> {buttons} <Snackbar anchorOrigin={{ vertical, horizontal }} open={open} onClose={handleClose} message="I love snacks" key={vertical + horizontal} /> </Box> ); }