tailwind.config.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 { generateColorVariables } = require('./src/tokens/colorVariables');
  8. const {
  9. fontFamily,
  10. fontSize,
  11. fontWeight,
  12. letterSpacing,
  13. lineHeight,
  14. typeScale,
  15. } = require('./src/tokens/typography');
  16. const { breakpoints } = require('./src/tokens/breakpoints');
  17. const {
  18. borderRadius,
  19. borderWidth,
  20. boxShadow,
  21. } = require('./src/tokens/objectStyles');
  22. const { spacing } = require('./src/tokens/spacing');
  23. /**
  24. * Plugins
  25. */
  26. const scrollbarThin = require('./src/plugins/scrollbarThin');
  27. /**
  28. * Functions
  29. * themeColors: For converting our design tokens into a format that tailwind accepts
  30. */
  31. const themeColors = Object.fromEntries(
  32. Object.entries(colors).map(([key, hues]) => {
  33. const shades = Object.fromEntries(
  34. Object.entries(hues).map(([k, shade]) => [
  35. k,
  36. `var(${shade.cssVariable})`,
  37. ]),
  38. );
  39. return [key, shades];
  40. }),
  41. );
  42. /**
  43. * Root Tailwind config, reusable for other projects.
  44. */
  45. module.exports = {
  46. prefix: 'w-',
  47. theme: {
  48. screens: {
  49. ...breakpoints,
  50. },
  51. colors: {
  52. ...themeColors,
  53. // Fades of white and black are not customisable.
  54. 'white-15': 'rgba(255, 255, 255, 0.15)',
  55. 'white-50': 'rgba(255, 255, 255, 0.50)',
  56. 'white-80': 'rgba(255, 255, 255, 0.80)',
  57. 'black-10': 'rgba(0, 0, 0, 0.10)',
  58. 'black-20': 'rgba(0, 0, 0, 0.20)',
  59. 'black-35': 'rgba(0, 0, 0, 0.35)',
  60. 'black-50': 'rgba(0, 0, 0, 0.50)',
  61. // Color keywords.
  62. 'inherit': 'inherit',
  63. 'current': 'currentColor',
  64. 'transparent': 'transparent',
  65. /* allow system colours https://www.w3.org/TR/css-color-4/#css-system-colors */
  66. 'LinkText': 'LinkText',
  67. 'ButtonText': 'ButtonText',
  68. },
  69. fontFamily: {
  70. sans: 'var(--w-font-sans)',
  71. mono: 'var(--w-font-mono)',
  72. },
  73. fontSize,
  74. fontWeight,
  75. lineHeight,
  76. letterSpacing,
  77. borderRadius,
  78. borderWidth,
  79. boxShadow: {
  80. ...boxShadow,
  81. none: 'none',
  82. },
  83. spacing,
  84. extend: {
  85. outlineOffset: {
  86. inside: '-3px',
  87. },
  88. transitionProperty: {
  89. sidebar:
  90. 'inset-inline-start, padding-inline-start, width, transform, margin-top, min-height',
  91. },
  92. zIndex: {
  93. 'header': '100',
  94. 'sidebar': '110',
  95. 'sidebar-toggle': '120',
  96. 'dialog': '130',
  97. },
  98. keyframes: {
  99. 'fade-in': {
  100. '0%': { opacity: 0 },
  101. '100%': { opacity: 1 },
  102. },
  103. },
  104. animation: {
  105. 'fade-in': 'fade-in 150ms both',
  106. },
  107. },
  108. },
  109. plugins: [
  110. typeScale,
  111. vanillaRTL,
  112. scrollbarThin,
  113. /**
  114. * forced-colors media query for Windows High-Contrast mode support
  115. * See:
  116. * - https://developer.mozilla.org/en-US/docs/Web/CSS/@media/forced-colors
  117. * - https://github.com/tailwindlabs/tailwindcss/blob/v3.0.23/src/corePlugins.js#L168-L171
  118. */
  119. plugin(({ addVariant }) => {
  120. addVariant('forced-colors', '@media (forced-colors: active)');
  121. }),
  122. /**
  123. * TypeScale plugin.
  124. * This plugin generates component classes using tailwind's theme values for each object inside of the typeScale configuration.
  125. * We have the `w-` prefix added in the configuration for documentation purposes, it needs to be removed here before Tailwind adds it back.
  126. */
  127. plugin(({ addComponents, theme }) => {
  128. const scale = {};
  129. Object.entries(typeScale).forEach(([name, styles]) => {
  130. scale[`.${name.replace('w-', '')}`] = Object.fromEntries(
  131. Object.entries(styles).map(([key, value]) => [key, theme(value)]),
  132. );
  133. });
  134. addComponents(scale);
  135. }),
  136. /**
  137. * CSS Custom properties defined from our design tokens.
  138. */
  139. plugin(({ addBase }) => {
  140. addBase({
  141. ':root': {
  142. '--w-font-sans': fontFamily.sans.join(', '),
  143. '--w-font-mono': fontFamily.mono.join(', '),
  144. ...generateColorVariables(colors),
  145. },
  146. });
  147. }),
  148. ],
  149. corePlugins: {
  150. ...vanillaRTL.disabledCorePlugins,
  151. // Disable float and clear which have poor RTL support.
  152. float: false,
  153. clear: false,
  154. // Disable text-transform so we don’t rely on uppercasing text.
  155. textTransform: false,
  156. },
  157. variants: {
  158. extend: {
  159. backgroundColor: ['forced-colors'],
  160. width: ['forced-colors'],
  161. height: ['forced-colors'],
  162. },
  163. },
  164. };