Skip to content

Instantly share code, notes, and snippets.

@Steve-Reid
Last active April 16, 2021 18:05
Show Gist options
  • Select an option

  • Save Steve-Reid/b6874f68c500ec555ae5f0bad0d1c561 to your computer and use it in GitHub Desktop.

Select an option

Save Steve-Reid/b6874f68c500ec555ae5f0bad0d1c561 to your computer and use it in GitHub Desktop.
Starter files for theming using css variables with Tailwind
const defaultTheme = require('tailwindcss/defaultTheme');
function withOpacity(variableName) {
return ({ opacityValue }) => {
if (opacityValue !== undefined) {
return `rgba(var(${variableName}) ${opacityValue})`;
}
return `rgb(var(${variableName}))`;
};
}
module.exports = {
purge: [
'./src/pages/**/*.{js,ts,jsx,tsx}',
'./src/components/**/*.{js,ts,jsx,tsx}',
'./src/layouts/**/*.{js,ts,jsx,tsx}',
'./src/ui/**/*.{js,ts,jsx,tsx}',
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
fontFamily: {
sans: ['Inter', ...defaultTheme.fontFamily.sans],
},
textColor: {
skin: {
primary: withOpacity('--color-text-primary'),
secondary: withOpacity('--color-text-secondary'),
base: withOpacity('--color-text-base'),
muted: withOpacity('--color-text-muted'),
inverted: withOpacity('--color-text-inverted'),
},
},
backgroundColor: {
skin: {
fill: withOpacity('--color-fill'),
'button-primary': withOpacity('--color-button-primary'),
'button-primary-hover': withOpacity('--color-button-primary-hover'),
'button-secondary': withOpacity('--color-button-secondary'),
'button-secondary-hover': withOpacity(
'--color-button-secondary-hover'
),
'button-accent': withOpacity('--color-button-accent'),
'button-accent-hover': withOpacity('--color-button-accent-hover'),
'button-muted': withOpacity('--color-button-muted'),
},
},
gradientColorStops: {
skin: {
hue: withOpacity('--color-fill'),
},
},
},
},
variants: {
extend: {},
},
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
/* transformed to just rgb values */
--color-text-primary: 51, 51, 51;
--color-text-secondary: 51, 51, 51;
--color-text-base: 51, 51, 51;
--color-text-muted: 119, 119, 119;
--color-text-inverted: 255, 255, 255;
--color-fill: 242, 242, 242;
--color-button-primary: 51, 51, 51;
--color-button-primary-hover: 51, 51, 51;
--color-button-secondary: 51, 51, 51;
--color-button-secondary-hover: 51, 51, 51;
--color-button-accent: 51, 51, 51;
--color-button-accent-hover: 77, 76, 76;
--color-button-muted: 207, 206, 206;
}
.theme-alt {
--color-text-primary: #333333;
--color-text-secondary: #333333;
--color-text-base: #333333;
--color-text-muted: #777777;
--color-text-inverted: #ffffff;
--color-fill: #f2f2f2;
--color-button-primary: #333333;
--color-button-primary-hover: #333333;
--color-button-secondary: #333333;
--color-button-secondary-hover: #333333;
--color-button-accent: #333333;
--color-button-accent-hover: #4d4c4c;
/* transform to just rgb values */
--color-button-muted: #cfcece;
}
}
/* Remove once transposed to Tailwind variables */
.color-text-primary {
color: #333333;
}
.color-text-secondary {
color: #333333;
}
.color-text-base {
color: #333333;
}
.color-text-muted {
color: #777777;
}
.color-text-inverted {
color: #ffffff;
}
.color-fill {
color: #f2f2f2;
}
.color-button-primary {
color: #333333;
}
.color-button-primary-hover {
color: #333333;
}
.color-button-secondary {
color: #333333;
}
.color-button-secondary-hover {
color: #333333;
}
.color-button-accent {
color: #333333;
}
.color-button-accent-hover {
color: #4d4c4c;
}
.color-button-muted {
color: #cfcece;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment