2022-03-15 16:05:18 +01:00
|
|
|
|
const plugin = require('tailwindcss/plugin');
|
|
|
|
|
const vanillaRTL = require('tailwindcss-vanilla-rtl');
|
2022-03-04 23:55:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Design Tokens
|
|
|
|
|
*/
|
2023-05-25 14:45:29 +02:00
|
|
|
|
const { staticColors, transparencies } = require('./src/tokens/colors');
|
2023-04-19 07:55:13 +02:00
|
|
|
|
const {
|
|
|
|
|
generateColorVariables,
|
|
|
|
|
generateThemeColorVariables,
|
|
|
|
|
} = require('./src/tokens/colorVariables');
|
|
|
|
|
const colorThemes = require('./src/tokens/colorThemes');
|
2022-02-27 17:08:38 +01:00
|
|
|
|
const {
|
|
|
|
|
fontFamily,
|
|
|
|
|
fontSize,
|
|
|
|
|
fontWeight,
|
|
|
|
|
letterSpacing,
|
|
|
|
|
lineHeight,
|
2022-10-28 11:14:52 +02:00
|
|
|
|
listStyleType,
|
2022-04-06 15:40:05 +02:00
|
|
|
|
typeScale,
|
2022-02-27 17:08:38 +01:00
|
|
|
|
} = require('./src/tokens/typography');
|
|
|
|
|
const { breakpoints } = require('./src/tokens/breakpoints');
|
|
|
|
|
const {
|
|
|
|
|
borderRadius,
|
|
|
|
|
borderWidth,
|
|
|
|
|
boxShadow,
|
|
|
|
|
} = require('./src/tokens/objectStyles');
|
|
|
|
|
const { spacing } = require('./src/tokens/spacing');
|
|
|
|
|
|
2022-03-04 23:55:24 +01:00
|
|
|
|
/**
|
|
|
|
|
* Plugins
|
|
|
|
|
*/
|
2022-04-12 17:11:08 +02:00
|
|
|
|
const scrollbarThin = require('./src/plugins/scrollbarThin');
|
2022-03-04 23:55:24 +01:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Functions
|
|
|
|
|
* themeColors: For converting our design tokens into a format that tailwind accepts
|
|
|
|
|
*/
|
2022-02-27 17:08:38 +01:00
|
|
|
|
const themeColors = Object.fromEntries(
|
2023-05-25 14:45:29 +02:00
|
|
|
|
Object.entries(staticColors).map(([key, hues]) => {
|
2022-02-27 17:08:38 +01:00
|
|
|
|
const shades = Object.fromEntries(
|
2022-07-09 07:58:26 +02:00
|
|
|
|
Object.entries(hues).map(([k, shade]) => [
|
|
|
|
|
k,
|
|
|
|
|
`var(${shade.cssVariable})`,
|
|
|
|
|
]),
|
2022-02-27 17:08:38 +01:00
|
|
|
|
);
|
|
|
|
|
return [key, shades];
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-19 07:55:13 +02:00
|
|
|
|
const lightThemeColors = colorThemes.light.reduce((colorTokens, category) => {
|
|
|
|
|
Object.entries(category.tokens).forEach(([name, token]) => {
|
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
|
colorTokens[name] = `var(${token.cssVariable})`;
|
|
|
|
|
});
|
|
|
|
|
return colorTokens;
|
|
|
|
|
}, {});
|
|
|
|
|
|
2022-02-27 17:08:38 +01:00
|
|
|
|
/**
|
|
|
|
|
* Root Tailwind config, reusable for other projects.
|
|
|
|
|
*/
|
|
|
|
|
module.exports = {
|
|
|
|
|
prefix: 'w-',
|
|
|
|
|
theme: {
|
|
|
|
|
screens: {
|
|
|
|
|
...breakpoints,
|
|
|
|
|
},
|
|
|
|
|
colors: {
|
|
|
|
|
...themeColors,
|
2023-04-19 07:55:13 +02:00
|
|
|
|
...lightThemeColors,
|
|
|
|
|
'white-10': 'var(--w-color-white-10)',
|
|
|
|
|
'white-15': 'var(--w-color-white-15)',
|
|
|
|
|
'white-50': 'var(--w-color-white-50)',
|
|
|
|
|
'white-80': 'var(--w-color-white-80)',
|
|
|
|
|
'black-5': 'var(--w-color-black-5)',
|
|
|
|
|
'black-10': 'var(--w-color-black-10)',
|
|
|
|
|
'black-20': 'var(--w-color-black-20)',
|
|
|
|
|
'black-25': 'var(--w-color-black-25)',
|
|
|
|
|
'black-35': 'var(--w-color-black-35)',
|
|
|
|
|
'black-50': 'var(--w-color-black-50)',
|
2022-07-09 07:58:26 +02:00
|
|
|
|
// Color keywords.
|
|
|
|
|
'inherit': 'inherit',
|
|
|
|
|
'current': 'currentColor',
|
|
|
|
|
'transparent': 'transparent',
|
2022-03-15 16:05:18 +01:00
|
|
|
|
/* allow system colours https://www.w3.org/TR/css-color-4/#css-system-colors */
|
2022-07-09 07:58:26 +02:00
|
|
|
|
'LinkText': 'LinkText',
|
|
|
|
|
'ButtonText': 'ButtonText',
|
2022-02-27 17:08:38 +01:00
|
|
|
|
},
|
2022-05-20 15:19:30 +02:00
|
|
|
|
fontFamily: {
|
|
|
|
|
sans: 'var(--w-font-sans)',
|
|
|
|
|
mono: 'var(--w-font-mono)',
|
|
|
|
|
},
|
2022-02-27 17:08:38 +01:00
|
|
|
|
fontSize,
|
|
|
|
|
fontWeight,
|
|
|
|
|
lineHeight,
|
2022-10-28 11:14:52 +02:00
|
|
|
|
listStyleType,
|
2022-02-27 17:08:38 +01:00
|
|
|
|
letterSpacing,
|
|
|
|
|
borderRadius,
|
|
|
|
|
borderWidth,
|
|
|
|
|
boxShadow: {
|
|
|
|
|
...boxShadow,
|
|
|
|
|
none: 'none',
|
|
|
|
|
},
|
2022-07-25 16:15:31 +02:00
|
|
|
|
spacing: {
|
|
|
|
|
...spacing,
|
|
|
|
|
'slim-header': '50px',
|
|
|
|
|
},
|
2022-03-23 04:27:12 +01:00
|
|
|
|
extend: {
|
2022-03-28 16:43:35 +02:00
|
|
|
|
outlineOffset: {
|
|
|
|
|
inside: '-3px',
|
|
|
|
|
},
|
2022-04-28 03:14:18 +02:00
|
|
|
|
transitionProperty: {
|
|
|
|
|
sidebar:
|
2022-05-05 15:58:37 +02:00
|
|
|
|
'inset-inline-start, padding-inline-start, width, transform, margin-top, min-height',
|
2022-04-28 03:14:18 +02:00
|
|
|
|
},
|
2022-04-29 15:38:53 +02:00
|
|
|
|
zIndex: {
|
2022-05-20 16:02:32 +02:00
|
|
|
|
'header': '100',
|
|
|
|
|
'sidebar': '110',
|
|
|
|
|
'sidebar-toggle': '120',
|
|
|
|
|
'dialog': '130',
|
|
|
|
|
},
|
|
|
|
|
keyframes: {
|
|
|
|
|
'fade-in': {
|
|
|
|
|
'0%': { opacity: 0 },
|
|
|
|
|
'100%': { opacity: 1 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
animation: {
|
|
|
|
|
'fade-in': 'fade-in 150ms both',
|
2022-04-29 15:38:53 +02:00
|
|
|
|
},
|
2022-03-23 04:27:12 +01:00
|
|
|
|
},
|
2022-02-27 17:08:38 +01:00
|
|
|
|
},
|
2022-03-15 16:05:18 +01:00
|
|
|
|
plugins: [
|
|
|
|
|
typeScale,
|
|
|
|
|
vanillaRTL,
|
2022-04-12 17:11:08 +02:00
|
|
|
|
scrollbarThin,
|
2022-03-15 16:05:18 +01:00
|
|
|
|
/**
|
|
|
|
|
* forced-colors media query for Windows High-Contrast mode support
|
|
|
|
|
* See:
|
|
|
|
|
* - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
|
|
|
|
|
* - https://github.com/tailwindlabs/tailwindcss/blob/v3.0.23/src/corePlugins.js#L168-L171
|
|
|
|
|
*/
|
|
|
|
|
plugin(({ addVariant }) => {
|
|
|
|
|
addVariant('forced-colors', '@media (forced-colors: active)');
|
|
|
|
|
}),
|
2022-04-06 15:40:05 +02:00
|
|
|
|
/**
|
|
|
|
|
* TypeScale plugin.
|
2022-04-07 15:54:34 +02:00
|
|
|
|
* This plugin generates component classes using tailwind's theme values for each object inside of the typeScale configuration.
|
|
|
|
|
* We have the `w-` prefix added in the configuration for documentation purposes, it needs to be removed here before Tailwind adds it back.
|
2022-04-06 15:40:05 +02:00
|
|
|
|
*/
|
|
|
|
|
plugin(({ addComponents, theme }) => {
|
|
|
|
|
const scale = {};
|
|
|
|
|
Object.entries(typeScale).forEach(([name, styles]) => {
|
|
|
|
|
scale[`.${name.replace('w-', '')}`] = Object.fromEntries(
|
|
|
|
|
Object.entries(styles).map(([key, value]) => [key, theme(value)]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
addComponents(scale);
|
|
|
|
|
}),
|
2022-05-20 15:19:30 +02:00
|
|
|
|
/**
|
|
|
|
|
* CSS Custom properties defined from our design tokens.
|
|
|
|
|
*/
|
|
|
|
|
plugin(({ addBase }) => {
|
|
|
|
|
addBase({
|
2022-12-27 17:55:19 +01:00
|
|
|
|
/** Support for web components */
|
|
|
|
|
':root, :host': {
|
2022-05-20 15:19:30 +02:00
|
|
|
|
'--w-font-sans': fontFamily.sans.join(', '),
|
|
|
|
|
'--w-font-mono': fontFamily.mono.join(', '),
|
2024-04-18 11:26:12 +02:00
|
|
|
|
'--w-density-factor': '1',
|
2023-05-25 14:45:29 +02:00
|
|
|
|
...transparencies,
|
|
|
|
|
...generateColorVariables(staticColors),
|
2023-04-19 07:55:13 +02:00
|
|
|
|
...generateThemeColorVariables(colorThemes.light),
|
2024-01-17 10:28:12 +01:00
|
|
|
|
'color-scheme': 'light',
|
2023-04-19 07:55:13 +02:00
|
|
|
|
},
|
|
|
|
|
'.w-theme-system': {
|
2024-01-17 10:28:12 +01:00
|
|
|
|
'@media (prefers-color-scheme: dark)': {
|
|
|
|
|
...generateThemeColorVariables(colorThemes.dark),
|
|
|
|
|
'color-scheme': 'dark',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
'.w-theme-dark': {
|
|
|
|
|
...generateThemeColorVariables(colorThemes.dark),
|
|
|
|
|
'color-scheme': 'dark',
|
2022-05-20 15:19:30 +02:00
|
|
|
|
},
|
2024-04-18 11:26:12 +02:00
|
|
|
|
'.w-density-snug': {
|
|
|
|
|
'--w-density-factor': '0.5',
|
|
|
|
|
},
|
2022-05-20 15:19:30 +02:00
|
|
|
|
});
|
|
|
|
|
}),
|
2022-08-31 12:43:14 +02:00
|
|
|
|
/** Support for aria-expanded=true variant */
|
|
|
|
|
plugin(({ addVariant }) => {
|
|
|
|
|
addVariant('expanded', '&[aria-expanded=true]');
|
|
|
|
|
}),
|
2024-10-17 10:13:22 +02:00
|
|
|
|
/** Support for increased contrast theme */
|
|
|
|
|
plugin(({ addVariant }) => {
|
|
|
|
|
addVariant('more-contrast', [
|
|
|
|
|
'.contrast-more &',
|
|
|
|
|
'@media (prefers-contrast: more) { .contrast-system & }',
|
|
|
|
|
]);
|
|
|
|
|
}),
|
2022-03-15 16:05:18 +01:00
|
|
|
|
],
|
|
|
|
|
corePlugins: {
|
|
|
|
|
...vanillaRTL.disabledCorePlugins,
|
2023-12-18 18:03:03 +01:00
|
|
|
|
// Disable float and clear. Use Flexbox or Grid instead.
|
2022-03-15 16:05:18 +01:00
|
|
|
|
float: false,
|
|
|
|
|
clear: false,
|
2022-03-23 04:27:12 +01:00
|
|
|
|
// Disable text-transform so we don’t rely on uppercasing text.
|
|
|
|
|
textTransform: false,
|
2022-03-15 16:05:18 +01:00
|
|
|
|
},
|
2022-04-29 14:51:42 +02:00
|
|
|
|
variants: {
|
|
|
|
|
extend: {
|
|
|
|
|
backgroundColor: ['forced-colors'],
|
|
|
|
|
width: ['forced-colors'],
|
|
|
|
|
height: ['forced-colors'],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-02-27 17:08:38 +01:00
|
|
|
|
};
|