-
Notifications
You must be signed in to change notification settings - Fork 0
/
tailwind-scrollbar.cjs
111 lines (101 loc) · 3.07 KB
/
tailwind-scrollbar.cjs
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
// https://gist.github.com/parafeu/3cf1c52d374a52091a685ce030563411
const plugin = require("tailwindcss/plugin");
module.exports = plugin(function ({ addUtilities, matchUtilities, theme }) {
const scrollbarTrackColorValue = (value) => ({
"--scrollbar-track": value,
"&::-webkit-scrollbar-track": {
"background-color": value,
},
});
const scrollbarTrackRoundedValue = (value) => ({
"&::-webkit-scrollbar-track": {
"border-radius": value,
},
});
const scrollbarThumbColorValue = (value) => ({
"--scrollbar-thumb": value,
"&::-webkit-scrollbar-thumb": {
"background-color": value,
},
});
const scrollbarThumbRoundedValue = (value) => ({
"&::-webkit-scrollbar-thumb": {
"border-radius": value,
},
});
const scrollbarCornerColorValue = (value) => ({
"&::-webkit-scrollbar-corner": {
"background-color": value,
},
});
const scrollbarCornerRoundedValue = (value) => ({
"&::-webkit-scrollbar-corner": {
"border-radius": value,
},
});
addUtilities({
".scrollbar": {
"--scrollbar-thumb": "#cdcdcd",
"--scrollbar-track": "#f0f0f0",
"--scrollbar-corner": "#f0f0f0",
"--scrollbar-width": "17px",
"scrollbar-color":
"var(--scrollbar-thumb) var(--scrollbar-track) var(--scrollbar-corner)",
"&::-webkit-scrollbar": {
width: "var(--scrollbar-width)",
height: "var(--scrollbar-width)",
},
},
".scrollbar-thin": {
"--scrollbar-width": "8px",
"scrollbar-width": "thin",
},
});
Object.entries(theme("colors")).forEach(([colorName, color]) => {
switch (typeof color) {
case "object":
matchUtilities(
{
[`scrollbar-track-${colorName}`]: (value) =>
scrollbarTrackColorValue(value),
[`scrollbar-thumb-${colorName}`]: (value) =>
scrollbarThumbColorValue(value),
[`scrollbar-corner-${colorName}`]: (value) =>
scrollbarCornerColorValue(value),
},
{
values: color,
}
);
break;
case "function":
addUtilities({
[`.scrollbar-track-${colorName}`]: scrollbarTrackColorValue(
color({})
),
[`.scrollbar-thumb-${colorName}`]: scrollbarThumbColorValue(
color({})
),
[`scrollbar-corner-${colorName}`]: scrollbarCornerColorValue({}),
});
break;
case "string":
addUtilities({
[`.scrollbar-track-${colorName}`]: scrollbarTrackColorValue(color),
[`.scrollbar-thumb-${colorName}`]: scrollbarThumbColorValue(color),
[`.scrollbar-corner-${colorName}`]: scrollbarCornerColorValue(color),
});
break;
}
});
matchUtilities(
{
"scrollbar-track-rounded": (value) => scrollbarTrackRoundedValue(value),
"scrollbar-thumb-rounded": (value) => scrollbarThumbRoundedValue(value),
"scrollbar-corner-rounded": (value) => scrollbarCornerRoundedValue(value),
},
{
values: theme("borderRadius"),
}
);
});