-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathindex.js
50 lines (46 loc) · 1.49 KB
/
index.js
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
const plugin = require('tailwindcss/plugin')
const merge = require('lodash/merge')
const castArray = require('lodash/castArray')
const styles = require('./styles')
const computed = {
// Reserved for future "magic properties", for example:
// bulletColor: (color) => ({ 'ul > li::before': { backgroundColor: color } }),
}
function configToCss(config) {
return merge(
...Object.keys(config)
.filter((key) => computed[key])
.map((key) => computed[key](config[key])),
...castArray(config.css || {})
)
}
module.exports = plugin.withOptions(
({ modifiers = ['sm', 'lg', 'xl', '2xl'], className = 'prose' } = {}) => {
return function ({ addComponents, theme, variants }) {
const config = theme('typography', {})
addComponents(
[
{
[`.${className}`]: merge(
...castArray(styles.default.css),
configToCss(config.default || {})
),
},
...modifiers.map((modifier) => ({
[`.${className}-${modifier}`]: merge(
...castArray(styles[modifier].css),
configToCss(config[modifier] || {})
),
})),
...Object.keys(config)
.filter((key) => !['default', ...modifiers].includes(key))
.map((modifier) => ({
[`.${className}-${modifier}`]: configToCss(config[modifier]),
})),
],
variants('typography')
)
}
},
() => ({ variants: { typography: ['responsive'] } })
)