From 673626bc474ed187375ae402262005929d7fc5b1 Mon Sep 17 00:00:00 2001 From: Daniel Bretzigheimer Date: Mon, 3 May 2021 23:00:32 +0200 Subject: [PATCH 1/2] [docs] Added new customized switch examples --- .../components/switches/CustomizedSwitches.js | 100 ++++++++++++++++-- .../switches/CustomizedSwitches.tsx | 100 ++++++++++++++++-- 2 files changed, 184 insertions(+), 16 deletions(-) diff --git a/docs/src/pages/components/switches/CustomizedSwitches.js b/docs/src/pages/components/switches/CustomizedSwitches.js index 1dcb8778462c5a..813614d9c6daf9 100644 --- a/docs/src/pages/components/switches/CustomizedSwitches.js +++ b/docs/src/pages/components/switches/CustomizedSwitches.js @@ -14,31 +14,46 @@ const IOSSwitch = styled((props) => ( padding: 0, margin: theme.spacing(1), '& .MuiSwitch-switchBase': { - padding: 1, + padding: 0, + margin: 2, + transitionDuration: '300ms', '&.Mui-checked': { transform: 'translateX(16px)', color: theme.palette.common.white, '& + .MuiSwitch-track': { - backgroundColor: '#52d869', + backgroundColor: '#65C466', opacity: 1, border: 0, }, + '&.Mui-disabled + .MuiSwitch-track': { + opacity: 0.5, + }, }, '&.Mui-focusVisible .MuiSwitch-thumb': { - color: '#52d869', + color: '#33cf4d', border: '6px solid #fff', }, + '&.Mui-disabled .MuiSwitch-thumb': { + color: + theme.palette.mode === 'light' + ? theme.palette.grey[100] + : theme.palette.grey[600], + }, + '&.Mui-disabled + .MuiSwitch-track': { + opacity: theme.palette.mode === 'light' ? 0.7 : 0.3, + }, }, '& .MuiSwitch-thumb': { - width: 24, - height: 24, + width: 22, + height: 22, }, '& .MuiSwitch-track': { borderRadius: 26 / 2, - border: `1px solid ${theme.palette.grey[400]}`, - backgroundColor: theme.palette.grey[50], + backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D', opacity: 1, - transition: theme.transitions.create(['background-color', 'border-color']), + transition: theme.transitions.create(['background-color'], { + duration: 500, + }), }, })); @@ -73,9 +88,78 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ }, })); +const Android12Switch = styled(Switch)(({ theme }) => ({ + padding: 8, + '& .MuiSwitch-track': { + borderRadius: 14, + '&:before, &:after': { + content: '""', + position: 'absolute', + top: '50%', + transform: 'translateY(-50%)', + width: 16, + height: 16, + }, + '&:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + left: 12, + }, + '&:after': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + right: 12, + }, + }, + '& .MuiSwitch-thumb': { + boxShadow: 'none', + width: 16, + height: 16, + margin: 2, + }, +})); + +const ThumbIconSwitch = styled(Switch)(({ theme }) => ({ + '& .MuiSwitch-thumb:before': { + content: "''", + position: 'absolute', + width: '100%', + height: '100%', + left: 0, + top: 0, + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center', + opacity: 0.8, + }, + '& .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + '& .MuiSwitch-switchBase:not(.Mui-checked) .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, +})); + export default function CustomizedSwitches() { return ( + } + label="Thumb with Icon" + /> + } + label="Android 12" + /> } label="iOS style" /> Off diff --git a/docs/src/pages/components/switches/CustomizedSwitches.tsx b/docs/src/pages/components/switches/CustomizedSwitches.tsx index 9dd13b3265d92d..99ebd673d6e2b2 100644 --- a/docs/src/pages/components/switches/CustomizedSwitches.tsx +++ b/docs/src/pages/components/switches/CustomizedSwitches.tsx @@ -14,31 +14,46 @@ const IOSSwitch = styled((props: SwitchProps) => ( padding: 0, margin: theme.spacing(1), '& .MuiSwitch-switchBase': { - padding: 1, + padding: 0, + margin: 2, + transitionDuration: '300ms', '&.Mui-checked': { transform: 'translateX(16px)', color: theme.palette.common.white, '& + .MuiSwitch-track': { - backgroundColor: '#52d869', + backgroundColor: '#65C466', opacity: 1, border: 0, }, + '&.Mui-disabled + .MuiSwitch-track': { + opacity: 0.5, + }, }, '&.Mui-focusVisible .MuiSwitch-thumb': { - color: '#52d869', + color: '#33cf4d', border: '6px solid #fff', }, + '&.Mui-disabled .MuiSwitch-thumb': { + color: + theme.palette.mode === 'light' + ? theme.palette.grey[100] + : theme.palette.grey[600], + }, + '&.Mui-disabled + .MuiSwitch-track': { + opacity: theme.palette.mode === 'light' ? 0.7 : 0.3, + }, }, '& .MuiSwitch-thumb': { - width: 24, - height: 24, + width: 22, + height: 22, }, '& .MuiSwitch-track': { borderRadius: 26 / 2, - border: `1px solid ${theme.palette.grey[400]}`, - backgroundColor: theme.palette.grey[50], + backgroundColor: theme.palette.mode === 'light' ? '#E9E9EA' : '#39393D', opacity: 1, - transition: theme.transitions.create(['background-color', 'border-color']), + transition: theme.transitions.create(['background-color'], { + duration: 500, + }), }, })); @@ -73,9 +88,78 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ }, })); +const Android12Switch = styled(Switch)(({ theme }) => ({ + padding: 8, + '& .MuiSwitch-track': { + borderRadius: 14, + '&:before, &:after': { + content: '""', + position: 'absolute', + top: '50%', + transform: 'translateY(-50%)', + width: 16, + height: 16, + }, + '&:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + left: 12, + }, + '&:after': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + right: 12, + }, + }, + '& .MuiSwitch-thumb': { + boxShadow: 'none', + width: 16, + height: 16, + margin: 2, + }, +})); + +const ThumbIconSwitch = styled(Switch)(({ theme }) => ({ + '& .MuiSwitch-thumb:before': { + content: "''", + position: 'absolute', + width: '100%', + height: '100%', + left: 0, + top: 0, + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center', + opacity: 0.8, + }, + '& .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + '& .MuiSwitch-switchBase:not(.Mui-checked) .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, +})); + export default function CustomizedSwitches() { return ( + } + label="Thumb with Icon" + /> + } + label="Android 12" + /> } label="iOS style" /> Off From 32ff12455587b20e9880743f0e252024e6370352 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Wed, 5 May 2021 20:39:09 +0200 Subject: [PATCH 2/2] push one step further --- .../components/switches/CustomizedSwitches.js | 159 ++++++++++-------- .../switches/CustomizedSwitches.tsx | 159 ++++++++++-------- 2 files changed, 182 insertions(+), 136 deletions(-) diff --git a/docs/src/pages/components/switches/CustomizedSwitches.js b/docs/src/pages/components/switches/CustomizedSwitches.js index 813614d9c6daf9..4502784c0e5363 100644 --- a/docs/src/pages/components/switches/CustomizedSwitches.js +++ b/docs/src/pages/components/switches/CustomizedSwitches.js @@ -6,20 +6,99 @@ import Switch from '@material-ui/core/Switch'; import Stack from '@material-ui/core/Stack'; import Typography from '@material-ui/core/Typography'; +const MaterialUISwitch = styled(Switch)({ + width: 62, + height: 34, + padding: 7, + '& .MuiSwitch-switchBase': { + margin: 1, + padding: 0, + transform: 'translateX(6px)', + '&.Mui-checked': { + color: '#fff', + transform: 'translateX(22px)', + '& .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + '& + .MuiSwitch-track': { + opacity: 1, + backgroundColor: '#aab4be', + }, + }, + }, + '& .MuiSwitch-thumb': { + backgroundColor: '#001e3c', + width: 32, + height: 32, + '&:before': { + content: "''", + position: 'absolute', + width: '100%', + height: '100%', + left: 0, + top: 0, + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center', + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + }, + '& .MuiSwitch-track': { + opacity: 1, + backgroundColor: '#aab4be', + borderRadius: 20 / 2, + }, +}); + +const Android12Switch = styled(Switch)(({ theme }) => ({ + padding: 8, + '& .MuiSwitch-track': { + borderRadius: 22 / 2, + '&:before, &:after': { + content: '""', + position: 'absolute', + top: '50%', + transform: 'translateY(-50%)', + width: 16, + height: 16, + }, + '&:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + left: 12, + }, + '&:after': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + right: 12, + }, + }, + '& .MuiSwitch-thumb': { + boxShadow: 'none', + width: 16, + height: 16, + margin: 2, + }, +})); + const IOSSwitch = styled((props) => ( ))(({ theme }) => ({ width: 42, height: 26, padding: 0, - margin: theme.spacing(1), '& .MuiSwitch-switchBase': { padding: 0, margin: 2, transitionDuration: '300ms', '&.Mui-checked': { transform: 'translateX(16px)', - color: theme.palette.common.white, + color: '#fff', '& + .MuiSwitch-track': { backgroundColor: '#65C466', opacity: 1, @@ -44,6 +123,7 @@ const IOSSwitch = styled((props) => ( }, }, '& .MuiSwitch-thumb': { + boxSizing: 'border-box', width: 22, height: 22, }, @@ -67,7 +147,7 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ color: theme.palette.grey[500], '&.Mui-checked': { transform: 'translateX(12px)', - color: theme.palette.common.white, + color: '#fff', '& + .MuiSwitch-track': { opacity: 1, backgroundColor: theme.palette.primary.main, @@ -84,68 +164,8 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ border: `1px solid ${theme.palette.grey[500]}`, borderRadius: 16 / 2, opacity: 1, - backgroundColor: theme.palette.common.white, - }, -})); - -const Android12Switch = styled(Switch)(({ theme }) => ({ - padding: 8, - '& .MuiSwitch-track': { - borderRadius: 14, - '&:before, &:after': { - content: '""', - position: 'absolute', - top: '50%', - transform: 'translateY(-50%)', - width: 16, - height: 16, - }, - '&:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - left: 12, - }, - '&:after': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - right: 12, - }, - }, - '& .MuiSwitch-thumb': { - boxShadow: 'none', - width: 16, - height: 16, - margin: 2, - }, -})); - -const ThumbIconSwitch = styled(Switch)(({ theme }) => ({ - '& .MuiSwitch-thumb:before': { - content: "''", - position: 'absolute', - width: '100%', - height: '100%', - left: 0, - top: 0, - backgroundRepeat: 'no-repeat', - backgroundPosition: 'center', - opacity: 0.8, - }, - '& .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - }, - '& .MuiSwitch-switchBase:not(.Mui-checked) .MuiSwitch-thumb:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, + backgroundColor: '#fff', + boxSizing: 'border-box', }, })); @@ -153,14 +173,17 @@ export default function CustomizedSwitches() { return ( } - label="Thumb with Icon" + control={} + label="Material-UI switch" /> } label="Android 12" /> - } label="iOS style" /> + } + label="iOS style" + /> Off diff --git a/docs/src/pages/components/switches/CustomizedSwitches.tsx b/docs/src/pages/components/switches/CustomizedSwitches.tsx index 99ebd673d6e2b2..c2bf6a6490ca21 100644 --- a/docs/src/pages/components/switches/CustomizedSwitches.tsx +++ b/docs/src/pages/components/switches/CustomizedSwitches.tsx @@ -6,20 +6,99 @@ import Switch, { SwitchProps } from '@material-ui/core/Switch'; import Stack from '@material-ui/core/Stack'; import Typography from '@material-ui/core/Typography'; +const MaterialUISwitch = styled(Switch)({ + width: 62, + height: 34, + padding: 7, + '& .MuiSwitch-switchBase': { + margin: 1, + padding: 0, + transform: 'translateX(6px)', + '&.Mui-checked': { + color: '#fff', + transform: 'translateX(22px)', + '& .MuiSwitch-thumb:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + '& + .MuiSwitch-track': { + opacity: 1, + backgroundColor: '#aab4be', + }, + }, + }, + '& .MuiSwitch-thumb': { + backgroundColor: '#001e3c', + width: 32, + height: 32, + '&:before': { + content: "''", + position: 'absolute', + width: '100%', + height: '100%', + left: 0, + top: 0, + backgroundRepeat: 'no-repeat', + backgroundPosition: 'center', + backgroundImage: `url('data:image/svg+xml;utf8,')`, + }, + }, + '& .MuiSwitch-track': { + opacity: 1, + backgroundColor: '#aab4be', + borderRadius: 20 / 2, + }, +}); + +const Android12Switch = styled(Switch)(({ theme }) => ({ + padding: 8, + '& .MuiSwitch-track': { + borderRadius: 22 / 2, + '&:before, &:after': { + content: '""', + position: 'absolute', + top: '50%', + transform: 'translateY(-50%)', + width: 16, + height: 16, + }, + '&:before': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + left: 12, + }, + '&:after': { + backgroundImage: `url('data:image/svg+xml;utf8,')`, + right: 12, + }, + }, + '& .MuiSwitch-thumb': { + boxShadow: 'none', + width: 16, + height: 16, + margin: 2, + }, +})); + const IOSSwitch = styled((props: SwitchProps) => ( ))(({ theme }) => ({ width: 42, height: 26, padding: 0, - margin: theme.spacing(1), '& .MuiSwitch-switchBase': { padding: 0, margin: 2, transitionDuration: '300ms', '&.Mui-checked': { transform: 'translateX(16px)', - color: theme.palette.common.white, + color: '#fff', '& + .MuiSwitch-track': { backgroundColor: '#65C466', opacity: 1, @@ -44,6 +123,7 @@ const IOSSwitch = styled((props: SwitchProps) => ( }, }, '& .MuiSwitch-thumb': { + boxSizing: 'border-box', width: 22, height: 22, }, @@ -67,7 +147,7 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ color: theme.palette.grey[500], '&.Mui-checked': { transform: 'translateX(12px)', - color: theme.palette.common.white, + color: '#fff', '& + .MuiSwitch-track': { opacity: 1, backgroundColor: theme.palette.primary.main, @@ -84,68 +164,8 @@ const AntSwitch = styled(Switch)(({ theme }) => ({ border: `1px solid ${theme.palette.grey[500]}`, borderRadius: 16 / 2, opacity: 1, - backgroundColor: theme.palette.common.white, - }, -})); - -const Android12Switch = styled(Switch)(({ theme }) => ({ - padding: 8, - '& .MuiSwitch-track': { - borderRadius: 14, - '&:before, &:after': { - content: '""', - position: 'absolute', - top: '50%', - transform: 'translateY(-50%)', - width: 16, - height: 16, - }, - '&:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - left: 12, - }, - '&:after': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - right: 12, - }, - }, - '& .MuiSwitch-thumb': { - boxShadow: 'none', - width: 16, - height: 16, - margin: 2, - }, -})); - -const ThumbIconSwitch = styled(Switch)(({ theme }) => ({ - '& .MuiSwitch-thumb:before': { - content: "''", - position: 'absolute', - width: '100%', - height: '100%', - left: 0, - top: 0, - backgroundRepeat: 'no-repeat', - backgroundPosition: 'center', - opacity: 0.8, - }, - '& .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, - }, - '& .MuiSwitch-switchBase:not(.Mui-checked) .MuiSwitch-thumb:before': { - backgroundImage: `url('data:image/svg+xml;utf8,')`, + backgroundColor: '#fff', + boxSizing: 'border-box', }, })); @@ -153,14 +173,17 @@ export default function CustomizedSwitches() { return ( } - label="Thumb with Icon" + control={} + label="Material-UI switch" /> } label="Android 12" /> - } label="iOS style" /> + } + label="iOS style" + /> Off