Skip to content

[Slider][material-next] Add Slider component with Material You design #37520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
effdf91
[Material You] copy MD2 Slider component
DiegoAndai May 22, 2023
62cf97c
[Material You] add useThemeProps hook
DiegoAndai May 22, 2023
9bf7edf
[Material You] add useTheme
DiegoAndai May 22, 2023
2837b4b
[Material You] add shouldSpreadAdditionalProps
DiegoAndai May 22, 2023
66eb1e6
[Material You] fix Slider capitalize import
DiegoAndai May 22, 2023
aa9a695
[Material You] fix generateUtilityClass import
DiegoAndai May 22, 2023
d1a751e
[Material You] Fix slotShouldForwardProp import
DiegoAndai May 22, 2023
eb04c2d
[MD3][Slider] migrate index to TS
DiegoAndai May 22, 2023
abc85c6
[MD3][Slider] migrate component types to .types
DiegoAndai May 22, 2023
a7b4a3e
[MD3][Slider] migrate component file to .tsx
DiegoAndai May 22, 2023
84ec7f5
[MD3][Slider] Add types to identity function
DiegoAndai May 22, 2023
a39118f
[MD3][Slider] add Slider props and ref types
DiegoAndai May 22, 2023
4bd6fec
[MD3][Slider] fix ownerState typings
DiegoAndai May 24, 2023
a642ae3
[MD3][Slider] add markActive types
DiegoAndai May 24, 2023
9a6c299
[MD3][Slider] Add Forward function children type
DiegoAndai May 24, 2023
8884595
[MD3] Add direction to CssVarsProvider theme
DiegoAndai May 24, 2023
140bffd
[MD3][Slider] Fix StyledSliderValueLabel propTypes
DiegoAndai May 24, 2023
acf3b0d
Apply MD3 slider style
DiegoAndai Jun 6, 2023
f74848f
Add MD3 Slider playground
DiegoAndai Jun 6, 2023
0928ab0
Fix linting from unused eslint disable
DiegoAndai Jun 6, 2023
c59f923
Add missing neutral tones to md2 experiment page
DiegoAndai Jun 6, 2023
9a8668d
Improve Slider disabled colors
DiegoAndai Jun 8, 2023
4c37ec6
Fix incorrect import in tests
DiegoAndai Jun 8, 2023
2af568e
Fix .spec file types
DiegoAndai Jun 9, 2023
744a999
Remove shared mock match media util
DiegoAndai Jun 9, 2023
805227e
Deprecate components and componentsProps
DiegoAndai Jun 12, 2023
1848e1b
[Slider] Add onChange docs missing coma
DiegoAndai Jun 12, 2023
4bfc582
Refactor neutral tones type
DiegoAndai Jun 12, 2023
67b1ac6
Initialize slots ans slotProps to avoid `?.`
DiegoAndai Jun 15, 2023
4b3de78
Remove componentsProps from `.spec`
DiegoAndai Jun 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as React from 'react';
import MaterialYouUsageDemo from 'docs/src/modules/components/MaterialYouUsageDemo';
import Slider from '@mui/material-next/Slider';
import Box from '@mui/material/Box';

