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/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectGrouping.tsx.preview
<Select placeholder="Choose a character…"> <OptionGroup label="Hobbits"> <Option value="Frodo">Frodo</Option> <Option value="Sam">Sam</Option> <Option value="Merry">Merry</Option> <Option value="Pippin">Pippin</Option> </OptionGroup> <OptionGroup label="Elves"> <Option value="Galadriel">Galadriel</Option> <Option value="Legolas">Legolas</Option> </OptionGroup> </Select>
400
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectMultiple.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectMultiple() { return ( <MultiSelect defaultValue={[10, 20]}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> <Option value={40}>Forty</Option> <Option value={50}>Fifty</Option> </MultiSelect> ); } const MultiSelect = React.forwardRef(function CustomMultiSelect(props, ref) { const slots = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} multiple ref={ref} slots={slots} />; }); MultiSelect.propTypes = { /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), }; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; transition: border-radius 300ms ease; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } @supports selector(:has(*)) { &.${optionClasses.selected} { & + .${optionClasses.selected} { border-top-left-radius: 0; border-top-right-radius: 0; } &:has(+ .${optionClasses.selected}) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; } } } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
401
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectMultiple.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, selectClasses, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectMultiple() { return ( <MultiSelect defaultValue={[10, 20]}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> <Option value={40}>Forty</Option> <Option value={50}>Fifty</Option> </MultiSelect> ); } const MultiSelect = React.forwardRef(function CustomMultiSelect( props: SelectProps<number, true>, ref: React.ForwardedRef<any>, ) { const slots: SelectProps<number, true>['slots'] = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} multiple ref={ref} slots={slots} />; }); const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; transition: border-radius 300ms ease; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } @supports selector(:has(*)) { &.${optionClasses.selected} { & + .${optionClasses.selected} { border-top-left-radius: 0; border-top-right-radius: 0; } &:has(+ .${optionClasses.selected}) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; } } } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
402
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectMultiple.tsx.preview
<MultiSelect defaultValue={[10, 20]}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> <Option value={40}>Forty</Option> <Option value={50}>Fifty</Option> </MultiSelect>
403
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectObjectValues.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectObjectValues() { const [character, setCharacter] = React.useState(characters[0]); return ( <div> <Select value={character} onChange={(event, newValue) => setCharacter(newValue)} > {characters.map((c) => ( <Option key={c.name} value={c}> {c.name} </Option> ))} </Select> <Paragraph>Selected character:</Paragraph> <Pre>{JSON.stringify(character, null, 2)}</Pre> </div> ); } function Select(props) { const slots = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} slots={slots} />; } Select.propTypes = { /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), }; const characters = [ { name: 'Frodo', race: 'Hobbit' }, { name: 'Sam', race: 'Hobbit' }, { name: 'Merry', race: 'Hobbit' }, { name: 'Gandalf', race: 'Maia' }, { name: 'Gimli', race: 'Dwarf' }, ]; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const Paragraph = styled('p')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; margin: 12px 0; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]}; `, ); const Pre = styled('pre')( ({ theme }) => ` font-family: monospace; font-size: 0.75rem; color: ${theme.palette.mode === 'dark' ? '#FFF' : '#000'}; `, );
404
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectObjectValues.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, selectClasses, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectObjectValues() { const [character, setCharacter] = React.useState<Character | null>(characters[0]); return ( <div> <Select value={character} onChange={(event, newValue) => setCharacter(newValue)} > {characters.map((c) => ( <Option key={c.name} value={c}> {c.name} </Option> ))} </Select> <Paragraph>Selected character:</Paragraph> <Pre>{JSON.stringify(character, null, 2)}</Pre> </div> ); } function Select<TValue extends {}, Multiple extends boolean = false>( props: SelectProps<TValue, Multiple>, ) { const slots: SelectProps<TValue, Multiple>['slots'] = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} slots={slots} />; } interface Character { name: string; race: string; } const characters: Character[] = [ { name: 'Frodo', race: 'Hobbit' }, { name: 'Sam', race: 'Hobbit' }, { name: 'Merry', race: 'Hobbit' }, { name: 'Gandalf', race: 'Maia' }, { name: 'Gimli', race: 'Dwarf' }, ]; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const Paragraph = styled('p')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; margin: 12px 0; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[700]}; `, ); const Pre = styled('pre')( ({ theme }) => ` font-family: monospace; font-size: 0.75rem; color: ${theme.palette.mode === 'dark' ? '#FFF' : '#000'}; `, );
405
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectObjectValues.tsx.preview
<Select value={character} onChange={(event, newValue) => setCharacter(newValue)} > {characters.map((c) => ( <Option key={c.name} value={c}> {c.name} </Option> ))} </Select> <Paragraph>Selected character:</Paragraph> <Pre>{JSON.stringify(character, null, 2)}</Pre>
406
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectObjectValuesForm.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled, Box } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectObjectValuesForm() { const getSerializedValue = (option) => { if (option?.value == null) { return ''; } return `${option.value.race}.${option.value.name}`; }; const handleSubmit = (event) => { event.preventDefault(); const formData = new FormData(event.currentTarget); alert(`character=${formData.get('character')}`); }; return ( <div> <form onSubmit={handleSubmit}> <Box sx={{ display: 'flex', alignItems: 'flex-end' }}> <div> <Label id="object-value-default-label" htmlFor="object-value-default-button" > Default behavior </Label> <Select name="character" id="object-value-default-button" aria-labelledby="object-value-default-label object-value-default-button" placeholder="Choose a character…" > {characters.map((character) => ( <Option key={character.name} value={character}> {character.name} </Option> ))} </Select> </div> <SubmitButton sx={{ ml: 1 }} type="submit"> Submit </SubmitButton> </Box> </form> <form onSubmit={handleSubmit}> <Box sx={{ display: 'flex', alignItems: 'flex-end', mt: 2 }}> <div> <Label id="object-value-serialize-label" htmlFor="object-value-serialize-button" > Custom getSerializedValue </Label> <Select getSerializedValue={getSerializedValue} name="character" id="object-value-serialize-button" aria-labelledby="object-value-serialize-label object-value-serialize-button" placeholder="Choose a character…" > {characters.map((character) => ( <Option key={character.name} value={character}> {character.name} </Option> ))} </Select> </div> <SubmitButton sx={{ ml: 1 }} type="submit"> Submit </SubmitButton> </Box> </form> </div> ); } function Select(props) { const slots = { root: StyledButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} slots={slots} />; } Select.propTypes = { /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), }; const characters = [ { name: 'Frodo', race: 'Hobbit' }, { name: 'Sam', race: 'Hobbit' }, { name: 'Merry', race: 'Hobbit' }, { name: 'Gandalf', race: 'Maia' }, { name: 'Gimli', race: 'Dwarf' }, ]; const blue = { 100: '#DAECFF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled(Button, { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 8px; margin: 10px 0; min-width: 320px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[300]}; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; overflow: auto; outline: 0px; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px 12px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const Label = styled('label')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.85rem; display: block; margin-bottom: 4px; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]}; `, ); const SubmitButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; background-color: ${blue[500]}; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; border: 1px solid ${blue[500]}; box-shadow: 0 2px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)' }, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]}; &:hover { background-color: ${blue[600]}; } &:active { background-color: ${blue[700]}; box-shadow: none; } &:focus-visible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } &.disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; &:hover { background-color: ${blue[500]}; } } `, );
407
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectObjectValuesForm.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, selectClasses, SelectRootSlotProps, } from '@mui/base/Select'; import { SelectOption } from '@mui/base/useOption'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled, Box } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectObjectValuesForm() { const getSerializedValue = (option: SelectOption<Character> | null) => { if (option?.value == null) { return ''; } return `${option.value.race}.${option.value.name}`; }; const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); const formData = new FormData(event.currentTarget); alert(`character=${formData.get('character')}`); }; return ( <div> <form onSubmit={handleSubmit}> <Box sx={{ display: 'flex', alignItems: 'flex-end' }}> <div> <Label id="object-value-default-label" htmlFor="object-value-default-button" > Default behavior </Label> <Select name="character" id="object-value-default-button" aria-labelledby="object-value-default-label object-value-default-button" placeholder="Choose a character…" > {characters.map((character) => ( <Option key={character.name} value={character}> {character.name} </Option> ))} </Select> </div> <SubmitButton sx={{ ml: 1 }} type="submit"> Submit </SubmitButton> </Box> </form> <form onSubmit={handleSubmit}> <Box sx={{ display: 'flex', alignItems: 'flex-end', mt: 2 }}> <div> <Label id="object-value-serialize-label" htmlFor="object-value-serialize-button" > Custom getSerializedValue </Label> <Select getSerializedValue={getSerializedValue} name="character" id="object-value-serialize-button" aria-labelledby="object-value-serialize-label object-value-serialize-button" placeholder="Choose a character…" > {characters.map((character) => ( <Option key={character.name} value={character}> {character.name} </Option> ))} </Select> </div> <SubmitButton sx={{ ml: 1 }} type="submit"> Submit </SubmitButton> </Box> </form> </div> ); } function Select<TValue extends {}, Multiple extends boolean = false>( props: SelectProps<TValue, Multiple>, ) { const slots: SelectProps<TValue, Multiple>['slots'] = { root: StyledButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} slots={slots} />; } interface Character { name: string; race: string; } const characters: Character[] = [ { name: 'Frodo', race: 'Hobbit' }, { name: 'Sam', race: 'Hobbit' }, { name: 'Merry', race: 'Hobbit' }, { name: 'Gandalf', race: 'Maia' }, { name: 'Gimli', race: 'Dwarf' }, ]; const blue = { 100: '#DAECFF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); const StyledButton = styled(Button, { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 8px; margin: 10px 0; min-width: 320px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[300]}; border-radius: 8px; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; overflow: auto; outline: 0px; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px 12px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const Label = styled('label')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.85rem; display: block; margin-bottom: 4px; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[700]}; `, ); const SubmitButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; background-color: ${blue[500]}; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; border: 1px solid ${blue[500]}; box-shadow: 0 2px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.2)' }, inset 0 1.5px 1px ${blue[400]}, inset 0 -2px 1px ${blue[600]}; &:hover { background-color: ${blue[600]}; } &:active { background-color: ${blue[700]}; box-shadow: none; } &:focus-visible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } &.disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; &:hover { background-color: ${blue[500]}; } } `, );
408
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectRichOptions.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { styled } from '@mui/system'; import { Popper as BasePopper } from '@mui/base/Popper'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectRichOptions() { return ( <Select placeholder="Select country…"> {countries.map((country) => ( <Option key={country.code} value={country.code} label={country.label}> <img loading="lazy" width={20} height={14} srcSet={`https://flagcdn.com/w40/${country.code.toLowerCase()}.png 2x`} src={`https://flagcdn.com/w20/${country.code.toLowerCase()}.png`} alt={`Flag of ${country.label}`} /> {country.label} ({country.code}) +{country.phone} </Option> ))} </Select> ); } const Select = React.forwardRef(function CustomSelect(props, ref) { const slots = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }); Select.propTypes = { /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), }; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; max-height: 400px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } & img { margin-right: 10px; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const countries = [ { code: 'AD', label: 'Andorra', phone: '376' }, { code: 'AE', label: 'United Arab Emirates', phone: '971', }, { code: 'AF', label: 'Afghanistan', phone: '93' }, { code: 'AG', label: 'Antigua and Barbuda', phone: '1-268', }, { code: 'AI', label: 'Anguilla', phone: '1-264' }, { code: 'AL', label: 'Albania', phone: '355' }, { code: 'AM', label: 'Armenia', phone: '374' }, { code: 'AO', label: 'Angola', phone: '244' }, { code: 'AQ', label: 'Antarctica', phone: '672' }, { code: 'AR', label: 'Argentina', phone: '54' }, { code: 'AS', label: 'American Samoa', phone: '1-684' }, { code: 'AT', label: 'Austria', phone: '43' }, { code: 'AU', label: 'Australia', phone: '61', suggested: true, }, { code: 'AW', label: 'Aruba', phone: '297' }, { code: 'AX', label: 'Alland Islands', phone: '358' }, { code: 'AZ', label: 'Azerbaijan', phone: '994' }, { code: 'BA', label: 'Bosnia and Herzegovina', phone: '387', }, { code: 'BB', label: 'Barbados', phone: '1-246' }, { code: 'BD', label: 'Bangladesh', phone: '880' }, { code: 'BE', label: 'Belgium', phone: '32' }, { code: 'BF', label: 'Burkina Faso', phone: '226' }, { code: 'BG', label: 'Bulgaria', phone: '359' }, { code: 'BH', label: 'Bahrain', phone: '973' }, { code: 'BI', label: 'Burundi', phone: '257' }, { code: 'BJ', label: 'Benin', phone: '229' }, { code: 'BL', label: 'Saint Barthelemy', phone: '590' }, { code: 'BM', label: 'Bermuda', phone: '1-441' }, { code: 'BN', label: 'Brunei Darussalam', phone: '673' }, { code: 'BO', label: 'Bolivia', phone: '591' }, { code: 'BR', label: 'Brazil', phone: '55' }, { code: 'BS', label: 'Bahamas', phone: '1-242' }, { code: 'BT', label: 'Bhutan', phone: '975' }, { code: 'BV', label: 'Bouvet Island', phone: '47' }, { code: 'BW', label: 'Botswana', phone: '267' }, { code: 'BY', label: 'Belarus', phone: '375' }, { code: 'BZ', label: 'Belize', phone: '501' }, { code: 'CA', label: 'Canada', phone: '1', suggested: true, }, { code: 'CC', label: 'Cocos (Keeling) Islands', phone: '61', }, { code: 'CD', label: 'Congo, Democratic Republic of the', phone: '243', }, { code: 'CF', label: 'Central African Republic', phone: '236', }, { code: 'CG', label: 'Congo, Republic of the', phone: '242', }, { code: 'CH', label: 'Switzerland', phone: '41' }, { code: 'CI', label: "Cote d'Ivoire", phone: '225' }, { code: 'CK', label: 'Cook Islands', phone: '682' }, { code: 'CL', label: 'Chile', phone: '56' }, { code: 'CM', label: 'Cameroon', phone: '237' }, { code: 'CN', label: 'China', phone: '86' }, { code: 'CO', label: 'Colombia', phone: '57' }, { code: 'CR', label: 'Costa Rica', phone: '506' }, { code: 'CU', label: 'Cuba', phone: '53' }, { code: 'CV', label: 'Cape Verde', phone: '238' }, { code: 'CW', label: 'Curacao', phone: '599' }, { code: 'CX', label: 'Christmas Island', phone: '61' }, { code: 'CY', label: 'Cyprus', phone: '357' }, { code: 'CZ', label: 'Czech Republic', phone: '420' }, { code: 'DE', label: 'Germany', phone: '49', suggested: true, }, { code: 'DJ', label: 'Djibouti', phone: '253' }, { code: 'DK', label: 'Denmark', phone: '45' }, { code: 'DM', label: 'Dominica', phone: '1-767' }, { code: 'DO', label: 'Dominican Republic', phone: '1-809', }, { code: 'DZ', label: 'Algeria', phone: '213' }, { code: 'EC', label: 'Ecuador', phone: '593' }, { code: 'EE', label: 'Estonia', phone: '372' }, { code: 'EG', label: 'Egypt', phone: '20' }, { code: 'EH', label: 'Western Sahara', phone: '212' }, { code: 'ER', label: 'Eritrea', phone: '291' }, { code: 'ES', label: 'Spain', phone: '34' }, { code: 'ET', label: 'Ethiopia', phone: '251' }, { code: 'FI', label: 'Finland', phone: '358' }, { code: 'FJ', label: 'Fiji', phone: '679' }, { code: 'FK', label: 'Falkland Islands (Malvinas)', phone: '500', }, { code: 'FM', label: 'Micronesia, Federated States of', phone: '691', }, { code: 'FO', label: 'Faroe Islands', phone: '298' }, { code: 'FR', label: 'France', phone: '33', suggested: true, }, { code: 'GA', label: 'Gabon', phone: '241' }, { code: 'GB', label: 'United Kingdom', phone: '44' }, { code: 'GD', label: 'Grenada', phone: '1-473' }, { code: 'GE', label: 'Georgia', phone: '995' }, { code: 'GF', label: 'French Guiana', phone: '594' }, { code: 'GG', label: 'Guernsey', phone: '44' }, { code: 'GH', label: 'Ghana', phone: '233' }, { code: 'GI', label: 'Gibraltar', phone: '350' }, { code: 'GL', label: 'Greenland', phone: '299' }, { code: 'GM', label: 'Gambia', phone: '220' }, { code: 'GN', label: 'Guinea', phone: '224' }, { code: 'GP', label: 'Guadeloupe', phone: '590' }, { code: 'GQ', label: 'Equatorial Guinea', phone: '240' }, { code: 'GR', label: 'Greece', phone: '30' }, { code: 'GS', label: 'South Georgia and the South Sandwich Islands', phone: '500', }, { code: 'GT', label: 'Guatemala', phone: '502' }, { code: 'GU', label: 'Guam', phone: '1-671' }, { code: 'GW', label: 'Guinea-Bissau', phone: '245' }, { code: 'GY', label: 'Guyana', phone: '592' }, { code: 'HK', label: 'Hong Kong', phone: '852' }, { code: 'HM', label: 'Heard Island and McDonald Islands', phone: '672', }, { code: 'HN', label: 'Honduras', phone: '504' }, { code: 'HR', label: 'Croatia', phone: '385' }, { code: 'HT', label: 'Haiti', phone: '509' }, { code: 'HU', label: 'Hungary', phone: '36' }, { code: 'ID', label: 'Indonesia', phone: '62' }, { code: 'IE', label: 'Ireland', phone: '353' }, { code: 'IL', label: 'Israel', phone: '972' }, { code: 'IM', label: 'Isle of Man', phone: '44' }, { code: 'IN', label: 'India', phone: '91' }, { code: 'IO', label: 'British Indian Ocean Territory', phone: '246', }, { code: 'IQ', label: 'Iraq', phone: '964' }, { code: 'IR', label: 'Iran, Islamic Republic of', phone: '98', }, { code: 'IS', label: 'Iceland', phone: '354' }, { code: 'IT', label: 'Italy', phone: '39' }, { code: 'JE', label: 'Jersey', phone: '44' }, { code: 'JM', label: 'Jamaica', phone: '1-876' }, { code: 'JO', label: 'Jordan', phone: '962' }, { code: 'JP', label: 'Japan', phone: '81', suggested: true, }, { code: 'KE', label: 'Kenya', phone: '254' }, { code: 'KG', label: 'Kyrgyzstan', phone: '996' }, { code: 'KH', label: 'Cambodia', phone: '855' }, { code: 'KI', label: 'Kiribati', phone: '686' }, { code: 'KM', label: 'Comoros', phone: '269' }, { code: 'KN', label: 'Saint Kitts and Nevis', phone: '1-869', }, { code: 'KP', label: "Korea, Democratic People's Republic of", phone: '850', }, { code: 'KR', label: 'Korea, Republic of', phone: '82' }, { code: 'KW', label: 'Kuwait', phone: '965' }, { code: 'KY', label: 'Cayman Islands', phone: '1-345' }, { code: 'KZ', label: 'Kazakhstan', phone: '7' }, { code: 'LA', label: "Lao People's Democratic Republic", phone: '856', }, { code: 'LB', label: 'Lebanon', phone: '961' }, { code: 'LC', label: 'Saint Lucia', phone: '1-758' }, { code: 'LI', label: 'Liechtenstein', phone: '423' }, { code: 'LK', label: 'Sri Lanka', phone: '94' }, { code: 'LR', label: 'Liberia', phone: '231' }, { code: 'LS', label: 'Lesotho', phone: '266' }, { code: 'LT', label: 'Lithuania', phone: '370' }, { code: 'LU', label: 'Luxembourg', phone: '352' }, { code: 'LV', label: 'Latvia', phone: '371' }, { code: 'LY', label: 'Libya', phone: '218' }, { code: 'MA', label: 'Morocco', phone: '212' }, { code: 'MC', label: 'Monaco', phone: '377' }, { code: 'MD', label: 'Moldova, Republic of', phone: '373', }, { code: 'ME', label: 'Montenegro', phone: '382' }, { code: 'MF', label: 'Saint Martin (French part)', phone: '590', }, { code: 'MG', label: 'Madagascar', phone: '261' }, { code: 'MH', label: 'Marshall Islands', phone: '692' }, { code: 'MK', label: 'Macedonia, the Former Yugoslav Republic of', phone: '389', }, { code: 'ML', label: 'Mali', phone: '223' }, { code: 'MM', label: 'Myanmar', phone: '95' }, { code: 'MN', label: 'Mongolia', phone: '976' }, { code: 'MO', label: 'Macao', phone: '853' }, { code: 'MP', label: 'Northern Mariana Islands', phone: '1-670', }, { code: 'MQ', label: 'Martinique', phone: '596' }, { code: 'MR', label: 'Mauritania', phone: '222' }, { code: 'MS', label: 'Montserrat', phone: '1-664' }, { code: 'MT', label: 'Malta', phone: '356' }, { code: 'MU', label: 'Mauritius', phone: '230' }, { code: 'MV', label: 'Maldives', phone: '960' }, { code: 'MW', label: 'Malawi', phone: '265' }, { code: 'MX', label: 'Mexico', phone: '52' }, { code: 'MY', label: 'Malaysia', phone: '60' }, { code: 'MZ', label: 'Mozambique', phone: '258' }, { code: 'NA', label: 'Namibia', phone: '264' }, { code: 'NC', label: 'New Caledonia', phone: '687' }, { code: 'NE', label: 'Niger', phone: '227' }, { code: 'NF', label: 'Norfolk Island', phone: '672' }, { code: 'NG', label: 'Nigeria', phone: '234' }, { code: 'NI', label: 'Nicaragua', phone: '505' }, { code: 'NL', label: 'Netherlands', phone: '31' }, { code: 'NO', label: 'Norway', phone: '47' }, { code: 'NP', label: 'Nepal', phone: '977' }, { code: 'NR', label: 'Nauru', phone: '674' }, { code: 'NU', label: 'Niue', phone: '683' }, { code: 'NZ', label: 'New Zealand', phone: '64' }, { code: 'OM', label: 'Oman', phone: '968' }, { code: 'PA', label: 'Panama', phone: '507' }, { code: 'PE', label: 'Peru', phone: '51' }, { code: 'PF', label: 'French Polynesia', phone: '689' }, { code: 'PG', label: 'Papua New Guinea', phone: '675' }, { code: 'PH', label: 'Philippines', phone: '63' }, { code: 'PK', label: 'Pakistan', phone: '92' }, { code: 'PL', label: 'Poland', phone: '48' }, { code: 'PM', label: 'Saint Pierre and Miquelon', phone: '508', }, { code: 'PN', label: 'Pitcairn', phone: '870' }, { code: 'PR', label: 'Puerto Rico', phone: '1' }, { code: 'PS', label: 'Palestine, State of', phone: '970', }, { code: 'PT', label: 'Portugal', phone: '351' }, { code: 'PW', label: 'Palau', phone: '680' }, { code: 'PY', label: 'Paraguay', phone: '595' }, { code: 'QA', label: 'Qatar', phone: '974' }, { code: 'RE', label: 'Reunion', phone: '262' }, { code: 'RO', label: 'Romania', phone: '40' }, { code: 'RS', label: 'Serbia', phone: '381' }, { code: 'RU', label: 'Russian Federation', phone: '7' }, { code: 'RW', label: 'Rwanda', phone: '250' }, { code: 'SA', label: 'Saudi Arabia', phone: '966' }, { code: 'SB', label: 'Solomon Islands', phone: '677' }, { code: 'SC', label: 'Seychelles', phone: '248' }, { code: 'SD', label: 'Sudan', phone: '249' }, { code: 'SE', label: 'Sweden', phone: '46' }, { code: 'SG', label: 'Singapore', phone: '65' }, { code: 'SH', label: 'Saint Helena', phone: '290' }, { code: 'SI', label: 'Slovenia', phone: '386' }, { code: 'SJ', label: 'Svalbard and Jan Mayen', phone: '47', }, { code: 'SK', label: 'Slovakia', phone: '421' }, { code: 'SL', label: 'Sierra Leone', phone: '232' }, { code: 'SM', label: 'San Marino', phone: '378' }, { code: 'SN', label: 'Senegal', phone: '221' }, { code: 'SO', label: 'Somalia', phone: '252' }, { code: 'SR', label: 'Suriname', phone: '597' }, { code: 'SS', label: 'South Sudan', phone: '211' }, { code: 'ST', label: 'Sao Tome and Principe', phone: '239', }, { code: 'SV', label: 'El Salvador', phone: '503' }, { code: 'SX', label: 'Sint Maarten (Dutch part)', phone: '1-721', }, { code: 'SY', label: 'Syrian Arab Republic', phone: '963', }, { code: 'SZ', label: 'Swaziland', phone: '268' }, { code: 'TC', label: 'Turks and Caicos Islands', phone: '1-649', }, { code: 'TD', label: 'Chad', phone: '235' }, { code: 'TF', label: 'French Southern Territories', phone: '262', }, { code: 'TG', label: 'Togo', phone: '228' }, { code: 'TH', label: 'Thailand', phone: '66' }, { code: 'TJ', label: 'Tajikistan', phone: '992' }, { code: 'TK', label: 'Tokelau', phone: '690' }, { code: 'TL', label: 'Timor-Leste', phone: '670' }, { code: 'TM', label: 'Turkmenistan', phone: '993' }, { code: 'TN', label: 'Tunisia', phone: '216' }, { code: 'TO', label: 'Tonga', phone: '676' }, { code: 'TR', label: 'Turkey', phone: '90' }, { code: 'TT', label: 'Trinidad and Tobago', phone: '1-868', }, { code: 'TV', label: 'Tuvalu', phone: '688' }, { code: 'TW', label: 'Taiwan', phone: '886', }, { code: 'TZ', label: 'United Republic of Tanzania', phone: '255', }, { code: 'UA', label: 'Ukraine', phone: '380' }, { code: 'UG', label: 'Uganda', phone: '256' }, { code: 'US', label: 'United States', phone: '1', suggested: true, }, { code: 'UY', label: 'Uruguay', phone: '598' }, { code: 'UZ', label: 'Uzbekistan', phone: '998' }, { code: 'VA', label: 'Holy See (Vatican City State)', phone: '379', }, { code: 'VC', label: 'Saint Vincent and the Grenadines', phone: '1-784', }, { code: 'VE', label: 'Venezuela', phone: '58' }, { code: 'VG', label: 'British Virgin Islands', phone: '1-284', }, { code: 'VI', label: 'US Virgin Islands', phone: '1-340', }, { code: 'VN', label: 'Vietnam', phone: '84' }, { code: 'VU', label: 'Vanuatu', phone: '678' }, { code: 'WF', label: 'Wallis and Futuna', phone: '681' }, { code: 'WS', label: 'Samoa', phone: '685' }, { code: 'XK', label: 'Kosovo', phone: '383' }, { code: 'YE', label: 'Yemen', phone: '967' }, { code: 'YT', label: 'Mayotte', phone: '262' }, { code: 'ZA', label: 'South Africa', phone: '27' }, { code: 'ZM', label: 'Zambia', phone: '260' }, { code: 'ZW', label: 'Zimbabwe', phone: '263' }, ];
409
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectRichOptions.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, selectClasses, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { styled } from '@mui/system'; import { Popper as BasePopper } from '@mui/base/Popper'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectRichOptions() { return ( <Select placeholder="Select country…"> {countries.map((country) => ( <Option key={country.code} value={country.code} label={country.label}> <img loading="lazy" width={20} height={14} srcSet={`https://flagcdn.com/w40/${country.code.toLowerCase()}.png 2x`} src={`https://flagcdn.com/w20/${country.code.toLowerCase()}.png`} alt={`Flag of ${country.label}`} /> {country.label} ({country.code}) +{country.phone} </Option> ))} </Select> ); } const Select = React.forwardRef(function CustomSelect( props: SelectProps<number, false>, ref: React.ForwardedRef<any>, ) { const slots: SelectProps<number, false>['slots'] = { root: Button, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }); const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; max-height: 400px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } & img { margin-right: 10px; } `, ); const Popper = styled(BasePopper)` z-index: 1; `; const countries = [ { code: 'AD', label: 'Andorra', phone: '376' }, { code: 'AE', label: 'United Arab Emirates', phone: '971', }, { code: 'AF', label: 'Afghanistan', phone: '93' }, { code: 'AG', label: 'Antigua and Barbuda', phone: '1-268', }, { code: 'AI', label: 'Anguilla', phone: '1-264' }, { code: 'AL', label: 'Albania', phone: '355' }, { code: 'AM', label: 'Armenia', phone: '374' }, { code: 'AO', label: 'Angola', phone: '244' }, { code: 'AQ', label: 'Antarctica', phone: '672' }, { code: 'AR', label: 'Argentina', phone: '54' }, { code: 'AS', label: 'American Samoa', phone: '1-684' }, { code: 'AT', label: 'Austria', phone: '43' }, { code: 'AU', label: 'Australia', phone: '61', suggested: true, }, { code: 'AW', label: 'Aruba', phone: '297' }, { code: 'AX', label: 'Alland Islands', phone: '358' }, { code: 'AZ', label: 'Azerbaijan', phone: '994' }, { code: 'BA', label: 'Bosnia and Herzegovina', phone: '387', }, { code: 'BB', label: 'Barbados', phone: '1-246' }, { code: 'BD', label: 'Bangladesh', phone: '880' }, { code: 'BE', label: 'Belgium', phone: '32' }, { code: 'BF', label: 'Burkina Faso', phone: '226' }, { code: 'BG', label: 'Bulgaria', phone: '359' }, { code: 'BH', label: 'Bahrain', phone: '973' }, { code: 'BI', label: 'Burundi', phone: '257' }, { code: 'BJ', label: 'Benin', phone: '229' }, { code: 'BL', label: 'Saint Barthelemy', phone: '590' }, { code: 'BM', label: 'Bermuda', phone: '1-441' }, { code: 'BN', label: 'Brunei Darussalam', phone: '673' }, { code: 'BO', label: 'Bolivia', phone: '591' }, { code: 'BR', label: 'Brazil', phone: '55' }, { code: 'BS', label: 'Bahamas', phone: '1-242' }, { code: 'BT', label: 'Bhutan', phone: '975' }, { code: 'BV', label: 'Bouvet Island', phone: '47' }, { code: 'BW', label: 'Botswana', phone: '267' }, { code: 'BY', label: 'Belarus', phone: '375' }, { code: 'BZ', label: 'Belize', phone: '501' }, { code: 'CA', label: 'Canada', phone: '1', suggested: true, }, { code: 'CC', label: 'Cocos (Keeling) Islands', phone: '61', }, { code: 'CD', label: 'Congo, Democratic Republic of the', phone: '243', }, { code: 'CF', label: 'Central African Republic', phone: '236', }, { code: 'CG', label: 'Congo, Republic of the', phone: '242', }, { code: 'CH', label: 'Switzerland', phone: '41' }, { code: 'CI', label: "Cote d'Ivoire", phone: '225' }, { code: 'CK', label: 'Cook Islands', phone: '682' }, { code: 'CL', label: 'Chile', phone: '56' }, { code: 'CM', label: 'Cameroon', phone: '237' }, { code: 'CN', label: 'China', phone: '86' }, { code: 'CO', label: 'Colombia', phone: '57' }, { code: 'CR', label: 'Costa Rica', phone: '506' }, { code: 'CU', label: 'Cuba', phone: '53' }, { code: 'CV', label: 'Cape Verde', phone: '238' }, { code: 'CW', label: 'Curacao', phone: '599' }, { code: 'CX', label: 'Christmas Island', phone: '61' }, { code: 'CY', label: 'Cyprus', phone: '357' }, { code: 'CZ', label: 'Czech Republic', phone: '420' }, { code: 'DE', label: 'Germany', phone: '49', suggested: true, }, { code: 'DJ', label: 'Djibouti', phone: '253' }, { code: 'DK', label: 'Denmark', phone: '45' }, { code: 'DM', label: 'Dominica', phone: '1-767' }, { code: 'DO', label: 'Dominican Republic', phone: '1-809', }, { code: 'DZ', label: 'Algeria', phone: '213' }, { code: 'EC', label: 'Ecuador', phone: '593' }, { code: 'EE', label: 'Estonia', phone: '372' }, { code: 'EG', label: 'Egypt', phone: '20' }, { code: 'EH', label: 'Western Sahara', phone: '212' }, { code: 'ER', label: 'Eritrea', phone: '291' }, { code: 'ES', label: 'Spain', phone: '34' }, { code: 'ET', label: 'Ethiopia', phone: '251' }, { code: 'FI', label: 'Finland', phone: '358' }, { code: 'FJ', label: 'Fiji', phone: '679' }, { code: 'FK', label: 'Falkland Islands (Malvinas)', phone: '500', }, { code: 'FM', label: 'Micronesia, Federated States of', phone: '691', }, { code: 'FO', label: 'Faroe Islands', phone: '298' }, { code: 'FR', label: 'France', phone: '33', suggested: true, }, { code: 'GA', label: 'Gabon', phone: '241' }, { code: 'GB', label: 'United Kingdom', phone: '44' }, { code: 'GD', label: 'Grenada', phone: '1-473' }, { code: 'GE', label: 'Georgia', phone: '995' }, { code: 'GF', label: 'French Guiana', phone: '594' }, { code: 'GG', label: 'Guernsey', phone: '44' }, { code: 'GH', label: 'Ghana', phone: '233' }, { code: 'GI', label: 'Gibraltar', phone: '350' }, { code: 'GL', label: 'Greenland', phone: '299' }, { code: 'GM', label: 'Gambia', phone: '220' }, { code: 'GN', label: 'Guinea', phone: '224' }, { code: 'GP', label: 'Guadeloupe', phone: '590' }, { code: 'GQ', label: 'Equatorial Guinea', phone: '240' }, { code: 'GR', label: 'Greece', phone: '30' }, { code: 'GS', label: 'South Georgia and the South Sandwich Islands', phone: '500', }, { code: 'GT', label: 'Guatemala', phone: '502' }, { code: 'GU', label: 'Guam', phone: '1-671' }, { code: 'GW', label: 'Guinea-Bissau', phone: '245' }, { code: 'GY', label: 'Guyana', phone: '592' }, { code: 'HK', label: 'Hong Kong', phone: '852' }, { code: 'HM', label: 'Heard Island and McDonald Islands', phone: '672', }, { code: 'HN', label: 'Honduras', phone: '504' }, { code: 'HR', label: 'Croatia', phone: '385' }, { code: 'HT', label: 'Haiti', phone: '509' }, { code: 'HU', label: 'Hungary', phone: '36' }, { code: 'ID', label: 'Indonesia', phone: '62' }, { code: 'IE', label: 'Ireland', phone: '353' }, { code: 'IL', label: 'Israel', phone: '972' }, { code: 'IM', label: 'Isle of Man', phone: '44' }, { code: 'IN', label: 'India', phone: '91' }, { code: 'IO', label: 'British Indian Ocean Territory', phone: '246', }, { code: 'IQ', label: 'Iraq', phone: '964' }, { code: 'IR', label: 'Iran, Islamic Republic of', phone: '98', }, { code: 'IS', label: 'Iceland', phone: '354' }, { code: 'IT', label: 'Italy', phone: '39' }, { code: 'JE', label: 'Jersey', phone: '44' }, { code: 'JM', label: 'Jamaica', phone: '1-876' }, { code: 'JO', label: 'Jordan', phone: '962' }, { code: 'JP', label: 'Japan', phone: '81', suggested: true, }, { code: 'KE', label: 'Kenya', phone: '254' }, { code: 'KG', label: 'Kyrgyzstan', phone: '996' }, { code: 'KH', label: 'Cambodia', phone: '855' }, { code: 'KI', label: 'Kiribati', phone: '686' }, { code: 'KM', label: 'Comoros', phone: '269' }, { code: 'KN', label: 'Saint Kitts and Nevis', phone: '1-869', }, { code: 'KP', label: "Korea, Democratic People's Republic of", phone: '850', }, { code: 'KR', label: 'Korea, Republic of', phone: '82' }, { code: 'KW', label: 'Kuwait', phone: '965' }, { code: 'KY', label: 'Cayman Islands', phone: '1-345' }, { code: 'KZ', label: 'Kazakhstan', phone: '7' }, { code: 'LA', label: "Lao People's Democratic Republic", phone: '856', }, { code: 'LB', label: 'Lebanon', phone: '961' }, { code: 'LC', label: 'Saint Lucia', phone: '1-758' }, { code: 'LI', label: 'Liechtenstein', phone: '423' }, { code: 'LK', label: 'Sri Lanka', phone: '94' }, { code: 'LR', label: 'Liberia', phone: '231' }, { code: 'LS', label: 'Lesotho', phone: '266' }, { code: 'LT', label: 'Lithuania', phone: '370' }, { code: 'LU', label: 'Luxembourg', phone: '352' }, { code: 'LV', label: 'Latvia', phone: '371' }, { code: 'LY', label: 'Libya', phone: '218' }, { code: 'MA', label: 'Morocco', phone: '212' }, { code: 'MC', label: 'Monaco', phone: '377' }, { code: 'MD', label: 'Moldova, Republic of', phone: '373', }, { code: 'ME', label: 'Montenegro', phone: '382' }, { code: 'MF', label: 'Saint Martin (French part)', phone: '590', }, { code: 'MG', label: 'Madagascar', phone: '261' }, { code: 'MH', label: 'Marshall Islands', phone: '692' }, { code: 'MK', label: 'Macedonia, the Former Yugoslav Republic of', phone: '389', }, { code: 'ML', label: 'Mali', phone: '223' }, { code: 'MM', label: 'Myanmar', phone: '95' }, { code: 'MN', label: 'Mongolia', phone: '976' }, { code: 'MO', label: 'Macao', phone: '853' }, { code: 'MP', label: 'Northern Mariana Islands', phone: '1-670', }, { code: 'MQ', label: 'Martinique', phone: '596' }, { code: 'MR', label: 'Mauritania', phone: '222' }, { code: 'MS', label: 'Montserrat', phone: '1-664' }, { code: 'MT', label: 'Malta', phone: '356' }, { code: 'MU', label: 'Mauritius', phone: '230' }, { code: 'MV', label: 'Maldives', phone: '960' }, { code: 'MW', label: 'Malawi', phone: '265' }, { code: 'MX', label: 'Mexico', phone: '52' }, { code: 'MY', label: 'Malaysia', phone: '60' }, { code: 'MZ', label: 'Mozambique', phone: '258' }, { code: 'NA', label: 'Namibia', phone: '264' }, { code: 'NC', label: 'New Caledonia', phone: '687' }, { code: 'NE', label: 'Niger', phone: '227' }, { code: 'NF', label: 'Norfolk Island', phone: '672' }, { code: 'NG', label: 'Nigeria', phone: '234' }, { code: 'NI', label: 'Nicaragua', phone: '505' }, { code: 'NL', label: 'Netherlands', phone: '31' }, { code: 'NO', label: 'Norway', phone: '47' }, { code: 'NP', label: 'Nepal', phone: '977' }, { code: 'NR', label: 'Nauru', phone: '674' }, { code: 'NU', label: 'Niue', phone: '683' }, { code: 'NZ', label: 'New Zealand', phone: '64' }, { code: 'OM', label: 'Oman', phone: '968' }, { code: 'PA', label: 'Panama', phone: '507' }, { code: 'PE', label: 'Peru', phone: '51' }, { code: 'PF', label: 'French Polynesia', phone: '689' }, { code: 'PG', label: 'Papua New Guinea', phone: '675' }, { code: 'PH', label: 'Philippines', phone: '63' }, { code: 'PK', label: 'Pakistan', phone: '92' }, { code: 'PL', label: 'Poland', phone: '48' }, { code: 'PM', label: 'Saint Pierre and Miquelon', phone: '508', }, { code: 'PN', label: 'Pitcairn', phone: '870' }, { code: 'PR', label: 'Puerto Rico', phone: '1' }, { code: 'PS', label: 'Palestine, State of', phone: '970', }, { code: 'PT', label: 'Portugal', phone: '351' }, { code: 'PW', label: 'Palau', phone: '680' }, { code: 'PY', label: 'Paraguay', phone: '595' }, { code: 'QA', label: 'Qatar', phone: '974' }, { code: 'RE', label: 'Reunion', phone: '262' }, { code: 'RO', label: 'Romania', phone: '40' }, { code: 'RS', label: 'Serbia', phone: '381' }, { code: 'RU', label: 'Russian Federation', phone: '7' }, { code: 'RW', label: 'Rwanda', phone: '250' }, { code: 'SA', label: 'Saudi Arabia', phone: '966' }, { code: 'SB', label: 'Solomon Islands', phone: '677' }, { code: 'SC', label: 'Seychelles', phone: '248' }, { code: 'SD', label: 'Sudan', phone: '249' }, { code: 'SE', label: 'Sweden', phone: '46' }, { code: 'SG', label: 'Singapore', phone: '65' }, { code: 'SH', label: 'Saint Helena', phone: '290' }, { code: 'SI', label: 'Slovenia', phone: '386' }, { code: 'SJ', label: 'Svalbard and Jan Mayen', phone: '47', }, { code: 'SK', label: 'Slovakia', phone: '421' }, { code: 'SL', label: 'Sierra Leone', phone: '232' }, { code: 'SM', label: 'San Marino', phone: '378' }, { code: 'SN', label: 'Senegal', phone: '221' }, { code: 'SO', label: 'Somalia', phone: '252' }, { code: 'SR', label: 'Suriname', phone: '597' }, { code: 'SS', label: 'South Sudan', phone: '211' }, { code: 'ST', label: 'Sao Tome and Principe', phone: '239', }, { code: 'SV', label: 'El Salvador', phone: '503' }, { code: 'SX', label: 'Sint Maarten (Dutch part)', phone: '1-721', }, { code: 'SY', label: 'Syrian Arab Republic', phone: '963', }, { code: 'SZ', label: 'Swaziland', phone: '268' }, { code: 'TC', label: 'Turks and Caicos Islands', phone: '1-649', }, { code: 'TD', label: 'Chad', phone: '235' }, { code: 'TF', label: 'French Southern Territories', phone: '262', }, { code: 'TG', label: 'Togo', phone: '228' }, { code: 'TH', label: 'Thailand', phone: '66' }, { code: 'TJ', label: 'Tajikistan', phone: '992' }, { code: 'TK', label: 'Tokelau', phone: '690' }, { code: 'TL', label: 'Timor-Leste', phone: '670' }, { code: 'TM', label: 'Turkmenistan', phone: '993' }, { code: 'TN', label: 'Tunisia', phone: '216' }, { code: 'TO', label: 'Tonga', phone: '676' }, { code: 'TR', label: 'Turkey', phone: '90' }, { code: 'TT', label: 'Trinidad and Tobago', phone: '1-868', }, { code: 'TV', label: 'Tuvalu', phone: '688' }, { code: 'TW', label: 'Taiwan', phone: '886', }, { code: 'TZ', label: 'United Republic of Tanzania', phone: '255', }, { code: 'UA', label: 'Ukraine', phone: '380' }, { code: 'UG', label: 'Uganda', phone: '256' }, { code: 'US', label: 'United States', phone: '1', suggested: true, }, { code: 'UY', label: 'Uruguay', phone: '598' }, { code: 'UZ', label: 'Uzbekistan', phone: '998' }, { code: 'VA', label: 'Holy See (Vatican City State)', phone: '379', }, { code: 'VC', label: 'Saint Vincent and the Grenadines', phone: '1-784', }, { code: 'VE', label: 'Venezuela', phone: '58' }, { code: 'VG', label: 'British Virgin Islands', phone: '1-284', }, { code: 'VI', label: 'US Virgin Islands', phone: '1-340', }, { code: 'VN', label: 'Vietnam', phone: '84' }, { code: 'VU', label: 'Vanuatu', phone: '678' }, { code: 'WF', label: 'Wallis and Futuna', phone: '681' }, { code: 'WS', label: 'Samoa', phone: '685' }, { code: 'XK', label: 'Kosovo', phone: '383' }, { code: 'YE', label: 'Yemen', phone: '967' }, { code: 'YT', label: 'Mayotte', phone: '262' }, { code: 'ZA', label: 'South Africa', phone: '27' }, { code: 'ZM', label: 'Zambia', phone: '260' }, { code: 'ZW', label: 'Zimbabwe', phone: '263' }, ];
410
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectRichOptions.tsx.preview
<Select placeholder="Select country…"> {countries.map((country) => ( <Option key={country.code} value={country.code} label={country.label}> <img loading="lazy" width={20} height={14} srcSet={`https://flagcdn.com/w40/${country.code.toLowerCase()}.png 2x`} src={`https://flagcdn.com/w20/${country.code.toLowerCase()}.png`} alt={`Flag of ${country.label}`} /> {country.label} ({country.code}) +{country.phone} </Option> ))} </Select>
411
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UseSelect.js
import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; import { useSelect, SelectProvider } from '@mui/base/useSelect'; import { useOption } from '@mui/base/useOption'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UseSelect() { return <CustomSelect placeholder="Select a color…" options={options} />; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Root = styled('div')` position: relative; `; const Toggle = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:focus-visible { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-height: calc(1.5em + 22px); min-width: 320px; padding: 12px; border-radius: 12px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; padding: 5px; margin: 5px 0 0 0; position: absolute; height: auto; width: 100%; overflow: auto; z-index: 1; outline: 0px; list-style: none; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; &.hidden { opacity: 0; visibility: hidden; transition: opacity 0.4s ease, visibility 0.4s step-end; } `, ); const Option = styled('li')( ({ theme }) => ` padding: 8px; border-radius: 0.45em; &[aria-selected='true'] { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.highlighted, &:hover { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &[aria-selected='true'].highlighted { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &:before { content: ''; width: 1ex; height: 1ex; margin-right: 1ex; background-color: var(--color); display: inline-block; border-radius: 50%; vertical-align: middle; } `, ); function renderSelectedValue(value, options) { const selectedOption = options.find((option) => option.value === value); return selectedOption ? `${selectedOption.label} (${value})` : null; } function CustomOption(props) { const { children, value, className, disabled = false } = props; const { getRootProps, highlighted } = useOption({ value, disabled, label: children, }); return ( <Option {...getRootProps()} className={clsx({ highlighted }, className)} style={{ '--color': value }} > {children} </Option> ); } CustomOption.propTypes = { children: PropTypes.node, className: PropTypes.string, disabled: PropTypes.bool, value: PropTypes.string.isRequired, }; function CustomSelect({ options, placeholder }) { const listboxRef = React.useRef(null); const [listboxVisible, setListboxVisible] = React.useState(false); const { getButtonProps, getListboxProps, contextValue, value } = useSelect({ listboxRef, onOpenChange: setListboxVisible, open: listboxVisible, }); React.useEffect(() => { if (listboxVisible) { listboxRef.current?.focus(); } }, [listboxVisible]); return ( <Root> <Toggle {...getButtonProps()} style={{ '--color': value }}> {renderSelectedValue(value, options) || ( <span className="placeholder">{placeholder ?? ' '}</span> )} <UnfoldMoreRoundedIcon /> </Toggle> <Listbox {...getListboxProps()} aria-hidden={!listboxVisible} className={listboxVisible ? '' : 'hidden'} > <SelectProvider value={contextValue}> {options.map((option) => { return ( <CustomOption key={option.value} value={option.value}> {option.label} </CustomOption> ); })} </SelectProvider> </Listbox> </Root> ); } CustomSelect.propTypes = { options: PropTypes.arrayOf( PropTypes.shape({ disabled: PropTypes.bool, label: PropTypes.string.isRequired, value: PropTypes.string.isRequired, }), ).isRequired, placeholder: PropTypes.string, }; const options = [ { label: 'Red', value: '#D32F2F', }, { label: 'Green', value: '#4CAF50', }, { label: 'Blue', value: '#2196F3', }, ];
412
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UseSelect.tsx
import * as React from 'react'; import clsx from 'clsx'; import { useSelect, SelectOptionDefinition, SelectProvider, } from '@mui/base/useSelect'; import { useOption } from '@mui/base/useOption'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UseSelect() { return <CustomSelect placeholder="Select a color…" options={options} />; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Root = styled('div')` position: relative; `; const Toggle = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 2px ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:focus-visible { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[600] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-height: calc(1.5em + 22px); min-width: 320px; padding: 12px; border-radius: 12px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; padding: 5px; margin: 5px 0 0 0; position: absolute; height: auto; width: 100%; overflow: auto; z-index: 1; outline: 0px; list-style: none; box-shadow: 0px 2px 6px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; &.hidden { opacity: 0; visibility: hidden; transition: opacity 0.4s ease, visibility 0.4s step-end; } `, ); const Option = styled('li')( ({ theme }) => ` padding: 8px; border-radius: 0.45em; &[aria-selected='true'] { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.highlighted, &:hover { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &[aria-selected='true'].highlighted { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &:before { content: ''; width: 1ex; height: 1ex; margin-right: 1ex; background-color: var(--color); display: inline-block; border-radius: 50%; vertical-align: middle; } `, ); interface Props { options: SelectOptionDefinition<string>[]; placeholder?: string; } interface OptionProps { children?: React.ReactNode; className?: string; value: string; disabled?: boolean; } function renderSelectedValue( value: string | null, options: SelectOptionDefinition<string>[], ) { const selectedOption = options.find((option) => option.value === value); return selectedOption ? `${selectedOption.label} (${value})` : null; } function CustomOption(props: OptionProps) { const { children, value, className, disabled = false } = props; const { getRootProps, highlighted } = useOption({ value, disabled, label: children, }); return ( <Option {...getRootProps()} className={clsx({ highlighted }, className)} style={{ '--color': value } as any} > {children} </Option> ); } function CustomSelect({ options, placeholder }: Props) { const listboxRef = React.useRef<HTMLUListElement>(null); const [listboxVisible, setListboxVisible] = React.useState(false); const { getButtonProps, getListboxProps, contextValue, value } = useSelect< string, false >({ listboxRef, onOpenChange: setListboxVisible, open: listboxVisible, }); React.useEffect(() => { if (listboxVisible) { listboxRef.current?.focus(); } }, [listboxVisible]); return ( <Root> <Toggle {...getButtonProps()} style={{ '--color': value } as any}> {renderSelectedValue(value, options) || ( <span className="placeholder">{placeholder ?? ' '}</span> )} <UnfoldMoreRoundedIcon /> </Toggle> <Listbox {...getListboxProps()} aria-hidden={!listboxVisible} className={listboxVisible ? '' : 'hidden'} > <SelectProvider value={contextValue}> {options.map((option) => { return ( <CustomOption key={option.value} value={option.value}> {option.label} </CustomOption> ); })} </SelectProvider> </Listbox> </Root> ); } const options = [ { label: 'Red', value: '#D32F2F', }, { label: 'Green', value: '#4CAF50', }, { label: 'Blue', value: '#2196F3', }, ];
413
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/UseSelect.tsx.preview
<CustomSelect placeholder="Select a color…" options={options} />
414
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/select/select.md
--- productId: base-ui title: React Select components and hook components: Select, Option, OptionGroup hooks: useSelect, useOption, useOptionContextStabilizer githubLabel: 'component: select' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/ --- # Select <p class="description">The Select components let you create lists of options for users to choose from.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction A select is a UI element that gives users a list of options to choose from. Base UI's Select component replaces the native HTML `<select>` tag. It also includes the Option component for creating the options in the list, and Option Group for grouping those options. {{"demo": "UnstyledSelectIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Components ```jsx import { Select } from '@mui/base/Select'; import { Option } from '@mui/base/Option'; ``` The following demo shows how to create and style a Select component with several Options: {{"demo": "UnstyledSelectBasic", "defaultCodeOpen": false}} ### Form submission The value(s) chosen in the Select can be posted to a server using a standard HTML form. When the `name` prop is set, the Select will render a hidden input with the selected value. {{"demo": "UnstyledSelectForm.js"}} Note how the second Select in the demo above renders a hidden input with the name provided as a prop. You can customize the value of this hidden input—see the [Object values](#object-values) section for details. ### TypeScript caveat Select's props are generic. Due to TypeScript limitations, this may cause unexpected behavior when wrapping the component in `forwardRef` (or other higher-order components). In such cases, the generic argument will be defaulted to `unknown` and type suggestions will be incomplete. To avoid this, you can manually cast the resulting component to the correct type: ```tsx const CustomSelect = React.forwardRef(function CustomSelect<TValue>( props: SelectProps<TValue>, ref: React.ForwardedRef<HTMLUListElement>, ) { // ...your code here... return <Select {...props} ref={ref} />; }) as <TValue>( props: SelectProps<TValue> & React.RefAttributes<HTMLUListElement>, ) => JSX.Element; ``` For the sake of brevity, the rest of the demos throughout this doc will not use `forwardRef`. ### 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": "UnstyledSelectMultiple.js", "defaultCodeOpen": false}} ### Controlled select Select can be used as an uncontrolled or controlled component. :::info - The value is **controlled** when its parent manages it by providing a `value` prop. - The value is **uncontrolled** when it is managed by the component's own internal state. This state can be initialized using the `defaultValue` prop. Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components). ::: {{"demo": "UnstyledSelectControlled.js", "defaultCodeOpen": false}} Use the `value` prop to set the value of the controlled Select. The uncontrolled component accepts the `defaultValue` that can be used to set the initial value. To deselect all values, pass `null` to the respective prop. :::warning This pattern is where Base UI's Select differs from the equivalent [Material UI component](/material-ui/react-select/). The Material UI Select takes an empty string to deselect all values. In Base UI, you must use `null` to achieve this. ::: ### Object values The Select component can be used with non-string values: {{"demo": "UnstyledSelectObjectValues.js", "defaultCodeOpen": false}} If you use a Select with object values in a form and post the form contents to a server, the selected value will be converted to JSON. You can change this behavior with the help of the `getSerializedValue` prop. {{"demo": "UnstyledSelectObjectValuesForm.js", "defaultCodeOpen": false}} ### Grouping options ```jsx import { OptionGroup } from '@mui/base/OptionGroup'; ``` Options can be grouped, similarly to how the native `<select>` element works. Unlike the native `<select>`, groups can be nested. The following demo shows how to group Options with the Option Group component: {{"demo": "UnstyledSelectGrouping.js", "defaultCodeOpen": false}} ### Anatomy The Select component is composed of a root `<button>` along with a `<div>` that houses a `<ul>` within a [Popper](/base-ui/react-popper/). Option renders as an `<li>`, and Option Group renders a `<ul>` with an `<li>` that represents its label. ```html <button class="MuiSelect-root" type="button">Open</button> <div class="MuiSelect-popper"> <ul class="MuiSelect-listbox"> <li class="MuiOption-root">Option one</li> <li class="MuiOption-root">Option two</li> </ul> </div> ``` ### Custom structure Use the `slots` prop to override the root or any other interior slot: ```jsx <Select slots={{ root: 'div', listbox: 'ol' }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for full details. ::: Use the `slotProps` prop to pass custom props to internal slots. The following code snippet applies a CSS class called `my-listbox` to the listbox slot: ```jsx <Select slotProps={{ listbox: { className: 'my-listbox' } }} /> ``` ### Portals By default, the Select's popup is rendered in a [Portal](https://mui.com/base-ui/react-portal/) and appended to the bottom of the DOM. To instead render the popup where the component is defined, override the `disablePortal` prop of the underlying Popper, as shown below: ```jsx <Select slotProps={{ popper: { disablePortal: true } }} /> ``` ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <Select<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <Select<'button'> slots={{ root: 'button' }} onClick={() => {}} /> ``` ## Hooks ```js import { useSelect } from '@mui/base/useSelect'; ``` The `useSelect` hook lets you apply the functionality of a Select to a fully custom component. It returns props to be placed on the custom component, along with fields representing the component's internal state. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [structure](#anatomy). ::: The following example shows a select built with a hook. Note how this component does not include any built-in classes. The resulting HTML is much smaller compared with its prebuilt component counterpart, because the class names are not applied. {{"demo": "UseSelect.js", "defaultCodeOpen": false}} ### Performance The `useOption` hook listens to changes in a context that is set up by the parent Select component. This context changes every time an item is highlighted. Usually, it shouldn't be a problem, however, when your select has hundreds of options, you may notice it's not very responsive, as every option is rerendered whenever highlight changes. To improve performance by preventing options from rendering unnecessarily, you can create a component that wraps the option. Inside this component, call `useOptionContextStabilizer` and create a ListContext with the value from the hook's result: ```tsx const StableOption = React.forwardRef(function StableOption<OptionValue>( props: OptionProps<OptionValue>, ref: React.ForwardedRef<Element>, ) { const { contextValue } = useOptionContextStabilizer(props.value); return ( <ListContext.Provider value={contextValue}> <Option {...props} ref={ref} /> </ListContext.Provider> ); }); ``` The `useOptionContextStabilizer` hook ensures that the context value changes only when the state of the option is updated. ## Customization :::info The following features can be used with both components and hooks. For the sake of simplicity, demos and code snippets primarily feature components. ::: ### Selected value appearance You can customize the appearance of the selected value display by providing a function to the `renderValue` prop. The element returned by this function will be rendered inside the Select's button. {{"demo": "UnstyledSelectCustomRenderValue.js"}} ### Option appearance Options don't have to be plain strings. You can include custom elements to be rendered inside the listbox. {{"demo": "UnstyledSelectRichOptions.js"}}
415
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/css/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select, selectClasses } from '@mui/base/Select'; import { Option, optionClasses } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectBasic() { return ( <React.Fragment> <Select className="CustomSelect" slots={{ root: Button, }} slotProps={{ listbox: { className: 'CustomSelect-listbox' }, popper: { className: 'CustomSelect-popper' }, }} defaultValue={10} > <Option className="CustomSelect-option" value={10}> Ten </Option> <Option className="CustomSelect-option" value={20}> Twenty </Option> <Option className="CustomSelect-option" value={30}> Thirty </Option> </Select> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSelect { position: relative; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } } .CustomSelect-listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomSelect-popper { z-index: 1; } .CustomSelect-option { list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.highlighted} { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } } `} </style> ); }
416
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/css/index.tsx
import * as React from 'react'; import { Select, selectClasses, SelectRootSlotProps } from '@mui/base/Select'; import { Option, optionClasses } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectBasic() { return ( <React.Fragment> <Select className="CustomSelect" slots={{ root: Button, }} slotProps={{ listbox: { className: 'CustomSelect-listbox' }, popper: { className: 'CustomSelect-popper' }, }} defaultValue={10} > <Option className="CustomSelect-option" value={10}> Ten </Option> <Option className="CustomSelect-option" value={20}> Twenty </Option> <Option className="CustomSelect-option" value={30}> Thirty </Option> </Select> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSelect { position: relative; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } } .CustomSelect-listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomSelect-popper { z-index: 1; } .CustomSelect-option { list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.highlighted} { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } } `} </style> ); }
417
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/system/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; const Select = React.forwardRef(function Select(props, ref) { const slots = { root: CustomButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }); export default function UnstyledSelectBasic() { return ( <Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const CustomButton = React.forwardRef(function CustomButton(props, ref) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); CustomButton.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` position: relative; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
418
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/system/index.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, selectClasses, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; const Select = React.forwardRef(function Select< TValue extends {}, Multiple extends boolean, >(props: SelectProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>) { const slots: SelectProps<TValue, Multiple>['slots'] = { root: CustomButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }) as <TValue extends {}, Multiple extends boolean>( props: SelectProps<TValue, Multiple> & React.RefAttributes<HTMLButtonElement>, ) => JSX.Element; export default function UnstyledSelectBasic() { return ( <Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const CustomButton = React.forwardRef(function CustomButton< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <StyledButton type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </StyledButton> ); }); const StyledButton = styled('button', { shouldForwardProp: () => true })( ({ theme }) => ` position: relative; font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
419
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/system/index.tsx.preview
<Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select>
420
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect } from '@mui/base/Select'; import { Option as BaseOption } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; const getOptionColorClasses = ({ selected, highlighted, disabled }) => { let classes = ''; if (disabled) { classes += ' text-slate-400 dark:text-slate-700'; } else { if (selected) { classes += ' bg-purple-100 dark:bg-purple-950 text-purple-950 dark:text-purple-50'; } else if (highlighted) { classes += ' bg-slate-100 dark:bg-neutral-800 text-slate-900 dark:text-slate-300'; } classes += ' hover:dark:bg-neutral-800 hover:bg-slate-100 hover:dark:text-slate-300 hover:text-slate-900'; } return classes; }; const Option = React.forwardRef((props, ref) => { return ( <BaseOption ref={ref} {...props} slotProps={{ root: ({ selected, highlighted, disabled }) => ({ className: `list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 ${getOptionColorClasses( { selected, highlighted, disabled }, )}`, }), }} /> ); }); const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSelectBasic() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''}> <Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> </div> ); } const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Select = React.forwardRef(function CustomSelect(props, ref) { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseSelect ref={ref} {...props} className={clsx('CustomSelect', props.className)} slots={{ root: Button, }} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `relative text-sm font-sans box-border w-80 px-3 py-2 rounded-lg text-left bg-white dark:bg-neutral-900 border border-solid border-slate-200 dark:border-neutral-700 text-slate-900 dark:text-neutral-300 transition-all hover:bg-slate-50 dark:hover:bg-neutral-800 outline-0 shadow-md shadow-slate-100 dark:shadow-slate-900 ${ ownerState.focusVisible ? 'focus-visible:ring-4 ring-purple-500/30 focus-visible:border-purple-500 focus-visible:dark:border-purple-500' : '' } [&>svg]:text-base [&>svg]:absolute [&>svg]:h-full [&>svg]:top-0 [&>svg]:right-2.5`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( `text-sm font-sans p-1.5 my-3 w-80 rounded-xl overflow-auto outline-0 bg-white dark:bg-neutral-900 border border-solid border-slate-200 dark:border-neutral-700 text-slate-900 dark:text-neutral-300 shadow shadow-slate-200 dark:shadow-neutral-900`, resolvedSlotProps?.className, ), }; }, popper: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.popper, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, }} /> ); }); Select.propTypes = { className: PropTypes.string, /** * The props used for each slot inside the Input. * @default {} */ slotProps: PropTypes.shape({ listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), popper: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }), };
421
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/tailwind/index.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectProps, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, OptionProps, OptionOwnerState, } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import clsx from 'clsx'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; const getOptionColorClasses = ({ selected, highlighted, disabled, }: Partial<OptionOwnerState<number>>) => { let classes = ''; if (disabled) { classes += ' text-slate-400 dark:text-slate-700'; } else { if (selected) { classes += ' bg-purple-100 dark:bg-purple-950 text-purple-950 dark:text-purple-50'; } else if (highlighted) { classes += ' bg-slate-100 dark:bg-neutral-800 text-slate-900 dark:text-slate-300'; } classes += ' hover:dark:bg-neutral-800 hover:bg-slate-100 hover:dark:text-slate-300 hover:text-slate-900'; } return classes; }; const Option = React.forwardRef<HTMLLIElement, OptionProps<number>>((props, ref) => { return ( <BaseOption ref={ref} {...props} slotProps={{ root: ({ selected, highlighted, disabled }) => ({ className: `list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 ${getOptionColorClasses( { selected, highlighted, disabled }, )}`, }), }} /> ); }); const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSelectBasic() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''}> <Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select> </div> ); } const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Select = React.forwardRef(function CustomSelect< TValue extends {}, Multiple extends boolean, >(props: SelectProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>) { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseSelect ref={ref} {...props} className={clsx('CustomSelect', props.className)} slots={{ root: Button, }} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `relative text-sm font-sans box-border w-80 px-3 py-2 rounded-lg text-left bg-white dark:bg-neutral-900 border border-solid border-slate-200 dark:border-neutral-700 text-slate-900 dark:text-neutral-300 transition-all hover:bg-slate-50 dark:hover:bg-neutral-800 outline-0 shadow-md shadow-slate-100 dark:shadow-slate-900 ${ ownerState.focusVisible ? 'focus-visible:ring-4 ring-purple-500/30 focus-visible:border-purple-500 focus-visible:dark:border-purple-500' : '' } [&>svg]:text-base [&>svg]:absolute [&>svg]:h-full [&>svg]:top-0 [&>svg]:right-2.5`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( `text-sm font-sans p-1.5 my-3 w-80 rounded-xl overflow-auto outline-0 bg-white dark:bg-neutral-900 border border-solid border-slate-200 dark:border-neutral-700 text-slate-900 dark:text-neutral-300 shadow shadow-slate-200 dark:shadow-neutral-900`, resolvedSlotProps?.className, ), }; }, popper: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.popper, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, }} /> ); });
422
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectBasic/tailwind/index.tsx.preview
<Select defaultValue={10}> <Option value={10}>Ten</Option> <Option value={20}>Twenty</Option> <Option value={30}>Thirty</Option> </Select>
423
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/css/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select, selectClasses } from '@mui/base/Select'; import { Option, optionClasses } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectIntroduction() { return ( <React.Fragment> <Select className="CustomSelectIntroduction" slots={{ root: Button, }} slotProps={{ listbox: { className: 'CustomSelectIntroduction-listbox' }, popper: { className: 'CustomSelectIntroduction-popper' }, }} defaultValue={10} > <Option className="CustomSelectIntroduction-option" value={10}> Documentation </Option> <Option className="CustomSelectIntroduction-option" value={20}> Components </Option> <Option className="CustomSelectIntroduction-option" value={30}> Features </Option> </Select> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSelectIntroduction { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } } .CustomSelectIntroduction-listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomSelectIntroduction-popper { z-index: 1; } .CustomSelectIntroduction-option { list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.highlighted} { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } } `} </style> ); }
424
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/css/index.tsx
import * as React from 'react'; import { Select, selectClasses, SelectRootSlotProps } from '@mui/base/Select'; import { Option, optionClasses } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectIntroduction() { return ( <React.Fragment> <Select className="CustomSelectIntroduction" slots={{ root: Button, }} slotProps={{ listbox: { className: 'CustomSelectIntroduction-listbox' }, popper: { className: 'CustomSelectIntroduction-popper' }, }} defaultValue={10} > <Option className="CustomSelectIntroduction-option" value={10}> Documentation </Option> <Option className="CustomSelectIntroduction-option" value={20}> Components </Option> <Option className="CustomSelectIntroduction-option" value={30}> Features </Option> </Select> <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSelectIntroduction { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ isDarkMode ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${cyan[400]}; box-shadow: 0 0 0 3px ${isDarkMode ? cyan[600] : cyan[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } } .CustomSelectIntroduction-listbox { font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[300] : grey[900]}; box-shadow: 0px 4px 6px ${ isDarkMode ? 'rgba(0,0,0, 0.50)' : 'rgba(0,0,0, 0.05)' }; } .CustomSelectIntroduction-popper { z-index: 1; } .CustomSelectIntroduction-option { list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.highlighted} { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${isDarkMode ? cyan[700] : cyan[100]}; color: ${isDarkMode ? cyan[50] : cyan[900]}; } &.${optionClasses.disabled} { color: ${isDarkMode ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${isDarkMode ? grey[800] : grey[100]}; color: ${isDarkMode ? grey[300] : grey[900]}; } } `} </style> ); }
425
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/system/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect, selectClasses } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectIntroduction() { return ( <Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select> ); } const Select = React.forwardRef(function CustomSelect(props, ref) { const slots = { root: StyledButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }); Select.propTypes = { /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), }; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const StyledButton = styled(Button, { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
426
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/system/index.tsx
import * as React from 'react'; import { Select as BaseSelect, selectClasses, SelectProps, SelectRootSlotProps, } from '@mui/base/Select'; import { Option as BaseOption, optionClasses } from '@mui/base/Option'; import { Popper as BasePopper } from '@mui/base/Popper'; import { styled } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; export default function UnstyledSelectIntroduction() { return ( <Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select> ); } const Select = React.forwardRef(function CustomSelect< TValue extends {}, Multiple extends boolean, >(props: SelectProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>) { const slots = { root: StyledButton, listbox: Listbox, popper: Popper, ...props.slots, }; return <BaseSelect {...props} ref={ref} slots={slots} />; }); const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); const StyledButton = styled(Button, { shouldForwardProp: () => true })( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; min-width: 320px; padding: 8px 12px; border-radius: 8px; text-align: left; line-height: 1.5; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; position: relative; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &.${selectClasses.focusVisible} { outline: 0; border-color: ${blue[400]}; box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } & > svg { font-size: 1rem; position: absolute; height: 100%; top: 0; right: 10px; } `, ); const Listbox = styled('ul')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-size: 0.875rem; box-sizing: border-box; padding: 6px; margin: 12px 0; min-width: 320px; border-radius: 12px; overflow: auto; outline: 0px; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; box-shadow: 0px 2px 4px ${ theme.palette.mode === 'dark' ? 'rgba(0,0,0, 0.5)' : 'rgba(0,0,0, 0.05)' }; `, ); const Option = styled(BaseOption)( ({ theme }) => ` list-style: none; padding: 8px; border-radius: 8px; cursor: default; &:last-of-type { border-bottom: none; } &.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.highlighted} { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } &.${optionClasses.highlighted}.${optionClasses.selected} { background-color: ${theme.palette.mode === 'dark' ? blue[900] : blue[100]}; color: ${theme.palette.mode === 'dark' ? blue[100] : blue[900]}; } &.${optionClasses.disabled} { color: ${theme.palette.mode === 'dark' ? grey[700] : grey[400]}; } &:hover:not(.${optionClasses.disabled}) { background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; color: ${theme.palette.mode === 'dark' ? grey[300] : grey[900]}; } `, ); const Popper = styled(BasePopper)` z-index: 1; `;
427
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/system/index.tsx.preview
<Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select>
428
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { Select as BaseSelect } from '@mui/base/Select'; import { Option as BaseOption } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSelectIntroduction() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''}> <Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select> </div> ); } const getOptionColorClasses = ({ selected, highlighted, disabled }) => { let classes = ''; if (disabled) { classes += 'text-slate-400 dark:text-slate-700'; } else { if (selected) { classes += ' bg-purple-100 dark:bg-purple-950 text-purple-950 dark:text-purple-50'; } else if (highlighted) { classes += ' bg-slate-100 dark:bg-slate-800 text-slate-900 dark:text-slate-300'; } classes += ' hover:dark:bg-slate-800 hover:bg-slate-100 hover:dark:text-slate-300 hover:text-slate-900'; } return classes; }; const Option = React.forwardRef((props, ref) => { return ( <BaseOption ref={ref} {...props} slotProps={{ root: ({ selected, highlighted, disabled }) => ({ className: `list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 ${getOptionColorClasses( { selected, highlighted, disabled }, )}`, }), }} /> ); }); const Button = React.forwardRef(function Button(props, ref) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); Button.propTypes = { children: PropTypes.node, ownerState: PropTypes.object.isRequired, }; const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Select = React.forwardRef(function CustomSelect(props, ref) { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseSelect ref={ref} {...props} slots={{ root: Button, ...props.slots, }} className={clsx('CustomSelect', props.className)} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `relative text-sm font-sans box-border w-80 px-3 py-2 rounded-lg text-left bg-white dark:bg-slate-800 border border-solid border-slate-300 dark:border-slate-700 text-slate-900 dark:text-slate-300 transition-all hover:bg-slate-50 dark:hover:bg-slate-700 outline-0 shadow-[0_2px_4px_rgb(0_0_0/_0.05)] dark:shadow-[0_2px_4px_rgb(0_0_0/_0.5)] ${ ownerState.focusVisible ? 'border-purple-400 shadow-outline-purple' : '' } [&>svg]:text-base [&>svg]:absolute [&>svg]:h-full [&>svg]:top-0 [&>svg]:right-2.5`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( `text-sm font-sans p-1.5 my-3 w-80 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 shadow shadow-slate-200 dark:shadow-slate-900`, resolvedSlotProps?.className, ), }; }, popper: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.popper, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, }} /> ); }); Select.propTypes = { className: PropTypes.string, /** * The props used for each slot inside the Input. * @default {} */ slotProps: PropTypes.shape({ listbox: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), popper: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), }), /** * The components used for each slot inside the Select. * Either a string to use a HTML element or a component. * @default {} */ slots: PropTypes.shape({ listbox: PropTypes.elementType, popper: PropTypes.func, root: PropTypes.elementType, }), };
429
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/tailwind/index.tsx
import * as React from 'react'; import { Select as BaseSelect, SelectRootSlotProps, SelectProps, } from '@mui/base/Select'; import { Option as BaseOption, OptionProps, OptionOwnerState, } from '@mui/base/Option'; import { useTheme } from '@mui/system'; import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSelectIntroduction() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''}> <Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select> </div> ); } const getOptionColorClasses = ({ selected, highlighted, disabled, }: Partial<OptionOwnerState<number>>) => { let classes = ''; if (disabled) { classes += 'text-slate-400 dark:text-slate-700'; } else { if (selected) { classes += ' bg-purple-100 dark:bg-purple-950 text-purple-950 dark:text-purple-50'; } else if (highlighted) { classes += ' bg-slate-100 dark:bg-slate-800 text-slate-900 dark:text-slate-300'; } classes += ' hover:dark:bg-slate-800 hover:bg-slate-100 hover:dark:text-slate-300 hover:text-slate-900'; } return classes; }; const Option = React.forwardRef<HTMLLIElement, OptionProps<number>>((props, ref) => { return ( <BaseOption ref={ref} {...props} slotProps={{ root: ({ selected, highlighted, disabled }) => ({ className: `list-none p-2 rounded-lg cursor-default last-of-type:border-b-0 ${getOptionColorClasses( { selected, highlighted, disabled }, )}`, }), }} /> ); }); const Button = React.forwardRef(function Button< TValue extends {}, Multiple extends boolean, >( props: SelectRootSlotProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>, ) { const { ownerState, ...other } = props; return ( <button type="button" {...other} ref={ref}> {other.children} <UnfoldMoreRoundedIcon /> </button> ); }); const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Select = React.forwardRef(function CustomSelect< TValue extends {}, Multiple extends boolean, >(props: SelectProps<TValue, Multiple>, ref: React.ForwardedRef<HTMLButtonElement>) { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <BaseSelect ref={ref} {...props} slots={{ root: Button, ...props.slots, }} className={clsx('CustomSelect', props.className)} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `relative text-sm font-sans box-border w-80 px-3 py-2 rounded-lg text-left bg-white dark:bg-slate-800 border border-solid border-slate-300 dark:border-slate-700 text-slate-900 dark:text-slate-300 transition-all hover:bg-slate-50 dark:hover:bg-slate-700 outline-0 shadow-[0_2px_4px_rgb(0_0_0/_0.05)] dark:shadow-[0_2px_4px_rgb(0_0_0/_0.5)] ${ ownerState.focusVisible ? 'border-purple-400 shadow-outline-purple' : '' } [&>svg]:text-base [&>svg]:absolute [&>svg]:h-full [&>svg]:top-0 [&>svg]:right-2.5`, resolvedSlotProps?.className, ), }; }, listbox: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.listbox, ownerState, ); return { ...resolvedSlotProps, className: clsx( `text-sm font-sans p-1.5 my-3 w-80 rounded-xl overflow-auto outline-0 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-300 shadow shadow-slate-200 dark:shadow-slate-900`, resolvedSlotProps?.className, ), }; }, popper: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.popper, ownerState, ); return { ...resolvedSlotProps, className: clsx( `${isDarkMode ? 'dark' : ''} z-10`, resolvedSlotProps?.className, ), }; }, }} /> ); });
430
0
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/select/UnstyledSelectIntroduction/tailwind/index.tsx.preview
<Select defaultValue={10}> <Option value={10}>Documentation</Option> <Option value={20}>Components</Option> <Option value={30}>Features</Option> </Select>
431
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSlider.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={30} getAriaValueText={valuetext} step={10} marks min={10} max={110} slots={{ valueLabel: SliderValueLabel }} /> </Box> ); } function SliderValueLabel({ children }) { return <span className="valueLabel">{children}</span>; } SliderValueLabel.propTypes = { children: PropTypes.element.isRequired, }; function valuetext(value) { return `${value}°C`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; display: flex; flex-direction: column-reverse; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .valueLabel { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: relative; top: -1.5em; text-align: center; align-self: center; } `, );
432
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSlider.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSlider() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={30} getAriaValueText={valuetext} step={10} marks min={10} max={110} slots={{ valueLabel: SliderValueLabel }} /> </Box> ); } interface SliderValueLabelProps { children: React.ReactElement; } function SliderValueLabel({ children }: SliderValueLabelProps) { return <span className="valueLabel">{children}</span>; } function valuetext(value: number) { return `${value}°C`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; display: flex; flex-direction: column-reverse; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .valueLabel { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: relative; top: -1.5em; text-align: center; align-self: center; } `, );
433
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSlider.tsx.preview
<Slider aria-label="Temperature" defaultValue={30} getAriaValueText={valuetext} step={10} marks min={10} max={110} slots={{ valueLabel: SliderValueLabel }} />
434
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderMarks.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSliderMarks() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} marks={marks} /> </Box> ); } 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`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .${sliderClasses.markLabel} { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: absolute; top: 20px; transform: translateX(-50%); margin-top: 8px; } `, );
435
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderMarks.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSliderMarks() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} marks={marks} /> </Box> ); } 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`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .${sliderClasses.markLabel} { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: absolute; top: 20px; transform: translateX(-50%); margin-top: 8px; } `, );
436
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderMarks.tsx.preview
<Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} marks={marks} />
437
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderValues.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSliderValues() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} step={null} marks={marks} /> </Box> ); } 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`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .${sliderClasses.markLabel} { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: absolute; top: 20px; transform: translateX(-50%); margin-top: 8px; } `, );
438
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderValues.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function DiscreteSliderValues() { return ( <Box sx={{ width: 300 }}> <Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} step={null} marks={marks} /> </Box> ); } 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`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 8px; height: 8px; border-radius: 99%; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; top: 43%; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; } & .${sliderClasses.markLabel} { font-family: IBM Plex Sans; font-weight: 600; font-size: 12px; position: absolute; top: 20px; transform: translateX(-50%); margin-top: 8px; } `, );
439
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/DiscreteSliderValues.tsx.preview
<Slider aria-label="Temperature" defaultValue={37} getAriaValueText={valuetext} step={null} marks={marks} />
440
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/LabeledValuesSlider.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function LabeledValuesSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} slots={{ valueLabel: SliderValueLabel }} /> </Box> ); } function SliderValueLabel({ children }) { return ( <span className="label"> <div className="value">{children}</div> </span> ); } SliderValueLabel.propTypes = { children: PropTypes.element.isRequired, }; const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } & .label { font-family: IBM Plex Sans; font-weight: 600; font-size: 14px; background: unset; background-color: ${theme.palette.mode === 'light' ? blue[600] : blue[900]}; width: 32px; height: 32px; padding: 0px; visibility: hidden; color: #fff; border-radius: 50% 50% 50% 0; position: absolute; transform: translate(-35%, -140%) rotate(-45deg) scale(0); transition: transform 0.3s ease; display: flex; align-items: center; justify-content: center; } :hover .label { visibility: visible; transform: translate(-35%, -140%) rotate(-45deg) scale(1); } :hover .value { transform: rotate(45deg); text-align: center; } &.${sliderClasses.active} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[600] : blue[300]}; outline: none; } } `, );
441
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/LabeledValuesSlider.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function LabeledValuesSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} slots={{ valueLabel: SliderValueLabel }} /> </Box> ); } interface SliderValueLabelProps { children: React.ReactElement; } function SliderValueLabel({ children }: SliderValueLabelProps) { return ( <span className="label"> <div className="value">{children}</div> </span> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } & .label { font-family: IBM Plex Sans; font-weight: 600; font-size: 14px; background: unset; background-color: ${theme.palette.mode === 'light' ? blue[600] : blue[900]}; width: 32px; height: 32px; padding: 0px; visibility: hidden; color: #fff; border-radius: 50% 50% 50% 0; position: absolute; transform: translate(-35%, -140%) rotate(-45deg) scale(0); transition: transform 0.3s ease; display: flex; align-items: center; justify-content: center; } :hover .label { visibility: visible; transform: translate(-35%, -140%) rotate(-45deg) scale(1); } :hover .value { transform: rotate(45deg); text-align: center; } &.${sliderClasses.active} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[600] : blue[300]}; outline: none; } } `, );
442
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/LabeledValuesSlider.tsx.preview
<Slider defaultValue={10} slots={{ valueLabel: SliderValueLabel }} />
443
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/RangeSlider.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function RangeSlider() { const [value, setValue] = React.useState([20, 37]); const handleChange = (event, newValue) => { setValue(newValue); }; return ( <Box sx={{ width: 300 }}> {/* controlled: */} <Slider value={value} onChange={handleChange} getAriaLabel={() => 'Temperature range'} getAriaValueText={valuetext} min={0} max={100} /> {/* uncontrolled: */} <Slider defaultValue={[20, 37]} getAriaLabel={() => 'Temperature range'} getAriaValueText={valuetext} min={0} max={100} /> </Box> ); } function valuetext(value) { return `${value}°C`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 4px; height: 4px; border-radius: 2px; background-color: currentColor; top: 50%; opacity: 0.7; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: #fff; } `, );
444
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/RangeSlider.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; 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 }}> {/* controlled: */} <Slider value={value} onChange={handleChange} getAriaLabel={() => 'Temperature range'} getAriaValueText={valuetext} min={0} max={100} /> {/* uncontrolled: */} <Slider defaultValue={[20, 37]} getAriaLabel={() => 'Temperature range'} getAriaValueText={valuetext} min={0} max={100} /> </Box> ); } function valuetext(value: number) { return `${value}°C`; } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: ${theme.palette.mode === 'light' ? blue[200] : blue[900]}; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } & .${sliderClasses.mark} { position: absolute; width: 4px; height: 4px; border-radius: 2px; background-color: currentColor; top: 50%; opacity: 0.7; transform: translateX(-50%); } & .${sliderClasses.markActive} { background-color: #fff; } `, );
445
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSlider.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &:hover { opacity: 1; } &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
446
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSlider.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &:hover { opacity: 1; } &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
447
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSlider.tsx.preview
<Slider defaultValue={10} /> <Slider defaultValue={10} disabled />
448
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderValueLabel.tsx.preview
<StyledSlider defaultValue={10} slots={{ valueLabel: SliderValueLabel }} />
449
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/VerticalSlider.js
import * as React from 'react'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; import { styled, alpha, Box } from '@mui/system'; export default function VerticalSlider() { return ( <Box sx={{ height: 300 }}> <Slider orientation="vertical" defaultValue={30} /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 95%; width: 4px; display: inline-block; position: relative; margin-top: 0.75rem; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; & .${sliderClasses.rail} { display: block; position: absolute; height: 100%; width: inherit; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; width: inherit; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; left: 50%; -webkit-transform: translate(-50%, 50%); -moz-transform: translate(-50%, 50%); -ms-transform: translate(-50%, 50%); transform: translate(-50%, 50%); &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
450
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/VerticalSlider.tsx
import * as React from 'react'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; import { styled, alpha, Box } from '@mui/system'; export default function VerticalSlider() { return ( <Box sx={{ height: 300 }}> <Slider orientation="vertical" defaultValue={30} /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 95%; width: 4px; display: inline-block; position: relative; margin-top: 0.75rem; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; & .${sliderClasses.rail} { display: block; position: absolute; height: 100%; width: inherit; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; width: inherit; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; left: 50%; -webkit-transform: translate(-50%, 50%); -moz-transform: translate(-50%, 50%); -ms-transform: translate(-50%, 50%); transform: translate(-50%, 50%); &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
451
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/VerticalSlider.tsx.preview
<Slider orientation="vertical" defaultValue={30} />
452
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/slider/slider.md
--- productId: base-ui title: React Slider component and hook components: Slider hooks: useSlider githubLabel: 'component: slider' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/ --- # Slider <p class="description">A slider is a UI element that lets users select a single value or a range of values along a bar. </p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction The Slider component lets users make selections from a range of values along a horizontal or vertical bar. Sliders are ideal for interface controls that benefit from a visual representation of adjustable content, such as volume or brightness settings, or for applying image filters such as gradients or saturation. {{"demo": "UnstyledSliderIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Component ```jsx import { Slider } from '@mui/base/Slider'; ``` ### Anatomy The Slider component is composed of a root `<span>` that houses several interior `<span>` elements: - rail: the full length of the slider - track: the section of the slider that's active - thumb: the button that the user moves across the slider - mark: optional pre-defined stops along the track - markLabel: optional label to display the mark's value - valueLabel: optional label to display the values on a range slider ```html <span class="MuiSlider-root"> <span class="MuiSlider-rail"></span> <span class="MuiSlider-track"></span> <span data-index="0" class="MuiSlider-mark MuiSlider-markActive" style="left: 0%;" ></span> <span aria-hidden="true" data-index="0" class="MuiSlider-markLabel MuiSlider-markLabelActive" style="left: 0%;" >0</span > <span data-index="1" class="MuiSlider-mark" style="left: 50%;"></span> <span aria-hidden="true" data-index="1" class="MuiSlider-markLabel" style="left: 50%;" >50</span > <span data-index="2" class="MuiSlider-mark" style="left: 100%;"></span> <span aria-hidden="true" data-index="2" class="MuiSlider-markLabel" style="left: 100%;" >100</span > <span class="MuiSlider-thumb"> <input /> </span> </span> ``` :::info Both the `mark` and `markLabel` slots have corresponding `*Active` classes that are applied conditionally. ::: ### Custom structure Use the `slots` prop to override the root or any other interior slot: ```jsx <Slider slots={{ root: 'div', thumb: 'div' }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for full details. ::: Use the `slotProps` prop to pass custom props to internal slots. The following code snippet applies a CSS class called `my-rail` to the rail slot: ```jsx <Slider slotProps={{ rail: { className: 'my-rail' } }} /> ``` ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <Slider<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <Slider<'input'> slots={{ root: 'input' }} autoFocus={true} /> ``` ## Hook ```js import { useSlider } from '@mui/base/useSlider'; ``` The `useSlider` hook lets you apply the functionality of a Slider to a fully custom component. It returns props to be placed on the custom component, along with fields representing the component's internal state. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [structure](#anatomy). ::: ## Customization ### Vertical Slider components can be arranged vertically as well as horizontally. When vertical, you must set `orientation="vertical"` on the Slider so the user can navigate with the up and down arrow keys (rather than the default left-to-right behavior for horizontal sliders). {{"demo": "VerticalSlider.js"}} ### Discrete sliders The most basic Slider is _continuous_, which means it does not have pre-defined (_discrete_) values for the user to select from. This is suitable for situations in which an approximate value is good enough for the user, such as brightness or volume. But if your users need more precise options, you can create a discrete Slider that snaps the thumb to pre-defined stops along the bar. To generate a mark for each stop, use `marks={true}`: {{"demo": "DiscreteSlider.js"}} #### Custom marks You can create custom marks by providing a rich array to the `marks` prop: {{"demo": "DiscreteSliderMarks.js"}} #### Restricted values If the user should only be able to select from the values provided with the `marks` prop, add `step={null}` to disable all other options: {{"demo": "DiscreteSliderValues.js"}} ### Range slider To let users set the start and end of a range on a Slider, provide an array of values to the `value` or `defaultValue` prop: {{"demo": "RangeSlider.js"}} ### Value label A label for the value can be rendered around the thumb by using the optional `slots` prop with the `valueLabel` slot. These are typical use cases for showing the value label: - always - only when hovering over the thumb (using CSS) - while interacting with the thumb (hovering or dragging) The following demo shows how to render the value label when the mouse is hovering over the thumb: {{"demo": "LabeledValuesSlider.js"}} ## Accessibility See the [WAI-ARIA guide on the Slider (Multi-Thumb) pattern](https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/) for complete details on accessibility best practices. The component handles most of the work necessary to make it accessible. However, you need to make sure that: - Each thumb has a user-friendly label (`aria-label`, `aria-labelledby` or `getAriaLabel` prop). - Each thumb has a user-friendly text for its current value. This is not required if the value matches the semantics of the label. You can change the name with the `getAriaValueText` or `aria-valuetext` prop.
453
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/css/index.js
import * as React from 'react'; import { useTheme, alpha } from '@mui/system'; import { Slider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <div style={{ width: 300 }}> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} /> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomSlider { color: ${isDarkMode ? cyan[400] : cyan[500]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; } .CustomSlider:hover { opacity: 1; } .CustomSlider.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${isDarkMode ? grey[600] : grey[300]}; opacity: 0.5; } .CustomSlider-rail { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } .CustomSlider-track { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } .CustomSlider-thumb { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; } .CustomSlider-thumb:hover,&.${sliderClasses.focusVisible} { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[400], 0.15)}; } .CustomSlider-thumb.${sliderClasses.active} { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.3)}; } `}</style> ); }
454
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/css/index.tsx
import * as React from 'react'; import { useTheme, alpha } from '@mui/system'; import { Slider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <div style={{ width: 300 }}> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} /> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomSlider { color: ${isDarkMode ? cyan[400] : cyan[500]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; } .CustomSlider:hover { opacity: 1; } .CustomSlider.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${isDarkMode ? grey[600] : grey[300]}; opacity: 0.5; } .CustomSlider-rail { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } .CustomSlider-track { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } .CustomSlider-thumb { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; } .CustomSlider-thumb:hover,&.${sliderClasses.focusVisible} { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[400], 0.15)}; } .CustomSlider-thumb.${sliderClasses.active} { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.3)}; } `}</style> ); }
455
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/system/index.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 0.25rem ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[600] : blue[300]}; outline: none; } } `, );
456
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/system/index.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSlider() { return ( <Box sx={{ width: 300 }}> <Slider defaultValue={10} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 0.25rem ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[600] : blue[300]}; outline: none; } } `, );
457
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/system/index.tsx.preview
<Slider defaultValue={10} /> <Slider defaultValue={10} disabled />
458
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/tailwind/index.js
import * as React from 'react'; import { useTheme } from '@mui/system'; import { Slider } from '@mui/base/Slider'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSliderBasic() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''} style={{ width: 300 }}> <Slider slotProps={{ root: ({ disabled }) => ({ className: `h-1.5 w-full py-4 inline-block relative touch-none ${ disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, }), rail: { className: 'block absolute w-full h-1 rounded-sm bg-current opacity-40', }, track: { className: 'block absolute h-1 rounded-sm bg-current' }, thumb: (_, { active, focused }) => ({ className: `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-3 border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-outline-purple' : '' }`, }), }} defaultValue={10} /> <Slider slotProps={{ root: ({ disabled }) => ({ className: `h-1.5 w-full py-4 inline-block relative touch-none ${ disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, }), rail: { className: 'block absolute w-full h-1 rounded-sm bg-current opacity-40', }, track: { className: 'block absolute h-1 rounded-sm bg-current' }, thumb: (_, { active, focused }) => ({ className: `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-3 border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-outline-purple' : '' }`, }), }} defaultValue={10} disabled /> </div> ); }
459
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderBasic/tailwind/index.tsx
import * as React from 'react'; import { useTheme } from '@mui/system'; import { Slider } from '@mui/base/Slider'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSliderBasic() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''} style={{ width: 300 }}> <Slider slotProps={{ root: ({ disabled }) => ({ className: `h-1.5 w-full py-4 inline-block relative touch-none ${ disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, }), rail: { className: 'block absolute w-full h-1 rounded-sm bg-current opacity-40', }, track: { className: 'block absolute h-1 rounded-sm bg-current' }, thumb: (_, { active, focused }) => ({ className: `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-3 border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-outline-purple' : '' }`, }), }} defaultValue={10} /> <Slider slotProps={{ root: ({ disabled }) => ({ className: `h-1.5 w-full py-4 inline-block relative touch-none ${ disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, }), rail: { className: 'block absolute w-full h-1 rounded-sm bg-current opacity-40', }, track: { className: 'block absolute h-1 rounded-sm bg-current' }, thumb: (_, { active, focused }) => ({ className: `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-3 border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-outline-purple' : '' }`, }), }} defaultValue={10} disabled /> </div> ); }
460
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/css/index.js
import * as React from 'react'; import { useTheme, alpha } from '@mui/system'; import { Slider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSliderIntroduction() { return ( <div style={{ width: 320 }}> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb', tabIndex: 0 }, }} defaultValue={50} /> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomSlider { color: ${isDarkMode ? cyan[300] : cyan[500]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; } .CustomSlider:hover { opacity: 1; } .CustomSlider.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${isDarkMode ? grey[600] : grey[300]}; opacity: 0.5; outline: none; } .CustomSlider-rail { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } .CustomSlider-track { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } .CustomSlider-thumb { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; } .CustomSlider-thumb:hover { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.5)}; } .CustomSlider-thumb:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[700] : cyan[200]}; } .CustomSlider-thumb.${sliderClasses.active} { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[600] : cyan[300]}; } `}</style> ); }
461
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/css/index.tsx
import * as React from 'react'; import { useTheme, alpha } from '@mui/system'; import { Slider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSliderIntroduction() { return ( <div style={{ width: 320 }}> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb', tabIndex: 0 }, }} defaultValue={50} /> <Slider slotProps={{ root: { className: 'CustomSlider' }, rail: { className: 'CustomSlider-rail' }, track: { className: 'CustomSlider-track' }, thumb: { className: 'CustomSlider-thumb' }, }} defaultValue={10} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` .CustomSlider { color: ${isDarkMode ? cyan[300] : cyan[500]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; } .CustomSlider:hover { opacity: 1; } .CustomSlider.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${isDarkMode ? grey[600] : grey[300]}; opacity: 0.5; outline: none; } .CustomSlider-rail { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } .CustomSlider-track { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } .CustomSlider-thumb { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; } .CustomSlider-thumb:hover { box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.5)}; } .CustomSlider-thumb:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[700] : cyan[200]}; } .CustomSlider-thumb.${sliderClasses.active} { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[600] : cyan[300]}; } `}</style> ); }
462
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/system/index.js
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSliderIntroduction() { return ( <Box sx={{ width: 320 }}> <Slider defaultValue={50} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[300]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
463
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/system/index.tsx
import * as React from 'react'; import { styled, alpha, Box } from '@mui/system'; import { Slider as BaseSlider, sliderClasses } from '@mui/base/Slider'; export default function UnstyledSliderIntroduction() { return ( <Box sx={{ width: 320 }}> <Slider defaultValue={50} /> <Slider defaultValue={10} disabled /> </Box> ); } const blue = { 100: '#DAECFF', 200: '#99CCF3', 400: '#3399FF', 300: '#66B2FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B3', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Slider = styled(BaseSlider)( ({ theme }) => ` color: ${theme.palette.mode === 'light' ? blue[500] : blue[300]}; height: 6px; width: 100%; padding: 16px 0; display: inline-block; position: relative; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; &.${sliderClasses.disabled} { pointer-events: none; cursor: default; color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; opacity: 0.5; } & .${sliderClasses.rail} { display: block; position: absolute; width: 100%; height: 4px; border-radius: 2px; background-color: currentColor; opacity: 0.4; } & .${sliderClasses.track} { display: block; position: absolute; height: 4px; border-radius: 2px; background-color: currentColor; } & .${sliderClasses.thumb} { position: absolute; width: 16px; height: 16px; margin-left: -6px; margin-top: -6px; box-sizing: border-box; border-radius: 50%; outline: 0; border: 3px solid currentColor; background-color: #fff; &:hover{ box-shadow: 0 0 0 4px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.3, )}; } &.${sliderClasses.focusVisible} { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; outline: none; } &.${sliderClasses.active} { box-shadow: 0 0 0 5px ${alpha( theme.palette.mode === 'light' ? blue[200] : blue[300], 0.5, )}; outline: none; } } `, );
464
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/system/index.tsx.preview
<Slider defaultValue={50} /> <Slider defaultValue={10} disabled />
465
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/tailwind/index.js
import * as React from 'react'; import PropTypes from 'prop-types'; import { useTheme } from '@mui/system'; import { Slider as BaseSlider } from '@mui/base/Slider'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSliderIntroduction() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''} style={{ width: 320 }}> <Slider defaultValue={50} /> <Slider defaultValue={10} disabled /> </div> ); } const resolveSlotProps = (fn, args) => (typeof fn === 'function' ? fn(args) : fn); const Slider = React.forwardRef((props, ref) => { return ( <BaseSlider ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `h-1.5 w-full py-4 inline-block relative touch-none ${ ownerState.disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, resolvedSlotProps?.className, ), }; }, rail: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.rail, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'block absolute w-full h-1 rounded-sm bg-current opacity-40', resolvedSlotProps?.className, ), }; }, track: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.track, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'block absolute h-1 rounded-sm bg-current', resolvedSlotProps?.className, ), }; }, thumb: (ownerState, { active, focused }) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.thumb, ownerState, ); return { ...resolvedSlotProps, className: clsx( `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-[3px] border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-[0_0_0_4px_#e9d5ff] dark:shadow-[0_0_0_4px_#7e22ce] active:shadow-[0_0_0_4px_#d8b4fe] dark:active:shadow-[0_0_0_4px_#9333ea] outline-none' : '' }`, resolvedSlotProps?.className, ), }; }, }} /> ); }); Slider.propTypes = { /** * The props used for each slot inside the Slider. * @default {} */ slotProps: PropTypes.shape({ input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), mark: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), markLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), rail: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), track: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), valueLabel: PropTypes.oneOfType([PropTypes.any, PropTypes.func]), }), };
466
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx
import * as React from 'react'; import { useTheme } from '@mui/system'; import { Slider as BaseSlider, SliderProps } from '@mui/base/Slider'; import clsx from 'clsx'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSliderIntroduction() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <div className={isDarkMode ? 'dark' : ''} style={{ width: 320 }}> <Slider defaultValue={50} /> <Slider defaultValue={10} disabled /> </div> ); } const resolveSlotProps = (fn: any, args: any) => typeof fn === 'function' ? fn(args) : fn; const Slider = React.forwardRef<HTMLSpanElement, SliderProps>((props, ref) => { return ( <BaseSlider ref={ref} {...props} slotProps={{ ...props.slotProps, root: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.root, ownerState, ); return { ...resolvedSlotProps, className: clsx( `h-1.5 w-full py-4 inline-block relative touch-none ${ ownerState.disabled ? 'opacity-50 cursor-default pointer-events-none text-slate-300 dark:text-slate-600' : 'hover:opacity-100 cursor-pointer text-purple-500 dark:text-purple-400' }`, resolvedSlotProps?.className, ), }; }, rail: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.rail, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'block absolute w-full h-1 rounded-sm bg-current opacity-40', resolvedSlotProps?.className, ), }; }, track: (ownerState) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.track, ownerState, ); return { ...resolvedSlotProps, className: clsx( 'block absolute h-1 rounded-sm bg-current', resolvedSlotProps?.className, ), }; }, thumb: (ownerState, { active, focused }) => { const resolvedSlotProps = resolveSlotProps( props.slotProps?.thumb, ownerState, ); return { ...resolvedSlotProps, className: clsx( `absolute w-4 h-4 -ml-1.5 -mt-1.5 box-border rounded-full outline-0 border-[3px] border-solid border-current bg-white hover:shadow-outline-purple ${ focused || active ? 'shadow-[0_0_0_4px_#e9d5ff] dark:shadow-[0_0_0_4px_#7e22ce] active:shadow-[0_0_0_4px_#d8b4fe] dark:active:shadow-[0_0_0_4px_#9333ea] outline-none' : '' }`, resolvedSlotProps?.className, ), }; }, }} /> ); });
467
0
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx.preview
<Slider defaultValue={50} /> <Slider defaultValue={10} disabled />
468
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/TransitionComponentSnackbar.js
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { styled } from '@mui/system'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; export default function TransitionComponentSnackbar() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_, reason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleClick}> Open snackbar </TriggerButton> <StyledSnackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <SnackbarContent style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <div className="snackbar-title">Hello World</div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </SnackbarContent> )} </Transition> </StyledSnackbar> </React.Fragment> ); } const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.15)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const StyledSnackbar = styled(Snackbar)` position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; `; const SnackbarContent = styled('div')( ({ theme }) => ` position: relative; overflow: hidden; z-index: 5500; display: flex; left: auto; justify-content: space-between; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${ theme.palette.mode === 'dark' ? `0 2px 8px rgb(0 0 0 / 0.5)` : `0 2px 8px ${grey[200]}` }; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; & .snackbar-title { margin-right: 0.5rem; } & .snackbar-close-icon { cursor: pointer; font-size: 10px; width: 1.25rem; height: 1.5rem; display: flex; align-items: center; justify-content: center; } `, ); const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
469
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/TransitionComponentSnackbar.tsx
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { styled } from '@mui/system'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; import { SnackbarCloseReason } from '@mui/base/useSnackbar'; export default function TransitionComponentSnackbar() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_: any, reason: SnackbarCloseReason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleClick}> Open snackbar </TriggerButton> <StyledSnackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <SnackbarContent style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <div className="snackbar-title">Hello World</div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </SnackbarContent> )} </Transition> </StyledSnackbar> </React.Fragment> ); } const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.15)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const StyledSnackbar = styled(Snackbar)` position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; `; const SnackbarContent = styled('div')( ({ theme }) => ` position: relative; overflow: hidden; z-index: 5500; display: flex; left: auto; justify-content: space-between; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${ theme.palette.mode === 'dark' ? `0 2px 8px rgb(0 0 0 / 0.5)` : `0 2px 8px ${grey[200]}` }; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; & .snackbar-title { margin-right: 0.5rem; } & .snackbar-close-icon { cursor: pointer; font-size: 10px; width: 1.25rem; height: 1.5rem; display: flex; align-items: center; justify-content: center; } `, ); const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
470
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UseSnackbar.js
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { css, keyframes, styled } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment> ); } const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const snackbarInRight = keyframes` from { transform: translateX(100%); } to { transform: translateX(0); } `; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.15)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const CustomSnackbar = styled('div')( ({ theme }) => css` position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: space-between; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${theme.palette.mode === 'dark' ? `0 2px 8px rgb(0 0 0 / 0.5)` : `0 2px 8px ${grey[200]}`}; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; animation: ${snackbarInRight} 200ms; transition: transform 0.2s ease-out; `, );
471
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UseSnackbar.tsx
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { css, keyframes, styled } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment> ); } const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0066CC', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const snackbarInRight = keyframes` from { transform: translateX(100%); } to { transform: translateX(0); } `; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(45, 45, 60, 0.15)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const CustomSnackbar = styled('div')( ({ theme }) => css` position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: space-between; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${theme.palette.mode === 'dark' ? `0 2px 8px rgb(0 0 0 / 0.5)` : `0 2px 8px ${grey[200]}`}; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 600; animation: ${snackbarInRight} 200ms; transition: transform 0.2s ease-out; `, );
472
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UseSnackbar.tsx.preview
<React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment>
473
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/snackbar.md
--- productId: base-ui title: React Snackbar component and hook components: Snackbar hooks: useSnackbar githubLabel: 'component: snackbar' --- # Snackbar <p class="description">The Snackbar component informs users that an action has been or will be performed by the app.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction A snackbar provides users with a brief, temporary message about app processes without interrupting their activity or experience. The Snackbar component is built to appear on-screen to inform users about an action that the app is taking. {{"demo": "UnstyledSnackbarIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Component ```jsx import { Snackbar } from '@mui/base/Snackbar'; ``` Snackbar doesn't impose any restrictions on its implementation—it's up to you to design it so that it doesn't interrupt the user experience, and disappears after a set amount of time without requiring the user to take action. Use the `autoHideDuration` prop to set the time (in milliseconds) that the snackbar remains on the screen. :::info You may want to implement Snackbar with [Click-Away Listener](/base-ui/react-click-away-listener/), so that the user can choose to dismiss the Snackbar before its time is up by clicking anywhere outside of it. But this behavior is optional. ::: The following demo illustrates the basic usage of Snackbar. Click **Open snackbar** to see how it behaves: {{"demo": "UnstyledSnackbar", "defaultCodeOpen": false}} ### Anatomy The Snackbar component is composed of a single root `<div>` slot with no interior slots: ```html <div role="presentation" className="BaseSnackbar-root">snackbar content</div> ``` ### Custom structure Use the `slots.root` prop to override the root slot with a custom element: ```jsx <Snackbar slots={{ root: 'span' }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for full details. ::: ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic to the unstyled component. This way, you can safely provide the custom component's props directly on the component: ```tsx <Snackbar<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <Snackbar<'button'> slots={{ root: 'button' }} onClick={() => {}} /> ``` ## Hook ```js import { useSnackbar } from '@mui/base/useSnackbar'; ``` The `useSnackbar` hook lets you apply the functionality of a Snackbar to a fully custom component. It returns props to be placed on the custom component, along with fields representing the component's internal state. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). If you use a [Click-Away Listener](/base-ui/react-click-away-listener/) to let the user close the Snackbar by clicking outside of it, make sure to pass the `onClickAway` handler returned by this hook to the Click-Away Listener. Pass the `open` state to the hook and use it to show and hide the Snackbar. The demo below shows how to build a fully custom component with the `useSnackbar` hook that also incorporates the Click-Away Listener component: {{"demo": "UseSnackbar.js", "defaultCodeOpen": false}} :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [structure](#anatomy). ::: ## Customization :::info The following features can be used with both components and hooks. For the sake of simplicity, demos and code snippets primarily feature components. ::: ### Transitions You can animate the open and close states of the Snackbar with a render prop child and a transition component, as long as the component meets these conditions: - Is a direct child descendant of the snackbar - Has an `in` prop—this corresponds to the open state - Passes the `exited` prop to Snackbar - Calls the `onEnter` callback prop when the enter transition starts—sets `exited` to false - Calls the `onExited` callback prop when the exit transition is completed—sets `exited` to true These two callbacks allow the Snackbar to unmount the child content when closed and keep it fully transitioned. This is only applicable if you are using transition components using [react-transition-group](https://github.com/reactjs/react-transition-group) library internally. The demo below shows how to create a Snackbar with custom transitions: {{"demo": "TransitionComponentSnackbar.js", "defaultCodeOpen": false}}
474
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/css/index.js
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { useTheme } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <button className="TriggerButton" type="button" onClick={handleOpen}> Open snackbar </button> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <div className="CustomSnackbar" {...getRootProps()}> Hello World </div> </ClickAwayListener> ) : null} <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` @keyframes in-right { from { transform: translateX(100%); } to { transform: translateX(0); } } .TriggerButton { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomSnackbar { position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: start; max-width: 560px; min-width: 300px; background-color: ${isDarkMode ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: ${ isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)` }; padding: 0.75rem; color: ${isDarkMode ? cyan[100] : cyan[700]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 500; animation: in-right 200ms; transition: transform 0.2s ease-out; } `}</style> ); }
475
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/css/index.tsx
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { useTheme } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <button className="TriggerButton" type="button" onClick={handleOpen}> Open snackbar </button> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <div className="CustomSnackbar" {...getRootProps()}> Hello World </div> </ClickAwayListener> ) : null} <Styles /> </React.Fragment> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` @keyframes in-right { from { transform: translateX(100%); } to { transform: translateX(0); } } .TriggerButton { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomSnackbar { position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: start; max-width: 560px; min-width: 300px; background-color: ${isDarkMode ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: ${ isDarkMode ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)` }; padding: 0.75rem; color: ${isDarkMode ? cyan[100] : cyan[700]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 500; animation: in-right 200ms; transition: transform 0.2s ease-out; } `}</style> ); }
476
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/css/index.tsx.preview
<React.Fragment> <button className="TriggerButton" type="button" onClick={handleOpen}> Open snackbar </button> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <div className="CustomSnackbar" {...getRootProps()}> Hello World </div> </ClickAwayListener> ) : null} <Styles /> </React.Fragment>
477
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/system/index.js
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { css, keyframes, styled } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const snackbarInRight = keyframes` from { transform: translateX(100%); } to { transform: translateX(0); } `; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const CustomSnackbar = styled('div')( ({ theme }) => css` position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: start; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${theme.palette.mode === 'dark' ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`}; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? blue[200] : blue[700]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 500; animation: ${snackbarInRight} 200ms; transition: transform 0.2s ease-out; `, );
478
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/system/index.tsx
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { css, keyframes, styled } from '@mui/system'; export default function UseSnackbar() { const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment> ); } const blue = { 50: '#F0F7FF', 100: '#C2E0FF', 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 800: '#004C99', 900: '#003A75', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const snackbarInRight = keyframes` from { transform: translateX(100%); } to { transform: translateX(0); } `; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const CustomSnackbar = styled('div')( ({ theme }) => css` position: fixed; z-index: 5500; display: flex; right: 16px; bottom: 16px; left: auto; justify-content: start; max-width: 560px; min-width: 300px; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${theme.palette.mode === 'dark' ? `0 4px 8px rgb(0 0 0 / 0.7)` : `0 4px 8px rgb(0 0 0 / 0.1)`}; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? blue[200] : blue[700]}; font-family: 'IBM Plex Sans', sans-serif; font-weight: 500; animation: ${snackbarInRight} 200ms; transition: transform 0.2s ease-out; `, );
479
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/system/index.tsx.preview
<React.Fragment> <TriggerButton type="button" onClick={handleOpen}> Open snackbar </TriggerButton> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <CustomSnackbar {...getRootProps()}>Hello World</CustomSnackbar> </ClickAwayListener> ) : null} </React.Fragment>
480
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/tailwind/index.js
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UseSnackbar() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <button className="cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm" type="button" onClick={handleOpen} > Open snackbar </button> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <div className="fixed z-50 font-sans flex right-4 bottom-4 left-auto justify-start rounded-lg font-semibold bg-white dark:bg-slate-900 p-3 animation-appear transition-transform border border-solid border-slate-200 dark:border-slate-700 min-w-snackbar max-w-snackbar shadow-md text-purple-900 dark:text-purple-100" {...getRootProps()} > Hello World </div> </ClickAwayListener> ) : null} </div> ); }
481
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbar/tailwind/index.tsx
import * as React from 'react'; import { useSnackbar } from '@mui/base/useSnackbar'; import { ClickAwayListener } from '@mui/base/ClickAwayListener'; import { useTheme } from '@mui/system'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UseSnackbar() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); const [open, setOpen] = React.useState(false); const handleClose = () => { setOpen(false); }; const { getRootProps, onClickAway } = useSnackbar({ onClose: handleClose, open, autoHideDuration: 5000, }); const handleOpen = () => { setOpen(true); }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <button className="cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm" type="button" onClick={handleOpen} > Open snackbar </button> {open ? ( <ClickAwayListener onClickAway={onClickAway}> <div className="fixed z-50 font-sans flex right-4 bottom-4 left-auto justify-start rounded-lg font-semibold bg-white dark:bg-slate-900 p-3 animation-appear transition-transform border border-solid border-slate-200 dark:border-slate-700 min-w-snackbar max-w-snackbar shadow-md text-purple-900 dark:text-purple-100" {...getRootProps()} > Hello World </div> </ClickAwayListener> ) : null} </div> ); }
482
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/css/index.js
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { useTheme } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; export default function UnstyledSnackbarIntroduction() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_, reason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <button className="TriggerButtonIntroduction" type="button" onClick={handleClick} > Open snackbar </button> <Snackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} className="CustomSnackbarIntroduction" > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <div className="CustomSnackbarContentIntroduction" style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="snackbar-message"> <p className="snackbar-title">Notifications sent</p> <p className="snackbar-description"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </div> )} </Transition> </Snackbar> <Styles /> </React.Fragment> ); } const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` @keyframes in-right { from { transform: translateX(100%); } to { transform: translateX(0); } } .TriggerButtonIntroduction { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomSnackbarIntroduction { position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; max-width: 560px; min-width: 300px; } .CustomSnackbarContentIntroduction { display: flex; gap: 8px; overflow: hidden; background-color: ${isDarkMode ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: ${ isDarkMode ? `0 2px 16px rgba(0,0,0, 0.5)` : `0 2px 16px ${grey[200]}` }; padding: 0.75rem; color: ${isDarkMode ? grey[50] : grey[900]}; font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; & .snackbar-message { flex: 1 1 0%; max-width: 100%; } & .snackbar-title { margin: 0; line-height: 1.5rem; margin-right: 0.5rem; } & .snackbar-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${isDarkMode ? grey[400] : grey[800]}; } & .snackbar-close-icon { cursor: pointer; flex-shrink: 0; padding: 2px; border-radius: 4px; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; } } } `}</style> ); }
483
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/css/index.tsx
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { useTheme } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; import { SnackbarCloseReason } from '@mui/base/useSnackbar'; export default function UnstyledSnackbarIntroduction() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_: any, reason: SnackbarCloseReason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <button className="TriggerButtonIntroduction" type="button" onClick={handleClick} > Open snackbar </button> <Snackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} className="CustomSnackbarIntroduction" > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <div className="CustomSnackbarContentIntroduction" style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="snackbar-message"> <p className="snackbar-title">Notifications sent</p> <p className="snackbar-description"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </div> )} </Transition> </Snackbar> <Styles /> </React.Fragment> ); } const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark mode const isDarkMode = useIsDarkMode(); return ( <style>{` @keyframes in-right { from { transform: translateX(100%); } to { transform: translateX(0); } } .TriggerButtonIntroduction { font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${isDarkMode ? grey[900] : '#fff'}; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; color: ${isDarkMode ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } &:active { background: ${isDarkMode ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${isDarkMode ? cyan[300] : cyan[200]}; outline: none; } } .CustomSnackbarIntroduction { position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; max-width: 560px; min-width: 300px; } .CustomSnackbarContentIntroduction { display: flex; gap: 8px; overflow: hidden; background-color: ${isDarkMode ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${isDarkMode ? grey[700] : grey[200]}; box-shadow: ${ isDarkMode ? `0 2px 16px rgba(0,0,0, 0.5)` : `0 2px 16px ${grey[200]}` }; padding: 0.75rem; color: ${isDarkMode ? grey[50] : grey[900]}; font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; & .snackbar-message { flex: 1 1 0%; max-width: 100%; } & .snackbar-title { margin: 0; line-height: 1.5rem; margin-right: 0.5rem; } & .snackbar-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${isDarkMode ? grey[400] : grey[800]}; } & .snackbar-close-icon { cursor: pointer; flex-shrink: 0; padding: 2px; border-radius: 4px; &:hover { background: ${isDarkMode ? grey[800] : grey[50]}; } } } `}</style> ); }
484
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/system/index.js
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { styled } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; export default function UnstyledSnackbarIntroduction() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_, reason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleClick}> Open snackbar </TriggerButton> <StyledSnackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <SnackbarContent style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="snackbar-message"> <p className="snackbar-title">Notifications sent</p> <p className="snackbar-description"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </SnackbarContent> )} </Transition> </StyledSnackbar> </React.Fragment> ); } const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 800: '#004C99', 900: '#003A75', }; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const StyledSnackbar = styled(Snackbar)` position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; max-width: 560px; min-width: 300px; `; const SnackbarContent = styled('div')( ({ theme }) => ` display: flex; gap: 8px; overflow: hidden; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${ theme.palette.mode === 'dark' ? `0 2px 16px rgba(0,0,0, 0.5)` : `0 2px 16px ${grey[200]}` }; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; & .snackbar-message { flex: 1 1 0%; max-width: 100%; } & .snackbar-title { margin: 0; line-height: 1.5rem; margin-right: 0.5rem; } & .snackbar-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]}; } & .snackbar-close-icon { cursor: pointer; flex-shrink: 0; padding: 2px; border-radius: 4px; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; } } `, ); const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
485
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/system/index.tsx
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { styled } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; import { SnackbarCloseReason } from '@mui/base/useSnackbar'; export default function UnstyledSnackbarIntroduction() { const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_: any, reason: SnackbarCloseReason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <React.Fragment> <TriggerButton type="button" onClick={handleClick}> Open snackbar </TriggerButton> <StyledSnackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <SnackbarContent style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="snackbar-message"> <p className="snackbar-title">Notifications sent</p> <p className="snackbar-description"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="snackbar-close-icon" /> </SnackbarContent> )} </Transition> </StyledSnackbar> </React.Fragment> ); } const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const blue = { 200: '#99CCF3', 300: '#66B2FF', 400: '#3399FF', 500: '#007FFF', 600: '#0072E5', 700: '#0059B2', 800: '#004C99', 900: '#003A75', }; const TriggerButton = styled('button')( ({ theme }) => ` font-family: IBM Plex Sans, sans-serif; font-weight: 600; font-size: 0.875rem; line-height: 1.5; padding: 8px 16px; border-radius: 8px; color: white; transition: all 150ms ease; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : '#fff'}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; color: ${theme.palette.mode === 'dark' ? grey[200] : grey[900]}; box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; border-color: ${theme.palette.mode === 'dark' ? grey[600] : grey[300]}; } &:active { background: ${theme.palette.mode === 'dark' ? grey[700] : grey[100]}; } &:focus-visible { box-shadow: 0 0 0 4px ${theme.palette.mode === 'dark' ? blue[300] : blue[200]}; outline: none; } `, ); const StyledSnackbar = styled(Snackbar)` position: fixed; z-index: 5500; display: flex; bottom: 16px; right: 16px; max-width: 560px; min-width: 300px; `; const SnackbarContent = styled('div')( ({ theme }) => ` display: flex; gap: 8px; overflow: hidden; background-color: ${theme.palette.mode === 'dark' ? grey[900] : '#FFF'}; border-radius: 8px; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; box-shadow: ${ theme.palette.mode === 'dark' ? `0 2px 16px rgba(0,0,0, 0.5)` : `0 2px 16px ${grey[200]}` }; padding: 0.75rem; color: ${theme.palette.mode === 'dark' ? grey[50] : grey[900]}; font-family: IBM Plex Sans, sans-serif; font-weight: 500; text-align: start; position: relative; & .snackbar-message { flex: 1 1 0%; max-width: 100%; } & .snackbar-title { margin: 0; line-height: 1.5rem; margin-right: 0.5rem; } & .snackbar-description { margin: 0; line-height: 1.5rem; font-weight: 400; color: ${theme.palette.mode === 'dark' ? grey[400] : grey[800]}; } & .snackbar-close-icon { cursor: pointer; flex-shrink: 0; padding: 2px; border-radius: 4px; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[50]}; } } `, ); const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
486
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/tailwind/index.js
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { useTheme } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSnackbarIntroduction() { const isDarkMode = useIsDarkMode(); const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_, reason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <button className="cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm" type="button" onClick={handleClick} > Open snackbar </button> <Snackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} className="fixed z-50 font-sans flex right-4 bottom-4 left-auto max-w-xl min-w-xs" > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <div className="flex gap-4 overflow-hidden bg-white dark:bg-slate-900 rounded-lg border border-solid border-slate-200 dark:border-slate-700 shadow-md text-slate-900 dark:text-slate-50 p-3 text-start" style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="flex-1 max-w-full"> <p className="m-0 leading-normal mr-2 font-medium"> Notifications sent </p> <p className="m-0 leading-normal font-normal text-slate-800 dark:text-slate-400"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="cursor-pointer shrink-0 p-0.5 rounded hover:bg-slate-50 hover:dark:bg-slate-800" /> </div> )} </Transition> </Snackbar> </div> ); } const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
487
0
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/snackbar/UnstyledSnackbarIntroduction/tailwind/index.tsx
import * as React from 'react'; import { Transition } from 'react-transition-group'; import { useTheme } from '@mui/system'; import CheckRoundedIcon from '@mui/icons-material/CheckRounded'; import CloseIcon from '@mui/icons-material/Close'; import { Snackbar } from '@mui/base/Snackbar'; import { SnackbarCloseReason } from '@mui/base/useSnackbar'; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } export default function UnstyledSnackbarIntroduction() { const isDarkMode = useIsDarkMode(); const [open, setOpen] = React.useState(false); const [exited, setExited] = React.useState(true); const nodeRef = React.useRef(null); const handleClose = (_: any, reason: SnackbarCloseReason) => { if (reason === 'clickaway') { return; } setOpen(false); }; const handleClick = () => { setOpen(true); }; const handleOnEnter = () => { setExited(false); }; const handleOnExited = () => { setExited(true); }; return ( <div className={`${isDarkMode ? 'dark' : ''}`}> <button className="cursor-pointer text-sm font-sans box-border rounded-lg font-semibold px-4 py-2 bg-white dark:bg-slate-900 border border-solid border-slate-200 dark:border-slate-700 text-slate-900 dark:text-slate-200 hover:bg-slate-50 hover:dark:bg-slate-800 hover:border-slate-300 dark:hover:border-slate-600 focus-visible:shadow-[0_0_0_4px_#ddd6fe] dark:focus-visible:shadow-[0_0_0_4px_#a78bfa] focus-visible:outline-none shadow-sm" type="button" onClick={handleClick} > Open snackbar </button> <Snackbar autoHideDuration={5000} open={open} onClose={handleClose} exited={exited} className="fixed z-50 font-sans flex right-4 bottom-4 left-auto max-w-xl min-w-xs" > <Transition timeout={{ enter: 400, exit: 400 }} in={open} appear unmountOnExit onEnter={handleOnEnter} onExited={handleOnExited} nodeRef={nodeRef} > {(status) => ( <div className="flex gap-4 overflow-hidden bg-white dark:bg-slate-900 rounded-lg border border-solid border-slate-200 dark:border-slate-700 shadow-md text-slate-900 dark:text-slate-50 p-3 text-start" style={{ transform: positioningStyles[status], transition: 'transform 300ms ease', }} ref={nodeRef} > <CheckRoundedIcon sx={{ color: 'success.main', flexShrink: 0, width: '1.25rem', height: '1.5rem', }} /> <div className="flex-1 max-w-full"> <p className="m-0 leading-normal mr-2 font-medium"> Notifications sent </p> <p className="m-0 leading-normal font-normal text-slate-800 dark:text-slate-400"> Everything was sent to the desired address. </p> </div> <CloseIcon onClick={handleClose} className="cursor-pointer shrink-0 p-0.5 rounded hover:bg-slate-50 hover:dark:bg-slate-800" /> </div> )} </Transition> </Snackbar> </div> ); } const positioningStyles = { entering: 'translateX(0)', entered: 'translateX(0)', exiting: 'translateX(500px)', exited: 'translateX(500px)', unmounted: 'translateX(500px)', };
488
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitches.js
import * as React from 'react'; import { styled } from '@mui/system'; import { Switch, switchClasses } from '@mui/base/Switch'; export default function UnstyledSwitches() { const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } }; return ( <div> <Switch slots={{ root: Root, }} {...label} defaultChecked /> <Switch slots={{ root: Root, }} {...label} /> <Switch slots={{ root: Root, }} {...label} defaultChecked disabled /> <Switch slots={{ root: Root, }} {...label} disabled /> </div> ); } const blue = { 200: '#99CCF3', 500: '#007FFF', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Root = styled('span')( ({ theme }) => ` font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; &.${switchClasses.disabled} { opacity: 0.4; cursor: not-allowed; } & .${switchClasses.track} { background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; border-radius: 24px; display: block; height: 100%; width: 100%; position: absolute; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; } &:hover .${switchClasses.track} { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; } &.${switchClasses.focusVisible} .${switchClasses.track} { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]}; } & .${switchClasses.thumb} { display: block; width: 16px; height: 16px; top: 4px; left: 4px; border-radius: 16px; background-color: #FFF; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; box-shadow: 0px 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)' }; } &.${switchClasses.checked} { .${switchClasses.thumb} { left: 17px; background-color: #fff; } .${switchClasses.track} { background: ${blue[500]}; } } & .${switchClasses.input} { cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; } `, );
489
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitches.tsx
import * as React from 'react'; import { styled } from '@mui/system'; import { Switch, switchClasses } from '@mui/base/Switch'; export default function UnstyledSwitches() { const label = { slotProps: { input: { 'aria-label': 'Demo switch' } } }; return ( <div> <Switch slots={{ root: Root, }} {...label} defaultChecked /> <Switch slots={{ root: Root, }} {...label} /> <Switch slots={{ root: Root, }} {...label} defaultChecked disabled /> <Switch slots={{ root: Root, }} {...label} disabled /> </div> ); } const blue = { 200: '#99CCF3', 500: '#007FFF', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const Root = styled('span')( ({ theme }) => ` font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; &.${switchClasses.disabled} { opacity: 0.4; cursor: not-allowed; } & .${switchClasses.track} { background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; border-radius: 24px; display: block; height: 100%; width: 100%; position: absolute; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; } &:hover .${switchClasses.track} { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; } &.${switchClasses.focusVisible} .${switchClasses.track} { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? grey[700] : blue[200]}; } & .${switchClasses.thumb} { display: block; width: 16px; height: 16px; top: 4px; left: 4px; border-radius: 16px; background-color: #FFF; border: 1px solid ${theme.palette.mode === 'dark' ? grey[700] : grey[200]}; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; box-shadow: 0px 1px 2px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)' }; } &.${switchClasses.checked} { .${switchClasses.thumb} { left: 17px; background-color: #fff; } .${switchClasses.track} { background: ${blue[500]}; } } & .${switchClasses.input} { cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; } `, );
490
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesBasic.js
import * as React from 'react'; import clsx from 'clsx'; import { styled } from '@mui/system'; import { useSwitch } from '@mui/base/useSwitch'; export default function UseSwitchesBasic() { return ( <div> <BasicSwitch defaultChecked /> <BasicSwitch /> <BasicSwitch defaultChecked disabled /> <BasicSwitch disabled /> </div> ); } function BasicSwitch(props) { const { getInputProps, checked, disabled, focusVisible } = useSwitch(props); const stateClasses = { 'Switch-checked': checked, 'Switch-disabled': disabled, 'Switch-focusVisible': focusVisible, }; return ( <BasicSwitchRoot className={clsx(stateClasses)}> <BasicSwitchThumb className={clsx(stateClasses)} /> <BasicSwitchInput {...getInputProps()} aria-label="Demo switch" /> </BasicSwitchRoot> ); } const blue = { 200: '#99CCF3', 500: '#007FFF', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const BasicSwitchRoot = styled('span')( ({ theme }) => ` font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; border-radius: 24px; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; } &.Switch-focusVisible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } &.Switch-disabled { opacity: 0.4; cursor: not-allowed; } &.Switch-checked { border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; background: ${blue[500]}; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(0, 0, 0, 0.05)' }; &.Switch-focusVisible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } } `, ); const BasicSwitchInput = styled('input')` cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; `; const BasicSwitchThumb = styled('span')( ({ theme }) => ` display: block; width: 16px; height: 16px; top: 3px; left: 2px; border-radius: 16px; background-color: #fff; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; box-shadow: 0px 1px 2px ${theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)'}; &.Switch-checked { left: 17px; background-color: #fff; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; } `, );
491
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesBasic.tsx
import * as React from 'react'; import clsx from 'clsx'; import { styled } from '@mui/system'; import { useSwitch, UseSwitchParameters } from '@mui/base/useSwitch'; export default function UseSwitchesBasic() { return ( <div> <BasicSwitch defaultChecked /> <BasicSwitch /> <BasicSwitch defaultChecked disabled /> <BasicSwitch disabled /> </div> ); } function BasicSwitch(props: UseSwitchParameters) { const { getInputProps, checked, disabled, focusVisible } = useSwitch(props); const stateClasses = { 'Switch-checked': checked, 'Switch-disabled': disabled, 'Switch-focusVisible': focusVisible, }; return ( <BasicSwitchRoot className={clsx(stateClasses)}> <BasicSwitchThumb className={clsx(stateClasses)} /> <BasicSwitchInput {...getInputProps()} aria-label="Demo switch" /> </BasicSwitchRoot> ); } const blue = { 200: '#99CCF3', 500: '#007FFF', 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const BasicSwitchRoot = styled('span')( ({ theme }) => ` font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; background: ${theme.palette.mode === 'dark' ? grey[900] : grey[50]}; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; border-radius: 24px; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; &:hover { background: ${theme.palette.mode === 'dark' ? grey[800] : grey[100]}; } &.Switch-focusVisible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } &.Switch-disabled { opacity: 0.4; cursor: not-allowed; } &.Switch-checked { border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; background: ${blue[500]}; box-shadow: inset 0px 1px 1px ${ theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.2)' : 'rgba(0, 0, 0, 0.05)' }; &.Switch-focusVisible { box-shadow: 0 0 0 3px ${theme.palette.mode === 'dark' ? blue[700] : blue[200]}; } } `, ); const BasicSwitchInput = styled('input')` cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; `; const BasicSwitchThumb = styled('span')( ({ theme }) => ` display: block; width: 16px; height: 16px; top: 3px; left: 2px; border-radius: 16px; background-color: #fff; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; box-shadow: 0px 1px 2px ${theme.palette.mode === 'dark' ? 'rgba(0, 0, 0, 0.25)' : 'rgba(0, 0, 0, 0.1)'}; &.Switch-checked { left: 17px; background-color: #fff; border: 1px solid ${theme.palette.mode === 'dark' ? grey[800] : grey[200]}; } `, );
492
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesBasic.tsx.preview
<BasicSwitch defaultChecked /> <BasicSwitch /> <BasicSwitch defaultChecked disabled /> <BasicSwitch disabled />
493
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesCustom.js
import * as React from 'react'; import clsx from 'clsx'; import { styled } from '@mui/system'; import { useSwitch } from '@mui/base/useSwitch'; export default function UseSwitchesCustom() { return <MUISwitch defaultChecked />; } function MUISwitch(props) { const { getInputProps, checked, disabled, focusVisible } = useSwitch(props); const stateClasses = { checked, disabled, focusVisible, }; return ( <SwitchRoot className={clsx(stateClasses)}> <SwitchTrack> <SwitchThumb className={clsx(stateClasses)} /> </SwitchTrack> <SwitchInput {...getInputProps()} aria-label="Demo switch" /> </SwitchRoot> ); } const blue = { 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const SwitchRoot = styled('span')` display: inline-block; position: relative; width: 64px; height: 36px; padding: 8px; `; const SwitchInput = styled('input')` position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; cursor: pointer; `; const SwitchThumb = styled('span')` position: absolute; display: block; background-color: ${blue[700]}; width: 30px; height: 30px; border-radius: 8px; top: 3px; left: 4px; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); &::before { display: block; content: ''; width: 100%; height: 100%; /* false positive: */ /* stylelint-disable unit-no-unknown */ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 20 20"><path fill="${encodeURIComponent( '#fff', )}" d="M9.305 1.667V3.75h1.389V1.667h-1.39zm-4.707 1.95l-.982.982L5.09 6.072l.982-.982-1.473-1.473zm10.802 0L13.927 5.09l.982.982 1.473-1.473-.982-.982zM10 5.139a4.872 4.872 0 00-4.862 4.86A4.872 4.872 0 0010 14.862 4.872 4.872 0 0014.86 10 4.872 4.872 0 0010 5.139zm0 1.389A3.462 3.462 0 0113.471 10a3.462 3.462 0 01-3.473 3.472A3.462 3.462 0 016.527 10 3.462 3.462 0 0110 6.528zM1.665 9.305v1.39h2.083v-1.39H1.666zm14.583 0v1.39h2.084v-1.39h-2.084zM5.09 13.928L3.616 15.4l.982.982 1.473-1.473-.982-.982zm9.82 0l-.982.982 1.473 1.473.982-.982-1.473-1.473zM9.305 16.25v2.083h1.389V16.25h-1.39z"/></svg>') center center no-repeat; /* stylelint-enable unit-no-unknown */ } &.focusVisible { background-color: #79b; } &.checked { transform: translateX(24px); &::before { /* false positive: */ /* stylelint-disable unit-no-unknown */ background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 20 20"><path fill="${encodeURIComponent( '#fff', )}" d="M4.2 2.5l-.7 1.8-1.8.7 1.8.7.7 1.8.6-1.8L6.7 5l-1.9-.7-.6-1.8zm15 8.3a6.7 6.7 0 11-6.6-6.6 5.8 5.8 0 006.6 6.6z"/></svg>'); /* stylelint-enable unit-no-unknown */ } } `; const SwitchTrack = styled('span')( ({ theme }) => ` background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[400]}; border-radius: 4px; width: 100%; height: 100%; display: block; `, );
494
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesCustom.tsx
import * as React from 'react'; import clsx from 'clsx'; import { styled } from '@mui/system'; import { useSwitch, UseSwitchParameters } from '@mui/base/useSwitch'; export default function UseSwitchesCustom() { return <MUISwitch defaultChecked />; } function MUISwitch(props: UseSwitchParameters) { const { getInputProps, checked, disabled, focusVisible } = useSwitch(props); const stateClasses = { checked, disabled, focusVisible, }; return ( <SwitchRoot className={clsx(stateClasses)}> <SwitchTrack> <SwitchThumb className={clsx(stateClasses)} /> </SwitchTrack> <SwitchInput {...getInputProps()} aria-label="Demo switch" /> </SwitchRoot> ); } const blue = { 700: '#0059B2', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; const SwitchRoot = styled('span')` display: inline-block; position: relative; width: 64px; height: 36px; padding: 8px; `; const SwitchInput = styled('input')` position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; cursor: pointer; `; const SwitchThumb = styled('span')` position: absolute; display: block; background-color: ${blue[700]}; width: 30px; height: 30px; border-radius: 8px; top: 3px; left: 4px; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1); &::before { display: block; content: ''; width: 100%; height: 100%; /* false positive: */ /* stylelint-disable unit-no-unknown */ background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 20 20"><path fill="${encodeURIComponent( '#fff', )}" d="M9.305 1.667V3.75h1.389V1.667h-1.39zm-4.707 1.95l-.982.982L5.09 6.072l.982-.982-1.473-1.473zm10.802 0L13.927 5.09l.982.982 1.473-1.473-.982-.982zM10 5.139a4.872 4.872 0 00-4.862 4.86A4.872 4.872 0 0010 14.862 4.872 4.872 0 0014.86 10 4.872 4.872 0 0010 5.139zm0 1.389A3.462 3.462 0 0113.471 10a3.462 3.462 0 01-3.473 3.472A3.462 3.462 0 016.527 10 3.462 3.462 0 0110 6.528zM1.665 9.305v1.39h2.083v-1.39H1.666zm14.583 0v1.39h2.084v-1.39h-2.084zM5.09 13.928L3.616 15.4l.982.982 1.473-1.473-.982-.982zm9.82 0l-.982.982 1.473 1.473.982-.982-1.473-1.473zM9.305 16.25v2.083h1.389V16.25h-1.39z"/></svg>') center center no-repeat; /* stylelint-enable unit-no-unknown */ } &.focusVisible { background-color: #79b; } &.checked { transform: translateX(24px); &::before { /* false positive: */ /* stylelint-disable unit-no-unknown */ background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="20" width="20" viewBox="0 0 20 20"><path fill="${encodeURIComponent( '#fff', )}" d="M4.2 2.5l-.7 1.8-1.8.7 1.8.7.7 1.8.6-1.8L6.7 5l-1.9-.7-.6-1.8zm15 8.3a6.7 6.7 0 11-6.6-6.6 5.8 5.8 0 006.6 6.6z"/></svg>'); /* stylelint-enable unit-no-unknown */ } } `; const SwitchTrack = styled('span')( ({ theme }) => ` background-color: ${theme.palette.mode === 'dark' ? grey[800] : grey[400]}; border-radius: 4px; width: 100%; height: 100%; display: block; `, );
495
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/UseSwitchesCustom.tsx.preview
<MUISwitch defaultChecked />
496
0
petrpan-code/mui/material-ui/docs/data/base/components
petrpan-code/mui/material-ui/docs/data/base/components/switch/switch.md
--- productId: base-ui title: React Switch component and hook components: Switch hooks: useSwitch githubLabel: 'component: switch' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/switch/ --- # Switch <p class="description">Switches are UI elements that let users choose between two states—most commonly on/off.</p> {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} {{"component": "modules/components/ComponentPageTabs.js"}} ## Introduction The Switch component provides users with a switch for toggling between two mutually exclusive states. {{"demo": "UnstyledSwitchIntroduction", "defaultCodeOpen": false, "bg": "gradient"}} ## Component ```jsx import { Switch } from '@mui/base/Switch'; ``` ### Anatomy The Switch component is composed of a root `<span>` that houses three interior slots—a track, a thumb, and an input: ```html <span class="MuiSwitch-root"> <span class="MuiSwitch-track"></span> <span class="MuiSwitch-thumb"></span> <input type="checkbox" class="MuiSwitch-input" /> </span> ``` ### Custom structure Use the `slots` prop to override the root or any other interior slot: ```jsx <Switch slots={{ root: 'div', track: 'div' }} /> ``` :::info The `slots` prop is available on all non-utility Base components. See [Overriding component structure](/base-ui/guides/overriding-component-structure/) for full details. ::: Use the `slotProps` prop to pass custom props to internal slots. The following code snippet applies a CSS class called `my-thumb` to the thumb slot: ```jsx <Switch slotProps={{ thumb: { className: 'my-thumb' } }} /> ``` ### Usage with TypeScript In TypeScript, you can specify the custom component type used in the `slots.root` as a generic parameter of the unstyled component. This way, you can safely provide the custom root's props directly on the component: ```tsx <Switch<typeof CustomComponent> slots={{ root: CustomComponent }} customProp /> ``` The same applies for props specific to custom primitive elements: ```tsx <Switch<'input'> slots={{ root: 'input' }} autoFocus={true} /> ``` ## Hook ```js import { useSwitch } from '@mui/base/useSwitch'; ``` The `useSwitch` hook lets you apply the functionality of a Switch to a fully custom component. It returns props to be placed on the custom component, along with fields representing the component's internal state. Hooks _do not_ support [slot props](#custom-structure), but they do support [customization props](#customization). :::info Hooks give you the most room for customization, but require more work to implement. With hooks, you can take full control over how your component is rendered, and define all the custom props and CSS classes you need. You may not need to use hooks unless you find that you're limited by the customization options of their component counterparts—for instance, if your component requires significantly different [HTML structure](#anatomy). ::: ### Basic example {{"demo": "UseSwitchesBasic.js"}} ### Customized look and feel {{"demo": "UseSwitchesCustom.js"}} ## Accessibility To make the Switch component accessible, you should ensure that the corresponding labels reflect the Switch's current state.
497
0
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitchIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitchIntroduction/css/index.js
import * as React from 'react'; import { Switch, switchClasses } from '@mui/base/Switch'; import { useTheme } from '@mui/system'; export default function UnstyledSwitchIntroduction() { const label = { 'aria-label': 'Demo switch' }; return ( <div> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} defaultChecked /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} defaultChecked disabled /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSwitchIntroduction { font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; } .CustomSwitchIntroduction.${switchClasses.disabled} { opacity: 0.4; cursor: not-allowed; } .CustomSwitchIntroduction-track { background: ${isDarkMode ? grey[900] : grey[50]}; border: 1px solid ${isDarkMode ? grey[800] : grey[200]}; border-radius: 24px; display: block; height: 100%; width: 100%; position: absolute; box-shadow: inset 0px 1px 1px ${ isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; } .CustomSwitchIntroduction:hover .CustomSwitchIntroduction-track { background: ${isDarkMode ? grey[800] : grey[100]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } .CustomSwitchIntroduction-thumb { border: 1px solid ${isDarkMode ? grey[800] : grey[200]}; display: block; width: 16px; height: 16px; top: 4px; left: 4px; border-radius: 16px; background-color: #FFF; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; } .CustomSwitchIntroduction.${ switchClasses.focusVisible } .CustomSwitchIntroduction-track { box-shadow: 0 0 0 3px ${isDarkMode ? cyan[400] : cyan[200]}; } .CustomSwitchIntroduction.${ switchClasses.checked } .CustomSwitchIntroduction-thumb { left: 18px; background-color: #fff; box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); } .CustomSwitchIntroduction.${ switchClasses.checked } .CustomSwitchIntroduction-track { border: none; background: ${cyan[500]}; } .CustomSwitchIntroduction-input { cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; } `} </style> ); }
498
0
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitchIntroduction
petrpan-code/mui/material-ui/docs/data/base/components/switch/UnstyledSwitchIntroduction/css/index.tsx
import * as React from 'react'; import { Switch, switchClasses } from '@mui/base/Switch'; import { useTheme } from '@mui/system'; export default function UnstyledSwitchIntroduction() { const label = { 'aria-label': 'Demo switch' }; return ( <div> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} defaultChecked /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} defaultChecked disabled /> <Switch slotProps={{ root: { className: 'CustomSwitchIntroduction' }, input: { ...label, className: 'CustomSwitchIntroduction-input' }, thumb: { className: 'CustomSwitchIntroduction-thumb' }, track: { className: 'CustomSwitchIntroduction-track' }, }} disabled /> <Styles /> </div> ); } const cyan = { 50: '#E9F8FC', 100: '#BDEBF4', 200: '#99D8E5', 300: '#66BACC', 400: '#1F94AD', 500: '#0D5463', 600: '#094855', 700: '#063C47', 800: '#043039', 900: '#022127', }; const grey = { 50: '#F3F6F9', 100: '#E5EAF2', 200: '#DAE2ED', 300: '#C7D0DD', 400: '#B0B8C4', 500: '#9DA8B7', 600: '#6B7A90', 700: '#434D5B', 800: '#303740', 900: '#1C2025', }; function useIsDarkMode() { const theme = useTheme(); return theme.palette.mode === 'dark'; } function Styles() { // Replace this with your app logic for determining dark modes const isDarkMode = useIsDarkMode(); return ( <style> {` .CustomSwitchIntroduction { font-size: 0; position: relative; display: inline-block; width: 38px; height: 24px; margin: 10px; cursor: pointer; } .CustomSwitchIntroduction.${switchClasses.disabled} { opacity: 0.4; cursor: not-allowed; } .CustomSwitchIntroduction-track { background: ${isDarkMode ? grey[900] : grey[50]}; border: 1px solid ${isDarkMode ? grey[800] : grey[200]}; border-radius: 24px; display: block; height: 100%; width: 100%; position: absolute; box-shadow: inset 0px 1px 1px ${ isDarkMode ? 'rgba(0, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.05)' }; } .CustomSwitchIntroduction:hover .CustomSwitchIntroduction-track { background: ${isDarkMode ? grey[800] : grey[100]}; border-color: ${isDarkMode ? grey[600] : grey[300]}; } .CustomSwitchIntroduction-thumb { border: 1px solid ${isDarkMode ? grey[800] : grey[200]}; display: block; width: 16px; height: 16px; top: 4px; left: 4px; border-radius: 16px; background-color: #FFF; position: relative; transition-property: all; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); transition-duration: 120ms; } .CustomSwitchIntroduction.${ switchClasses.focusVisible } .CustomSwitchIntroduction-track { box-shadow: 0 0 0 3px ${isDarkMode ? cyan[400] : cyan[200]}; } .CustomSwitchIntroduction.${ switchClasses.checked } .CustomSwitchIntroduction-thumb { left: 18px; background-color: #fff; box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.3); } .CustomSwitchIntroduction.${ switchClasses.checked } .CustomSwitchIntroduction-track { border: none; background: ${cyan[500]}; } .CustomSwitchIntroduction-input { cursor: inherit; position: absolute; width: 100%; height: 100%; top: 0; left: 0; opacity: 0; z-index: 1; margin: 0; } `} </style> ); }
499