UNPKG

@primer/primitives

Version:

Typography, spacing, and color primitives for Primer design system

39 lines (38 loc) 1.38 kB
import { isBorder } from '../filters/isBorder.js'; /** * checks if all required properties exist on shadow token * @param object - BorderTokenValue * @returns void or throws error */ const checkForBorderTokenProperties = (border) => { if ('color' in border && 'width' in border && 'style' in border) { return true; } return false; }; /** * @description converts w3c border tokens in css border string * @type valueTransformer — [StyleDictionary.ValueTransform](https://github.com/amzn/style-dictionary/blob/main/types/Transform.d.ts) * @matcher matches all tokens of $type `border` * @transformer returns css border `string` */ export const borderToCss = { name: 'border/css', type: 'value', transitive: true, filter: isBorder, transform: (token) => { var _a; const value = (_a = token.$value) !== null && _a !== void 0 ? _a : token.value; // if value === string it was probably already transformed if (typeof value === 'string') { return value; } // if (!checkForBorderTokenProperties(value)) { throw new Error(`Invalid border token property ${JSON.stringify(value)}. Must be an object with color, width and style properties.`); } /* width | style | color */ return `${value.width} ${value.style} ${value.color}`; }, };