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/checkbox/CheckboxColors.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxColors() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<Checkbox label="Primary" color="primary" defaultChecked />
<Checkbox label="Neutral" color="neutral" defaultChecked />
<Checkbox label="Danger" color="danger" defaultChecked />
<Checkbox label="Success" color="success" defaultChecked />
<Checkbox label="Warning" color="warning" defaultChecked />
</Box>
);
}
| 1,000 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxColors.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxColors() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<Checkbox label="Primary" color="primary" defaultChecked />
<Checkbox label="Neutral" color="neutral" defaultChecked />
<Checkbox label="Danger" color="danger" defaultChecked />
<Checkbox label="Success" color="success" defaultChecked />
<Checkbox label="Warning" color="warning" defaultChecked />
</Box>
);
}
| 1,001 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxColors.tsx.preview | <Checkbox label="Primary" color="primary" defaultChecked />
<Checkbox label="Neutral" color="neutral" defaultChecked />
<Checkbox label="Danger" color="danger" defaultChecked />
<Checkbox label="Success" color="success" defaultChecked />
<Checkbox label="Warning" color="warning" defaultChecked /> | 1,002 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxSizes.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxSizes() {
return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 3 }}>
<Checkbox label="Small" size="sm" defaultChecked />
<Checkbox label="Medium" size="md" defaultChecked />
<Checkbox label="Large" size="lg" defaultChecked />
</Box>
);
}
| 1,003 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxSizes.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxSizes() {
return (
<Box sx={{ display: 'flex', alignItems: 'center', gap: 3 }}>
<Checkbox label="Small" size="sm" defaultChecked />
<Checkbox label="Medium" size="md" defaultChecked />
<Checkbox label="Large" size="lg" defaultChecked />
</Box>
);
}
| 1,004 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxSizes.tsx.preview | <Checkbox label="Small" size="sm" defaultChecked />
<Checkbox label="Medium" size="md" defaultChecked />
<Checkbox label="Large" size="lg" defaultChecked /> | 1,005 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxUsage.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function CheckboxUsage() {
return (
<JoyUsageDemo
componentName="Checkbox"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'outlined',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'disabled',
knob: 'switch',
defaultValue: false,
},
{
propName: 'label',
knob: 'input',
defaultValue: 'Label',
},
]}
renderDemo={(props) => <Checkbox {...props} />}
/>
);
}
| 1,006 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxVariants.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxVariants() {
return (
<Box sx={{ display: 'flex', gap: 3 }}>
<Checkbox label="Solid" variant="solid" defaultChecked />
<Checkbox label="Soft" variant="soft" defaultChecked />
<Checkbox label="Outlined" variant="outlined" defaultChecked />
<Checkbox label="Plain" variant="plain" defaultChecked />
</Box>
);
}
| 1,007 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxVariants.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function CheckboxVariants() {
return (
<Box sx={{ display: 'flex', gap: 3 }}>
<Checkbox label="Solid" variant="solid" defaultChecked />
<Checkbox label="Soft" variant="soft" defaultChecked />
<Checkbox label="Outlined" variant="outlined" defaultChecked />
<Checkbox label="Plain" variant="plain" defaultChecked />
</Box>
);
}
| 1,008 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/CheckboxVariants.tsx.preview | <Checkbox label="Solid" variant="solid" defaultChecked />
<Checkbox label="Soft" variant="soft" defaultChecked />
<Checkbox label="Outlined" variant="outlined" defaultChecked />
<Checkbox label="Plain" variant="plain" defaultChecked /> | 1,009 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleButtonCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import LaptopIcon from '@mui/icons-material/Laptop';
import TvIcon from '@mui/icons-material/Tv';
import PhoneAndroidIcon from '@mui/icons-material/PhoneAndroid';
export default function ExampleButtonCheckbox() {
const [value, setValue] = React.useState([]);
return (
<List
variant="outlined"
aria-label="Screens"
role="group"
orientation="horizontal"
sx={{
flexGrow: 0,
'--List-gap': '8px',
'--List-padding': '8px',
'--List-radius': '8px',
}}
>
{['Mobile', 'Laptop', 'Monitor'].map((item) => (
<ListItem key={item}>
<ListItemDecorator
sx={{
zIndex: 2,
pointerEvents: 'none',
...(value.includes(item) && { color: 'text.primary' }),
}}
>
{
{
Mobile: <PhoneAndroidIcon />,
Laptop: <LaptopIcon />,
Monitor: <TvIcon />,
}[item]
}
</ListItemDecorator>
<Checkbox
disableIcon
overlay
label={item}
checked={value.includes(item)}
color="neutral"
variant={value.includes(item) ? 'outlined' : 'plain'}
onChange={(event) => {
if (event.target.checked) {
setValue((val) => [...val, item]);
} else {
setValue((val) => val.filter((text) => text !== item));
}
}}
slotProps={{
action: ({ checked }) => ({
sx: {
bgcolor: checked ? 'background.level1' : 'transparent',
boxShadow: checked ? 'sm' : 'none',
},
}),
}}
/>
</ListItem>
))}
</List>
);
}
| 1,010 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleButtonCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import ListItemDecorator from '@mui/joy/ListItemDecorator';
import LaptopIcon from '@mui/icons-material/Laptop';
import TvIcon from '@mui/icons-material/Tv';
import PhoneAndroidIcon from '@mui/icons-material/PhoneAndroid';
export default function ExampleButtonCheckbox() {
const [value, setValue] = React.useState<string[]>([]);
return (
<List
variant="outlined"
aria-label="Screens"
role="group"
orientation="horizontal"
sx={{
flexGrow: 0,
'--List-gap': '8px',
'--List-padding': '8px',
'--List-radius': '8px',
}}
>
{['Mobile', 'Laptop', 'Monitor'].map((item) => (
<ListItem key={item}>
<ListItemDecorator
sx={{
zIndex: 2,
pointerEvents: 'none',
...(value.includes(item) && { color: 'text.primary' }),
}}
>
{
{
Mobile: <PhoneAndroidIcon />,
Laptop: <LaptopIcon />,
Monitor: <TvIcon />,
}[item]
}
</ListItemDecorator>
<Checkbox
disableIcon
overlay
label={item}
checked={value.includes(item)}
color="neutral"
variant={value.includes(item) ? 'outlined' : 'plain'}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.checked) {
setValue((val) => [...val, item]);
} else {
setValue((val) => val.filter((text) => text !== item));
}
}}
slotProps={{
action: ({ checked }) => ({
sx: {
bgcolor: checked ? 'background.level1' : 'transparent',
boxShadow: checked ? 'sm' : 'none',
},
}),
}}
/>
</ListItem>
))}
</List>
);
}
| 1,011 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleChoiceChipCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import Done from '@mui/icons-material/Done';
export default function ExampleChoiceChipCheckbox() {
const [value, setValue] = React.useState([]);
return (
<Sheet variant="outlined" sx={{ width: 360, p: 2, borderRadius: 'sm' }}>
<Typography id="rank" level="body-sm" fontWeight="lg" sx={{ mb: 1.5 }}>
Choose amenities
</Typography>
<div role="group" aria-labelledby="rank">
<List
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
'--ListItem-radius': '20px',
'--ListItem-minHeight': '32px',
'--ListItem-gap': '4px',
}}
>
{['Elevator', 'Washer/Dryer', 'Fireplace', 'Dogs ok', 'Cats ok'].map(
(item, index) => (
<ListItem key={item}>
{value.includes(item) && (
<Done
fontSize="md"
color="primary"
sx={{ ml: -0.5, zIndex: 2, pointerEvents: 'none' }}
/>
)}
<Checkbox
size="sm"
disabled={index === 0}
disableIcon
overlay
label={item}
checked={value.includes(item)}
variant={value.includes(item) ? 'soft' : 'outlined'}
onChange={(event) => {
if (event.target.checked) {
setValue((val) => [...val, item]);
} else {
setValue((val) => val.filter((text) => text !== item));
}
}}
slotProps={{
action: ({ checked }) => ({
sx: checked
? {
border: '1px solid',
borderColor: 'primary.500',
}
: {},
}),
}}
/>
</ListItem>
),
)}
</List>
</div>
</Sheet>
);
}
| 1,012 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleChoiceChipCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
import Done from '@mui/icons-material/Done';
export default function ExampleChoiceChipCheckbox() {
const [value, setValue] = React.useState<string[]>([]);
return (
<Sheet variant="outlined" sx={{ width: 360, p: 2, borderRadius: 'sm' }}>
<Typography id="rank" level="body-sm" fontWeight="lg" sx={{ mb: 1.5 }}>
Choose amenities
</Typography>
<div role="group" aria-labelledby="rank">
<List
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
'--ListItem-radius': '20px',
'--ListItem-minHeight': '32px',
'--ListItem-gap': '4px',
}}
>
{['Elevator', 'Washer/Dryer', 'Fireplace', 'Dogs ok', 'Cats ok'].map(
(item, index) => (
<ListItem key={item}>
{value.includes(item) && (
<Done
fontSize="md"
color="primary"
sx={{ ml: -0.5, zIndex: 2, pointerEvents: 'none' }}
/>
)}
<Checkbox
size="sm"
disabled={index === 0}
disableIcon
overlay
label={item}
checked={value.includes(item)}
variant={value.includes(item) ? 'soft' : 'outlined'}
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.checked) {
setValue((val) => [...val, item]);
} else {
setValue((val) => val.filter((text) => text !== item));
}
}}
slotProps={{
action: ({ checked }) => ({
sx: checked
? {
border: '1px solid',
borderColor: 'primary.500',
}
: {},
}),
}}
/>
</ListItem>
),
)}
</List>
</div>
</Sheet>
);
}
| 1,013 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleFilterMemberCheckbox.js | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
export default function ExampleFilterMemberCheckbox() {
const [members, setMembers] = React.useState([false, true, false]);
const toggleMember = (index) => (event) => {
const newMembers = [...members];
newMembers[index] = event.target.checked;
setMembers(newMembers);
};
return (
<Sheet
variant="outlined"
sx={{
p: 2,
borderRadius: 'sm',
width: 360,
maxWidth: '100%',
}}
>
<Typography
id="member"
sx={{
textTransform: 'uppercase',
fontSize: 'xs',
letterSpacing: 'lg',
fontWeight: 'lg',
color: 'text.secondary',
mb: 2,
}}
>
Team members
</Typography>
<div role="group" aria-labelledby="member">
<List
sx={{
'--ListItem-gap': '0.75rem',
[`& .${checkboxClasses.root}`]: {
mr: 'auto',
flexGrow: 1,
alignItems: 'center',
flexDirection: 'row-reverse',
},
}}
>
<ListItem>
<Avatar aria-hidden="true" src="/static/images/avatar/1.jpg" />
<Checkbox
disabled
label="Friedrich Oberbrunner"
overlay
checked={members[0]}
onChange={toggleMember(0)}
/>
</ListItem>
<ListItem
{...(members[1] && {
variant: 'soft',
color: 'primary',
})}
>
<Avatar aria-hidden="true" src="/static/images/avatar/2.jpg" />
<Checkbox
overlay
label={
<React.Fragment>
Adeline O'Reilly{' '}
{members[1] && (
<Typography
aria-hidden="true"
sx={{ display: 'block', fontSize: 'sm', color: 'neutral.500' }}
>
This user is your friend.
</Typography>
)}
</React.Fragment>
}
checked={members[1]}
onChange={toggleMember(1)}
sx={{ color: 'inherit' }}
/>
</ListItem>
<ListItem {...(members[2] && { variant: 'soft', color: 'neutral' })}>
<Avatar aria-hidden="true" variant="solid">
FP
</Avatar>
<Checkbox
label="Fernando Pidrillio"
overlay
color="neutral"
checked={members[2]}
onChange={toggleMember(2)}
/>
</ListItem>
</List>
</div>
</Sheet>
);
}
| 1,014 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleFilterMemberCheckbox.tsx | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
export default function ExampleFilterMemberCheckbox() {
const [members, setMembers] = React.useState([false, true, false]);
const toggleMember =
(index: number) => (event: React.ChangeEvent<HTMLInputElement>) => {
const newMembers = [...members];
newMembers[index] = event.target.checked;
setMembers(newMembers);
};
return (
<Sheet
variant="outlined"
sx={{
p: 2,
borderRadius: 'sm',
width: 360,
maxWidth: '100%',
}}
>
<Typography
id="member"
sx={{
textTransform: 'uppercase',
fontSize: 'xs',
letterSpacing: 'lg',
fontWeight: 'lg',
color: 'text.secondary',
mb: 2,
}}
>
Team members
</Typography>
<div role="group" aria-labelledby="member">
<List
sx={{
'--ListItem-gap': '0.75rem',
[`& .${checkboxClasses.root}`]: {
mr: 'auto',
flexGrow: 1,
alignItems: 'center',
flexDirection: 'row-reverse',
},
}}
>
<ListItem>
<Avatar aria-hidden="true" src="/static/images/avatar/1.jpg" />
<Checkbox
disabled
label="Friedrich Oberbrunner"
overlay
checked={members[0]}
onChange={toggleMember(0)}
/>
</ListItem>
<ListItem
{...(members[1] && {
variant: 'soft',
color: 'primary',
})}
>
<Avatar aria-hidden="true" src="/static/images/avatar/2.jpg" />
<Checkbox
overlay
label={
<React.Fragment>
Adeline O'Reilly{' '}
{members[1] && (
<Typography
aria-hidden="true"
sx={{ display: 'block', fontSize: 'sm', color: 'neutral.500' }}
>
This user is your friend.
</Typography>
)}
</React.Fragment>
}
checked={members[1]}
onChange={toggleMember(1)}
sx={{ color: 'inherit' }}
/>
</ListItem>
<ListItem {...(members[2] && { variant: 'soft', color: 'neutral' })}>
<Avatar aria-hidden="true" variant="solid">
FP
</Avatar>
<Checkbox
label="Fernando Pidrillio"
overlay
color="neutral"
checked={members[2]}
onChange={toggleMember(2)}
/>
</ListItem>
</List>
</div>
</Sheet>
);
}
| 1,015 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleFilterStatusCheckbox.js | import * as React from 'react';
import Button from '@mui/joy/Button';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
export default function ExampleFilterStatusCheckbox() {
const [status, setStatus] = React.useState({
declinedPayment: true,
deliveryError: true,
wrongAddress: false,
});
return (
<Sheet variant="outlined" sx={{ p: 2, borderRadius: 'sm', width: 300 }}>
<Typography
id="filter-status"
sx={{
textTransform: 'uppercase',
fontSize: 'xs',
letterSpacing: 'lg',
fontWeight: 'lg',
color: 'text.secondary',
mb: 2,
}}
>
Filter status
</Typography>
<div role="group" aria-labelledby="filter-status">
<List>
<ListItem variant="soft" color="danger">
<Checkbox
label="Declined Payment"
color="danger"
overlay
checked={status.declinedPayment}
onChange={(event) =>
setStatus({ ...status, declinedPayment: event.target.checked })
}
sx={{ color: 'inherit' }}
/>
<Typography textColor="inherit" sx={{ ml: 'auto' }}>
8
</Typography>
</ListItem>
<ListItem variant="plain" color="warning" sx={{ borderRadius: 'sm' }}>
<Checkbox
label="Delivery Error"
color="warning"
overlay
checked={status.deliveryError}
onChange={(event) =>
setStatus({ ...status, deliveryError: event.target.checked })
}
/>
<Typography textColor="inherit" sx={{ ml: 'auto' }}>
24
</Typography>
</ListItem>
<ListItem variant="plain" sx={{ borderRadius: 'sm' }}>
<Checkbox
label="Wrong Address"
color="neutral"
overlay
checked={status.wrongAddress}
onChange={(event) =>
setStatus({ ...status, wrongAddress: event.target.checked })
}
/>
</ListItem>
</List>
</div>
<Button
variant="outlined"
color="neutral"
size="sm"
onClick={() =>
setStatus({
declinedPayment: false,
deliveryError: false,
wrongAddress: false,
})
}
sx={{ px: 1.5, mt: 1 }}
>
Clear All
</Button>
</Sheet>
);
}
| 1,016 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleFilterStatusCheckbox.tsx | import * as React from 'react';
import Button from '@mui/joy/Button';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
import Sheet from '@mui/joy/Sheet';
export default function ExampleFilterStatusCheckbox() {
const [status, setStatus] = React.useState({
declinedPayment: true,
deliveryError: true,
wrongAddress: false,
});
return (
<Sheet variant="outlined" sx={{ p: 2, borderRadius: 'sm', width: 300 }}>
<Typography
id="filter-status"
sx={{
textTransform: 'uppercase',
fontSize: 'xs',
letterSpacing: 'lg',
fontWeight: 'lg',
color: 'text.secondary',
mb: 2,
}}
>
Filter status
</Typography>
<div role="group" aria-labelledby="filter-status">
<List>
<ListItem variant="soft" color="danger">
<Checkbox
label="Declined Payment"
color="danger"
overlay
checked={status.declinedPayment}
onChange={(event) =>
setStatus({ ...status, declinedPayment: event.target.checked })
}
sx={{ color: 'inherit' }}
/>
<Typography textColor="inherit" sx={{ ml: 'auto' }}>
8
</Typography>
</ListItem>
<ListItem variant="plain" color="warning" sx={{ borderRadius: 'sm' }}>
<Checkbox
label="Delivery Error"
color="warning"
overlay
checked={status.deliveryError}
onChange={(event) =>
setStatus({ ...status, deliveryError: event.target.checked })
}
/>
<Typography textColor="inherit" sx={{ ml: 'auto' }}>
24
</Typography>
</ListItem>
<ListItem variant="plain" sx={{ borderRadius: 'sm' }}>
<Checkbox
label="Wrong Address"
color="neutral"
overlay
checked={status.wrongAddress}
onChange={(event) =>
setStatus({ ...status, wrongAddress: event.target.checked })
}
/>
</ListItem>
</List>
</div>
<Button
variant="outlined"
color="neutral"
size="sm"
onClick={() =>
setStatus({
declinedPayment: false,
deliveryError: false,
wrongAddress: false,
})
}
sx={{ px: 1.5, mt: 1 }}
>
Clear All
</Button>
</Sheet>
);
}
| 1,017 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleSignUpCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormHelperText from '@mui/joy/FormHelperText';
import Link from '@mui/joy/Link';
import Typography from '@mui/joy/Typography';
export default function ExampleSignUpCheckbox() {
return (
<FormControl size="sm" sx={{ width: 400 }}>
<Checkbox
label={
<React.Fragment>
I have read and agree to the{' '}
<Typography fontWeight="md">terms and conditions</Typography>.
</React.Fragment>
}
/>
<FormHelperText>
<Typography level="body-sm">
Read our <Link href="#link">terms and conditions</Link>.
</Typography>
</FormHelperText>
</FormControl>
);
}
| 1,018 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleSignUpCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormHelperText from '@mui/joy/FormHelperText';
import Link from '@mui/joy/Link';
import Typography from '@mui/joy/Typography';
export default function ExampleSignUpCheckbox() {
return (
<FormControl size="sm" sx={{ width: 400 }}>
<Checkbox
label={
<React.Fragment>
I have read and agree to the{' '}
<Typography fontWeight="md">terms and conditions</Typography>.
</React.Fragment>
}
/>
<FormHelperText>
<Typography level="body-sm">
Read our <Link href="#link">terms and conditions</Link>.
</Typography>
</FormHelperText>
</FormControl>
);
}
| 1,019 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/ExampleSignUpCheckbox.tsx.preview | <FormControl size="sm" sx={{ width: 400 }}>
<Checkbox
label={
<React.Fragment>
I have read and agree to the{' '}
<Typography fontWeight="md">terms and conditions</Typography>.
</React.Fragment>
}
/>
<FormHelperText>
<Typography level="body-sm">
Read our <Link href="#link">terms and conditions</Link>.
</Typography>
</FormHelperText>
</FormControl> | 1,020 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/FocusCheckbox.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
export default function FocusCheckbox() {
return (
<Box sx={{ display: 'flex', gap: 3 }}>
<Checkbox
label="Fully wrapped"
defaultChecked
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
<Checkbox
label="Input wrapped"
defaultChecked
sx={{ [`& > .${checkboxClasses.checkbox}`]: { position: 'relative' } }}
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
</Box>
);
}
| 1,021 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/FocusCheckbox.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
export default function FocusCheckbox() {
return (
<Box sx={{ display: 'flex', gap: 3 }}>
<Checkbox
label="Fully wrapped"
defaultChecked
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
<Checkbox
label="Input wrapped"
defaultChecked
sx={{ [`& > .${checkboxClasses.checkbox}`]: { position: 'relative' } }}
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
</Box>
);
}
| 1,022 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/FocusCheckbox.tsx.preview | <Checkbox
label="Fully wrapped"
defaultChecked
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
<Checkbox
label="Input wrapped"
defaultChecked
sx={{ [`& > .${checkboxClasses.checkbox}`]: { position: 'relative' } }}
// to demonstrate the focus outline
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/> | 1,023 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/GroupCheckboxes.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
export default function GroupCheckboxes() {
return (
<div>
<Typography id="sandwich-group" level="body-sm" fontWeight="lg" mb={1}>
Sandwich Dressings
</Typography>
<div role="group" aria-labelledby="sandwich-group">
<List size="sm">
<ListItem>
<Checkbox label="Lettuce" defaultChecked />
</ListItem>
<ListItem>
<Checkbox label="Tomato" />
</ListItem>
<ListItem>
<Checkbox label="Mustard" />
</ListItem>
</List>
</div>
</div>
);
}
| 1,024 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/GroupCheckboxes.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
export default function GroupCheckboxes() {
return (
<div>
<Typography id="sandwich-group" level="body-sm" fontWeight="lg" mb={1}>
Sandwich Dressings
</Typography>
<div role="group" aria-labelledby="sandwich-group">
<List size="sm">
<ListItem>
<Checkbox label="Lettuce" defaultChecked />
</ListItem>
<ListItem>
<Checkbox label="Tomato" />
</ListItem>
<ListItem>
<Checkbox label="Mustard" />
</ListItem>
</List>
</div>
</div>
);
}
| 1,025 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/GroupCheckboxes.tsx.preview | <Typography id="sandwich-group" level="body-sm" fontWeight="lg" mb={1}>
Sandwich Dressings
</Typography>
<div role="group" aria-labelledby="sandwich-group">
<List size="sm">
<ListItem>
<Checkbox label="Lettuce" defaultChecked />
</ListItem>
<ListItem>
<Checkbox label="Tomato" />
</ListItem>
<ListItem>
<Checkbox label="Mustard" />
</ListItem>
</List>
</div> | 1,026 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HelperTextCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormHelperText from '@mui/joy/FormHelperText';
export default function HelperTextCheckbox() {
return (
<FormControl>
<Checkbox label="Label" />
<FormHelperText>A description for the Checkbox.</FormHelperText>
</FormControl>
);
}
| 1,027 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HelperTextCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import FormControl from '@mui/joy/FormControl';
import FormHelperText from '@mui/joy/FormHelperText';
export default function HelperTextCheckbox() {
return (
<FormControl>
<Checkbox label="Label" />
<FormHelperText>A description for the Checkbox.</FormHelperText>
</FormControl>
);
}
| 1,028 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HelperTextCheckbox.tsx.preview | <FormControl>
<Checkbox label="Label" />
<FormHelperText>A description for the Checkbox.</FormHelperText>
</FormControl> | 1,029 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HoverCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import Done from '@mui/icons-material/Done';
export default function HoverCheckbox() {
return (
<Checkbox
uncheckedIcon={<Done />}
label="My unchecked icon appears on hover"
slotProps={{
root: ({ checked, focusVisible }) => ({
sx: !checked
? {
'& svg': { opacity: focusVisible ? 1 : 0 },
'&:hover svg': {
opacity: 1,
},
}
: undefined,
}),
}}
/>
);
}
| 1,030 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HoverCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import Done from '@mui/icons-material/Done';
export default function HoverCheckbox() {
return (
<Checkbox
uncheckedIcon={<Done />}
label="My unchecked icon appears on hover"
slotProps={{
root: ({ checked, focusVisible }) => ({
sx: !checked
? {
'& svg': { opacity: focusVisible ? 1 : 0 },
'&:hover svg': {
opacity: 1,
},
}
: undefined,
}),
}}
/>
);
}
| 1,031 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/HoverCheckbox.tsx.preview | <Checkbox
uncheckedIcon={<Done />}
label="My unchecked icon appears on hover"
slotProps={{
root: ({ checked, focusVisible }) => ({
sx: !checked
? {
'& svg': { opacity: focusVisible ? 1 : 0 },
'&:hover svg': {
opacity: 1,
},
}
: undefined,
}),
}}
/> | 1,032 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IconlessCheckbox.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
export default function IconlessCheckbox() {
return (
<Box sx={{ width: 343 }}>
<Typography id="topping" level="body-sm" fontWeight="lg" mb={2}>
Pizza toppings
</Typography>
<div role="group" aria-labelledby="topping">
<List
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
'--ListItem-radius': '20px',
}}
>
{[
'Pepperoni',
'Cheese',
'Olives',
'Tomatoes',
'Fried Bacon',
'Spinach',
].map((item, index) => (
<ListItem key={item}>
<Checkbox
disabled={index === 0}
overlay
disableIcon
variant="soft"
label={item}
/>
</ListItem>
))}
</List>
</div>
</Box>
);
}
| 1,033 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IconlessCheckbox.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
import List from '@mui/joy/List';
import ListItem from '@mui/joy/ListItem';
import Typography from '@mui/joy/Typography';
export default function IconlessCheckbox() {
return (
<Box sx={{ width: 343 }}>
<Typography id="topping" level="body-sm" fontWeight="lg" mb={2}>
Pizza toppings
</Typography>
<div role="group" aria-labelledby="topping">
<List
orientation="horizontal"
wrap
sx={{
'--List-gap': '8px',
'--ListItem-radius': '20px',
}}
>
{[
'Pepperoni',
'Cheese',
'Olives',
'Tomatoes',
'Fried Bacon',
'Spinach',
].map((item, index) => (
<ListItem key={item}>
<Checkbox
disabled={index === 0}
overlay
disableIcon
variant="soft"
label={item}
/>
</ListItem>
))}
</List>
</div>
</Box>
);
}
| 1,034 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IconsCheckbox.js | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import Close from '@mui/icons-material/Close';
export default function IconsCheckbox() {
return (
<Checkbox uncheckedIcon={<Close />} label="I have an icon when unchecked" />
);
}
| 1,035 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IconsCheckbox.tsx | import * as React from 'react';
import Checkbox from '@mui/joy/Checkbox';
import Close from '@mui/icons-material/Close';
export default function IconsCheckbox() {
return (
<Checkbox uncheckedIcon={<Close />} label="I have an icon when unchecked" />
);
}
| 1,036 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IconsCheckbox.tsx.preview | <Checkbox uncheckedIcon={<Close />} label="I have an icon when unchecked" /> | 1,037 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IndeterminateCheckbox.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function IndeterminateCheckbox() {
const [checked, setChecked] = React.useState([true, false]);
const handleChange1 = (event) => {
setChecked([event.target.checked, event.target.checked]);
};
const handleChange2 = (event) => {
setChecked([event.target.checked, checked[1]]);
};
const handleChange3 = (event) => {
setChecked([checked[0], event.target.checked]);
};
const children = (
<Box sx={{ display: 'flex', flexDirection: 'column', ml: 3, gap: 1, mt: 1 }}>
<Checkbox checked={checked[0]} onChange={handleChange2} label="Child 1" />
<Checkbox checked={checked[1]} onChange={handleChange3} label="Child 2" />
</Box>
);
return (
<div>
<Checkbox
label="Parent"
checked={checked[0] && checked[1]}
indeterminate={checked[0] !== checked[1]}
onChange={handleChange1}
/>
{children}
</div>
);
}
| 1,038 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IndeterminateCheckbox.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
export default function IndeterminateCheckbox() {
const [checked, setChecked] = React.useState([true, false]);
const handleChange1 = (event: React.ChangeEvent<HTMLInputElement>) => {
setChecked([event.target.checked, event.target.checked]);
};
const handleChange2 = (event: React.ChangeEvent<HTMLInputElement>) => {
setChecked([event.target.checked, checked[1]]);
};
const handleChange3 = (event: React.ChangeEvent<HTMLInputElement>) => {
setChecked([checked[0], event.target.checked]);
};
const children = (
<Box sx={{ display: 'flex', flexDirection: 'column', ml: 3, gap: 1, mt: 1 }}>
<Checkbox checked={checked[0]} onChange={handleChange2} label="Child 1" />
<Checkbox checked={checked[1]} onChange={handleChange3} label="Child 2" />
</Box>
);
return (
<div>
<Checkbox
label="Parent"
checked={checked[0] && checked[1]}
indeterminate={checked[0] !== checked[1]}
onChange={handleChange1}
/>
{children}
</div>
);
}
| 1,039 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/IndeterminateCheckbox.tsx.preview | <Checkbox
label="Parent"
checked={checked[0] && checked[1]}
indeterminate={checked[0] !== checked[1]}
onChange={handleChange1}
/>
{children} | 1,040 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/OverlayCheckbox.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
import Sheet from '@mui/joy/Sheet';
export default function OverlayCheckbox() {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
width: 300,
'& > div': { p: 2, borderRadius: 'md', display: 'flex' },
}}
>
<Sheet variant="outlined">
<Checkbox overlay label="Focus on me" />
</Sheet>
<Sheet variant="outlined">
<Checkbox
label="My parent receives focus"
overlay
// Force the outline to appear in the demo. Usually, you don't need this in your project.
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
</Sheet>
</Box>
);
}
| 1,041 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/OverlayCheckbox.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Checkbox, { checkboxClasses } from '@mui/joy/Checkbox';
import Sheet from '@mui/joy/Sheet';
export default function OverlayCheckbox() {
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
gap: 2,
width: 300,
'& > div': { p: 2, borderRadius: 'md', display: 'flex' },
}}
>
<Sheet variant="outlined">
<Checkbox overlay label="Focus on me" />
</Sheet>
<Sheet variant="outlined">
<Checkbox
label="My parent receives focus"
overlay
// Force the outline to appear in the demo. Usually, you don't need this in your project.
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
</Sheet>
</Box>
);
}
| 1,042 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/OverlayCheckbox.tsx.preview | <Sheet variant="outlined">
<Checkbox overlay label="Focus on me" />
</Sheet>
<Sheet variant="outlined">
<Checkbox
label="My parent receives focus"
overlay
// Force the outline to appear in the demo. Usually, you don't need this in your project.
slotProps={{ action: { className: checkboxClasses.focusVisible } }}
/>
</Sheet> | 1,043 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/checkbox/checkbox.md | ---
productId: joy-ui
title: React Checkbox component
components: Checkbox
githubLabel: 'component: checkbox'
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/
---
# Checkbox
<p class="description">Checkboxes give users binary choices when presented with multiple options in a series.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
Checkboxes provide users with a graphical representation of a binary choice (yes or no, on or off).
They are most commonly presented in a series, giving the user multiple choices to make.
The Joy UI Checkbox component replaces the native HTML `<input type="checkbox">` element and offers expanded options for styling and accessibility.
{{"demo": "CheckboxUsage.js", "hideToolbar": true, "bg": "gradient"}}
:::success
When should you use checkboxes rather than switches or radio buttons?
- Use a switch to provide the user with **a single binary choice**—checkboxes are preferable when you need to give the user multiple binary choices.
- Use radio buttons to give the user **mutually exclusive options**—checkboxes are preferable when you need to let the user select one, some, all, or none from a series of options.
:::
## Basics
```jsx
import Checkbox from '@mui/joy/Checkbox';
```
The basic Checkbox component is a single input set to the unchecked state.
Use the `label` prop to provide text, and add `defaultChecked` when the input should be checked by default.
{{"demo": "BasicCheckbox.js"}}
## Customization
### Variants
The Checkbox component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `solid`, `soft`, `outlined`, and `plain`. By default, when unchecked, the Checkbox is set to `outlined`;
when checked, the variant changes to `solid`.
Adding the `variant` prop to your Checkbox overrides this default behavior. Try checking and unchecking the Checkboxes in the demo below to see the differences:
{{"demo": "CheckboxVariants.js"}}
:::info
To learn how to add your own variants, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants).
Note that you lose the global variants when you add custom variants.
:::
### Sizes
The Checkbox component comes in three sizes: `sm`, `md` (default), and `lg`.
{{"demo": "CheckboxSizes.js"}}
:::info
To learn how to add custom sizes to the component, check out [Themed components—Extend sizes](/joy-ui/customization/themed-components/#extend-sizes).
:::
### Colors
Every palette included in the theme is available via the `color` prop.
{{"demo": "CheckboxColors.js"}}
### Icons
By default, the Checkbox component is empty when unchecked.
Use the `uncheckedIcon` prop to add a custom icon for the unchecked state.
You can also use `checkedIcon` to customize the checked state.
{{"demo": "IconsCheckbox.js"}}
#### Appear on hover
You can use the `uncheckedIcon` as a "preview" of the checked state by making it appear when the user hovers over the empty Checkbox.
The demo below shows how to target the icon by using the `svg` selector and apply `opacity` for a smooth effect:
{{"demo": "HoverCheckbox.js"}}
#### No icons
Use the `disableIcon` prop to remove the icon entirely.
In this case, the state of the Checkbox is communicated through the type of variant applied to the label.
Try clicking on the Checkbox labels in the demo below to see how this works:
{{"demo": "IconlessCheckbox.js"}}
### Focus outline
By default, the focus outline wraps both the Checkbox input and its label.
To set the focus outline so that it only wraps the input, target the `checkboxClasses.checkbox` class and add `position: 'relative'`, as shown in the demo below:
{{"demo": "FocusCheckbox.js"}}
### Clickable container
Use the `overlay` prop to shift the focus outline from the Checkbox to its container, making the entire container clickable to toggle the state of the Checkbox.
This works with any wrapper element with [positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/position#types_of_positioning)—the demo below uses [Sheet](/joy-ui/react-sheet/) (by default, it has `relative` position):
{{"demo": "OverlayCheckbox.js"}}
### Indeterminate
The default Checkbox is _dual-state:_ the user can toggle between checked and unchecked.
There is also the option for a _tri-state_ or indeterminate Checkbox that supports a state known as "partially checked."
This indeterminate state is often used to communicate the fact that only some out of a set of Checkboxes are checked.
As such, it's usually reserved for parent Checkboxes that can control the states of their children.
The demo below shows how to implement the `indeterminate` prop on a parent Checkbox that watches for the checked state in its children.
If only one child is checked, then the parent displays the indeterminate state.
Clicking on the parent Checkbox toggles selecting and deselecting all children.
:::warning
When the indeterminate state is set, the value of the `checked` prop only impacts form-submitted values.
It has no accessibility or UX implications.
:::
{{"demo": "IndeterminateCheckbox.js"}}
### Helper text
```jsx
import FormControl from '@mui/joy/FormControl';
import FormHelperText from '@mui/joy/FormHelperText';
```
Use the Form Control and Form Helper Text components add a description to the Checkbox.
The Checkbox will be linked to the helper text via the `aria-describedby` attribute.
{{"demo": "HelperTextCheckbox.js"}}
### Group
To group multiple Checkboxes, wrap them in a container component like Box with `role="group"`.
Combine with the [List](/joy-ui/react-list/) component to ensure consistent spacing and enable screen readers to interpret the Checkbox group as a list.
Learn more about accessible design patterns for checkboxes [in the W3C documentation](https://www.w3.org/WAI/ARIA/apg/patterns/checkbox/examples/checkbox-mixed/).
{{"demo": "GroupCheckboxes.js"}}
## Common examples
### Sign-up checkbox
To use an interactive element together with a Checkbox, you can wrap it with a FormControl and FormHelperText.
{{"demo": "ExampleSignUpCheckbox.js"}}
:::info
It is recommended that the interactive elements such as link should be placed outside of the checkbox's label.
To learn more, [visit HTML label](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#accessibility_concerns) from Mozilla.
:::
### Filtering status
This example uses variants and colors available to the List Item and Checkbox components to communicate state changes.
{{"demo": "ExampleFilterStatusCheckbox.js"}}
### Filtering members
This example uses the CSS `flexDirection: 'rowReverse'` property to position the label and icon.
Don't forget to use the `label` prop to ensure proper Checkbox accessibility.
{{"demo": "ExampleFilterMemberCheckbox.js"}}
### Choice chips
You can use Checkbox to recreate a kind of [Chip](/joy-ui/react-chip/) component, which is commonly implemented in the form of a group of filtering options.
{{"demo": "ExampleChoiceChipCheckbox.js"}}
### Viewport checklist
{{"demo": "ExampleButtonCheckbox.js"}}
## Anatomy
The Checkbox component is composed of a root `<span>` that wraps the input and `<label>` (if present).
Note that the actual `<input type="checkbox">` is doubly nested within `<span>` elements that represent the `checkbox` and `action` slots, respectively.
```html
<span class="MuiCheckbox-root">
<span class="MuiCheckbox-checkbox">
<span class="MuiCheckbox-action">
<input type="checkbox" class="MuiCheckbox-input" value />
</span>
</span>
<label class="MuiCheckbox-label">
<!-- label text -->
</label>
</span>
```
| 1,044 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/BasicChip.js | import * as React from 'react';
import Chip from '@mui/joy/Chip';
export default function BasicChip() {
return (
<div>
<Chip>This is a chip</Chip>
</div>
);
}
| 1,045 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/BasicChip.tsx | import * as React from 'react';
import Chip from '@mui/joy/Chip';
export default function BasicChip() {
return (
<div>
<Chip>This is a chip</Chip>
</div>
);
}
| 1,046 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/BasicChip.tsx.preview | <Chip>This is a chip</Chip> | 1,047 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/CheckboxChip.js | import CheckIcon from '@mui/icons-material/Check';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
import Chip from '@mui/joy/Chip';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
export default function CheckboxChip() {
const [selected, setSelected] = React.useState([]);
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<div>
<Typography level="title-lg" id="fav-movie" mb={2}>
Favorite Movies
</Typography>
<Box
role="group"
aria-labelledby="fav-movie"
sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}
>
{[
'Star trek',
'Batman',
'Spider man',
'Eternals',
'Shang chi',
'Jungle cruise',
'No time to die',
'Thor',
'The hulk',
].map((name) => {
const checked = selected.includes(name);
return (
<Chip
key={name}
variant="plain"
color={checked ? 'primary' : 'neutral'}
startDecorator={
checked && <CheckIcon sx={{ zIndex: 1, pointerEvents: 'none' }} />
}
>
<Checkbox
variant="outlined"
color={checked ? 'primary' : 'neutral'}
disableIcon
overlay
label={name}
checked={checked}
onChange={(event) => {
setSelected((names) =>
!event.target.checked
? names.filter((n) => n !== name)
: [...names, name],
);
}}
/>
</Chip>
);
})}
</Box>
</div>
</Box>
);
}
| 1,048 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/CheckboxChip.tsx | import CheckIcon from '@mui/icons-material/Check';
import Box from '@mui/joy/Box';
import Checkbox from '@mui/joy/Checkbox';
import Chip from '@mui/joy/Chip';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
export default function CheckboxChip() {
const [selected, setSelected] = React.useState<string[]>([]);
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<div>
<Typography level="title-lg" id="fav-movie" mb={2}>
Favorite Movies
</Typography>
<Box
role="group"
aria-labelledby="fav-movie"
sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}
>
{[
'Star trek',
'Batman',
'Spider man',
'Eternals',
'Shang chi',
'Jungle cruise',
'No time to die',
'Thor',
'The hulk',
].map((name) => {
const checked = selected.includes(name);
return (
<Chip
key={name}
variant="plain"
color={checked ? 'primary' : 'neutral'}
startDecorator={
checked && <CheckIcon sx={{ zIndex: 1, pointerEvents: 'none' }} />
}
>
<Checkbox
variant="outlined"
color={checked ? 'primary' : 'neutral'}
disableIcon
overlay
label={name}
checked={checked}
onChange={(event) => {
setSelected((names) =>
!event.target.checked
? names.filter((n) => n !== name)
: [...names, name],
);
}}
/>
</Chip>
);
})}
</Box>
</div>
</Box>
);
}
| 1,049 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ChipUsage.js | import * as React from 'react';
import Chip from '@mui/joy/Chip';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function ChipUsage() {
return (
<JoyUsageDemo
componentName="Chip"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'soft',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'neutral',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'disabled',
knob: 'switch',
defaultValue: false,
},
{ propName: 'onClick', defaultValue: () => {} },
]}
renderDemo={(props) => <Chip {...props}>Chip</Chip>}
/>
);
}
| 1,050 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ChipVariables.js | import * as React from 'react';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import ChipDelete from '@mui/joy/ChipDelete';
import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo';
export default function ChipVariables() {
return (
<JoyVariablesDemo
componentName="Chip"
renderCode={(formattedSx) => `<Chip
startDecorator={<Avatar />}
endDecorator={<ChipDelete />}${formattedSx ? `${formattedSx}>` : '\n>'}`}
data={[
{
var: '--Chip-minHeight',
defaultValue: '32px',
},
{
var: '--Chip-radius',
defaultValue: '24px',
},
{
var: '--Chip-gap',
defaultValue: '6px',
},
{
var: '--Chip-paddingInline',
defaultValue: '12px',
},
{
var: '--Chip-decoratorChildHeight',
defaultValue: '24px',
},
]}
renderDemo={(sx) => (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 1,
}}
>
<Chip variant="soft" color="danger" sx={sx}>
Some text
</Chip>
<Chip
startDecorator={<Avatar src="/static/images/avatar/1.jpg" />}
endDecorator={<ChipDelete />}
sx={sx}
>
Person name
</Chip>
<Chip
variant="outlined"
color="neutral"
startDecorator={<Avatar src="/static/images/avatar/1.jpg" />}
endDecorator={<ChipDelete />}
sx={sx}
>
Person name
</Chip>
</Box>
)}
/>
);
}
| 1,051 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ChipWithDecorators.js | import Cloud from '@mui/icons-material/Cloud';
import Sun from '@mui/icons-material/LightMode';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import * as React from 'react';
export default function ChipWithDecorators() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip variant="soft" startDecorator={<Sun />}>
Today is sunny
</Chip>
<Chip variant="soft" startDecorator={<Cloud />}>
Tomorrow is cloudy
</Chip>
</Box>
);
}
| 1,052 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ChipWithDecorators.tsx | import Cloud from '@mui/icons-material/Cloud';
import Sun from '@mui/icons-material/LightMode';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import * as React from 'react';
export default function ChipWithDecorators() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip variant="soft" startDecorator={<Sun />}>
Today is sunny
</Chip>
<Chip variant="soft" startDecorator={<Cloud />}>
Tomorrow is cloudy
</Chip>
</Box>
);
}
| 1,053 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ChipWithDecorators.tsx.preview | <Chip variant="soft" startDecorator={<Sun />}>
Today is sunny
</Chip>
<Chip variant="soft" startDecorator={<Cloud />}>
Tomorrow is cloudy
</Chip> | 1,054 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableAndDeletableChip.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import ChipDelete from '@mui/joy/ChipDelete';
import DeleteForever from '@mui/icons-material/DeleteForever';
export default function ClickableAndDeletableChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
variant="outlined"
color="danger"
onClick={() => alert('You clicked the chip!')}
endDecorator={
<ChipDelete
color="danger"
variant="plain"
onClick={() => alert('You clicked the delete button!')}
>
<DeleteForever />
</ChipDelete>
}
>
Clear
</Chip>
</Box>
);
}
| 1,055 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableAndDeletableChip.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import ChipDelete from '@mui/joy/ChipDelete';
import DeleteForever from '@mui/icons-material/DeleteForever';
export default function ClickableAndDeletableChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
variant="outlined"
color="danger"
onClick={() => alert('You clicked the chip!')}
endDecorator={
<ChipDelete
color="danger"
variant="plain"
onClick={() => alert('You clicked the delete button!')}
>
<DeleteForever />
</ChipDelete>
}
>
Clear
</Chip>
</Box>
);
}
| 1,056 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableAndDeletableChip.tsx.preview | <Chip
variant="outlined"
color="danger"
onClick={() => alert('You clicked the chip!')}
endDecorator={
<ChipDelete
color="danger"
variant="plain"
onClick={() => alert('You clicked the delete button!')}
>
<DeleteForever />
</ChipDelete>
}
>
Clear
</Chip> | 1,057 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableChip.js | import CheckIcon from '@mui/icons-material/Check';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import * as React from 'react';
export default function ClickableChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
variant="outlined"
color="neutral"
size="lg"
startDecorator={<Avatar size="sm" src={`/static/images/avatar/1.jpg`} />}
endDecorator={<CheckIcon fontSize="md" />}
onClick={() => alert('You clicked the Joy Chip!')}
>
Mark
</Chip>
</Box>
);
}
| 1,058 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableChip.tsx | import CheckIcon from '@mui/icons-material/Check';
import Avatar from '@mui/joy/Avatar';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import * as React from 'react';
export default function ClickableChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
variant="outlined"
color="neutral"
size="lg"
startDecorator={<Avatar size="sm" src={`/static/images/avatar/1.jpg`} />}
endDecorator={<CheckIcon fontSize="md" />}
onClick={() => alert('You clicked the Joy Chip!')}
>
Mark
</Chip>
</Box>
);
}
| 1,059 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/ClickableChip.tsx.preview | <Chip
variant="outlined"
color="neutral"
size="lg"
startDecorator={<Avatar size="sm" src={`/static/images/avatar/1.jpg`} />}
endDecorator={<CheckIcon fontSize="md" />}
onClick={() => alert('You clicked the Joy Chip!')}
>
Mark
</Chip> | 1,060 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/DeleteButtonChip.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import ChipDelete from '@mui/joy/ChipDelete';
export default function DeleteButtonChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
size="sm"
variant="outlined"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Remove
</Chip>
<Chip
variant="soft"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Delete
</Chip>
<Chip
size="lg"
variant="solid"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Delete
</Chip>
</Box>
);
}
| 1,061 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/DeleteButtonChip.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import ChipDelete from '@mui/joy/ChipDelete';
export default function DeleteButtonChip() {
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<Chip
size="sm"
variant="outlined"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Remove
</Chip>
<Chip
variant="soft"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Delete
</Chip>
<Chip
size="lg"
variant="solid"
color="danger"
endDecorator={<ChipDelete onDelete={() => alert('Delete')} />}
>
Delete
</Chip>
</Box>
);
}
| 1,062 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/LinkChip.js | import * as React from 'react';
import Chip from '@mui/joy/Chip';
export default function LinkChip() {
return (
<Chip slotProps={{ action: { component: 'a', href: '#as-link' } }}>
Anchor chip
</Chip>
);
}
| 1,063 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/LinkChip.tsx | import * as React from 'react';
import Chip from '@mui/joy/Chip';
export default function LinkChip() {
return (
<Chip slotProps={{ action: { component: 'a', href: '#as-link' } }}>
Anchor chip
</Chip>
);
}
| 1,064 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/LinkChip.tsx.preview | <Chip slotProps={{ action: { component: 'a', href: '#as-link' } }}>
Anchor chip
</Chip> | 1,065 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/RadioChip.js | import CheckIcon from '@mui/icons-material/Check';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
export default function RadioChip() {
const [selected, setSelected] = React.useState('');
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<div>
<Typography level="title-lg" id="best-movie" mb={2}>
Best Movie
</Typography>
<RadioGroup
name="best-movie"
aria-labelledby="best-movie"
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 1 }}
>
{[
'Star trek',
'Batman',
'Spider man',
'Eternals',
'Shang chi',
'Jungle cruise',
'No time to die',
'Thor',
'The hulk',
].map((name) => {
const checked = selected === name;
return (
<Chip
key={name}
variant="plain"
color={checked ? 'primary' : 'neutral'}
startDecorator={
checked && <CheckIcon sx={{ zIndex: 1, pointerEvents: 'none' }} />
}
>
<Radio
variant="outlined"
color={checked ? 'primary' : 'neutral'}
disableIcon
overlay
label={name}
value={name}
checked={checked}
onChange={(event) => {
if (event.target.checked) {
setSelected(name);
}
}}
/>
</Chip>
);
})}
</RadioGroup>
</div>
</Box>
);
}
| 1,066 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/RadioChip.tsx | import CheckIcon from '@mui/icons-material/Check';
import Box from '@mui/joy/Box';
import Chip from '@mui/joy/Chip';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Typography from '@mui/joy/Typography';
import * as React from 'react';
export default function RadioChip() {
const [selected, setSelected] = React.useState('');
return (
<Box sx={{ display: 'flex', gap: 1, alignItems: 'center' }}>
<div>
<Typography level="title-lg" id="best-movie" mb={2}>
Best Movie
</Typography>
<RadioGroup
name="best-movie"
aria-labelledby="best-movie"
orientation="horizontal"
sx={{ flexWrap: 'wrap', gap: 1 }}
>
{[
'Star trek',
'Batman',
'Spider man',
'Eternals',
'Shang chi',
'Jungle cruise',
'No time to die',
'Thor',
'The hulk',
].map((name) => {
const checked = selected === name;
return (
<Chip
key={name}
variant="plain"
color={checked ? 'primary' : 'neutral'}
startDecorator={
checked && <CheckIcon sx={{ zIndex: 1, pointerEvents: 'none' }} />
}
>
<Radio
variant="outlined"
color={checked ? 'primary' : 'neutral'}
disableIcon
overlay
label={name}
value={name}
checked={checked}
onChange={(event) => {
if (event.target.checked) {
setSelected(name);
}
}}
/>
</Chip>
);
})}
</RadioGroup>
</div>
</Box>
);
}
| 1,067 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/chip/chip.md | ---
productId: joy-ui
title: React Chip component
components: Chip, ChipDelete
githubLabel: 'component: chip'
---
# Chip
<p class="description">Chip generates a compact element that can represent an input, attribute, or action.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
Chips are most frequently used in two main use cases: as pills of informative content or as filtering options.
{{"demo": "ChipUsage.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 Chip from '@mui/joy/Chip';
export default function MyApp() {
return <Chip>My chip</Chip>;
}
```
### Basic usage
Chips comes with medium size, primary color, and solid variant set by default.
{{"demo": "BasicChip.js"}}
### Decorators
Use the `startDecorator` and/or `endDecorator` props to add supporting icons to the chip.
{{"demo": "ChipWithDecorators.js"}}
### Delete button
To add a delete action inside a chip, use the complementary `ChipDelete` component.
The `onDelete` callback is fired on `ChipDelete` either when:
- `Backspace`, `Enter` or `Delete` is pressed.
- The `ChipDelete` is clicked.
```jsx
import ChipDelete from '@mui/joy/ChipDelete';
```
{{"demo": "DeleteButtonChip.js"}}
### As a link
You can also use the chip component as a link by assigning a value of `a` to the `component` prop.
Since links are the most appropriate component for navigating through pages, that's useful when you want the same chip design for a link.
Doing so will automatically change the rendered HTML tag from `<div>` to `<a>`.
{{"demo": "LinkChip.js"}}
### Clickable
To make chips clickable, pass a function to the `onClick` prop.
{{"demo": "ClickableChip.js"}}
### Clickable and deletable
Use both the `onClick` prop and the complementary `ChipDelete` component to make a chip support two actions.
{{"demo": "ClickableAndDeletableChip.js"}}
### With radio
Common to filtering UIs, wrap the `Radio` component with the `Chip` to use them together.
Use radios when you want to enable single selection.
{{"demo": "RadioChip.js"}}
### With a checkbox
Similar to the above, wrap the `Checkbox` component with the `Chip` to use them together.
Use checkboxes when you want to enable multiple selection.
{{"demo": "CheckboxChip.js"}}
## CSS variables playground
Play around with all the CSS variables available in the slider component to see how the design changes.
You can use those to customize the component on both the `sx` prop and the theme.
{{"demo": "ChipVariables.js", "hideToolbar": true, "bg": "gradient"}}
| 1,068 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressButton.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Link from '@mui/joy/Link';
import IconButton from '@mui/joy/IconButton';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressButton() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Button startDecorator={<CircularProgress variant="solid" />}>Loading…</Button>
<IconButton>
<CircularProgress />
</IconButton>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link
component="button"
variant="plain"
startDecorator={<CircularProgress />}
sx={{ p: 1 }}
>
Submitting...
</Link>
</Box>
);
}
| 1,069 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressButton.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Link from '@mui/joy/Link';
import IconButton from '@mui/joy/IconButton';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressButton() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<Button startDecorator={<CircularProgress variant="solid" />}>Loading…</Button>
<IconButton>
<CircularProgress />
</IconButton>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link
component="button"
variant="plain"
startDecorator={<CircularProgress />}
sx={{ p: 1 }}
>
Submitting...
</Link>
</Box>
);
}
| 1,070 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressButton.tsx.preview | <Button startDecorator={<CircularProgress variant="solid" />}>Loading…</Button>
<IconButton>
<CircularProgress />
</IconButton>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<Link
component="button"
variant="plain"
startDecorator={<CircularProgress />}
sx={{ p: 1 }}
>
Submitting...
</Link> | 1,071 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressChildren.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import ReportIcon from '@mui/icons-material/Report';
import WarningIcon from '@mui/icons-material/Warning';
export default function CircularProgressChildren() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress color="warning">
<WarningIcon color="warning" />
</CircularProgress>
<CircularProgress size="lg" determinate value={66.67}>
2 / 3
</CircularProgress>
<CircularProgress color="danger" sx={{ '--CircularProgress-size': '80px' }}>
<ReportIcon color="danger" />
</CircularProgress>
</Box>
);
}
| 1,072 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressChildren.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import ReportIcon from '@mui/icons-material/Report';
import WarningIcon from '@mui/icons-material/Warning';
export default function CircularProgressChildren() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress color="warning">
<WarningIcon color="warning" />
</CircularProgress>
<CircularProgress size="lg" determinate value={66.67}>
2 / 3
</CircularProgress>
<CircularProgress color="danger" sx={{ '--CircularProgress-size': '80px' }}>
<ReportIcon color="danger" />
</CircularProgress>
</Box>
);
}
| 1,073 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressChildren.tsx.preview | <CircularProgress color="warning">
<WarningIcon color="warning" />
</CircularProgress>
<CircularProgress size="lg" determinate value={66.67}>
2 / 3
</CircularProgress>
<CircularProgress color="danger" sx={{ '--CircularProgress-size': '80px' }}>
<ReportIcon color="danger" />
</CircularProgress> | 1,074 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressColors.js | import Typography from '@mui/joy/Typography';
import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';
export default function CircularProgressColors() {
const [variant, setVariant] = React.useState('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 3,
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(150px, 1fr))',
gap: 1,
}}
>
<CircularProgress variant={variant} color="primary" />
<CircularProgress variant={variant} color="neutral" />
<CircularProgress variant={variant} color="danger" />
<CircularProgress variant={variant} color="success" />
<CircularProgress variant={variant} color="warning" />
</Box>
<Sheet
sx={{
background: 'transparent',
pl: 4,
borderLeft: '1px solid',
borderColor: 'divider',
}}
>
<Typography
level="body-sm"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
| 1,075 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressColors.tsx | import Typography from '@mui/joy/Typography';
import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import { VariantProp } from '@mui/joy';
import Radio from '@mui/joy/Radio';
import RadioGroup from '@mui/joy/RadioGroup';
import Sheet from '@mui/joy/Sheet';
export default function CircularProgressColors() {
const [variant, setVariant] = React.useState<VariantProp>('solid');
return (
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 3,
}}
>
<Box
sx={{
display: 'grid',
gridTemplateColumns: 'repeat(3, minmax(150px, 1fr))',
gap: 1,
}}
>
<CircularProgress variant={variant} color="primary" />
<CircularProgress variant={variant} color="neutral" />
<CircularProgress variant={variant} color="danger" />
<CircularProgress variant={variant} color="success" />
<CircularProgress variant={variant} color="warning" />
</Box>
<Sheet
sx={{
background: 'transparent',
pl: 4,
borderLeft: '1px solid',
borderColor: 'divider',
}}
>
<Typography
level="body-sm"
fontWeight="xl"
id="variant-label"
textColor="text.primary"
mb={1}
>
Variant:
</Typography>
<RadioGroup
size="sm"
aria-labelledby="variant-label"
name="variant"
value={variant}
onChange={(event) => setVariant(event.target.value as VariantProp)}
>
<Radio label="Solid" value="solid" />
<Radio label="Soft" value="soft" />
<Radio label="Outlined" value="outlined" />
<Radio label="Plain" value="plain" />
</RadioGroup>
</Sheet>
</Box>
);
}
| 1,076 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressCountUp.js | import * as React from 'react';
import Stack from '@mui/joy/Stack';
import Button from '@mui/joy/Button';
import Typography from '@mui/joy/Typography';
import CircularProgress from '@mui/joy/CircularProgress';
import { useCountUp } from 'use-count-up';
export default function CircularProgressCountUp() {
const [isLoading, setIsLoading] = React.useState(false);
const [buttonLabel, setButtonLabel] = React.useState('Start');
const { value: value1, reset: resetValue1 } = useCountUp({
isCounting: isLoading,
duration: 1,
start: 0,
end: 25,
onComplete: () => {
setIsLoading(false);
setButtonLabel('Reset');
},
});
const { value: value2, reset } = useCountUp({
isCounting: true,
duration: 1,
start: 0,
end: 75,
});
const handleButtonClick = () => {
if (isLoading) {
setIsLoading(false);
setButtonLabel('Start');
resetValue1();
} else if (buttonLabel === 'Reset') {
setButtonLabel('Start');
resetValue1();
} else {
setIsLoading(true);
setButtonLabel('Reset');
}
};
return (
<Stack direction="row" alignItems="center" flexWrap="wrap" spacing={8}>
<Stack spacing={2}>
<CircularProgress size="lg" determinate value={value1}>
<Typography>{value1}%</Typography>
</CircularProgress>
<Button
size="sm"
variant="outlined"
color="neutral"
onClick={handleButtonClick}
>
{buttonLabel}
</Button>
</Stack>
<Stack spacing={2}>
<CircularProgress size="lg" determinate value={value2}>
<Typography>{value2}%</Typography>
</CircularProgress>
<Button size="sm" variant="outlined" color="neutral" onClick={reset}>
Reload
</Button>
</Stack>
</Stack>
);
}
| 1,077 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressCountUp.tsx | import * as React from 'react';
import Stack from '@mui/joy/Stack';
import Button from '@mui/joy/Button';
import Typography from '@mui/joy/Typography';
import CircularProgress from '@mui/joy/CircularProgress';
import { useCountUp } from 'use-count-up';
export default function CircularProgressCountUp() {
const [isLoading, setIsLoading] = React.useState(false);
const [buttonLabel, setButtonLabel] = React.useState('Start');
const { value: value1, reset: resetValue1 } = useCountUp({
isCounting: isLoading,
duration: 1,
start: 0,
end: 25,
onComplete: () => {
setIsLoading(false);
setButtonLabel('Reset');
},
});
const { value: value2, reset } = useCountUp({
isCounting: true,
duration: 1,
start: 0,
end: 75,
});
const handleButtonClick = () => {
if (isLoading) {
setIsLoading(false);
setButtonLabel('Start');
resetValue1();
} else if (buttonLabel === 'Reset') {
setButtonLabel('Start');
resetValue1();
} else {
setIsLoading(true);
setButtonLabel('Reset');
}
};
return (
<Stack direction="row" alignItems="center" flexWrap="wrap" spacing={8}>
<Stack spacing={2}>
<CircularProgress size="lg" determinate value={value1 as number}>
<Typography>{value1}%</Typography>
</CircularProgress>
<Button
size="sm"
variant="outlined"
color="neutral"
onClick={handleButtonClick}
>
{buttonLabel}
</Button>
</Stack>
<Stack spacing={2}>
<CircularProgress size="lg" determinate value={value2 as number}>
<Typography>{value2}%</Typography>
</CircularProgress>
<Button size="sm" variant="outlined" color="neutral" onClick={reset}>
Reload
</Button>
</Stack>
</Stack>
);
}
| 1,078 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressDeterminate.js | import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import * as React from 'react';
export default function CircularProgressDeterminate() {
const [progress, setProgress] = React.useState(0);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress determinate value={25} />
<CircularProgress determinate value={50} />
<CircularProgress determinate value={75} />
<CircularProgress determinate value={100} />
<CircularProgress determinate value={progress} />
</Box>
);
}
| 1,079 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressDeterminate.tsx | import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
import * as React from 'react';
export default function CircularProgressDeterminate() {
const [progress, setProgress] = React.useState(0);
React.useEffect(() => {
const timer = setInterval(() => {
setProgress((prevProgress) => (prevProgress >= 100 ? 0 : prevProgress + 10));
}, 800);
return () => {
clearInterval(timer);
};
}, []);
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress determinate value={25} />
<CircularProgress determinate value={50} />
<CircularProgress determinate value={75} />
<CircularProgress determinate value={100} />
<CircularProgress determinate value={progress} />
</Box>
);
}
| 1,080 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressDeterminate.tsx.preview | <CircularProgress determinate value={25} />
<CircularProgress determinate value={50} />
<CircularProgress determinate value={75} />
<CircularProgress determinate value={100} />
<CircularProgress determinate value={progress} /> | 1,081 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressSizes.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress size="sm" />
<CircularProgress size="md" />
<CircularProgress size="lg" />
</Box>
);
}
| 1,082 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressSizes.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressSizes() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress size="sm" />
<CircularProgress size="md" />
<CircularProgress size="lg" />
</Box>
);
}
| 1,083 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressSizes.tsx.preview | <CircularProgress size="sm" />
<CircularProgress size="md" />
<CircularProgress size="lg" /> | 1,084 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressThickness.js | import * as React from 'react';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressThickness() {
return <CircularProgress thickness={1} />;
}
| 1,085 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressUsage.js | import * as React from 'react';
import CircularProgress from '@mui/joy/CircularProgress';
import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo';
export default function CircularProgressUsage() {
return (
<JoyUsageDemo
componentName="CircularProgress"
data={[
{
propName: 'variant',
knob: 'radio',
defaultValue: 'soft',
options: ['plain', 'outlined', 'soft', 'solid'],
},
{
propName: 'color',
knob: 'color',
defaultValue: 'primary',
},
{
propName: 'size',
knob: 'radio',
options: ['sm', 'md', 'lg'],
defaultValue: 'md',
},
{
propName: 'determinate',
knob: 'switch',
defaultValue: false,
},
{
propName: 'value',
knob: 'number',
defaultValue: 25,
},
]}
renderDemo={(props) => <CircularProgress {...props} />}
/>
);
}
| 1,086 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressVariables.js | import * as React from 'react';
import CircularProgress from '@mui/joy/CircularProgress';
import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo';
export default function CircularProgressVariables() {
return (
<JoyVariablesDemo
componentName="CircularProgress"
data={[
{
var: '--CircularProgress-size',
defaultValue: '40px',
helperText: 'Supports only `px` unit',
},
{
var: '--CircularProgress-trackThickness',
defaultValue: '6px',
},
{
var: '--CircularProgress-progressThickness',
defaultValue: '6px',
},
]}
renderDemo={(sx) => <CircularProgress sx={sx} />}
/>
);
}
| 1,087 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressVariants.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress variant="solid" />
<CircularProgress variant="soft" />
<CircularProgress variant="outlined" />
<CircularProgress variant="plain" />
</Box>
);
}
| 1,088 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressVariants.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import CircularProgress from '@mui/joy/CircularProgress';
export default function CircularProgressVariants() {
return (
<Box sx={{ display: 'flex', gap: 2, alignItems: 'center', flexWrap: 'wrap' }}>
<CircularProgress variant="solid" />
<CircularProgress variant="soft" />
<CircularProgress variant="outlined" />
<CircularProgress variant="plain" />
</Box>
);
}
| 1,089 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/CircularProgressVariants.tsx.preview | <CircularProgress variant="solid" />
<CircularProgress variant="soft" />
<CircularProgress variant="outlined" />
<CircularProgress variant="plain" /> | 1,090 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/circular-progress/circular-progress.md | ---
productId: joy-ui
title: React Circular Progress component
components: CircularProgress
githubLabel: 'component: CircularProgress'
---
# Circular Progress
<p class="description">The Circular Progress component showcases the duration of a process or an indefinite wait period.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Introduction
A circular progress indicator, often referred to as a spinner, is a visual representation of the progress of an operation or task.
The Circular Progress component defaults to indeterminate, signifying an undefined wait duration.
Use [determinate](#determinate) mode to indicate how long a given operation will take.
{{"demo": "CircularProgressUsage.js", "hideToolbar": true, "bg": "gradient"}}
:::info
The component's animations rely primarily on CSS to ensure that it functions even before JavaScript loads.
:::
## Basics
```jsx
import CircularProgress from '@mui/joy/CircularProgress';
```
The Circular Progress component provides users with updates on the status of ongoing processes such as loading an app, submitting a form, or saving updates.
## Customization
### Variants
The Circular Progress component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `solid` (default), `soft`, `outlined`, and `plain`.
{{"demo": "CircularProgressVariants.js"}}
### Sizes
Circular Progress comes in three sizes: `sm`, `md` (default), and `lg`.
{{"demo": "CircularProgressSizes.js"}}
:::info
To learn how to add custom sizes to the component, check out [Themed components—Extend sizes](/joy-ui/customization/themed-components/#extend-sizes).
:::
### Colors
Every palette included in the theme is available via the `color` prop.
{{"demo": "CircularProgressColors.js"}}
### Thickness
You can use the `thickness` prop to control the circle's stroke width.
{{"demo": "CircularProgressThickness.js"}}
### Determinate
The `determinate` prop lets you indicate a specified wait time.
{{"demo": "CircularProgressDeterminate.js"}}
### Children
By default, any children nested inside the Circular Progress will be centered.
{{"demo": "CircularProgressChildren.js"}}
:::info
For plain texts and icons, the dimension is relative to the circular progress's CSS variable (`--CircularProgress-size`).
:::
### With a button
The Circular Progress component can be used as a decorator to show loading on a button.
The size of the Circular Progress is controlled by a button, an icon button, or a link unless the `size` prop is explicitly specified on the progress.
{{"demo": "CircularProgressButton.js"}}
## Third-party integrations
### use-count-up
Use the `useCountUp` hook from the [use-count-up](https://www.npmjs.com/package/use-count-up) package to create a counting animation by providing `start`, `end`, and `duration` values.
{{"demo": "CircularProgressCountUp.js"}}
## CSS variables playground
Play around with all the CSS variables available on the component to see how the design changes.
You can use these to customize the component with both the `sx` prop and the theme.
{{"demo": "CircularProgressVariables.js", "hideToolbar": true, "bg": "gradient"}}
## Accessibility
Out of the box, the `aria-valuenow` attribute will indicate the current value of the progress bar only when the value is not indeterminate.
This attribute will display the value as a percentage.
Here are a few tips to make sure you have an accessible circular progress component:
- When creating your circular progress component, ensure sufficient color contrast between it and the background, using a minimum of [WCAG 2.0's color contrast ratio](https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) of 4.5:1.
- To define a human-readable text alternative to `aria-valuenow`, the `aria-valuetext` will show the current value in a more user-friendly way.
For example, downloading files might be conveyed as `aria-valuetext="8% (34 minutes) remaining`.
- The `aria-valuemin` and `aria-valuemax` attributes are commonly used to indicate the minimum and maximum values of a range.
By default, these attributes are set to 0 and 100, respectively.
If you need to set a different minimum or maximum value for your range, you can use the these attributes to do so.
- Use the `aria-label` or `aria-labelledby` attribute to provide an accessible name for your progress component.
These define the string value or identifies the element(s) that label the progress component.
## Anatomy
The Circular Progress component is composed of a single root `<span>` with an `<svg>` component that wraps around two `<circle>`.
```html
<span role="progressbar" class="MuiCircularProgress-root">
<svg class="MuiCircularProgress-svg">
<circle class="MuiCircularProgress-track"></circle>
<circle class="MuiCircularProgress-progress"></circle>
</svg>
<!-- children are nested here when present -->
</span>
```
| 1,091 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/css-baseline/css-baseline.md | ---
productId: joy-ui
components: CssBaseline, ScopedCssBaseline
githubLabel: 'component: CssBaseline'
---
# CSS Baseline
<p class="description">Joy UI provides a CssBaseline component to kickstart an elegant, consistent, and simple baseline to build upon.</p>
{{"component": "modules/components/ComponentLinkHeader.js", "design": false}}
## Global reset
You might be familiar with [normalize.css](https://github.com/necolas/normalize.css), a collection of HTML element and attribute style-normalizations.
```jsx
import * as React from 'react';
import { CssVarsProvider } from '@mui/joy/styles';
import CssBaseline from '@mui/joy/CssBaseline';
export default function MyApp() {
return (
<CssVarsProvider>
{/* must be used under CssVarsProvider */}
<CssBaseline />
{/* The rest of your application */}
</CssVarsProvider>
);
}
```
## Scoping on children
However, you might be progressively migrating a website to Joy UI, using a global reset might not be an option.
It's possible to apply the baseline only to the children by using the `ScopedCssBaseline` component.
```jsx
import * as React from 'react';
import { CssVarsProvider } from '@mui/joy/styles';
import ScopedCssBaseline from '@mui/joy/ScopedCssBaseline';
import MyApp from './MyApp';
export default function MyApp() {
const [root, setRoot] = React.useState(null);
return (
{/* target the node to ScopedCssBaseline's div */}
<CssVarsProvider colorSchemeNode={root}>
{/* must be used under CssVarsProvider */}
<ScopedCssBaseline ref={(element) => setRoot(element)}>
{/* The rest of your application */}
<MyApp />
</ScopedCssBaseline>
</CssVarsProvider>
);
}
```
:::warning
Make sure you import `ScopedCssBaseline` first to avoid box-sizing conflicts as in the above example.
:::
## Approach
### Page
The `<html>` and `<body>` elements are updated to provide better page-wide defaults. More specifically:
- The margin in all browsers is removed.
- The default Material Design background color is applied.
It's using `theme.palette.background.body` for standard devices and a white background for print devices.
- The CSS [`color-scheme`](https://web.dev/articles/color-scheme) is applied by default. You can disable it by setting `disableColorScheme` to true on the `CssBaseline` or `ScopedCssBaseline`.
### Layout
- `box-sizing` is set globally on the `<html>` element to `border-box`.
Every element—including `*::before` and `*::after` are declared to inherit this property, which ensures that the declared width of the element is never exceeded due to padding or border.
### Color scheme
The CSS [`color-scheme`](https://web.dev/articles/color-scheme) is applied by default to render proper built-in components on the web. You can disable it by setting `disableColorScheme` to true on the `CssBaseline` or `ScopedCssBaseline`.
```jsx
<CssVarsProvider>
<CssBaseline disableColorScheme />
</CssVarsProvider>
// or
<CssVarsProvider>
<ScopedCssBaseline disableColorScheme >
{/* The rest of your application */}
</ScopedCssBaseline>
</CssVarsProvider>
```
### Typography
- No base font-size is declared on the `<html>`, but 16px is assumed (the browser default).
You can learn more about the implications of changing the `<html>` default font size in [the theme documentation](/material-ui/customization/typography/#html-font-size) page.
- Set the default `Typography`'s level (`body1`) style on the `<body>` element. The style comes from `theme.typography.{default typography level prop}`.
- Set the font-weight to `bold` for the `<b>` and `<strong>` elements.
- Custom font-smoothing is enabled for better display of the default font.
## Customization
### CssBaseline
To custom the styles produced by the `CssBaseline` component, append the `GlobalStyles` next to it:
```js
import { CssVarsProvider } from '@mui/joy/styles';
import CssBaseline from '@mui/joy/CssBaseline';
import GlobalStyles from '@mui/joy/GlobalStyles';
function App() {
return (
<CssVarsProvider>
<CssBaseline /> {/* CssBaseline must come first */}
<GlobalStyles
styles={{
// CSS object styles
html: {
// ...
},
body: {
// ...
},
}}
/>
</CssVarsProvider>
);
}
```
### ScopedCssBaseline
You can customize it using the [themed components](https://mui.com/joy-ui/customization/themed-components/) approach. The component identifier is `JoyScopedCssBaseline` which contains only the `root` slot.
```js
import { CssVarsProvider, extendTheme } from '@mui/joy/styles';
import ScopedCssBaseline from '@mui/joy/ScopedCssBaseline';
import MyApp from './MyApp';
const theme = extendTheme({
components: {
JoyScopedCssBaseline: {
styleOverrides: {
root: ({ theme }) => ({
// ...CSS object styles
})
}
}
}
})
export default function MyApp() {
const [root, setRoot] = React.useState(null);
return (
{/* target the node to ScopedCssBaseline's div */}
<CssVarsProvider colorSchemeNode={root}>
{/* must be used under CssVarsProvider */}
<ScopedCssBaseline ref={(element) => setRoot(element)}>
{/* The rest of your application */}
<MyApp />
</ScopedCssBaseline>
</CssVarsProvider>
);
}
```
| 1,092 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerChildPosition.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
import Stack from '@mui/joy/Stack';
import Slider from '@mui/joy/Slider';
import Sheet from '@mui/joy/Sheet';
export default function DividerChildPosition() {
const [position, setPosition] = React.useState(50);
return (
<Box sx={{ width: '100%' }}>
<Stack spacing={1} sx={{ fontSize: 'sm' }}>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
<Divider sx={{ '--Divider-childPosition': `${position}%` }}>
Visual indicator
</Divider>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
</Stack>
<Slider
value={position}
min={0}
max={100}
step={1}
valueLabelDisplay="on"
valueLabelFormat={(value) => `${value}%`}
onChange={(event, value) => setPosition(value)}
/>
</Box>
);
}
| 1,093 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerChildPosition.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Divider from '@mui/joy/Divider';
import Stack from '@mui/joy/Stack';
import Slider from '@mui/joy/Slider';
import Sheet from '@mui/joy/Sheet';
export default function DividerChildPosition() {
const [position, setPosition] = React.useState<number | Array<number>>(50);
return (
<Box sx={{ width: '100%' }}>
<Stack spacing={1} sx={{ fontSize: 'sm' }}>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
<Divider sx={{ '--Divider-childPosition': `${position}%` }}>
Visual indicator
</Divider>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
</Stack>
<Slider
value={position}
min={0}
max={100}
step={1}
valueLabelDisplay="on"
valueLabelFormat={(value) => `${value}%`}
onChange={(event, value) => setPosition(value)}
/>
</Box>
);
}
| 1,094 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerChildPosition.tsx.preview | <Stack spacing={1} sx={{ fontSize: 'sm' }}>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
<Divider sx={{ '--Divider-childPosition': `${position}%` }}>
Visual indicator
</Divider>
<Sheet variant="soft" sx={{ height: 40, borderRadius: 'xs' }} />
</Stack>
<Slider
value={position}
min={0}
max={100}
step={1}
valueLabelDisplay="on"
valueLabelFormat={(value) => `${value}%`}
onChange={(event, value) => setPosition(value)}
/> | 1,095 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerInCard.js | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Card from '@mui/joy/Card';
import Checkbox from '@mui/joy/Checkbox';
import Divider from '@mui/joy/Divider';
import Typography from '@mui/joy/Typography';
import ArrowForward from '@mui/icons-material/ArrowForward';
export default function DividerInCard() {
const [orientation, setOrientation] = React.useState('vertical');
return (
<div>
<Checkbox
label="horizontal"
checked={orientation === 'horizontal'}
onChange={(event) =>
setOrientation(event.target.checked ? 'horizontal' : 'vertical')
}
sx={{ mb: 2 }}
/>
<Card
orientation={orientation}
variant="outlined"
sx={{ width: 400, maxWidth: '100%', gap: 1.5 }}
>
<Typography fontSize="lg" fontWeight="md">
Headline
</Typography>
<Divider />
<Box sx={{ display: orientation === 'horizontal' ? 'block' : 'contents' }}>
<Typography level="body-sm">
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry standard dummy text ever
since the 1500s
</Typography>
<Button
size="sm"
variant="soft"
color="neutral"
endDecorator={<ArrowForward />}
sx={{ width: '100%', mt: orientation === 'horizontal' ? 2 : 0 }}
>
See more
</Button>
</Box>
</Card>
</div>
);
}
| 1,096 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerInCard.tsx | import * as React from 'react';
import Box from '@mui/joy/Box';
import Button from '@mui/joy/Button';
import Card, { CardProps } from '@mui/joy/Card';
import Checkbox from '@mui/joy/Checkbox';
import Divider from '@mui/joy/Divider';
import Typography from '@mui/joy/Typography';
import ArrowForward from '@mui/icons-material/ArrowForward';
export default function DividerInCard() {
const [orientation, setOrientation] =
React.useState<CardProps['orientation']>('vertical');
return (
<div>
<Checkbox
label="horizontal"
checked={orientation === 'horizontal'}
onChange={(event) =>
setOrientation(event.target.checked ? 'horizontal' : 'vertical')
}
sx={{ mb: 2 }}
/>
<Card
orientation={orientation}
variant="outlined"
sx={{ width: 400, maxWidth: '100%', gap: 1.5 }}
>
<Typography fontSize="lg" fontWeight="md">
Headline
</Typography>
<Divider />
<Box sx={{ display: orientation === 'horizontal' ? 'block' : 'contents' }}>
<Typography level="body-sm">
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry standard dummy text ever
since the 1500s
</Typography>
<Button
size="sm"
variant="soft"
color="neutral"
endDecorator={<ArrowForward />}
sx={{ width: '100%', mt: orientation === 'horizontal' ? 2 : 0 }}
>
See more
</Button>
</Box>
</Card>
</div>
);
}
| 1,097 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerInModalDialog.js | import * as React from 'react';
import Button from '@mui/joy/Button';
import CardOverflow from '@mui/joy/CardOverflow';
import ModalDialog from '@mui/joy/ModalDialog';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import DialogActions from '@mui/joy/DialogActions';
import Divider from '@mui/joy/Divider';
export default function DividerInModalDialog() {
return (
<ModalDialog
sx={{
// this custom styles is for demonstration purpose, you might not need them in your app
position: 'static',
transform: 'none',
maxWidth: 300,
}}
>
<DialogTitle>Modal Title</DialogTitle>
<Divider inset="none" />
<DialogContent>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry standard dummy text ever since the 1500s
</DialogContent>
<CardOverflow
sx={{
bgcolor: 'background.level1',
}}
>
<Divider inset="context" />
<DialogActions
buttonFlex="none"
sx={{ pt: 1.5, justifyContent: 'flex-start' }}
>
<Button size="sm">Got it!</Button>
</DialogActions>
</CardOverflow>
</ModalDialog>
);
}
| 1,098 |
0 | petrpan-code/mui/material-ui/docs/data/joy/components | petrpan-code/mui/material-ui/docs/data/joy/components/divider/DividerInModalDialog.tsx | import * as React from 'react';
import Button from '@mui/joy/Button';
import CardOverflow from '@mui/joy/CardOverflow';
import ModalDialog from '@mui/joy/ModalDialog';
import DialogTitle from '@mui/joy/DialogTitle';
import DialogContent from '@mui/joy/DialogContent';
import DialogActions from '@mui/joy/DialogActions';
import Divider from '@mui/joy/Divider';
export default function DividerInModalDialog() {
return (
<ModalDialog
sx={{
// this custom styles is for demonstration purpose, you might not need them in your app
position: 'static',
transform: 'none',
maxWidth: 300,
}}
>
<DialogTitle>Modal Title</DialogTitle>
<Divider inset="none" />
<DialogContent>
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry standard dummy text ever since the 1500s
</DialogContent>
<CardOverflow
sx={{
bgcolor: 'background.level1',
}}
>
<Divider inset="context" />
<DialogActions
buttonFlex="none"
sx={{ pt: 1.5, justifyContent: 'flex-start' }}
>
<Button size="sm">Got it!</Button>
</DialogActions>
</CardOverflow>
</ModalDialog>
);
}
| 1,099 |
Subsets and Splits