style-dictionary-utils
Version:
Utilities to use in your style dictionary config
22 lines (21 loc) • 1.07 kB
JavaScript
import { isShadowFilter } from '../filter/isShadow.js';
import { getValue } from '../utilities/getValue.js';
import { dimensionValueTransformer } from './dimension-css.js';
import { colorValueTransformer } from './color-css.js';
const formatShadow = ({ offsetX, offsetY, blur, spread, color, inset = false }, platform) => `${inset ? 'inset' : ''} ${dimensionValueTransformer(offsetX, platform)} ${dimensionValueTransformer(offsetY, platform)} ${dimensionValueTransformer(blur, platform)} ${dimensionValueTransformer(spread, platform)} ${colorValueTransformer(color, platform)}`.trim();
export const shadowCss = {
name: 'shadow/css',
type: `value`,
transitive: true,
filter: isShadowFilter,
transform: (token, platform) => {
const tokenValue = getValue(token);
if (Array.isArray(tokenValue)) {
return tokenValue.map(shadow => formatShadow(shadow, platform)).join(', ');
}
if (typeof tokenValue === 'object') {
return formatShadow(tokenValue, platform);
}
return tokenValue;
},
};