@atlaskit/tokens
Version:
Design tokens are the single source of truth to name and store design decisions.
15 lines • 582 B
JavaScript
import { deltaE } from './delta-e';
import { hexToRgb } from './hex-to-rgb';
export const getClosestColorIndex = (themeRamp, brandColor) => {
// Iterate over themeRamp and find whichever color is closest to brandColor
let closestColorIndex = 0;
let closestColorDistance = null;
themeRamp.forEach((value, index) => {
const distance = deltaE(hexToRgb(value), hexToRgb(brandColor));
if (closestColorDistance === null || distance < closestColorDistance) {
closestColorIndex = index;
closestColorDistance = distance;
}
});
return closestColorIndex;
};