Files
cunningham/packages/tokens/src/lib/index.ts
Nathan Panchout 146a8a20b3 ♻️(tokens) refactor tokens architectures
This commit introduces a significant refactor of the color and
typography tokens in the Cunningham package. The previous structure has
been replaced with a more comprehensive and organized format, including
new color definitions for branding, contextual backgrounds, and content.
Additionally, the font sizes, weights, and families have been updated to
align with the new design system. This change enhances the overall
maintainability and scalability of the token system.
2025-09-23 15:58:43 +02:00

45 lines
1.1 KiB
TypeScript

import { tokens } from "./cunningham-tokens";
export type Configuration = typeof tokens;
export type DefaultTokens = (typeof tokens)["themes"]["default"];
export type DarkTokens = (typeof tokens)["themes"]["dark"];
export const defaultTokens = tokens.themes.default;
export const darkTokens = tokens.themes.dark;
export const defaultThemes = tokens.themes;
/**
* Transform such object:
* {
* theme: {
* colors: {
* "primary-500": "blue"
* }
* }
* }
*
* to:
* {
* theme: {
* colors: {
* "primary-500": "ref(theme.colors.primary-500)"
* }
* }
* }
* @param tokens_
*/
export const buildRefs = <T extends Object>(tokens_: T): T => {
const buildRefsAux = (upperKey: string, subTokens: any) => {
if (typeof subTokens === "object") {
const obj: any = {};
Object.entries(subTokens).forEach(([key, value]) => {
obj[key] = buildRefsAux((upperKey ? upperKey + "." : "") + key, value);
});
return obj;
}
return "ref(" + upperKey + ")";
};
return buildRefsAux("", tokens_);
};
export const defaultTokenRefs = buildRefs(defaultTokens);