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/radio-button/RadioFocus.tsx
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import FormHelperText from '@mui/joy/FormHelperText'; import Radio, { radioClasses } from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; export default function RadioFocus() { return ( <FormControl> <FormLabel>Focus</FormLabel> <RadioGroup name="radio-buttons-group-focus"> <Radio value="default" label="Default" /> <Radio value="relative" label="Position relative" sx={{ [`& .${radioClasses.radio}`]: { position: 'relative' } }} /> </RadioGroup> <FormHelperText> Select an option and use keyboard ↑↓ to see the focus outline </FormHelperText> </FormControl> ); }
1,400
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioFocus.tsx.preview
<FormControl> <FormLabel>Focus</FormLabel> <RadioGroup name="radio-buttons-group-focus"> <Radio value="default" label="Default" /> <Radio value="relative" label="Position relative" sx={{ [`& .${radioClasses.radio}`]: { position: 'relative' } }} /> </RadioGroup> <FormHelperText> Select an option and use keyboard ↑↓ to see the focus outline </FormHelperText> </FormControl>
1,401
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioPositionEnd.js
import * as React from 'react'; import List from '@mui/joy/List'; import ListItem from '@mui/joy/ListItem'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; import Person from '@mui/icons-material/Person'; import People from '@mui/icons-material/People'; import Apartment from '@mui/icons-material/Apartment'; export default function RadioPositionEnd() { return ( <RadioGroup aria-label="Your plan" name="people" defaultValue="Individual"> <List sx={{ minWidth: 240, '--List-gap': '0.5rem', '--ListItem-paddingY': '1rem', '--ListItem-radius': '8px', '--ListItemDecorator-size': '32px', }} > {['Individual', 'Team', 'Enterprise'].map((item, index) => ( <ListItem variant="outlined" key={item} sx={{ boxShadow: 'sm' }}> <ListItemDecorator> {[<Person />, <People />, <Apartment />][index]} </ListItemDecorator> <Radio overlay value={item} label={item} sx={{ flexGrow: 1, flexDirection: 'row-reverse' }} slotProps={{ action: ({ checked }) => ({ sx: (theme) => ({ ...(checked && { inset: -1, border: '2px solid', borderColor: theme.vars.palette.primary[500], }), }), }), }} /> </ListItem> ))} </List> </RadioGroup> ); }
1,402
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioPositionEnd.tsx
import * as React from 'react'; import List from '@mui/joy/List'; import ListItem from '@mui/joy/ListItem'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; import Person from '@mui/icons-material/Person'; import People from '@mui/icons-material/People'; import Apartment from '@mui/icons-material/Apartment'; export default function RadioPositionEnd() { return ( <RadioGroup aria-label="Your plan" name="people" defaultValue="Individual"> <List sx={{ minWidth: 240, '--List-gap': '0.5rem', '--ListItem-paddingY': '1rem', '--ListItem-radius': '8px', '--ListItemDecorator-size': '32px', }} > {['Individual', 'Team', 'Enterprise'].map((item, index) => ( <ListItem variant="outlined" key={item} sx={{ boxShadow: 'sm' }}> <ListItemDecorator> {[<Person />, <People />, <Apartment />][index]} </ListItemDecorator> <Radio overlay value={item} label={item} sx={{ flexGrow: 1, flexDirection: 'row-reverse' }} slotProps={{ action: ({ checked }) => ({ sx: (theme) => ({ ...(checked && { inset: -1, border: '2px solid', borderColor: theme.vars.palette.primary[500], }), }), }), }} /> </ListItem> ))} </List> </RadioGroup> ); }
1,403
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioSizes.js
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; export default function RadioSizes() { return ( <FormControl> <FormLabel>Sizes</FormLabel> <RadioGroup defaultValue="medium" name="radio-buttons-group"> <Radio value="small" label="Small" size="sm" /> <Radio value="medium" label="Medium" size="md" /> <Radio value="large" label="Large" size="lg" /> </RadioGroup> </FormControl> ); }
1,404
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioSizes.tsx
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; export default function RadioSizes() { return ( <FormControl> <FormLabel>Sizes</FormLabel> <RadioGroup defaultValue="medium" name="radio-buttons-group"> <Radio value="small" label="Small" size="sm" /> <Radio value="medium" label="Medium" size="md" /> <Radio value="large" label="Large" size="lg" /> </RadioGroup> </FormControl> ); }
1,405
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioSizes.tsx.preview
<FormControl> <FormLabel>Sizes</FormLabel> <RadioGroup defaultValue="medium" name="radio-buttons-group"> <Radio value="small" label="Small" size="sm" /> <Radio value="medium" label="Medium" size="md" /> <Radio value="large" label="Large" size="lg" /> </RadioGroup> </FormControl>
1,406
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioUsage.js
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import RadioGroup from '@mui/joy/RadioGroup'; import Radio from '@mui/joy/Radio'; import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo'; export default function RadioUsage() { return ( <JoyUsageDemo componentName="Radio" 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: 'orientation', knob: 'radio', options: ['vertical', 'horizontal'], defaultValue: 'vertical', }, ]} renderDemo={({ orientation, ...props }) => ( <FormControl> <FormLabel>Pizza crust</FormLabel> <RadioGroup orientation={orientation} defaultValue="1" name="radio-button-usage" > <Radio label="Regular crust" value="1" {...props} /> <Radio label="Deep dish" value="2" {...props} /> <Radio label="Thin crust" value="3" {...props} disabled /> </RadioGroup> </FormControl> )} /> ); }
1,407
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioVariants.js
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; export default function RadioVariants() { return ( <FormControl> <FormLabel>Variants</FormLabel> <RadioGroup defaultValue="outlined" name="radio-buttons-group"> <Radio value="outlined" label="Outlined" variant="outlined" /> <Radio value="soft" label="Soft" variant="soft" /> <Radio value="solid" label="Solid" variant="solid" /> <Radio value="plain" label="Plain" variant="plain" /> </RadioGroup> </FormControl> ); }
1,408
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioVariants.tsx
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Radio from '@mui/joy/Radio'; import RadioGroup from '@mui/joy/RadioGroup'; export default function RadioVariants() { return ( <FormControl> <FormLabel>Variants</FormLabel> <RadioGroup defaultValue="outlined" name="radio-buttons-group"> <Radio value="outlined" label="Outlined" variant="outlined" /> <Radio value="soft" label="Soft" variant="soft" /> <Radio value="solid" label="Solid" variant="solid" /> <Radio value="plain" label="Plain" variant="plain" /> </RadioGroup> </FormControl> ); }
1,409
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/RadioVariants.tsx.preview
<FormControl> <FormLabel>Variants</FormLabel> <RadioGroup defaultValue="outlined" name="radio-buttons-group"> <Radio value="outlined" label="Outlined" variant="outlined" /> <Radio value="soft" label="Soft" variant="soft" /> <Radio value="solid" label="Solid" variant="solid" /> <Radio value="plain" label="Plain" variant="plain" /> </RadioGroup> </FormControl>
1,410
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/radio-button/radio-button.md
--- productId: joy-ui title: React Radio Button component components: Radio, RadioGroup githubLabel: 'component: radio' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/radio/ --- # Radio <p class="description">Radio buttons enable the user to select one option from a set.</p> {{"component": "modules/components/ComponentLinkHeader.js"}} ## Introduction Radio buttons let users make a mutually exclusive choice (e.g., this or that). Only one selection is allowed from the available set of options. Radio buttons should have the most commonly used option selected by default. {{"demo": "RadioUsage.js", "hideToolbar": true, "bg": "gradient"}} :::success When should you use radio buttons rather than checkboxes, switches, or selects? - Use checkboxes to give the user **multiple binary choices**—radio buttons are preferable when you need to restrict user selection to one mutually exclusive option from a series. - Use a switch to provide the user with **a single binary choice**—radio buttons are preferable when you need to give the user multiple binary choices. - Consider using a select if it's not important for the user to be able to see all options. - If available options can be collapsed, consider using a Select component to conserve space. ::: ## Basics ```jsx import Radio from '@mui/joy/Radio'; ``` The Joy UI Radio button behaves similar to the native HTML <input type="radio">, so it accepts props like `checked`, `value` and `onChange`. {{"demo": "RadioButtons.js"}} ## Customization ### Variants The Radio component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `outlined` (default), `soft` , `solid` , and `plain`. {{"demo": "RadioVariants.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 Radio component comes in three sizes: `sm`, `md` (default), and `lg`: {{"demo": "RadioSizes.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": "RadioColors.js"}} ### Label Use the `label` prop to add a label to a Radio button. {{"demo": "RadioButtonLabel.js"}} For more complex layouts, compose a Radio button with Form Control, Form Label, and Form Helper Text (optional), as shown below: {{"demo": "RadioButtonControl.js"}} ### Position To swap the positions of a Radio and its label, use the CSS property `flex-direction: row-reverse`. {{"demo": "RadioPositionEnd.js"}} ## Usage with Radio Group ```jsx import RadioGroup from '@mui/joy/RadioGroup'; ``` The Radio Group component is the ideal wrapper for multiple Radio components as it provides a tailored API for grouping and better keyboard navigation accessibility. {{"demo": "RadioButtonsGroup.js"}} ### Controlled Use the `value` and `onChange` props to control the actions performed by the Radio buttons. For example, the Radio buttons in the demo below update the state to reflect the selected option: {{"demo": "ControlledRadioButtonsGroup.js"}} ### Focus outline By default, the focus outline wraps both the Radio button and its label. If you need to focus to omit the label, target the `radioClasses.radio` class and add `position: 'relative'`. {{"demo": "RadioFocus.js"}} ### Overlay To make the Radio button's container clickable, use the `overlay` prop. You can also apply this prop directly to a Radio Group when present, which will pass the prop to each individual Radio button nested within. {{"demo": "OverlayRadio.js"}} :::info Use the CSS variable `--Radio-actionRadius` to control the border radius of the clickable area. ::: ### Custom icons Use the `checkedIcon` and `uncheckedIcon` props to add custom icons to the Radio button that correspond to each state, respectively. The demo below shows how to apply a custom `checkedIcon` to the Radio button that sits on the corner of each Sheet: {{"demo": "IconsRadio.js"}} ### No icon Use the `disableIcon` prop to remove the Radio button's icon. In this case, you'll need to use CSS properties like border and background color to communicate the state of the Radio button, as shown in the demo below: {{"demo": "IconlessRadio.js"}} ## Common examples ### Segmented controls {{"demo": "ExampleSegmentedControls.js"}} ### Tiers This example demonstrates the composition of the components, and was inspired by [this Dribbble shot from Tailwind Labs](https://dribbble.com/shots/11239824-Radio-button-groups). {{"demo": "ExampleTiers.js"}} ### Alignment buttons This example uses icons as labels for a group of Radio buttons to recreate the form and function of [Toggle Buttons](https://mui.com/material-ui/react-toggle-button/). In this case, you must provide an `aria-label` to the input slot for users who rely on screen readers. {{"demo": "ExampleAlignmentButtons.js"}} ### Payment methods Mix Radio buttons with the [List](/joy-ui/react-list/) components to create a vertical or horizontal payment method list. {{"demo": "ExamplePaymentChannels.js"}} ### E-commerce product attributes This example demonstrates complex customization using the Sheet component as a container for the Radio buttons. The focus outline is customized to be smaller, and the color changes based on the value. The check icon's color inherits the Radio button's `solid` variant, so you don't need to handpick a color that contrasts enough with the background. {{"demo": "ExampleProductAttributes.js"}} ## Accessibility Here are a few tips to make sure you have an accessible Radio button component: - Every Form Control should have proper labels. This includes Radio buttons, Checkboxes, and Switches. In most cases, this is done by using the Form Control and Form Label element. - When a label can't be used, make sure to add an attribute, such as `aria-label`, `aria-labelledby`, and/or `title`, directly on the input component. You can also use the `slotProps.input` prop to add them. ```jsx <Radio value="radioA" slotProps={{ input: { 'aria-label': 'Radio A', }, }} /> ``` Visit the [WAI-ARIA documentation](https://www.w3.org/WAI/ARIA/apg/patterns/radio/) for more details. ## Anatomy The Radio Group component is composed of a root `<div>` element that can wrap multiple Radio components. ```html <div class="MuiRadioGroup-root"> <!-- Radio components here --> </div> ``` The Radio component is composed of a root `<span>`, with further nested `<span>` elements for the radio button, icon, action (with a nested `<input>`), and its associated `<label>`. ```html <span class="MuiRadio-root"> <span class="MuiRadio-radio"> <span class="MuiRadio-icon"></span> <span class="MuiRadio-action"> <input class="MuiRadio-input"> </span> </span> <label class="MuiRadio-label"> </span> ```
1,411
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/ControlledOpenSelect.js
import * as React from 'react'; import Stack from '@mui/joy/Stack'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Button from '@mui/joy/Button'; export default function ControlledOpenSelect() { const [age, setAge] = React.useState(''); const [open, setOpen] = React.useState(false); const skipRef = React.useRef(false); const handleChange = (event, newValue) => { setAge(newValue); }; return ( <Stack spacing={2} useFlexGap> <Button variant="solid" onMouseDown={() => { skipRef.current = true; }} onClick={() => { skipRef.current = false; setOpen((bool) => !bool); }} > Toggle the select </Button> <div> <Select listboxOpen={open} onListboxOpenChange={(isOpen) => { if (!skipRef.current) { setOpen(isOpen); } }} value={age} onChange={handleChange} > <Option value=""> <em>None</em> </Option> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> </div> </Stack> ); }
1,412
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/ControlledOpenSelect.tsx
import * as React from 'react'; import Stack from '@mui/joy/Stack'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Button from '@mui/joy/Button'; export default function ControlledOpenSelect() { const [age, setAge] = React.useState(''); const [open, setOpen] = React.useState(false); const skipRef = React.useRef(false); const handleChange = ( event: React.SyntheticEvent | null, newValue: string | null, ) => { setAge(newValue!); }; return ( <Stack spacing={2} useFlexGap> <Button variant="solid" onMouseDown={() => { skipRef.current = true; }} onClick={() => { skipRef.current = false; setOpen((bool) => !bool); }} > Toggle the select </Button> <div> <Select listboxOpen={open} onListboxOpenChange={(isOpen) => { if (!skipRef.current) { setOpen(isOpen); } }} value={age} onChange={handleChange} > <Option value=""> <em>None</em> </Option> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> </div> </Stack> ); }
1,413
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectBasic.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectBasic() { const handleChange = (event, newValue) => { alert(`You chose "${newValue}"`); }; return ( <Select defaultValue="dog" onChange={handleChange}> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,414
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectBasic.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectBasic() { const handleChange = ( event: React.SyntheticEvent | null, newValue: string | null, ) => { alert(`You chose "${newValue}"`); }; return ( <Select defaultValue="dog" onChange={handleChange}> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,415
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectBasic.tsx.preview
<Select defaultValue="dog" onChange={handleChange}> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select>
1,416
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectClearable.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import IconButton from '@mui/joy/IconButton'; import CloseRounded from '@mui/icons-material/CloseRounded'; export default function SelectClearable() { const [value, setValue] = React.useState('dog'); const action = React.useRef(null); return ( <Select action={action} value={value} placeholder="Favorite pet…" onChange={(e, newValue) => setValue(newValue)} {...(value && { // display the button and remove select indicator // when user has selected a value endDecorator: ( <IconButton size="sm" variant="plain" color="neutral" onMouseDown={(event) => { // don't open the popup when clicking on this button event.stopPropagation(); }} onClick={() => { setValue(null); action.current?.focusVisible(); }} > <CloseRounded /> </IconButton> ), indicator: null, })} sx={{ minWidth: 160 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,417
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectClearable.tsx
import * as React from 'react'; import Select, { SelectStaticProps } from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import IconButton from '@mui/joy/IconButton'; import CloseRounded from '@mui/icons-material/CloseRounded'; export default function SelectClearable() { const [value, setValue] = React.useState<string | null>('dog'); const action: SelectStaticProps['action'] = React.useRef(null); return ( <Select action={action} value={value} placeholder="Favorite pet…" onChange={(e, newValue) => setValue(newValue)} {...(value && { // display the button and remove select indicator // when user has selected a value endDecorator: ( <IconButton size="sm" variant="plain" color="neutral" onMouseDown={(event) => { // don't open the popup when clicking on this button event.stopPropagation(); }} onClick={() => { setValue(null); action.current?.focusVisible(); }} > <CloseRounded /> </IconButton> ), indicator: null, })} sx={{ minWidth: 160 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,418
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectCustomOption.js
import * as React from 'react'; import Avatar from '@mui/joy/Avatar'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import ListDivider from '@mui/joy/ListDivider'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; const options = [ { value: '1', label: 'Eric', src: '/static/images/avatar/1.jpg' }, { value: '2', label: 'Smith', src: '/static/images/avatar/2.jpg' }, { value: '3', label: 'Erika', src: '/static/images/avatar/3.jpg' }, ]; function renderValue(option) { if (!option) { return null; } return ( <React.Fragment> <ListItemDecorator> <Avatar size="sm" src={options.find((o) => o.value === option.value)?.src} /> </ListItemDecorator> {option.label} </React.Fragment> ); } export default function SelectCustomOption() { return ( <Select defaultValue="1" slotProps={{ listbox: { sx: { '--ListItemDecorator-size': '44px', }, }, }} sx={{ '--ListItemDecorator-size': '44px', minWidth: 240, }} renderValue={renderValue} > {options.map((option, index) => ( <React.Fragment key={option.value}> {index !== 0 ? <ListDivider role="none" inset="startContent" /> : null} <Option value={option.value} label={option.label}> <ListItemDecorator> <Avatar size="sm" src={option.src} /> </ListItemDecorator> {option.label} </Option> </React.Fragment> ))} </Select> ); }
1,419
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectCustomOption.tsx
import * as React from 'react'; import Avatar from '@mui/joy/Avatar'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import ListDivider from '@mui/joy/ListDivider'; import Select, { SelectOption } from '@mui/joy/Select'; import Option from '@mui/joy/Option'; const options = [ { value: '1', label: 'Eric', src: '/static/images/avatar/1.jpg' }, { value: '2', label: 'Smith', src: '/static/images/avatar/2.jpg' }, { value: '3', label: 'Erika', src: '/static/images/avatar/3.jpg' }, ]; function renderValue(option: SelectOption<string> | null) { if (!option) { return null; } return ( <React.Fragment> <ListItemDecorator> <Avatar size="sm" src={options.find((o) => o.value === option.value)?.src} /> </ListItemDecorator> {option.label} </React.Fragment> ); } export default function SelectCustomOption() { return ( <Select defaultValue="1" slotProps={{ listbox: { sx: { '--ListItemDecorator-size': '44px', }, }, }} sx={{ '--ListItemDecorator-size': '44px', minWidth: 240, }} renderValue={renderValue} > {options.map((option, index) => ( <React.Fragment key={option.value}> {index !== 0 ? <ListDivider role="none" inset="startContent" /> : null} <Option value={option.value} label={option.label}> <ListItemDecorator> <Avatar size="sm" src={option.src} /> </ListItemDecorator> {option.label} </Option> </React.Fragment> ))} </Select> ); }
1,420
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectCustomValueAppearance.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 ListItemDecorator from '@mui/joy/ListItemDecorator'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Typography from '@mui/joy/Typography'; export default function SelectCustomValueAppearance() { const people = [ { name: 'Eric', role: 'PM', status: '2days ago' }, { name: 'Smith', role: 'Engineer', status: 'secs ago' }, { name: 'Erika', role: 'Designer', status: '10hrs ago' }, ]; const colors = { PM: 'success', Engineer: 'primary', Designer: 'warning', }; return ( <Select defaultValue="Eric" slotProps={{ listbox: { sx: { '--ListItemDecorator-size': '48px', }, }, }} sx={{ minWidth: 240, }} > {people.map((data, index) => ( <Option key={data.name} value={data.name} label={data.name} // The appearance of the selected value will be a string > <ListItemDecorator> <Avatar src={`/static/images/avatar/${index + 1}.jpg`} /> </ListItemDecorator> <Box component="span" sx={{ display: 'block' }}> <Typography component="span" level="title-sm"> {data.name} </Typography> <Typography level="body-xs">{data.status}</Typography> </Box> <Chip size="sm" variant="outlined" color={colors[data.role]} sx={{ ml: 'auto', borderRadius: '2px', minHeight: '20px', paddingInline: '4px', fontSize: 'xs', bgcolor: `${colors[data.role]}.softBg`, }} > {data.role} </Chip> </Option> ))} </Select> ); }
1,421
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectCustomValueAppearance.tsx
import * as React from 'react'; import Avatar from '@mui/joy/Avatar'; import Box from '@mui/joy/Box'; import Chip from '@mui/joy/Chip'; import ListItemDecorator from '@mui/joy/ListItemDecorator'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Typography from '@mui/joy/Typography'; export default function SelectCustomValueAppearance() { const people = [ { name: 'Eric', role: 'PM', status: '2days ago' }, { name: 'Smith', role: 'Engineer', status: 'secs ago' }, { name: 'Erika', role: 'Designer', status: '10hrs ago' }, ] as const; const colors = { PM: 'success', Engineer: 'primary', Designer: 'warning', } as const; return ( <Select defaultValue="Eric" slotProps={{ listbox: { sx: { '--ListItemDecorator-size': '48px', }, }, }} sx={{ minWidth: 240, }} > {people.map((data, index) => ( <Option key={data.name} value={data.name} label={data.name} // The appearance of the selected value will be a string > <ListItemDecorator> <Avatar src={`/static/images/avatar/${index + 1}.jpg`} /> </ListItemDecorator> <Box component="span" sx={{ display: 'block' }}> <Typography component="span" level="title-sm"> {data.name} </Typography> <Typography level="body-xs">{data.status}</Typography> </Box> <Chip size="sm" variant="outlined" color={colors[data.role]} sx={{ ml: 'auto', borderRadius: '2px', minHeight: '20px', paddingInline: '4px', fontSize: 'xs', bgcolor: `${colors[data.role]}.softBg`, }} > {data.role} </Chip> </Option> ))} </Select> ); }
1,422
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectDecorators.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Chip from '@mui/joy/Chip'; import FavoriteBorder from '@mui/icons-material/FavoriteBorder'; export default function SelectDecorators() { return ( <Select placeholder="Select a pet…" startDecorator={<FavoriteBorder />} endDecorator={ <Chip size="sm" color="danger" variant="soft"> +5 </Chip> } sx={{ width: 240 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,423
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectDecorators.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Chip from '@mui/joy/Chip'; import FavoriteBorder from '@mui/icons-material/FavoriteBorder'; export default function SelectDecorators() { return ( <Select placeholder="Select a pet…" startDecorator={<FavoriteBorder />} endDecorator={ <Chip size="sm" color="danger" variant="soft"> +5 </Chip> } sx={{ width: 240 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,424
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectDecorators.tsx.preview
<Select placeholder="Select a pet…" startDecorator={<FavoriteBorder />} endDecorator={ <Chip size="sm" color="danger" variant="soft"> +5 </Chip> } sx={{ width: 240 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select>
1,425
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectFieldDemo.js
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import FormHelperText from '@mui/joy/FormHelperText'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectFieldDemo() { return ( <FormControl sx={{ width: 240 }}> <FormLabel id="select-field-demo-label" htmlFor="select-field-demo-button"> Favorite pet </FormLabel> <Select defaultValue="dog" slotProps={{ button: { id: 'select-field-demo-button', // TODO: Material UI set aria-labelledby correctly & automatically // but Base UI and Joy UI don't yet. 'aria-labelledby': 'select-field-demo-label select-field-demo-button', }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <FormHelperText id="select-field-demo-helper"> This is a helper text. </FormHelperText> </FormControl> ); }
1,426
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectFieldDemo.tsx
import * as React from 'react'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import FormHelperText from '@mui/joy/FormHelperText'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectFieldDemo() { return ( <FormControl sx={{ width: 240 }}> <FormLabel id="select-field-demo-label" htmlFor="select-field-demo-button"> Favorite pet </FormLabel> <Select defaultValue="dog" slotProps={{ button: { id: 'select-field-demo-button', // TODO: Material UI set aria-labelledby correctly & automatically // but Base UI and Joy UI don't yet. 'aria-labelledby': 'select-field-demo-label select-field-demo-button', }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <FormHelperText id="select-field-demo-helper"> This is a helper text. </FormHelperText> </FormControl> ); }
1,427
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectFormSubmission.js
import * as React from 'react'; import Button from '@mui/joy/Button'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Stack from '@mui/joy/Stack'; export default function SelectFormSubmission() { return ( <form onSubmit={(event) => { event.preventDefault(); const formData = new FormData(event.currentTarget); const formJson = Object.fromEntries(formData.entries()); alert(JSON.stringify(formJson)); }} > <Stack spacing={2} alignItems="flex-start"> <Select placeholder="Select a pet" name="foo" required sx={{ minWidth: 200 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Button type="submit">Submit</Button> </Stack> </form> ); }
1,428
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectFormSubmission.tsx
import * as React from 'react'; import Button from '@mui/joy/Button'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Stack from '@mui/joy/Stack'; export default function SelectFormSubmission() { return ( <form onSubmit={(event) => { event.preventDefault(); const formData = new FormData(event.currentTarget); const formJson = Object.fromEntries((formData as any).entries()); alert(JSON.stringify(formJson)); }} > <Stack spacing={2} alignItems="flex-start"> <Select placeholder="Select a pet" name="foo" required sx={{ minWidth: 200 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Button type="submit">Submit</Button> </Stack> </form> ); }
1,429
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectGroupedOptions.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option, { optionClasses } from '@mui/joy/Option'; import Chip from '@mui/joy/Chip'; import List from '@mui/joy/List'; import ListItemDecorator, { listItemDecoratorClasses, } from '@mui/joy/ListItemDecorator'; import ListDivider from '@mui/joy/ListDivider'; import ListItem from '@mui/joy/ListItem'; import Typography from '@mui/joy/Typography'; import Check from '@mui/icons-material/Check'; export default function SelectGroupedOptions() { const group = { Land: ['Cat', 'Dog', 'Tiger', 'Reindeer', 'Raccoon'], Water: ['Dolphin', 'Flounder', 'Eel'], Air: ['Falcon', 'Winged Horse', 'Owl'], }; const colors = { Land: 'neutral', Water: 'primary', Air: 'success', }; return ( <Select placeholder="Choose your animal" slotProps={{ listbox: { component: 'div', sx: { maxHeight: 240, overflow: 'auto', '--List-padding': '0px', '--ListItem-radius': '0px', }, }, }} sx={{ width: 240 }} > {Object.entries(group).map(([name, animals], index) => ( <React.Fragment key={name}> {index !== 0 && <ListDivider role="none" />} <List aria-labelledby={`select-group-${name}`} sx={{ '--ListItemDecorator-size': '28px' }} > <ListItem id={`select-group-${name}`} sticky> <Typography level="body-xs" textTransform="uppercase"> {name} ({animals.length}) </Typography> </ListItem> {animals.map((anim) => ( <Option key={anim} value={anim} label={ <React.Fragment> <Chip size="sm" color={colors[name]} sx={{ borderRadius: 'xs', mr: 1 }} > {name} </Chip>{' '} {anim} </React.Fragment> } sx={{ [`&.${optionClasses.selected} .${listItemDecoratorClasses.root}`]: { opacity: 1, }, }} > <ListItemDecorator sx={{ opacity: 0 }}> <Check /> </ListItemDecorator> {anim} </Option> ))} </List> </React.Fragment> ))} </Select> ); }
1,430
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectGroupedOptions.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option, { optionClasses } from '@mui/joy/Option'; import Chip from '@mui/joy/Chip'; import List from '@mui/joy/List'; import ListItemDecorator, { listItemDecoratorClasses, } from '@mui/joy/ListItemDecorator'; import ListDivider from '@mui/joy/ListDivider'; import ListItem from '@mui/joy/ListItem'; import Typography from '@mui/joy/Typography'; import Check from '@mui/icons-material/Check'; export default function SelectGroupedOptions() { const group = { Land: ['Cat', 'Dog', 'Tiger', 'Reindeer', 'Raccoon'], Water: ['Dolphin', 'Flounder', 'Eel'], Air: ['Falcon', 'Winged Horse', 'Owl'], }; const colors = { Land: 'neutral', Water: 'primary', Air: 'success', } as const; return ( <Select placeholder="Choose your animal" slotProps={{ listbox: { component: 'div', sx: { maxHeight: 240, overflow: 'auto', '--List-padding': '0px', '--ListItem-radius': '0px', }, }, }} sx={{ width: 240 }} > {Object.entries(group).map(([name, animals], index) => ( <React.Fragment key={name}> {index !== 0 && <ListDivider role="none" />} <List aria-labelledby={`select-group-${name}`} sx={{ '--ListItemDecorator-size': '28px' }} > <ListItem id={`select-group-${name}`} sticky> <Typography level="body-xs" textTransform="uppercase"> {name} ({animals.length}) </Typography> </ListItem> {animals.map((anim) => ( <Option key={anim} value={anim} label={ <React.Fragment> <Chip size="sm" color={colors[name as keyof typeof group]} sx={{ borderRadius: 'xs', mr: 1 }} > {name} </Chip>{' '} {anim} </React.Fragment> } sx={{ [`&.${optionClasses.selected} .${listItemDecoratorClasses.root}`]: { opacity: 1, }, }} > <ListItemDecorator sx={{ opacity: 0 }}> <Check /> </ListItemDecorator> {anim} </Option> ))} </List> </React.Fragment> ))} </Select> ); }
1,431
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectIndicator.js
import * as React from 'react'; import Select, { selectClasses } from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown'; export default function SelectIndicator() { return ( <Select placeholder="Select a pet…" indicator={<KeyboardArrowDown />} sx={{ width: 240, [`& .${selectClasses.indicator}`]: { transition: '0.2s', [`&.${selectClasses.expanded}`]: { transform: 'rotate(-180deg)', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,432
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectIndicator.tsx
import * as React from 'react'; import Select, { selectClasses } from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import KeyboardArrowDown from '@mui/icons-material/KeyboardArrowDown'; export default function SelectIndicator() { return ( <Select placeholder="Select a pet…" indicator={<KeyboardArrowDown />} sx={{ width: 240, [`& .${selectClasses.indicator}`]: { transition: '0.2s', [`&.${selectClasses.expanded}`]: { transform: 'rotate(-180deg)', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,433
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMinWidth.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Typography from '@mui/joy/Typography'; export default function SelectMinWidth() { return ( <Box sx={{ width: 100 }}> <Select defaultValue="German Shepherd" slotProps={{ listbox: { placement: 'bottom-start', sx: { minWidth: 160 }, }, }} > <Option value="German Shepherd">German Shepherd</Option> <Option value="Anatolian Shepherd Dog">Anatolian Shepherd Dog</Option> <Option value="West Highland White Terrier"> West Highland White Terrier </Option> <Option value="Maltese dog">Maltese dog</Option> </Select> <Typography level="body-xs" textAlign="center" sx={{ mt: 1 }}> Width is fixed at 100px </Typography> </Box> ); }
1,434
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMinWidth.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Typography from '@mui/joy/Typography'; export default function SelectMinWidth() { return ( <Box sx={{ width: 100 }}> <Select defaultValue="German Shepherd" slotProps={{ listbox: { placement: 'bottom-start', sx: { minWidth: 160 }, }, }} > <Option value="German Shepherd">German Shepherd</Option> <Option value="Anatolian Shepherd Dog">Anatolian Shepherd Dog</Option> <Option value="West Highland White Terrier"> West Highland White Terrier </Option> <Option value="Maltese dog">Maltese dog</Option> </Select> <Typography level="body-xs" textAlign="center" sx={{ mt: 1 }}> Width is fixed at 100px </Typography> </Box> ); }
1,435
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultiple.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectMultiple() { const handleChange = (event, newValue) => { console.log(`You have choosen "${newValue}"`); }; return ( <Select defaultValue={['dog']} multiple onChange={handleChange} sx={{ minWidth: '13rem', }} slotProps={{ listbox: { sx: { width: '100%', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,436
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultiple.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectMultiple() { const handleChange = ( event: React.SyntheticEvent | null, newValue: Array<string> | null, ) => { console.log(`You have choosen "${newValue}"`); }; return ( <Select defaultValue={['dog']} multiple onChange={handleChange} sx={{ minWidth: '13rem', }} slotProps={{ listbox: { sx: { width: '100%', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,437
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultipleAppearance.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import { Box, Chip } from '@mui/joy'; export default function SelectMultipleAppearance() { return ( <Select multiple defaultValue={['dog', 'cat']} renderValue={(selected) => ( <Box sx={{ display: 'flex', gap: '0.25rem' }}> {selected.map((selectedOption) => ( <Chip variant="soft" color="primary"> {selectedOption.label} </Chip> ))} </Box> )} sx={{ minWidth: '15rem', }} slotProps={{ listbox: { sx: { width: '100%', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,438
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultipleAppearance.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import { Box, Chip } from '@mui/joy'; export default function SelectMultipleAppearance() { return ( <Select multiple defaultValue={['dog', 'cat']} renderValue={(selected) => ( <Box sx={{ display: 'flex', gap: '0.25rem' }}> {selected.map((selectedOption) => ( <Chip variant="soft" color="primary"> {selectedOption.label} </Chip> ))} </Box> )} sx={{ minWidth: '15rem', }} slotProps={{ listbox: { sx: { width: '100%', }, }, }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> ); }
1,439
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultipleFormSubmission.js
import * as React from 'react'; import Button from '@mui/joy/Button'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Stack from '@mui/joy/Stack'; export default function SelectMultipleFormSubmission() { return ( <form onSubmit={(event) => { event.preventDefault(); const formData = new FormData(event.currentTarget); const formJson = Object.fromEntries(formData.entries()); const selectedPets = JSON.parse(formJson.pets); alert(JSON.stringify(selectedPets)); }} > <Stack spacing={2} alignItems="flex-start"> <Select placeholder="Select a pet" name="pets" required multiple defaultValue={['dog', 'cat']} sx={{ minWidth: 200 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Button type="submit">Submit</Button> </Stack> </form> ); }
1,440
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectMultipleFormSubmission.tsx
import * as React from 'react'; import Button from '@mui/joy/Button'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import Stack from '@mui/joy/Stack'; export default function SelectMultipleFormSubmission() { return ( <form onSubmit={(event) => { event.preventDefault(); const formData = new FormData(event.currentTarget); const formJson = Object.fromEntries((formData as any).entries()); const selectedPets = JSON.parse(formJson.pets); alert(JSON.stringify(selectedPets)); }} > <Stack spacing={2} alignItems="flex-start"> <Select placeholder="Select a pet" name="pets" required multiple defaultValue={['dog', 'cat']} sx={{ minWidth: 200 }} > <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Button type="submit">Submit</Button> </Stack> </form> ); }
1,441
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectPosition.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; function SelectPosition() { return ( <Select placeholder="Select address" sx={{ width: 240 }} slotProps={{ listbox: { placement: 'bottom-start', }, }} > <Option value="1"> Flat 5, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> <Option value="2"> Flat 6, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> <Option value="3"> Flat 6b, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> </Select> ); } export default SelectPosition;
1,442
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectPosition.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; function SelectPosition() { return ( <Select placeholder="Select address" sx={{ width: 240 }} slotProps={{ listbox: { placement: 'bottom-start', }, }} > <Option value="1"> Flat 5, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> <Option value="2"> Flat 6, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> <Option value="3"> Flat 6b, 24 Bhlenheiman Avenue, South Kensington, EW13 9SD </Option> </Select> ); } export default SelectPosition;
1,443
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectUsage.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo'; export default function SelectUsage() { const [value, setValue] = React.useState(null); const action = React.useRef(null); return ( <JoyUsageDemo componentName="Select" 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: 'placeholder', knob: 'input', defaultValue: 'Choose one…', codeBlockDisplay: true, }, { propName: 'disabled', knob: 'switch', }, { propName: 'children', defaultValue: '<Option>...</Option>', }, ]} renderDemo={(props) => ( <Select {...props} defaultListboxOpen action={action} value={value} onChange={(e, newValue) => setValue(newValue)} sx={{ minWidth: 160, mb: 20 }} > <Option value="react">React</Option> <Option value="vue">Vue</Option> <Option value="svelte">Svelte</Option> <Option value="angular">Angular</Option> </Select> )} /> ); }
1,444
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectVariants.js
import * as React from 'react'; import Select from '@mui/joy/Select'; import Stack from '@mui/joy/Stack'; import Option from '@mui/joy/Option'; export default function SelectVariants() { return ( <Stack spacing={2}> <Select defaultValue="dog"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="plain"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="soft"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="solid"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> </Stack> ); }
1,445
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/SelectVariants.tsx
import * as React from 'react'; import Select from '@mui/joy/Select'; import Stack from '@mui/joy/Stack'; import Option from '@mui/joy/Option'; export default function SelectVariants() { return ( <Stack spacing={2}> <Select defaultValue="dog"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="plain"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="soft"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> <Select defaultValue="dog" variant="solid"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> <Option value="fish">Fish</Option> <Option value="bird">Bird</Option> </Select> </Stack> ); }
1,446
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/select/select.md
--- productId: joy-ui title: React Select component components: Select, Option githubLabel: 'component: select' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ unstyled: /base-ui/react-select/ --- # Select <p class="description">Select components are used for collecting user-provided information from a list of options.</p> {{"component": "modules/components/ComponentLinkHeader.js"}} ## Introduction The `Select` component is used to trigger a popup that displays a list of `Option` components. {{"demo": "SelectUsage.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 Select from '@mui/joy/Select'; import Option from '@mui/joy/Option'; export default function SelectBasic() { return ( <Select defaultValue="dog"> <Option value="dog">Dog</Option> <Option value="cat">Cat</Option> </Select> ); } ``` ### Basic usage The `Select` component is similar to the native HTML's `<select>` and `<option>` tags. {{"demo": "SelectBasic.js"}} ### Form submission The `Select` component supports `name` and `required` props that will be used when submitting the form. {{"demo": "SelectFormSubmission.js"}} ### Variants The Select component supports the four global variants: `outlined` (default), `plain`, `soft`, and `solid`. The variant and color values are propagated to the Select's `button` and `listbox` slots. {{"demo": "SelectVariants.js"}} :::info To learn how to add more variants to the component, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants). ::: To customize the variant and color for a specific slot, use `slotProps`: ```js <Select variant="plain" slotProps={{ listbox: { variant: 'outlined', }, }} /> ``` ### Decorators Use the `startDecorator` and/or `endDecorator` props to add supporting icons or elements to the select. {{"demo": "SelectDecorators.js"}} If you have interactive elements as the select's decorators, call `stopPropagation()` from the mouse down event to prevent the popup from being opened. ```jsx <IconButton onMouseDown={(event) => { // don't open the popup when clicking on this button event.stopPropagation(); }} onClick={() => { // click handler goes here } >...</IconButton> ``` ### Indicator To change the default indicator, use the `indicator` prop with either any React element (including string) or `null` as value (to remove the indicator completely). {{"demo": "SelectIndicator.js"}} To apply the indicator to all instances of the select component, customize the `indicator` prop directly in the theme: ```js import { extendTheme, CssVarsProvider } from '@mui/joy/styles'; import Select from '@mui/joy/Select'; const theme = extendTheme({ components: { JoySelect: { defaultProps: { indicator: '↕', }, }, }, }); const App = () => ( <CssVarsProvider theme={theme}> <Select>...options</Select> </CssVarsProvider> ); ``` ### Multiple selections Set the `multiple` prop to let your users select multiple options from the list. In contrast with single-selection mode, the options popup doesn't close after an item is selected, which enables users to continue choosing more options. Note that in multiple selection mode, the `value` prop (and `defaultValue`) is an array. {{"demo": "SelectMultiple.js"}} #### Selected value appearance Use the `renderValue` prop to customize the display of the selected options. {{"demo": "SelectMultipleAppearance.js"}} #### Form submission The `Select` component supports `name` and `required` props that will be used when submitting the form. {{"demo": "SelectMultipleFormSubmission.js"}} ### Listbox #### Maximum height To change the listbox's maximum height, use `slotProps` prop to target listbox slot: ```jsx <Select slotProps={{ listbox: { sx: { maxHeight: '300px', }, }, }} > ... </Select> ``` #### Minimum width By default, the listbox's width is equal to Select's button or the maximum content of its children. You can control the minimum width by using `slotProps` prop to target listbox slot. {{"demo": "SelectMinWidth.js"}} :::success To control the placement of the listbox, use `placement`: ```js <Select slotProps={{ // the left-edge of the listbox will align with button. listbox: { placement: 'bottom-start' }, }} > ``` ::: #### Placement To align `listbox` position to `Select` while displaying long options, use `slotProps` prop to position listbox slot: {{"demo": "SelectPosition.js"}} #### Controlling the open state You can control the open state of the select with the `listboxOpen` prop. Alternatively, it is also possible to set the initial (uncontrolled) open state of the component with the `defaultListboxOpen` prop. {{"demo": "ControlledOpenSelect.js"}} ### `Option` component The `Option` component is used for the choosable options within the select. The selected option inherits the `color` from the Select parent, and it uses the `primary` palette by default. However, it does not inherit the Select's used `variant`. The `ListItemButton` component is very similar to this one, as they share the same internal styles. In fact, you can mix them together to compose various designs. In the demo below, we're using the `ListItemDecorator` to provide space between the avatars. We're also using the `ListDivider` as a visual separator. {{"demo": "SelectCustomOption.js"}} :::warning By default, the option children are used for displaying the selected value. Take a look at [selected value appearance](#selected-value-appearance) to see how to customize its appearance. ::: ### Grouped options To create a [listbox with grouped options](https://www.w3.org/WAI/ARIA/apg/patterns/listbox/examples/listbox-grouped/), wrap the `Option` with `List` component and provide an associated label using `ListItem`. That way, you'll have a consistent height and will be able to leverage nested CSS variables. {{"demo": "SelectGroupedOptions.js"}} :::warning If you'd like to set a `max-height` for a long list of options, make sure to specify it to the `listbox` slot so that keyboard-based navigation works as expected. ```jsx <Select slotProps={{ listbox: { sx: { maxHeight: 300, overflow: 'auto', // required for scrolling } } }} > ``` ::: ## Accessibility In order for the select to be accessible, **it should be linked to a label**. The `FormControl` automatically generates a unique id that links the select with the `FormLabel` component: {{"demo": "SelectFieldDemo.js"}} Alternatively, you can do it manually by targeting the button slot: ```jsx <label htmlFor="select-button" id="select-label">Label</label> <Select slotProps={{ button: { id: 'select-button', 'aria-labelledby': 'select-label select-button', } }} > <Option value="option1">Option I</Option> <Option value="option2">Option II</Option> </Select> ``` ## Common examples ### Clear action Use the `IconButton` component as a decorator to the `Select` to add a clear action. The `Select` will set the focus-visible state back to the select button after the select value is cleared, ensuring a great keyboard-navigation experience. {{"demo": "SelectClearable.js"}} ### Selected value appearance The select will display the value of the `label` prop when the option is selected. The value can be `string`, `number`, or any valid React element. {{"demo": "SelectCustomValueAppearance.js"}} ## Debugging To keep the listbox open for inspecting elements, enable the `Emulate a focused page` option from the [Chrome DevTool Rendering](https://developer.chrome.com/docs/devtools/rendering/apply-effects/#emulate-a-focused-page) tab. You can also access this option by using [command menu and search for it](https://developer.chrome.com/docs/devtools/command-menu/).
1,447
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/sheet/SheetUsage.js
import * as React from 'react'; import Sheet from '@mui/joy/Sheet'; import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo'; export default function SheetUsage() { return ( <JoyUsageDemo componentName="Sheet" data={[ { propName: 'variant', knob: 'radio', defaultValue: 'plain', options: ['plain', 'outlined', 'soft', 'solid'], }, { propName: 'color', knob: 'color', defaultValue: 'neutral', options: ['neutral', 'primary', 'danger', 'info', 'success', 'warning'], }, ]} renderDemo={(props) => ( <Sheet {...props} sx={{ width: 250, height: 200, m: 1, mb: 4, display: 'flex', alignItems: 'center', justifyContent: 'center', }} > Sheet </Sheet> )} /> ); }
1,448
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/sheet/SimpleSheet.js
import Sheet from '@mui/joy/Sheet'; import * as React from 'react'; export default function SimpleSheet() { return ( <Sheet variant="outlined" color="neutral" sx={{ p: 4 }}> Hello world! </Sheet> ); }
1,449
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/sheet/SimpleSheet.tsx
import Sheet from '@mui/joy/Sheet'; import * as React from 'react'; export default function SimpleSheet() { return ( <Sheet variant="outlined" color="neutral" sx={{ p: 4 }}> Hello world! </Sheet> ); }
1,450
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/sheet/SimpleSheet.tsx.preview
<Sheet variant="outlined" color="neutral" sx={{ p: 4 }}> Hello world! </Sheet>
1,451
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/sheet/sheet.md
--- productId: joy-ui title: React Sheet component components: Sheet --- # Sheet <p class="description">Sheet is a generic container that supports Joy UI's global variants.</p> {{"component": "modules/components/ComponentLinkHeader.js"}} ## Introduction The `Sheet` container is a generic container. It's a sibling to the [`Box`](/system/react-box/) component, and equivalent to Material UI's [`Paper`](/material-ui/react-paper/), with the difference being that it supports Joy UI's global variants out of the box. {{"demo": "SheetUsage.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 Sheet from '@mui/joy/Sheet'; export default function MyApp() { return <Sheet>Holy sheet!</Sheet>; } ``` ### Basic usage The `Sheet` component, in addition to the variants, also has access to the `color` prop, allowing you to use every palette of the theme. {{"demo": "SimpleSheet.js"}}
1,452
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/AnimationSkeleton.js
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Stack from '@mui/joy/Stack'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function AnimationSkeleton() { return ( <Stack spacing={2} useFlexGap> <Card variant="outlined" sx={{ width: 343 }}> <CardContent orientation="horizontal"> <Skeleton animation="wave" variant="circular" width={48} height={48} /> <div> <Skeleton animation="wave" variant="text" sx={{ width: 120 }} /> <Skeleton animation="wave" variant="text" level="body-sm" sx={{ width: 200 }} /> </div> </CardContent> <AspectRatio ratio="21/9"> <Skeleton animation="wave" variant="overlay"> <img alt="" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" /> </Skeleton> </AspectRatio> <Typography sx={{ overflow: 'hidden' }}> <Skeleton animation="wave"> Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries. </Skeleton> </Typography> <Button> Read more <Skeleton animation="wave" /> </Button> </Card> </Stack> ); }
1,453
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/AnimationSkeleton.tsx
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Stack from '@mui/joy/Stack'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function AnimationSkeleton() { return ( <Stack spacing={2} useFlexGap> <Card variant="outlined" sx={{ width: 343 }}> <CardContent orientation="horizontal"> <Skeleton animation="wave" variant="circular" width={48} height={48} /> <div> <Skeleton animation="wave" variant="text" sx={{ width: 120 }} /> <Skeleton animation="wave" variant="text" level="body-sm" sx={{ width: 200 }} /> </div> </CardContent> <AspectRatio ratio="21/9"> <Skeleton animation="wave" variant="overlay"> <img alt="" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" /> </Skeleton> </AspectRatio> <Typography sx={{ overflow: 'hidden' }}> <Skeleton animation="wave"> Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries. </Skeleton> </Typography> <Button> Read more <Skeleton animation="wave" /> </Button> </Card> </Stack> ); }
1,454
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/AvatarSkeleton.js
import * as React from 'react'; import Avatar from '@mui/joy/Avatar'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; export default function AvatarSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={4} useFlexGap sx={{ width: 200, height: 100, alignItems: 'center' }} > <Avatar src={loading ? '' : '/static/images/avatar/1.jpg'}> <Skeleton loading={loading} /> </Avatar> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,455
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/AvatarSkeleton.tsx
import * as React from 'react'; import Avatar from '@mui/joy/Avatar'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; export default function AvatarSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={4} useFlexGap sx={{ width: 200, height: 100, alignItems: 'center' }} > <Avatar src={loading ? '' : '/static/images/avatar/1.jpg'}> <Skeleton loading={loading} /> </Avatar> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,456
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/AvatarSkeleton.tsx.preview
<Avatar src={loading ? '' : '/static/images/avatar/1.jpg'}> <Skeleton loading={loading} /> </Avatar> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl>
1,457
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/BasicCardSkeleton.js
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import IconButton from '@mui/joy/IconButton'; import Typography from '@mui/joy/Typography'; import Skeleton from '@mui/joy/Skeleton'; import BookmarkAdd from '@mui/icons-material/BookmarkAddOutlined'; export default function BasicCardSkeleton() { return ( <Card variant="outlined" sx={{ width: 320 }}> <div> <Typography level="h2" fontSize="md" sx={{ mb: 0.5 }}> <Skeleton>Yosemite National Park</Skeleton> </Typography> <Typography level="body-sm"> <Skeleton>April 24 to May 02, 2021</Skeleton> </Typography> <IconButton aria-label="bookmark Bahamas Islands" variant="plain" color="neutral" size="sm" sx={{ position: 'absolute', top: '0.5rem', right: '0.5rem' }} > <BookmarkAdd /> <Skeleton /> </IconButton> </div> <AspectRatio minHeight="120px" maxHeight="200px"> <Skeleton> <img src="https://images.unsplash.com/photo-1527549993586-dff825b37782?auto=format&fit=crop&w=286" srcSet="https://images.unsplash.com/photo-1527549993586-dff825b37782?auto=format&fit=crop&w=286&dpr=2 2x" loading="lazy" alt="" /> </Skeleton> </AspectRatio> <CardContent orientation="horizontal"> <div> <Typography level="body-xs"> <Skeleton>Total price:</Skeleton> </Typography> <Typography fontSize="lg" fontWeight="lg"> <Skeleton>$2,900</Skeleton> </Typography> </div> <Button variant="solid" size="sm" color="primary" aria-label="Explore Bahamas Islands" sx={{ ml: 'auto', fontWeight: 600 }} > Explore <Skeleton /> </Button> </CardContent> </Card> ); }
1,458
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/BasicCardSkeleton.tsx
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import IconButton from '@mui/joy/IconButton'; import Typography from '@mui/joy/Typography'; import Skeleton from '@mui/joy/Skeleton'; import BookmarkAdd from '@mui/icons-material/BookmarkAddOutlined'; export default function BasicCardSkeleton() { return ( <Card variant="outlined" sx={{ width: 320 }}> <div> <Typography level="h2" fontSize="md" sx={{ mb: 0.5 }}> <Skeleton>Yosemite National Park</Skeleton> </Typography> <Typography level="body-sm"> <Skeleton>April 24 to May 02, 2021</Skeleton> </Typography> <IconButton aria-label="bookmark Bahamas Islands" variant="plain" color="neutral" size="sm" sx={{ position: 'absolute', top: '0.5rem', right: '0.5rem' }} > <BookmarkAdd /> <Skeleton /> </IconButton> </div> <AspectRatio minHeight="120px" maxHeight="200px"> <Skeleton> <img src="https://images.unsplash.com/photo-1527549993586-dff825b37782?auto=format&fit=crop&w=286" srcSet="https://images.unsplash.com/photo-1527549993586-dff825b37782?auto=format&fit=crop&w=286&dpr=2 2x" loading="lazy" alt="" /> </Skeleton> </AspectRatio> <CardContent orientation="horizontal"> <div> <Typography level="body-xs"> <Skeleton>Total price:</Skeleton> </Typography> <Typography fontSize="lg" fontWeight="lg"> <Skeleton>$2,900</Skeleton> </Typography> </div> <Button variant="solid" size="sm" color="primary" aria-label="Explore Bahamas Islands" sx={{ ml: 'auto', fontWeight: 600 }} > Explore <Skeleton /> </Button> </CardContent> </Card> ); }
1,459
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/BasicSkeleton.js
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Card from '@mui/joy/Card'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function BasicSkeleton() { return ( <Card variant="outlined" sx={{ width: 343, display: 'flex', gap: 2 }}> <AspectRatio ratio="21/9"> <Skeleton variant="overlay"> <img alt="" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" /> </Skeleton> </AspectRatio> <Typography> <Skeleton> Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries. </Skeleton> </Typography> </Card> ); }
1,460
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/BasicSkeleton.tsx
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Card from '@mui/joy/Card'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function BasicSkeleton() { return ( <Card variant="outlined" sx={{ width: 343, display: 'flex', gap: 2 }}> <AspectRatio ratio="21/9"> <Skeleton variant="overlay"> <img alt="" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" /> </Skeleton> </AspectRatio> <Typography> <Skeleton> Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries. </Skeleton> </Typography> </Card> ); }
1,461
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/BasicSkeleton.tsx.preview
<Card variant="outlined" sx={{ width: 343, display: 'flex', gap: 2 }}> <AspectRatio ratio="21/9"> <Skeleton variant="overlay"> <img alt="" src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" /> </Skeleton> </AspectRatio> <Typography> <Skeleton> Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries. </Skeleton> </Typography> </Card>
1,462
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/CommentSkeleton.js
import * as React from 'react'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import Skeleton from '@mui/joy/Skeleton'; export default function CommentSkeleton() { return ( <Card variant="outlined" sx={{ width: 'max(400px, 60%)', borderRadius: 0, '--Card-radius': 0 }} > <CardContent orientation="horizontal"> <Skeleton variant="rectangular" width={44} height={44} /> <div> <Skeleton variant="text" width={100} /> <Skeleton level="body-sm" variant="text" width={200} /> </div> </CardContent> <CardContent sx={{ gap: 0.5, mt: 1 }}> <Skeleton level="body-xs" variant="text" width="92%" /> <Skeleton level="body-xs" variant="text" width="99%" /> <Skeleton level="body-xs" variant="text" width="96%" /> </CardContent> </Card> ); }
1,463
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/CommentSkeleton.tsx
import * as React from 'react'; import Card from '@mui/joy/Card'; import CardContent from '@mui/joy/CardContent'; import Skeleton from '@mui/joy/Skeleton'; export default function CommentSkeleton() { return ( <Card variant="outlined" sx={{ width: 'max(400px, 60%)', borderRadius: 0, '--Card-radius': 0 }} > <CardContent orientation="horizontal"> <Skeleton variant="rectangular" width={44} height={44} /> <div> <Skeleton variant="text" width={100} /> <Skeleton level="body-sm" variant="text" width={200} /> </div> </CardContent> <CardContent sx={{ gap: 0.5, mt: 1 }}> <Skeleton level="body-xs" variant="text" width="92%" /> <Skeleton level="body-xs" variant="text" width="99%" /> <Skeleton level="body-xs" variant="text" width="96%" /> </CardContent> </Card> ); }
1,464
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/GeometrySkeleton.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Skeleton from '@mui/joy/Skeleton'; export default function GeometrySkeleton() { return ( <div> <Box sx={{ m: 'auto', display: 'flex', alignItems: 'center', gap: 2 }}> <Skeleton variant="circular" width={48} height={48} /> <div> <Skeleton variant="rectangular" width={200} height="1em" sx={{ mb: 1 }} /> <Skeleton variant="rectangular" width={140} height="1em" /> </div> </Box> </div> ); }
1,465
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/GeometrySkeleton.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Skeleton from '@mui/joy/Skeleton'; export default function GeometrySkeleton() { return ( <div> <Box sx={{ m: 'auto', display: 'flex', alignItems: 'center', gap: 2 }}> <Skeleton variant="circular" width={48} height={48} /> <div> <Skeleton variant="rectangular" width={200} height="1em" sx={{ mb: 1 }} /> <Skeleton variant="rectangular" width={140} height="1em" /> </div> </Box> </div> ); }
1,466
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/GeometrySkeleton.tsx.preview
<Box sx={{ m: 'auto', display: 'flex', alignItems: 'center', gap: 2 }}> <Skeleton variant="circular" width={48} height={48} /> <div> <Skeleton variant="rectangular" width={200} height="1em" sx={{ mb: 1 }} /> <Skeleton variant="rectangular" width={140} height="1em" /> </div> </Box>
1,467
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/ImageSkeleton.js
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Box from '@mui/joy/Box'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; export default function ImageSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap sx={{ alignItems: 'center' }}> <Box sx={{ m: 'auto' }}> <AspectRatio variant="plain" sx={{ width: 300 }}> <Skeleton loading={loading}> <img src={ loading ? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' : 'https://images.unsplash.com/photo-1686548812883-9d3777f4c137?h=400&fit=crop&auto=format&dpr=2' } alt="" /> </Skeleton> </AspectRatio> </Box> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,468
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/ImageSkeleton.tsx
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Box from '@mui/joy/Box'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; export default function ImageSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap sx={{ alignItems: 'center' }}> <Box sx={{ m: 'auto' }}> <AspectRatio variant="plain" sx={{ width: 300 }}> <Skeleton loading={loading}> <img src={ loading ? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' : 'https://images.unsplash.com/photo-1686548812883-9d3777f4c137?h=400&fit=crop&auto=format&dpr=2' } alt="" /> </Skeleton> </AspectRatio> </Box> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,469
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/InlineSkeleton.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; import Typography from '@mui/joy/Typography'; export default function InlineSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap sx={{ maxWidth: '60ch' }}> <Box sx={{ m: 'auto' }}> <Typography sx={{ position: 'relative', overflow: 'hidden' }} level="h1" fontSize="xl" > <Skeleton loading={loading}>A heading</Skeleton> </Typography> <Typography level="body-xs" sx={{ mt: 1, mb: 2, position: 'relative', overflow: 'hidden' }} > <Skeleton loading={loading}>HISTORY, PURPOSE AND USAGE</Skeleton> </Typography> <Typography sx={{ position: 'relative', overflow: 'hidden' }}> <Skeleton loading={loading}> <i>Lorem ipsum</i> is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. </Skeleton> </Typography> </Box> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,470
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/InlineSkeleton.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import FormControl from '@mui/joy/FormControl'; import FormLabel from '@mui/joy/FormLabel'; import Skeleton from '@mui/joy/Skeleton'; import Stack from '@mui/joy/Stack'; import Switch from '@mui/joy/Switch'; import Typography from '@mui/joy/Typography'; export default function InlineSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap sx={{ maxWidth: '60ch' }}> <Box sx={{ m: 'auto' }}> <Typography sx={{ position: 'relative', overflow: 'hidden' }} level="h1" fontSize="xl" > <Skeleton loading={loading}>A heading</Skeleton> </Typography> <Typography level="body-xs" sx={{ mt: 1, mb: 2, position: 'relative', overflow: 'hidden' }} > <Skeleton loading={loading}>HISTORY, PURPOSE AND USAGE</Skeleton> </Typography> <Typography sx={{ position: 'relative', overflow: 'hidden' }}> <Skeleton loading={loading}> <i>Lorem ipsum</i> is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups. </Skeleton> </Typography> </Box> <FormControl orientation="horizontal" sx={{ gap: 1 }}> <Switch size="sm" checked={loading} onChange={(event) => setLoading(event.target.checked)} /> <FormLabel>Loading</FormLabel> </FormControl> </Stack> ); }
1,471
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/LoadingSkeleton.js
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Stack from '@mui/joy/Stack'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function LoadingSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap> <Card variant="outlined" sx={{ width: 343 }}> <AspectRatio ratio="21/9"> <Skeleton loading={loading} variant="overlay"> <img alt="" src={ loading ? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' : 'https://images.unsplash.com/photo-1686548812883-9d3777f4c137?h=400&fit=crop&auto=format&dpr=2' } /> </Skeleton> </AspectRatio> <Typography> <Skeleton loading={loading}> {loading ? 'Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries.' : 'An aerial view of a road in the middle of a forest. This image was uploaded by Dian Yu on Unsplash.'} </Skeleton> </Typography> <Button onClick={() => setLoading(!loading)}> {loading ? 'Stop' : 'Start'} loading </Button> </Card> </Stack> ); }
1,472
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/LoadingSkeleton.tsx
import * as React from 'react'; import AspectRatio from '@mui/joy/AspectRatio'; import Stack from '@mui/joy/Stack'; import Button from '@mui/joy/Button'; import Card from '@mui/joy/Card'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function LoadingSkeleton() { const [loading, setLoading] = React.useState(true); return ( <Stack spacing={2} useFlexGap> <Card variant="outlined" sx={{ width: 343 }}> <AspectRatio ratio="21/9"> <Skeleton loading={loading} variant="overlay"> <img alt="" src={ loading ? 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' : 'https://images.unsplash.com/photo-1686548812883-9d3777f4c137?h=400&fit=crop&auto=format&dpr=2' } /> </Skeleton> </AspectRatio> <Typography> <Skeleton loading={loading}> {loading ? 'Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries.' : 'An aerial view of a road in the middle of a forest. This image was uploaded by Dian Yu on Unsplash.'} </Skeleton> </Typography> <Button onClick={() => setLoading(!loading)}> {loading ? 'Stop' : 'Start'} loading </Button> </Card> </Stack> ); }
1,473
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/TextBlockSkeleton.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function TextBlockSkeleton() { return ( <Box sx={{ display: 'grid', gridTemplateColumns: '100px 260px', gap: 1 }}> <Skeleton variant="text" level="h1" /> <Typography level="h1">h1 Typeface</Typography> <Skeleton variant="text" level="h2" /> <Typography level="h2">h2 Typeface</Typography> <Skeleton variant="text" /> <Typography>body-md Typeface</Typography> <Skeleton variant="text" level="body-sm" /> <Typography level="body-sm">body-sm Typeface</Typography> <Skeleton variant="text" level="body-xs" /> <Typography level="body-xs">body-xs Typeface</Typography> </Box> ); }
1,474
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/TextBlockSkeleton.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Skeleton from '@mui/joy/Skeleton'; import Typography from '@mui/joy/Typography'; export default function TextBlockSkeleton() { return ( <Box sx={{ display: 'grid', gridTemplateColumns: '100px 260px', gap: 1 }}> <Skeleton variant="text" level="h1" /> <Typography level="h1">h1 Typeface</Typography> <Skeleton variant="text" level="h2" /> <Typography level="h2">h2 Typeface</Typography> <Skeleton variant="text" /> <Typography>body-md Typeface</Typography> <Skeleton variant="text" level="body-sm" /> <Typography level="body-sm">body-sm Typeface</Typography> <Skeleton variant="text" level="body-xs" /> <Typography level="body-xs">body-xs Typeface</Typography> </Box> ); }
1,475
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/TextBlockSkeleton.tsx.preview
<Skeleton variant="text" level="h1" /> <Typography level="h1">h1 Typeface</Typography> <Skeleton variant="text" level="h2" /> <Typography level="h2">h2 Typeface</Typography> <Skeleton variant="text" /> <Typography>body-md Typeface</Typography> <Skeleton variant="text" level="body-sm" /> <Typography level="body-sm">body-sm Typeface</Typography> <Skeleton variant="text" level="body-xs" /> <Typography level="body-xs">body-xs Typeface</Typography>
1,476
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/skeleton/skeleton.md
--- productId: joy-ui title: React Skeleton component githubLabel: 'component: skeleton' components: Skeleton, AspectRatio, Avatar, Typography --- # Skeleton <p class="description">Skeletons are preview placeholders for components that haven't loaded yet, reducing load-time frustration.</p> ## Introduction Skeletons provide users an expectation of what the UI looks like while data loads. It helps reducing the perception of long loading times while being a more interesting loading state to look at. {{"demo": "BasicSkeleton.js"}} ## Basics ```jsx import Skeleton from '@mui/joy/Skeleton'; ``` There are two methods of using the Skeleton component: 1. **Masking a component**: see the [Avatar](#avatar), [Image](#image) and [Typography](#inline-with-typography) examples. The Skeleton component will inherit their dimension which makes for a more predictable UI while also preventing layout shift when the loading is done. 2. **Setting a custom width and height**: see the [Geometry](#geometry) and [Text block](#text-block) examples. Use this for full control of the Skeleton size, ignoring its parent dimensions entirely. Be aware that this option _can_ generate layout shift if the actual component the Skeleton is mimicking has a different size. ## Customization ### Loading The Skeleton has the `loading` prop set to `true` by default. Set it to `false` to hide the Skeleton component. If the Skeleton has children, they will be rendered instead. {{"demo": "LoadingSkeleton.js"}} ### Animation Use the `animation` prop to control how the Skeleton component animates. The `animation` prop value can be one of the following: - `pulse` (default): The background of the Skeleton fades in and out. - `wave`: A wave animation flowing from left to right. - `false`: Disable the animation entirely. The demo below shows the wave animation: {{"demo": "AnimationSkeleton.js"}} To set the `wave` animation as the default for all Skeleton component instances, use the theme's default props: ```js import { CssVarsProvider, extendTheme } from '@mui/joy/styles'; const theme = extendTheme({ components: { JoySkeleton: { defaultProps: { animation: 'wave', }, }, }, }); function App() { return ( <CssVarsProvider theme={theme}> <Skeleton />{' '} {/* The Skeleton component will have the wave animation by default */} </CssVarsProvider> ); } ``` :::info To learn more about global theme changes, see [Themed Components](/joy-ui/customization/themed-components/) page. ::: ### Avatar Use the [Avatar](/joy-ui/react-avatar/) component to wrap the Skeleton when displaying an avatar. {{"demo": "AvatarSkeleton.js"}} ### Image Use the [AspectRatio](/joy-ui/react-aspect-ratio/) component to wrap the Skeleton when displaying an image. {{"demo": "ImageSkeleton.js"}} ### Inline with Typography Insert the Skeleton between the Typography component and the text to display placeholder lines. {{"demo": "InlineSkeleton.js"}} ### Geometry To build a specific Skeleton shape, use the `variant` prop and choose between `circular` or `rectangular`. And to have it on a specific dimension, use the `width` and `height` props. {{"demo": "GeometrySkeleton.js"}} :::success The `width` and `height` props support object notation for responsive values. The example below shows how to create a Skeleton component with a circular shape that is 40x40px on mobile and 48x48px on desktop. ```js <Skeleton variant="circular" width={{ xs: 40, md: 48 }} height={{ xs: 40, md: 48 }} /> ``` ::: ### Text block Use the `variant="text"` and `level` props to create a block of skeleton text that follows the theme's typography styles. The `level` prop value can be a theme's typography-related token. The result of the skeleton text will have the same height as the text of the `level` prop. {{"demo": "TextBlockSkeleton.js"}} ## Common examples ### Basic card {{"demo": "BasicCardSkeleton.js"}} ### Comment {{"demo": "CommentSkeleton.js"}}
1,477
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/AlwaysVisibleLabelSlider.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value) { return `${value}°C`; } export default function AlwaysVisibleLabelSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Always visible" defaultValue={80} getAriaValueText={valueText} step={10} marks={marks} valueLabelDisplay="on" /> </Box> ); }
1,478
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/AlwaysVisibleLabelSlider.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value: number) { return `${value}°C`; } export default function AlwaysVisibleLabelSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Always visible" defaultValue={80} getAriaValueText={valueText} step={10} marks={marks} valueLabelDisplay="on" /> </Box> ); }
1,479
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/AlwaysVisibleLabelSlider.tsx.preview
<Slider aria-label="Always visible" defaultValue={80} getAriaValueText={valueText} step={10} marks={marks} valueLabelDisplay="on" />
1,480
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/EdgeLabelSlider.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider, { sliderClasses } from '@mui/joy/Slider'; function valueText(value) { return `${value}°C`; } export default function EdgeLabelSlider() { return ( <Box sx={{ width: 300 }}> <Slider track={false} defaultValue={[0, 100]} getAriaLabel={() => 'Amount'} getAriaValueText={valueText} marks={[ { value: 0, label: '0°C', }, { value: 100, label: '100°C', }, ]} valueLabelDisplay="on" sx={{ // Need both of the selectors to make it works on the server-side and client-side [`& [style*="left:0%"], & [style*="left: 0%"]`]: { [`&.${sliderClasses.markLabel}`]: { transform: 'none', }, [`& .${sliderClasses.valueLabel}`]: { left: 'calc(var(--Slider-thumbSize) / 2)', borderBottomLeftRadius: 0, '&::before': { left: 0, transform: 'translateY(100%)', borderLeftColor: 'currentColor', }, }, }, [`& [style*="left:100%"], & [style*="left: 100%"]`]: { [`&.${sliderClasses.markLabel}`]: { transform: 'translateX(-100%)', }, [`& .${sliderClasses.valueLabel}`]: { right: 'calc(var(--Slider-thumbSize) / 2)', borderBottomRightRadius: 0, '&::before': { left: 'initial', right: 0, transform: 'translateY(100%)', borderRightColor: 'currentColor', }, }, }, }} /> </Box> ); }
1,481
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/EdgeLabelSlider.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider, { sliderClasses } from '@mui/joy/Slider'; function valueText(value: number) { return `${value}°C`; } export default function EdgeLabelSlider() { return ( <Box sx={{ width: 300 }}> <Slider track={false} defaultValue={[0, 100]} getAriaLabel={() => 'Amount'} getAriaValueText={valueText} marks={[ { value: 0, label: '0°C', }, { value: 100, label: '100°C', }, ]} valueLabelDisplay="on" sx={{ // Need both of the selectors to make it works on the server-side and client-side [`& [style*="left:0%"], & [style*="left: 0%"]`]: { [`&.${sliderClasses.markLabel}`]: { transform: 'none', }, [`& .${sliderClasses.valueLabel}`]: { left: 'calc(var(--Slider-thumbSize) / 2)', borderBottomLeftRadius: 0, '&::before': { left: 0, transform: 'translateY(100%)', borderLeftColor: 'currentColor', }, }, }, [`& [style*="left:100%"], & [style*="left: 100%"]`]: { [`&.${sliderClasses.markLabel}`]: { transform: 'translateX(-100%)', }, [`& .${sliderClasses.valueLabel}`]: { right: 'calc(var(--Slider-thumbSize) / 2)', borderBottomRightRadius: 0, '&::before': { left: 'initial', right: 0, transform: 'translateY(100%)', borderRightColor: 'currentColor', }, }, }, }} /> </Box> ); }
1,482
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/MarksSlider.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value) { return `${value}°C`; } export default function MarksSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Custom marks" defaultValue={20} getAriaValueText={valueText} step={10} valueLabelDisplay="auto" marks={marks} /> </Box> ); }
1,483
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/MarksSlider.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value: number) { return `${value}°C`; } export default function MarksSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Custom marks" defaultValue={20} getAriaValueText={valueText} step={10} valueLabelDisplay="auto" marks={marks} /> </Box> ); }
1,484
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/MarksSlider.tsx.preview
<Slider aria-label="Custom marks" defaultValue={20} getAriaValueText={valueText} step={10} valueLabelDisplay="auto" marks={marks} />
1,485
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/RangeSlider.js
import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; import * as React from 'react'; function valueText(value) { return `${value}°C`; } export default function RangeSlider() { const [value, setValue] = React.useState([20, 37]); const handleChange = (event, newValue) => { setValue(newValue); }; return ( <Box sx={{ width: 300 }}> <Slider getAriaLabel={() => 'Temperature range'} value={value} onChange={handleChange} valueLabelDisplay="auto" getAriaValueText={valueText} /> </Box> ); }
1,486
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/RangeSlider.tsx
import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; import * as React from 'react'; function valueText(value: number) { return `${value}°C`; } export default function RangeSlider() { const [value, setValue] = React.useState<number[]>([20, 37]); const handleChange = (event: Event, newValue: number | number[]) => { setValue(newValue as number[]); }; return ( <Box sx={{ width: 300 }}> <Slider getAriaLabel={() => 'Temperature range'} value={value} onChange={handleChange} valueLabelDisplay="auto" getAriaValueText={valueText} /> </Box> ); }
1,487
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/RangeSlider.tsx.preview
<Slider getAriaLabel={() => 'Temperature range'} value={value} onChange={handleChange} valueLabelDisplay="auto" getAriaValueText={valueText} />
1,488
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/SliderSizes.js
import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; import * as React from 'react'; function valueText(value) { return `${value}°C`; } export default function SliderSizes() { return ( <Box sx={{ width: 300, display: 'flex', gap: 2, flexWrap: 'wrap', }} > <Slider size="sm" aria-labelledby="color-primary-slider" getAriaValueText={valueText} defaultValue={37} /> <Slider aria-labelledby="color-neutral-slider" getAriaValueText={valueText} defaultValue={37} /> <Slider size="lg" aria-labelledby="color-danger-slider" getAriaValueText={valueText} defaultValue={37} /> </Box> ); }
1,489
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/SliderSizes.tsx
import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; import * as React from 'react'; function valueText(value: number) { return `${value}°C`; } export default function SliderSizes() { return ( <Box sx={{ width: 300, display: 'flex', gap: 2, flexWrap: 'wrap', }} > <Slider size="sm" aria-labelledby="color-primary-slider" getAriaValueText={valueText} defaultValue={37} /> <Slider aria-labelledby="color-neutral-slider" getAriaValueText={valueText} defaultValue={37} /> <Slider size="lg" aria-labelledby="color-danger-slider" getAriaValueText={valueText} defaultValue={37} /> </Box> ); }
1,490
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/SliderUsage.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; import JoyUsageDemo from 'docs/src/modules/components/JoyUsageDemo'; export default function SliderUsage() { return ( <JoyUsageDemo componentName="Slider" data={[ { propName: 'variant', knob: 'radio', defaultValue: 'solid', options: ['plain', 'outlined', 'soft', 'solid'], }, { propName: 'color', knob: 'color', defaultValue: 'primary', }, { propName: 'size', knob: 'radio', options: ['sm', 'md', 'lg'], defaultValue: 'md', }, { propName: 'orientation', knob: 'radio', options: ['horizontal', 'vertical'], defaultValue: 'horizontal', }, { propName: 'valueLabelDisplay', knob: 'radio', options: ['off', 'on', 'auto'], defaultValue: 'off', }, { propName: 'disabled', knob: 'switch' }, { propName: 'marks', knob: 'switch' }, ]} renderDemo={(props) => ( <Box sx={{ ...(props.orientation === 'horizontal' && { width: 240, maxWidth: '100%', }), ...(props.orientation === 'vertical' && { height: 200 }), p: 2, lineHeight: 0, borderRadius: 'sm', }} > <Slider defaultValue={3} max={10} {...props} /> </Box> )} /> ); }
1,491
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/SliderVariables.js
import * as React from 'react'; import Slider from '@mui/joy/Slider'; import JoyVariablesDemo from 'docs/src/modules/components/JoyVariablesDemo'; export default function SliderVariables() { return ( <JoyVariablesDemo componentName="Slider" data={[ { var: '--Slider-trackSize', defaultValue: '6px' }, { var: '--Slider-markSize', defaultValue: '2px' }, { var: '--Slider-thumbSize', defaultValue: '14px' }, { var: '--Slider-thumbWidth', defaultValue: '14px' }, { var: '--Slider-valueLabelArrowSize', defaultValue: '8px' }, ]} renderDemo={(sx) => ( <Slider defaultValue={3} max={10} marks valueLabelDisplay="on" sx={{ ...sx, width: 240, maxWidth: '100%' }} /> )} /> ); }
1,492
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/StepsSlider.js
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; function valueText(value) { return `${value}°C`; } export default function StepsSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Small steps" defaultValue={0.00000005} getAriaValueText={valueText} step={0.00000001} marks min={-0.00000005} max={0.0000001} valueLabelDisplay="auto" /> </Box> ); }
1,493
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/StepsSlider.tsx
import * as React from 'react'; import Box from '@mui/joy/Box'; import Slider from '@mui/joy/Slider'; function valueText(value: number) { return `${value}°C`; } export default function StepsSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Small steps" defaultValue={0.00000005} getAriaValueText={valueText} step={0.00000001} marks min={-0.00000005} max={0.0000001} valueLabelDisplay="auto" /> </Box> ); }
1,494
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/StepsSlider.tsx.preview
<Slider aria-label="Small steps" defaultValue={0.00000005} getAriaValueText={valueText} step={0.00000001} marks min={-0.00000005} max={0.0000001} valueLabelDisplay="auto" />
1,495
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/TrackFalseSlider.js
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Box from '@mui/joy/Box'; import Typography from '@mui/joy/Typography'; import Slider from '@mui/joy/Slider'; const Separator = styled('div')( ({ theme }) => ` height: ${theme.spacing(3)}; `, ); const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value) { return `${value}°C`; } export default function TrackFalseSlider() { return ( <Box sx={{ width: 250 }}> <Typography id="track-false-slider" gutterBottom> Removed track </Typography> <Slider track={false} aria-labelledby="track-false-slider" getAriaValueText={valueText} defaultValue={37} marks={marks} /> <Separator /> <Typography id="track-false-range-slider" gutterBottom> Removed track range slider </Typography> <Slider track={false} aria-labelledby="track-false-range-slider" getAriaValueText={valueText} defaultValue={[20, 37, 100]} marks={marks} /> </Box> ); }
1,496
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/TrackFalseSlider.tsx
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Box from '@mui/joy/Box'; import Typography from '@mui/joy/Typography'; import Slider from '@mui/joy/Slider'; const Separator = styled('div')( ({ theme }) => ` height: ${theme.spacing(3)}; `, ); const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value: number) { return `${value}°C`; } export default function TrackFalseSlider() { return ( <Box sx={{ width: 250 }}> <Typography id="track-false-slider" gutterBottom> Removed track </Typography> <Slider track={false} aria-labelledby="track-false-slider" getAriaValueText={valueText} defaultValue={37} marks={marks} /> <Separator /> <Typography id="track-false-range-slider" gutterBottom> Removed track range slider </Typography> <Slider track={false} aria-labelledby="track-false-range-slider" getAriaValueText={valueText} defaultValue={[20, 37, 100]} marks={marks} /> </Box> ); }
1,497
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/TrackInvertedSlider.js
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Box from '@mui/joy/Box'; import Typography from '@mui/joy/Typography'; import Slider from '@mui/joy/Slider'; const Separator = styled('div')( ({ theme }) => ` height: ${theme.spacing(3)}; `, ); const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value) { return `${value}°C`; } export default function TrackInvertedSlider() { return ( <Box sx={{ width: 250 }}> <Typography id="track-inverted-slider" gutterBottom> Inverted track </Typography> <Slider track="inverted" aria-labelledby="track-inverted-slider" getAriaValueText={valueText} defaultValue={30} marks={marks} /> <Separator /> <Typography id="track-inverted-range-slider" gutterBottom> Inverted track range </Typography> <Slider track="inverted" aria-labelledby="track-inverted-range-slider" getAriaValueText={valueText} defaultValue={[20, 37]} marks={marks} /> </Box> ); }
1,498
0
petrpan-code/mui/material-ui/docs/data/joy/components
petrpan-code/mui/material-ui/docs/data/joy/components/slider/TrackInvertedSlider.tsx
import * as React from 'react'; import { styled } from '@mui/material/styles'; import Box from '@mui/joy/Box'; import Typography from '@mui/joy/Typography'; import Slider from '@mui/joy/Slider'; const Separator = styled('div')( ({ theme }) => ` height: ${theme.spacing(3)}; `, ); const marks = [ { value: 0, label: '0°C', }, { value: 20, label: '20°C', }, { value: 37, label: '37°C', }, { value: 100, label: '100°C', }, ]; function valueText(value: number) { return `${value}°C`; } export default function TrackInvertedSlider() { return ( <Box sx={{ width: 250 }}> <Typography id="track-inverted-slider" gutterBottom> Inverted track </Typography> <Slider track="inverted" aria-labelledby="track-inverted-slider" getAriaValueText={valueText} defaultValue={30} marks={marks} /> <Separator /> <Typography id="track-inverted-range-slider" gutterBottom> Inverted track range </Typography> <Slider track="inverted" aria-labelledby="track-inverted-range-slider" getAriaValueText={valueText} defaultValue={[20, 37]} marks={marks} /> </Box> ); }
1,499