Skip to content

Commit

Permalink
feat(config): add a global config wrapper
Browse files Browse the repository at this point in the history
encapsulate Tailwind config in a wrapper to pass purge, plugins and more configurations internally

BREAKING CHANGE: Instead of adding Windmill files to `purge` or to `plugins`, now you only need to
encapsulate your Tailwind config using this wrapper. It will automatically add what Windmill needs
to work properly and you can use your `tailwind.config.js` file as before, as it will be merged.
  • Loading branch information
estevanmaito committed Jul 17, 2020
1 parent fdab07a commit 6a6de16
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 276 deletions.
121 changes: 75 additions & 46 deletions plugin.js → config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const plugin = require('tailwindcss/plugin')
const deepMerge = require('deepmerge')
const Color = require('color')
const customFormsPlugin = require('@tailwindcss/custom-forms')
const multiThemePlugin = require('tailwindcss-multi-theme')
Expand Down Expand Up @@ -189,49 +189,78 @@ const customForms = (theme) => ({
},
})

module.exports = plugin.withOptions(
() => (options) => {
customFormsPlugin(options)
multiThemePlugin(options)
shadowOutlinePlugin(options)
},
() => ({
theme: {
themeVariants: ['dark'],
colors,
backgroundOpacity,
maxHeight,
minWidth,
customForms,
},
variants: {
backgroundOpacity: ['responsive', 'hover', 'focus', 'dark:hover'],
backgroundColor: [
'hover',
'focus',
'active',
'odd',
'dark',
'dark:hover',
'dark:focus',
'dark:active',
'dark:odd',
],
display: ['responsive', 'dark'],
textColor: [
'focus-within',
'hover',
'active',
'dark',
'dark:focus-within',
'dark:hover',
'dark:active',
],
placeholderColor: ['focus', 'dark', 'dark:focus'],
borderColor: ['focus', 'hover', 'dark', 'dark:focus', 'dark:hover'],
divideColor: ['dark'],
boxShadow: ['focus', 'dark:focus'],
margin: ['responsive', 'last'],
const windmillConfig = {
purge: {
content: [
'node_modules/windmill-react-ui/lib/defaultTheme.js',
'node_modules/windmill-react-ui/dist/index.js',
],
options: {
whitelist: ['theme-dark'],
},
})
)
},
theme: {
themeVariants: ['dark'],
colors,
backgroundOpacity,
maxHeight,
minWidth,
customForms,
},
variants: {
backgroundOpacity: ['responsive', 'hover', 'focus', 'dark:hover'],
backgroundColor: [
'hover',
'focus',
'active',
'odd',
'dark',
'dark:hover',
'dark:focus',
'dark:active',
'dark:odd',
],
display: ['responsive', 'dark'],
textColor: [
'focus-within',
'hover',
'active',
'dark',
'dark:focus-within',
'dark:hover',
'dark:active',
],
placeholderColor: ['focus', 'dark', 'dark:focus'],
borderColor: ['responsive', 'hover', 'focus', 'dark', 'dark:focus', 'dark:hover'],
divideColor: ['dark'],
boxShadow: ['focus', 'dark:focus'],
margin: ['responsive', 'last'],
},
plugins: [customFormsPlugin, multiThemePlugin, shadowOutlinePlugin],
}

function arrayMergeFn(destinationArray, sourceArray) {
return destinationArray.concat(sourceArray).reduce((acc, cur) => {
if (acc.includes(cur)) return acc
return [...acc, cur]
}, [])
}

/**
* Merge Windmill and Tailwind CSS configurations
* @param {object} tailwindConfig - Tailwind config object
* @return {object} new config object
*/
function wrapper(tailwindConfig) {
let purge
if (Array.isArray(tailwindConfig.purge)) {
purge = {
content: tailwindConfig.purge,
}
} else {
purge = tailwindConfig.purge
}
return deepMerge({ ...tailwindConfig, purge }, windmillConfig, { arrayMerge: arrayMergeFn })
}

module.exports = wrapper
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"main": "dist/index.js",
"files": [
"dist",
"lib",
"defaultTheme.js",
"plugin.js",
"config.js",
"README.md"
],
"scripts": {
Expand All @@ -27,6 +25,7 @@
"build": "webpack",
"prerelease": "npm run build",
"release": "dotenv release-it",
"pre:release": "dotenv release-it -- --preRelease=beta",
"semantic-release": "semantic-release"
},
"peerDependencies": {
Expand All @@ -38,6 +37,7 @@
"@tailwindcss/custom-forms": "0.2.1",
"classnames": "2.2.6",
"color": "3.1.2",
"deepmerge": "4.2.2",
"prop-types": "15.7.2",
"react-focus-lock": "2.4.0",
"react-transition-group": "4.4.1",
Expand Down
222 changes: 0 additions & 222 deletions style/tailwind.config.js

This file was deleted.

3 changes: 0 additions & 3 deletions style/tailwind.css

This file was deleted.

0 comments on commit 6a6de16

Please sign in to comment.