Skip to content

Commit

Permalink
handle light & dark Mode && Storybook themes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBusshoff committed Nov 20, 2024
1 parent bad08bd commit 9c34c24
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 515 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/import-figma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,23 @@ jobs:
working-directory: packages/figma-utils

# we need to separately import the themes because they are all needed in different formats and selectors
- name: 🎨 Import onyx variables
- name: 🎨 Import onyx light variables
run: |
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m Value onyx-light onyx-dark -f CSS -s ":where(:root), .onyx-theme-default"
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m Value onyx-light -f CSS -s ":where(:root), .onyx-theme-default"
working-directory: packages/figma-utils
- name: 🎨 Import onyx dark variables
run: |
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m Value onyx-dark -f CSS -s ":where(.dark), .onyx-theme-default-dark"
working-directory: packages/figma-utils

- name: 🎨 Import additional onyx light-themes
run: |
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m lidl-light kaufland-light digits-light -f CSS -s ":where(:root), .onyx-theme-{mode}"
working-directory: packages/figma-utils

- name: 🎨 Import additional onyx themes
- name: 🎨 Import additional onyx dark-themes
run: |
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m lidl-light lidl-dark kaufland-light kaufland-dark digits-light digits-dark -f CSS -s ":where(:root), .onyx-theme-{mode}"
pnpm run @sit-onyx/figma-utils import-variables -k "${{ vars.FIGMA_FILE_KEY }}" -t "${{ secrets.FIGMA_TOKEN }}" -d "../sit-onyx/src/styles/variables/themes" -m lidl-dark kaufland-dark digits-dark -f CSS -s ":where(.dark), .onyx-theme-{mode}"
working-directory: packages/figma-utils

- name: 🛠️ Import spacing variables
Expand Down
14 changes: 10 additions & 4 deletions packages/sit-onyx/.storybook/theme-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ import type { StorybookGlobalType } from "@sit-onyx/storybook-utils";
import type { Decorator } from "@storybook/vue3";
import { ref, watch, watchEffect } from "vue";

const themes = import.meta.glob("../src/styles/variables/themes/*.css");
const allThemes = import.meta.glob("../src/styles/variables/themes/*.css");
/**
* Removes alles dark-themes from the listing
*/
const themes = Object.fromEntries(
Object.entries(allThemes).filter(([key]) => !key.includes("dark") && !key.includes("Value")),
);

/**
* Map of all available onyx themes. Default theme will be sorted first.
* key = theme name, value = async function to dynamically import the CSS variables
*/
export const ONYX_THEMES = Object.entries(themes)
.sort(([a], [b]) => {
if (a.endsWith("onyx.css")) return -1;
if (b.endsWith("onyx.css")) return 1;
if (a.endsWith("onyx-light.css")) return -1;
if (b.endsWith("onyx-light.css")) return 1;
return a.localeCompare(b);
})
.reduce<typeof themes>((obj, [filePath, importFn]) => {
const themeName = filePath.split("/").at(-1)!.replace(".css", "");
const themeName = filePath.split("/").at(-1)!.replace("-light.css", "");
obj[themeName] = importFn;
return obj;
}, {});
Expand Down
2 changes: 1 addition & 1 deletion packages/sit-onyx/src/components/OnyxTag/OnyxTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OnyxIcon from "../OnyxIcon/OnyxIcon.vue";
import type { OnyxTagProps } from "./types";
const props = withDefaults(defineProps<OnyxTagProps>(), {
color: "default",
color: "primary",
});
const { densityClass } = useDensity(props);
Expand Down
2 changes: 1 addition & 1 deletion packages/sit-onyx/src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

@use "variables/themes/Value.css";

@use "variables/themes/onyx-dark.css";
@use "variables/themes/onyx-light.css";
@use "variables/themes/onyx-dark.css";

@use "variables/density-compact.css";
@use "variables/density-default.css";
Expand Down
126 changes: 0 additions & 126 deletions packages/sit-onyx/src/styles/variables/themes/kaufland.css

This file was deleted.

126 changes: 0 additions & 126 deletions packages/sit-onyx/src/styles/variables/themes/lidl.css

This file was deleted.

Loading

0 comments on commit 9c34c24

Please sign in to comment.