From 4dc585244c6cd6fa704749fe25af3a03d20f6452 Mon Sep 17 00:00:00 2001 From: Max Kohler Date: Wed, 4 Feb 2026 00:09:31 +0100 Subject: [PATCH] Build out feature --- components/src/ChartList/ChartList.mdx | 28 +++--- .../src/ChartList/ChartList.stories.svelte | 15 ++++ components/src/ChartList/ChartList.svelte | 85 ++++++++----------- components/src/ChartList/Row.svelte | 64 ++++++++++++++ 4 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 components/src/ChartList/Row.svelte diff --git a/components/src/ChartList/ChartList.mdx b/components/src/ChartList/ChartList.mdx index 4064d0aa..59943966 100644 --- a/components/src/ChartList/ChartList.mdx +++ b/components/src/ChartList/ChartList.mdx @@ -8,17 +8,6 @@ import * as ChartListStories from './ChartList.stories.svelte'; **Development-only** utility component for displaying a list of charts with associated embed, typically at the `/` route of your Svelte project. -- `charts` is a list of `ChartSpec` objects of the following shape: - - ```ts - interface ChartSpec { - title: string; - slug: string; - } - ``` - -- `project` is a string of the shape `: `. - ## Usage In your `+page.svelte`: @@ -41,6 +30,21 @@ In your `+page.svelte`: ``` - +### Props + +- `charts` is a list of `ChartSpec` objects of the following shape: + + ```ts + interface ChartSpec { + title: string; + slug: string; + group?: string; + } + ``` + +- `project` is a string of the shape `: `. +- `group` is an optional group name (useful for grouping charts by bundesland) + + diff --git a/components/src/ChartList/ChartList.stories.svelte b/components/src/ChartList/ChartList.stories.svelte index 7dacecf3..f25999e7 100644 --- a/components/src/ChartList/ChartList.stories.svelte +++ b/components/src/ChartList/ChartList.stories.svelte @@ -60,6 +60,21 @@ + + + + + + import { dev } from '$app/environment'; + import Row from './Row.svelte'; type ProjectPrefix = 'p' | 't'; type ProjectIdentifier = `${ProjectPrefix}${number}: ${string}`; @@ -7,13 +8,26 @@ interface ChartSpec { title: string; slug: string; + group?: string; } interface ChartListProps { project?: ProjectIdentifier; charts?: ChartSpec[]; baseUrl?: string; } - let { project, charts, baseUrl }: ChartListProps = $props(); + let { project, charts = [], baseUrl }: ChartListProps = $props(); + + const groups: string[] = $derived( + Array.from(new Set(charts.map((c) => c.group).filter((c) => typeof c === 'string'))) + ); + + const groupedCharts = $derived.by(() => { + let res: { [key: string]: ChartSpec[] } = {}; + groups.forEach((g) => (res[g] = charts.filter((el) => el.group === g))); + return res; + }); + + const ungroupedCharts = $derived(charts.filter((el) => !el.group));
@@ -23,23 +37,27 @@ + {#if groups.length > 0} + + {/if} - {#each charts as chart} - {@const route = `/${chart.slug}`} - - - - + {#each Object.values(groupedCharts) as charts} + {#each charts as chart, i} + + {/each} + {/each} + {#each ungroupedCharts as chart, i} + 0 && i === 0} + rowspan={ungroupedCharts.length === 1 ? 1 : 0} + > {/each}
GroupTitle Embed URL
- - {chart.title} - - - -
@@ -81,55 +99,22 @@ } } table { + border: 1px solid var(--color-surfaceBorder); border-collapse: collapse; border-spacing: 0; width: 100%; - border: 1px solid var(--color-surfaceBorder); - } - a { - display: block; - color: inherit; - text-decoration: none; - } - th, - td { - padding: 0 0.4em; - text-align: left; - border-right: 1px solid var(--color-surfaceBorder); - &:last-child { - border-right: 0; - } } + th { + text-align: left; padding: 0.2em 0.4em; border-right: 1px solid var(--color-textSecondary); border-bottom: 1px solid var(--color-textSecondary); - } - tr { - border-bottom: 1px solid var(--color-surfaceBorder); &:last-child { - border-bottom: 0; + border-right: 0; } } - input { - display: block; - font-family: monospace; - width: 100%; - padding: 0.35em 0; - font-size: 0.9rem; - background: var(--color-pageFill); - color: var(--color-textSecondary); - border: 0; - } - - a:hover, - a:focus-visible { - text-decoration: underline; - } - a:last-child { - border-bottom: 0; - } .notes { margin-top: 0.5em; color: var(--color-textSecondary); diff --git a/components/src/ChartList/Row.svelte b/components/src/ChartList/Row.svelte new file mode 100644 index 00000000..a1872d44 --- /dev/null +++ b/components/src/ChartList/Row.svelte @@ -0,0 +1,64 @@ + + + + {#if group} + {chart.group} + {/if} + + + {chart.title} + + + + + + + +