Last active
March 5, 2020 17:41
-
-
Save innocenzi/9e0d2d5586bedb05c697b4512ed8f0f4 to your computer and use it in GitHub Desktop.
box-shadow with same colors as their borders with Tailwind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const { default: flattenColorPalette } = require('tailwindcss/lib/util/flattenColorPalette'); | |
module.exports = { | |
theme: { | |
extend: { | |
boxShadow: { | |
button: '0px 3px 0px 2px var(--current-border-color)', | |
}, | |
}, | |
}, | |
corePlugins: { | |
borderColor: false, | |
}, | |
plugins: [ | |
function({ addUtilities, e, theme, variants }) { | |
const colors = flattenColorPalette(theme('borderColor')); | |
const utilities = _.fromPairs( | |
_.map(_.omit(colors, 'default'), (value, modifier) => { | |
return [ | |
`.${e(`border-${modifier}`)}`, | |
{ | |
'border-color': value, | |
'--current-border-color': `${value}`, // or something like `${value}80` for 50% opacity | |
}, | |
]; | |
}), | |
); | |
addUtilities(utilities, variants('borderColor')); | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment