Skip to content

Commit 7132875

Browse files
authored
[v4] Add font-stretch utilities (#13153)
* [v4] Add `font-stretch` utilities Based on #12171 y @Gregory-Gerard. Add [`font-stretch`](https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch) utilities. Naming with `font-stretch` rather than `stretch` since the latter isn't clearly associated with fonts. Named values (e.g. `font-stretch-ulta-expanded`) and percentages (e.g. `font-stretch-50`) are supported.
1 parent 0e1af11 commit 7132875

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `font-stretch` utilities ([#13153](https://github.com/tailwindlabs/tailwindcss/pull/13153))
13+
1014
### Fixed
1115

1216
- Don't error on `@apply` with leading/trailing whitespace ([#13144](https://github.com/tailwindlabs/tailwindcss/pull/13144))

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,25 @@ exports[`getClassList 1`] = `
714714
"font-medium",
715715
"font-normal",
716716
"font-semibold",
717+
"font-stretch-100",
718+
"font-stretch-105",
719+
"font-stretch-110",
720+
"font-stretch-125",
721+
"font-stretch-150",
722+
"font-stretch-200",
723+
"font-stretch-50",
724+
"font-stretch-75",
725+
"font-stretch-90",
726+
"font-stretch-95",
727+
"font-stretch-condensed",
728+
"font-stretch-expanded",
729+
"font-stretch-extra-condensed",
730+
"font-stretch-extra-expanded",
731+
"font-stretch-normal",
732+
"font-stretch-semi-condensed",
733+
"font-stretch-semi-expanded",
734+
"font-stretch-ultra-condensed",
735+
"font-stretch-ultra-expanded",
717736
"font-thin",
718737
"forced-color-adjust-auto",
719738
"forced-color-adjust-none",

packages/tailwindcss/src/property-order.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ export default [
257257
'font-weight',
258258
'text-transform',
259259
'font-style',
260+
'font-stretch',
260261
'font-variant-numeric',
261262
'line-height',
262263
'letter-spacing',

packages/tailwindcss/src/utilities.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8788,6 +8788,26 @@ test('font-style', () => {
87888788
expect(run(['-italic', '-not-italic'])).toEqual('')
87898789
})
87908790

8791+
test('font-stretch', () => {
8792+
expect(run(['font-stretch-ultra-expanded', 'font-stretch-50', 'font-stretch-200']))
8793+
.toMatchInlineSnapshot(`
8794+
".font-stretch-200 {
8795+
font-stretch: 200%;
8796+
}
8797+
8798+
.font-stretch-50 {
8799+
font-stretch: 50%;
8800+
}
8801+
8802+
.font-stretch-ultra-expanded {
8803+
font-stretch: ultra-expanded;
8804+
}"
8805+
`)
8806+
expect(
8807+
run(['font-stretch', 'font-stretch-20', 'font-stretch-400', 'font-stretch-potato']),
8808+
).toEqual('')
8809+
})
8810+
87918811
test('text-decoration-line', () => {
87928812
expect(run(['underline', 'overline', 'line-through', 'no-underline'])).toMatchInlineSnapshot(`
87938813
".line-through {

packages/tailwindcss/src/utilities.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,6 +2865,32 @@ export function createUtilities(theme: Theme) {
28652865
staticUtility('line-through', [['text-decoration-line', 'line-through']])
28662866
staticUtility('no-underline', [['text-decoration-line', 'none']])
28672867

2868+
staticUtility('font-stretch-normal', [['font-stretch', 'normal']])
2869+
staticUtility('font-stretch-ultra-condensed', [['font-stretch', 'ultra-condensed']])
2870+
staticUtility('font-stretch-extra-condensed', [['font-stretch', 'extra-condensed']])
2871+
staticUtility('font-stretch-condensed', [['font-stretch', 'condensed']])
2872+
staticUtility('font-stretch-semi-condensed', [['font-stretch', 'semi-condensed']])
2873+
staticUtility('font-stretch-semi-expanded', [['font-stretch', 'semi-expanded']])
2874+
staticUtility('font-stretch-expanded', [['font-stretch', 'expanded']])
2875+
staticUtility('font-stretch-extra-expanded', [['font-stretch', 'extra-expanded']])
2876+
staticUtility('font-stretch-ultra-expanded', [['font-stretch', 'ultra-expanded']])
2877+
functionalUtility('font-stretch', {
2878+
themeKeys: [],
2879+
handleBareValue: ({ value }) => {
2880+
let num = Number(value)
2881+
// Only 50-200% (inclusive) are valid:
2882+
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch#percentage
2883+
if (Number.isNaN(num) || num < 50 || num > 200) return null
2884+
return `${value}%`
2885+
},
2886+
handle: (value) => [decl('font-stretch', value)],
2887+
})
2888+
suggest('font-stretch', () => [
2889+
{
2890+
values: ['50', '75', '90', '95', '100', '105', '110', '125', '150', '200'],
2891+
},
2892+
])
2893+
28682894
colorUtility('placeholder', {
28692895
themeKeys: ['--background-color', '--color'],
28702896
handle: (value) => [

0 commit comments

Comments
 (0)