tailwind.config.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const plugin = require('tailwindcss/plugin');
  2. const vanillaRTL = require('tailwindcss-vanilla-rtl');
  3. /**
  4. * Design Tokens
  5. */
  6. const colors = require('./src/tokens/colors');
  7. const {
  8. fontFamily,
  9. fontSize,
  10. fontWeight,
  11. letterSpacing,
  12. lineHeight,
  13. } = require('./src/tokens/typography');
  14. const { breakpoints } = require('./src/tokens/breakpoints');
  15. const {
  16. borderRadius,
  17. borderWidth,
  18. boxShadow,
  19. } = require('./src/tokens/objectStyles');
  20. const { spacing } = require('./src/tokens/spacing');
  21. /**
  22. * Plugins
  23. */
  24. const typeScale = require('./src/tokens/typeScale');
  25. /**
  26. * Functions
  27. * themeColors: For converting our design tokens into a format that tailwind accepts
  28. */
  29. const themeColors = Object.fromEntries(
  30. Object.entries(colors).map(([key, hues]) => {
  31. const shades = Object.fromEntries(
  32. Object.entries(hues).map(([k, shade]) => [k, shade.hex]),
  33. );
  34. return [key, shades];
  35. }),
  36. );
  37. /**
  38. * Root Tailwind config, reusable for other projects.
  39. */
  40. module.exports = {
  41. prefix: 'w-',
  42. theme: {
  43. screens: {
  44. ...breakpoints,
  45. },
  46. colors: {
  47. ...themeColors,
  48. inherit: 'inherit',
  49. current: 'currentColor',
  50. transparent: 'transparent',
  51. /* allow system colours https://www.w3.org/TR/css-color-4/#css-system-colors */
  52. LinkText: 'LinkText',
  53. ButtonText: 'ButtonText',
  54. },
  55. fontFamily,
  56. fontSize,
  57. fontWeight,
  58. lineHeight,
  59. letterSpacing,
  60. borderRadius,
  61. borderWidth,
  62. boxShadow: {
  63. ...boxShadow,
  64. none: 'none',
  65. },
  66. spacing,
  67. },
  68. plugins: [
  69. typeScale,
  70. vanillaRTL,
  71. /**
  72. * forced-colors media query for Windows High-Contrast mode support
  73. * See:
  74. * - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
  75. * - https://github.com/tailwindlabs/tailwindcss/blob/v3.0.23/src/corePlugins.js#L168-L171
  76. */
  77. plugin(({ addVariant }) => {
  78. addVariant('forced-colors', '@media (forced-colors: active)');
  79. }),
  80. ],
  81. corePlugins: {
  82. ...vanillaRTL.disabledCorePlugins,
  83. // Disable float and clear which have poor RTL support.
  84. float: false,
  85. clear: false,
  86. },
  87. };