Skip to content

Commit b3e8e4d

Browse files
Proposal: Allow overwriting static utilities that have a namespace
1 parent d69604e commit b3e8e4d

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

packages/tailwindcss/src/utilities.test.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9683,6 +9683,25 @@ test('rounded', async () => {
96839683
border-radius: var(--radius-sm);
96849684
}"
96859685
`)
9686+
expect(
9687+
await compileCss(
9688+
css`
9689+
@theme {
9690+
--radius-full: 99999px;
9691+
}
9692+
@tailwind utilities;
9693+
`,
9694+
['rounded-full'],
9695+
),
9696+
).toMatchInlineSnapshot(`
9697+
":root, :host {
9698+
--radius-full: 99999px;
9699+
}
9700+
9701+
.rounded-full {
9702+
border-radius: var(--radius-full);
9703+
}"
9704+
`)
96869705
expect(
96879706
await run([
96889707
'-rounded',
@@ -9858,15 +9877,11 @@ test('rounded-t', async () => {
98589877
}
98599878

98609879
.rounded-t-full {
9861-
border-top-left-radius: 3.40282e38px;
9862-
border-top-right-radius: 3.40282e38px;
98639880
border-top-left-radius: var(--radius-full);
98649881
border-top-right-radius: var(--radius-full);
98659882
}
98669883

98679884
.rounded-t-none {
9868-
border-top-left-radius: 0;
9869-
border-top-right-radius: 0;
98709885
border-top-left-radius: var(--radius-none);
98719886
border-top-right-radius: var(--radius-none);
98729887
}
@@ -9925,15 +9940,11 @@ test('rounded-r', async () => {
99259940
}
99269941

99279942
.rounded-r-full {
9928-
border-top-right-radius: 3.40282e38px;
9929-
border-bottom-right-radius: 3.40282e38px;
99309943
border-top-right-radius: var(--radius-full);
99319944
border-bottom-right-radius: var(--radius-full);
99329945
}
99339946

99349947
.rounded-r-none {
9935-
border-top-right-radius: 0;
9936-
border-bottom-right-radius: 0;
99379948
border-top-right-radius: var(--radius-none);
99389949
border-bottom-right-radius: var(--radius-none);
99399950
}
@@ -9992,15 +10003,11 @@ test('rounded-b', async () => {
999210003
}
999310004

999410005
.rounded-b-full {
9995-
border-bottom-right-radius: 3.40282e38px;
9996-
border-bottom-left-radius: 3.40282e38px;
999710006
border-bottom-right-radius: var(--radius-full);
999810007
border-bottom-left-radius: var(--radius-full);
999910008
}
1000010009

1000110010
.rounded-b-none {
10002-
border-bottom-right-radius: 0;
10003-
border-bottom-left-radius: 0;
1000410011
border-bottom-right-radius: var(--radius-none);
1000510012
border-bottom-left-radius: var(--radius-none);
1000610013
}
@@ -10059,15 +10066,11 @@ test('rounded-l', async () => {
1005910066
}
1006010067

1006110068
.rounded-l-full {
10062-
border-top-left-radius: 3.40282e38px;
10063-
border-bottom-left-radius: 3.40282e38px;
1006410069
border-top-left-radius: var(--radius-full);
1006510070
border-bottom-left-radius: var(--radius-full);
1006610071
}
1006710072

1006810073
.rounded-l-none {
10069-
border-top-left-radius: 0;
10070-
border-bottom-left-radius: 0;
1007110074
border-top-left-radius: var(--radius-none);
1007210075
border-bottom-left-radius: var(--radius-none);
1007310076
}
@@ -10356,12 +10359,10 @@ test('rounded-tl', async () => {
1035610359
}
1035710360

1035810361
.rounded-tl-full {
10359-
border-top-left-radius: 3.40282e38px;
1036010362
border-top-left-radius: var(--radius-full);
1036110363
}
1036210364

1036310365
.rounded-tl-none {
10364-
border-top-left-radius: 0;
1036510366
border-top-left-radius: var(--radius-none);
1036610367
}
1036710368

@@ -10416,12 +10417,10 @@ test('rounded-tr', async () => {
1041610417
}
1041710418

1041810419
.rounded-tr-full {
10419-
border-top-right-radius: 3.40282e38px;
1042010420
border-top-right-radius: var(--radius-full);
1042110421
}
1042210422

1042310423
.rounded-tr-none {
10424-
border-top-right-radius: 0;
1042510424
border-top-right-radius: var(--radius-none);
1042610425
}
1042710426

@@ -10476,12 +10475,10 @@ test('rounded-br', async () => {
1047610475
}
1047710476

1047810477
.rounded-br-full {
10479-
border-bottom-right-radius: 3.40282e38px;
1048010478
border-bottom-right-radius: var(--radius-full);
1048110479
}
1048210480

1048310481
.rounded-br-none {
10484-
border-bottom-right-radius: 0;
1048510482
border-bottom-right-radius: var(--radius-none);
1048610483
}
1048710484

@@ -10536,12 +10533,10 @@ test('rounded-bl', async () => {
1053610533
}
1053710534

1053810535
.rounded-bl-full {
10539-
border-bottom-left-radius: 3.40282e38px;
1054010536
border-bottom-left-radius: var(--radius-full);
1054110537
}
1054210538

1054310539
.rounded-bl-none {
10544-
border-bottom-left-radius: 0;
1054510540
border-bottom-left-radius: var(--radius-none);
1054610541
}
1054710542

packages/tailwindcss/src/utilities.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ export function createUtilities(theme: Theme) {
371371
supportsFractions?: boolean
372372
themeKeys?: ThemeKey[]
373373
defaultValue?: string | null
374+
fallbacks?: Record<string, AstNode[]>
374375
handleBareValue?: (value: NamedUtilityValue) => string | null
375376
handleNegativeBareValue?: (value: NamedUtilityValue) => string | null
376377
handle: (value: string, dataType: string | null) => AstNode[] | undefined
@@ -427,6 +428,14 @@ export function createUtilities(theme: Theme) {
427428
value = desc.handleBareValue(candidate.value)
428429
if (!value?.includes('/') && candidate.modifier) return
429430
}
431+
432+
if (value === null && desc.fallbacks) {
433+
let fallback = desc.fallbacks[candidate.value.value]
434+
if (fallback) {
435+
if (candidate.modifier) return
436+
return fallback
437+
}
438+
}
430439
}
431440

432441
// If there is no value, don't generate any rules.
@@ -2119,17 +2128,13 @@ export function createUtilities(theme: Theme) {
21192128
['rounded-br', ['border-bottom-right-radius']],
21202129
['rounded-bl', ['border-bottom-left-radius']],
21212130
] as const) {
2122-
staticUtility(
2123-
`${root}-none`,
2124-
properties.map((property) => [property, '0']),
2125-
)
2126-
staticUtility(
2127-
`${root}-full`,
2128-
properties.map((property) => [property, 'calc(infinity * 1px)']),
2129-
)
21302131
functionalUtility(root, {
21312132
themeKeys: ['--radius'],
21322133
handle: (value) => properties.map((property) => decl(property, value)),
2134+
fallbacks: {
2135+
none: properties.map((property) => decl(property, '0')),
2136+
full: properties.map((property) => decl(property, 'calc(infinity * 1px)')),
2137+
},
21332138
})
21342139
}
21352140
}

0 commit comments

Comments
 (0)