-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ActionIcon.styles.ts
126 lines (111 loc) · 2.95 KB
/
ActionIcon.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
119
120
121
122
123
124
125
126
import {
createStyles,
MantineNumberSize,
MantineColor,
MantineTheme,
MantineGradient,
} from '@mantine/styles';
export const ACTION_ICON_VARIANTS = [
'subtle',
'filled',
'outline',
'light',
'default',
'transparent',
'gradient',
] as const;
export type ActionIconVariant = typeof ACTION_ICON_VARIANTS[number];
export interface ActionIconStylesParams {
color: MantineColor;
size: MantineNumberSize;
radius: MantineNumberSize;
variant: ActionIconVariant;
gradient: MantineGradient;
}
export const sizes = {
xs: 18,
sm: 22,
md: 28,
lg: 34,
xl: 44,
};
interface GetVariantStyles {
variant: ActionIconVariant;
theme: MantineTheme;
color: MantineColor;
gradient: MantineGradient;
}
function getVariantStyles({ variant, theme, color, gradient }: GetVariantStyles) {
const colors = theme.fn.variant({ color, variant, gradient });
if (variant === 'gradient') {
return {
border: 0,
backgroundImage: colors.background,
color: colors.color,
'&:hover': theme.fn.hover({
backgroundSize: '200%',
}),
};
}
return {
border: `1px solid ${colors.border}`,
backgroundColor: colors.background,
color: colors.color,
...theme.fn.hover({
backgroundColor: colors.hover,
}),
};
}
export default createStyles(
(theme, { color, size, radius, variant, gradient }: ActionIconStylesParams) => ({
root: {
...getVariantStyles({ variant, theme, color, gradient }),
position: 'relative',
height: theme.fn.size({ size, sizes }),
minHeight: theme.fn.size({ size, sizes }),
width: theme.fn.size({ size, sizes }),
minWidth: theme.fn.size({ size, sizes }),
borderRadius: theme.fn.radius(radius),
padding: 0,
lineHeight: 1,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
'&:active': theme.activeStyles,
'&:disabled, &[data-disabled]': {
color: theme.colors.gray[theme.colorScheme === 'dark' ? 6 : 4],
cursor: 'not-allowed',
backgroundColor:
variant === 'transparent'
? undefined
: theme.fn.themeColor('gray', theme.colorScheme === 'dark' ? 8 : 1),
borderColor:
variant === 'transparent'
? undefined
: theme.fn.themeColor('gray', theme.colorScheme === 'dark' ? 8 : 1),
backgroundImage: 'none',
pointerEvents: 'none',
'&:active': {
transform: 'none',
},
},
'&[data-loading]': {
pointerEvents: 'none',
'&::before': {
content: '""',
position: 'absolute',
top: -1,
left: -1,
right: -1,
bottom: -1,
backgroundColor:
theme.colorScheme === 'dark'
? theme.fn.rgba(theme.colors.dark[7], 0.5)
: 'rgba(255, 255, 255, .5)',
borderRadius: theme.fn.radius(radius),
cursor: 'not-allowed',
},
},
},
})
);