tailwind.config.js 2.4 KB

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