Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: adding a smaller version of the switch for use in the autosave

Ilian Sapundshievefb6df4f7a46
diff --git a/src/renderer/components/TsSwitch.tsx b/src/renderer/components/TsSwitch.tsx
index 3629f4b79..aa95b5728 100644
--- a/src/renderer/components/TsSwitch.tsx
+++ b/src/renderer/components/TsSwitch.tsx
@@ -26,63 +26,70 @@ export type TsSwitchProps = SwitchProps & {
const IOSSwitch = styled((props: SwitchProps) => (
<Switch focusVisibleClassName=".Mui-focusVisible" disableRipple {...props} />
-))(({ theme }) => ({
- width: 42,
- height: 26,
- padding: 0,
- margin: '6px 4px',
- '& .MuiSwitch-switchBase': {
+))(({ theme, size }) => {
+ const small = size === 'small';
+ const width = small ? 28 : 42;
+ const height = small ? 18 : 26;
+ const thumbSize = small ? 14 : 22;
+ const translate = width - thumbSize - 4; // 4 = 2px margin on each side
+ return {
+ width,
+ height,
padding: 0,
- margin: 2,
- transitionDuration: '300ms',
- '&.Mui-checked': {
- transform: 'translateX(16px)',
- color: '#fff',
- '& + .MuiSwitch-track': {
- backgroundColor: theme.palette.primary.main,
- opacity: 1,
- border: 0,
+ margin: small ? '4px 3px' : '6px 4px',
+ '& .MuiSwitch-switchBase': {
+ padding: 0,
+ margin: 2,
+ transitionDuration: '300ms',
+ '&.Mui-checked': {
+ transform: `translateX(${translate}px)`,
+ color: '#fff',
+ '& + .MuiSwitch-track': {
+ backgroundColor: theme.palette.primary.main,
+ opacity: 1,
+ border: 0,
+ },
+ '&.Mui-disabled + .MuiSwitch-track': {
+ opacity: 0.5,
+ },
+ },
+ '&.Mui-focusVisible .MuiSwitch-thumb': {
+ color: theme.palette.primary.light,
+ border: '6px solid #fff',
+ },
+ '&.Mui-disabled .MuiSwitch-thumb': {
+ color: theme.palette.grey[100],
+ ...theme.applyStyles('dark', {
+ color: theme.palette.grey[600],
+ }),
},
'&.Mui-disabled + .MuiSwitch-track': {
- opacity: 0.5,
+ opacity: 0.7,
+ ...theme.applyStyles('dark', {
+ opacity: 0.3,
+ }),
},
},
- '&.Mui-focusVisible .MuiSwitch-thumb': {
- color: theme.palette.primary.light,
- border: '6px solid #fff',
+ '& .MuiSwitch-thumb': {
+ boxSizing: 'border-box',
+ width: thumbSize,
+ height: thumbSize,
},
- '&.Mui-disabled .MuiSwitch-thumb': {
- color: theme.palette.grey[100],
- ...theme.applyStyles('dark', {
- color: theme.palette.grey[600],
+ '& .MuiSwitch-track': {
+ boxSizing: 'border-box',
+ borderRadius: height / 2,
+ backgroundColor: '#E9E9EA',
+ opacity: 1,
+ transition: theme.transitions.create(['background-color'], {
+ duration: 500,
}),
- },
- '&.Mui-disabled + .MuiSwitch-track': {
- opacity: 0.7,
...theme.applyStyles('dark', {
- opacity: 0.3,
+ backgroundColor: '#39393D',
+ border: `1px solid ${theme.palette.divider}`,
}),
},
- },
- '& .MuiSwitch-thumb': {
- boxSizing: 'border-box',
- width: 22,
- height: 22,
- },
- '& .MuiSwitch-track': {
- boxSizing: 'border-box',
- borderRadius: 26 / 2,
- backgroundColor: '#E9E9EA',
- opacity: 1,
- transition: theme.transitions.create(['background-color'], {
- duration: 500,
- }),
- ...theme.applyStyles('dark', {
- backgroundColor: '#39393D',
- border: `1px solid ${theme.palette.divider}`,
- }),
- },
-}));
+ };
+});
function TsSwitch(props: TsSwitchProps) {
const { tooltip, ...rest } = props;