/
Alert.styles.ts
123 lines (107 loc) · 2.62 KB
/
Alert.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
import {
createStyles,
CSSObject,
MantineColor,
MantineNumberSize,
MantineTheme,
} from '@mantine/styles';
type AlertVariant = 'filled' | 'outline' | 'light';
export interface AlertStylesParams {
color: MantineColor;
radius: MantineNumberSize;
variant: AlertVariant;
}
interface GetVariantStylesInput {
variant: AlertVariant;
color: MantineColor;
theme: MantineTheme;
}
function getVariantStyles({ variant, color, theme }: GetVariantStylesInput): CSSObject {
if (variant === 'filled') {
const colors = theme.fn.variant({ variant: 'filled', color });
return {
backgroundColor: colors.background,
color: theme.white,
};
}
if (variant === 'outline') {
const colors = theme.fn.variant({ variant: 'outline', color });
return {
color: colors.color,
borderColor: colors.border,
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.white,
};
}
const colors = theme.fn.variant({ variant: 'light', color });
return {
backgroundColor: colors.background,
color: colors.color,
};
}
export default createStyles((theme, { color, radius, variant }: AlertStylesParams) => ({
root: {
...theme.fn.fontStyles(),
position: 'relative',
overflow: 'hidden',
padding: `${theme.spacing.sm}px ${theme.spacing.md}px`,
borderRadius: theme.fn.radius(radius),
border: '1px solid transparent',
...getVariantStyles({ variant, color, theme }),
},
wrapper: {
display: 'flex',
},
body: {
flex: 1,
},
title: {
boxSizing: 'border-box',
margin: 0,
marginBottom: 7,
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
lineHeight: theme.lineHeight,
fontSize: theme.fontSizes.sm,
fontWeight: 700,
'&[data-with-close-button]': {
paddingRight: theme.spacing.md,
},
},
label: {
display: 'block',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
icon: {
lineHeight: 1,
width: 20,
height: 20,
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-start',
marginRight: theme.spacing.md,
marginTop: 1,
},
message: {
...theme.fn.fontStyles(),
lineHeight: theme.lineHeight,
textOverflow: 'ellipsis',
overflow: 'hidden',
fontSize: theme.fontSizes.sm,
color:
variant === 'filled'
? theme.white
: theme.colorScheme === 'dark'
? variant === 'light'
? theme.white
: theme.colors.dark[0]
: theme.black,
},
closeButton: {
position: 'absolute',
top: theme.spacing.sm,
right: theme.spacing.sm,
color: 'inherit',
},
}));