negative-prefix.test.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. import { run, html, css } from './util/run'
  2. test('using a negative prefix with a negative scale value', () => {
  3. let config = {
  4. content: [{ raw: html`<div class="mt-2 -mt-2"></div>` }],
  5. theme: {
  6. margin: {
  7. 2: '8px',
  8. '-2': '-4px',
  9. },
  10. },
  11. }
  12. return run('@tailwind utilities', config).then((result) => {
  13. return expect(result.css).toMatchCss(css`
  14. .mt-2 {
  15. margin-top: 8px;
  16. }
  17. .-mt-2 {
  18. margin-top: -4px;
  19. }
  20. `)
  21. })
  22. })
  23. test('using a negative scale value with a plugin that does not support dynamic negative values', () => {
  24. let config = {
  25. content: [{ raw: html`<div class="-opacity-50"></div>` }],
  26. theme: {
  27. opacity: {
  28. '-50': '0.5',
  29. },
  30. },
  31. }
  32. return run('@tailwind utilities', config).then((result) => {
  33. return expect(result.css).toMatchCss(css`
  34. .-opacity-50 {
  35. opacity: 0.5;
  36. }
  37. `)
  38. })
  39. })
  40. test('using a negative prefix without a negative scale value', () => {
  41. let config = {
  42. content: [{ raw: html`<div class="mt-5 -mt-5"></div>` }],
  43. theme: {
  44. margin: {
  45. 5: '20px',
  46. },
  47. },
  48. }
  49. return run('@tailwind utilities', config).then((result) => {
  50. return expect(result.css).toMatchCss(css`
  51. .mt-5 {
  52. margin-top: 20px;
  53. }
  54. .-mt-5 {
  55. margin-top: -20px;
  56. }
  57. `)
  58. })
  59. })
  60. test('being an asshole', () => {
  61. let config = {
  62. content: [{ raw: html`<div class="-mt-[10px]"></div>` }],
  63. theme: {
  64. margin: {
  65. '-[10px]': '55px',
  66. },
  67. },
  68. }
  69. return run('@tailwind utilities', config).then((result) => {
  70. return expect(result.css).toMatchCss(css`
  71. .-mt-\[10px\] {
  72. margin-top: 55px;
  73. }
  74. `)
  75. })
  76. })
  77. test('being a real asshole', () => {
  78. let config = {
  79. content: [{ raw: html`<div class="-mt-[10px]"></div>` }],
  80. theme: {
  81. margin: {
  82. '[10px]': '55px',
  83. },
  84. },
  85. }
  86. return run('@tailwind utilities', config).then((result) => {
  87. return expect(result.css).toMatchCss(css`
  88. .-mt-\[10px\] {
  89. margin-top: -55px;
  90. }
  91. `)
  92. })
  93. })
  94. test('a value that includes a variable', () => {
  95. let config = {
  96. content: [{ raw: html`<div class="mt-5 -mt-5"></div>` }],
  97. theme: {
  98. margin: {
  99. 5: 'var(--sizing-5)',
  100. },
  101. },
  102. }
  103. return run('@tailwind utilities', config).then((result) => {
  104. return expect(result.css).toMatchCss(css`
  105. .mt-5 {
  106. margin-top: var(--sizing-5);
  107. }
  108. .-mt-5 {
  109. margin-top: calc(var(--sizing-5) * -1);
  110. }
  111. `)
  112. })
  113. })
  114. test('a value that includes a calc', () => {
  115. let config = {
  116. content: [{ raw: html`<div class="mt-5 -mt-5"></div>` }],
  117. theme: {
  118. margin: {
  119. 5: 'calc(52px * -3)',
  120. },
  121. },
  122. }
  123. return run('@tailwind utilities', config).then((result) => {
  124. return expect(result.css).toMatchCss(css`
  125. .mt-5 {
  126. margin-top: calc(52px * -3);
  127. }
  128. .-mt-5 {
  129. margin-top: calc(calc(52px * -3) * -1);
  130. }
  131. `)
  132. })
  133. })
  134. test('a value that includes min/max/clamp functions', () => {
  135. let config = {
  136. content: [{ raw: html`<div class="mt-min -mt-min mt-max -mt-max mt-clamp -mt-clamp"></div>` }],
  137. theme: {
  138. margin: {
  139. 'min': 'min(100vmin, 3rem)',
  140. 'max': 'max(100vmax, 3rem)',
  141. 'clamp': 'clamp(1rem, 100vh, 3rem)',
  142. },
  143. },
  144. }
  145. return run('@tailwind utilities', config).then((result) => {
  146. return expect(result.css).toMatchCss(css`
  147. .mt-min {
  148. margin-top: min(100vmin, 3rem);
  149. }
  150. .-mt-min {
  151. margin-top: calc(min(100vmin, 3rem) * -1);
  152. }
  153. .mt-max {
  154. margin-top: max(100vmax, 3rem);
  155. }
  156. .-mt-max {
  157. margin-top: calc(max(100vmax, 3rem) * -1);
  158. }
  159. .mt-clamp {
  160. margin-top: clamp(1rem, 100vh, 3rem);
  161. }
  162. .-mt-clamp {
  163. margin-top: calc(clamp(1rem, 100vh, 3rem) * -1);
  164. }
  165. `)
  166. })
  167. })
  168. test('a keyword value', () => {
  169. let config = {
  170. content: [{ raw: html`<div class="-mt-auto mt-auto"></div>` }],
  171. theme: {
  172. margin: {
  173. auto: 'auto',
  174. },
  175. },
  176. }
  177. return run('@tailwind utilities', config).then((result) => {
  178. return expect(result.css).toMatchCss(css`
  179. .mt-auto {
  180. margin-top: auto;
  181. }
  182. `)
  183. })
  184. })
  185. test('a zero value', () => {
  186. let config = {
  187. content: [{ raw: html`<div class="mt-0 -mt-0"></div>` }],
  188. theme: {
  189. margin: {
  190. 0: '0',
  191. },
  192. },
  193. }
  194. return run('@tailwind utilities', config).then((result) => {
  195. return expect(result.css).toMatchCss(css`
  196. .mt-0 {
  197. margin-top: 0;
  198. }
  199. .-mt-0 {
  200. margin-top: 0;
  201. }
  202. `)
  203. })
  204. })
  205. test('a color', () => {
  206. let config = {
  207. content: [{ raw: html`<div class="-bg-red"></div>` }],
  208. theme: {
  209. colors: {
  210. red: 'red',
  211. },
  212. },
  213. }
  214. return run('@tailwind utilities', config).then((result) => {
  215. return expect(result.css).toMatchCss(css``)
  216. })
  217. })
  218. test('arbitrary values', () => {
  219. let config = {
  220. content: [{ raw: html`<div class="-mt-[10px]"></div>` }],
  221. }
  222. return run('@tailwind utilities', config).then((result) => {
  223. return expect(result.css).toMatchCss(css`
  224. .-mt-\[10px\] {
  225. margin-top: -10px;
  226. }
  227. `)
  228. })
  229. })
  230. test('negating a negative scale value', () => {
  231. let config = {
  232. content: [{ raw: html`<div class="-mt-weird"></div>` }],
  233. theme: {
  234. margin: {
  235. weird: '-15px',
  236. },
  237. },
  238. }
  239. return run('@tailwind utilities', config).then((result) => {
  240. return expect(result.css).toMatchCss(css`
  241. .-mt-weird {
  242. margin-top: 15px;
  243. }
  244. `)
  245. })
  246. })
  247. test('negating a default value', () => {
  248. let config = {
  249. content: [{ raw: html`<div class="-mt"></div>` }],
  250. theme: {
  251. margin: {
  252. DEFAULT: '15px',
  253. },
  254. },
  255. }
  256. return run('@tailwind utilities', config).then((result) => {
  257. return expect(result.css).toMatchCss(css`
  258. .-mt {
  259. margin-top: -15px;
  260. }
  261. `)
  262. })
  263. })
  264. test('using a negative prefix with a negative default scale value', () => {
  265. let config = {
  266. content: [{ raw: html`<div class="mt -mt"></div>` }],
  267. theme: {
  268. margin: {
  269. DEFAULT: '8px',
  270. '-DEFAULT': '-4px',
  271. },
  272. },
  273. }
  274. return run('@tailwind utilities', config).then((result) => {
  275. return expect(result.css).toMatchCss(css`
  276. .mt {
  277. margin-top: 8px;
  278. }
  279. .-mt {
  280. margin-top: -4px;
  281. }
  282. `)
  283. })
  284. })
  285. test('negating a default value with a configured prefix', () => {
  286. let config = {
  287. prefix: 'tw-',
  288. content: [{ raw: html`<div class="tw--mt"></div>` }],
  289. theme: {
  290. margin: {
  291. DEFAULT: '15px',
  292. },
  293. },
  294. }
  295. return run('@tailwind utilities', config).then((result) => {
  296. return expect(result.css).toMatchCss(css`
  297. .tw--mt {
  298. margin-top: -15px;
  299. }
  300. `)
  301. })
  302. })
  303. test('arbitrary value keywords should be ignored', () => {
  304. let config = {
  305. content: [{ raw: html`<div class="-mt-[auto]"></div>` }],
  306. }
  307. return run('@tailwind utilities', config).then((result) => {
  308. return expect(result.css).toMatchCss(css``)
  309. })
  310. })