Skip to content

Commit a7c4106

Browse files
committed
Add test coverage for default letter-spacing feature
1 parent 2c05a4a commit a7c4106

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

__tests__/plugins/fontSize.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,59 @@ test('font-size utilities can include a default line-height', () => {
2828
],
2929
])
3030
})
31+
32+
test('font-size utilities can include a default letter-spacing', () => {
33+
const config = {
34+
theme: {
35+
fontSize: {
36+
sm: '12px',
37+
md: ['16px', { letterSpacing: '-0.01em' }],
38+
lg: ['20px', { letterSpacing: '-0.02em' }],
39+
},
40+
},
41+
variants: {
42+
fontSize: ['responsive'],
43+
},
44+
}
45+
46+
const { utilities } = invokePlugin(plugin(), config)
47+
48+
expect(utilities).toEqual([
49+
[
50+
{
51+
'.text-sm': { 'font-size': '12px' },
52+
'.text-md': { 'font-size': '16px', 'letter-spacing': '-0.01em' },
53+
'.text-lg': { 'font-size': '20px', 'letter-spacing': '-0.02em' },
54+
},
55+
['responsive'],
56+
],
57+
])
58+
})
59+
60+
test('font-size utilities can include a default line-height and letter-spacing', () => {
61+
const config = {
62+
theme: {
63+
fontSize: {
64+
sm: '12px',
65+
md: ['16px', { lineHeight: '24px', letterSpacing: '-0.01em' }],
66+
lg: ['20px', { lineHeight: '28px', letterSpacing: '-0.02em' }],
67+
},
68+
},
69+
variants: {
70+
fontSize: ['responsive'],
71+
},
72+
}
73+
74+
const { utilities } = invokePlugin(plugin(), config)
75+
76+
expect(utilities).toEqual([
77+
[
78+
{
79+
'.text-sm': { 'font-size': '12px' },
80+
'.text-md': { 'font-size': '16px', 'line-height': '24px', 'letter-spacing': '-0.01em' },
81+
'.text-lg': { 'font-size': '20px', 'line-height': '28px', 'letter-spacing': '-0.02em' },
82+
},
83+
['responsive'],
84+
],
85+
])
86+
})

src/plugins/fontSize.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ export default function() {
55
const utilities = _.fromPairs(
66
_.map(theme('fontSize'), (value, modifier) => {
77
const [fontSize, options] = Array.isArray(value) ? value : [value]
8-
// Tailwind 1.3+ syntax allowed line height to be specified in the array like
9-
// ['16px', '24px'], so we can get it from there as well as from object syntax
10-
const lineHeight = options instanceof Object ? options.lineHeight : options
11-
const letterSpacing = options && options.letterSpacing
8+
const { lineHeight, letterSpacing } = _.isPlainObject(options)
9+
? options
10+
: {
11+
lineHeight: options,
12+
}
1213

1314
return [
1415
`.${e(`text-${modifier}`)}`,

0 commit comments

Comments
 (0)