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/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectLabels.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function SelectLabels() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-helper-label">Age</InputLabel>
<Select
labelId="demo-simple-select-helper-label"
id="demo-simple-select-helper"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>With label + helper text</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<Select
value={age}
onChange={handleChange}
displayEmpty
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Without label</FormHelperText>
</FormControl>
</div>
);
}
| 2,900 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectLabels.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function SelectLabels() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-helper-label">Age</InputLabel>
<Select
labelId="demo-simple-select-helper-label"
id="demo-simple-select-helper"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>With label + helper text</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<Select
value={age}
onChange={handleChange}
displayEmpty
inputProps={{ 'aria-label': 'Without label' }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Without label</FormHelperText>
</FormControl>
</div>
);
}
| 2,901 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectOtherProps.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function SelectOtherProps() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }} disabled>
<InputLabel id="demo-simple-select-disabled-label">Age</InputLabel>
<Select
labelId="demo-simple-select-disabled-label"
id="demo-simple-select-disabled"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Disabled</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }} error>
<InputLabel id="demo-simple-select-error-label">Age</InputLabel>
<Select
labelId="demo-simple-select-error-label"
id="demo-simple-select-error"
value={age}
label="Age"
onChange={handleChange}
renderValue={(value) => `⚠️ - ${value}`}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Error</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-readonly-label">Age</InputLabel>
<Select
labelId="demo-simple-select-readonly-label"
id="demo-simple-select-readonly"
value={age}
label="Age"
onChange={handleChange}
inputProps={{ readOnly: true }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Read only</FormHelperText>
</FormControl>
<FormControl required sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-required-label">Age</InputLabel>
<Select
labelId="demo-simple-select-required-label"
id="demo-simple-select-required"
value={age}
label="Age *"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Required</FormHelperText>
</FormControl>
</div>
);
}
| 2,902 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectOtherProps.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormHelperText from '@mui/material/FormHelperText';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function SelectOtherProps() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value);
};
return (
<div>
<FormControl sx={{ m: 1, minWidth: 120 }} disabled>
<InputLabel id="demo-simple-select-disabled-label">Age</InputLabel>
<Select
labelId="demo-simple-select-disabled-label"
id="demo-simple-select-disabled"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Disabled</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }} error>
<InputLabel id="demo-simple-select-error-label">Age</InputLabel>
<Select
labelId="demo-simple-select-error-label"
id="demo-simple-select-error"
value={age}
label="Age"
onChange={handleChange}
renderValue={(value) => `⚠️ - ${value}`}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Error</FormHelperText>
</FormControl>
<FormControl sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-readonly-label">Age</InputLabel>
<Select
labelId="demo-simple-select-readonly-label"
id="demo-simple-select-readonly"
value={age}
label="Age"
onChange={handleChange}
inputProps={{ readOnly: true }}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Read only</FormHelperText>
</FormControl>
<FormControl required sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-required-label">Age</InputLabel>
<Select
labelId="demo-simple-select-required-label"
id="demo-simple-select-required"
value={age}
label="Age *"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
<FormHelperText>Required</FormHelperText>
</FormControl>
</div>
);
}
| 2,903 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectSmall.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function SelectSmall() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<FormControl sx={{ m: 1, minWidth: 120 }} size="small">
<InputLabel id="demo-select-small-label">Age</InputLabel>
<Select
labelId="demo-select-small-label"
id="demo-select-small"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
);
}
| 2,904 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectSmall.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function SelectSmall() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value);
};
return (
<FormControl sx={{ m: 1, minWidth: 120 }} size="small">
<InputLabel id="demo-select-small-label">Age</InputLabel>
<Select
labelId="demo-select-small-label"
id="demo-select-small"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
);
}
| 2,905 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectVariants.js | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select from '@mui/material/Select';
export default function SelectVariants() {
const [age, setAge] = React.useState('');
const handleChange = (event) => {
setAge(event.target.value);
};
return (
<div>
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-standard-label">Age</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
id="demo-simple-select-standard"
value={age}
onChange={handleChange}
label="Age"
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
<FormControl variant="filled" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-filled-label">Age</InputLabel>
<Select
labelId="demo-simple-select-filled-label"
id="demo-simple-select-filled"
value={age}
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,906 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/SelectVariants.tsx | import * as React from 'react';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import FormControl from '@mui/material/FormControl';
import Select, { SelectChangeEvent } from '@mui/material/Select';
export default function SelectVariants() {
const [age, setAge] = React.useState('');
const handleChange = (event: SelectChangeEvent) => {
setAge(event.target.value);
};
return (
<div>
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-standard-label">Age</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
id="demo-simple-select-standard"
value={age}
onChange={handleChange}
label="Age"
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
<FormControl variant="filled" sx={{ m: 1, minWidth: 120 }}>
<InputLabel id="demo-simple-select-filled-label">Age</InputLabel>
<Select
labelId="demo-simple-select-filled-label"
id="demo-simple-select-filled"
value={age}
onChange={handleChange}
>
<MenuItem value="">
<em>None</em>
</MenuItem>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
</div>
);
}
| 2,907 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/selects/selects.md | ---
productId: material-ui
title: React Select component
components: Select, NativeSelect
githubLabel: 'component: select'
materialDesign: https://m2.material.io/components/menus#exposed-dropdown-menu
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/
unstyled: /base-ui/react-select/
---
# Select
<p class="description">Select components are used for collecting user provided information from a list of options.</p>
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Basic select
Menus are positioned under their emitting elements, unless they are close to the bottom of the viewport.
{{"demo": "BasicSelect.js"}}
## Advanced features
The Select component is meant to be interchangeable with a native `<select>` element.
If you are looking for more advanced features, like combobox, multiselect, autocomplete, async or creatable support, head to the [`Autocomplete` component](/material-ui/react-autocomplete/).
It's meant to be an improved version of the "react-select" and "downshift" packages.
## Props
The Select component is implemented as a custom `<input>` element of the [InputBase](/material-ui/api/input-base/).
It extends the [text field components](/material-ui/react-text-field/) subcomponents, either the [OutlinedInput](/material-ui/api/outlined-input/), [Input](/material-ui/api/input/), or [FilledInput](/material-ui/api/filled-input/), depending on the variant selected.
It shares the same styles and many of the same props. Refer to the respective component's API page for details.
### Filled and standard variants
{{"demo": "SelectVariants.js"}}
### Labels and helper text
{{"demo": "SelectLabels.js"}}
:::warning
Note that when using FormControl with the outlined variant of the Select, you need to provide a label in two places: in the InputLabel component and in the `label` prop of the Select component (see the above demo).
:::
### Auto width
{{"demo": "SelectAutoWidth.js"}}
### Small Size
{{"demo": "SelectSmall.js"}}
### Other props
{{"demo": "SelectOtherProps.js"}}
## Native select
As the user experience can be improved on mobile using the native select of the platform,
we allow such pattern.
{{"demo": "NativeSelectDemo.js"}}
## TextField
The `TextField` wrapper component is a complete form control including a label, input and help text.
You can find an example with the select mode [in this section](/material-ui/react-text-field/#select).
## Customization
Here are some examples of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
The first step is to style the `InputBase` component.
Once it's styled, you can either use it directly as a text field or provide it to the select `input` prop to have a `select` field.
Notice that the `"standard"` variant is easier to customize, since it does not wrap the contents in a `fieldset`/`legend` markup.
{{"demo": "CustomizedSelects.js"}}
🎨 If you are looking for inspiration, you can check [MUI Treasury's customization examples](https://mui-treasury.com/styles/select/).
## Multiple select
The `Select` component can handle multiple selections.
It's enabled with the `multiple` prop.
Like with the single selection, you can pull out the new value by accessing `event.target.value` in the `onChange` callback. It's always an array.
### Default
{{"demo": "MultipleSelect.js"}}
### Checkmarks
{{"demo": "MultipleSelectCheckmarks.js"}}
### Chip
{{"demo": "MultipleSelectChip.js"}}
### Placeholder
{{"demo": "MultipleSelectPlaceholder.js"}}
### Native
{{"demo": "MultipleSelectNative.js"}}
## Controlling the open state
You can control the open state of the select with the `open` prop. Alternatively, it is also possible to set the initial (uncontrolled) open state of the component with the `defaultOpen` prop.
:::info
- A component is **controlled** when it's managed by its parent using props.
- A component is **uncontrolled** when it's managed by its own local state.
Learn more about controlled and uncontrolled components in the [React documentation](https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components).
:::
{{"demo": "ControlledOpenSelect.js"}}
## With a dialog
While it's discouraged by the Material Design guidelines, you can use a select inside a dialog.
{{"demo": "DialogSelect.js"}}
## Grouping
Display categories with the `ListSubheader` component or the native `<optgroup>` element.
{{"demo": "GroupedSelect.js"}}
:::warning
If you wish to wrap the ListSubheader in a custom component, you'll have to annotate it so Material UI can handle it properly when determining focusable elements.
You have two options for solving this:
Option 1: Define a static boolean field called `muiSkipListHighlight` on your component function, and set it to `true`:
```tsx
function MyListSubheader(props: ListSubheaderProps) {
return <ListSubheader {...props} />;
}
MyListSubheader.muiSkipListHighlight = true;
export default MyListSubheader;
// elsewhere:
return (
<Select>
<MyListSubheader>Group 1</MyListSubheader>
<MenuItem value={1}>Option 1</MenuItem>
<MenuItem value={2}>Option 2</MenuItem>
<MyListSubheader>Group 2</MyListSubheader>
<MenuItem value={3}>Option 3</MenuItem>
<MenuItem value={4}>Option 4</MenuItem>
{/* ... */}
</Select>
```
Option 2: Place a `muiSkipListHighlight` prop on each instance of your component.
The prop doesn't have to be forwarded to the ListSubheader, nor present in the underlying DOM element.
It just has to be placed on a component that's used as a subheader.
```tsx
export default function MyListSubheader(
props: ListSubheaderProps & { muiSkipListHighlight: boolean },
) {
const { muiSkipListHighlight, ...other } = props;
return <ListSubheader {...other} />;
}
// elsewhere:
return (
<Select>
<MyListSubheader muiSkipListHighlight>Group 1</MyListSubheader>
<MenuItem value={1}>Option 1</MenuItem>
<MenuItem value={2}>Option 2</MenuItem>
<MyListSubheader muiSkipListHighlight>Group 2</MyListSubheader>
<MenuItem value={3}>Option 3</MenuItem>
<MenuItem value={4}>Option 4</MenuItem>
{/* ... */}
</Select>
);
```
We recommend the first option as it doesn't require updating all the usage sites of the component.
Keep in mind this is **only necessary** if you wrap the ListSubheader in a custom component.
If you use the ListSubheader directly, **no additional code is required**.
:::
## Accessibility
To properly label your `Select` input you need an extra element with an `id` that contains a label.
That `id` needs to match the `labelId` of the `Select` e.g.
```jsx
<InputLabel id="label">Age</InputLabel>
<Select labelId="label" id="select" value="20">
<MenuItem value="10">Ten</MenuItem>
<MenuItem value="20">Twenty</MenuItem>
</Select>
```
Alternatively a `TextField` with an `id` and `label` creates the proper markup and
ids for you:
```jsx
<TextField id="select" label="Age" value="20" select>
<MenuItem value="10">Ten</MenuItem>
<MenuItem value="20">Twenty</MenuItem>
</TextField>
```
For a [native select](#native-select), you should mention a label by giving the value of the `id` attribute of the select element to the `InputLabel`'s `htmlFor` attribute:
```jsx
<InputLabel htmlFor="select">Age</InputLabel>
<NativeSelect id="select">
<option value="10">Ten</option>
<option value="20">Twenty</option>
</NativeSelect>
```
| 2,908 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Animations.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Skeleton from '@mui/material/Skeleton';
export default function Animations() {
return (
<Box sx={{ width: 300 }}>
<Skeleton />
<Skeleton animation="wave" />
<Skeleton animation={false} />
</Box>
);
}
| 2,909 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Animations.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Skeleton from '@mui/material/Skeleton';
export default function Animations() {
return (
<Box sx={{ width: 300 }}>
<Skeleton />
<Skeleton animation="wave" />
<Skeleton animation={false} />
</Box>
);
}
| 2,910 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Animations.tsx.preview | <Skeleton />
<Skeleton animation="wave" />
<Skeleton animation={false} /> | 2,911 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Facebook.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import Skeleton from '@mui/material/Skeleton';
function Media(props) {
const { loading = false } = props;
return (
<Card sx={{ maxWidth: 345, m: 2 }}>
<CardHeader
avatar={
loading ? (
<Skeleton animation="wave" variant="circular" width={40} height={40} />
) : (
<Avatar
alt="Ted talk"
src="https://pbs.twimg.com/profile_images/877631054525472768/Xp5FAPD5_reasonably_small.jpg"
/>
)
}
action={
loading ? null : (
<IconButton aria-label="settings">
<MoreVertIcon />
</IconButton>
)
}
title={
loading ? (
<Skeleton
animation="wave"
height={10}
width="80%"
style={{ marginBottom: 6 }}
/>
) : (
'Ted'
)
}
subheader={
loading ? (
<Skeleton animation="wave" height={10} width="40%" />
) : (
'5 hours ago'
)
}
/>
{loading ? (
<Skeleton sx={{ height: 190 }} animation="wave" variant="rectangular" />
) : (
<CardMedia
component="img"
height="140"
image="https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/72bda89f-9bbf-4685-910a-2f151c4f3a8a/NicolaSturgeon_2019T-embed.jpg?w=512"
alt="Nicola Sturgeon on a TED talk stage"
/>
)}
<CardContent>
{loading ? (
<React.Fragment>
<Skeleton animation="wave" height={10} style={{ marginBottom: 6 }} />
<Skeleton animation="wave" height={10} width="80%" />
</React.Fragment>
) : (
<Typography variant="body2" color="text.secondary" component="p">
{
"Why First Minister of Scotland Nicola Sturgeon thinks GDP is the wrong measure of a country's success:"
}
</Typography>
)}
</CardContent>
</Card>
);
}
Media.propTypes = {
loading: PropTypes.bool,
};
export default function Facebook() {
return (
<div>
<Media loading />
<Media />
</div>
);
}
| 2,912 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Facebook.tsx | import * as React from 'react';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
import CardContent from '@mui/material/CardContent';
import CardMedia from '@mui/material/CardMedia';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import IconButton from '@mui/material/IconButton';
import MoreVertIcon from '@mui/icons-material/MoreVert';
import Skeleton from '@mui/material/Skeleton';
interface MediaProps {
loading?: boolean;
}
function Media(props: MediaProps) {
const { loading = false } = props;
return (
<Card sx={{ maxWidth: 345, m: 2 }}>
<CardHeader
avatar={
loading ? (
<Skeleton animation="wave" variant="circular" width={40} height={40} />
) : (
<Avatar
alt="Ted talk"
src="https://pbs.twimg.com/profile_images/877631054525472768/Xp5FAPD5_reasonably_small.jpg"
/>
)
}
action={
loading ? null : (
<IconButton aria-label="settings">
<MoreVertIcon />
</IconButton>
)
}
title={
loading ? (
<Skeleton
animation="wave"
height={10}
width="80%"
style={{ marginBottom: 6 }}
/>
) : (
'Ted'
)
}
subheader={
loading ? (
<Skeleton animation="wave" height={10} width="40%" />
) : (
'5 hours ago'
)
}
/>
{loading ? (
<Skeleton sx={{ height: 190 }} animation="wave" variant="rectangular" />
) : (
<CardMedia
component="img"
height="140"
image="https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/72bda89f-9bbf-4685-910a-2f151c4f3a8a/NicolaSturgeon_2019T-embed.jpg?w=512"
alt="Nicola Sturgeon on a TED talk stage"
/>
)}
<CardContent>
{loading ? (
<React.Fragment>
<Skeleton animation="wave" height={10} style={{ marginBottom: 6 }} />
<Skeleton animation="wave" height={10} width="80%" />
</React.Fragment>
) : (
<Typography variant="body2" color="text.secondary" component="p">
{
"Why First Minister of Scotland Nicola Sturgeon thinks GDP is the wrong measure of a country's success:"
}
</Typography>
)}
</CardContent>
</Card>
);
}
export default function Facebook() {
return (
<div>
<Media loading />
<Media />
</div>
);
}
| 2,913 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Facebook.tsx.preview | <Media loading />
<Media /> | 2,914 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonChildren.js | import * as React from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Avatar from '@mui/material/Avatar';
import Grid from '@mui/material/Grid';
import Skeleton from '@mui/material/Skeleton';
const Image = styled('img')({
width: '100%',
});
function SkeletonChildrenDemo(props) {
const { loading = false } = props;
return (
<div>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Box sx={{ margin: 1 }}>
{loading ? (
<Skeleton variant="circular">
<Avatar />
</Skeleton>
) : (
<Avatar src="https://pbs.twimg.com/profile_images/877631054525472768/Xp5FAPD5_reasonably_small.jpg" />
)}
</Box>
<Box sx={{ width: '100%' }}>
{loading ? (
<Skeleton width="100%">
<Typography>.</Typography>
</Skeleton>
) : (
<Typography>Ted</Typography>
)}
</Box>
</Box>
{loading ? (
<Skeleton variant="rectangular" width="100%">
<div style={{ paddingTop: '57%' }} />
</Skeleton>
) : (
<Image
src="https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/72bda89f-9bbf-4685-910a-2f151c4f3a8a/NicolaSturgeon_2019T-embed.jpg?w=512"
alt=""
/>
)}
</div>
);
}
SkeletonChildrenDemo.propTypes = {
loading: PropTypes.bool,
};
export default function SkeletonChildren() {
return (
<Grid container spacing={8}>
<Grid item xs>
<SkeletonChildrenDemo loading />
</Grid>
<Grid item xs>
<SkeletonChildrenDemo />
</Grid>
</Grid>
);
}
| 2,915 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonChildren.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Avatar from '@mui/material/Avatar';
import Grid from '@mui/material/Grid';
import Skeleton from '@mui/material/Skeleton';
const Image = styled('img')({
width: '100%',
});
function SkeletonChildrenDemo(props: { loading?: boolean }) {
const { loading = false } = props;
return (
<div>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<Box sx={{ margin: 1 }}>
{loading ? (
<Skeleton variant="circular">
<Avatar />
</Skeleton>
) : (
<Avatar src="https://pbs.twimg.com/profile_images/877631054525472768/Xp5FAPD5_reasonably_small.jpg" />
)}
</Box>
<Box sx={{ width: '100%' }}>
{loading ? (
<Skeleton width="100%">
<Typography>.</Typography>
</Skeleton>
) : (
<Typography>Ted</Typography>
)}
</Box>
</Box>
{loading ? (
<Skeleton variant="rectangular" width="100%">
<div style={{ paddingTop: '57%' }} />
</Skeleton>
) : (
<Image
src="https://pi.tedcdn.com/r/talkstar-photos.s3.amazonaws.com/uploads/72bda89f-9bbf-4685-910a-2f151c4f3a8a/NicolaSturgeon_2019T-embed.jpg?w=512"
alt=""
/>
)}
</div>
);
}
export default function SkeletonChildren() {
return (
<Grid container spacing={8}>
<Grid item xs>
<SkeletonChildrenDemo loading />
</Grid>
<Grid item xs>
<SkeletonChildrenDemo />
</Grid>
</Grid>
);
}
| 2,916 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonChildren.tsx.preview | <Grid container spacing={8}>
<Grid item xs>
<SkeletonChildrenDemo loading />
</Grid>
<Grid item xs>
<SkeletonChildrenDemo />
</Grid>
</Grid> | 2,917 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonColor.js | import * as React from 'react';
import Skeleton from '@mui/material/Skeleton';
import Box from '@mui/material/Box';
export default function SkeletonColor() {
return (
<Box
sx={{
bgcolor: '#121212',
p: 8,
width: '100%',
display: 'flex',
justifyContent: 'center',
}}
>
<Skeleton
sx={{ bgcolor: 'grey.900' }}
variant="rectangular"
width={210}
height={118}
/>
</Box>
);
}
| 2,918 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonColor.tsx | import * as React from 'react';
import Skeleton from '@mui/material/Skeleton';
import Box from '@mui/material/Box';
export default function SkeletonColor() {
return (
<Box
sx={{
bgcolor: '#121212',
p: 8,
width: '100%',
display: 'flex',
justifyContent: 'center',
}}
>
<Skeleton
sx={{ bgcolor: 'grey.900' }}
variant="rectangular"
width={210}
height={118}
/>
</Box>
);
}
| 2,919 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonColor.tsx.preview | <Skeleton
sx={{ bgcolor: 'grey.900' }}
variant="rectangular"
width={210}
height={118}
/> | 2,920 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonTypography.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Typography from '@mui/material/Typography';
import Skeleton from '@mui/material/Skeleton';
import Grid from '@mui/material/Grid';
const variants = ['h1', 'h3', 'body1', 'caption'];
function TypographyDemo(props) {
const { loading = false } = props;
return (
<div>
{variants.map((variant) => (
<Typography component="div" key={variant} variant={variant}>
{loading ? <Skeleton /> : variant}
</Typography>
))}
</div>
);
}
TypographyDemo.propTypes = {
loading: PropTypes.bool,
};
export default function SkeletonTypography() {
return (
<Grid container spacing={8}>
<Grid item xs>
<TypographyDemo loading />
</Grid>
<Grid item xs>
<TypographyDemo />
</Grid>
</Grid>
);
}
| 2,921 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonTypography.tsx | import * as React from 'react';
import Typography, { TypographyProps } from '@mui/material/Typography';
import Skeleton from '@mui/material/Skeleton';
import Grid from '@mui/material/Grid';
const variants = [
'h1',
'h3',
'body1',
'caption',
] as readonly TypographyProps['variant'][];
function TypographyDemo(props: { loading?: boolean }) {
const { loading = false } = props;
return (
<div>
{variants.map((variant) => (
<Typography component="div" key={variant} variant={variant}>
{loading ? <Skeleton /> : variant}
</Typography>
))}
</div>
);
}
export default function SkeletonTypography() {
return (
<Grid container spacing={8}>
<Grid item xs>
<TypographyDemo loading />
</Grid>
<Grid item xs>
<TypographyDemo />
</Grid>
</Grid>
);
}
| 2,922 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/SkeletonTypography.tsx.preview | <Grid container spacing={8}>
<Grid item xs>
<TypographyDemo loading />
</Grid>
<Grid item xs>
<TypographyDemo />
</Grid>
</Grid> | 2,923 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Variants.js | import * as React from 'react';
import Skeleton from '@mui/material/Skeleton';
import Stack from '@mui/material/Stack';
export default function Variants() {
return (
<Stack spacing={1}>
{/* For variant="text", adjust the height via font-size */}
<Skeleton variant="text" sx={{ fontSize: '1rem' }} />
{/* For other variants, adjust the size with `width` and `height` */}
<Skeleton variant="circular" width={40} height={40} />
<Skeleton variant="rectangular" width={210} height={60} />
<Skeleton variant="rounded" width={210} height={60} />
</Stack>
);
}
| 2,924 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Variants.tsx | import * as React from 'react';
import Skeleton from '@mui/material/Skeleton';
import Stack from '@mui/material/Stack';
export default function Variants() {
return (
<Stack spacing={1}>
{/* For variant="text", adjust the height via font-size */}
<Skeleton variant="text" sx={{ fontSize: '1rem' }} />
{/* For other variants, adjust the size with `width` and `height` */}
<Skeleton variant="circular" width={40} height={40} />
<Skeleton variant="rectangular" width={210} height={60} />
<Skeleton variant="rounded" width={210} height={60} />
</Stack>
);
}
| 2,925 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/Variants.tsx.preview | {/* For variant="text", adjust the height via font-size */}
<Skeleton variant="text" sx={{ fontSize: '1rem' }} />
{/* For other variants, adjust the size with `width` and `height` */}
<Skeleton variant="circular" width={40} height={40} />
<Skeleton variant="rectangular" width={210} height={60} />
<Skeleton variant="rounded" width={210} height={60} /> | 2,926 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/YouTube.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Grid from '@mui/material/Grid';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Skeleton from '@mui/material/Skeleton';
const data = [
{
src: 'https://i.ytimg.com/vi/pLqipJNItIo/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLBkklsyaw9FxDmMKapyBYCn9tbPNQ',
title: 'Don Diablo @ Tomorrowland Main Stage 2019 | Official…',
channel: 'Don Diablo',
views: '396k views',
createdAt: 'a week ago',
},
{
src: 'https://i.ytimg.com/vi/_Uu12zY01ts/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCpX6Jan2rxrCAZxJYDXppTP4MoQA',
title: 'Queen - Greatest Hits',
channel: 'Queen Official',
views: '40M views',
createdAt: '3 years ago',
},
{
src: 'https://i.ytimg.com/vi/kkLk2XWMBf8/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLB4GZTFu1Ju2EPPPXnhMZtFVvYBaw',
title: 'Calvin Harris, Sam Smith - Promises (Official Video)',
channel: 'Calvin Harris',
views: '130M views',
createdAt: '10 months ago',
},
];
function Media(props) {
const { loading = false } = props;
return (
<Grid container wrap="nowrap">
{(loading ? Array.from(new Array(3)) : data).map((item, index) => (
<Box key={index} sx={{ width: 210, marginRight: 0.5, my: 5 }}>
{item ? (
<img
style={{ width: 210, height: 118 }}
alt={item.title}
src={item.src}
/>
) : (
<Skeleton variant="rectangular" width={210} height={118} />
)}
{item ? (
<Box sx={{ pr: 2 }}>
<Typography gutterBottom variant="body2">
{item.title}
</Typography>
<Typography display="block" variant="caption" color="text.secondary">
{item.channel}
</Typography>
<Typography variant="caption" color="text.secondary">
{`${item.views} • ${item.createdAt}`}
</Typography>
</Box>
) : (
<Box sx={{ pt: 0.5 }}>
<Skeleton />
<Skeleton width="60%" />
</Box>
)}
</Box>
))}
</Grid>
);
}
Media.propTypes = {
loading: PropTypes.bool,
};
export default function YouTube() {
return (
<Box sx={{ overflow: 'hidden' }}>
<Media loading />
<Media />
</Box>
);
}
| 2,927 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/YouTube.tsx | import * as React from 'react';
import Grid from '@mui/material/Grid';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Skeleton from '@mui/material/Skeleton';
const data = [
{
src: 'https://i.ytimg.com/vi/pLqipJNItIo/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLBkklsyaw9FxDmMKapyBYCn9tbPNQ',
title: 'Don Diablo @ Tomorrowland Main Stage 2019 | Official…',
channel: 'Don Diablo',
views: '396k views',
createdAt: 'a week ago',
},
{
src: 'https://i.ytimg.com/vi/_Uu12zY01ts/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCpX6Jan2rxrCAZxJYDXppTP4MoQA',
title: 'Queen - Greatest Hits',
channel: 'Queen Official',
views: '40M views',
createdAt: '3 years ago',
},
{
src: 'https://i.ytimg.com/vi/kkLk2XWMBf8/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLB4GZTFu1Ju2EPPPXnhMZtFVvYBaw',
title: 'Calvin Harris, Sam Smith - Promises (Official Video)',
channel: 'Calvin Harris',
views: '130M views',
createdAt: '10 months ago',
},
];
interface MediaProps {
loading?: boolean;
}
function Media(props: MediaProps) {
const { loading = false } = props;
return (
<Grid container wrap="nowrap">
{(loading ? Array.from(new Array(3)) : data).map((item, index) => (
<Box key={index} sx={{ width: 210, marginRight: 0.5, my: 5 }}>
{item ? (
<img
style={{ width: 210, height: 118 }}
alt={item.title}
src={item.src}
/>
) : (
<Skeleton variant="rectangular" width={210} height={118} />
)}
{item ? (
<Box sx={{ pr: 2 }}>
<Typography gutterBottom variant="body2">
{item.title}
</Typography>
<Typography display="block" variant="caption" color="text.secondary">
{item.channel}
</Typography>
<Typography variant="caption" color="text.secondary">
{`${item.views} • ${item.createdAt}`}
</Typography>
</Box>
) : (
<Box sx={{ pt: 0.5 }}>
<Skeleton />
<Skeleton width="60%" />
</Box>
)}
</Box>
))}
</Grid>
);
}
export default function YouTube() {
return (
<Box sx={{ overflow: 'hidden' }}>
<Media loading />
<Media />
</Box>
);
}
| 2,928 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/YouTube.tsx.preview | <Media loading />
<Media /> | 2,929 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/skeleton/skeleton.md | ---
productId: material-ui
title: React Skeleton component
components: Skeleton
githubLabel: 'component: skeleton'
---
# Skeleton
<p class="description">Display a placeholder preview of your content before the data gets loaded to reduce load-time frustration.</p>
The data for your components might not be immediately available. You can improve the perceived responsiveness of the page by using skeletons. It feels like things are happening immediately, then the information is incrementally displayed on the screen (Cf. [Avoid The Spinner](https://www.lukew.com/ff/entry.asp?1797)).
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Usage
The component is designed to be used **directly in your components**.
For instance:
```jsx
{
item ? (
<img
style={{
width: 210,
height: 118,
}}
alt={item.title}
src={item.src}
/>
) : (
<Skeleton variant="rectangular" width={210} height={118} />
);
}
```
## Variants
The component supports 4 shape variants:
- `text` (default): represents a single line of text (you can adjust the height via font size).
- `circular`, `rectangular`, and `rounded`: come with different border radius to let you take control of the size.
{{"demo": "Variants.js"}}
## Animations
By default, the skeleton pulsates, but you can change the animation to a wave or disable it entirely.
{{"demo": "Animations.js"}}
### Pulsate example
{{"demo": "YouTube.js", "defaultCodeOpen": false}}
### Wave example
{{"demo": "Facebook.js", "defaultCodeOpen": false, "bg": true}}
## Inferring dimensions
In addition to accepting `width` and `height` props, the component can also infer the dimensions.
It works well when it comes to typography as its height is set using `em` units.
```jsx
<Typography variant="h1">{loading ? <Skeleton /> : 'h1'}</Typography>
```
{{"demo": "SkeletonTypography.js", "defaultCodeOpen": false}}
But when it comes to other components, you may not want to repeat the width and
height. In these instances, you can pass `children` and it will
infer its width and height from them.
```jsx
loading ? (
<Skeleton variant="circular">
<Avatar />
</Skeleton>
) : (
<Avatar src={data.avatar} />
);
```
{{"demo": "SkeletonChildren.js", "defaultCodeOpen": false}}
## Color
The color of the component can be customized by changing its `background-color` CSS property.
This is especially useful when on a black background (as the skeleton will otherwise be invisible).
{{"demo": "SkeletonColor.js", "bg": "inline"}}
## Accessibility
Skeleton screens provide an alternative to the traditional spinner method.
Rather than showing an abstract widget, skeleton screens create anticipation of what is to come and reduce cognitive load.
The background color of the skeleton uses the least amount of luminance to be visible in good conditions (good ambient light, good screen, no visual impairments).
### ARIA
None.
### Keyboard
The skeleton is not focusable.
| 2,930 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ColorSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
export default function ColorSlider() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
color="secondary"
/>
</Box>
);
}
| 2,931 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ColorSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
export default function ColorSlider() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
color="secondary"
/>
</Box>
);
}
| 2,932 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ColorSlider.tsx.preview | <Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
color="secondary"
/> | 2,933 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ContinuousSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
import VolumeDown from '@mui/icons-material/VolumeDown';
import VolumeUp from '@mui/icons-material/VolumeUp';
export default function ContinuousSlider() {
const [value, setValue] = React.useState(30);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: 200 }}>
<Stack spacing={2} direction="row" sx={{ mb: 1 }} alignItems="center">
<VolumeDown />
<Slider aria-label="Volume" value={value} onChange={handleChange} />
<VolumeUp />
</Stack>
<Slider disabled defaultValue={30} aria-label="Disabled slider" />
</Box>
);
}
| 2,934 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ContinuousSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
import VolumeDown from '@mui/icons-material/VolumeDown';
import VolumeUp from '@mui/icons-material/VolumeUp';
export default function ContinuousSlider() {
const [value, setValue] = React.useState<number>(30);
const handleChange = (event: Event, newValue: number | number[]) => {
setValue(newValue as number);
};
return (
<Box sx={{ width: 200 }}>
<Stack spacing={2} direction="row" sx={{ mb: 1 }} alignItems="center">
<VolumeDown />
<Slider aria-label="Volume" value={value} onChange={handleChange} />
<VolumeUp />
</Stack>
<Slider disabled defaultValue={30} aria-label="Disabled slider" />
</Box>
);
}
| 2,935 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/ContinuousSlider.tsx.preview | <Stack spacing={2} direction="row" sx={{ mb: 1 }} alignItems="center">
<VolumeDown />
<Slider aria-label="Volume" value={value} onChange={handleChange} />
<VolumeUp />
</Stack>
<Slider disabled defaultValue={30} aria-label="Disabled slider" /> | 2,936 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/CustomizedSlider.js | import * as React from 'react';
import PropTypes from 'prop-types';
import Slider, { SliderThumb } from '@mui/material/Slider';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Tooltip from '@mui/material/Tooltip';
import Box from '@mui/material/Box';
function ValueLabelComponent(props) {
const { children, value } = props;
return (
<Tooltip enterTouchDelay={0} placement="top" title={value}>
{children}
</Tooltip>
);
}
ValueLabelComponent.propTypes = {
children: PropTypes.element.isRequired,
value: PropTypes.number.isRequired,
};
const iOSBoxShadow =
'0 3px 1px rgba(0,0,0,0.1),0 4px 8px rgba(0,0,0,0.13),0 0 0 1px rgba(0,0,0,0.02)';
const marks = [
{
value: 0,
},
{
value: 20,
},
{
value: 37,
},
{
value: 100,
},
];
const IOSSlider = styled(Slider)(({ theme }) => ({
color: theme.palette.mode === 'dark' ? '#3880ff' : '#3880ff',
height: 2,
padding: '15px 0',
'& .MuiSlider-thumb': {
height: 28,
width: 28,
backgroundColor: '#fff',
boxShadow: iOSBoxShadow,
'&:focus, &:hover, &.Mui-active': {
boxShadow:
'0 3px 1px rgba(0,0,0,0.1),0 4px 8px rgba(0,0,0,0.3),0 0 0 1px rgba(0,0,0,0.02)',
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
boxShadow: iOSBoxShadow,
},
},
},
'& .MuiSlider-valueLabel': {
fontSize: 12,
fontWeight: 'normal',
top: -6,
backgroundColor: 'unset',
color: theme.palette.text.primary,
'&:before': {
display: 'none',
},
'& *': {
background: 'transparent',
color: theme.palette.mode === 'dark' ? '#fff' : '#000',
},
},
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-rail': {
opacity: 0.5,
backgroundColor: '#bfbfbf',
},
'& .MuiSlider-mark': {
backgroundColor: '#bfbfbf',
height: 8,
width: 1,
'&.MuiSlider-markActive': {
opacity: 1,
backgroundColor: 'currentColor',
},
},
}));
const PrettoSlider = styled(Slider)({
color: '#52af77',
height: 8,
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-thumb': {
height: 24,
width: 24,
backgroundColor: '#fff',
border: '2px solid currentColor',
'&:focus, &:hover, &.Mui-active, &.Mui-focusVisible': {
boxShadow: 'inherit',
},
'&:before': {
display: 'none',
},
},
'& .MuiSlider-valueLabel': {
lineHeight: 1.2,
fontSize: 12,
background: 'unset',
padding: 0,
width: 32,
height: 32,
borderRadius: '50% 50% 50% 0',
backgroundColor: '#52af77',
transformOrigin: 'bottom left',
transform: 'translate(50%, -100%) rotate(-45deg) scale(0)',
'&:before': { display: 'none' },
'&.MuiSlider-valueLabelOpen': {
transform: 'translate(50%, -100%) rotate(-45deg) scale(1)',
},
'& > *': {
transform: 'rotate(45deg)',
},
},
});
const AirbnbSlider = styled(Slider)(({ theme }) => ({
color: '#3a8589',
height: 3,
padding: '13px 0',
'& .MuiSlider-thumb': {
height: 27,
width: 27,
backgroundColor: '#fff',
border: '1px solid currentColor',
'&:hover': {
boxShadow: '0 0 0 8px rgba(58, 133, 137, 0.16)',
},
'& .airbnb-bar': {
height: 9,
width: 1,
backgroundColor: 'currentColor',
marginLeft: 1,
marginRight: 1,
},
},
'& .MuiSlider-track': {
height: 3,
},
'& .MuiSlider-rail': {
color: theme.palette.mode === 'dark' ? '#bfbfbf' : '#d8d8d8',
opacity: theme.palette.mode === 'dark' ? undefined : 1,
height: 3,
},
}));
function AirbnbThumbComponent(props) {
const { children, ...other } = props;
return (
<SliderThumb {...other}>
{children}
<span className="airbnb-bar" />
<span className="airbnb-bar" />
<span className="airbnb-bar" />
</SliderThumb>
);
}
AirbnbThumbComponent.propTypes = {
children: PropTypes.node,
};
export default function CustomizedSlider() {
return (
<Box sx={{ width: 320 }}>
<Typography gutterBottom>iOS</Typography>
<IOSSlider
aria-label="ios slider"
defaultValue={60}
marks={marks}
valueLabelDisplay="on"
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>pretto.fr</Typography>
<PrettoSlider
valueLabelDisplay="auto"
aria-label="pretto slider"
defaultValue={20}
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>Tooltip value label</Typography>
<Slider
valueLabelDisplay="auto"
slots={{
valueLabel: ValueLabelComponent,
}}
aria-label="custom thumb label"
defaultValue={20}
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>Airbnb</Typography>
<AirbnbSlider
slots={{ thumb: AirbnbThumbComponent }}
getAriaLabel={(index) => (index === 0 ? 'Minimum price' : 'Maximum price')}
defaultValue={[20, 40]}
/>
</Box>
);
}
| 2,937 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/CustomizedSlider.tsx | import * as React from 'react';
import Slider, { SliderThumb, SliderValueLabelProps } from '@mui/material/Slider';
import { styled } from '@mui/material/styles';
import Typography from '@mui/material/Typography';
import Tooltip from '@mui/material/Tooltip';
import Box from '@mui/material/Box';
function ValueLabelComponent(props: SliderValueLabelProps) {
const { children, value } = props;
return (
<Tooltip enterTouchDelay={0} placement="top" title={value}>
{children}
</Tooltip>
);
}
const iOSBoxShadow =
'0 3px 1px rgba(0,0,0,0.1),0 4px 8px rgba(0,0,0,0.13),0 0 0 1px rgba(0,0,0,0.02)';
const marks = [
{
value: 0,
},
{
value: 20,
},
{
value: 37,
},
{
value: 100,
},
];
const IOSSlider = styled(Slider)(({ theme }) => ({
color: theme.palette.mode === 'dark' ? '#3880ff' : '#3880ff',
height: 2,
padding: '15px 0',
'& .MuiSlider-thumb': {
height: 28,
width: 28,
backgroundColor: '#fff',
boxShadow: iOSBoxShadow,
'&:focus, &:hover, &.Mui-active': {
boxShadow:
'0 3px 1px rgba(0,0,0,0.1),0 4px 8px rgba(0,0,0,0.3),0 0 0 1px rgba(0,0,0,0.02)',
// Reset on touch devices, it doesn't add specificity
'@media (hover: none)': {
boxShadow: iOSBoxShadow,
},
},
},
'& .MuiSlider-valueLabel': {
fontSize: 12,
fontWeight: 'normal',
top: -6,
backgroundColor: 'unset',
color: theme.palette.text.primary,
'&:before': {
display: 'none',
},
'& *': {
background: 'transparent',
color: theme.palette.mode === 'dark' ? '#fff' : '#000',
},
},
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-rail': {
opacity: 0.5,
backgroundColor: '#bfbfbf',
},
'& .MuiSlider-mark': {
backgroundColor: '#bfbfbf',
height: 8,
width: 1,
'&.MuiSlider-markActive': {
opacity: 1,
backgroundColor: 'currentColor',
},
},
}));
const PrettoSlider = styled(Slider)({
color: '#52af77',
height: 8,
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-thumb': {
height: 24,
width: 24,
backgroundColor: '#fff',
border: '2px solid currentColor',
'&:focus, &:hover, &.Mui-active, &.Mui-focusVisible': {
boxShadow: 'inherit',
},
'&:before': {
display: 'none',
},
},
'& .MuiSlider-valueLabel': {
lineHeight: 1.2,
fontSize: 12,
background: 'unset',
padding: 0,
width: 32,
height: 32,
borderRadius: '50% 50% 50% 0',
backgroundColor: '#52af77',
transformOrigin: 'bottom left',
transform: 'translate(50%, -100%) rotate(-45deg) scale(0)',
'&:before': { display: 'none' },
'&.MuiSlider-valueLabelOpen': {
transform: 'translate(50%, -100%) rotate(-45deg) scale(1)',
},
'& > *': {
transform: 'rotate(45deg)',
},
},
});
const AirbnbSlider = styled(Slider)(({ theme }) => ({
color: '#3a8589',
height: 3,
padding: '13px 0',
'& .MuiSlider-thumb': {
height: 27,
width: 27,
backgroundColor: '#fff',
border: '1px solid currentColor',
'&:hover': {
boxShadow: '0 0 0 8px rgba(58, 133, 137, 0.16)',
},
'& .airbnb-bar': {
height: 9,
width: 1,
backgroundColor: 'currentColor',
marginLeft: 1,
marginRight: 1,
},
},
'& .MuiSlider-track': {
height: 3,
},
'& .MuiSlider-rail': {
color: theme.palette.mode === 'dark' ? '#bfbfbf' : '#d8d8d8',
opacity: theme.palette.mode === 'dark' ? undefined : 1,
height: 3,
},
}));
interface AirbnbThumbComponentProps extends React.HTMLAttributes<unknown> {}
function AirbnbThumbComponent(props: AirbnbThumbComponentProps) {
const { children, ...other } = props;
return (
<SliderThumb {...other}>
{children}
<span className="airbnb-bar" />
<span className="airbnb-bar" />
<span className="airbnb-bar" />
</SliderThumb>
);
}
export default function CustomizedSlider() {
return (
<Box sx={{ width: 320 }}>
<Typography gutterBottom>iOS</Typography>
<IOSSlider
aria-label="ios slider"
defaultValue={60}
marks={marks}
valueLabelDisplay="on"
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>pretto.fr</Typography>
<PrettoSlider
valueLabelDisplay="auto"
aria-label="pretto slider"
defaultValue={20}
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>Tooltip value label</Typography>
<Slider
valueLabelDisplay="auto"
slots={{
valueLabel: ValueLabelComponent,
}}
aria-label="custom thumb label"
defaultValue={20}
/>
<Box sx={{ m: 3 }} />
<Typography gutterBottom>Airbnb</Typography>
<AirbnbSlider
slots={{ thumb: AirbnbThumbComponent }}
getAriaLabel={(index) => (index === 0 ? 'Minimum price' : 'Maximum price')}
defaultValue={[20, 40]}
/>
</Box>
);
}
| 2,938 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
export default function DiscreteSlider() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
<Slider defaultValue={30} step={10} marks min={10} max={110} disabled />
</Box>
);
}
| 2,939 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
export default function DiscreteSlider() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
<Slider defaultValue={30} step={10} marks min={10} max={110} disabled />
</Box>
);
}
| 2,940 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSlider.tsx.preview | <Slider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
<Slider defaultValue={30} step={10} marks min={10} max={110} disabled /> | 2,941 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderLabel.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value) {
return `${value}°C`;
}
export default function DiscreteSliderLabel() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Always visible"
defaultValue={80}
getAriaValueText={valuetext}
step={10}
marks={marks}
valueLabelDisplay="on"
/>
</Box>
);
}
| 2,942 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderLabel.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value: number) {
return `${value}°C`;
}
export default function DiscreteSliderLabel() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Always visible"
defaultValue={80}
getAriaValueText={valuetext}
step={10}
marks={marks}
valueLabelDisplay="on"
/>
</Box>
);
}
| 2,943 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderLabel.tsx.preview | <Slider
aria-label="Always visible"
defaultValue={80}
getAriaValueText={valuetext}
step={10}
marks={marks}
valueLabelDisplay="on"
/> | 2,944 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderMarks.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value) {
return `${value}°C`;
}
export default function DiscreteSliderMarks() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Custom marks"
defaultValue={20}
getAriaValueText={valuetext}
step={10}
valueLabelDisplay="auto"
marks={marks}
/>
</Box>
);
}
| 2,945 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderMarks.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value: number) {
return `${value}°C`;
}
export default function DiscreteSliderMarks() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Custom marks"
defaultValue={20}
getAriaValueText={valuetext}
step={10}
valueLabelDisplay="auto"
marks={marks}
/>
</Box>
);
}
| 2,946 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderMarks.tsx.preview | <Slider
aria-label="Custom marks"
defaultValue={20}
getAriaValueText={valuetext}
step={10}
valueLabelDisplay="auto"
marks={marks}
/> | 2,947 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderSteps.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
export default function DiscreteSliderSteps() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Small steps"
defaultValue={0.00000005}
getAriaValueText={valuetext}
step={0.00000001}
marks
min={-0.00000005}
max={0.0000001}
valueLabelDisplay="auto"
/>
</Box>
);
}
| 2,948 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderSteps.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
export default function DiscreteSliderSteps() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Small steps"
defaultValue={0.00000005}
getAriaValueText={valuetext}
step={0.00000001}
marks
min={-0.00000005}
max={0.0000001}
valueLabelDisplay="auto"
/>
</Box>
);
}
| 2,949 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderSteps.tsx.preview | <Slider
aria-label="Small steps"
defaultValue={0.00000005}
getAriaValueText={valuetext}
step={0.00000001}
marks
min={-0.00000005}
max={0.0000001}
valueLabelDisplay="auto"
/> | 2,950 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderValues.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value) {
return `${value}°C`;
}
function valueLabelFormat(value) {
return marks.findIndex((mark) => mark.value === value) + 1;
}
export default function DiscreteSliderValues() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Restricted values"
defaultValue={20}
valueLabelFormat={valueLabelFormat}
getAriaValueText={valuetext}
step={null}
valueLabelDisplay="auto"
marks={marks}
/>
</Box>
);
}
| 2,951 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderValues.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value: number) {
return `${value}°C`;
}
function valueLabelFormat(value: number) {
return marks.findIndex((mark) => mark.value === value) + 1;
}
export default function DiscreteSliderValues() {
return (
<Box sx={{ width: 300 }}>
<Slider
aria-label="Restricted values"
defaultValue={20}
valueLabelFormat={valueLabelFormat}
getAriaValueText={valuetext}
step={null}
valueLabelDisplay="auto"
marks={marks}
/>
</Box>
);
}
| 2,952 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/DiscreteSliderValues.tsx.preview | <Slider
aria-label="Restricted values"
defaultValue={20}
valueLabelFormat={valueLabelFormat}
getAriaValueText={valuetext}
step={null}
valueLabelDisplay="auto"
marks={marks}
/> | 2,953 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/InputSlider.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
import MuiInput from '@mui/material/Input';
import VolumeUp from '@mui/icons-material/VolumeUp';
const Input = styled(MuiInput)`
width: 42px;
`;
export default function InputSlider() {
const [value, setValue] = React.useState(30);
const handleSliderChange = (event, newValue) => {
setValue(newValue);
};
const handleInputChange = (event) => {
setValue(event.target.value === '' ? 0 : Number(event.target.value));
};
const handleBlur = () => {
if (value < 0) {
setValue(0);
} else if (value > 100) {
setValue(100);
}
};
return (
<Box sx={{ width: 250 }}>
<Typography id="input-slider" gutterBottom>
Volume
</Typography>
<Grid container spacing={2} alignItems="center">
<Grid item>
<VolumeUp />
</Grid>
<Grid item xs>
<Slider
value={typeof value === 'number' ? value : 0}
onChange={handleSliderChange}
aria-labelledby="input-slider"
/>
</Grid>
<Grid item>
<Input
value={value}
size="small"
onChange={handleInputChange}
onBlur={handleBlur}
inputProps={{
step: 10,
min: 0,
max: 100,
type: 'number',
'aria-labelledby': 'input-slider',
}}
/>
</Grid>
</Grid>
</Box>
);
}
| 2,954 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/InputSlider.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
import MuiInput from '@mui/material/Input';
import VolumeUp from '@mui/icons-material/VolumeUp';
const Input = styled(MuiInput)`
width: 42px;
`;
export default function InputSlider() {
const [value, setValue] = React.useState(30);
const handleSliderChange = (event: Event, newValue: number | number[]) => {
setValue(newValue as number);
};
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setValue(event.target.value === '' ? 0 : Number(event.target.value));
};
const handleBlur = () => {
if (value < 0) {
setValue(0);
} else if (value > 100) {
setValue(100);
}
};
return (
<Box sx={{ width: 250 }}>
<Typography id="input-slider" gutterBottom>
Volume
</Typography>
<Grid container spacing={2} alignItems="center">
<Grid item>
<VolumeUp />
</Grid>
<Grid item xs>
<Slider
value={typeof value === 'number' ? value : 0}
onChange={handleSliderChange}
aria-labelledby="input-slider"
/>
</Grid>
<Grid item>
<Input
value={value}
size="small"
onChange={handleInputChange}
onBlur={handleBlur}
inputProps={{
step: 10,
min: 0,
max: 100,
type: 'number',
'aria-labelledby': 'input-slider',
}}
/>
</Grid>
</Grid>
</Box>
);
}
| 2,955 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/MinimumDistanceSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
const minDistance = 10;
export default function MinimumDistanceSlider() {
const [value1, setValue1] = React.useState([20, 37]);
const handleChange1 = (event, newValue, activeThumb) => {
if (!Array.isArray(newValue)) {
return;
}
if (activeThumb === 0) {
setValue1([Math.min(newValue[0], value1[1] - minDistance), value1[1]]);
} else {
setValue1([value1[0], Math.max(newValue[1], value1[0] + minDistance)]);
}
};
const [value2, setValue2] = React.useState([20, 37]);
const handleChange2 = (event, newValue, activeThumb) => {
if (!Array.isArray(newValue)) {
return;
}
if (newValue[1] - newValue[0] < minDistance) {
if (activeThumb === 0) {
const clamped = Math.min(newValue[0], 100 - minDistance);
setValue2([clamped, clamped + minDistance]);
} else {
const clamped = Math.max(newValue[1], minDistance);
setValue2([clamped - minDistance, clamped]);
}
} else {
setValue2(newValue);
}
};
return (
<Box sx={{ width: 300 }}>
<Slider
getAriaLabel={() => 'Minimum distance'}
value={value1}
onChange={handleChange1}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/>
<Slider
getAriaLabel={() => 'Minimum distance shift'}
value={value2}
onChange={handleChange2}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/>
</Box>
);
}
| 2,956 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/MinimumDistanceSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
const minDistance = 10;
export default function MinimumDistanceSlider() {
const [value1, setValue1] = React.useState<number[]>([20, 37]);
const handleChange1 = (
event: Event,
newValue: number | number[],
activeThumb: number,
) => {
if (!Array.isArray(newValue)) {
return;
}
if (activeThumb === 0) {
setValue1([Math.min(newValue[0], value1[1] - minDistance), value1[1]]);
} else {
setValue1([value1[0], Math.max(newValue[1], value1[0] + minDistance)]);
}
};
const [value2, setValue2] = React.useState<number[]>([20, 37]);
const handleChange2 = (
event: Event,
newValue: number | number[],
activeThumb: number,
) => {
if (!Array.isArray(newValue)) {
return;
}
if (newValue[1] - newValue[0] < minDistance) {
if (activeThumb === 0) {
const clamped = Math.min(newValue[0], 100 - minDistance);
setValue2([clamped, clamped + minDistance]);
} else {
const clamped = Math.max(newValue[1], minDistance);
setValue2([clamped - minDistance, clamped]);
}
} else {
setValue2(newValue as number[]);
}
};
return (
<Box sx={{ width: 300 }}>
<Slider
getAriaLabel={() => 'Minimum distance'}
value={value1}
onChange={handleChange1}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/>
<Slider
getAriaLabel={() => 'Minimum distance shift'}
value={value2}
onChange={handleChange2}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/>
</Box>
);
}
| 2,957 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/MinimumDistanceSlider.tsx.preview | <Slider
getAriaLabel={() => 'Minimum distance'}
value={value1}
onChange={handleChange1}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/>
<Slider
getAriaLabel={() => 'Minimum distance shift'}
value={value2}
onChange={handleChange2}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
disableSwap
/> | 2,958 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/MusicPlayerSlider.js | import * as React from 'react';
import { styled, useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
import IconButton from '@mui/material/IconButton';
import Stack from '@mui/material/Stack';
import PauseRounded from '@mui/icons-material/PauseRounded';
import PlayArrowRounded from '@mui/icons-material/PlayArrowRounded';
import FastForwardRounded from '@mui/icons-material/FastForwardRounded';
import FastRewindRounded from '@mui/icons-material/FastRewindRounded';
import VolumeUpRounded from '@mui/icons-material/VolumeUpRounded';
import VolumeDownRounded from '@mui/icons-material/VolumeDownRounded';
const WallPaper = styled('div')({
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
left: 0,
overflow: 'hidden',
background: 'linear-gradient(rgb(255, 38, 142) 0%, rgb(255, 105, 79) 100%)',
transition: 'all 500ms cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s',
'&:before': {
content: '""',
width: '140%',
height: '140%',
position: 'absolute',
top: '-40%',
right: '-50%',
background:
'radial-gradient(at center center, rgb(62, 79, 249) 0%, rgba(62, 79, 249, 0) 64%)',
},
'&:after': {
content: '""',
width: '140%',
height: '140%',
position: 'absolute',
bottom: '-50%',
left: '-30%',
background:
'radial-gradient(at center center, rgb(247, 237, 225) 0%, rgba(247, 237, 225, 0) 70%)',
transform: 'rotate(30deg)',
},
});
const Widget = styled('div')(({ theme }) => ({
padding: 16,
borderRadius: 16,
width: 343,
maxWidth: '100%',
margin: 'auto',
position: 'relative',
zIndex: 1,
backgroundColor:
theme.palette.mode === 'dark' ? 'rgba(0,0,0,0.6)' : 'rgba(255,255,255,0.4)',
backdropFilter: 'blur(40px)',
}));
const CoverImage = styled('div')({
width: 100,
height: 100,
objectFit: 'cover',
overflow: 'hidden',
flexShrink: 0,
borderRadius: 8,
backgroundColor: 'rgba(0,0,0,0.08)',
'& > img': {
width: '100%',
},
});
const TinyText = styled(Typography)({
fontSize: '0.75rem',
opacity: 0.38,
fontWeight: 500,
letterSpacing: 0.2,
});
export default function MusicPlayerSlider() {
const theme = useTheme();
const duration = 200; // seconds
const [position, setPosition] = React.useState(32);
const [paused, setPaused] = React.useState(false);
function formatDuration(value) {
const minute = Math.floor(value / 60);
const secondLeft = value - minute * 60;
return `${minute}:${secondLeft < 10 ? `0${secondLeft}` : secondLeft}`;
}
const mainIconColor = theme.palette.mode === 'dark' ? '#fff' : '#000';
const lightIconColor =
theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.4)' : 'rgba(0,0,0,0.4)';
return (
<Box sx={{ width: '100%', overflow: 'hidden' }}>
<Widget>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<CoverImage>
<img
alt="can't win - Chilling Sunday"
src="/static/images/sliders/chilling-sunday.jpg"
/>
</CoverImage>
<Box sx={{ ml: 1.5, minWidth: 0 }}>
<Typography variant="caption" color="text.secondary" fontWeight={500}>
Jun Pulse
</Typography>
<Typography noWrap>
<b>คนเก่าเขาทำไว้ดี (Can't win)</b>
</Typography>
<Typography noWrap letterSpacing={-0.25}>
Chilling Sunday — คนเก่าเขาทำไว้ดี
</Typography>
</Box>
</Box>
<Slider
aria-label="time-indicator"
size="small"
value={position}
min={0}
step={1}
max={duration}
onChange={(_, value) => setPosition(value)}
sx={{
color: theme.palette.mode === 'dark' ? '#fff' : 'rgba(0,0,0,0.87)',
height: 4,
'& .MuiSlider-thumb': {
width: 8,
height: 8,
transition: '0.3s cubic-bezier(.47,1.64,.41,.8)',
'&:before': {
boxShadow: '0 2px 12px 0 rgba(0,0,0,0.4)',
},
'&:hover, &.Mui-focusVisible': {
boxShadow: `0px 0px 0px 8px ${
theme.palette.mode === 'dark'
? 'rgb(255 255 255 / 16%)'
: 'rgb(0 0 0 / 16%)'
}`,
},
'&.Mui-active': {
width: 20,
height: 20,
},
},
'& .MuiSlider-rail': {
opacity: 0.28,
},
}}
/>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
mt: -2,
}}
>
<TinyText>{formatDuration(position)}</TinyText>
<TinyText>-{formatDuration(duration - position)}</TinyText>
</Box>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
mt: -1,
}}
>
<IconButton aria-label="previous song">
<FastRewindRounded fontSize="large" htmlColor={mainIconColor} />
</IconButton>
<IconButton
aria-label={paused ? 'play' : 'pause'}
onClick={() => setPaused(!paused)}
>
{paused ? (
<PlayArrowRounded
sx={{ fontSize: '3rem' }}
htmlColor={mainIconColor}
/>
) : (
<PauseRounded sx={{ fontSize: '3rem' }} htmlColor={mainIconColor} />
)}
</IconButton>
<IconButton aria-label="next song">
<FastForwardRounded fontSize="large" htmlColor={mainIconColor} />
</IconButton>
</Box>
<Stack spacing={2} direction="row" sx={{ mb: 1, px: 1 }} alignItems="center">
<VolumeDownRounded htmlColor={lightIconColor} />
<Slider
aria-label="Volume"
defaultValue={30}
sx={{
color: theme.palette.mode === 'dark' ? '#fff' : 'rgba(0,0,0,0.87)',
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-thumb': {
width: 24,
height: 24,
backgroundColor: '#fff',
'&:before': {
boxShadow: '0 4px 8px rgba(0,0,0,0.4)',
},
'&:hover, &.Mui-focusVisible, &.Mui-active': {
boxShadow: 'none',
},
},
}}
/>
<VolumeUpRounded htmlColor={lightIconColor} />
</Stack>
</Widget>
<WallPaper />
</Box>
);
}
| 2,959 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/MusicPlayerSlider.tsx | import * as React from 'react';
import { styled, useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
import IconButton from '@mui/material/IconButton';
import Stack from '@mui/material/Stack';
import PauseRounded from '@mui/icons-material/PauseRounded';
import PlayArrowRounded from '@mui/icons-material/PlayArrowRounded';
import FastForwardRounded from '@mui/icons-material/FastForwardRounded';
import FastRewindRounded from '@mui/icons-material/FastRewindRounded';
import VolumeUpRounded from '@mui/icons-material/VolumeUpRounded';
import VolumeDownRounded from '@mui/icons-material/VolumeDownRounded';
const WallPaper = styled('div')({
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
left: 0,
overflow: 'hidden',
background: 'linear-gradient(rgb(255, 38, 142) 0%, rgb(255, 105, 79) 100%)',
transition: 'all 500ms cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s',
'&:before': {
content: '""',
width: '140%',
height: '140%',
position: 'absolute',
top: '-40%',
right: '-50%',
background:
'radial-gradient(at center center, rgb(62, 79, 249) 0%, rgba(62, 79, 249, 0) 64%)',
},
'&:after': {
content: '""',
width: '140%',
height: '140%',
position: 'absolute',
bottom: '-50%',
left: '-30%',
background:
'radial-gradient(at center center, rgb(247, 237, 225) 0%, rgba(247, 237, 225, 0) 70%)',
transform: 'rotate(30deg)',
},
});
const Widget = styled('div')(({ theme }) => ({
padding: 16,
borderRadius: 16,
width: 343,
maxWidth: '100%',
margin: 'auto',
position: 'relative',
zIndex: 1,
backgroundColor:
theme.palette.mode === 'dark' ? 'rgba(0,0,0,0.6)' : 'rgba(255,255,255,0.4)',
backdropFilter: 'blur(40px)',
}));
const CoverImage = styled('div')({
width: 100,
height: 100,
objectFit: 'cover',
overflow: 'hidden',
flexShrink: 0,
borderRadius: 8,
backgroundColor: 'rgba(0,0,0,0.08)',
'& > img': {
width: '100%',
},
});
const TinyText = styled(Typography)({
fontSize: '0.75rem',
opacity: 0.38,
fontWeight: 500,
letterSpacing: 0.2,
});
export default function MusicPlayerSlider() {
const theme = useTheme();
const duration = 200; // seconds
const [position, setPosition] = React.useState(32);
const [paused, setPaused] = React.useState(false);
function formatDuration(value: number) {
const minute = Math.floor(value / 60);
const secondLeft = value - minute * 60;
return `${minute}:${secondLeft < 10 ? `0${secondLeft}` : secondLeft}`;
}
const mainIconColor = theme.palette.mode === 'dark' ? '#fff' : '#000';
const lightIconColor =
theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.4)' : 'rgba(0,0,0,0.4)';
return (
<Box sx={{ width: '100%', overflow: 'hidden' }}>
<Widget>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<CoverImage>
<img
alt="can't win - Chilling Sunday"
src="/static/images/sliders/chilling-sunday.jpg"
/>
</CoverImage>
<Box sx={{ ml: 1.5, minWidth: 0 }}>
<Typography variant="caption" color="text.secondary" fontWeight={500}>
Jun Pulse
</Typography>
<Typography noWrap>
<b>คนเก่าเขาทำไว้ดี (Can't win)</b>
</Typography>
<Typography noWrap letterSpacing={-0.25}>
Chilling Sunday — คนเก่าเขาทำไว้ดี
</Typography>
</Box>
</Box>
<Slider
aria-label="time-indicator"
size="small"
value={position}
min={0}
step={1}
max={duration}
onChange={(_, value) => setPosition(value as number)}
sx={{
color: theme.palette.mode === 'dark' ? '#fff' : 'rgba(0,0,0,0.87)',
height: 4,
'& .MuiSlider-thumb': {
width: 8,
height: 8,
transition: '0.3s cubic-bezier(.47,1.64,.41,.8)',
'&:before': {
boxShadow: '0 2px 12px 0 rgba(0,0,0,0.4)',
},
'&:hover, &.Mui-focusVisible': {
boxShadow: `0px 0px 0px 8px ${
theme.palette.mode === 'dark'
? 'rgb(255 255 255 / 16%)'
: 'rgb(0 0 0 / 16%)'
}`,
},
'&.Mui-active': {
width: 20,
height: 20,
},
},
'& .MuiSlider-rail': {
opacity: 0.28,
},
}}
/>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
mt: -2,
}}
>
<TinyText>{formatDuration(position)}</TinyText>
<TinyText>-{formatDuration(duration - position)}</TinyText>
</Box>
<Box
sx={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
mt: -1,
}}
>
<IconButton aria-label="previous song">
<FastRewindRounded fontSize="large" htmlColor={mainIconColor} />
</IconButton>
<IconButton
aria-label={paused ? 'play' : 'pause'}
onClick={() => setPaused(!paused)}
>
{paused ? (
<PlayArrowRounded
sx={{ fontSize: '3rem' }}
htmlColor={mainIconColor}
/>
) : (
<PauseRounded sx={{ fontSize: '3rem' }} htmlColor={mainIconColor} />
)}
</IconButton>
<IconButton aria-label="next song">
<FastForwardRounded fontSize="large" htmlColor={mainIconColor} />
</IconButton>
</Box>
<Stack spacing={2} direction="row" sx={{ mb: 1, px: 1 }} alignItems="center">
<VolumeDownRounded htmlColor={lightIconColor} />
<Slider
aria-label="Volume"
defaultValue={30}
sx={{
color: theme.palette.mode === 'dark' ? '#fff' : 'rgba(0,0,0,0.87)',
'& .MuiSlider-track': {
border: 'none',
},
'& .MuiSlider-thumb': {
width: 24,
height: 24,
backgroundColor: '#fff',
'&:before': {
boxShadow: '0 4px 8px rgba(0,0,0,0.4)',
},
'&:hover, &.Mui-focusVisible, &.Mui-active': {
boxShadow: 'none',
},
},
}}
/>
<VolumeUpRounded htmlColor={lightIconColor} />
</Stack>
</Widget>
<WallPaper />
</Box>
);
}
| 2,960 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/NonLinearSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
function valueLabelFormat(value) {
const units = ['KB', 'MB', 'GB', 'TB'];
let unitIndex = 0;
let scaledValue = value;
while (scaledValue >= 1024 && unitIndex < units.length - 1) {
unitIndex += 1;
scaledValue /= 1024;
}
return `${scaledValue} ${units[unitIndex]}`;
}
function calculateValue(value) {
return 2 ** value;
}
export default function NonLinearSlider() {
const [value, setValue] = React.useState(10);
const handleChange = (event, newValue) => {
if (typeof newValue === 'number') {
setValue(newValue);
}
};
return (
<Box sx={{ width: 250 }}>
<Typography id="non-linear-slider" gutterBottom>
Storage: {valueLabelFormat(calculateValue(value))}
</Typography>
<Slider
value={value}
min={5}
step={1}
max={30}
scale={calculateValue}
getAriaValueText={valueLabelFormat}
valueLabelFormat={valueLabelFormat}
onChange={handleChange}
valueLabelDisplay="auto"
aria-labelledby="non-linear-slider"
/>
</Box>
);
}
| 2,961 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/NonLinearSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
function valueLabelFormat(value: number) {
const units = ['KB', 'MB', 'GB', 'TB'];
let unitIndex = 0;
let scaledValue = value;
while (scaledValue >= 1024 && unitIndex < units.length - 1) {
unitIndex += 1;
scaledValue /= 1024;
}
return `${scaledValue} ${units[unitIndex]}`;
}
function calculateValue(value: number) {
return 2 ** value;
}
export default function NonLinearSlider() {
const [value, setValue] = React.useState<number>(10);
const handleChange = (event: Event, newValue: number | number[]) => {
if (typeof newValue === 'number') {
setValue(newValue);
}
};
return (
<Box sx={{ width: 250 }}>
<Typography id="non-linear-slider" gutterBottom>
Storage: {valueLabelFormat(calculateValue(value))}
</Typography>
<Slider
value={value}
min={5}
step={1}
max={30}
scale={calculateValue}
getAriaValueText={valueLabelFormat}
valueLabelFormat={valueLabelFormat}
onChange={handleChange}
valueLabelDisplay="auto"
aria-labelledby="non-linear-slider"
/>
</Box>
);
}
| 2,962 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/NonLinearSlider.tsx.preview | <Typography id="non-linear-slider" gutterBottom>
Storage: {valueLabelFormat(calculateValue(value))}
</Typography>
<Slider
value={value}
min={5}
step={1}
max={30}
scale={calculateValue}
getAriaValueText={valueLabelFormat}
valueLabelFormat={valueLabelFormat}
onChange={handleChange}
valueLabelDisplay="auto"
aria-labelledby="non-linear-slider"
/> | 2,963 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/RangeSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
export default function RangeSlider() {
const [value, setValue] = React.useState([20, 37]);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<Box sx={{ width: 300 }}>
<Slider
getAriaLabel={() => 'Temperature range'}
value={value}
onChange={handleChange}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
/>
</Box>
);
}
| 2,964 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/RangeSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
export default function RangeSlider() {
const [value, setValue] = React.useState<number[]>([20, 37]);
const handleChange = (event: Event, newValue: number | number[]) => {
setValue(newValue as number[]);
};
return (
<Box sx={{ width: 300 }}>
<Slider
getAriaLabel={() => 'Temperature range'}
value={value}
onChange={handleChange}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
/>
</Box>
);
}
| 2,965 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/RangeSlider.tsx.preview | <Slider
getAriaLabel={() => 'Temperature range'}
value={value}
onChange={handleChange}
valueLabelDisplay="auto"
getAriaValueText={valuetext}
/> | 2,966 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/SliderMaterialYouPlayground.js | import * as React from 'react';
import Slider from '@mui/material-next/Slider';
import Box from '@mui/material/Box';
import MaterialYouUsageDemo from 'docs/src/modules/components/MaterialYouUsageDemo';
export default function SliderMaterialYouPlayground() {
return (
<MaterialYouUsageDemo
componentName="Slider"
data={[
{
propName: 'min',
defaultValue: 0,
},
{
propName: 'max',
defaultValue: 10,
},
{
propName: 'valueLabelDisplay',
knob: 'select',
options: ['auto', 'on', 'off'],
defaultValue: 'off',
},
{
propName: 'size',
knob: 'select',
options: ['small', 'medium'],
defaultValue: 'medium',
},
{
propName: 'marks',
knob: 'switch',
defaultValue: false,
},
{
propName: 'disabled',
knob: 'switch',
defaultValue: false,
},
]}
renderDemo={(props) => (
<Box sx={{ width: 300 }}>
<Slider {...props}>Hello world</Slider>
</Box>
)}
/>
);
}
| 2,967 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/SliderSizes.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
export default function SliderSizes() {
return (
<Box sx={{ width: 300 }}>
<Slider
size="small"
defaultValue={70}
aria-label="Small"
valueLabelDisplay="auto"
/>
<Slider defaultValue={50} aria-label="Default" valueLabelDisplay="auto" />
</Box>
);
}
| 2,968 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/SliderSizes.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
export default function SliderSizes() {
return (
<Box sx={{ width: 300 }}>
<Slider
size="small"
defaultValue={70}
aria-label="Small"
valueLabelDisplay="auto"
/>
<Slider defaultValue={50} aria-label="Default" valueLabelDisplay="auto" />
</Box>
);
}
| 2,969 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/SliderSizes.tsx.preview | <Slider
size="small"
defaultValue={70}
aria-label="Small"
valueLabelDisplay="auto"
/>
<Slider defaultValue={50} aria-label="Default" valueLabelDisplay="auto" /> | 2,970 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/TrackFalseSlider.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
const Separator = styled('div')(
({ theme }) => `
height: ${theme.spacing(3)};
`,
);
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value) {
return `${value}°C`;
}
export default function TrackFalseSlider() {
return (
<Box sx={{ width: 250 }}>
<Typography id="track-false-slider" gutterBottom>
Removed track
</Typography>
<Slider
track={false}
aria-labelledby="track-false-slider"
getAriaValueText={valuetext}
defaultValue={30}
marks={marks}
/>
<Separator />
<Typography id="track-false-range-slider" gutterBottom>
Removed track range slider
</Typography>
<Slider
track={false}
aria-labelledby="track-false-range-slider"
getAriaValueText={valuetext}
defaultValue={[20, 37, 50]}
marks={marks}
/>
</Box>
);
}
| 2,971 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/TrackFalseSlider.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
const Separator = styled('div')(
({ theme }) => `
height: ${theme.spacing(3)};
`,
);
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value: number) {
return `${value}°C`;
}
export default function TrackFalseSlider() {
return (
<Box sx={{ width: 250 }}>
<Typography id="track-false-slider" gutterBottom>
Removed track
</Typography>
<Slider
track={false}
aria-labelledby="track-false-slider"
getAriaValueText={valuetext}
defaultValue={30}
marks={marks}
/>
<Separator />
<Typography id="track-false-range-slider" gutterBottom>
Removed track range slider
</Typography>
<Slider
track={false}
aria-labelledby="track-false-range-slider"
getAriaValueText={valuetext}
defaultValue={[20, 37, 50]}
marks={marks}
/>
</Box>
);
}
| 2,972 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/TrackInvertedSlider.js | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
const Separator = styled('div')(
({ theme }) => `
height: ${theme.spacing(3)};
`,
);
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value) {
return `${value}°C`;
}
export default function TrackInvertedSlider() {
return (
<Box sx={{ width: 250 }}>
<Typography id="track-inverted-slider" gutterBottom>
Inverted track
</Typography>
<Slider
track="inverted"
aria-labelledby="track-inverted-slider"
getAriaValueText={valuetext}
defaultValue={30}
marks={marks}
/>
<Separator />
<Typography id="track-inverted-range-slider" gutterBottom>
Inverted track range
</Typography>
<Slider
track="inverted"
aria-labelledby="track-inverted-range-slider"
getAriaValueText={valuetext}
defaultValue={[20, 37]}
marks={marks}
/>
</Box>
);
}
| 2,973 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/TrackInvertedSlider.tsx | import * as React from 'react';
import { styled } from '@mui/material/styles';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import Slider from '@mui/material/Slider';
const Separator = styled('div')(
({ theme }) => `
height: ${theme.spacing(3)};
`,
);
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
function valuetext(value: number) {
return `${value}°C`;
}
export default function TrackInvertedSlider() {
return (
<Box sx={{ width: 250 }}>
<Typography id="track-inverted-slider" gutterBottom>
Inverted track
</Typography>
<Slider
track="inverted"
aria-labelledby="track-inverted-slider"
getAriaValueText={valuetext}
defaultValue={30}
marks={marks}
/>
<Separator />
<Typography id="track-inverted-range-slider" gutterBottom>
Inverted track range
</Typography>
<Slider
track="inverted"
aria-labelledby="track-inverted-range-slider"
getAriaValueText={valuetext}
defaultValue={[20, 37]}
marks={marks}
/>
</Box>
);
}
| 2,974 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/VerticalAccessibleSlider.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
export default function VerticalAccessibleSlider() {
function preventHorizontalKeyboardNavigation(event) {
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
event.preventDefault();
}
}
return (
<Box sx={{ height: 300 }}>
<Slider
sx={{
'& input[type="range"]': {
WebkitAppearance: 'slider-vertical',
},
}}
orientation="vertical"
defaultValue={30}
aria-label="Temperature"
valueLabelDisplay="auto"
onKeyDown={preventHorizontalKeyboardNavigation}
/>
</Box>
);
}
| 2,975 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/VerticalAccessibleSlider.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Slider from '@mui/material/Slider';
export default function VerticalAccessibleSlider() {
function preventHorizontalKeyboardNavigation(event: React.KeyboardEvent) {
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
event.preventDefault();
}
}
return (
<Box sx={{ height: 300 }}>
<Slider
sx={{
'& input[type="range"]': {
WebkitAppearance: 'slider-vertical',
},
}}
orientation="vertical"
defaultValue={30}
aria-label="Temperature"
valueLabelDisplay="auto"
onKeyDown={preventHorizontalKeyboardNavigation}
/>
</Box>
);
}
| 2,976 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/VerticalAccessibleSlider.tsx.preview | <Slider
sx={{
'& input[type="range"]': {
WebkitAppearance: 'slider-vertical',
},
}}
orientation="vertical"
defaultValue={30}
aria-label="Temperature"
valueLabelDisplay="auto"
onKeyDown={preventHorizontalKeyboardNavigation}
/> | 2,977 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/VerticalSlider.js | import * as React from 'react';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
function valuetext(value) {
return `${value}°C`;
}
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
export default function VerticalSlider() {
return (
<Stack sx={{ height: 300 }} spacing={1} direction="row">
<Slider
aria-label="Temperature"
orientation="vertical"
getAriaValueText={valuetext}
valueLabelDisplay="auto"
defaultValue={30}
/>
<Slider
aria-label="Temperature"
orientation="vertical"
defaultValue={30}
valueLabelDisplay="auto"
disabled
/>
<Slider
getAriaLabel={() => 'Temperature'}
orientation="vertical"
getAriaValueText={valuetext}
defaultValue={[20, 37]}
valueLabelDisplay="auto"
marks={marks}
/>
</Stack>
);
}
| 2,978 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/VerticalSlider.tsx | import * as React from 'react';
import Stack from '@mui/material/Stack';
import Slider from '@mui/material/Slider';
function valuetext(value: number) {
return `${value}°C`;
}
const marks = [
{
value: 0,
label: '0°C',
},
{
value: 20,
label: '20°C',
},
{
value: 37,
label: '37°C',
},
{
value: 100,
label: '100°C',
},
];
export default function VerticalSlider() {
return (
<Stack sx={{ height: 300 }} spacing={1} direction="row">
<Slider
aria-label="Temperature"
orientation="vertical"
getAriaValueText={valuetext}
valueLabelDisplay="auto"
defaultValue={30}
/>
<Slider
aria-label="Temperature"
orientation="vertical"
defaultValue={30}
valueLabelDisplay="auto"
disabled
/>
<Slider
getAriaLabel={() => 'Temperature'}
orientation="vertical"
getAriaValueText={valuetext}
defaultValue={[20, 37]}
valueLabelDisplay="auto"
marks={marks}
/>
</Stack>
);
}
| 2,979 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/slider/slider.md | ---
productId: material-ui
title: React Slider component
components: Slider
githubLabel: 'component: slider'
materialDesign: https://m2.material.io/components/sliders
waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/
unstyled: /base-ui/react-slider/
---
# Slider
<p class="description">Sliders allow users to make selections from a range of values.</p>
Sliders reflect a range of values along a bar, from which users may select a single value. They are ideal for adjusting settings such as volume, brightness, or applying image filters.
{{"component": "modules/components/ComponentLinkHeader.js"}}
## Continuous sliders
Continuous sliders allow users to select a value along a subjective range.
{{"demo": "ContinuousSlider.js"}}
## Sizes
For smaller slider, use the prop `size="small"`.
{{"demo": "SliderSizes.js"}}
## Discrete sliders
Discrete sliders can be adjusted to a specific value by referencing its value indicator.
You can generate a mark for each step with `marks={true}`.
{{"demo": "DiscreteSlider.js"}}
### Small steps
You can change the default step increment.
{{"demo": "DiscreteSliderSteps.js"}}
### Custom marks
You can have custom marks by providing a rich array to the `marks` prop.
{{"demo": "DiscreteSliderMarks.js"}}
### Restricted values
You can restrict the selectable values to those provided with the `marks` prop with `step={null}`.
{{"demo": "DiscreteSliderValues.js"}}
### Label always visible
You can force the thumb label to be always visible with `valueLabelDisplay="on"`.
{{"demo": "DiscreteSliderLabel.js"}}
## Range slider
The slider can be used to set the start and end of a range by supplying an array of values to the `value` prop.
{{"demo": "RangeSlider.js"}}
### Minimum distance
You can enforce a minimum distance between values in the `onChange` event handler.
By default, when you move the pointer over a thumb while dragging another thumb, the active thumb will swap to the hovered thumb. You can disable this behavior with the `disableSwap` prop.
If you want the range to shift when reaching minimum distance, you can utilize the `activeThumb` parameter in `onChange`.
{{"demo": "MinimumDistanceSlider.js"}}
## Slider with input field
In this example, an input allows a discrete value to be set.
{{"demo": "InputSlider.js"}}
## Color
{{"demo": "ColorSlider.js"}}
## Customization
Here are some examples of customizing the component.
You can learn more about this in the [overrides documentation page](/material-ui/customization/how-to-customize/).
{{"demo": "CustomizedSlider.js"}}
### Music player
{{"demo": "MusicPlayerSlider.js"}}
## Vertical sliders
{{"demo": "VerticalSlider.js"}}
**WARNING**: Chrome, Safari and newer Edge versions i.e. any browser based on WebKit exposes `<Slider orientation="vertical" />` as horizontal ([chromium issue #1158217](https://bugs.chromium.org/p/chromium/issues/detail?id=1158217)).
By applying `-webkit-appearance: slider-vertical;` the slider is exposed as vertical.
However, by applying `-webkit-appearance: slider-vertical;` keyboard navigation for horizontal keys (<kbd class="key">Arrow Left</kbd>, <kbd class="key">Arrow Right</kbd>) is reversed ([chromium issue #1162640](https://bugs.chromium.org/p/chromium/issues/detail?id=1162640)).
Usually, up and right should increase and left and down should decrease the value.
If you apply `-webkit-appearance` you could prevent keyboard navigation for horizontal arrow keys for a truly vertical slider.
This might be less confusing to users compared to a change in direction.
{{"demo": "VerticalAccessibleSlider.js"}}
## Track
The track shows the range available for user selection.
### Removed track
The track can be turned off with `track={false}`.
{{"demo": "TrackFalseSlider.js"}}
### Inverted track
The track can be inverted with `track="inverted"`.
{{"demo": "TrackInvertedSlider.js"}}
## Non-linear scale
You can use the `scale` prop to represent the `value` on a different scale.
In the following demo, the value _x_ represents the value _2^x_.
Increasing _x_ by one increases the represented value by factor _2_.
{{"demo": "NonLinearSlider.js"}}
## Accessibility
(WAI-ARIA: https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/)
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.
## Limitations
### IE 11
The slider's value label is not centered in IE 11.
The alignment is not handled to make customizations easier with the latest browsers.
You can solve the issue with:
```css
.MuiSlider-valueLabel {
left: calc(-50% - 4px);
}
```
## Experimental APIs
### Material You version
The default Material UI Slider component follows the Material Design 2 specs.
To get the Material You ([Material Design 3](https://m3.material.io/)) version, use the new experimental `@mui/material-next` package:
```js
import Slider from '@mui/material-next/Slider';
```
{{"demo": "SliderMaterialYouPlayground.js", "hideToolbar": true, "bg": "playground"}}
| 2,980 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/ConsecutiveSnackbars.js | import * as React from 'react';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
export default function ConsecutiveSnackbars() {
const [snackPack, setSnackPack] = React.useState([]);
const [open, setOpen] = React.useState(false);
const [messageInfo, setMessageInfo] = React.useState(undefined);
React.useEffect(() => {
if (snackPack.length && !messageInfo) {
// Set a new snack when we don't have an active one
setMessageInfo({ ...snackPack[0] });
setSnackPack((prev) => prev.slice(1));
setOpen(true);
} else if (snackPack.length && messageInfo && open) {
// Close an active snack when a new one is added
setOpen(false);
}
}, [snackPack, messageInfo, open]);
const handleClick = (message) => () => {
setSnackPack((prev) => [...prev, { message, key: new Date().getTime() }]);
};
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
const handleExited = () => {
setMessageInfo(undefined);
};
return (
<div>
<Button onClick={handleClick('Message A')}>Show message A</Button>
<Button onClick={handleClick('Message B')}>Show message B</Button>
<Snackbar
key={messageInfo ? messageInfo.key : undefined}
open={open}
autoHideDuration={6000}
onClose={handleClose}
TransitionProps={{ onExited: handleExited }}
message={messageInfo ? messageInfo.message : undefined}
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
aria-label="close"
color="inherit"
sx={{ p: 0.5 }}
onClick={handleClose}
>
<CloseIcon />
</IconButton>
</React.Fragment>
}
/>
</div>
);
}
| 2,981 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/ConsecutiveSnackbars.tsx | import * as React from 'react';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
export interface SnackbarMessage {
message: string;
key: number;
}
export interface State {
open: boolean;
snackPack: readonly SnackbarMessage[];
messageInfo?: SnackbarMessage;
}
export default function ConsecutiveSnackbars() {
const [snackPack, setSnackPack] = React.useState<readonly SnackbarMessage[]>([]);
const [open, setOpen] = React.useState(false);
const [messageInfo, setMessageInfo] = React.useState<SnackbarMessage | undefined>(
undefined,
);
React.useEffect(() => {
if (snackPack.length && !messageInfo) {
// Set a new snack when we don't have an active one
setMessageInfo({ ...snackPack[0] });
setSnackPack((prev) => prev.slice(1));
setOpen(true);
} else if (snackPack.length && messageInfo && open) {
// Close an active snack when a new one is added
setOpen(false);
}
}, [snackPack, messageInfo, open]);
const handleClick = (message: string) => () => {
setSnackPack((prev) => [...prev, { message, key: new Date().getTime() }]);
};
const handleClose = (event: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
const handleExited = () => {
setMessageInfo(undefined);
};
return (
<div>
<Button onClick={handleClick('Message A')}>Show message A</Button>
<Button onClick={handleClick('Message B')}>Show message B</Button>
<Snackbar
key={messageInfo ? messageInfo.key : undefined}
open={open}
autoHideDuration={6000}
onClose={handleClose}
TransitionProps={{ onExited: handleExited }}
message={messageInfo ? messageInfo.message : undefined}
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
aria-label="close"
color="inherit"
sx={{ p: 0.5 }}
onClick={handleClose}
>
<CloseIcon />
</IconButton>
</React.Fragment>
}
/>
</div>
);
}
| 2,982 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/CustomizedSnackbars.js | import * as React from 'react';
import Stack from '@mui/material/Stack';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert from '@mui/material/Alert';
const Alert = React.forwardRef(function Alert(props, ref) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});
export default function CustomizedSnackbars() {
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(true);
};
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Button variant="outlined" onClick={handleClick}>
Open success snackbar
</Button>
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
This is a success message!
</Alert>
</Snackbar>
<Alert severity="error">This is an error message!</Alert>
<Alert severity="warning">This is a warning message!</Alert>
<Alert severity="info">This is an information message!</Alert>
<Alert severity="success">This is a success message!</Alert>
</Stack>
);
}
| 2,983 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/CustomizedSnackbars.tsx | import * as React from 'react';
import Stack from '@mui/material/Stack';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertProps } from '@mui/material/Alert';
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
props,
ref,
) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});
export default function CustomizedSnackbars() {
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(true);
};
const handleClose = (event?: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
return (
<Stack spacing={2} sx={{ width: '100%' }}>
<Button variant="outlined" onClick={handleClick}>
Open success snackbar
</Button>
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
This is a success message!
</Alert>
</Snackbar>
<Alert severity="error">This is an error message!</Alert>
<Alert severity="warning">This is a warning message!</Alert>
<Alert severity="info">This is an information message!</Alert>
<Alert severity="success">This is a success message!</Alert>
</Stack>
);
}
| 2,984 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/CustomizedSnackbars.tsx.preview | <Button variant="outlined" onClick={handleClick}>
Open success snackbar
</Button>
<Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
This is a success message!
</Alert>
</Snackbar>
<Alert severity="error">This is an error message!</Alert>
<Alert severity="warning">This is a warning message!</Alert>
<Alert severity="info">This is an information message!</Alert>
<Alert severity="success">This is a success message!</Alert> | 2,985 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/DirectionSnackbar.js | import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import Slide from '@mui/material/Slide';
function TransitionLeft(props) {
return <Slide {...props} direction="left" />;
}
function TransitionUp(props) {
return <Slide {...props} direction="up" />;
}
function TransitionRight(props) {
return <Slide {...props} direction="right" />;
}
function TransitionDown(props) {
return <Slide {...props} direction="down" />;
}
export default function DirectionSnackbar() {
const [open, setOpen] = React.useState(false);
const [transition, setTransition] = React.useState(undefined);
const handleClick = (Transition) => () => {
setTransition(() => Transition);
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<Box sx={{ width: 300 }}>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick(TransitionUp)}>Up</Button>
</Box>
<Grid container justifyContent="center">
<Grid item xs={6}>
<Button onClick={handleClick(TransitionRight)}>Left</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick(TransitionLeft)}>Right</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick(TransitionDown)}>Down</Button>
</Box>
<Snackbar
open={open}
onClose={handleClose}
TransitionComponent={transition}
message="I love snacks"
key={transition ? transition.name : ''}
/>
</Box>
);
}
| 2,986 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/DirectionSnackbar.tsx | import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import Slide, { SlideProps } from '@mui/material/Slide';
type TransitionProps = Omit<SlideProps, 'direction'>;
function TransitionLeft(props: TransitionProps) {
return <Slide {...props} direction="left" />;
}
function TransitionUp(props: TransitionProps) {
return <Slide {...props} direction="up" />;
}
function TransitionRight(props: TransitionProps) {
return <Slide {...props} direction="right" />;
}
function TransitionDown(props: TransitionProps) {
return <Slide {...props} direction="down" />;
}
export default function DirectionSnackbar() {
const [open, setOpen] = React.useState(false);
const [transition, setTransition] = React.useState<
React.ComponentType<TransitionProps> | undefined
>(undefined);
const handleClick = (Transition: React.ComponentType<TransitionProps>) => () => {
setTransition(() => Transition);
setOpen(true);
};
const handleClose = () => {
setOpen(false);
};
return (
<Box sx={{ width: 300 }}>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick(TransitionUp)}>Up</Button>
</Box>
<Grid container justifyContent="center">
<Grid item xs={6}>
<Button onClick={handleClick(TransitionRight)}>Left</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick(TransitionLeft)}>Right</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick(TransitionDown)}>Down</Button>
</Box>
<Snackbar
open={open}
onClose={handleClose}
TransitionComponent={transition}
message="I love snacks"
key={transition ? transition.name : ''}
/>
</Box>
);
}
| 2,987 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/FabIntegrationSnackbar.js | import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import CssBaseline from '@mui/material/CssBaseline';
import GlobalStyles from '@mui/material/GlobalStyles';
import Toolbar from '@mui/material/Toolbar';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import Fab from '@mui/material/Fab';
import AddIcon from '@mui/icons-material/Add';
import Snackbar from '@mui/material/Snackbar';
export default function FabIntegrationSnackbar() {
return (
<React.Fragment>
<CssBaseline />
<GlobalStyles
styles={(theme) => ({
body: { backgroundColor: theme.palette.background.paper },
})}
/>
<div>
<AppBar position="static" color="primary">
<Toolbar>
<IconButton
edge="start"
sx={{ mr: 2 }}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" component="div">
App bar
</Typography>
</Toolbar>
</AppBar>
<Fab
color="secondary"
sx={{
position: 'absolute',
bottom: (theme) => theme.spacing(2),
right: (theme) => theme.spacing(2),
}}
>
<AddIcon />
</Fab>
<Snackbar
open
autoHideDuration={6000}
message="Archived"
action={
<Button color="inherit" size="small">
Undo
</Button>
}
sx={{ bottom: { xs: 90, sm: 0 } }}
/>
</div>
</React.Fragment>
);
}
| 2,988 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/FabIntegrationSnackbar.tsx | import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import CssBaseline from '@mui/material/CssBaseline';
import GlobalStyles from '@mui/material/GlobalStyles';
import Toolbar from '@mui/material/Toolbar';
import IconButton from '@mui/material/IconButton';
import MenuIcon from '@mui/icons-material/Menu';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import Fab from '@mui/material/Fab';
import AddIcon from '@mui/icons-material/Add';
import Snackbar from '@mui/material/Snackbar';
export default function FabIntegrationSnackbar() {
return (
<React.Fragment>
<CssBaseline />
<GlobalStyles
styles={(theme) => ({
body: { backgroundColor: theme.palette.background.paper },
})}
/>
<div>
<AppBar position="static" color="primary">
<Toolbar>
<IconButton
edge="start"
sx={{ mr: 2 }}
color="inherit"
aria-label="menu"
>
<MenuIcon />
</IconButton>
<Typography variant="h6" color="inherit" component="div">
App bar
</Typography>
</Toolbar>
</AppBar>
<Fab
color="secondary"
sx={{
position: 'absolute',
bottom: (theme) => theme.spacing(2),
right: (theme) => theme.spacing(2),
}}
>
<AddIcon />
</Fab>
<Snackbar
open
autoHideDuration={6000}
message="Archived"
action={
<Button color="inherit" size="small">
Undo
</Button>
}
sx={{ bottom: { xs: 90, sm: 0 } }}
/>
</div>
</React.Fragment>
);
}
| 2,989 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/IntegrationNotistack.js | import * as React from 'react';
import Button from '@mui/material/Button';
import { SnackbarProvider, useSnackbar } from 'notistack';
function MyApp() {
const { enqueueSnackbar } = useSnackbar();
const handleClick = () => {
enqueueSnackbar('I love snacks.');
};
const handleClickVariant = (variant) => () => {
// variant could be success, error, warning, info, or default
enqueueSnackbar('This is a success message!', { variant });
};
return (
<React.Fragment>
<Button onClick={handleClick}>Show snackbar</Button>
<Button onClick={handleClickVariant('success')}>Show success snackbar</Button>
</React.Fragment>
);
}
export default function IntegrationNotistack() {
return (
<SnackbarProvider maxSnack={3}>
<MyApp />
</SnackbarProvider>
);
}
| 2,990 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/IntegrationNotistack.tsx | import * as React from 'react';
import Button from '@mui/material/Button';
import { SnackbarProvider, VariantType, useSnackbar } from 'notistack';
function MyApp() {
const { enqueueSnackbar } = useSnackbar();
const handleClick = () => {
enqueueSnackbar('I love snacks.');
};
const handleClickVariant = (variant: VariantType) => () => {
// variant could be success, error, warning, info, or default
enqueueSnackbar('This is a success message!', { variant });
};
return (
<React.Fragment>
<Button onClick={handleClick}>Show snackbar</Button>
<Button onClick={handleClickVariant('success')}>Show success snackbar</Button>
</React.Fragment>
);
}
export default function IntegrationNotistack() {
return (
<SnackbarProvider maxSnack={3}>
<MyApp />
</SnackbarProvider>
);
}
| 2,991 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/IntegrationNotistack.tsx.preview | <SnackbarProvider maxSnack={3}>
<MyApp />
</SnackbarProvider> | 2,992 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/LongTextSnackbar.js | import * as React from 'react';
import Button from '@mui/material/Button';
import Stack from '@mui/material/Stack';
import SnackbarContent from '@mui/material/SnackbarContent';
const action = (
<Button color="secondary" size="small">
lorem ipsum dolorem
</Button>
);
export default function LongTextSnackbar() {
return (
<Stack spacing={2} sx={{ maxWidth: 600 }}>
<SnackbarContent message="I love snacks." action={action} />
<SnackbarContent
message={
'I love candy. I love cookies. I love cupcakes. \
I love cheesecake. I love chocolate.'
}
/>
<SnackbarContent
message="I love candy. I love cookies. I love cupcakes."
action={action}
/>
<SnackbarContent
message={
'I love candy. I love cookies. I love cupcakes. \
I love cheesecake. I love chocolate.'
}
action={action}
/>
</Stack>
);
}
| 2,993 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/LongTextSnackbar.tsx | import * as React from 'react';
import Button from '@mui/material/Button';
import Stack from '@mui/material/Stack';
import SnackbarContent from '@mui/material/SnackbarContent';
const action = (
<Button color="secondary" size="small">
lorem ipsum dolorem
</Button>
);
export default function LongTextSnackbar() {
return (
<Stack spacing={2} sx={{ maxWidth: 600 }}>
<SnackbarContent message="I love snacks." action={action} />
<SnackbarContent
message={
'I love candy. I love cookies. I love cupcakes. \
I love cheesecake. I love chocolate.'
}
/>
<SnackbarContent
message="I love candy. I love cookies. I love cupcakes."
action={action}
/>
<SnackbarContent
message={
'I love candy. I love cookies. I love cupcakes. \
I love cheesecake. I love chocolate.'
}
action={action}
/>
</Stack>
);
}
| 2,994 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/PositionedSnackbar.js | import * as React from 'react';
import Grid from '@mui/material/Grid';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
export default function PositionedSnackbar() {
const [state, setState] = React.useState({
open: false,
vertical: 'top',
horizontal: 'center',
});
const { vertical, horizontal, open } = state;
const handleClick = (newState) => () => {
setState({ ...newState, open: true });
};
const handleClose = () => {
setState({ ...state, open: false });
};
const buttons = (
<React.Fragment>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick({ vertical: 'top', horizontal: 'center' })}>
Top-Center
</Button>
</Box>
<Grid container justifyContent="center">
<Grid item xs={6}>
<Button onClick={handleClick({ vertical: 'top', horizontal: 'left' })}>
Top-Left
</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick({ vertical: 'top', horizontal: 'right' })}>
Top-Right
</Button>
</Grid>
<Grid item xs={6}>
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'left' })}>
Bottom-Left
</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'right' })}>
Bottom-Right
</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'center' })}>
Bottom-Center
</Button>
</Box>
</React.Fragment>
);
return (
<Box sx={{ width: 500 }}>
{buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
message="I love snacks"
key={vertical + horizontal}
/>
</Box>
);
}
| 2,995 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/PositionedSnackbar.tsx | import * as React from 'react';
import Grid from '@mui/material/Grid';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import Snackbar, { SnackbarOrigin } from '@mui/material/Snackbar';
interface State extends SnackbarOrigin {
open: boolean;
}
export default function PositionedSnackbar() {
const [state, setState] = React.useState<State>({
open: false,
vertical: 'top',
horizontal: 'center',
});
const { vertical, horizontal, open } = state;
const handleClick = (newState: SnackbarOrigin) => () => {
setState({ ...newState, open: true });
};
const handleClose = () => {
setState({ ...state, open: false });
};
const buttons = (
<React.Fragment>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick({ vertical: 'top', horizontal: 'center' })}>
Top-Center
</Button>
</Box>
<Grid container justifyContent="center">
<Grid item xs={6}>
<Button onClick={handleClick({ vertical: 'top', horizontal: 'left' })}>
Top-Left
</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick({ vertical: 'top', horizontal: 'right' })}>
Top-Right
</Button>
</Grid>
<Grid item xs={6}>
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'left' })}>
Bottom-Left
</Button>
</Grid>
<Grid item xs={6} textAlign="right">
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'right' })}>
Bottom-Right
</Button>
</Grid>
</Grid>
<Box sx={{ display: 'flex', justifyContent: 'center' }}>
<Button onClick={handleClick({ vertical: 'bottom', horizontal: 'center' })}>
Bottom-Center
</Button>
</Box>
</React.Fragment>
);
return (
<Box sx={{ width: 500 }}>
{buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
message="I love snacks"
key={vertical + horizontal}
/>
</Box>
);
}
| 2,996 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/PositionedSnackbar.tsx.preview | {buttons}
<Snackbar
anchorOrigin={{ vertical, horizontal }}
open={open}
onClose={handleClose}
message="I love snacks"
key={vertical + horizontal}
/> | 2,997 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/SimpleSnackbar.js | import * as React from 'react';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
export default function SimpleSnackbar() {
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(true);
};
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
const action = (
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
);
return (
<div>
<Button onClick={handleClick}>Open simple snackbar</Button>
<Snackbar
open={open}
autoHideDuration={6000}
onClose={handleClose}
message="Note archived"
action={action}
/>
</div>
);
}
| 2,998 |
0 | petrpan-code/mui/material-ui/docs/data/material/components | petrpan-code/mui/material-ui/docs/data/material/components/snackbars/SimpleSnackbar.tsx | import * as React from 'react';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';
export default function SimpleSnackbar() {
const [open, setOpen] = React.useState(false);
const handleClick = () => {
setOpen(true);
};
const handleClose = (event: React.SyntheticEvent | Event, reason?: string) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
const action = (
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
UNDO
</Button>
<IconButton
size="small"
aria-label="close"
color="inherit"
onClick={handleClose}
>
<CloseIcon fontSize="small" />
</IconButton>
</React.Fragment>
);
return (
<div>
<Button onClick={handleClick}>Open simple snackbar</Button>
<Snackbar
open={open}
autoHideDuration={6000}
onClose={handleClose}
message="Note archived"
action={action}
/>
</div>
);
}
| 2,999 |
Subsets and Splits