@patreon/studio
Version:
Patreon Studio Design System
28 lines • 1.23 kB
JavaScript
// This file contains helpers towards a strategy to remove use of theme.units from our codebases.
// Many unit values can be replaced with tokens, but for the values which cannot, we should wrap
// them in one of these helpers so that have better context for what otherwise look like magic numbers.
const typeScaleRootPx = 16;
const BASE_UNIT = 0.5; // rem
/**
* Converts a legacy unit value into a pixel value. This is a temporary helper to be used
* while we transition away from `theme.units.getValue()`
*
* @deprecated this is an escape hatch for legacy units. Please use tokens instead.
*/
export function convertLegacyUnitValue(unit) {
const res = unit * BASE_UNIT * typeScaleRootPx;
return `${res}px`;
}
/**
* Converts an array of legacy unit values into pixel values. This is a temporary helper to be used
* while we transition away from `theme.units.getValues()`
*
* @deprecated this is an escape hatch for legacy units. Please use tokens instead.
*/
export function convertLegacyUnitValues(values) {
if (typeof values === 'number') {
return convertLegacyUnitValue(values);
}
return values.map((value) => convertLegacyUnitValue(value));
}
//# sourceMappingURL=legacy-units.js.map