Skip to content

Commit de33f88

Browse files
committed
add more custom values to default config
1 parent 454493c commit de33f88

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

src/config-validators.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ const stringLengths = new Set(['px', 'full', 'screen'])
44
const lengthUnitRegex = /\d+(%|px|em|rem|vh|vw|pt|pc|in|cm|mm|cap|ch|ex|lh|rlh|vi|vb|vmin|vmax)/
55

66
export function isLength(classPart: string) {
7+
return (
8+
isCustomLength(classPart) ||
9+
!Number.isNaN(Number(classPart)) ||
10+
stringLengths.has(classPart) ||
11+
fractionRegex.test(classPart)
12+
)
13+
}
14+
15+
export function isCustomLength(classPart: string) {
716
const customValue = customValueRegex.exec(classPart)?.[1]
817

918
if (customValue) {
1019
return customValue.startsWith('length:') || lengthUnitRegex.test(customValue)
1120
}
1221

13-
return (
14-
!Number.isNaN(Number(classPart)) ||
15-
stringLengths.has(classPart) ||
16-
fractionRegex.test(classPart)
17-
)
22+
return false
1823
}
1924

2025
export function isInteger(classPart: string) {

src/default-config.ts

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isAny, isCustomValue, isInteger, isLength } from './config-validators'
1+
import { isAny, isCustomLength, isCustomValue, isInteger, isLength } from './config-validators'
22

33
const SIZES_SIMPLE = ['sm', 'md', 'lg', 'xl', '2xl'] as const
44
const SIZES_EXTENDED = ['3xl', '4xl', '5xl', '6xl', '7xl'] as const
@@ -21,7 +21,7 @@ const POSITIONS = [
2121
'right-top',
2222
'top',
2323
] as const
24-
const ROUNDED = ['none', '', ...SIZES_SIMPLE, '3xl', 'full'] as const
24+
const ROUNDED = ['none', '', ...SIZES_SIMPLE, '3xl', 'full', isCustomLength] as const
2525
const BORDER_STYLES = ['solid', 'dashed', 'dotted', 'double', 'none'] as const
2626
const BLEND_MODES = [
2727
{
@@ -271,7 +271,7 @@ export function getDefaultConfig() {
271271
* Flex
272272
* @see https://tailwindcss.com/docs/flex
273273
*/
274-
flex: [{ flex: ['1', 'auto', 'initial', 'none'] }],
274+
flex: [{ flex: ['1', 'auto', 'initial', 'none', isCustomValue] }],
275275
/**
276276
* Flex Grow
277277
* @see https://tailwindcss.com/docs/flex-grow
@@ -543,13 +543,23 @@ export function getDefaultConfig() {
543543
* Font Family
544544
* @see https://tailwindcss.com/docs/font-family
545545
*/
546-
'font-family': [{ font: ['sans', 'serif', 'mono'] }],
546+
'font-family': [{ font: ANY }],
547547
/**
548548
* Font Size
549549
* @see https://tailwindcss.com/docs/font-size
550550
*/
551551
'font-size': [
552-
{ text: ['xs', ...SIZES_SIMPLE, 'base', ...SIZES_EXTENDED, '8xl', '9xl'] },
552+
{
553+
text: [
554+
'xs',
555+
...SIZES_SIMPLE,
556+
'base',
557+
...SIZES_EXTENDED,
558+
'8xl',
559+
'9xl',
560+
isCustomLength,
561+
],
562+
},
553563
],
554564
/**
555565
* Font Smoothing
@@ -614,7 +624,19 @@ export function getDefaultConfig() {
614624
* Letter Spacing
615625
* @see https://tailwindcss.com/docs/letter-spacing
616626
*/
617-
tracking: [{ tracking: ['tighter', 'tight', 'normal', 'wide', 'wider', 'widest'] }],
627+
tracking: [
628+
{
629+
tracking: [
630+
'tighter',
631+
'tight',
632+
'normal',
633+
'wide',
634+
'wider',
635+
'widest',
636+
isCustomLength,
637+
],
638+
},
639+
],
618640
/**
619641
* Line Height
620642
* @see https://tailwindcss.com/docs/line-height
@@ -954,7 +976,7 @@ export function getDefaultConfig() {
954976
* Blur
955977
* @see https://tailwindcss.com/docs/blur
956978
*/
957-
blur: [{ blur: ['none', '', ...SIZES_SIMPLE, '3xl'] }],
979+
blur: [{ blur: ['none', '', ...SIZES_SIMPLE, '3xl', isCustomLength] }],
958980
/**
959981
* Brightness
960982
* @see https://tailwindcss.com/docs/brightness
@@ -1170,6 +1192,7 @@ export function getDefaultConfig() {
11701192
'move',
11711193
'help',
11721194
'not-allowed',
1195+
isCustomValue,
11731196
],
11741197
},
11751198
],

0 commit comments

Comments
 (0)