Skip to content

Commit 7b06509

Browse files
committed
Add support for configuring default font-feature-settings for a font-family
1 parent 99b53b4 commit 7b06509

File tree

2 files changed

+124
-3
lines changed

2 files changed

+124
-3
lines changed

src/corePlugins.js

+26-3
Original file line numberDiff line numberDiff line change
@@ -1604,9 +1604,32 @@ export let corePlugins = {
16041604
matchUtilities({ align: (value) => ({ 'vertical-align': value }) })
16051605
},
16061606

1607-
fontFamily: createUtilityPlugin('fontFamily', [['font', ['fontFamily']]], {
1608-
type: ['lookup', 'generic-name', 'family-name'],
1609-
}),
1607+
// fontFamily: createUtilityPlugin('fontFamily', [['font', ['fontFamily']]], {
1608+
// type: ['lookup', 'generic-name', 'family-name'],
1609+
// }),
1610+
1611+
fontFamily: ({ matchUtilities, theme }) => {
1612+
matchUtilities(
1613+
{
1614+
font: (value) => {
1615+
let [families, options = {}] =
1616+
Array.isArray(value) && isPlainObject(value[1]) ? value : [value]
1617+
let { fontFeatureSettings } = options
1618+
1619+
return {
1620+
'font-family': Array.isArray(families) ? families.join(', ') : families,
1621+
...(fontFeatureSettings === undefined
1622+
? {}
1623+
: { 'font-feature-settings': fontFeatureSettings }),
1624+
}
1625+
},
1626+
},
1627+
{
1628+
values: theme('fontFamily'),
1629+
type: ['lookup', 'generic-name', 'family-name'],
1630+
}
1631+
)
1632+
},
16101633

16111634
fontSize: ({ matchUtilities, theme }) => {
16121635
matchUtilities(

tests/plugins/fontFamily.test.js

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { run, html, css } from '../util/run'
2+
3+
test('font-family utilities can be defined as a string', () => {
4+
let config = {
5+
content: [{ raw: html`<div class="font-sans"></div>` }],
6+
theme: {
7+
fontFamily: {
8+
sans: 'Helvetica, Arial, sans-serif',
9+
},
10+
},
11+
}
12+
13+
return run('@tailwind utilities', config).then((result) => {
14+
expect(result.css).toMatchCss(css`
15+
.font-sans {
16+
font-family: Helvetica, Arial, sans-serif;
17+
}
18+
`)
19+
})
20+
})
21+
22+
test('font-family utilities can be defined as an array', () => {
23+
let config = {
24+
content: [{ raw: html`<div class="font-sans"></div>` }],
25+
theme: {
26+
fontFamily: {
27+
sans: ['Helvetica', 'Arial', 'sans-serif'],
28+
},
29+
},
30+
}
31+
32+
return run('@tailwind utilities', config).then((result) => {
33+
expect(result.css).toMatchCss(css`
34+
.font-sans {
35+
font-family: Helvetica, Arial, sans-serif;
36+
}
37+
`)
38+
})
39+
})
40+
41+
test('font-family values are not automatically escaped', () => {
42+
let config = {
43+
content: [{ raw: html`<div class="font-sans"></div>` }],
44+
theme: {
45+
fontFamily: {
46+
sans: ["'Exo 2'", 'sans-serif'],
47+
},
48+
},
49+
}
50+
51+
return run('@tailwind utilities', config).then((result) => {
52+
expect(result.css).toMatchCss(css`
53+
.font-sans {
54+
font-family: 'Exo 2', sans-serif;
55+
}
56+
`)
57+
})
58+
})
59+
60+
test('font-feature-settings can be provided when families are defined as a string', () => {
61+
let config = {
62+
content: [{ raw: html`<div class="font-sans"></div>` }],
63+
theme: {
64+
fontFamily: {
65+
sans: ['Helvetica, Arial, sans-serif', { fontFeatureSettings: '"cv11", "ss01"' }],
66+
},
67+
},
68+
}
69+
70+
return run('@tailwind utilities', config).then((result) => {
71+
expect(result.css).toMatchCss(`
72+
.font-sans {
73+
font-family: Helvetica, Arial, sans-serif;
74+
font-feature-settings: "cv11", "ss01";
75+
}
76+
`)
77+
})
78+
})
79+
80+
test('font-feature-settings can be provided when families are defined as an array', () => {
81+
let config = {
82+
content: [{ raw: html`<div class="font-sans"></div>` }],
83+
theme: {
84+
fontFamily: {
85+
sans: [['Helvetica', 'Arial', 'sans-serif'], { fontFeatureSettings: '"cv11", "ss01"' }],
86+
},
87+
},
88+
}
89+
90+
return run('@tailwind utilities', config).then((result) => {
91+
expect(result.css).toMatchCss(`
92+
.font-sans {
93+
font-family: Helvetica, Arial, sans-serif;
94+
font-feature-settings: "cv11", "ss01";
95+
}
96+
`)
97+
})
98+
})

0 commit comments

Comments
 (0)