index
int64 0
0
| repo_id
stringlengths 16
181
| file_path
stringlengths 28
270
| content
stringlengths 1
11.6M
| __index_level_0__
int64 0
10k
|
---|---|---|---|---|
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerText.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Stack from '@mui/joy/Stack';
import Divider from '@mui/joy/Divider';
import Chip from '@mui/joy/Chip';
export default function DividerText() {
const content = (
<Box sx={{ fontSize: 'sm', color: 'text.tertiary' }}>
{`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id dignissim justo.
Nulla ut facilisis ligula. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Sed malesuada lobortis pretium.`}
</Box>
);
return (
<Stack spacing={1}>
{content}
<Divider>Visual indicator</Divider>
{content}
<Divider>
<Chip variant="soft" color="neutral" size="sm">
Visual indicator
</Chip>
</Divider>
{content}
</Stack>
);
}
| 1,100 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerText.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Stack from '@mui/joy/Stack';
import Divider from '@mui/joy/Divider';
import Chip from '@mui/joy/Chip';
export default function DividerText() {
const content = (
<Box sx={{ fontSize: 'sm', color: 'text.tertiary' }}>
{`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id dignissim justo.
Nulla ut facilisis ligula. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Sed malesuada lobortis pretium.`}
</Box>
);
return (
<Stack spacing={1}>
{content}
<Divider>Visual indicator</Divider>
{content}
<Divider>
<Chip variant="soft" color="neutral" size="sm">
Visual indicator
</Chip>
</Divider>
{content}
</Stack>
);
}
| 1,101 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerText.tsx.preview | {content}
<Divider>Visual indicator</Divider>
{content}
<Divider>
<Chip variant="soft" color="neutral" size="sm">
Visual indicator
</Chip>
</Divider>
{content} | 1,102 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerUsage.js | import * as React from 'react';
import Stack from '@mui/joy/Stack';
import Sheet from '@mui/joy/Sheet';
import Divider from '@mui/joy/Divider';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function DividerUsage() {
return (
<JoyUsageDemo
componentName="Divider"
data={[
{
propName: 'orientation',
knob: 'radio',
defaultValue: 'horizontal',
options: ['horizontal', 'vertical'],
},
{
propName: 'children',
knob: 'input',
defaultValue: '',
},
]}
renderDemo={(props) => (
<Sheet sx={{ my: 2, bgcolor: 'transparent' }}>
<Sheet
sx={{
height: 12,
width: 80,
borderRadius: 'lg',
mb: 1,
bgcolor: 'background.level3',
}}
/>
<Stack
direction={props.orientation === 'vertical' ? 'row' : 'column'}
spacing={2}
sx={{ width: 300, pb: 3 }}
>
<Sheet
sx={{
height: props.orientation === 'vertical' ? 120 : 40,
flexGrow: 1,
borderRadius: 'xs',
bgcolor: 'background.level3',
}}
/>
<Divider {...props} />
<Sheet
sx={{
height: props.orientation === 'vertical' ? 120 : 40,
flexGrow: 1,
borderRadius: 'xs',
bgcolor: 'background.level3',
}}
/>
</Stack>
</Sheet>
)}
/>
);
}
| 1,103 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerUsage.tsx | import * as React from 'react';
import Stack from '@mui/joy/Stack';
import Sheet from '@mui/joy/Sheet';
import Divider from '@mui/joy/Divider';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function DividerUsage() {
return (
<JoyUsageDemo
componentName="Divider"
data={[
{
propName: 'orientation',
knob: 'radio',
defaultValue: 'horizontal',
options: ['horizontal', 'vertical'],
},
{
propName: 'children',
knob: 'input',
defaultValue: '',
},
]}
renderDemo={(props) => (
<Sheet sx={{ my: 2, bgcolor: 'transparent' }}>
<Sheet
sx={{
height: 12,
width: 80,
borderRadius: 'lg',
mb: 1,
bgcolor: 'background.level3',
}}
/>
<Stack
direction={props.orientation === 'vertical' ? 'row' : 'column'}
spacing={2}
sx={{ width: 300, pb: 3 }}
>
<Sheet
sx={{
height: props.orientation === 'vertical' ? 120 : 40,
flexGrow: 1,
borderRadius: 'xs',
bgcolor: 'background.level3',
}}
/>
<Divider {...props} />
<Sheet
sx={{
height: props.orientation === 'vertical' ? 120 : 40,
flexGrow: 1,
borderRadius: 'xs',
bgcolor: 'background.level3',
}}
/>
</Stack>
</Sheet>
)}
/>
);
}
| 1,104 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/FullscreenOverflowDivider.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
import Checkbox from '@mui/joy/Checkbox';
export default function FullscreenOverflowDivider() {
const [shadow, setShadow] = React.useState(false);
const [clip, setClip] = React.useState(false);
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ width: '100%', overflow: 'hidden' }}>
<Box
sx={{
width: 200,
py: 5,
mx: 'auto',
border: '1px solid',
borderColor: 'success.300',
bgcolor: (theme) =>
`rgba(${theme.vars.palette.success.lightChannel} / 0.5)`,
}}
>
<Divider
sx={{
boxShadow: shadow
? '0 0 0 100vmax var(--Divider-lineColor)'
: 'initial',
clipPath: clip ? 'inset(0px -100vmax)' : 'initial',
}}
/>
</Box>
</Box>
<Box sx={{ display: 'flex', gap: 3, justifyContent: 'center', mt: 2 }}>
<Checkbox
label="box-shadow"
checked={shadow}
onChange={(event) => setShadow(event.target.checked)}
/>
<Checkbox
label="clip-path"
checked={clip}
onChange={(event) => setClip(event.target.checked)}
/>
</Box>
</Box>
);
}
| 1,105 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/FullscreenOverflowDivider.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
import Checkbox from '@mui/joy/Checkbox';
export default function FullscreenOverflowDivider() {
const [shadow, setShadow] = React.useState(false);
const [clip, setClip] = React.useState(false);
return (
<Box sx={{ width: '100%' }}>
<Box sx={{ width: '100%', overflow: 'hidden' }}>
<Box
sx={{
width: 200,
py: 5,
mx: 'auto',
border: '1px solid',
borderColor: 'success.300',
bgcolor: (theme) =>
`rgba(${theme.vars.palette.success.lightChannel} / 0.5)`,
}}
>
<Divider
sx={{
boxShadow: shadow
? '0 0 0 100vmax var(--Divider-lineColor)'
: 'initial',
clipPath: clip ? 'inset(0px -100vmax)' : 'initial',
}}
/>
</Box>
</Box>
<Box sx={{ display: 'flex', gap: 3, justifyContent: 'center', mt: 2 }}>
<Checkbox
label="box-shadow"
checked={shadow}
onChange={(event) => setShadow(event.target.checked)}
/>
<Checkbox
label="clip-path"
checked={clip}
onChange={(event) => setClip(event.target.checked)}
/>
</Box>
</Box>
);
}
| 1,106 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/VerticalDividerText.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Stack from '@mui/joy/Stack';
import Divider from '@mui/joy/Divider';
export default function VerticalDividerText() {
const content = (
<Box sx={{ fontSize: 'sm', color: 'text.tertiary' }}>
{`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id dignissim justo.
Nulla ut facilisis ligula. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Sed malesuada lobortis pretium.`}
</Box>
);
return (
<Stack spacing={2} direction="row">
{content}
<Divider orientation="vertical">Visual indicator</Divider>
{content}
</Stack>
);
}
| 1,107 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/VerticalDividerText.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Stack from '@mui/joy/Stack';
import Divider from '@mui/joy/Divider';
export default function VerticalDividerText() {
const content = (
<Box sx={{ fontSize: 'sm', color: 'text.tertiary' }}>
{`Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id dignissim justo.
Nulla ut facilisis ligula. Interdum et malesuada fames ac ante ipsum primis in faucibus.
Sed malesuada lobortis pretium.`}
</Box>
);
return (
<Stack spacing={2} direction="row">
{content}
<Divider orientation="vertical">Visual indicator</Divider>
{content}
</Stack>
);
}
| 1,108 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/VerticalDividerText.tsx.preview | {content}
<Divider orientation="vertical">Visual indicator</Divider>
{content} | 1,109 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/VerticalDividers.js | import * as React from 'react';
import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft';
import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter';
import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight';
import FormatBoldIcon from '@mui/icons-material/FormatBold';
import FormatItalicIcon from '@mui/icons-material/FormatItalic';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
export default function VerticalDividers() {
return (
<div>
<Box
sx={{
display: 'flex',
alignItems: 'center',
width: 'fit-content',
border: '1px solid',
borderColor: 'divider',
borderRadius: 'sm',
bgcolor: 'background.surface',
color: 'text.secondary',
'& svg': {
m: 1.5,
},
'& hr': {
mx: 0.5,
},
}}
>
<FormatAlignLeftIcon />
<FormatAlignCenterIcon />
<FormatAlignRightIcon />
<Divider orientation="vertical" />
<FormatBoldIcon />
<FormatItalicIcon />
</Box>
</div>
);
}
| 1,110 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/VerticalDividers.tsx | import * as React from 'react';
import FormatAlignLeftIcon from '@mui/icons-material/FormatAlignLeft';
import FormatAlignCenterIcon from '@mui/icons-material/FormatAlignCenter';
import FormatAlignRightIcon from '@mui/icons-material/FormatAlignRight';
import FormatBoldIcon from '@mui/icons-material/FormatBold';
import FormatItalicIcon from '@mui/icons-material/FormatItalic';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
export default function VerticalDividers() {
return (
<div>
<Box
sx={{
display: 'flex',
alignItems: 'center',
width: 'fit-content',
border: '1px solid',
borderColor: 'divider',
borderRadius: 'sm',
bgcolor: 'background.surface',
color: 'text.secondary',
'& svg': {
m: 1.5,
},
'& hr': {
mx: 0.5,
},
}}
>
<FormatAlignLeftIcon />
<FormatAlignCenterIcon />
<FormatAlignRightIcon />
<Divider orientation="vertical" />
<FormatBoldIcon />
<FormatItalicIcon />
</Box>
</div>
);
}
| 1,111 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/divider.md | ---
productId: joy-ui
title: React Divider component
components: Divider
githubLabel: 'component: divider'
---
# Divider
<p class="description">A divider is a thin line that groups content in lists and layouts.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
Dividers separate content into clear groups.
{{"demo": "DividerUsage.js", "hideToolbar": "true", "bg": "gradient"}}
## Component
After [installation](/joy-ui/getting-started/installation/), you can start building with this component using the following basic elements:
```jsx
import Divider from '@mui/joy/Divider';
export default function MyApp() {
return <Divider />;
}
```
### Rendered with content
Use the `Divider` to wrap elements that will be added to it.
{{"demo": "DividerText.js"}}
:::warning
When using the `Divider` component for visual decoration, such as in a heading, explicitly specify `role="presentation"` on it to make sure screen readers can announce its content:
```js
<Divider component="div" role="presentation">
{/* any elements nested inside the role="presentation" preserve their semantics. */}
</Divider>
```
:::
### Vertical divider
Use the `orientation` prop to render a vertical divider.
{{"demo": "VerticalDividers.js"}}
#### Vertical with text
You can also render a vertical divider with content.
{{"demo": "VerticalDividerText.js"}}
### Child position
To control the position of the content, override the CSS variable `--Divider-childPosition` via `sx` prop.
```js
<Divider sx={{ '--Divider-childPosition': '20%' }}> {/* the value can be any CSS valid unit */}
```
{{"demo": "DividerChildPosition.js"}}
## Automatic adjustment
When the `Divider` is a direct child of either a [Card](/joy-ui/react-card/) or [ModalDialog](/joy-ui/react-modal/#modal-dialog), it will automatically adapt to their spacing and orientation.
### Card
Note how the `Divider`stretches by default from edge to edge of the `Card`.
It will also adapt to the `Card` orientation.
{{"demo": "DividerInCard.js"}}
### ModalDialog
The same edge to edge stretching happens with the `ModalDialog` as well.
To opt-out from the automatic adjustment, use `inset="none"` on the divider.
{{"demo": "DividerInModalDialog.js"}}
## Common examples
### Fullscreen overflow
Here is a CSS trick that lets you stretch the divider outside of its parent's boundary.
Use `box-shadow` with `100vmax` unit to fill the outer space and then remove the vertical overflow by using `clip-path: inset(0px -100vmax)`.
{{"demo": "FullscreenOverflowDivider.js"}}
:::info
The `var(--Divider-lineColor)` is defined by the Divider component so you can refer to it without hard-coding the value or accessing to the theme.
:::
| 1,112 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerAnchor.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerAnchor() {
const [state, setState] = React.useState({
top: false,
left: false,
bottom: false,
right: false,
});
const toggleDrawer = (anchor, open) => (event) => {
if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
return;
}
setState({ ...state, [anchor]: open });
};
const list = (anchor) => (
<Box
role="presentation"
onClick={toggleDrawer(anchor, false)}
onKeyDown={toggleDrawer(anchor, false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
);
return (
<React.Fragment>
<ButtonGroup variant="outlined">
{['top', 'right', 'bottom', 'left'].map((anchor) => (
<Button key={anchor} onClick={toggleDrawer(anchor, true)}>
{anchor}
</Button>
))}
</ButtonGroup>
{['top', 'right', 'bottom', 'left'].map((anchor) => (
<Drawer
key={anchor}
anchor={anchor}
open={state[anchor]}
onClose={toggleDrawer(anchor, false)}
>
{list(anchor)}
</Drawer>
))}
</React.Fragment>
);
}
| 1,113 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerAnchor.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
type Anchor = 'top' | 'left' | 'bottom' | 'right';
export default function DrawerAnchor() {
const [state, setState] = React.useState({
top: false,
left: false,
bottom: false,
right: false,
});
const toggleDrawer =
(anchor: Anchor, open: boolean) =>
(event: React.KeyboardEvent | React.MouseEvent) => {
if (
event.type === 'keydown' &&
((event as React.KeyboardEvent).key === 'Tab' ||
(event as React.KeyboardEvent).key === 'Shift')
) {
return;
}
setState({ ...state, [anchor]: open });
};
const list = (anchor: Anchor) => (
<Box
role="presentation"
onClick={toggleDrawer(anchor, false)}
onKeyDown={toggleDrawer(anchor, false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
);
return (
<React.Fragment>
<ButtonGroup variant="outlined">
{(['top', 'right', 'bottom', 'left'] as const).map((anchor) => (
<Button key={anchor} onClick={toggleDrawer(anchor, true)}>
{anchor}
</Button>
))}
</ButtonGroup>
{(['top', 'right', 'bottom', 'left'] as const).map((anchor) => (
<Drawer
key={anchor}
anchor={anchor}
open={state[anchor]}
onClose={toggleDrawer(anchor, false)}
>
{list(anchor)}
</Drawer>
))}
</React.Fragment>
);
}
| 1,114 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerBasic.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerBasic() {
const [open, setOpen] = React.useState(false);
const toggleDrawer = (inOpen) => (event) => {
if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
return;
}
setOpen(inOpen);
};
return (
<Box sx={{ display: 'flex' }}>
<Button variant="outlined" color="neutral" onClick={toggleDrawer(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={toggleDrawer(false)}>
<Box
role="presentation"
onClick={toggleDrawer(false)}
onKeyDown={toggleDrawer(false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
</Drawer>
</Box>
);
}
| 1,115 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerBasic.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerBasic() {
const [open, setOpen] = React.useState(false);
const toggleDrawer =
(inOpen: boolean) => (event: React.KeyboardEvent | React.MouseEvent) => {
if (
event.type === 'keydown' &&
((event as React.KeyboardEvent).key === 'Tab' ||
(event as React.KeyboardEvent).key === 'Shift')
) {
return;
}
setOpen(inOpen);
};
return (
<Box sx={{ display: 'flex' }}>
<Button variant="outlined" color="neutral" onClick={toggleDrawer(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={toggleDrawer(false)}>
<Box
role="presentation"
onClick={toggleDrawer(false)}
onKeyDown={toggleDrawer(false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
</Drawer>
</Box>
);
}
| 1,116 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerCloseButton.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Drawer from '@mui/joy/Drawer';
import DialogTitle from '@mui/joy/DialogTitle';
import ModalClose from '@mui/joy/ModalClose';
export default function DrawerCloseButton() {
const [open, setOpen] = React.useState(false);
return (
<Box sx={{ display: 'flex' }}>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={() => setOpen(false)}>
<ModalClose />
<DialogTitle>Title</DialogTitle>
</Drawer>
</Box>
);
}
| 1,117 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerCloseButton.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Drawer from '@mui/joy/Drawer';
import DialogTitle from '@mui/joy/DialogTitle';
import ModalClose from '@mui/joy/ModalClose';
export default function DrawerCloseButton() {
const [open, setOpen] = React.useState(false);
return (
<Box sx={{ display: 'flex' }}>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={() => setOpen(false)}>
<ModalClose />
<DialogTitle>Title</DialogTitle>
</Drawer>
</Box>
);
}
| 1,118 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerCloseButton.tsx.preview | <Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={() => setOpen(false)}>
<ModalClose />
<DialogTitle>Title</DialogTitle>
</Drawer> | 1,119 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerFilters.js | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import Card from '@mui/joy/Card';
import CardContent from '@mui/joy/CardContent';
import Checkbox from '@mui/joy/Checkbox';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import ModalClose from '@mui/joy/ModalClose';
import Divider from '@mui/joy/Divider';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Stack from '@mui/joy/Stack';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import Switch from '@mui/joy/Switch';
import Typography from '@mui/joy/Typography';
import TuneIcon from '@mui/icons-material/TuneRounded';
import HomeRoundedIcon from '@mui/icons-material/HomeRounded';
import ApartmentRoundedIcon from '@mui/icons-material/ApartmentRounded';
import MeetingRoomRoundedIcon from '@mui/icons-material/MeetingRoomRounded';
import HotelRoundedIcon from '@mui/icons-material/HotelRounded';
import Done from '@mui/icons-material/Done';
export default function DrawerFilters() {
const [open, setOpen] = React.useState(false);
const [type, setType] = React.useState('Guesthouse');
const [amenities, setAmenities] = React.useState([0, 6]);
return (
<React.Fragment>
<Button
variant="outlined"
color="neutral"
startDecorator={<TuneIcon />}
onClick={() => setOpen(true)}
>
Change filters
</Button>
<Drawer
size="md"
variant="plain"
open={open}
onClose={() => setOpen(false)}
slotProps={{
content: {
sx: {
bgcolor: 'transparent',
p: { md: 3, sm: 0 },
boxShadow: 'none',
},
},
}}
>
<Sheet
sx={{
borderRadius: 'md',
p: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
height: '100%',
overflow: 'auto',
}}
>
<DialogTitle>Filters</DialogTitle>
<ModalClose />
<Divider sx={{ mt: 'auto' }} />
<DialogContent sx={{ gap: 2 }}>
<FormControl>
<FormLabel sx={{ typography: 'title-md', fontWeight: 'bold' }}>
Property type
</FormLabel>
<RadioGroup
value={type || ''}
onChange={(event) => {
setType(event.target.value);
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))',
gap: 1.5,
}}
>
{[
{
name: 'House',
icon: <HomeRoundedIcon />,
},
{
name: 'Apartment',
icon: <ApartmentRoundedIcon />,
},
{
name: 'Guesthouse',
icon: <MeetingRoomRoundedIcon />,
},
{
name: 'Hotel',
icon: <HotelRoundedIcon />,
},
].map((item) => (
<Card
key={item.name}
sx={{
boxShadow: 'none',
'&:hover': { bgcolor: 'background.level1' },
}}
>
<CardContent>
{item.icon}
<Typography level="title-md">{item.name}</Typography>
</CardContent>
<Radio
disableIcon
overlay
checked={type === item.name}
variant="outlined"
color="neutral"
value={item.name}
sx={{ mt: -2 }}
slotProps={{
action: {
sx: {
...(type === item.name && {
borderWidth: 2,
borderColor:
'var(--joy-palette-primary-outlinedBorder)',
}),
'&:hover': {
bgcolor: 'transparent',
},
},
},
}}
/>
</Card>
))}
</Box>
</RadioGroup>
</FormControl>
<Typography level="title-md" fontWeight="bold" sx={{ mt: 1 }}>
Amenities
</Typography>
<div role="group" aria-labelledby="rank">
<List
orientation="horizontal"
size="sm"
sx={{
'--List-gap': '12px',
'--ListItem-radius': '20px',
}}
>
{['Wi-fi', 'Washer', 'A/C', 'Kitchen'].map((item, index) => {
const selected = amenities.includes(index);
return (
<ListItem key={item}>
<AspectRatio
variant={selected ? 'solid' : 'outlined'}
color={selected ? 'primary' : 'neutral'}
ratio={1}
sx={{ width: 20, borderRadius: 20, ml: -0.5, mr: 0.75 }}
>
<div>{selected && <Done fontSize="md" />}</div>
</AspectRatio>
<Checkbox
size="sm"
color="neutral"
disableIcon
overlay
label={item}
variant="outlined"
checked={selected}
onChange={(event) =>
setAmenities((prev) => {
const set = new Set([...prev, index]);
if (!event.target.checked) {
set.delete(index);
}
return [...set];
})
}
slotProps={{
action: {
sx: {
'&:hover': {
bgcolor: 'transparent',
},
},
},
}}
/>
</ListItem>
);
})}
</List>
</div>
<Typography level="title-md" fontWeight="bold" sx={{ mt: 2 }}>
Booking options
</Typography>
<FormControl orientation="horizontal">
<Box sx={{ flex: 1, pr: 1 }}>
<FormLabel sx={{ typography: 'title-sm' }}>
Instant booking
</FormLabel>
<FormHelperText sx={{ typography: 'body-sm' }}>
Listings that you can book without waiting for host approval.
</FormHelperText>
</Box>
<Switch />
</FormControl>
<FormControl orientation="horizontal">
<Box sx={{ flex: 1, mt: 1, mr: 1 }}>
<FormLabel sx={{ typography: 'title-sm' }}>Self check-in</FormLabel>
<FormHelperText sx={{ typography: 'body-sm' }}>
Easy access to the property when you arrive.
</FormHelperText>
</Box>
<Switch />
</FormControl>
</DialogContent>
<Divider sx={{ mt: 'auto' }} />
<Stack
direction="row"
justifyContent="space-between"
useFlexGap
spacing={1}
>
<Button
variant="outlined"
color="neutral"
onClick={() => {
setType('');
setAmenities([]);
}}
>
Clear
</Button>
<Button onClick={() => setOpen(false)}>Show 165 properties</Button>
</Stack>
</Sheet>
</Drawer>
</React.Fragment>
);
}
| 1,120 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerFilters.tsx | import * as React from 'react';
import AspectRatio from '@mui/joy/AspectRatio';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import Card from '@mui/joy/Card';
import CardContent from '@mui/joy/CardContent';
import Checkbox from '@mui/joy/Checkbox';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import ModalClose from '@mui/joy/ModalClose';
import Divider from '@mui/joy/Divider';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Stack from '@mui/joy/Stack';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import Switch from '@mui/joy/Switch';
import Typography from '@mui/joy/Typography';
import TuneIcon from '@mui/icons-material/TuneRounded';
import HomeRoundedIcon from '@mui/icons-material/HomeRounded';
import ApartmentRoundedIcon from '@mui/icons-material/ApartmentRounded';
import MeetingRoomRoundedIcon from '@mui/icons-material/MeetingRoomRounded';
import HotelRoundedIcon from '@mui/icons-material/HotelRounded';
import Done from '@mui/icons-material/Done';
export default function DrawerFilters() {
const [open, setOpen] = React.useState(false);
const [type, setType] = React.useState('Guesthouse');
const [amenities, setAmenities] = React.useState([0, 6]);
return (
<React.Fragment>
<Button
variant="outlined"
color="neutral"
startDecorator={<TuneIcon />}
onClick={() => setOpen(true)}
>
Change filters
</Button>
<Drawer
size="md"
variant="plain"
open={open}
onClose={() => setOpen(false)}
slotProps={{
content: {
sx: {
bgcolor: 'transparent',
p: { md: 3, sm: 0 },
boxShadow: 'none',
},
},
}}
>
<Sheet
sx={{
borderRadius: 'md',
p: 2,
display: 'flex',
flexDirection: 'column',
gap: 2,
height: '100%',
overflow: 'auto',
}}
>
<DialogTitle>Filters</DialogTitle>
<ModalClose />
<Divider sx={{ mt: 'auto' }} />
<DialogContent sx={{ gap: 2 }}>
<FormControl>
<FormLabel sx={{ typography: 'title-md', fontWeight: 'bold' }}>
Property type
</FormLabel>
<RadioGroup
value={type || ''}
onChange={(event) => {
setType(event.target.value);
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))',
gap: 1.5,
}}
>
{[
{
name: 'House',
icon: <HomeRoundedIcon />,
},
{
name: 'Apartment',
icon: <ApartmentRoundedIcon />,
},
{
name: 'Guesthouse',
icon: <MeetingRoomRoundedIcon />,
},
{
name: 'Hotel',
icon: <HotelRoundedIcon />,
},
].map((item) => (
<Card
key={item.name}
sx={{
boxShadow: 'none',
'&:hover': { bgcolor: 'background.level1' },
}}
>
<CardContent>
{item.icon}
<Typography level="title-md">{item.name}</Typography>
</CardContent>
<Radio
disableIcon
overlay
checked={type === item.name}
variant="outlined"
color="neutral"
value={item.name}
sx={{ mt: -2 }}
slotProps={{
action: {
sx: {
...(type === item.name && {
borderWidth: 2,
borderColor:
'var(--joy-palette-primary-outlinedBorder)',
}),
'&:hover': {
bgcolor: 'transparent',
},
},
},
}}
/>
</Card>
))}
</Box>
</RadioGroup>
</FormControl>
<Typography level="title-md" fontWeight="bold" sx={{ mt: 1 }}>
Amenities
</Typography>
<div role="group" aria-labelledby="rank">
<List
orientation="horizontal"
size="sm"
sx={{
'--List-gap': '12px',
'--ListItem-radius': '20px',
}}
>
{['Wi-fi', 'Washer', 'A/C', 'Kitchen'].map((item, index) => {
const selected = amenities.includes(index);
return (
<ListItem key={item}>
<AspectRatio
variant={selected ? 'solid' : 'outlined'}
color={selected ? 'primary' : 'neutral'}
ratio={1}
sx={{ width: 20, borderRadius: 20, ml: -0.5, mr: 0.75 }}
>
<div>{selected && <Done fontSize="md" />}</div>
</AspectRatio>
<Checkbox
size="sm"
color="neutral"
disableIcon
overlay
label={item}
variant="outlined"
checked={selected}
onChange={(event) =>
setAmenities((prev) => {
const set = new Set([...prev, index]);
if (!event.target.checked) {
set.delete(index);
}
// @ts-ignore
return [...set];
})
}
slotProps={{
action: {
sx: {
'&:hover': {
bgcolor: 'transparent',
},
},
},
}}
/>
</ListItem>
);
})}
</List>
</div>
<Typography level="title-md" fontWeight="bold" sx={{ mt: 2 }}>
Booking options
</Typography>
<FormControl orientation="horizontal">
<Box sx={{ flex: 1, pr: 1 }}>
<FormLabel sx={{ typography: 'title-sm' }}>
Instant booking
</FormLabel>
<FormHelperText sx={{ typography: 'body-sm' }}>
Listings that you can book without waiting for host approval.
</FormHelperText>
</Box>
<Switch />
</FormControl>
<FormControl orientation="horizontal">
<Box sx={{ flex: 1, mt: 1, mr: 1 }}>
<FormLabel sx={{ typography: 'title-sm' }}>Self check-in</FormLabel>
<FormHelperText sx={{ typography: 'body-sm' }}>
Easy access to the property when you arrive.
</FormHelperText>
</Box>
<Switch />
</FormControl>
</DialogContent>
<Divider sx={{ mt: 'auto' }} />
<Stack
direction="row"
justifyContent="space-between"
useFlexGap
spacing={1}
>
<Button
variant="outlined"
color="neutral"
onClick={() => {
setType('');
setAmenities([]);
}}
>
Clear
</Button>
<Button onClick={() => setOpen(false)}>Show 165 properties</Button>
</Stack>
</Sheet>
</Drawer>
</React.Fragment>
);
}
| 1,121 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerMobileNavigation.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import IconButton from '@mui/joy/IconButton';
import Drawer from '@mui/joy/Drawer';
import Input from '@mui/joy/Input';
import List from '@mui/joy/List';
import ListItemButton from '@mui/joy/ListItemButton';
import Typography from '@mui/joy/Typography';
import ModalClose from '@mui/joy/ModalClose';
import Menu from '@mui/icons-material/Menu';
import Search from '@mui/icons-material/Search';
export default function DrawerMobileNavigation() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<IconButton variant="outlined" color="neutral" onClick={() => setOpen(true)}>
<Menu />
</IconButton>
<Drawer open={open} onClose={() => setOpen(false)}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 0.5,
ml: 'auto',
mt: 1,
mr: 2,
}}
>
<Typography
component="label"
htmlFor="close-icon"
fontSize="sm"
fontWeight="lg"
sx={{ cursor: 'pointer' }}
>
Close
</Typography>
<ModalClose id="close-icon" sx={{ position: 'initial' }} />
</Box>
<Input
size="sm"
placeholder="Search"
variant="plain"
endDecorator={<Search />}
slotProps={{
input: {
'aria-label': 'Search anything',
},
}}
sx={{
m: 3,
borderRadius: 0,
borderBottom: '2px solid',
borderColor: 'neutral.outlinedBorder',
'&:hover': {
borderColor: 'neutral.outlinedHoverBorder',
},
'&::before': {
border: '1px solid var(--Input-focusedHighlight)',
transform: 'scaleX(0)',
left: 0,
right: 0,
bottom: '-2px',
top: 'unset',
transition: 'transform .15s cubic-bezier(0.1,0.9,0.2,1)',
borderRadius: 0,
},
'&:focus-within::before': {
transform: 'scaleX(1)',
},
}}
/>
<List
size="lg"
component="nav"
sx={{
flex: 'none',
fontSize: 'xl',
'& > div': { justifyContent: 'center' },
}}
>
<ListItemButton sx={{ fontWeight: 'lg' }}>Home</ListItemButton>
<ListItemButton>About</ListItemButton>
<ListItemButton>Studio</ListItemButton>
<ListItemButton>Contact</ListItemButton>
</List>
</Drawer>
</React.Fragment>
);
}
| 1,122 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerMobileNavigation.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import IconButton from '@mui/joy/IconButton';
import Drawer from '@mui/joy/Drawer';
import Input from '@mui/joy/Input';
import List from '@mui/joy/List';
import ListItemButton from '@mui/joy/ListItemButton';
import Typography from '@mui/joy/Typography';
import ModalClose from '@mui/joy/ModalClose';
import Menu from '@mui/icons-material/Menu';
import Search from '@mui/icons-material/Search';
export default function DrawerMobileNavigation() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<IconButton variant="outlined" color="neutral" onClick={() => setOpen(true)}>
<Menu />
</IconButton>
<Drawer open={open} onClose={() => setOpen(false)}>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 0.5,
ml: 'auto',
mt: 1,
mr: 2,
}}
>
<Typography
component="label"
htmlFor="close-icon"
fontSize="sm"
fontWeight="lg"
sx={{ cursor: 'pointer' }}
>
Close
</Typography>
<ModalClose id="close-icon" sx={{ position: 'initial' }} />
</Box>
<Input
size="sm"
placeholder="Search"
variant="plain"
endDecorator={<Search />}
slotProps={{
input: {
'aria-label': 'Search anything',
},
}}
sx={{
m: 3,
borderRadius: 0,
borderBottom: '2px solid',
borderColor: 'neutral.outlinedBorder',
'&:hover': {
borderColor: 'neutral.outlinedHoverBorder',
},
'&::before': {
border: '1px solid var(--Input-focusedHighlight)',
transform: 'scaleX(0)',
left: 0,
right: 0,
bottom: '-2px',
top: 'unset',
transition: 'transform .15s cubic-bezier(0.1,0.9,0.2,1)',
borderRadius: 0,
},
'&:focus-within::before': {
transform: 'scaleX(1)',
},
}}
/>
<List
size="lg"
component="nav"
sx={{
flex: 'none',
fontSize: 'xl',
'& > div': { justifyContent: 'center' },
}}
>
<ListItemButton sx={{ fontWeight: 'lg' }}>Home</ListItemButton>
<ListItemButton>About</ListItemButton>
<ListItemButton>Studio</ListItemButton>
<ListItemButton>Contact</ListItemButton>
</List>
</Drawer>
</React.Fragment>
);
}
| 1,123 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerScrollable.js | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Drawer from '@mui/joy/Drawer';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
import Typography from '@mui/joy/Typography';
import ModalClose from '@mui/joy/ModalClose';
export default function DrawerScrollable() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={() => setOpen(false)}>
<ModalClose />
<DialogTitle>Title</DialogTitle>
<DialogContent>
<List>
{[...new Array(100)].map((_, index) => (
<ListItem key={index}>
<ListItemButton onClick={() => setOpen(false)}>
Item {index}
</ListItemButton>
</ListItem>
))}
</List>
</DialogContent>
<Box
sx={{
display: 'flex',
gap: 1,
p: 1.5,
pb: 2,
borderTop: '1px solid',
borderColor: 'divider',
}}
>
<Avatar size="lg" />
<div>
<Typography level="title-md">Username</Typography>
<Typography level="body-sm">joined 20 Jun 2023</Typography>
</div>
</Box>
</Drawer>
</React.Fragment>
);
}
| 1,124 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerScrollable.tsx | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Drawer from '@mui/joy/Drawer';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
import Typography from '@mui/joy/Typography';
import ModalClose from '@mui/joy/ModalClose';
export default function DrawerScrollable() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={() => setOpen(false)}>
<ModalClose />
<DialogTitle>Title</DialogTitle>
<DialogContent>
<List>
{[...new Array(100)].map((_, index) => (
<ListItem key={index}>
<ListItemButton onClick={() => setOpen(false)}>
Item {index}
</ListItemButton>
</ListItem>
))}
</List>
</DialogContent>
<Box
sx={{
display: 'flex',
gap: 1,
p: 1.5,
pb: 2,
borderTop: '1px solid',
borderColor: 'divider',
}}
>
<Avatar size="lg" />
<div>
<Typography level="title-md">Username</Typography>
<Typography level="body-sm">joined 20 Jun 2023</Typography>
</div>
</Box>
</Drawer>
</React.Fragment>
);
}
| 1,125 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerSize.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerSize() {
const [state, setState] = React.useState({
sm: false,
md: false,
lg: false,
});
const toggleDrawer = (size, open) => (event) => {
if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
return;
}
setState({ ...state, [size]: open });
};
const list = (size) => (
<Box
role="presentation"
onClick={toggleDrawer(size, false)}
onKeyDown={toggleDrawer(size, false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
);
return (
<React.Fragment>
<ButtonGroup variant="outlined">
{['sm', 'md', 'lg'].map((size) => (
<Button key={size} onClick={toggleDrawer(size, true)}>
{size}
</Button>
))}
</ButtonGroup>
{['sm', 'md', 'lg'].map((size) => (
<Drawer
key={size}
size={size}
open={state[size]}
onClose={toggleDrawer(size, false)}
>
{list(size)}
</Drawer>
))}
</React.Fragment>
);
}
| 1,126 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerSize.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import ButtonGroup from '@mui/joy/ButtonGroup';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
type Size = 'sm' | 'md' | 'lg';
export default function DrawerSize() {
const [state, setState] = React.useState({
sm: false,
md: false,
lg: false,
});
const toggleDrawer =
(size: Size, open: boolean) =>
(event: React.KeyboardEvent | React.MouseEvent) => {
if (
event.type === 'keydown' &&
((event as React.KeyboardEvent).key === 'Tab' ||
(event as React.KeyboardEvent).key === 'Shift')
) {
return;
}
setState({ ...state, [size]: open });
};
const list = (size: Size) => (
<Box
role="presentation"
onClick={toggleDrawer(size, false)}
onKeyDown={toggleDrawer(size, false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
);
return (
<React.Fragment>
<ButtonGroup variant="outlined">
{(['sm', 'md', 'lg'] as const).map((size) => (
<Button key={size} onClick={toggleDrawer(size, true)}>
{size}
</Button>
))}
</ButtonGroup>
{(['sm', 'md', 'lg'] as const).map((size) => (
<Drawer
key={size}
size={size}
open={state[size]}
onClose={toggleDrawer(size, false)}
>
{list(size)}
</Drawer>
))}
</React.Fragment>
);
}
| 1,127 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerTransition.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerTransition() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer
open={open}
onClose={() => setOpen(false)}
sx={{
'--Drawer-transitionDuration': open ? '0.4s' : '0.2s',
'--Drawer-transitionFunction': open
? 'cubic-bezier(0.79,0.14,0.15,0.86)'
: 'cubic-bezier(0.77,0,0.18,1)',
}}
>
<Box role="presentation" sx={{ p: 2 }}>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
</Drawer>
</React.Fragment>
);
}
| 1,128 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerTransition.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import Button from '@mui/joy/Button';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
export default function DrawerTransition() {
const [open, setOpen] = React.useState(false);
return (
<React.Fragment>
<Button variant="outlined" color="neutral" onClick={() => setOpen(true)}>
Open drawer
</Button>
<Drawer
open={open}
onClose={() => setOpen(false)}
sx={{
'--Drawer-transitionDuration': open ? '0.4s' : '0.2s',
'--Drawer-transitionFunction': open
? 'cubic-bezier(0.79,0.14,0.15,0.86)'
: 'cubic-bezier(0.77,0,0.18,1)',
}}
>
<Box role="presentation" sx={{ p: 2 }}>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text) => (
<ListItem key={text}>
<ListItemButton>{text}</ListItemButton>
</ListItem>
))}
</List>
</Box>
</Drawer>
</React.Fragment>
);
}
| 1,129 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/DrawerUsage.js | import * as React from 'react';
import Button from '@mui/joy/Button';
import Box from '@mui/joy/Box';
import Drawer from '@mui/joy/Drawer';
import List from '@mui/joy/List';
import Divider from '@mui/joy/Divider';
import ListItem from '@mui/joy/ListItem';
import ListItemButton from '@mui/joy/ListItemButton';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import ListItemContent from '@mui/joy/ListItemContent';
import InboxIcon from '@mui/icons-material/MoveToInbox';
import MailIcon from '@mui/icons-material/Mail';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function DrawerUsage() {
const [open, setOpen] = React.useState(false);
const toggleDrawer = (value) => (event) => {
if (event.type === 'keydown' && (event.key === 'Tab' || event.key === 'Shift')) {
return;
}
setOpen(value);
};
return (
<JoyUsageDemo
componentName="Drawer"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'plain',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
},
{
propName: 'anchor',
knob: 'radio',
defaultValue: 'left',
options: ['left', 'top', 'right', 'bottom'],
},
{
propName: 'size',
knob: 'radio',
defaultValue: 'md',
options: ['sm', 'md', 'lg'],
},
{
propName: 'invertedColors',
knob: 'switch',
},
{
propName: 'children',
defaultValue: '{/* Drawer content */}',
},
]}
renderDemo={(props) => (
<React.Fragment>
<Button variant="outlined" color="neutral" onClick={toggleDrawer(true)}>
Open drawer
</Button>
<Drawer open={open} onClose={toggleDrawer(false)} {...props}>
<Box
role="presentation"
onClick={toggleDrawer(false)}
onKeyDown={toggleDrawer(false)}
>
<List>
{['Inbox', 'Starred', 'Send email', 'Drafts'].map((text, index) => (
<ListItem key={text}>
<ListItemButton>
<ListItemDecorator>
{index === 0 && <InboxIcon />}
</ListItemDecorator>
<ListItemContent>{text}</ListItemContent>
</ListItemButton>
</ListItem>
))}
</List>
<Divider />
<List>
{['All mail', 'Trash', 'Spam'].map((text, index) => (
<ListItem key={text}>
<ListItemButton>
<ListItemDecorator>
{index === 0 && <MailIcon />}
</ListItemDecorator>
<ListItemContent>{text}</ListItemContent>
</ListItemButton>
</ListItem>
))}
</List>
</Box>
</Drawer>
</React.Fragment>
)}
/>
);
}
| 1,130 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/drawer/drawer.md | ---
productId: joy-ui
title: React Drawer component
components: Drawer, ModalClose, DialogContent
githubLabel: 'component: drawer'
---
# Drawer
<p class="description">Navigation drawers provide quick access to other areas of an app without taking the user away from their current location.</p>
## Introduction
Drawers are commonly used as menus for desktop navigation, and as dialogs on mobile devices (similar to [Apple's sheets](https://developer.apple.com/design/human-interface-guidelines/sheets)).
{{"demo": "DrawerUsage.js", "hideToolbar": true, "bg": "gradient"}}
## Basics
```jsx
import Drawer from '@mui/joy/Drawer';
```
The Drawer will close after the user makes a selection, clicks anywhere outside of it, or presses the <kbd class="key">Esc</kbd> key.
Use the `open` prop to control the toggling of the Drawer's open and close states, as shown in the demo below:
{{"demo": "DrawerBasic.js"}}
## Customization
### Anchor
Use the `anchor` prop to specify which side of the screen the Drawer should originate from.
The default value is `left`.
{{"demo": "DrawerAnchor.js"}}
### Size
Use the `size` prop to adjust the Drawer's width (when anchored to the left or right) or height (when anchored to the top or bottom).
{{"demo": "DrawerSize.js"}}
### Close button
Use the Modal Close component to add a close button to the Drawer that automatically handles the `onClick` event.
```jsx
import ModalClose from '@mui/joy/ModalClose';
```
{{"demo": "DrawerCloseButton.js"}}
### Transition
Customize the Drawer's opening transition by using the CSS variables below inside the [`sx` prop](/system/getting-started/the-sx-prop/):
- `--Drawer-transitionFunction`: the [transition function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function); default is `ease`.
- `--Drawer-transitionDuration`: the [duration of the transition](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-duration); default is `0.3s`.
{{"demo": "DrawerTransition.js"}}
### Scrollable content
Use the Dialog Content component to create a scrollable container inside the Drawer.
```jsx
import DialogContent from '@mui/joy/DialogContent';
```
{{"demo": "DrawerScrollable.js"}}
## Common examples
### Mobile navigation
A common use case for the Drawer is to build mobile-friendly navigation menus:
{{"demo": "DrawerMobileNavigation.js"}}
### Inset drawer
An inset drawer is a panel that's not anchored to any edge of the screen.
You can achieve this by applying background and padding values to the Drawer component, and using either a Box or [Sheet](/joy-ui/react-sheet/) component for a full-height wrapper, as shown below:
{{"demo": "DrawerFilters.js"}}
| 1,131 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/AutoGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function AutoGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
);
}
| 1,132 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/AutoGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function AutoGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
);
}
| 1,133 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/AutoGrid.tsx.preview | <Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs>
<Item>xs</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid> | 1,134 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/BasicGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function BasicGrid() {
return (
<Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
);
}
| 1,135 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/BasicGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function BasicGrid() {
return (
<Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
);
}
| 1,136 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/BasicGrid.tsx.preview | <Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={4}>
<Item>xs=4</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid> | 1,137 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/CSSGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Box from '@mui/joy/Box';
import Sheet from '@mui/joy/Sheet';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function CSSGrid() {
return (
<Box sx={{ width: 1 }}>
<Box display="grid" gridTemplateColumns="repeat(12, 1fr)" gap={2}>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
</Box>
</Box>
);
}
| 1,138 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/CSSGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Box from '@mui/joy/Box';
import Sheet from '@mui/joy/Sheet';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function CSSGrid() {
return (
<Box sx={{ width: 1 }}>
<Box display="grid" gridTemplateColumns="repeat(12, 1fr)" gap={2}>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
</Box>
</Box>
);
}
| 1,139 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/CSSGrid.tsx.preview | <Box display="grid" gridTemplateColumns="repeat(12, 1fr)" gap={2}>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 4">
<Item>xs=4</Item>
</Box>
<Box gridColumn="span 8">
<Item>xs=8</Item>
</Box>
</Box> | 1,140 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ChildrenCenteredGrid.js | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Grid from '@mui/joy/Grid';
import Typography from '@mui/joy/Typography';
export default function ChildrenCenteredGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid
container
spacing={2}
sx={{
'--Grid-borderWidth': '1px',
borderTop: 'var(--Grid-borderWidth) solid',
borderLeft: 'var(--Grid-borderWidth) solid',
borderColor: 'divider',
'& > div': {
borderRight: 'var(--Grid-borderWidth) solid',
borderBottom: 'var(--Grid-borderWidth) solid',
borderColor: 'divider',
},
}}
>
{['Jimmy', 'Michal', 'Jun', 'Marija'].map((name, index) => (
<Grid
key={name}
xs={12}
sm={6}
md={3}
display="flex"
justifyContent="center"
alignItems="center"
minHeight={180}
>
<Avatar src={`/static/images/avatar/${index + 1}.jpg`} size="lg" />
<Typography sx={{ ml: 1.5 }}>{name}</Typography>
</Grid>
))}
</Grid>
</Box>
);
}
| 1,141 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ChildrenCenteredGrid.tsx | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Grid from '@mui/joy/Grid';
import Typography from '@mui/joy/Typography';
export default function ChildrenCenteredGrid() {
return (
<Box sx={{ flexGrow: 1 }}>
<Grid
container
spacing={2}
sx={{
'--Grid-borderWidth': '1px',
borderTop: 'var(--Grid-borderWidth) solid',
borderLeft: 'var(--Grid-borderWidth) solid',
borderColor: 'divider',
'& > div': {
borderRight: 'var(--Grid-borderWidth) solid',
borderBottom: 'var(--Grid-borderWidth) solid',
borderColor: 'divider',
},
}}
>
{['Jimmy', 'Michal', 'Jun', 'Marija'].map((name, index) => (
<Grid
key={name}
xs={12}
sm={6}
md={3}
display="flex"
justifyContent="center"
alignItems="center"
minHeight={180}
>
<Avatar src={`/static/images/avatar/${index + 1}.jpg`} size="lg" />
<Typography sx={{ ml: 1.5 }}>{name}</Typography>
</Grid>
))}
</Grid>
</Box>
);
}
| 1,142 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ColumnsGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function ColumnsGrid() {
return (
<Grid container spacing={2} columns={16} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
);
}
| 1,143 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ColumnsGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function ColumnsGrid() {
return (
<Grid container spacing={2} columns={16} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid>
);
}
| 1,144 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ColumnsGrid.tsx.preview | <Grid container spacing={2} columns={16} sx={{ flexGrow: 1 }}>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
<Grid xs={8}>
<Item>xs=8</Item>
</Grid>
</Grid> | 1,145 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/FullWidthGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function FullWidthGrid() {
return (
<Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid>
);
}
| 1,146 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/FullWidthGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function FullWidthGrid() {
return (
<Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid>
);
}
| 1,147 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/FullWidthGrid.tsx.preview | <Grid container spacing={2} sx={{ flexGrow: 1 }}>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={4}>
<Item>xs=6 md=4</Item>
</Grid>
<Grid xs={6} md={8}>
<Item>xs=6 md=8</Item>
</Grid>
</Grid> | 1,148 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/InteractiveGrid.js | import * as React from 'react';
import Grid from '@mui/joy/Grid';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import BrandingProvider from 'docs/src/BrandingProvider';
import HighlightedCode from 'docs/src/modules/components/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 = `
<Grid
container
direction="${direction}"
justifyContent="${justifyContent}"
alignItems="${alignItems}"
>
`;
return (
<Grid sx={{ flexGrow: 1 }} container>
<Grid xs={12}>
<Grid
sx={{ height: 300, pt: 2, pb: 2 }}
container
spacing={2}
alignItems={alignItems}
direction={direction}
justifyContent={justifyContent}
>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Sheet
sx={{
p: 2,
height: '100%',
pt: `${(value + 1) * 10}px`,
pb: `${(value + 1) * 10}px`,
}}
>
{`Cell ${value + 1}`}
</Sheet>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Sheet sx={{ p: 2 }}>
<Grid container spacing={3}>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>direction</FormLabel>
<RadioGroup
orientation="horizontal"
name="direction"
aria-label="direction"
value={direction}
onChange={(event) => {
setDirection(event.target.value);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="row" value="row" />
<Radio label="row-reverse" value="row-reverse" />
<Radio label="column" value="column" />
<Radio label="column-reverse" value="column-reverse" />
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>justifyContent</FormLabel>
<RadioGroup
orientation="horizontal"
name="justifyContent"
aria-label="justifyContent"
value={justifyContent}
onChange={(event) => {
setJustifyContent(event.target.value);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="flex-start" value="flex-start" />
<Radio label="center" value="center" />
<Radio label="flex-end" value="flex-end" />
<Radio label="space-between" value="space-between" />
<Radio label="space-around" value="space-around" />
<Radio label="space-evenly" value="space-evenly" />
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>alignItems</FormLabel>
<RadioGroup
orientation="horizontal"
name="alignItems"
aria-label="align items"
value={alignItems}
onChange={(event) => {
setAlignItems(event.target.value);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="flex-start" value="flex-start" />
<Radio label="center" value="center" />
<Radio label="flex-end" value="flex-end" />
<Radio label="stretch" value="stretch" />
<Radio label="baseline" value="baseline" />
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Sheet>
</Grid>
<Grid xs={12}>
<BrandingProvider mode="dark">
<HighlightedCode code={jsx} language="jsx" />
</BrandingProvider>
</Grid>
</Grid>
);
}
| 1,149 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/InteractiveGrid.tsx | import * as React from 'react';
import Grid from '@mui/joy/Grid';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import { GridDirection } from '@mui/system';
import BrandingProvider from 'docs/src/BrandingProvider';
import HighlightedCode from 'docs/src/modules/components/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<GridDirection>('row');
const [justifyContent, setJustifyContent] =
React.useState<GridJustification>('center');
const [alignItems, setAlignItems] = React.useState<GridItemsAlignment>('center');
const jsx = `
<Grid
container
direction="${direction}"
justifyContent="${justifyContent}"
alignItems="${alignItems}"
>
`;
return (
<Grid sx={{ flexGrow: 1 }} container>
<Grid xs={12}>
<Grid
sx={{ height: 300, pt: 2, pb: 2 }}
container
spacing={2}
alignItems={alignItems}
direction={direction}
justifyContent={justifyContent}
>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Sheet
sx={{
p: 2,
height: '100%',
pt: `${(value + 1) * 10}px`,
pb: `${(value + 1) * 10}px`,
}}
>
{`Cell ${value + 1}`}
</Sheet>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Sheet sx={{ p: 2 }}>
<Grid container spacing={3}>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>direction</FormLabel>
<RadioGroup
orientation="horizontal"
name="direction"
aria-label="direction"
value={direction}
onChange={(event) => {
setDirection(
(event.target as HTMLInputElement).value as GridDirection,
);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="row" value="row" />
<Radio label="row-reverse" value="row-reverse" />
<Radio label="column" value="column" />
<Radio label="column-reverse" value="column-reverse" />
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>justifyContent</FormLabel>
<RadioGroup
orientation="horizontal"
name="justifyContent"
aria-label="justifyContent"
value={justifyContent}
onChange={(event) => {
setJustifyContent(
(event.target as HTMLInputElement).value as GridJustification,
);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="flex-start" value="flex-start" />
<Radio label="center" value="center" />
<Radio label="flex-end" value="flex-end" />
<Radio label="space-between" value="space-between" />
<Radio label="space-around" value="space-around" />
<Radio label="space-evenly" value="space-evenly" />
</RadioGroup>
</FormControl>
</Grid>
<Grid xs={12}>
<FormControl>
<FormLabel sx={{ mb: 1.5 }}>alignItems</FormLabel>
<RadioGroup
orientation="horizontal"
name="alignItems"
aria-label="align items"
value={alignItems}
onChange={(event) => {
setAlignItems(
(event.target as HTMLInputElement).value as GridItemsAlignment,
);
}}
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
<Radio label="flex-start" value="flex-start" />
<Radio label="center" value="center" />
<Radio label="flex-end" value="flex-end" />
<Radio label="stretch" value="stretch" />
<Radio label="baseline" value="baseline" />
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Sheet>
</Grid>
<Grid xs={12}>
<BrandingProvider mode="dark">
<HighlightedCode code={jsx} language="jsx" />
</BrandingProvider>
</Grid>
</Grid>
);
}
| 1,150 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ResponsiveGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function ResponsiveGrid() {
return (
<Grid
container
spacing={{ xs: 2, md: 3 }}
columns={{ xs: 4, sm: 8, md: 12 }}
sx={{ flexGrow: 1 }}
>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} md={4} key={index}>
<Item>xs=2</Item>
</Grid>
))}
</Grid>
);
}
| 1,151 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ResponsiveGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function ResponsiveGrid() {
return (
<Grid
container
spacing={{ xs: 2, md: 3 }}
columns={{ xs: 4, sm: 8, md: 12 }}
sx={{ flexGrow: 1 }}
>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} md={4} key={index}>
<Item>xs=2</Item>
</Grid>
))}
</Grid>
);
}
| 1,152 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/ResponsiveGrid.tsx.preview | <Grid
container
spacing={{ xs: 2, md: 3 }}
columns={{ xs: 4, sm: 8, md: 12 }}
sx={{ flexGrow: 1 }}
>
{Array.from(Array(6)).map((_, index) => (
<Grid xs={2} sm={4} md={4} key={index}>
<Item>xs=2</Item>
</Grid>
))}
</Grid> | 1,153 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/RowAndColumnSpacing.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Grid from '@mui/joy/Grid';
import Sheet from '@mui/joy/Sheet';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function RowAndColumnSpacing() {
return (
<Grid
container
rowSpacing={1}
columnSpacing={{ xs: 1, sm: 2, md: 3 }}
sx={{ width: '100%' }}
>
<Grid xs={6}>
<Item>1</Item>
</Grid>
<Grid xs={6}>
<Item>2</Item>
</Grid>
<Grid xs={6}>
<Item>3</Item>
</Grid>
<Grid xs={6}>
<Item>4</Item>
</Grid>
</Grid>
);
}
| 1,154 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/RowAndColumnSpacing.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Grid from '@mui/joy/Grid';
import Sheet from '@mui/joy/Sheet';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function RowAndColumnSpacing() {
return (
<Grid
container
rowSpacing={1}
columnSpacing={{ xs: 1, sm: 2, md: 3 }}
sx={{ width: '100%' }}
>
<Grid xs={6}>
<Item>1</Item>
</Grid>
<Grid xs={6}>
<Item>2</Item>
</Grid>
<Grid xs={6}>
<Item>3</Item>
</Grid>
<Grid xs={6}>
<Item>4</Item>
</Grid>
</Grid>
);
}
| 1,155 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/SpacingGrid.js | import * as React from 'react';
import Grid from '@mui/joy/Grid';
import FormLabel from '@mui/joy/FormLabel';
import FormControl from '@mui/joy/FormControl';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
import BrandingProvider from 'docs/src/BrandingProvider';
export default function SpacingGrid() {
const [spacing, setSpacing] = React.useState(2);
const handleChange = (event) => {
setSpacing(Number(event.target.value));
};
const jsx = `
<Grid container spacing={${spacing}}>
`;
return (
<Grid sx={{ flexGrow: 1 }} container spacing={2}>
<Grid xs={12}>
<Grid container justifyContent="center" spacing={spacing}>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Sheet
sx={{
height: 140,
width: 100,
}}
/>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Sheet sx={{ p: 2 }}>
<Grid container>
<Grid>
<FormControl>
<FormLabel>spacing</FormLabel>
<RadioGroup
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={handleChange}
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<Radio
key={value}
value={value.toString()}
label={value.toString()}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Sheet>
<BrandingProvider mode="dark">
<HighlightedCode code={jsx} language="jsx" />
</BrandingProvider>
</Grid>
</Grid>
);
}
| 1,156 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/SpacingGrid.tsx | import * as React from 'react';
import Grid from '@mui/joy/Grid';
import FormLabel from '@mui/joy/FormLabel';
import FormControl from '@mui/joy/FormControl';
import RadioGroup from '@mui/joy/RadioGroup';
import Radio from '@mui/joy/Radio';
import Sheet from '@mui/joy/Sheet';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
import BrandingProvider from 'docs/src/BrandingProvider';
export default function SpacingGrid() {
const [spacing, setSpacing] = React.useState(2);
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSpacing(Number((event.target as HTMLInputElement).value));
};
const jsx = `
<Grid container spacing={${spacing}}>
`;
return (
<Grid sx={{ flexGrow: 1 }} container spacing={2}>
<Grid xs={12}>
<Grid container justifyContent="center" spacing={spacing}>
{[0, 1, 2].map((value) => (
<Grid key={value}>
<Sheet
sx={{
height: 140,
width: 100,
}}
/>
</Grid>
))}
</Grid>
</Grid>
<Grid xs={12}>
<Sheet sx={{ p: 2 }}>
<Grid container>
<Grid>
<FormControl>
<FormLabel>spacing</FormLabel>
<RadioGroup
name="spacing"
aria-label="spacing"
value={spacing.toString()}
onChange={handleChange}
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 2, '--RadioGroup-gap': '0px' }}
>
{[0, 0.5, 1, 2, 3, 4, 8, 12].map((value) => (
<Radio
key={value}
value={value.toString()}
label={value.toString()}
/>
))}
</RadioGroup>
</FormControl>
</Grid>
</Grid>
</Sheet>
<BrandingProvider mode="dark">
<HighlightedCode code={jsx} language="jsx" />
</BrandingProvider>
</Grid>
</Grid>
);
}
| 1,157 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/VariableWidthGrid.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function VariableWidthGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs="auto">
<Item>variable width content</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
);
}
| 1,158 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/VariableWidthGrid.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Grid from '@mui/joy/Grid';
const Item = styled(Sheet)(({ theme }) => ({
backgroundColor:
theme.palette.mode === 'dark' ? theme.palette.background.level1 : '#fff',
...theme.typography['body-sm'],
padding: theme.spacing(1),
textAlign: 'center',
borderRadius: 4,
color: theme.vars.palette.text.secondary,
}));
export default function VariableWidthGrid() {
return (
<Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs="auto">
<Item>variable width content</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid>
);
}
| 1,159 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/VariableWidthGrid.tsx.preview | <Grid container spacing={3} sx={{ flexGrow: 1 }}>
<Grid xs="auto">
<Item>variable width content</Item>
</Grid>
<Grid xs={6}>
<Item>xs=6</Item>
</Grid>
<Grid xs>
<Item>xs</Item>
</Grid>
</Grid> | 1,160 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/grid/grid.md | ---
productId: joy-ui
title: React Grid component
components: Grid
githubLabel: 'component: Grid'
---
# Grid
<p class="description">Grid acts as a generic container, wrapping around the elements to be arranged.</p>
## Introduction
The Grid component, based on a 12-column grid layout, creates visual consistency between layouts while allowing flexibility across a wide variety of designs.
:::warning
The `Grid` component shouldn't be confused with a data grid; it is closer to a layout grid. For a data grid head to the [`DataGrid`](/x/react-data-grid/) component.
:::
## Basics
```jsx
import Grid from '@mui/joy/Grid';
```
Column widths are integer values between 1 and 12. They apply at any breakpoint and indicate how many columns are occupied by the component.
By default, the value given to a breakpoint is applied to all the other **wider** breakpoints.
For example, `xs={12}` sizes a component to occupy the whole viewport width regardless of its size, even if you do not pass any value for wider breakpoints like `sm` or `md`.
{{"demo": "BasicGrid.js", "bg": true}}
## Customization
### Grid with multiple breakpoints
Components may have multiple widths defined, causing the layout to change at the defined breakpoint. Width values given to larger breakpoints override those given to smaller breakpoints.
For example, `xs={12} sm={6}` sizes a component to occupy half of the viewport width (6 columns) when viewport width is 600 or more pixels. For smaller viewports, the component fills all 12 available columns.
{{"demo": "FullWidthGrid.js", "bg": true}}
### Spacing
To control space between children, use the `spacing` prop.
The spacing value can be any positive number, including decimals and any string.
The prop is converted into a CSS property using the [`theme.spacing()`](/material-ui/customization/spacing/) helper.
{{"demo": "SpacingGrid.js", "bg": true}}
### Row & column spacing
The `rowSpacing` and `columnSpacing` props allow for specifying the row and column gaps independently.
It's similar to the `row-gap` and `column-gap` properties of [CSS Grid](/system/grid/#row-gap-amp-column-gap).
{{"demo": "RowAndColumnSpacing.js", "bg": true}}
### Responsive values
You can switch the props' value based on the active breakpoint.
{{"demo": "ResponsiveGrid.js", "bg": true}}
Responsive values is supported by:
- `columns`
- `columnSpacing`
- `direction`
- `rowSpacing`
- `spacing`
- all the [other props](#system-props) of the system
:::warning
When using a responsive `columns` prop, each grid item needs its corresponding breakpoint.
For instance, this is not working. The grid item misses the value for `md`:
```jsx
<Grid container columns={{ xs: 4, md: 12 }}>
<Grid xs={2} />
</Grid>
```
:::
### Auto-layout
The Auto-layout makes the grid items equitably share the available space.
This also means that you can set the width of one grid item, and the others will automatically resize around it.
{{"demo": "AutoGrid.js", "bg": true}}
### Variable width content
Set one of the size breakpoint props to `"auto"` instead of `true` or a `number` to render a column based on the natural width of its content.
{{"demo": "VariableWidthGrid.js", "bg": true}}
### Columns
You can change the default number of columns (12) with the `columns` prop.
{{"demo": "ColumnsGrid.js", "bg": true}}
### System props
As a CSS utility component, Grid supports all [MUI System properties](/system/properties/).
You can use them as props directly on the component.
For instance, a margin-top:
```jsx
<Grid mt={2}>
```
## Interactive demo
Below is an interactive demo that lets you explore the visual results of the different settings:
{{"demo": "InteractiveGrid.js", "hideToolbar": true, "bg": true}}
## Limitations
### Negative margin
The spacing between items is implemented with a negative margin. This might lead to unexpected behaviors. For instance, to apply a background color, you need to apply `display: flex;` to the parent.
### direction: column | column-reverse
The `xs`, `sm`, `md`, `lg`, and `xl` props are **not supported** within `direction="column"` and `direction="column-reverse"` containers.
They define the number of grids the component will use for a given breakpoint. They are intended to control **width** using `flex-basis` in `row` containers but they will impact height in `column` containers.
If used, these props may have undesirable effects on the height of the `Grid` item elements.
## CSS Grid Layout
The `Grid` component is using CSS flexbox internally.
But as seen below, you can easily use [the system](/system/grid/) and CSS Grid to layout your pages.
{{"demo": "CSSGrid.js", "bg": true}}
## Common examples
### Centering children
To center a grid item's content, specify `display="flex"` directly on the item.
Then use `justifyContent` and/or `alignItems` to adjust the position of the content, as shown below:
{{"demo": "ChildrenCenteredGrid.js"}}
## Anatomy
The Grid component is composed of a single root `<div>` element:
```html
<div class="MuiGrid-root">
<!-- Grid contents -->
</div>
```
| 1,161 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/BasicInput.js | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function BasicInput() {
return <Input placeholder="Type in here…" />;
}
| 1,162 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/BasicInput.tsx | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function BasicInput() {
return <Input placeholder="Type in here…" />;
}
| 1,163 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/BasicInput.tsx.preview | <Input placeholder="Type in here…" /> | 1,164 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/DebouncedInput.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Input from '@mui/joy/Input';
import Typography from '@mui/joy/Typography';
import Box from '@mui/joy/Box';
function DebounceInput(props) {
const { handleDebounce, debounceTimeout, ...rest } = props;
const timerRef = React.useRef();
const handleChange = (event) => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = window.setTimeout(() => {
handleDebounce(event.target.value);
}, debounceTimeout);
};
return <Input {...rest} onChange={handleChange} />;
}
DebounceInput.propTypes = {
debounceTimeout: PropTypes.number.isRequired,
handleDebounce: PropTypes.func.isRequired,
};
export default function DebouncedInput() {
const [debouncedValue, setDebouncedValue] = React.useState('');
const handleDebounce = (value) => {
setDebouncedValue(value);
};
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
<DebounceInput
placeholder="Type in here…"
debounceTimeout={1000}
handleDebounce={handleDebounce}
/>
<Typography>Debounced input: {debouncedValue}</Typography>
</Box>
);
}
| 1,165 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/DebouncedInput.tsx | import * as React from 'react';
import Input, { InputProps } from '@mui/joy/Input';
import Typography from '@mui/joy/Typography';
import Box from '@mui/joy/Box';
type DebounceProps = {
handleDebounce: (value: string) => void;
debounceTimeout: number;
};
function DebounceInput(props: InputProps & DebounceProps) {
const { handleDebounce, debounceTimeout, ...rest } = props;
const timerRef = React.useRef<number>();
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
timerRef.current = window.setTimeout(() => {
handleDebounce(event.target.value);
}, debounceTimeout);
};
return <Input {...rest} onChange={handleChange} />;
}
export default function DebouncedInput() {
const [debouncedValue, setDebouncedValue] = React.useState('');
const handleDebounce = (value: string) => {
setDebouncedValue(value);
};
return (
<Box sx={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
<DebounceInput
placeholder="Type in here…"
debounceTimeout={1000}
handleDebounce={handleDebounce}
/>
<Typography>Debounced input: {debouncedValue}</Typography>
</Box>
);
}
| 1,166 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/DebouncedInput.tsx.preview | <DebounceInput
placeholder="Type in here…"
debounceTimeout={1000}
handleDebounce={handleDebounce}
/>
<Typography>Debounced input: {debouncedValue}</Typography> | 1,167 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FloatingLabelInput.js | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Input from '@mui/joy/Input';
import CheckCircleOutlined from '@mui/icons-material/CheckCircleOutlined';
const StyledInput = styled('input')({
border: 'none', // remove the native input border
minWidth: 0, // remove the native input width
outline: 0, // remove the native input outline
padding: 0, // remove the native input padding
paddingTop: '1em',
flex: 1,
color: 'inherit',
backgroundColor: 'transparent',
fontFamily: 'inherit',
fontSize: 'inherit',
fontStyle: 'inherit',
fontWeight: 'inherit',
lineHeight: 'inherit',
textOverflow: 'ellipsis',
'&::placeholder': {
opacity: 0,
transition: '0.1s ease-out',
},
'&:focus::placeholder': {
opacity: 1,
},
'&:focus ~ label, &:not(:placeholder-shown) ~ label, &:-webkit-autofill ~ label': {
top: '0.5rem',
fontSize: '0.75rem',
},
'&:focus ~ label': {
color: 'var(--Input-focusedHighlight)',
},
'&:-webkit-autofill': {
alignSelf: 'stretch', // to fill the height of the root slot
},
'&:-webkit-autofill:not(* + &)': {
marginInlineStart: 'calc(-1 * var(--Input-paddingInline))',
paddingInlineStart: 'var(--Input-paddingInline)',
borderTopLeftRadius:
'calc(var(--Input-radius) - var(--variant-borderWidth, 0px))',
borderBottomLeftRadius:
'calc(var(--Input-radius) - var(--variant-borderWidth, 0px))',
},
});
const StyledLabel = styled('label')(({ theme }) => ({
position: 'absolute',
lineHeight: 1,
top: 'calc((var(--Input-minHeight) - 1em) / 2)',
color: theme.vars.palette.text.tertiary,
fontWeight: theme.vars.fontWeight.md,
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
}));
const InnerInput = React.forwardRef(function InnerInput(props, ref) {
const id = React.useId();
return (
<React.Fragment>
<StyledInput {...props} ref={ref} id={id} />
<StyledLabel htmlFor={id}>Label</StyledLabel>
</React.Fragment>
);
});
export default function FloatingLabelInput() {
return (
<Input
endDecorator={<CheckCircleOutlined />}
slots={{ input: InnerInput }}
slotProps={{ input: { placeholder: 'A placeholder', type: 'password' } }}
sx={{
'--Input-minHeight': '56px',
'--Input-radius': '6px',
}}
/>
);
}
| 1,168 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FloatingLabelInput.tsx | import * as React from 'react';
import { styled } from '@mui/joy/styles';
import Input from '@mui/joy/Input';
import CheckCircleOutlined from '@mui/icons-material/CheckCircleOutlined';
const StyledInput = styled('input')({
border: 'none', // remove the native input border
minWidth: 0, // remove the native input width
outline: 0, // remove the native input outline
padding: 0, // remove the native input padding
paddingTop: '1em',
flex: 1,
color: 'inherit',
backgroundColor: 'transparent',
fontFamily: 'inherit',
fontSize: 'inherit',
fontStyle: 'inherit',
fontWeight: 'inherit',
lineHeight: 'inherit',
textOverflow: 'ellipsis',
'&::placeholder': {
opacity: 0,
transition: '0.1s ease-out',
},
'&:focus::placeholder': {
opacity: 1,
},
'&:focus ~ label, &:not(:placeholder-shown) ~ label, &:-webkit-autofill ~ label': {
top: '0.5rem',
fontSize: '0.75rem',
},
'&:focus ~ label': {
color: 'var(--Input-focusedHighlight)',
},
'&:-webkit-autofill': {
alignSelf: 'stretch', // to fill the height of the root slot
},
'&:-webkit-autofill:not(* + &)': {
marginInlineStart: 'calc(-1 * var(--Input-paddingInline))',
paddingInlineStart: 'var(--Input-paddingInline)',
borderTopLeftRadius:
'calc(var(--Input-radius) - var(--variant-borderWidth, 0px))',
borderBottomLeftRadius:
'calc(var(--Input-radius) - var(--variant-borderWidth, 0px))',
},
});
const StyledLabel = styled('label')(({ theme }) => ({
position: 'absolute',
lineHeight: 1,
top: 'calc((var(--Input-minHeight) - 1em) / 2)',
color: theme.vars.palette.text.tertiary,
fontWeight: theme.vars.fontWeight.md,
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
}));
const InnerInput = React.forwardRef<
HTMLInputElement,
JSX.IntrinsicElements['input']
>(function InnerInput(props, ref) {
const id = React.useId();
return (
<React.Fragment>
<StyledInput {...props} ref={ref} id={id} />
<StyledLabel htmlFor={id}>Label</StyledLabel>
</React.Fragment>
);
});
export default function FloatingLabelInput() {
return (
<Input
endDecorator={<CheckCircleOutlined />}
slots={{ input: InnerInput }}
slotProps={{ input: { placeholder: 'A placeholder', type: 'password' } }}
sx={{
'--Input-minHeight': '56px',
'--Input-radius': '6px',
}}
/>
);
}
| 1,169 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FloatingLabelInput.tsx.preview | <Input
endDecorator={<CheckCircleOutlined />}
slots={{ input: InnerInput }}
slotProps={{ input: { placeholder: 'A placeholder', type: 'password' } }}
sx={{
'--Input-minHeight': '56px',
'--Input-radius': '6px',
}}
/> | 1,170 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusOutlineInput.js | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function FocusOutlineInput() {
return (
<Input
placeholder="Type in here…"
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Input-focusedHighlight)',
outlineOffset: '2px',
},
}}
/>
);
}
| 1,171 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusOutlineInput.tsx | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function FocusOutlineInput() {
return (
<Input
placeholder="Type in here…"
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Input-focusedHighlight)',
outlineOffset: '2px',
},
}}
/>
);
}
| 1,172 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusOutlineInput.tsx.preview | <Input
placeholder="Type in here…"
sx={{
'&::before': {
display: 'none',
},
'&:focus-within': {
outline: '2px solid var(--Input-focusedHighlight)',
outlineOffset: '2px',
},
}}
/> | 1,173 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusedRingInput.js | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function FocusedRingInput() {
return (
<Input
placeholder="Bootstrap"
sx={{
'--Input-focusedInset': 'var(--any, )',
'--Input-focusedThickness': '0.25rem',
'--Input-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/>
);
}
| 1,174 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusedRingInput.tsx | import * as React from 'react';
import Input from '@mui/joy/Input';
export default function FocusedRingInput() {
return (
<Input
placeholder="Bootstrap"
sx={{
'--Input-focusedInset': 'var(--any, )',
'--Input-focusedThickness': '0.25rem',
'--Input-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/>
);
}
| 1,175 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/FocusedRingInput.tsx.preview | <Input
placeholder="Bootstrap"
sx={{
'--Input-focusedInset': 'var(--any, )',
'--Input-focusedThickness': '0.25rem',
'--Input-focusedHighlight': 'rgba(13,110,253,.25)',
'&::before': {
transition: 'box-shadow .15s ease-in-out',
},
'&:focus-within': {
borderColor: '#86b7fe',
},
}}
/> | 1,176 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputColors.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';
export default function InputColors() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="success" />
<Input placeholder="Type in here…" variant="outlined" color="warning" />
</Box>
);
}
| 1,177 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputColors.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Input from '@mui/joy/Input';
export default function InputColors() {
return (
<Box
sx={{
py: 2,
display: 'grid',
gap: 2,
alignItems: 'center',
flexWrap: 'wrap',
}}
>
<Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="success" />
<Input placeholder="Type in here…" variant="outlined" color="warning" />
</Box>
);
}
| 1,178 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputColors.tsx.preview | <Input placeholder="Type in here…" variant="outlined" color="primary" />
<Input placeholder="Type in here…" variant="outlined" color="neutral" />
<Input placeholder="Type in here…" variant="outlined" color="danger" />
<Input placeholder="Type in here…" variant="outlined" color="success" />
<Input placeholder="Type in here…" variant="outlined" color="warning" /> | 1,179 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputDecorators.js | import * as React from 'react';
import Button from '@mui/joy/Button';
import Divider from '@mui/joy/Divider';
import Input from '@mui/joy/Input';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Stack from '@mui/joy/Stack';
import LocationOn from '@mui/icons-material/LocationOn';
export default function InputDecorators() {
const [currency, setCurrency] = React.useState('dollar');
return (
<Stack spacing={1.5}>
<Input
placeholder="Amount"
startDecorator={{ dollar: '$', baht: '฿', yen: '¥' }[currency]}
endDecorator={
<React.Fragment>
<Divider orientation="vertical" />
<Select
variant="plain"
value={currency}
onChange={(_, value) => setCurrency(value)}
slotProps={{
listbox: {
variant: 'outlined',
},
}}
sx={{ mr: -1.5, '&:hover': { bgcolor: 'transparent' } }}
>
<Option value="dollar">US dollar</Option>
<Option value="baht">Thai baht</Option>
<Option value="yen">Japanese yen</Option>
</Select>
</React.Fragment>
}
sx={{ width: 300 }}
/>
<Input
placeholder="Your location"
startDecorator={
<Button variant="soft" color="neutral" startDecorator={<LocationOn />}>
Locate
</Button>
}
sx={{ width: 300 }}
/>
</Stack>
);
}
| 1,180 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputDecorators.tsx | import * as React from 'react';
import Button from '@mui/joy/Button';
import Divider from '@mui/joy/Divider';
import Input from '@mui/joy/Input';
import Select from '@mui/joy/Select';
import Option from '@mui/joy/Option';
import Stack from '@mui/joy/Stack';
import LocationOn from '@mui/icons-material/LocationOn';
export default function InputDecorators() {
const [currency, setCurrency] = React.useState('dollar');
return (
<Stack spacing={1.5}>
<Input
placeholder="Amount"
startDecorator={{ dollar: '$', baht: '฿', yen: '¥' }[currency]}
endDecorator={
<React.Fragment>
<Divider orientation="vertical" />
<Select
variant="plain"
value={currency}
onChange={(_, value) => setCurrency(value!)}
slotProps={{
listbox: {
variant: 'outlined',
},
}}
sx={{ mr: -1.5, '&:hover': { bgcolor: 'transparent' } }}
>
<Option value="dollar">US dollar</Option>
<Option value="baht">Thai baht</Option>
<Option value="yen">Japanese yen</Option>
</Select>
</React.Fragment>
}
sx={{ width: 300 }}
/>
<Input
placeholder="Your location"
startDecorator={
<Button variant="soft" color="neutral" startDecorator={<LocationOn />}>
Locate
</Button>
}
sx={{ width: 300 }}
/>
</Stack>
);
}
| 1,181 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputField.js | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';
export default function InputField() {
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl>
);
}
| 1,182 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputField.tsx | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';
export default function InputField() {
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl>
);
}
| 1,183 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputField.tsx.preview | <FormControl>
<FormLabel>Label</FormLabel>
<Input placeholder="Placeholder" />
<FormHelperText>This is a helper text.</FormHelperText>
</FormControl> | 1,184 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputFormProps.js | import * as React from 'react';
import Button from '@mui/joy/Button';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputFormProps() {
return (
<form
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const formJson = Object.fromEntries(formData.entries());
alert(JSON.stringify(formJson));
}}
>
<Stack spacing={1}>
<Input placeholder="Try to submit with no text!" required />
<Input placeholder="It is disabled" disabled />
<Button type="submit">Submit</Button>
</Stack>
</form>
);
}
| 1,185 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputFormProps.tsx | import * as React from 'react';
import Button from '@mui/joy/Button';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputFormProps() {
return (
<form
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const formJson = Object.fromEntries((formData as any).entries());
alert(JSON.stringify(formJson));
}}
>
<Stack spacing={1}>
<Input placeholder="Try to submit with no text!" required />
<Input placeholder="It is disabled" disabled />
<Button type="submit">Submit</Button>
</Stack>
</form>
);
}
| 1,186 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputFormProps.tsx.preview | <form
onSubmit={(event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const formJson = Object.fromEntries((formData as any).entries());
alert(JSON.stringify(formJson));
}}
>
<Stack spacing={1}>
<Input placeholder="Try to submit with no text!" required />
<Input placeholder="It is disabled" disabled />
<Button type="submit">Submit</Button>
</Stack>
</form> | 1,187 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactImask.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { IMaskInput } from 'react-imask';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
const TextMaskAdapter = React.forwardRef(function TextMaskAdapter(props, ref) {
const { onChange, ...other } = props;
return (
<IMaskInput
{...other}
mask="(#00) 000-0000"
definitions={{
'#': /[1-9]/,
}}
inputRef={ref}
onAccept={(value) => onChange({ target: { name: props.name, value } })}
overwrite
/>
);
});
TextMaskAdapter.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
export default function InputReactImask() {
const [value, setValue] = React.useState('(100) 000-0000');
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{ input: { component: TextMaskAdapter } }}
/>
</FormControl>
);
}
| 1,188 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactImask.tsx | import * as React from 'react';
import { IMaskInput } from 'react-imask';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
interface CustomProps {
onChange: (event: { target: { name: string; value: string } }) => void;
name: string;
}
const TextMaskAdapter = React.forwardRef<HTMLElement, CustomProps>(
function TextMaskAdapter(props, ref) {
const { onChange, ...other } = props;
return (
<IMaskInput
{...other}
mask="(#00) 000-0000"
definitions={{
'#': /[1-9]/,
}}
inputRef={ref}
onAccept={(value: any) => onChange({ target: { name: props.name, value } })}
overwrite
/>
);
},
);
export default function InputReactImask() {
const [value, setValue] = React.useState('(100) 000-0000');
return (
<FormControl>
<FormLabel>Label</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{ input: { component: TextMaskAdapter } }}
/>
</FormControl>
);
}
| 1,189 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactImask.tsx.preview | <FormControl>
<FormLabel>Label</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{ input: { component: TextMaskAdapter } }}
/>
</FormControl> | 1,190 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactNumberFormat.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { NumericFormat } from 'react-number-format';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
const NumericFormatAdapter = React.forwardRef(function NumericFormatAdapter(
props,
ref,
) {
const { onChange, ...other } = props;
return (
<NumericFormat
{...other}
getInputRef={ref}
onValueChange={(values) => {
onChange({
target: {
name: props.name,
value: values.value,
},
});
}}
thousandSeparator
valueIsNumericString
prefix="$"
/>
);
});
NumericFormatAdapter.propTypes = {
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
export default function InputReactNumberFormat() {
const [value, setValue] = React.useState('1320');
return (
<FormControl>
<FormLabel>React number format</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{
input: {
component: NumericFormatAdapter,
},
}}
/>
</FormControl>
);
}
| 1,191 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactNumberFormat.tsx | import * as React from 'react';
import { NumericFormat, NumericFormatProps } from 'react-number-format';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import Input from '@mui/joy/Input';
interface CustomProps {
onChange: (event: { target: { name: string; value: string } }) => void;
name: string;
}
const NumericFormatAdapter = React.forwardRef<NumericFormatProps, CustomProps>(
function NumericFormatAdapter(props, ref) {
const { onChange, ...other } = props;
return (
<NumericFormat
{...other}
getInputRef={ref}
onValueChange={(values) => {
onChange({
target: {
name: props.name,
value: values.value,
},
});
}}
thousandSeparator
valueIsNumericString
prefix="$"
/>
);
},
);
export default function InputReactNumberFormat() {
const [value, setValue] = React.useState('1320');
return (
<FormControl>
<FormLabel>React number format</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{
input: {
component: NumericFormatAdapter,
},
}}
/>
</FormControl>
);
}
| 1,192 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputReactNumberFormat.tsx.preview | <FormControl>
<FormLabel>React number format</FormLabel>
<Input
value={value}
onChange={(event) => setValue(event.target.value)}
placeholder="Placeholder"
slotProps={{
input: {
component: NumericFormatAdapter,
},
}}
/>
</FormControl> | 1,193 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSizes.js | import * as React from 'react';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputSizes() {
return (
<Stack spacing={2}>
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
</Stack>
);
}
| 1,194 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSizes.tsx | import * as React from 'react';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputSizes() {
return (
<Stack spacing={2}>
<Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" />
</Stack>
);
}
| 1,195 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSizes.tsx.preview | <Input size="sm" placeholder="Small" />
<Input size="md" placeholder="Medium" />
<Input size="lg" placeholder="Large" /> | 1,196 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSlotProps.js | import * as React from 'react';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputSlotProps() {
const inputRef = React.useRef(null);
return (
<Stack spacing={1.5} sx={{ minWidth: 300 }}>
<Input
type="number"
defaultValue={2.5}
slotProps={{
input: {
ref: inputRef,
min: 1,
max: 5,
step: 0.1,
},
}}
/>
<Input
type="date"
slotProps={{
input: {
min: '2018-06-07T00:00',
max: '2018-06-14T00:00',
},
}}
/>
</Stack>
);
}
| 1,197 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSlotProps.tsx | import * as React from 'react';
import Input from '@mui/joy/Input';
import Stack from '@mui/joy/Stack';
export default function InputSlotProps() {
const inputRef = React.useRef<HTMLInputElement | null>(null);
return (
<Stack spacing={1.5} sx={{ minWidth: 300 }}>
<Input
type="number"
defaultValue={2.5}
slotProps={{
input: {
ref: inputRef,
min: 1,
max: 5,
step: 0.1,
},
}}
/>
<Input
type="date"
slotProps={{
input: {
min: '2018-06-07T00:00',
max: '2018-06-14T00:00',
},
}}
/>
</Stack>
);
}
| 1,198 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/input/InputSubscription.js | import * as React from 'react';
import FormControl from '@mui/joy/FormControl';
import FormLabel from '@mui/joy/FormLabel';
import FormHelperText from '@mui/joy/FormHelperText';
import Input from '@mui/joy/Input';
import Button from '@mui/joy/Button';
export default function InputSubscription() {
const [data, setData] = React.useState({
email: '',
status: 'initial',
});
const handleSubmit = (event) => {
event.preventDefault();
setData((current) => ({ ...current, status: 'loading' }));
try {
// Replace timeout with real backend operation
setTimeout(() => {
setData({ email: '', status: 'sent' });
}, 1500);
} catch (error) {
setData((current) => ({ ...current, status: 'failure' }));
}
};
return (
<form onSubmit={handleSubmit} id="demo">
<FormControl>
<FormLabel
sx={(theme) => ({
'--FormLabel-color': theme.vars.palette.primary.plainColor,
})}
>
MUI Newsletter
</FormLabel>
<Input
sx={{ '--Input-decoratorChildHeight': '45px' }}
placeholder="[email protected]"
type="email"
required
value={data.email}
onChange={(event) =>
setData({ email: event.target.value, status: 'initial' })
}
error={data.status === 'failure'}
endDecorator={
<Button
variant="solid"
color="primary"
loading={data.status === 'loading'}
type="submit"
sx={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}
>
Subscribe
</Button>
}
/>
{data.status === 'failure' && (
<FormHelperText
sx={(theme) => ({ color: theme.vars.palette.danger[400] })}
>
Oops! something went wrong, please try again later.
</FormHelperText>
)}
{data.status === 'sent' && (
<FormHelperText
sx={(theme) => ({ color: theme.vars.palette.primary[400] })}
>
You are all set!
</FormHelperText>
)}
</FormControl>
</form>
);
}
| 1,199 |
Subsets and Splits