gradientColorStops.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { run, html, css } from '../util/run'
  2. test('opacity variables are given to colors defined as closures', () => {
  3. let config = {
  4. content: [
  5. {
  6. raw: html`<div
  7. class="text-primary text-secondary from-primary from-secondary via-primary via-secondary to-primary to-secondary text-opacity-50"
  8. ></div>`,
  9. },
  10. ],
  11. theme: {
  12. colors: {
  13. primary: ({ opacityVariable, opacityValue }) => {
  14. if (opacityValue !== undefined) {
  15. return `rgba(31,31,31,${opacityValue})`
  16. }
  17. if (opacityVariable !== undefined) {
  18. return `rgba(31,31,31,var(${opacityVariable},1))`
  19. }
  20. return `rgb(31,31,31)`
  21. },
  22. secondary: 'hsl(10, 50%, 50%)',
  23. },
  24. opacity: {
  25. 50: '0.5',
  26. },
  27. },
  28. }
  29. return run('@tailwind utilities', config).then((result) => {
  30. expect(result.css).toMatchFormattedCss(css`
  31. .from-primary {
  32. --tw-gradient-from: rgb(31, 31, 31);
  33. --tw-gradient-to: rgba(31, 31, 31, 0);
  34. --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
  35. }
  36. .from-secondary {
  37. --tw-gradient-from: hsl(10, 50%, 50%);
  38. --tw-gradient-to: hsl(10 50% 50% / 0);
  39. --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to);
  40. }
  41. .via-primary {
  42. --tw-gradient-to: rgba(31, 31, 31, 0);
  43. --tw-gradient-stops: var(--tw-gradient-from), rgb(31, 31, 31), var(--tw-gradient-to);
  44. }
  45. .via-secondary {
  46. --tw-gradient-to: hsl(10 50% 50% / 0);
  47. --tw-gradient-stops: var(--tw-gradient-from), hsl(10, 50%, 50%), var(--tw-gradient-to);
  48. }
  49. .to-primary {
  50. --tw-gradient-to: rgb(31, 31, 31);
  51. }
  52. .to-secondary {
  53. --tw-gradient-to: hsl(10, 50%, 50%);
  54. }
  55. .text-primary {
  56. --tw-text-opacity: 1;
  57. color: rgba(31, 31, 31, var(--tw-text-opacity));
  58. }
  59. .text-secondary {
  60. --tw-text-opacity: 1;
  61. color: hsl(10 50% 50% / var(--tw-text-opacity));
  62. }
  63. .text-opacity-50 {
  64. --tw-text-opacity: 0.5;
  65. }
  66. `)
  67. })
  68. })