/
githubmirror
/
material-ui
Обзор
Документация
Войти
/
githubmirror
/
material-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/data/material/components/lists/InteractiveList.tsx
170 строк
5 KB
Siriwat K
[docs] Fix `Breadcrumbs`, `List`, `Divider`, and `Typography` dark mode demos (#45692)
26 мар 2025, 19:15
Не верифицирован
26 мар 2025, 19:15
7dd106e
Код
Авторство
О чём код?
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Box from '@mui/material/Box'; import List from '@mui/material/List'; import ListItem from '@mui/material/ListItem'; import ListItemAvatar from '@mui/material/ListItemAvatar'; import ListItemIcon from '@mui/material/ListItemIcon'; import ListItemText from '@mui/material/ListItemText'; import Avatar from '@mui/material/Avatar'; import IconButton from '@mui/material/IconButton'; import FormGroup from '@mui/material/FormGroup'; import FormControlLabel from '@mui/material/FormControlLabel'; import Checkbox from '@mui/material/Checkbox'; import Grid from '@mui/material/Grid'; import Typography from '@mui/material/Typography'; import FolderIcon from '@mui/icons-material/Folder'; import DeleteIcon from '@mui/icons-material/Delete'; function generate(element: React.ReactElement<unknown>) { return [0, 1, 2].map((value) => React.cloneElement(element, { key: value, }), ); } const Demo = styled('div')(({ theme }) => ({ backgroundColor: (theme.vars || theme).palette.background.paper, })); export default function InteractiveList() { const [dense, setDense] = React.useState(false); const [secondary, setSecondary] = React.useState(false); return ( <Box sx={{ flexGrow: 1, maxWidth: 752 }}> <FormGroup row> <FormControlLabel control={ <Checkbox checked={dense} onChange={(event) => setDense(event.target.checked)} /> } label="Enable dense" /> <FormControlLabel control={ <Checkbox checked={secondary} onChange={(event) => setSecondary(event.target.checked)} /> } label="Enable secondary text" /> </FormGroup> <Grid container spacing={2}> <Grid size={{ xs: 12, md: 6, }} > <Typography sx={{ mt: 4, mb: 2 }} variant="h6" component="div"> Text only </Typography> <Demo> <List dense={dense}> {generate( <ListItem> <ListItemText primary="Single-line item" secondary={secondary ? 'Secondary text' : null} /> </ListItem>, )} </List> </Demo> </Grid> <Grid size={{ xs: 12, md: 6, }} > <Typography sx={{ mt: 4, mb: 2 }} variant="h6" component="div"> Icon with text </Typography> <Demo> <List dense={dense}> {generate( <ListItem> <ListItemIcon> <FolderIcon /> </ListItemIcon> <ListItemText primary="Single-line item" secondary={secondary ? 'Secondary text' : null} /> </ListItem>, )} </List> </Demo> </Grid> </Grid> <Grid container spacing={2}> <Grid size={{ xs: 12, md: 6, }} > <Typography sx={{ mt: 4, mb: 2 }} variant="h6" component="div"> Avatar with text </Typography> <Demo> <List dense={dense}> {generate( <ListItem> <ListItemAvatar> <Avatar> <FolderIcon /> </Avatar> </ListItemAvatar> <ListItemText primary="Single-line item" secondary={secondary ? 'Secondary text' : null} /> </ListItem>, )} </List> </Demo> </Grid> <Grid size={{ xs: 12, md: 6, }} > <Typography sx={{ mt: 4, mb: 2 }} variant="h6" component="div"> Avatar with text and icon </Typography> <Demo> <List dense={dense}> {generate( <ListItem secondaryAction={ <IconButton edge="end" aria-label="delete"> <DeleteIcon /> </IconButton> } > <ListItemAvatar> <Avatar> <FolderIcon /> </Avatar> </ListItemAvatar> <ListItemText primary="Single-line item" secondary={secondary ? 'Secondary text' : null} /> </ListItem>, )} </List> </Demo> </Grid> </Grid> </Box> ); }