Skip to content

Commit 63f9dc8

Browse files
authored
feat(DevContainer): Support dark mode (#243)
* Add theme prop * Default to light theme for backwards compatibility * Iterate docs
1 parent 507d031 commit 63f9dc8

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

components/src/ChartList/ChartList.mdx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as ChartListStories from './ChartList.stories.svelte';
66

77
# ChartList
88

9-
Utility component for displaying a list of charts with associated embed URLs during development, typically at the `/` route of your Svelte project.
9+
**Development-only** utility component for displaying a list of charts with associated embed, typically at the `/` route of your Svelte project.
1010

1111
- `charts` is a list of `ChartSpec` objects of the following shape:
1212

@@ -19,6 +19,28 @@ Utility component for displaying a list of charts with associated embed URLs dur
1919

2020
- `project` is a string of the shape `<Project Number>: <Project Title>`.
2121

22+
## Usage
23+
24+
In your `+page.svelte`:
25+
26+
```js
27+
<script>
28+
import { ChartList, DesignTokens } from '@swr-data-lab/components';
29+
30+
const baseUrl = 'https://static.datenhub.net/apps/p110_wald-klimawandel/main';
31+
const charts = [
32+
{ title: 'Baden-Württemberg Loosers', slug: 'bw-loosers' },
33+
{ title: 'Baden-Württemberg Winners', slug: 'bw-winners' },
34+
{ title: 'Rheinland-Pfalz Loosers', slug: 'rp-loosers' },
35+
{ title: 'Rheinland-Pfalz Winners', slug: 'rp-winners' }
36+
];
37+
</script>
38+
39+
<DesignTokens>
40+
<ChartList {baseUrl} {charts} project="p110: Wie sieht der Wald von morgen aus?" />
41+
</DesignTokens>
42+
```
43+
2244
<Stories />
2345

2446
<Controls />

components/src/DevContainer/DevContainer.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ import * as DevContainerStories from './DevContainer.stories.svelte';
66

77
# DevContainer
88

9-
Development fixture for simulating the grid system and various UI features on [SWR.de](https://www.swr.de). Particularly useful for developing charts using the [breakout component](?path=/docs/layout-breakout--docs).
9+
**Development-only** fixture for simulating the grid system and various UI features on [SWR.de](https://www.swr.de). Particularly useful for developing charts using the [breakout component](?path=/docs/layout-breakout--docs).
1010

1111
<Story of={DevContainerStories.NoPlayer} />
1212

1313
<Controls />
1414

1515
## Usage
1616

17+
In your `+page.svelte`:
18+
1719
```jsx
1820
<script lang='ts'>
1921
import { dev } from '$app/environment';
20-
import DevContainer from '@swr-data-lab/components';
22+
import { DevContainer } from '@swr-data-lab/components';
2123
import App from '$lib/App.svelte';
2224
</script>
2325

2426
{#if dev}
25-
<DevContainer>
27+
<DevContainer theme="light" showGrid>
2628
<App />
2729
</DevContainer>
2830
{:else}
2931
<p123-your-custom-element></p123-your-custom-element>
3032
{/if}
31-
```
33+
```

components/src/DevContainer/DevContainer.svelte

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
22
import type { Snippet } from 'svelte';
3+
34
import SwrLogo from './SwrLogo.svg.svelte';
45
import GridInspector from './GridInspector.svelte';
5-
import Copy from '../Copy/Copy.svelte';
66
import DesignTokens from '../DesignTokens/DesignTokens.svelte';
7-
import { text } from '@sveltejs/kit';
7+
import Copy from '../Copy/Copy.svelte';
88
99
interface DevContainerProps {
10+
theme: 'light' | 'dark' | 'auto';
1011
showHeader?: boolean;
1112
showNav?: boolean;
1213
showPlayer?: boolean;
@@ -21,6 +22,7 @@
2122
children?: Snippet;
2223
}
2324
let {
25+
theme = 'light',
2426
showHeader = true,
2527
showNav = true,
2628
showArticleHeader = true,
@@ -39,8 +41,13 @@
3941
let articleEl: HTMLElement | undefined = $state();
4042
</script>
4143

42-
<DesignTokens>
43-
<div class="container">
44+
<DesignTokens {theme}>
45+
<div
46+
class="container"
47+
style={theme === 'light'
48+
? '--blue: hsl(221, 75%, 46%); --blue-light: hsl(221, 100%, 95%)'
49+
: '--blue: hsl(220, 22%, 51%); --blue-light: hsl(219, 22%, 18%)'}
50+
>
4451
{#if showHeader}
4552
<header>
4653
<div class="header-inner">
@@ -144,9 +151,8 @@
144151
display: block;
145152
}
146153
.container {
147-
--blue: hsl(221, 75%, 46%);
148-
--blue-light: hsl(221, 100%, 95%);
149154
color: var(--blue);
155+
background: var(--color-pageFill);
150156
font-family: 'SWR-VAR-Sans', sans-serif;
151157
}
152158
header {

0 commit comments

Comments
 (0)