Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function will be used by the `prettier-plugin-tailwindcss` plugin, this way the sorting happens within Tailwind CSS itself adn the `prettier-plugin-tailwindcss` plugin doesn't have to use internal / private APIs. The signature looks like this: ```ts function sortClassList(classes: string[]): string[] ``` E.g.: ```js let sortedClasses = context.sortClassList(['p-1', 'm-1', 'container']) ```
- Loading branch information
1 parent
5807529
commit 4822d62
Showing
5 changed files
with
171 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import resolveConfig from '../src/public/resolve-config' | ||
import { createContext } from '../src/lib/setupContextUtils' | ||
|
||
it.each([ | ||
// Utitlies | ||
['px-3 p-1 py-3', 'p-1 px-3 py-3'], | ||
|
||
// Utitlies and components | ||
['px-4 container', 'container px-4'], | ||
|
||
// Utilities with variants | ||
['px-3 focus:hover:p-3 hover:p-1 py-3', 'px-3 py-3 hover:p-1 focus:hover:p-3'], | ||
|
||
// Components with variants | ||
['hover:container container', 'container hover:container'], | ||
|
||
// Components and utilities with variants | ||
[ | ||
'focus:hover:container hover:underline hover:container p-1', | ||
'p-1 hover:container hover:underline focus:hover:container', | ||
], | ||
|
||
// Leave user css order alone, and move to the front | ||
['b p-1 a', 'b a p-1'], | ||
['hover:b focus:p-1 a', 'hover:b a focus:p-1'], | ||
|
||
// Add special treatment for `group` and `peer` | ||
['a peer container underline', 'a container peer underline'], | ||
])('should sort "%s" based on the order we generate them in to "%s"', (input, output) => { | ||
let config = {} | ||
let context = createContext(resolveConfig(config)) | ||
expect(context.sortClassList(input.split(' '))).toEqual(output.split(' ')) | ||
}) | ||
|
||
it.each([ | ||
// Utitlies | ||
['tw-px-3 tw-p-1 tw-py-3', 'tw-p-1 tw-px-3 tw-py-3'], | ||
|
||
// Utitlies and components | ||
['tw-px-4 tw-container', 'tw-container tw-px-4'], | ||
|
||
// Utilities with variants | ||
[ | ||
'tw-px-3 focus:hover:tw-p-3 hover:tw-p-1 tw-py-3', | ||
'tw-px-3 tw-py-3 hover:tw-p-1 focus:hover:tw-p-3', | ||
], | ||
|
||
// Components with variants | ||
['hover:tw-container tw-container', 'tw-container hover:tw-container'], | ||
|
||
// Components and utilities with variants | ||
[ | ||
'focus:hover:tw-container hover:tw-underline hover:tw-container tw-p-1', | ||
'tw-p-1 hover:tw-container hover:tw-underline focus:hover:tw-container', | ||
], | ||
|
||
// Leave user css order alone, and move to the front | ||
['b tw-p-1 a', 'b a tw-p-1'], | ||
['hover:b focus:tw-p-1 a', 'hover:b a focus:tw-p-1'], | ||
|
||
// Add special treatment for `group` and `peer` | ||
['a tw-peer tw-container tw-underline', 'a tw-container tw-peer tw-underline'], | ||
])( | ||
'should sort "%s" with prefixex based on the order we generate them in to "%s"', | ||
(input, output) => { | ||
let config = { prefix: 'tw-' } | ||
let context = createContext(resolveConfig(config)) | ||
expect(context.sortClassList(input.split(' '))).toEqual(output.split(' ')) | ||
} | ||
) | ||
|
||
// TODO: Copy test from above using prefix |