Skip to content

Commit 6dea147

Browse files
committed
Add support for Tailwind v1.x
1 parent c6f7f23 commit 6dea147

File tree

4 files changed

+3963
-20
lines changed

4 files changed

+3963
-20
lines changed

index.js

+64-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,69 @@
11
const _ = require('lodash')
2+
const flatten = require('flat')
23

3-
module.exports = function ({ indents, variants }) {
4-
return function ({ addUtilities, e }) {
5-
const utilities = _.map(indents, (size, name) => ({
6-
[`.${size.charAt(0) === '-' ? '-' : ''}indent-${name}`]: {
7-
textIndent: size,
8-
},
9-
}))
104

11-
addUtilities(utilities, variants)
5+
const FLATTEN_CONFIG = { delimiter: '-', maxDepth: 2 }
6+
const handleName = (name, className) => {
7+
const split = name.split(`${className}-`)
8+
const prefixedName = `${split[0]}${prefixNegativeModifiers(className, split[1])}`
9+
10+
return prefixedName.split('-default').join('')
11+
}
12+
const prefixNegativeModifiers = function(base, modifier) {
13+
return _.startsWith(modifier, '-')
14+
? `-${base}-${modifier.slice(1)}`
15+
: `${base}-${modifier}`
16+
}
17+
18+
19+
module.exports = function () {
20+
return function ({
21+
addUtilities, addComponents, addBase, addVariant,
22+
e, prefix, theme, variants, config,
23+
}) {
24+
const buildConfig = (themeKey, ...fallbackKeys) => {
25+
return buildConfigFromTheme(themeKey, ...fallbackKeys) || buildConfigFromArray(themeKey)
26+
}
27+
const buildConfigFromTheme = (themeKey, ...fallbackKeys) => {
28+
const buildObject = ([ modifier, value ]) => [ modifier, { [themeKey]: value } ]
29+
const getThemeSettings = (themeKey, fallbackKeys) => {
30+
const [newThemeKey, ...newFallbackKeys] = fallbackKeys || []
31+
32+
return theme(themeKey, false) || (fallbackKeys.length && getThemeSettings(newThemeKey, [...newFallbackKeys]))
33+
}
34+
35+
const themeSettings = getThemeSettings(themeKey, fallbackKeys)
36+
const themeObject = _.isArray(themeSettings) ? _.zipObject(themeSettings, themeSettings) : themeSettings
37+
const themeEntries = themeSettings && Object
38+
.entries(flatten(themeObject, FLATTEN_CONFIG))
39+
.map(entry => buildObject(entry))
40+
41+
return themeSettings ? _.fromPairs(themeEntries) : false
42+
}
43+
const buildConfigFromArray = (property) => {
44+
const defaultSettings = defaultValues[property]
45+
const defaultEntries = defaultSettings && defaultSettings
46+
.map((value) => ([value, { [property]: value }]))
47+
48+
return defaultSettings ? _.fromPairs(defaultEntries) : false
49+
}
50+
51+
const defaultValues = {}
52+
const pluginUtilities = {
53+
'indent': buildConfig('textIndent'),
54+
}
55+
56+
Object.entries(pluginUtilities)
57+
.filter(([ modifier, values ]) => !_.isEmpty(values))
58+
.forEach(([ modifier, values ]) => {
59+
const className = _.kebabCase(modifier)
60+
const variantName = Object.keys(Object.entries(values)[0][1])[0]
61+
const utilities = flatten({ [`.${e(`${className}`)}`]: values }, FLATTEN_CONFIG)
62+
63+
addUtilities(
64+
_.mapKeys(utilities, (value, key) => handleName(key, className)),
65+
variants(variantName, ['responsive'])
66+
)
67+
})
1268
}
1369
}

package.json

+27-12
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,40 @@
22
"name": "tailwindcss-text-indent",
33
"version": "0.1.0",
44
"description": "Text-indent utilities for Tailwind CSS.",
5-
"main": "index.js",
6-
"repository": {
7-
"type": "git",
8-
"url": "git+https://github.com/hacknug/tailwindcss-text-indent.git"
9-
},
105
"keywords": [
6+
"plugin",
117
"tailwind",
12-
"tailwindcss",
138
"tailwind css",
14-
"tailwindcss-plugin",
15-
"plugin"
9+
"tailwindcss",
10+
"tailwindcss-plugin"
1611
],
17-
"author": "Nestor Vera <[email protected]> (https://nestor.rip)",
18-
"license": "MIT",
12+
"homepage": "https://github.com/hacknug/tailwindcss-text-indent#readme",
1913
"bugs": {
2014
"url": "https://github.com/hacknug/tailwindcss-text-indent/issues"
2115
},
22-
"homepage": "https://github.com/hacknug/tailwindcss-text-indent#readme",
16+
"repository": {
17+
"type": "git",
18+
"url": "git+https://github.com/hacknug/tailwindcss-text-indent.git"
19+
},
20+
"license": "MIT",
21+
"author": {
22+
"name": "Nestor Vera",
23+
"email": "[email protected]",
24+
"url": "https://nestor.rip/"
25+
},
26+
"main": "index.js",
27+
"scripts": {
28+
"dev": "jest --watchAll",
29+
"test": "jest"
30+
},
2331
"dependencies": {
24-
"lodash": "^4.17.10"
32+
"flat": "^4.1.0",
33+
"lodash": "^4.17.11"
34+
},
35+
"devDependencies": {
36+
"jest": "^24.8.0",
37+
"jest-matcher-css": "^1.0.3",
38+
"postcss": "^7.0.16",
39+
"tailwindcss": "^1.0.1"
2540
}
2641
}

0 commit comments

Comments
 (0)