Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add component tokens #1615

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/calm-readers-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@localyze-pluto/design-tokens": minor
"@localyze-pluto/theme": minor
---

Add component specific tokens
55 changes: 55 additions & 0 deletions packages/design-tokens/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,61 @@ const colorPrefixes = [
"bg",
"content",
"border",

"checkbox",
"tooltip",
"title",
"toast",
"text-area",
"table-header",
"table-cell",
"table",
"tab",
"status-dot",
"step-progress",
"step-progress-item",
"switch",
"step-header",
"step-indicator",
"step-card",
"select",
"sidebar-link-icon",
"sidebar",
"sidebar-link",
"radio-button",
"search",
"radio",
"progess",
"paragraph",
"pagination-item",
"modal",
"logo",
"link",
"help-text",
"icon-wrapper",
"hero-section",
"emoji-wrapper",
"form-field",
"field-text",
"field-suffix",
"field-prefix",
"field-label",
"dropzone",
"document-upload",
"document-list-item",
"document-list-header",
"document-list",
"divider",
"day-label",
"callout",
"day",
"date-picker",
"card",
"button",
"bullet",
"badge",
"avatar",
"alert-dialog",
];

module.exports = {
Expand Down
30 changes: 27 additions & 3 deletions packages/design-tokens/docs/components/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from "react";
import keys from "lodash/keys";
import filter from "lodash/filter";
import reduce from "lodash/reduce";
import get from "lodash/get";
import replace from "lodash/replace";
import startsWith from "lodash/startsWith";
import fontSizeTokens from "../../src/tokens/font-size.tokens.json";
import fontWeightTokens from "../../src/tokens/font-weight.tokens.json";
import colorTokens from "../../src/tokens/color.tokens.json";
Expand All @@ -24,6 +27,7 @@ import {
import { Box } from "../../../components/src/primitives/Box";
import { Text } from "../../../components/src/primitives/Text";
import { TokenColumn } from "../types/TokenColumn";
import { Token } from "../types/Token";
import { createPreview } from "./createPreview";

const TEXT_PREVIEW = (
Expand All @@ -34,6 +38,10 @@ type TokenColumnsProps = {
[key: string]: Array<TokenColumn>;
};

const getTokenFromVariable = (tokens: unknown, token: Token): string => {
return get(tokens, replace(token.value, /[{}]/g, "")).value as string;
};

const COLORS = reduce(
filter(keys(colorTokens), (item) => item !== "default"),
(acc, prefix) => {
Expand All @@ -42,14 +50,30 @@ const COLORS = reduce(
name: "Name",
transform: getTokenNameFromTuple(prefix),
},
{ name: "Hex", transform: getTokenValue },
{
name: "Raw",
transform: ([, token]: TokenTuple) => token.value,
},
{
name: "Hex",
transform: ([, token]: TokenTuple) =>
startsWith(token.value, "{")
? getTokenFromVariable(colorTokens, token)
: token.value,
},
{
name: "RGB",
transform: ([, token]: TokenTuple): string => hexToRgb(token.value),
transform: ([, token]: TokenTuple): string =>
startsWith(token.value, "{")
? hexToRgb(getTokenFromVariable(colorTokens, token))
: hexToRgb(token.value),
},
{
name: "Hsla",
transform: ([, token]: TokenTuple): string => hexToHsla(token.value),
transform: ([, token]: TokenTuple): string =>
startsWith(token.value, "{")
? hexToHsla(getTokenFromVariable(colorTokens, token))
: hexToHsla(token.value),
},
{
name: "Preview",
Expand Down
Loading
Loading