Skip to content

feat: add style-dictionary tokens for download #820

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

Merged
merged 17 commits into from
Mar 31, 2025
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
2,159 changes: 1,739 additions & 420 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"preview": "vite preview"
},
"dependencies": {
"@bundled-es-modules/memfs": "^4.9.4",
"@craftjs/core": "^0.2.11",
"@db-ux/db-theme": "1.0.2",
"@db-ux/react-core-components": "1.0.0",
Expand Down Expand Up @@ -48,6 +49,7 @@
"react-dom": "^18.3.1",
"react-i18next": "15.4.0",
"react-router-dom": "7.1.5",
"style-dictionary": "^4.3.3",
"traverse": "^0.6.10",
"zustand": "^5.0.3"
},
Expand Down
41 changes: 24 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { Outlet } from "react-router-dom";
import Notifications from "./components/Notifications";
import { useThemeBuilderStore } from "./store";
import { useEffect } from "react";
import {
getNonColorCssProperties,
getPaletteOutput,
getSpeakingNames,
} from "./utils/outputs";
import { DefaultColorType } from "./utils/data.ts";
import {
getSDColorPalette,
getSDSpeakingColors,
} from "./utils/outputs/style-dictionary/colors.ts";
import { mergeObjectsRecursive } from "./utils";
import { runStyleDictionary } from "./utils/outputs/style-dictionary";
import { appConfig } from "./utils/outputs/style-dictionary/config";
import { getSDBaseIconProps } from "./utils/outputs/style-dictionary/typography.ts";

const App = () => {
const { speakingNames, luminanceSteps, theme } = useThemeBuilderStore(
Expand All @@ -21,20 +24,24 @@ const App = () => {
...theme.customColors,
};

const cssProps: any = {
...getPaletteOutput(allColors, luminanceSteps),
...getSpeakingNames(speakingNames, allColors),
...getNonColorCssProperties(theme),
const sdColorPalette = getSDColorPalette(allColors, luminanceSteps);
const sdSpeakingColors = getSDSpeakingColors(speakingNames, allColors);

const finalTheme = {
...getSDBaseIconProps(theme),
...theme,
...mergeObjectsRecursive(sdColorPalette, sdSpeakingColors),
};

const pages = document.getElementsByTagName("html");
Array.from(pages).forEach((page: Element) => {
page.setAttribute(
"style",
Object.entries(cssProps)
.map((value) => `${value[0]}:${value[1]};`)
.join(" "),
);
runStyleDictionary({
tokens: finalTheme,
...appConfig,
}).then((result) => {
const page = document.querySelector("html");
const overwrites = result["/overwrites"];
if (page && overwrites) {
page.setAttribute("style", overwrites);
}
});
}, [speakingNames, theme, luminanceSteps]);

Expand Down
32 changes: 4 additions & 28 deletions src/components/Customization/Settings/Scaling/data.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import DefaultTheme from "../../../../data/default-theme.json";
import traverse from "traverse";
import { defaultTheme } from "../../../../store/themes.ts";

export type ShirtSelectionType = {
label: string;
params: string[];
};

const theme = traverse(DefaultTheme);
const theme = traverse(defaultTheme);

export const getShirtValue = (
scaleString: string,
path: string[],
): string | number | undefined => {
if (path.at(-1) === "_scale") {
if (path.at(-2) === "_scale") {
return scaleString;
}

let scale = 1;
let scale: number;

if (scaleString === "none") {
scale = 0;
Expand All @@ -30,30 +30,6 @@ export const getShirtValue = (
return undefined;
}

if (path[0] === "elevation") {
if (path.at(-1) === "sm") {
return (
`0 0 ${scale}px -${scale}px rgba(0, 0, 0, 0.2),` +
`0 0 ${4 * scale}px ${scale}px rgba(0, 0, 0, 0.12),` +
`0 0 ${2 * scale}px 0 rgba(0, 0, 0, 0.14)`
);
}
if (path.at(-1) === "md") {
return (
`0 0 ${2 * scale}px -${scale}px rgba(0, 0, 0, 0.2),` +
`0 0 ${8 * scale}px ${scale}px rgba(0, 0, 0, 0.12),` +
`0 0 ${4 * scale}px 0 rgba(0, 0, 0, 0.14)`
);
}
if (path.at(-1) === "lg") {
return (
`0 0 ${4 * scale}px -${3 * scale}px rgba(0, 0, 0, 0.2),` +
`0 0 ${16 * scale}px ${3 * scale}px rgba(0, 0, 0, 0.12),` +
`0 0 ${8 * scale}px ${scale}px rgba(0, 0, 0, 0.14)`
);
}
}

if (path.length < 2) {
return undefined;
}
Expand Down
11 changes: 6 additions & 5 deletions src/components/Customization/Settings/Scaling/scaling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import traverse from "traverse";
const getFromJsonByArray = (params: string[], json: any): any => {
try {
let currentObject = json;
params.forEach((param) => {
for (const param of params) {
currentObject = currentObject[param];
});
}

return currentObject;
} catch (error) {
Expand All @@ -29,7 +29,8 @@ const Scaling = ({ label, params }: ShirtSelectionType) => {
if (
this.isLeaf &&
this.path.length > 0 &&
path.every((value, index) => value === this.path[index])
path.every((value, index) => value === this.path[index]) &&
this.path.at(-1) === "value"
) {
this.update(getShirtValue(scale, this.path) || value);
}
Expand All @@ -46,7 +47,7 @@ const Scaling = ({ label, params }: ShirtSelectionType) => {
<DBSelect
label={`${t(label)} ${t("scale")}`}
variant="floating"
value={getFromJsonByArray([...params, "_scale"], theme)}
value={getFromJsonByArray([...params, "_scale", "value"], theme)}
onChange={(event) => {
setDetfaultTheme(event.target.value);
}}
Expand Down Expand Up @@ -75,7 +76,7 @@ const Scaling = ({ label, params }: ShirtSelectionType) => {
<option>120%</option>
</>
)}
{(params.includes("elevation") || params.includes("radius")) && (
{params.includes("radius") && (
<>
<option>none</option>
<option>50%</option>
Expand Down
8 changes: 1 addition & 7 deletions src/components/Landing/ThemeSelect/theme-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ import {
ThemeType,
speakingNamesDefaultMapping,
} from "../../../utils/data.ts";
import DefaultTheme from "../../../data/default-theme.json";
import DBTheme from "../../../data/db-theme.json";
import SBahnTheme from "../../../data/sbahn-theme.json";
import { getThemeImage } from "../../../utils";

const defaultTheme = DefaultTheme as unknown as ThemeType;
const sBahnTheme = SBahnTheme as unknown as ThemeType;
const dbTheme = DBTheme as unknown as ThemeType;
import { dbTheme, defaultTheme, sBahnTheme } from "../../../store/themes.ts";

const themes: Record<string, ThemeType> = {
neutralTheme: defaultTheme,
Expand Down
Loading
Loading