123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- const plugin = require('tailwindcss/plugin');
- const vanillaRTL = require('tailwindcss-vanilla-rtl');
- /**
- * Design Tokens
- */
- const colors = require('./src/tokens/colors');
- const {
- fontFamily,
- fontSize,
- fontWeight,
- letterSpacing,
- lineHeight,
- typeScale,
- } = require('./src/tokens/typography');
- const { breakpoints } = require('./src/tokens/breakpoints');
- const {
- borderRadius,
- borderWidth,
- boxShadow,
- } = require('./src/tokens/objectStyles');
- const { spacing } = require('./src/tokens/spacing');
- /**
- * Plugins
- */
- const scrollbarThin = require('./src/plugins/scrollbarThin');
- /**
- * Functions
- * themeColors: For converting our design tokens into a format that tailwind accepts
- */
- const themeColors = Object.fromEntries(
- Object.entries(colors).map(([key, hues]) => {
- const shades = Object.fromEntries(
- Object.entries(hues).map(([k, shade]) => [k, shade.hex]),
- );
- return [key, shades];
- }),
- );
- /**
- * Root Tailwind config, reusable for other projects.
- */
- module.exports = {
- prefix: 'w-',
- theme: {
- screens: {
- ...breakpoints,
- },
- colors: {
- ...themeColors,
- inherit: 'inherit',
- current: 'currentColor',
- transparent: 'transparent',
- /* allow system colours https://www.w3.org/TR/css-color-4/#css-system-colors */
- LinkText: 'LinkText',
- ButtonText: 'ButtonText',
- },
- fontFamily,
- fontSize,
- fontWeight,
- lineHeight,
- letterSpacing,
- borderRadius,
- borderWidth,
- boxShadow: {
- ...boxShadow,
- none: 'none',
- },
- spacing,
- extend: {
- opacity: {
- 15: '0.15',
- 85: '0.85',
- },
- outlineOffset: {
- inside: '-3px',
- },
- transitionProperty: {
- sidebar:
- 'inset-inline-start, padding-inline-start, width, transform, margin-top, min-height',
- },
- zIndex: {
- header: '100',
- },
- },
- },
- plugins: [
- typeScale,
- vanillaRTL,
- scrollbarThin,
- /**
- * 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)');
- }),
- /**
- * TypeScale plugin.
- * 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.
- */
- 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);
- }),
- ],
- corePlugins: {
- ...vanillaRTL.disabledCorePlugins,
- // Disable float and clear which have poor RTL support.
- float: false,
- clear: false,
- // Disable text-transform so we don’t rely on uppercasing text.
- textTransform: false,
- },
- variants: {
- extend: {
- backgroundColor: ['forced-colors'],
- width: ['forced-colors'],
- height: ['forced-colors'],
- },
- },
- };
|