tailwind.config.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. typeScale,
  14. } = require('./src/tokens/typography');
  15. const { breakpoints } = require('./src/tokens/breakpoints');
  16. const {
  17. borderRadius,
  18. borderWidth,
  19. boxShadow,
  20. } = require('./src/tokens/objectStyles');
  21. const { spacing } = require('./src/tokens/spacing');
  22. /**
  23. * Plugins
  24. */
  25. const scrollbarThin = require('./src/plugins/scrollbarThin');
  26. /**
  27. * Functions
  28. * themeColors: For converting our design tokens into a format that tailwind accepts
  29. */
  30. const themeColors = Object.fromEntries(
  31. Object.entries(colors).map(([key, hues]) => {
  32. const shades = Object.fromEntries(
  33. Object.entries(hues).map(([k, shade]) => [k, shade.hex]),
  34. );
  35. return [key, shades];
  36. }),
  37. );
  38. /**
  39. * Root Tailwind config, reusable for other projects.
  40. */
  41. module.exports = {
  42. prefix: 'w-',
  43. theme: {
  44. screens: {
  45. ...breakpoints,
  46. },
  47. colors: {
  48. ...themeColors,
  49. inherit: 'inherit',
  50. current: 'currentColor',
  51. transparent: 'transparent',
  52. /* allow system colours https://www.w3.org/TR/css-color-4/#css-system-colors */
  53. LinkText: 'LinkText',
  54. ButtonText: 'ButtonText',
  55. },
  56. fontFamily,
  57. fontSize,
  58. fontWeight,
  59. lineHeight,
  60. letterSpacing,
  61. borderRadius,
  62. borderWidth,
  63. boxShadow: {
  64. ...boxShadow,
  65. none: 'none',
  66. },
  67. spacing,
  68. extend: {
  69. opacity: {
  70. 15: '0.15',
  71. 85: '0.85',
  72. },
  73. outlineOffset: {
  74. inside: '-3px',
  75. },
  76. transitionProperty: {
  77. sidebar:
  78. 'inset-inline-start, padding-inline-start, width, transform, margin-top, min-height',
  79. },
  80. zIndex: {
  81. header: '100',
  82. },
  83. },
  84. },
  85. plugins: [
  86. typeScale,
  87. vanillaRTL,
  88. scrollbarThin,
  89. /**
  90. * forced-colors media query for Windows High-Contrast mode support
  91. * See:
  92. * - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
  93. * - https://github.com/tailwindlabs/tailwindcss/blob/v3.0.23/src/corePlugins.js#L168-L171
  94. */
  95. plugin(({ addVariant }) => {
  96. addVariant('forced-colors', '@media (forced-colors: active)');
  97. }),
  98. /**
  99. * TypeScale plugin.
  100. * This plugin generates component classes using tailwind's theme values for each object inside of the typeScale configuration.
  101. * We have the `w-` prefix added in the configuration for documentation purposes, it needs to be removed here before Tailwind adds it back.
  102. */
  103. plugin(({ addComponents, theme }) => {
  104. const scale = {};
  105. Object.entries(typeScale).forEach(([name, styles]) => {
  106. scale[`.${name.replace('w-', '')}`] = Object.fromEntries(
  107. Object.entries(styles).map(([key, value]) => [key, theme(value)]),
  108. );
  109. });
  110. addComponents(scale);
  111. }),
  112. ],
  113. corePlugins: {
  114. ...vanillaRTL.disabledCorePlugins,
  115. // Disable float and clear which have poor RTL support.
  116. float: false,
  117. clear: false,
  118. // Disable text-transform so we don’t rely on uppercasing text.
  119. textTransform: false,
  120. },
  121. variants: {
  122. extend: {
  123. backgroundColor: ['forced-colors'],
  124. width: ['forced-colors'],
  125. height: ['forced-colors'],
  126. },
  127. },
  128. };