export default function ButtonUsage() {
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>
)}
/>
);
}
13 changes: 13 additions & 0 deletions docs/data/material/components/slider/slider.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,16 @@ You can solve the issue with:
left: calc(-50% - 4px);
}
```

## Experimental API

### Material You version

The default Slider component follows the Material Design 2 specs.
For the Material Design 3 ([Material You](https://m3.material.io/)) version, you can use the new experimental `@mui/material-next` package:

```js
import Slider from '@mui/material-next/Slider';
```

{{"demo": "SliderMaterialYouPlayground.js", "hideToolbar": true}}
3 changes: 3 additions & 0 deletions docs/pages/experiments/md3/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,17 @@ const customPalette = {
neutral: {
'0': '#000000',
'10': '#201a1c',
'17': '#2e282a',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to update the types too. Are these values coming from the specs?

Copy link
Member Author

@DiegoAndai DiegoAndai Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated them here 😊:

neutral: MD3Tones & { 17: string; 22: string; 92: string };

Yes, they come from the specs. Here are the values for the MD3 default theme, and here I added them to our palette:

For this experiment file, I noticed that it didn't use the default MD3 colors so I created the tones based on the existing neutral tones, altering the light value as explained in: https://m3.material.io/styles/color/the-color-system/key-colors-tones#a828e350-1551-45e5-8430-eb643e6a7713

These are used for the surfaceContainerHigh and surfaceContainerHighest tokens:

Screenshot 2023-06-07 at 08 19 31

'20': '#352f30',
'22': '#393335',
'30': '#4c4546',
'40': '#645c5e',
'50': '#7e7577',
'60': '#988e90',
'70': '#b3a9aa',
'80': '#cfc4c5',
'90': '#ebe0e1',
'92': '#f1e5e6',
'95': '#faeef0',
'99': '#fffbff',
'100': '#ffffff',
Expand Down
76 changes: 76 additions & 0 deletions packages/mui-material-next/src/Slider/Slider.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import * as React from 'react';
import Slider from '@mui/material-next/Slider';
import { SliderOwnerState } from './Slider.types';

function testOnChange() {
function handleSliderChange(event: Event, value: unknown) {}
function handleSliderChangeCommitted(event: React.SyntheticEvent | Event, value: unknown) {}
<Slider onChange={handleSliderChange} onChangeCommitted={handleSliderChangeCommitted} />;

function handleElementChange(event: React.ChangeEvent) {}
<Slider onChange={handleElementChange} onChangeCommitted={handleElementChange} />;
}

<Slider track="inverted" />;

// slotProps and componentsProps as objects
<Slider
slotProps={{
root: { onMouseDown: () => 'onMouseDown event triggered' },
input: { disabled: true },
mark: { onClick: () => 'clicked' },
markLabel: { className: 'markLabel' },
rail: { className: 'rail' },
thumb: { className: 'thumb' },
valueLabel: { valueLabelDisplay: 'auto' },
}}
componentsProps={{
root: { onMouseDown: () => 'onMouseDown event triggered' },
input: { disabled: true },
mark: { onClick: () => 'clicked' },
markLabel: { className: 'markLabel' },
rail: { className: 'rail' },
thumb: { className: 'thumb' },
valueLabel: { valueLabelDisplay: 'auto' },
}}
/>;

// slotProps and componentsProps as functions
<Slider
slotProps={{
root: ({ color }: SliderOwnerState) => ({
className: color === 'primary' ? 'root_primary' : 'root_secondary',
}),
input: ({ size }: SliderOwnerState) => ({ disabled: size === 'medium' }),
mark: ({ marked }: SliderOwnerState) => ({
className: marked ? 'marked' : '',
}),
markLabel: ({ max }: SliderOwnerState) => ({
className: max === 99 ? 'red' : 'normal',
}),
rail: ({ dragging }: SliderOwnerState) => ({
className: dragging ? 'rail' : '',
}),
thumb: ({ orientation }: SliderOwnerState) => ({
className: orientation === 'vertical' ? 'thumb_vertical' : '',
}),
}}
componentsProps={{
root: ({ color }: SliderOwnerState) => ({
className: color === 'primary' ? 'root_primary' : 'root_secondary',
}),
input: ({ size }: SliderOwnerState) => ({ disabled: size === 'medium' }),
mark: ({ marked }: SliderOwnerState) => ({
className: marked ? 'marked' : '',
}),
markLabel: ({ max }: SliderOwnerState) => ({
className: max === 99 ? 'red' : 'normal',
}),
rail: ({ dragging }: SliderOwnerState) => ({
className: dragging ? 'rail' : '',
}),
thumb: ({ orientation }: SliderOwnerState) => ({
className: orientation === 'vertical' ? 'thumb_vertical' : '',
}),
}}
/>;
Loading