@primer/primitives
Version:
Typography, spacing, and color primitives for Primer design system
33 lines (32 loc) • 900 B
JavaScript
import { z } from 'zod';
import { joinFriendly, schemaErrorMessage } from '../utilities/index.js';
const validTypes = [
'color',
'cubicBezier',
'typography',
'dimension',
'duration',
'border',
'shadow',
'fontFamily',
'fontWeight',
'gradient',
'number',
'string',
'custom-viewportRange',
];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: TODO: fix this
export const validateType = z.record(z.string(), z.lazy(() => {
return z.union([
z
.object({
$value: z.any(),
$type: z.string().refine(type => validTypes.includes(type), val => ({
message: schemaErrorMessage(`Invalid token $type: "${val}"`, `Must be one of the following: ${joinFriendly([...validTypes], 'or')}`),
})),
})
.required(),
validateType,
]);
}));