-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Checkbox.styles.ts
118 lines (104 loc) · 3.2 KB
/
Checkbox.styles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { createStyles, MantineSize, MantineColor, MantineNumberSize } from '@mantine/styles';
const sizes = {
xs: 16,
sm: 20,
md: 24,
lg: 30,
xl: 36,
};
const iconSizes = {
xs: 8,
sm: 10,
md: 14,
lg: 16,
xl: 20,
};
export interface CheckboxStylesParams {
size: MantineSize;
radius: MantineNumberSize;
color: MantineColor;
transitionDuration: number;
}
export default createStyles(
(theme, { size, radius, color, transitionDuration }: CheckboxStylesParams, getRef) => {
const _size = theme.fn.size({ size, sizes });
const colors = theme.fn.variant({ variant: 'filled', color });
return {
icon: {
ref: getRef('icon'),
color: theme.white,
transform: 'translateY(5px) scale(0.5)',
opacity: 0,
transitionProperty: 'opacity, transform',
transitionTimingFunction: 'ease',
transitionDuration: `${transitionDuration}ms`,
pointerEvents: 'none',
width: theme.fn.size({ size, sizes: iconSizes }),
position: 'absolute',
zIndex: 1,
top: 0,
bottom: 0,
left: 0,
right: 0,
margin: 'auto',
'@media (prefers-reduced-motion)': {
transitionDuration: theme.respectReducedMotion ? '0ms' : undefined,
},
},
root: {
display: 'flex',
alignItems: 'center',
},
inner: {
position: 'relative',
width: _size,
height: _size,
},
label: {
...theme.fn.fontStyles(),
WebkitTapHighlightColor: 'transparent',
paddingLeft: theme.spacing.sm,
fontSize: theme.fn.size({ size, sizes: theme.fontSizes }),
lineHeight: `${_size}px`,
color: theme.colorScheme === 'dark' ? theme.colors.dark[0] : theme.black,
cursor: theme.cursorType,
'&[data-disabled]': {
color: theme.colorScheme === 'dark' ? theme.colors.dark[3] : theme.colors.gray[5],
},
},
input: {
...theme.fn.focusStyles(),
appearance: 'none',
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.white,
border: `1px solid ${
theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[4]
}`,
width: _size,
height: _size,
borderRadius: theme.fn.radius(radius),
padding: 0,
display: 'block',
margin: 0,
transition: `border-color ${transitionDuration}ms ease, background-color ${transitionDuration}ms ease`,
cursor: theme.cursorType,
'&:checked': {
backgroundColor: colors.background,
borderColor: colors.background,
[`& + .${getRef('icon')}`]: {
opacity: 1,
transform: 'translateY(0) scale(1)',
},
},
'&:disabled': {
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[2],
borderColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[3],
cursor: 'not-allowed',
[`& + .${getRef('icon')}`]: {
color: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[5],
},
},
},
};
}
);