-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SliderUnstyled] Improved logic for displaying the value label (#35805)
Signed-off-by: Zeeshan Tamboli <zeeshan.tamboli@gmail.com> Co-authored-by: Marija Najdova <mnajdova@gmail.com> Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
- Loading branch information
1 parent
0ff044d
commit 6311da5
Showing
34 changed files
with
793 additions
and
379 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
135 changes: 135 additions & 0 deletions
135
docs/data/base/components/slider/LabeledValuesSlider.js
This file contains 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,135 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { styled, alpha, Box } from '@mui/system'; | ||
import SliderUnstyled, { sliderUnstyledClasses } from '@mui/base/SliderUnstyled'; | ||
|
||
const blue = { | ||
100: '#DAECFF', | ||
200: '#99CCF3', | ||
400: '#3399FF', | ||
300: '#66B2FF', | ||
500: '#007FFF', | ||
600: '#0072E5', | ||
900: '#003A75', | ||
}; | ||
|
||
const grey = { | ||
50: '#f6f8fa', | ||
100: '#eaeef2', | ||
200: '#d0d7de', | ||
300: '#afb8c1', | ||
400: '#8c959f', | ||
500: '#6e7781', | ||
600: '#57606a', | ||
700: '#424a53', | ||
800: '#32383f', | ||
900: '#24292f', | ||
}; | ||
|
||
const StyledSlider = styled(SliderUnstyled)( | ||
({ theme }) => ` | ||
color: ${theme.palette.mode === 'light' ? blue[500] : blue[300]}; | ||
height: 6px; | ||
width: 100%; | ||
padding: 16px 0; | ||
display: inline-block; | ||
position: relative; | ||
cursor: pointer; | ||
touch-action: none; | ||
-webkit-tap-highlight-color: transparent; | ||
&:hover { | ||
opacity: 1; | ||
} | ||
&.${sliderUnstyledClasses.disabled} { | ||
pointer-events: none; | ||
cursor: default; | ||
color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]}; | ||
opacity: 0.5; | ||
} | ||
& .${sliderUnstyledClasses.rail} { | ||
display: block; | ||
position: absolute; | ||
width: 100%; | ||
height: 4px; | ||
border-radius: 2px; | ||
background-color: currentColor; | ||
opacity: 0.4; | ||
} | ||
& .${sliderUnstyledClasses.track} { | ||
display: block; | ||
position: absolute; | ||
height: 4px; | ||
border-radius: 2px; | ||
background-color: currentColor; | ||
} | ||
& .${sliderUnstyledClasses.thumb} { | ||
position: absolute; | ||
width: 16px; | ||
height: 16px; | ||
margin-left: -6px; | ||
margin-top: -6px; | ||
box-sizing: border-box; | ||
border-radius: 50%; | ||
outline: 0; | ||
border: 3px solid currentColor; | ||
background-color: #fff; | ||
:hover, | ||
&.${sliderUnstyledClasses.focusVisible} { | ||
box-shadow: 0 0 0 0.25rem ${alpha( | ||
theme.palette.mode === 'light' ? blue[400] : blue[300], | ||
0.15, | ||
)}; | ||
} | ||
& .label { | ||
background: unset; | ||
background-color: ${theme.palette.mode === 'light' ? blue[500] : blue[300]}; | ||
width: 32px; | ||
height: 32px; | ||
padding: 0px; | ||
visibility: hidden; | ||
color: #fff; | ||
border-radius: 50% 50% 50% 0; | ||
position: absolute; | ||
transform: translate(-35%, -140%) rotate(-45deg) scale(0); | ||
transition: transform 0.3s ease; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
:hover .label { | ||
visibility: visible; | ||
transform: translate(-35%, -140%) rotate(-45deg) scale(1); | ||
} | ||
:hover .value { | ||
transform: rotate(45deg); | ||
text-align: center; | ||
} | ||
&.${sliderUnstyledClasses.active} { | ||
box-shadow: 0 0 0 0.25rem ${alpha( | ||
theme.palette.mode === 'light' ? blue[200] : blue[300], | ||
0.3, | ||
)}; | ||
} | ||
} | ||
`, | ||
); | ||
|
||
function SliderValueLabel({ children }) { | ||
return ( | ||
<span className="label"> | ||
<div className="value">{children}</div> | ||
</span> | ||
); | ||
} | ||
|
||
SliderValueLabel.propTypes = { | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
export default function LabeledValuesSlider() { | ||
return ( | ||
<Box sx={{ width: 300 }}> | ||
<StyledSlider defaultValue={10} slots={{ valueLabel: SliderValueLabel }} /> | ||
</Box> | ||
); | ||
} |
Oops, something went wrong.