Skip to content
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

[docs] Create SliderUnstyled docs #31850

Merged
merged 13 commits into from
Mar 29, 2022
Merged
120 changes: 120 additions & 0 deletions docs/data/base/components/slider/DiscreteSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled, { sliderUnstyledClasses } from '@mui/base/SliderUnstyled';

const StyledSlider = styled(SliderUnstyled)(
Copy link
Member

Choose a reason for hiding this comment

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

We should improve the hover styles:

image

Also, we need a focus visible styles on the thumb, there is not indication that it is focused.

({ theme }) => `
color: ${theme.palette.mode === 'light' ? '#1976d2' : '#90caf9'};
height: 4px;
width: 100%;
padding: 13px 0;
display: inline-block;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
opacity: 0.75;

&:hover {
opacity: 1;
}

&.${sliderUnstyledClasses.disabled} {
pointer-events: none;
cursor: default;
color: #bdbdbd;
}

& .${sliderUnstyledClasses.rail} {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 2px;
background-color: currentColor;
opacity: 0.38;
}

& .${sliderUnstyledClasses.track} {
display: block;
position: absolute;
height: 4px;
border-radius: 2px;
background-color: currentColor;
}

& .${sliderUnstyledClasses.thumb} {
position: absolute;
width: 14px;
height: 14px;
margin-left: -6px;
margin-top: -5px;
box-sizing: border-box;
border-radius: 50%;
outline: 0;
border: 2px solid currentColor;
background-color: #fff;

:hover,
&.${sliderUnstyledClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.15,
)};
}

&.${sliderUnstyledClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.3,
)};
}
}

& .${sliderUnstyledClasses.mark} {
position: absolute;
width: 4px;
height: 4px;
border-radius: 2px;
background-color: currentColor;
top: 50%;
opacity: 0.7;
transform: translateX(-50%);
}

& .${sliderUnstyledClasses.markActive} {
background-color: #fff;
}

& .${sliderUnstyledClasses.valueLabel} {
font-family: IBM Plex Sans;
font-size: 14px;
display: block;
position: relative;
top: -1.6em;
text-align: center;
transform: translateX(-50%);
}
`,
);

function valuetext(value) {
return `${value}°C`;
}

export default function DiscreteSlider() {
return (
<Box sx={{ width: 300 }}>
<StyledSlider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
</Box>
);
}
120 changes: 120 additions & 0 deletions docs/data/base/components/slider/DiscreteSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled, { sliderUnstyledClasses } from '@mui/base/SliderUnstyled';

const StyledSlider = styled(SliderUnstyled)(
({ theme }) => `
color: ${theme.palette.mode === 'light' ? '#1976d2' : '#90caf9'};
height: 4px;
width: 100%;
padding: 13px 0;
display: inline-block;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
opacity: 0.75;

&:hover {
opacity: 1;
}

&.${sliderUnstyledClasses.disabled} {
pointer-events: none;
cursor: default;
color: #bdbdbd;
}

& .${sliderUnstyledClasses.rail} {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 2px;
background-color: currentColor;
opacity: 0.38;
}

& .${sliderUnstyledClasses.track} {
display: block;
position: absolute;
height: 4px;
border-radius: 2px;
background-color: currentColor;
}

& .${sliderUnstyledClasses.thumb} {
position: absolute;
width: 14px;
height: 14px;
margin-left: -6px;
margin-top: -5px;
box-sizing: border-box;
border-radius: 50%;
outline: 0;
border: 2px solid currentColor;
background-color: #fff;

:hover,
&.${sliderUnstyledClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.15,
)};
}

&.${sliderUnstyledClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.3,
)};
}
}

& .${sliderUnstyledClasses.mark} {
position: absolute;
width: 4px;
height: 4px;
border-radius: 2px;
background-color: currentColor;
top: 50%;
opacity: 0.7;
transform: translateX(-50%);
}

& .${sliderUnstyledClasses.markActive} {
background-color: #fff;
}

& .${sliderUnstyledClasses.valueLabel} {
font-family: IBM Plex Sans;
font-size: 14px;
display: block;
position: relative;
top: -1.6em;
text-align: center;
transform: translateX(-50%);
}
`,
);

function valuetext(value: number) {
return `${value}°C`;
}

export default function DiscreteSlider() {
return (
<Box sx={{ width: 300 }}>
<StyledSlider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
</Box>
);
}
10 changes: 10 additions & 0 deletions docs/data/base/components/slider/DiscreteSlider.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<StyledSlider
aria-label="Temperature"
defaultValue={30}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
step={10}
marks
min={10}
max={110}
/>
143 changes: 143 additions & 0 deletions docs/data/base/components/slider/DiscreteSliderMarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled, { sliderUnstyledClasses } from '@mui/base/SliderUnstyled';

const StyledSlider = styled(SliderUnstyled)(
({ theme }) => `
color: ${theme.palette.mode === 'light' ? '#1976d2' : '#90caf9'};
height: 4px;
width: 100%;
padding: 13px 0;
display: inline-block;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
opacity: 0.75;

&:hover {
opacity: 1;
}

&.${sliderUnstyledClasses.disabled} {
pointer-events: none;
cursor: default;
color: #bdbdbd;
}

& .${sliderUnstyledClasses.rail} {
display: block;
position: absolute;
width: 100%;
height: 4px;
border-radius: 2px;
background-color: currentColor;
opacity: 0.38;
}

& .${sliderUnstyledClasses.track} {
display: block;
position: absolute;
height: 4px;
border-radius: 2px;
background-color: currentColor;
}

& .${sliderUnstyledClasses.thumb} {
position: absolute;
width: 14px;
height: 14px;
margin-left: -6px;
margin-top: -5px;
box-sizing: border-box;
border-radius: 50%;
outline: 0;
border: 2px solid currentColor;
background-color: #fff;

:hover,
&.${sliderUnstyledClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.15,
)};
}

&.${sliderUnstyledClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.3,
)};
}
}

& .${sliderUnstyledClasses.mark} {
position: absolute;
width: 4px;
height: 4px;
border-radius: 2px;
background-color: currentColor;
top: 50%;
opacity: 0.7;
transform: translateX(-50%);
}

& .${sliderUnstyledClasses.markActive} {
background-color: #fff;
}

& .${sliderUnstyledClasses.valueLabel} {
font-family: IBM Plex Sans;
font-size: 14px;
display: block;
position: relative;
top: -1.6em;
text-align: center;
transform: translateX(-50%);
}

& .${sliderUnstyledClasses.markLabel} {
font-family: IBM Plex Sans;
font-size: 12px;
position: absolute;
top: 20px;
transform: translateX(-50%);
}
`,
);

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 }}>
<StyledSlider
aria-label="Temperature"
defaultValue={37}
getAriaValueText={valuetext}
marks={marks}
/>
</Box>
);
}
Loading