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
115 changes: 115 additions & 0 deletions docs/data/base/components/slider/DiscreteSlider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled 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;
}

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

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

& .MuiSlider-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;
}

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

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

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

}

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

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

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>
);
}
115 changes: 115 additions & 0 deletions docs/data/base/components/slider/DiscreteSlider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled 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;
}

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

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

& .MuiSlider-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;
}

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

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

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

}

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

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

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}
/>
131 changes: 131 additions & 0 deletions docs/data/base/components/slider/DiscreteSliderMarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import SliderUnstyled 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;
}

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

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

& .MuiSlider-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;
}

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

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

& .MuiSlider-markLabel {
font-family: IBM Plex Sans;
font-size: 14px;
position: absolute;
white-space: nowrap;
top: 30px;
-webkit-transform: translateX(-50%);
-moz-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%);
}

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

&.Mui-active {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? '#1976d2' : '#90caf9',
0.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 DiscreteSliderMarks() {
return (
<Box sx={{ width: 300 }}>
<StyledSlider
aria-label="Temperature"
defaultValue={37}
getAriaValueText={valuetext}
marks={marks}
/>
</Box>
);
}
Loading