summaryrefslogtreecommitdiff
path: root/frontend/src/lib/components/ui/chart/chart-style.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/lib/components/ui/chart/chart-style.svelte')
-rw-r--r--frontend/src/lib/components/ui/chart/chart-style.svelte37
1 files changed, 37 insertions, 0 deletions
diff --git a/frontend/src/lib/components/ui/chart/chart-style.svelte b/frontend/src/lib/components/ui/chart/chart-style.svelte
new file mode 100644
index 0000000..74c2b8a
--- /dev/null
+++ b/frontend/src/lib/components/ui/chart/chart-style.svelte
@@ -0,0 +1,37 @@
+<script lang="ts">
+ import { THEMES, type ChartConfig } from "./chart-utils.js";
+
+ let { id, config }: { id: string; config: ChartConfig } = $props();
+
+ const colorConfig = $derived(
+ config ? Object.entries(config).filter(([, config]) => config.theme || config.color) : null
+ );
+
+ const themeContents = $derived.by(() => {
+ if (!colorConfig || !colorConfig.length) return;
+
+ const themeContents = [];
+ for (const [_theme, prefix] of Object.entries(THEMES)) {
+ let content = `${prefix} [data-chart=${id}] {\n`;
+ const color = colorConfig.map(([key, itemConfig]) => {
+ const theme = _theme as keyof typeof itemConfig.theme;
+ const color = itemConfig.theme?.[theme] || itemConfig.color;
+ return color ? `\t--color-${key}: ${color};` : null;
+ });
+
+ content += color.join("\n") +"\n}";
+
+ themeContents.push(content);
+ }
+
+ return themeContents.join("\n");
+ });
+</script>
+
+{#if themeContents}
+ {#key id}
+ <svelte:element this={"style"}>
+ {themeContents}
+ </svelte:element>
+ {/key}
+{/if}