Add support for configuring default font-feature-settings for a font-family (#9039)
* Add support for configuring default font-feature-settings for a font-family * Update changelog Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
This commit is contained in:
parent
fbbe3c011e
commit
c7f627dd68
3 changed files with 124 additions and 3 deletions
|
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Add support fo configuring default `font-feature-settings` for a font family ([#9039](https://github.com/tailwindlabs/tailwindcss/pull/9039))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Use absolute paths when resolving changed files for resilience against working directory changes ([#9032](https://github.com/tailwindlabs/tailwindcss/pull/9032))
|
||||
|
|
|
|||
|
|
@ -1604,9 +1604,28 @@ export let corePlugins = {
|
|||
matchUtilities({ align: (value) => ({ 'vertical-align': value }) })
|
||||
},
|
||||
|
||||
fontFamily: createUtilityPlugin('fontFamily', [['font', ['fontFamily']]], {
|
||||
type: ['lookup', 'generic-name', 'family-name'],
|
||||
}),
|
||||
fontFamily: ({ matchUtilities, theme }) => {
|
||||
matchUtilities(
|
||||
{
|
||||
font: (value) => {
|
||||
let [families, options = {}] =
|
||||
Array.isArray(value) && isPlainObject(value[1]) ? value : [value]
|
||||
let { fontFeatureSettings } = options
|
||||
|
||||
return {
|
||||
'font-family': Array.isArray(families) ? families.join(', ') : families,
|
||||
...(fontFeatureSettings === undefined
|
||||
? {}
|
||||
: { 'font-feature-settings': fontFeatureSettings }),
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
values: theme('fontFamily'),
|
||||
type: ['lookup', 'generic-name', 'family-name'],
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
fontSize: ({ matchUtilities, theme }) => {
|
||||
matchUtilities(
|
||||
|
|
|
|||
98
tests/plugins/fontFamily.test.js
Normal file
98
tests/plugins/fontFamily.test.js
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import { run, html, css } from '../util/run'
|
||||
|
||||
test('font-family utilities can be defined as a string', () => {
|
||||
let config = {
|
||||
content: [{ raw: html`<div class="font-sans"></div>` }],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: 'Helvetica, Arial, sans-serif',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return run('@tailwind utilities', config).then((result) => {
|
||||
expect(result.css).toMatchCss(css`
|
||||
.font-sans {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
test('font-family utilities can be defined as an array', () => {
|
||||
let config = {
|
||||
content: [{ raw: html`<div class="font-sans"></div>` }],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: ['Helvetica', 'Arial', 'sans-serif'],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return run('@tailwind utilities', config).then((result) => {
|
||||
expect(result.css).toMatchCss(css`
|
||||
.font-sans {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
test('font-family values are not automatically escaped', () => {
|
||||
let config = {
|
||||
content: [{ raw: html`<div class="font-sans"></div>` }],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: ["'Exo 2'", 'sans-serif'],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return run('@tailwind utilities', config).then((result) => {
|
||||
expect(result.css).toMatchCss(css`
|
||||
.font-sans {
|
||||
font-family: 'Exo 2', sans-serif;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
test('font-feature-settings can be provided when families are defined as a string', () => {
|
||||
let config = {
|
||||
content: [{ raw: html`<div class="font-sans"></div>` }],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: ['Helvetica, Arial, sans-serif', { fontFeatureSettings: '"cv11", "ss01"' }],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return run('@tailwind utilities', config).then((result) => {
|
||||
expect(result.css).toMatchCss(`
|
||||
.font-sans {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-feature-settings: "cv11", "ss01";
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
test('font-feature-settings can be provided when families are defined as an array', () => {
|
||||
let config = {
|
||||
content: [{ raw: html`<div class="font-sans"></div>` }],
|
||||
theme: {
|
||||
fontFamily: {
|
||||
sans: [['Helvetica', 'Arial', 'sans-serif'], { fontFeatureSettings: '"cv11", "ss01"' }],
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
return run('@tailwind utilities', config).then((result) => {
|
||||
expect(result.css).toMatchCss(`
|
||||
.font-sans {
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-feature-settings: "cv11", "ss01";
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue