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][base] Add Tailwind CSS & plain CSS demo on the Slider page #37736

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
131 changes: 131 additions & 0 deletions docs/data/base/components/slider/UnstyledSliderBasic/css/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import * as React from 'react';
import { useTheme, alpha } from '@mui/system';
import Slider, { sliderClasses } from '@mui/base/Slider';

export default function UnstyledSlider() {
return (
<div style={{ width: 300 }}>
<Slider
slotProps={{
root: { className: 'CustomSlider' },
rail: { className: 'CustomSlider-rail' },
track: { className: 'CustomSlider-track' },
thumb: { className: 'CustomSlider-thumb' },
}}
defaultValue={10}
/>
<Slider
slotProps={{
root: { className: 'CustomSlider' },
rail: { className: 'CustomSlider-rail' },
track: { className: 'CustomSlider-track' },
thumb: { className: 'CustomSlider-thumb' },
}}
defaultValue={10}
disabled
/>
<Styles />
</div>
);
}

const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};

const grey = {
50: '#f6f8fa',
100: '#eaeef2',
200: '#d0d7de',
300: '#afb8c1',
400: '#8c959f',
500: '#6e7781',
600: '#57606a',
700: '#424a53',
800: '#32383f',
900: '#24292f',
};

function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}

function Styles() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<style>{`
.CustomSlider {
color: ${isDarkMode ? cyan[400] : cyan[500]};
height: 6px;
width: 100%;
padding: 16px 0;
display: inline-block;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
}

.CustomSlider:hover {
opacity: 1;
}

.CustomSlider.${sliderClasses.disabled} {
pointer-events: none;
cursor: default;
color: ${isDarkMode ? grey[600] : grey[300]};
opacity: 0.5;
}

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

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

.CustomSlider-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;
}

.CustomSlider-thumb:hover,&.${sliderClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[400], 0.15)};
}

.CustomSlider-thumb.${sliderClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.3)};
}
`}</style>
);
}
131 changes: 131 additions & 0 deletions docs/data/base/components/slider/UnstyledSliderBasic/css/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import * as React from 'react';
import { useTheme, alpha } from '@mui/system';
import Slider, { sliderClasses } from '@mui/base/Slider';

export default function UnstyledSlider() {
return (
<div style={{ width: 300 }}>
<Slider
slotProps={{
root: { className: 'CustomSlider' },
rail: { className: 'CustomSlider-rail' },
track: { className: 'CustomSlider-track' },
thumb: { className: 'CustomSlider-thumb' },
}}
defaultValue={10}
/>
<Slider
slotProps={{
root: { className: 'CustomSlider' },
rail: { className: 'CustomSlider-rail' },
track: { className: 'CustomSlider-track' },
thumb: { className: 'CustomSlider-thumb' },
}}
defaultValue={10}
disabled
/>
<Styles />
</div>
);
}

const cyan = {
50: '#E9F8FC',
100: '#BDEBF4',
200: '#99D8E5',
300: '#66BACC',
400: '#1F94AD',
500: '#0D5463',
600: '#094855',
700: '#063C47',
800: '#043039',
900: '#022127',
};

const grey = {
50: '#f6f8fa',
100: '#eaeef2',
200: '#d0d7de',
300: '#afb8c1',
400: '#8c959f',
500: '#6e7781',
600: '#57606a',
700: '#424a53',
800: '#32383f',
900: '#24292f',
};

function useIsDarkMode() {
const theme = useTheme();
return theme.palette.mode === 'dark';
}

function Styles() {
// Replace this with your app logic for determining dark mode
const isDarkMode = useIsDarkMode();
return (
<style>{`
.CustomSlider {
color: ${isDarkMode ? cyan[400] : cyan[500]};
height: 6px;
width: 100%;
padding: 16px 0;
display: inline-block;
position: relative;
cursor: pointer;
touch-action: none;
-webkit-tap-highlight-color: transparent;
}

.CustomSlider:hover {
opacity: 1;
}

.CustomSlider.${sliderClasses.disabled} {
pointer-events: none;
cursor: default;
color: ${isDarkMode ? grey[600] : grey[300]};
opacity: 0.5;
}

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

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

.CustomSlider-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;
}

.CustomSlider-thumb:hover,&.${sliderClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[400], 0.15)};
}

.CustomSlider-thumb.${sliderClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(isDarkMode ? cyan[300] : cyan[200], 0.3)};
}
`}</style>
);
}
106 changes: 106 additions & 0 deletions docs/data/base/components/slider/UnstyledSliderBasic/system/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import * as React from 'react';
import { styled, alpha, Box } from '@mui/system';
import Slider, { sliderClasses } from '@mui/base/Slider';

export default function UnstyledSlider() {
return (
<Box sx={{ width: 300 }}>
<StyledSlider defaultValue={10} />
<StyledSlider defaultValue={10} disabled />
</Box>
);
}

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(Slider)(
({ theme }) => `
color: ${theme.palette.mode === 'light' ? blue[500] : blue[400]};
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;
}

&.${sliderClasses.disabled} {
pointer-events: none;
cursor: default;
color: ${theme.palette.mode === 'light' ? grey[300] : grey[600]};
opacity: 0.5;
}

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

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

& .${sliderClasses.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,
&.${sliderClasses.focusVisible} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[400] : blue[300],
0.15,
)};
}

&.${sliderClasses.active} {
box-shadow: 0 0 0 0.25rem ${alpha(
theme.palette.mode === 'light' ? blue[200] : blue[300],
0.3,
)};
}
}
`,
);
Loading