Skip to content

Commit caa70b6

Browse files
authored
chore: Prepare for Tailwind 2.0 - Part 3 (#87)
* bump dependencies * test by running everything through tailwindcss itself * simplify implementation Making use of the merging of extended themes 🚀 * clear unnecessary whitespace * add additional test to verify overriding of backticks still work * bump to latest tailwindcss alpha version
1 parent cbfeb47 commit caa70b6

File tree

4 files changed

+23049
-1485
lines changed

4 files changed

+23049
-1485
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prepublishOnly": "node scripts/build.js"
2525
},
2626
"peerDependencies": {
27-
"tailwindcss": "^1.5.0"
27+
"tailwindcss": "2.0.0-alpha.4 || ^2.0.0"
2828
},
2929
"devDependencies": {
3030
"@mdx-js/loader": "^1.0.19",
@@ -39,9 +39,9 @@
3939
"next": "^9.4.4",
4040
"postcss": "^7.0.17",
4141
"prettier": "^2.1.2",
42-
"react-dom": "^16.8.6",
4342
"react": "^16.8.6",
43+
"react-dom": "^16.8.6",
4444
"snapshot-diff": "^0.8.1",
45-
"tailwindcss": "^2.0.0-alpha.1"
45+
"tailwindcss": "^2.0.0-alpha.4"
4646
}
4747
}

src/index.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const plugin = require('tailwindcss/plugin')
22
const merge = require('lodash/merge')
33
const castArray = require('lodash/castArray')
4+
const uniq = require('lodash/uniq')
45
const styles = require('./styles')
56

67
const computed = {
78
// Reserved for future "magic properties", for example:
89
// bulletColor: (color) => ({ 'ul > li::before': { backgroundColor: color } }),
910
}
1011

11-
function configToCss(config) {
12+
function configToCss(config = {}) {
1213
return merge(
1314
{},
1415
...Object.keys(config)
@@ -18,36 +19,27 @@ function configToCss(config) {
1819
)
1920
}
2021

22+
const DEFAULT_MODIFIERS = ['DEFAULT', 'sm', 'lg', 'xl', '2xl']
2123
module.exports = plugin.withOptions(
22-
({ modifiers = ['sm', 'lg', 'xl', '2xl'], className = 'prose' } = {}) => {
24+
({ modifiers = DEFAULT_MODIFIERS, className = 'prose' } = {}) => {
2325
return function ({ addComponents, theme, variants }) {
24-
const config = theme('typography', {})
26+
const config = theme('typography')
27+
28+
const all = uniq([
29+
'DEFAULT',
30+
...modifiers,
31+
...Object.keys(config).filter((modifier) => !DEFAULT_MODIFIERS.includes(modifier)),
32+
])
2533

2634
addComponents(
27-
[
28-
{
29-
[`.${className}`]: merge(
30-
{},
31-
...castArray(styles.DEFAULT.css),
32-
configToCss(config.DEFAULT || {})
33-
),
34-
},
35-
...modifiers.map((modifier) => ({
36-
[`.${className}-${modifier}`]: merge(
37-
{},
38-
...castArray(styles[modifier].css),
39-
configToCss(config[modifier] || {})
40-
),
41-
})),
42-
...Object.keys(config)
43-
.filter((key) => !['DEFAULT', ...modifiers].includes(key))
44-
.map((modifier) => ({
45-
[`.${className}-${modifier}`]: configToCss(config[modifier]),
46-
})),
47-
],
35+
all.map((modifier) => ({
36+
[modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`]: configToCss(
37+
config[modifier]
38+
),
39+
})),
4840
variants('typography')
4941
)
5042
}
5143
},
52-
() => ({ variants: { typography: ['responsive'] } })
44+
() => ({ theme: { typography: styles }, variants: { typography: ['responsive'] } })
5345
)

0 commit comments

Comments
 (0)