Skip to content

Commit

Permalink
Include percent sign in font-stretch utilities (#13158)
Browse files Browse the repository at this point in the history
Include a percent sign in `font-stretch` utilities (e.g. `font-stretch-50%` rather than `font-stretch-50`) to make the meaning of the value clearer.
  • Loading branch information
KrisBraun authored Mar 8, 2024
1 parent c550a62 commit 5d1e48d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
20 changes: 10 additions & 10 deletions packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -714,16 +714,16 @@ exports[`getClassList 1`] = `
"font-medium",
"font-normal",
"font-semibold",
"font-stretch-100",
"font-stretch-105",
"font-stretch-110",
"font-stretch-125",
"font-stretch-150",
"font-stretch-200",
"font-stretch-50",
"font-stretch-75",
"font-stretch-90",
"font-stretch-95",
"font-stretch-100%",
"font-stretch-105%",
"font-stretch-110%",
"font-stretch-125%",
"font-stretch-150%",
"font-stretch-200%",
"font-stretch-50%",
"font-stretch-75%",
"font-stretch-90%",
"font-stretch-95%",
"font-stretch-condensed",
"font-stretch-expanded",
"font-stretch-extra-condensed",
Expand Down
14 changes: 10 additions & 4 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8789,13 +8789,13 @@ test('font-style', () => {
})

test('font-stretch', () => {
expect(run(['font-stretch-ultra-expanded', 'font-stretch-50', 'font-stretch-200']))
expect(run(['font-stretch-ultra-expanded', 'font-stretch-50%', 'font-stretch-200%']))
.toMatchInlineSnapshot(`
".font-stretch-200 {
".font-stretch-200\\% {
font-stretch: 200%;
}
.font-stretch-50 {
.font-stretch-50\\% {
font-stretch: 50%;
}
Expand All @@ -8804,7 +8804,13 @@ test('font-stretch', () => {
}"
`)
expect(
run(['font-stretch', 'font-stretch-20', 'font-stretch-400', 'font-stretch-potato']),
run([
'font-stretch',
'font-stretch-20%',
'font-stretch-50',
'font-stretch-400%',
'font-stretch-potato',
]),
).toEqual('')
})

Expand Down
7 changes: 4 additions & 3 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2877,17 +2877,18 @@ export function createUtilities(theme: Theme) {
functionalUtility('font-stretch', {
themeKeys: [],
handleBareValue: ({ value }) => {
let num = Number(value)
if (!value.endsWith('%')) return null
let num = Number(value.slice(0, -1))
// Only 50-200% (inclusive) are valid:
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch#percentage
if (Number.isNaN(num) || num < 50 || num > 200) return null
return `${value}%`
return value
},
handle: (value) => [decl('font-stretch', value)],
})
suggest('font-stretch', () => [
{
values: ['50', '75', '90', '95', '100', '105', '110', '125', '150', '200'],
values: ['50%', '75%', '90%', '95%', '100%', '105%', '110%', '125%', '150%', '200%'],
},
])

Expand Down

0 comments on commit 5d1e48d

Please sign in to comment.