Skip to content

Commit 8bd3c85

Browse files
authored
Derive all font-weight values from theme (#14883)
This PR removes all of the static `font-weight` utilities that were previously hard-coded into the framework in favor of deriving those utilities from the `--font-weight-*` theme values instead. Biggest motivation for this is giving people a way to explicitly disable font-weight utilities they don't want to use in their project, which previously wasn't possible. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent 7175605 commit 8bd3c85

File tree

7 files changed

+37
-64
lines changed

7 files changed

+37
-64
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- Remove `--transition-timing-function-linear` from the default theme in favor of a static `ease-linear` utility ([#14880](https://github.com/tailwindlabs/tailwindcss/pull/14880))
3636
- Remove default `--spacing-*` scale in favor of `--spacing` multiplier ([#14857](https://github.com/tailwindlabs/tailwindcss/pull/14857))
3737
- Remove `var(…)` fallbacks from theme values in utilities ([#14881](https://github.com/tailwindlabs/tailwindcss/pull/14881))
38+
- Remove static `font-weight` utilities and add `--font-weight-*` values to the default theme ([#14883](https://github.com/tailwindlabs/tailwindcss/pull/14883))
3839

3940
## [4.0.0-alpha.31] - 2024-10-29
4041

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
340340
--font-size-8xl--line-height: 1;
341341
--font-size-9xl: 8rem;
342342
--font-size-9xl--line-height: 1;
343+
--font-weight-thin: 100;
344+
--font-weight-extralight: 200;
345+
--font-weight-light: 300;
346+
--font-weight-normal: 400;
347+
--font-weight-medium: 500;
348+
--font-weight-semibold: 600;
349+
--font-weight-bold: 700;
350+
--font-weight-extrabold: 800;
351+
--font-weight-black: 900;
343352
--letter-spacing-tighter: -.05em;
344353
--letter-spacing-tight: -.025em;
345354
--letter-spacing-normal: 0em;
@@ -555,8 +564,8 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
555564
556565
@media (width >= 96rem) {
557566
.\\32 xl\\:font-bold {
558-
--tw-font-weight: 700;
559-
font-weight: 700;
567+
--tw-font-weight: var(--font-weight-bold);
568+
font-weight: var(--font-weight-bold);
560569
}
561570
}
562571
}

packages/@tailwindcss-upgrade/src/template/codemods/theme-to-var.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test.each([
9090
['grid-cols-[min(50%_,_theme(spacing.80))_auto]', 'grid-cols-[min(50%,var(--spacing-80))_auto]'],
9191

9292
// `theme(…)` calls valid in v3, but not in v4 should still be converted.
93-
['[--foo:theme(fontWeight.semibold)]', '[--foo:theme(fontWeight.semibold)]'],
93+
['[--foo:theme(transitionDuration.500)]', '[--foo:theme(transitionDuration.500)]'],
9494

9595
// `screens` values
9696
['max-w-[theme(screens.md)]', 'max-w-[var(--breakpoint-md)]'],

packages/tailwindcss/src/__snapshots__/index.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using
339339
--font-size-8xl--line-height: 1;
340340
--font-size-9xl: 8rem;
341341
--font-size-9xl--line-height: 1;
342+
--font-weight-thin: 100;
343+
--font-weight-extralight: 200;
344+
--font-weight-light: 300;
345+
--font-weight-normal: 400;
346+
--font-weight-medium: 500;
347+
--font-weight-semibold: 600;
348+
--font-weight-bold: 700;
349+
--font-weight-extrabold: 800;
350+
--font-weight-black: 900;
342351
--letter-spacing-tighter: -.05em;
343352
--letter-spacing-tight: -.025em;
344353
--letter-spacing-normal: 0em;

packages/tailwindcss/src/utilities.test.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12375,11 +12375,6 @@ test('font', async () => {
1237512375
font-weight: var(--my-family);
1237612376
}
1237712377
12378-
.font-bold {
12379-
--tw-font-weight: 700;
12380-
font-weight: 700;
12381-
}
12382-
1238312378
@supports (-moz-orient: inline) {
1238412379
@layer base {
1238512380
*, :before, :after, ::backdrop {
@@ -16430,7 +16425,7 @@ describe('custom utilities', () => {
1643016425
}
1643116426
1643216427
@utility bar {
16433-
@apply dark:foo font-bold;
16428+
@apply dark:foo flex-wrap;
1643416429
}
1643516430
1643616431
@tailwind utilities;
@@ -16439,8 +16434,7 @@ describe('custom utilities', () => {
1643916434
),
1644016435
).toMatchInlineSnapshot(`
1644116436
".bar {
16442-
--tw-font-weight: 700;
16443-
font-weight: 700;
16437+
flex-wrap: wrap;
1644416438
}
1644516439
1644616440
@media (prefers-color-scheme: dark) {
@@ -16449,19 +16443,6 @@ describe('custom utilities', () => {
1644916443
text-decoration-line: underline;
1645016444
display: flex;
1645116445
}
16452-
}
16453-
16454-
@supports (-moz-orient: inline) {
16455-
@layer base {
16456-
*, :before, :after, ::backdrop {
16457-
--tw-font-weight: initial;
16458-
}
16459-
}
16460-
}
16461-
16462-
@property --tw-font-weight {
16463-
syntax: "*";
16464-
inherits: false
1646516446
}"
1646616447
`)
1646716448
})
@@ -16471,7 +16452,7 @@ describe('custom utilities', () => {
1647116452
compileCss(
1647216453
css`
1647316454
@utility foo {
16474-
@apply font-bold hover:bar;
16455+
@apply flex-wrap hover:bar;
1647516456
}
1647616457
1647716458
@utility bar {
@@ -16495,7 +16476,7 @@ describe('custom utilities', () => {
1649516476
.bar {
1649616477
.baz {
1649716478
.qux {
16498-
@apply font-bold hover:bar;
16479+
@apply flex-wrap hover:bar;
1649916480
}
1650016481
}
1650116482
}

packages/tailwindcss/src/utilities.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,44 +2801,6 @@ export function createUtilities(theme: Theme) {
28012801
decl('font-weight', value),
28022802
]
28032803
}
2804-
2805-
switch (candidate.value.value) {
2806-
case 'thin':
2807-
value = '100'
2808-
break
2809-
case 'extralight':
2810-
value = '200'
2811-
break
2812-
case 'light':
2813-
value = '300'
2814-
break
2815-
case 'normal':
2816-
value = '400'
2817-
break
2818-
case 'medium':
2819-
value = '500'
2820-
break
2821-
case 'semibold':
2822-
value = '600'
2823-
break
2824-
case 'bold':
2825-
value = '700'
2826-
break
2827-
case 'extrabold':
2828-
value = '800'
2829-
break
2830-
case 'black':
2831-
value = '900'
2832-
break
2833-
}
2834-
2835-
if (value) {
2836-
return [
2837-
atRoot([property('--tw-font-weight')]),
2838-
decl('--tw-font-weight', value),
2839-
decl('font-weight', value),
2840-
]
2841-
}
28422804
}
28432805
})
28442806

packages/tailwindcss/theme.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,17 @@
386386
--font-size-9xl: 8rem;
387387
--font-size-9xl--line-height: 1;
388388

389+
/* Font weights */
390+
--font-weight-thin: 100;
391+
--font-weight-extralight: 200;
392+
--font-weight-light: 300;
393+
--font-weight-normal: 400;
394+
--font-weight-medium: 500;
395+
--font-weight-semibold: 600;
396+
--font-weight-bold: 700;
397+
--font-weight-extrabold: 800;
398+
--font-weight-black: 900;
399+
389400
/* Letter spacing */
390401
--letter-spacing-tighter: -0.05em;
391402
--letter-spacing-tight: -0.025em;

0 commit comments

Comments
 (0)