@atlaskit/eslint-plugin-design-system
Version:
The essential plugin for use with the Atlassian Design System.
15 lines • 868 B
JavaScript
import spacingScale from '@atlaskit/tokens/atlassian-spacing';
import { borderWidthValueToToken } from './border-width-value-to-token';
import { isBorderSizeProperty } from './is-border-size-property';
import { isShapeProperty } from './is-shape-property';
import { normaliseValue } from './normalise-value';
import { radiusValueToToken } from './radius-value-to-token';
const spacingValueToToken = Object.fromEntries(spacingScale.map(token => [token.value, token.cleanName]));
export function findTokenNameByPropertyValue(propertyName, value) {
const lookupValue = normaliseValue(propertyName, value);
const tokenName = isShapeProperty(propertyName) ? isBorderSizeProperty(propertyName) ? borderWidthValueToToken[lookupValue] : radiusValueToToken[lookupValue] : spacingValueToToken[lookupValue];
if (!tokenName) {
return undefined;
}
return tokenName;
}