Skip to content

Instantly share code, notes, and snippets.

@innocenzi
Last active March 5, 2020 17:41
Show Gist options
  • Save innocenzi/9e0d2d5586bedb05c697b4512ed8f0f4 to your computer and use it in GitHub Desktop.
Save innocenzi/9e0d2d5586bedb05c697b4512ed8f0f4 to your computer and use it in GitHub Desktop.
box-shadow with same colors as their borders with Tailwind
<div class="mr-4 p-4 rounded-lg border-2 font-bold text-white bg-red-300 border-red-400 shadow-button">border-red-400 shadow-button</div>
<div class="p-4 rounded-lg border-2 font-bold text-white bg-blue-300 border-blue-400 shadow-button">border-blue-400 shadow-button</div>
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