Skip to content
This repository was archived by the owner on Feb 22, 2022. It is now read-only.

Commit 5bc33ba

Browse files
authored
Merge pull request #15 from mapgrid/feat/kerning-next
Add kerning utility
2 parents 1e333ea + 187524b commit 5bc33ba

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const _ = require('lodash');
44
const defaultOptions = {
55
ellipsis: true,
66
hyphens: true,
7+
kerning: true,
78
textUnset: true,
89
componentPrefix: 'c-',
910
};
@@ -62,6 +63,18 @@ module.exports = plugin.withOptions(function(options = {}) {
6263
},
6364
} : {};
6465

66+
const kerningUtilities = options.kerning ? {
67+
'.kerning': {
68+
fontKerning: 'normal',
69+
},
70+
'.kerning-none': {
71+
fontKerning: 'none',
72+
},
73+
'.kerning-auto': {
74+
fontKerning: 'auto',
75+
},
76+
} : {};
77+
6578
const textUnsetUtilities = options.textUnset ? {
6679
'.font-family-unset': {
6780
fontFamily: 'inherit',
@@ -164,6 +177,7 @@ module.exports = plugin.withOptions(function(options = {}) {
164177
addUtilities(textShadowUtilities, variants('textShadow'));
165178
addUtilities(ellipsisUtilities, variants('ellipsis'));
166179
addUtilities(hyphensUtilities, variants('hyphens'));
180+
addUtilities(kerningUtilities, variants('kerning'));
167181
addUtilities(textUnsetUtilities, variants('textUnset'));
168182
addUtilities(fontVariantCapsUtilities, variants('fontVariantCaps'));
169183
addUtilities(fontVariantNumericUtilities, variants('fontVariantNumeric'));
@@ -213,6 +227,7 @@ module.exports = plugin.withOptions(function(options = {}) {
213227
textShadow: ['responsive'],
214228
ellipsis: ['responsive'],
215229
hyphens: ['responsive'],
230+
kerning: ['responsive'],
216231
textUnset: ['responsive'],
217232
fontVariantCaps: ['responsive'],
218233
fontVariantNumeric: ['responsive'],

test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ test('the plugin generates some utilities and responsive variants by default', (
5050
.hyphens-auto {
5151
hyphens: auto;
5252
}
53+
.kerning {
54+
font-kerning: normal;
55+
}
56+
.kerning-none {
57+
font-kerning: none;
58+
}
59+
.kerning-auto {
60+
font-kerning: auto;
61+
}
5362
.font-family-unset {
5463
font-family: inherit;
5564
}
@@ -168,6 +177,15 @@ test('the plugin generates some utilities and responsive variants by default', (
168177
.sm\\:hyphens-auto {
169178
hyphens: auto;
170179
}
180+
.sm\\:kerning {
181+
font-kerning: normal;
182+
}
183+
.sm\\:kerning-none {
184+
font-kerning: none;
185+
}
186+
.sm\\:kerning-auto {
187+
font-kerning: auto;
188+
}
171189
.sm\\:font-family-unset {
172190
font-family: inherit;
173191
}
@@ -285,6 +303,7 @@ test('the font variant utilities can be disabled', () => {
285303
variants: {
286304
ellipsis: [],
287305
hyphens: [],
306+
kerning: [],
288307
textUnset: [],
289308
},
290309
}).then(css => {
@@ -304,6 +323,15 @@ test('the font variant utilities can be disabled', () => {
304323
.hyphens-auto {
305324
hyphens: auto;
306325
}
326+
.kerning {
327+
font-kerning: normal;
328+
}
329+
.kerning-none {
330+
font-kerning: none;
331+
}
332+
.kerning-auto {
333+
font-kerning: auto;
334+
}
307335
.font-family-unset {
308336
font-family: inherit;
309337
}
@@ -345,6 +373,7 @@ test('the ellipsis, hyphens, and text unset utilities can be disabled', () => {
345373
}, {
346374
ellipsis: false,
347375
hyphens: false,
376+
kerning: false,
348377
textUnset: false,
349378
}).then(css => {
350379
expect(css).toMatchCss(``);
@@ -373,6 +402,7 @@ test('the text indent and text shadow utilities can be customized', () => {
373402
}, {
374403
ellipsis: false,
375404
hyphens: false,
405+
kerning: false,
376406
textUnset: false,
377407
}).then(css => {
378408
expect(css).toMatchCss(`
@@ -415,6 +445,7 @@ test('the font variant utilities can be extended', () => {
415445
}, {
416446
ellipsis: false,
417447
hyphens: false,
448+
kerning: false,
418449
textUnset: false,
419450
}).then(css => {
420451
expect(css).toMatchCss(`
@@ -540,6 +571,7 @@ test('text style components can be generated', () => {
540571
}, {
541572
ellipsis: false,
542573
hyphens: false,
574+
kerning: false,
543575
textUnset: false,
544576
}).then(css => {
545577
expect(css).toMatchCss(`
@@ -580,6 +612,7 @@ test('the component prefix can be customized', () => {
580612
}, {
581613
ellipsis: false,
582614
hyphens: false,
615+
kerning: false,
583616
textUnset: false,
584617
componentPrefix: '',
585618
}).then(css => {
@@ -634,6 +667,7 @@ test('text styles can extend other text styles', () => {
634667
}, {
635668
ellipsis: false,
636669
hyphens: false,
670+
kerning: false,
637671
textUnset: false,
638672
}).then(css => {
639673
expect(css).toMatchCss(`
@@ -712,6 +746,7 @@ test('text styles can extend more than one other text style', () => {
712746
}, {
713747
ellipsis: false,
714748
hyphens: false,
749+
kerning: false,
715750
textUnset: false,
716751
}).then(css => {
717752
expect(css).toMatchCss(`
@@ -807,6 +842,7 @@ test('text style components can style their children', () => {
807842
}, {
808843
ellipsis: false,
809844
hyphens: false,
845+
kerning: false,
810846
textUnset: false,
811847
}).then(css => {
812848
expect(css).toMatchCss(`
@@ -905,6 +941,7 @@ test('text styles can be responsive', () => {
905941
}, {
906942
ellipsis: false,
907943
hyphens: false,
944+
kerning: false,
908945
textUnset: false,
909946
}).then(css => {
910947
expect(css).toMatchCss(`
@@ -983,6 +1020,7 @@ test('text styles can be set to not be output', () => {
9831020
}, {
9841021
ellipsis: false,
9851022
hyphens: false,
1023+
kerning: false,
9861024
textUnset: false,
9871025
}).then(css => {
9881026
expect(css).toMatchCss(`
@@ -1098,6 +1136,7 @@ test('all these options can be used to generate a full-featured rich text compon
10981136
}, {
10991137
ellipsis: false,
11001138
hyphens: false,
1139+
kerning: false,
11011140
textUnset: false,
11021141
}).then(css => {
11031142
expect(css).toMatchCss(`
@@ -1175,6 +1214,7 @@ test('variants can be customized', () => {
11751214
variants: {
11761215
ellipsis: ['hover'],
11771216
hyphens: ['active'],
1217+
kerning: ['focus'],
11781218
textUnset: [],
11791219
fontVariantCaps: ['focus', 'responsive'],
11801220
fontVariantNumeric: ['group-hover'],
@@ -1212,6 +1252,24 @@ test('variants can be customized', () => {
12121252
.active\\:hyphens-auto:active {
12131253
hyphens: auto;
12141254
}
1255+
.kerning {
1256+
font-kerning: normal;
1257+
}
1258+
.kerning-none {
1259+
font-kerning: none;
1260+
}
1261+
.kerning-auto {
1262+
font-kerning: auto;
1263+
}
1264+
.focus\\:kerning:focus {
1265+
font-kerning: normal;
1266+
}
1267+
.focus\\:kerning-none:focus {
1268+
font-kerning: none;
1269+
}
1270+
.focus\\:kerning-auto:focus {
1271+
font-kerning: auto;
1272+
}
12151273
.font-family-unset {
12161274
font-family: inherit;
12171275
}

0 commit comments

Comments
 (0)