Skip to content

Commit 9a77119

Browse files
authored
Merge pull request #2 from gradints/dev
allow configuration from theme in addition to plugin.withOptions
2 parents d06482b + a942c95 commit 9a77119

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

.eslintrc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module.exports = {
44
browser: true,
55
es6: true,
66
},
7+
parserOptions: {
8+
ecmaVersion: 2018,
9+
},
710
rules: {
811
'brace-style': 'warn', // [1tbs default, stroustrup, allman]
912
'comma-dangle': ['warn', 'always-multiline'],
@@ -24,7 +27,4 @@ module.exports = {
2427
'space-infix-ops': ['warn'],
2528
'space-in-parens': ['warn', 'never'],
2629
},
27-
globals: {
28-
process: true,
29-
},
3030
}

README.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Tailwindcss plugin to customize browser scrollbar.
44

5-
![npm (scoped)](https://img.shields.io/npm/v/@gradin/tailwindcss-scrollbar)
5+
[![npm (scoped)](https://img.shields.io/npm/v/@gradin/tailwindcss-scrollbar)](https://www.npmjs.com/package/@gradin/tailwindcss-scrollbar)
66
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/min/@gradin/tailwindcss-scrollbar)
77
![npm](https://img.shields.io/npm/dw/@gradin/tailwindcss-scrollbar)
88

9-
[Live Demo](https://play.tailwindcss.com/SeDSnfsxrR)
9+
[Live Demo](https://play.tailwindcss.com/2Mc2a5IbSY)
1010

1111
## Installation
1212

@@ -18,7 +18,22 @@ npm install -D @gradin/tailwindcss-scrollbar
1818
yarn add -D @gradin/tailwindcss-scrollbar
1919
```
2020

21-
Then add the plugin to `tailwind.config.js` file
21+
Then add the plugin to `tailwind.config.js` file.
22+
23+
```js
24+
module.exports = {
25+
theme: {
26+
// ...
27+
},
28+
plugins: [
29+
require('@gradin/tailwindcss-scrollbar'),
30+
],
31+
}
32+
```
33+
34+
## Configuration
35+
36+
You can customize the size and color of the scrollbar.
2237

2338
```js
2439
module.exports = {
@@ -38,6 +53,26 @@ module.exports = {
3853
}
3954
```
4055

56+
To use colors from your theme, you need to override `theme.scrollbar.DEFAULT`.
57+
58+
```js
59+
module.exports = {
60+
theme: {
61+
// ...
62+
scrollbar: theme => ({
63+
DEFAULT: {
64+
size: theme('spacing.1'),
65+
colors: {
66+
track: theme('colors.gray.300'),
67+
thumb: theme('colors.gray.100'),
68+
thumbHover: theme('colors.gray.600'),
69+
}
70+
},
71+
})
72+
},
73+
}
74+
```
75+
4176
## Browser Support
4277

4378
Custom scrollbars are not supported in Firefox or in Edge, prior version 79.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gradin/tailwindcss-scrollbar",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Tailwindcss plugin to customize scrollbar.",
55
"main": "src/index.js",
66
"scripts": {},

src/index.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
const plugin = require('tailwindcss/plugin')
22

33
module.exports = plugin.withOptions(function (options) {
4-
return function ({ addBase }) {
5-
// const size = options?.size ?? '5px'
6-
// const { track, thumb, thumbHover } = options?.colors ?? {}
4+
return function ({ addBase, theme }) {
5+
const size = options && options.size ? options.size : theme('scrollbar.DEFAULT.size', '5px')
76

8-
const size = options && options.size ? options.size : '5px'
9-
const { track, thumb, thumbHover } = options && options.colors ? options.colors : {}
7+
const optionColors = options && options.colors ? options.colors : {}
8+
const defaultColors = theme('scrollbar.DEFAULT.colors', {
9+
track: '#f1f1f1',
10+
thumb: '#c1c1c1',
11+
hover: '#a8a8a8',
12+
})
13+
const { track, thumb, thumbHover } = { ...defaultColors, ...optionColors }
1014

1115
addBase([
1216
{
@@ -15,13 +19,13 @@ module.exports = plugin.withOptions(function (options) {
1519
height: size,
1620
},
1721
'::-webkit-scrollbar-track': {
18-
background: track ? track : '#f1f1f1',
22+
background: track,
1923
},
2024
'::-webkit-scrollbar-thumb': {
21-
background: thumb ? thumb : '#c1c1c1',
25+
background: thumb,
2226
},
2327
'::-webkit-scrollbar-thumb:hover': {
24-
background: thumbHover ? thumbHover : '#a8a8a8',
28+
background: thumbHover,
2529
},
2630
},
2731
])

0 commit comments

Comments
 (0)