Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support font-weight in font-size utilities #8763

Merged
merged 4 commits into from Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix usage of special-character prefixes ([#8772](https://github.com/tailwindlabs/tailwindcss/pull/8772))
- Don’t prefix selectors in arbitrary variants ([#8773](https://github.com/tailwindlabs/tailwindcss/pull/8773))
- Add support for alpha values in safe list ([#8774](https://github.com/tailwindlabs/tailwindcss/pull/8774))
- Support default `font-weight`s in font size utilities ([#8763](https://github.com/tailwindlabs/tailwindcss/pull/8763))

## [3.1.4] - 2022-06-21

Expand Down
3 changes: 2 additions & 1 deletion src/corePlugins.js
Expand Up @@ -1613,14 +1613,15 @@ export let corePlugins = {
{
text: (value) => {
let [fontSize, options] = Array.isArray(value) ? value : [value]
let { lineHeight, letterSpacing } = isPlainObject(options)
let { lineHeight, letterSpacing, fontWeight } = isPlainObject(options)
? options
: { lineHeight: options }

return {
'font-size': fontSize,
...(lineHeight === undefined ? {} : { 'line-height': lineHeight }),
...(letterSpacing === undefined ? {} : { 'letter-spacing': letterSpacing }),
...(fontWeight === undefined ? {} : { 'font-weight': fontWeight }),
}
},
},
Expand Down
31 changes: 31 additions & 0 deletions tests/plugins/fontSize.test.js
Expand Up @@ -88,3 +88,34 @@ test('font-size utilities can include a default line-height and letter-spacing',
`)
})
})

test('font-size utilities can include a font-weight', () => {
let config = {
content: [{ raw: html`<div class="text-md text-sm text-lg"></div>` }],
theme: {
fontSize: {
sm: '12px',
md: ['16px', { lineHeight: '24px', fontWeight: 500 }],
lg: ['20px', { lineHeight: '28px', fontWeight: 'bold' }],
},
},
}

return run('@tailwind utilities', config).then((result) => {
expect(result.css).toMatchCss(css`
.text-md {
font-size: 16px;
line-height: 24px;
font-weight: 500;
}
.text-sm {
font-size: 12px;
}
.text-lg {
font-size: 20px;
line-height: 28px;
font-weight: bold;
}
`)
})
})
1 change: 1 addition & 0 deletions types/config.d.ts
Expand Up @@ -164,6 +164,7 @@ interface ThemeConfig {
configuration: Partial<{
lineHeight: string
letterSpacing: string
fontWeight: string | number
}>
]
>
Expand Down