From 93665d6f3c042890ebafa96bfd15d744617aa103 Mon Sep 17 00:00:00 2001 From: Yash Shah <49yash@gmail.com> Date: Wed, 25 Dec 2024 01:06:00 +0530 Subject: [PATCH] [docs] Add interactive demo for Grid v2 (#44820) --- .../components/grid2/InteractiveGrid.js | 184 ++++++++++++++++ .../components/grid2/InteractiveGrid.tsx | 206 ++++++++++++++++++ docs/data/material/components/grid2/grid2.md | 6 + 3 files changed, 396 insertions(+) create mode 100644 docs/data/material/components/grid2/InteractiveGrid.js create mode 100644 docs/data/material/components/grid2/InteractiveGrid.tsx diff --git a/docs/data/material/components/grid2/InteractiveGrid.js b/docs/data/material/components/grid2/InteractiveGrid.js new file mode 100644 index 00000000000000..b3f33df5df6557 --- /dev/null +++ b/docs/data/material/components/grid2/InteractiveGrid.js @@ -0,0 +1,184 @@ +import * as React from 'react'; +import Grid from '@mui/material/Grid2'; +import FormControl from '@mui/material/FormControl'; +import FormLabel from '@mui/material/FormLabel'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import RadioGroup from '@mui/material/RadioGroup'; +import Radio from '@mui/material/Radio'; +import Paper from '@mui/material/Paper'; +import { HighlightedCode } from '@mui/docs/HighlightedCode'; + +export default function InteractiveGrid() { + const [direction, setDirection] = React.useState('row'); + const [justifyContent, setJustifyContent] = React.useState('center'); + const [alignItems, setAlignItems] = React.useState('center'); + + const jsx = ` + +`; + + return ( + + + + {[0, 1, 2].map((value) => ( + + ({ + p: 2, + backgroundColor: '#fff', + height: '100%', + color: 'text.secondary', + pt: `${(value + 1) * 10}px`, + pb: `${(value + 1) * 10}px`, + ...theme.applyStyles('dark', { + backgroundColor: '#1A2027', + }), + })} + > + {`Cell ${value + 1}`} + + + ))} + + + + + + + + direction + { + setDirection(event.target.value); + }} + > + } label="row" /> + } + label="row-reverse" + /> + } + label="column" + /> + } + label="column-reverse" + /> + + + + + + justifyContent + { + setJustifyContent(event.target.value); + }} + > + } + label="flex-start" + /> + } + label="center" + /> + } + label="flex-end" + /> + } + label="space-between" + /> + } + label="space-around" + /> + } + label="space-evenly" + /> + + + + + + alignItems + { + setAlignItems(event.target.value); + }} + > + } + label="flex-start" + /> + } + label="center" + /> + } + label="flex-end" + /> + } + label="stretch" + /> + } + label="baseline" + /> + + + + + + + + + + + ); +} diff --git a/docs/data/material/components/grid2/InteractiveGrid.tsx b/docs/data/material/components/grid2/InteractiveGrid.tsx new file mode 100644 index 00000000000000..6dabaafb7a974f --- /dev/null +++ b/docs/data/material/components/grid2/InteractiveGrid.tsx @@ -0,0 +1,206 @@ +import * as React from 'react'; +import Grid, { GridDirection } from '@mui/material/Grid2'; +import FormControl from '@mui/material/FormControl'; +import FormLabel from '@mui/material/FormLabel'; +import FormControlLabel from '@mui/material/FormControlLabel'; +import RadioGroup from '@mui/material/RadioGroup'; +import Radio from '@mui/material/Radio'; +import Paper from '@mui/material/Paper'; +import { HighlightedCode } from '@mui/docs/HighlightedCode'; + +type GridItemsAlignment = + | 'flex-start' + | 'center' + | 'flex-end' + | 'stretch' + | 'baseline'; + +type GridJustification = + | 'flex-start' + | 'center' + | 'flex-end' + | 'space-between' + | 'space-around' + | 'space-evenly'; + +export default function InteractiveGrid() { + const [direction, setDirection] = React.useState('row'); + const [justifyContent, setJustifyContent] = + React.useState('center'); + const [alignItems, setAlignItems] = React.useState('center'); + + const jsx = ` + +`; + + return ( + + + + {[0, 1, 2].map((value) => ( + + ({ + p: 2, + backgroundColor: '#fff', + height: '100%', + color: 'text.secondary', + pt: `${(value + 1) * 10}px`, + pb: `${(value + 1) * 10}px`, + ...theme.applyStyles('dark', { + backgroundColor: '#1A2027', + }), + })} + > + {`Cell ${value + 1}`} + + + ))} + + + + + + + + direction + { + setDirection( + (event.target as HTMLInputElement).value as GridDirection, + ); + }} + > + } label="row" /> + } + label="row-reverse" + /> + } + label="column" + /> + } + label="column-reverse" + /> + + + + + + justifyContent + { + setJustifyContent( + (event.target as HTMLInputElement).value as GridJustification, + ); + }} + > + } + label="flex-start" + /> + } + label="center" + /> + } + label="flex-end" + /> + } + label="space-between" + /> + } + label="space-around" + /> + } + label="space-evenly" + /> + + + + + + alignItems + { + setAlignItems( + (event.target as HTMLInputElement).value as GridItemsAlignment, + ); + }} + > + } + label="flex-start" + /> + } + label="center" + /> + } + label="flex-end" + /> + } + label="stretch" + /> + } + label="baseline" + /> + + + + + + + + + + + ); +} diff --git a/docs/data/material/components/grid2/grid2.md b/docs/data/material/components/grid2/grid2.md index 5ab1d1f7873a73..aca1e24e0bb535 100644 --- a/docs/data/material/components/grid2/grid2.md +++ b/docs/data/material/components/grid2/grid2.md @@ -92,6 +92,12 @@ Responsive values are supported by: - `spacing` - `offset` +## Interactive + +Below is an interactive demo that lets you explore the visual results of the different settings: + +{{"demo": "InteractiveGrid.js", "hideToolbar": true, "bg": true}} + ## Auto-layout The auto-layout feature gives equal space to all items present.