-
Notifications
You must be signed in to change notification settings - Fork 0
/
twClipInset.ts
83 lines (73 loc) · 3.65 KB
/
twClipInset.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
import plugin from 'tailwindcss/plugin';
const splitArgsAtRound = (string: string) => {
let borderRadius = '',
inset = string;
const borderRadiusIndex = string.indexOf('round');
if (borderRadiusIndex >= 0) {
borderRadius = string.slice(borderRadiusIndex);
inset = string.slice(0, borderRadiusIndex);
}
return [inset, borderRadius];
};
// eslint-disable-next-line @typescript-eslint/unbound-method
export default plugin(({ matchUtilities, theme }) => {
matchUtilities(
{
'clip-inset': (insetAll_round: string) => {
const [inset, borderRadius] = splitArgsAtRound(insetAll_round);
return {
'--tw-clip-inset-t': inset,
'--tw-clip-inset-r': inset,
'--tw-clip-inset-b': inset,
'--tw-clip-inset-l': inset,
'clip-path': `inset(var(--tw-clip-inset-t) var(--tw-clip-inset-r) var(--tw-clip-inset-b) var(--tw-clip-inset-l) ${borderRadius});`,
};
},
'clip-inset-t': (insetTop_round: string) => {
const [top, borderRadius] = splitArgsAtRound(insetTop_round);
return {
'--tw-clip-inset-t': top,
'clip-path': `inset(var(--tw-clip-inset-t) var(--tw-clip-inset-r, 0%) var(--tw-clip-inset-b, 0%) var(--tw-clip-inset-l, 0%) ${borderRadius});`,
};
},
'clip-inset-r': (insetRight_round: string) => {
const [right, borderRadius] = splitArgsAtRound(insetRight_round);
return {
'--tw-clip-inset-r': right,
'clip-path': `inset(var(--tw-clip-inset-t, 0%) var(--tw-clip-inset-r) var(--tw-clip-inset-b, 0%) var(--tw-clip-inset-l, 0%) ${borderRadius});`,
};
},
'clip-inset-b': (insetBottom_round: string) => {
const [bottom, borderRadius] = splitArgsAtRound(insetBottom_round);
return {
'--tw-clip-inset-b': bottom,
'clip-path': `inset(var(--tw-clip-inset-t, 0%) var(--tw-clip-inset-r, 0%) var(--tw-clip-inset-b) var(--tw-clip-inset-l, 0%) ${borderRadius}) !important;`,
};
},
'clip-inset-l': (insetLeft_round: string) => {
const [left, borderRadius] = splitArgsAtRound(insetLeft_round);
return {
'--tw-clip-inset-l': left,
'clip-path': `inset(var(--tw-clip-inset-t, 0%) var(--tw-clip-inset-r, 0%) var(--tw-clip-inset-b, 0%) var(--tw-clip-inset-l) ${borderRadius});`,
};
},
'clip-inset-x': (insetHorizontal_round: string) => {
const [horizontal, borderRadius] = splitArgsAtRound(insetHorizontal_round);
return {
'--tw-clip-inset-r': horizontal,
'--tw-clip-inset-l': horizontal,
'clip-path': `inset(var(--tw-clip-inset-t, 0%) var(--tw-clip-inset-r) var(--tw-clip-inset-b, 0%) var(--tw-clip-inset-l) ${borderRadius});`,
};
},
'clip-inset-y': (insetVertical_round: string) => {
const [vertical, borderRadius] = splitArgsAtRound(insetVertical_round);
return {
'--tw-clip-inset-t': vertical,
'--tw-clip-inset-b': vertical,
'clip-path': `inset(var(--tw-clip-inset-t) var(--tw-clip-inset-r, 0%) var(--tw-clip-inset-b) var(--tw-clip-inset-l, 0%) ${borderRadius});`,
};
},
},
{ values: theme('width') },
);
});