-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #444 from dcastil/feature/440/allow-hooking-into-c…
…lass-parsing Allow hooking into class parsing logic (experimental)
- Loading branch information
Showing
10 changed files
with
123 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { createClassUtils } from './class-utils' | ||
import { createClassGroupUtils } from './class-group-utils' | ||
import { createLruCache } from './lru-cache' | ||
import { createSplitModifiers } from './modifier-utils' | ||
import { createParseClassName } from './parse-class-name' | ||
import { GenericConfig } from './types' | ||
|
||
export type ConfigUtils = ReturnType<typeof createConfigUtils> | ||
|
||
export function createConfigUtils(config: GenericConfig) { | ||
return { | ||
cache: createLruCache<string, string>(config.cacheSize), | ||
splitModifiers: createSplitModifiers(config), | ||
...createClassUtils(config), | ||
parseClassName: createParseClassName(config), | ||
...createClassGroupUtils(config), | ||
} | ||
} |
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
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,37 @@ | ||
import { extendTailwindMerge } from '../src' | ||
|
||
test('default case', () => { | ||
const twMerge = extendTailwindMerge({ | ||
experimentalParseClassName({ className, parseClassName }) { | ||
return parseClassName(className) | ||
}, | ||
}) | ||
|
||
expect(twMerge('px-2 py-1 p-3')).toBe('p-3') | ||
}) | ||
|
||
test('removing first three characters from class', () => { | ||
const twMerge = extendTailwindMerge({ | ||
experimentalParseClassName({ className, parseClassName }) { | ||
return parseClassName(className.slice(3)) | ||
}, | ||
}) | ||
|
||
expect(twMerge('barpx-2 foopy-1 lolp-3')).toBe('lolp-3') | ||
}) | ||
|
||
test('ignoring breakpoint modifiers', () => { | ||
const breakpoints = new Set(['sm', 'md', 'lg', 'xl', '2xl']) | ||
const twMerge = extendTailwindMerge({ | ||
experimentalParseClassName({ className, parseClassName }) { | ||
const parsed = parseClassName(className) | ||
|
||
return { | ||
...parsed, | ||
modifiers: parsed.modifiers.filter((modifier) => !breakpoints.has(modifier)), | ||
} | ||
}, | ||
}) | ||
|
||
expect(twMerge('md:px-2 hover:py-4 py-1 lg:p-3')).toBe('hover:py-4 lg:p-3') | ||
}) |