Skip to content

Commit 1091192

Browse files
authored
feat: add validation for letter spacing that allows negative values (#138)
1 parent b545df9 commit 1091192

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

package-lock.json

Lines changed: 0 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/build/tasks/__tests__/theme-json-schema.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,44 @@ describe('validateJson', () => {
268268
});
269269
});
270270
});
271+
272+
describe('letter spacing', () => {
273+
test('accepts positive, negative, and zero values with valid units', () => {
274+
['1px', '-0.5rem', '0em', '0.25px', '-1.5em', '.5px', '-.5rem'].forEach((validValue) => {
275+
expect(
276+
validateTokens({
277+
'letter-spacing-button': {
278+
$value: validValue,
279+
},
280+
}),
281+
).toBe(true);
282+
});
283+
});
284+
285+
test('accepts keyword values', () => {
286+
['normal', 'inherit', 'initial', 'revert', 'revert-layer', 'unset'].forEach((validValue) => {
287+
expect(
288+
validateTokens({
289+
'letter-spacing-button': {
290+
$value: validValue,
291+
},
292+
}),
293+
).toBe(true);
294+
});
295+
});
296+
297+
test('rejects invalid formats', () => {
298+
['100', '-1', '1.5', '100 px', '20ps', '.px', '-.rem'].forEach((invalidValue) => {
299+
expect(() =>
300+
validateTokens({
301+
'letter-spacing-button': {
302+
$value: invalidValue,
303+
},
304+
}),
305+
).toThrowError(
306+
'Tokens validation error: instance.tokens.letter-spacing-button.$value does not match pattern "normal|inherit|initial|revert|revert-layer|unset|-?\\\\d*\\\\.?\\\\d+(px|rem|em)"',
307+
);
308+
});
309+
});
310+
});
271311
});

src/build/tasks/theme-json-schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const textWeightValueSchema: GenericSchema = {
3838
type: 'string',
3939
pattern: '300|400|700|900|normal|bold|light|heavy',
4040
};
41+
const letterSpacingValueSchema: GenericSchema = {
42+
type: 'string',
43+
pattern: 'normal|inherit|initial|revert|revert-layer|unset|-?\\d*\\.?\\d+(px|rem|em)',
44+
};
4145
const durationValueSchema: GenericSchema = { type: 'string', pattern: '\\d+m?s' };
4246

4347
const visualModes = ['light', 'dark'];
@@ -79,7 +83,7 @@ const tokensSchema: GenericSchema = {
7983
'^font-size-': getTokenSchema(textSizeValueSchema),
8084
'^line-height-': getTokenSchema(textSizeValueSchema),
8185
'^font-weight-': getTokenSchema(textWeightValueSchema),
82-
'^letter-spacing-': getTokenSchema(textSizeValueSchema),
86+
'^letter-spacing-': getTokenSchema(letterSpacingValueSchema),
8387
},
8488
additionalProperties: false,
8589
};

0 commit comments

Comments
 (0)