Skip to content
This repository was archived by the owner on Sep 25, 2020. It is now read-only.

Commit 2dd8749

Browse files
committed
Add notes about configuring the buttons plugin via callback
1 parent f2364c1 commit 2dd8749

File tree

2 files changed

+97
-66
lines changed

2 files changed

+97
-66
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In `plugins/simple-buttons/index.js` you'll find an example of a plugin that add
4949

5050
![](https://user-images.githubusercontent.com/4323180/37477287-b367cf88-284d-11e8-823b-f793c3ba1119.png)
5151

52-
This plugin exposes quite a number of configuration options *(all optional)*, which can be passed to the plugin as an object:
52+
This plugin exposes quite a number of configuration options which can be passed to the plugin as an object:
5353

5454
```js
5555
module.exports = {
@@ -91,18 +91,47 @@ module.exports = {
9191
// You can override any of the default styles from above
9292
// at any given button size.
9393
sizes: {
94+
// Class name: `.btn-sm`
9495
sm: {
9596
fontSize: '.875rem',
9697
padding: '.5rem .75rem',
9798
},
99+
// Class name: `.btn-lg`
98100
lg: {
99101
fontSize: '1.25rem',
100102
padding: '.75rem 1.5rem',
101103
borderRadius: '.5rem',
102104
}
103105
}
106+
107+
}),
108+
],
109+
}
110+
```
111+
112+
Configuration is entirely optional; the plugin will use sane defaults based on Tailwind's default configuration if you don't provide any of your own overrides.
113+
114+
If you want to extend the plugin's default configuration instead of overriding it entirely, you can pass a function which accepts the default configuration, modifies it, and returns a new configuration object:
115+
116+
```js
117+
module.exports = {
118+
// ...
119+
120+
plugins: [
121+
// ...
122+
require('./plugins/simple-buttons')(function (options) {
123+
options.sizes = Object.assign(options.sizes, {
124+
xl: {
125+
fontSize: '1.5rem',
126+
padding: '1rem 2rem',
127+
borderRadius: '.75rem',
128+
}
129+
})
130+
131+
return options
104132
}),
105133
],
106134
}
107135
```
108136

137+
Again, the sky is the limit in terms of the API a plugin exposes for configuration. You can do anything you want!

plugins/simple-buttons/index.js

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,80 @@ const _ = require('lodash')
22
const Color = require('color')
33
const defaultConfig = require('tailwindcss/defaultConfig')()
44

5-
const defaultOptions = {
6-
borderRadius: '.25rem',
7-
fontWeight: '600',
8-
lineHeight: '1.25',
9-
fontSize: '1rem',
10-
padding: '.5rem 1rem',
11-
colors: {
12-
white: {
13-
background: defaultConfig.colors['white'],
14-
text: defaultConfig.colors['black'],
15-
},
16-
black: {
17-
background: defaultConfig.colors['black'],
18-
text: defaultConfig.colors['white'],
19-
},
20-
grey: {
21-
background: defaultConfig.colors['grey'],
22-
text: defaultConfig.colors['black'],
23-
},
24-
red: {
25-
background: defaultConfig.colors['red'],
26-
text: defaultConfig.colors['white'],
27-
},
28-
orange: {
29-
background: defaultConfig.colors['orange'],
30-
text: defaultConfig.colors['white'],
31-
},
32-
yellow: {
33-
background: defaultConfig.colors['yellow'],
34-
text: defaultConfig.colors['yellow-darkest'],
35-
},
36-
green: {
37-
background: defaultConfig.colors['green'],
38-
text: defaultConfig.colors['white'],
39-
},
40-
teal: {
41-
background: defaultConfig.colors['teal'],
42-
text: defaultConfig.colors['white'],
43-
},
44-
blue: {
45-
background: defaultConfig.colors['blue'],
46-
text: defaultConfig.colors['white'],
47-
},
48-
indigo: {
49-
background: defaultConfig.colors['indigo'],
50-
text: defaultConfig.colors['white'],
51-
},
52-
purple: {
53-
background: defaultConfig.colors['purple'],
54-
text: defaultConfig.colors['white'],
55-
},
56-
pink: {
57-
background: defaultConfig.colors['pink'],
58-
text: defaultConfig.colors['white'],
59-
},
60-
},
61-
sizes: {
62-
sm: {
63-
fontSize: '.875rem',
64-
padding: '.5rem .75rem',
5+
function defaultOptions() {
6+
return {
7+
borderRadius: '.25rem',
8+
fontWeight: '600',
9+
lineHeight: '1.25',
10+
fontSize: '1rem',
11+
padding: '.5rem 1rem',
12+
colors: {
13+
white: {
14+
background: defaultConfig.colors['white'],
15+
text: defaultConfig.colors['black'],
16+
},
17+
black: {
18+
background: defaultConfig.colors['black'],
19+
text: defaultConfig.colors['white'],
20+
},
21+
grey: {
22+
background: defaultConfig.colors['grey'],
23+
text: defaultConfig.colors['black'],
24+
},
25+
red: {
26+
background: defaultConfig.colors['red'],
27+
text: defaultConfig.colors['white'],
28+
},
29+
orange: {
30+
background: defaultConfig.colors['orange'],
31+
text: defaultConfig.colors['white'],
32+
},
33+
yellow: {
34+
background: defaultConfig.colors['yellow'],
35+
text: defaultConfig.colors['yellow-darkest'],
36+
},
37+
green: {
38+
background: defaultConfig.colors['green'],
39+
text: defaultConfig.colors['white'],
40+
},
41+
teal: {
42+
background: defaultConfig.colors['teal'],
43+
text: defaultConfig.colors['white'],
44+
},
45+
blue: {
46+
background: defaultConfig.colors['blue'],
47+
text: defaultConfig.colors['white'],
48+
},
49+
indigo: {
50+
background: defaultConfig.colors['indigo'],
51+
text: defaultConfig.colors['white'],
52+
},
53+
purple: {
54+
background: defaultConfig.colors['purple'],
55+
text: defaultConfig.colors['white'],
56+
},
57+
pink: {
58+
background: defaultConfig.colors['pink'],
59+
text: defaultConfig.colors['white'],
60+
},
6561
},
66-
lg: {
67-
fontSize: '1.25rem',
68-
padding: '.75rem 1.5rem',
62+
sizes: {
63+
sm: {
64+
fontSize: '.875rem',
65+
padding: '.5rem .75rem',
66+
},
67+
lg: {
68+
fontSize: '1.25rem',
69+
padding: '.75rem 1.5rem',
70+
}
6971
}
7072
}
7173
}
7274

7375
module.exports = function (options) {
7476
options = _.isFunction(options)
75-
? options(defaultOptions)
76-
: _.defaults(options, defaultOptions)
77+
? options(defaultOptions())
78+
: _.defaults(options, defaultOptions())
7779

7880
return function ({ addComponents, e }) {
7981
addComponents([

0 commit comments

Comments
 (0)