tailwind.config.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. extend: {
  68. opacity: {
  69. 15: '0.15',
  70. 85: '0.85',
  71. },
  72. },
  73. },
  74. plugins: [
  75. typeScale,
  76. vanillaRTL,
  77. /**
  78. * forced-colors media query for Windows High-Contrast mode support
  79. * See:
  80. * - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
  81. * - https://github.com/tailwindlabs/tailwindcss/blob/v3.0.23/src/corePlugins.js#L168-L171
  82. */
  83. plugin(({ addVariant }) => {
  84. addVariant('forced-colors', '@media (forced-colors: active)');
  85. }),
  86. ],
  87. corePlugins: {
  88. ...vanillaRTL.disabledCorePlugins,
  89. // Disable float and clear which have poor RTL support.
  90. float: false,
  91. clear: false,
  92. // Disable text-transform so we don’t rely on uppercasing text.
  93. textTransform: false,
  94. },
  95. };