important-modifier.test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { run, html, css } from './util/run'
  2. test('important modifier', () => {
  3. let config = {
  4. important: false,
  5. darkMode: 'class',
  6. content: [
  7. {
  8. raw: html`
  9. <div class="!container"></div>
  10. <div class="!font-bold"></div>
  11. <div class="hover:!text-center"></div>
  12. <div class="lg:!opacity-50"></div>
  13. <div class="xl:focus:disabled:!float-right"></div>
  14. <div class="!custom-parent-5"></div>
  15. <div class="btn !disabled"></div>
  16. `,
  17. },
  18. ],
  19. corePlugins: { preflight: false },
  20. plugins: [
  21. function ({ theme, matchUtilities, addComponents }) {
  22. matchUtilities(
  23. {
  24. 'custom-parent': (value) => {
  25. return {
  26. '.custom-child': {
  27. margin: value,
  28. },
  29. }
  30. },
  31. },
  32. { values: theme('spacing') }
  33. )
  34. addComponents({
  35. '.btn': {
  36. '&.disabled, &:disabled': {
  37. color: 'gray',
  38. },
  39. },
  40. })
  41. },
  42. ],
  43. }
  44. let input = css`
  45. @tailwind components;
  46. @tailwind utilities;
  47. `
  48. return run(input, config).then((result) => {
  49. expect(result.css).toMatchFormattedCss(css`
  50. .\!container {
  51. width: 100% !important;
  52. }
  53. @media (min-width: 640px) {
  54. .\!container {
  55. max-width: 640px !important;
  56. }
  57. }
  58. @media (min-width: 768px) {
  59. .\!container {
  60. max-width: 768px !important;
  61. }
  62. }
  63. @media (min-width: 1024px) {
  64. .\!container {
  65. max-width: 1024px !important;
  66. }
  67. }
  68. @media (min-width: 1280px) {
  69. .\!container {
  70. max-width: 1280px !important;
  71. }
  72. }
  73. @media (min-width: 1536px) {
  74. .\!container {
  75. max-width: 1536px !important;
  76. }
  77. }
  78. .btn.disabled,
  79. .btn:disabled {
  80. color: gray;
  81. }
  82. .btn.\!disabled {
  83. color: gray !important;
  84. }
  85. .\!font-bold {
  86. font-weight: 700 !important;
  87. }
  88. .\!custom-parent-5 .custom-child {
  89. margin: 1.25rem !important;
  90. }
  91. .hover\:\!text-center:hover {
  92. text-align: center !important;
  93. }
  94. @media (min-width: 1024px) {
  95. .lg\:\!opacity-50 {
  96. opacity: 0.5 !important;
  97. }
  98. }
  99. @media (min-width: 1280px) {
  100. .xl\:focus\:disabled\:\!float-right:disabled:focus {
  101. float: right !important;
  102. }
  103. }
  104. `)
  105. })
  106. })
  107. test('the important modifier works on utilities using :where()', () => {
  108. let config = {
  109. content: [
  110. {
  111. raw: html` <div class="btn hover:btn !btn hover:focus:disabled:!btn"></div> `,
  112. },
  113. ],
  114. corePlugins: { preflight: false },
  115. plugins: [
  116. function ({ addComponents }) {
  117. addComponents({
  118. ':where(.btn)': {
  119. backgroundColor: '#00f',
  120. },
  121. })
  122. },
  123. ],
  124. }
  125. let input = css`
  126. @tailwind components;
  127. @tailwind utilities;
  128. `
  129. return run(input, config).then((result) => {
  130. expect(result.css).toMatchFormattedCss(css`
  131. :where(.\!btn) {
  132. background-color: #00f !important;
  133. }
  134. :where(.btn),
  135. :where(.hover\:btn:hover) {
  136. background-color: #00f;
  137. }
  138. :where(.hover\:focus\:disabled\:\!btn:disabled:focus:hover) {
  139. background-color: #00f !important;
  140. }
  141. `)
  142. })
  143. })