-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[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
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 62cf97c
[Material You] add useThemeProps hook
DiegoAndai 9bf7edf
[Material You] add useTheme
DiegoAndai 2837b4b
[Material You] add shouldSpreadAdditionalProps
DiegoAndai 66eb1e6
[Material You] fix Slider capitalize import
DiegoAndai aa9a695
[Material You] fix generateUtilityClass import
DiegoAndai d1a751e
[Material You] Fix slotShouldForwardProp import
DiegoAndai eb04c2d
[MD3][Slider] migrate index to TS
DiegoAndai abc85c6
[MD3][Slider] migrate component types to .types
DiegoAndai a7b4a3e
[MD3][Slider] migrate component file to .tsx
DiegoAndai 84ec7f5
[MD3][Slider] Add types to identity function
DiegoAndai a39118f
[MD3][Slider] add Slider props and ref types
DiegoAndai 4bd6fec
[MD3][Slider] fix ownerState typings
DiegoAndai a642ae3
[MD3][Slider] add markActive types
DiegoAndai 9a6c299
[MD3][Slider] Add Forward function children type
DiegoAndai 8884595
[MD3] Add direction to CssVarsProvider theme
DiegoAndai 140bffd
[MD3][Slider] Fix StyledSliderValueLabel propTypes
DiegoAndai acf3b0d
Apply MD3 slider style
DiegoAndai f74848f
Add MD3 Slider playground
DiegoAndai 0928ab0
Fix linting from unused eslint disable
DiegoAndai c59f923
Add missing neutral tones to md2 experiment page
DiegoAndai 9a8668d
Improve Slider disabled colors
DiegoAndai 4c37ec6
Fix incorrect import in tests
DiegoAndai 2af568e
Fix .spec file types
DiegoAndai 744a999
Remove shared mock match media util
DiegoAndai 805227e
Deprecate components and componentsProps
DiegoAndai 1848e1b
[Slider] Add onChange docs missing coma
DiegoAndai 4bfc582
Refactor neutral tones type
DiegoAndai 67b1ac6
Initialize slots ans slotProps to avoid `?.`
DiegoAndai 4b3de78
Remove componentsProps from `.spec`
DiegoAndai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
docs/data/material/components/slider/SliderMaterialYouPlayground.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
)} | ||
/> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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={{ | ||
DiegoAndai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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' : '', | ||
}), | ||
}} | ||
/>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated them here 😊:
material-ui/packages/mui-material-next/src/styles/Theme.types.ts
Line 28 in c59f923
Yes, they come from the specs. Here are the values for the MD3 default theme, and here I added them to our palette:
material-ui/packages/mui-material-next/src/styles/palette.ts
Line 81 in c59f923
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
andsurfaceContainerHighest
tokens: