Skip to content

Commit c488940

Browse files
committed
docs: Add shared debug state across all examples to simplify UI and be easily reachable (sticky)
1 parent c335593 commit c488940

18 files changed

Lines changed: 79 additions & 168 deletions

File tree

packages/layerchart/src/routes/docs/+layout.svelte

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@
1919
ApiDocs,
2020
Button,
2121
Dialog,
22+
Field,
2223
Icon,
2324
ListItem,
25+
Menu,
26+
Switch,
2427
TableOfContents,
28+
Toggle,
2529
ToggleGroup,
2630
ToggleOption,
31+
Tooltip,
2732
} from 'svelte-ux';
2833
2934
import { MediaQueryPresets } from '@layerstack/svelte-state';
@@ -35,6 +40,9 @@
3540
import { page } from '$app/state';
3641
import { shared } from './shared.svelte.js';
3742
43+
// @ts-ignore
44+
import IconSettings from '~icons/lucide/settings';
45+
3846
const { children } = $props();
3947
4048
const [type, name] = $derived(page.url.pathname.split('/').slice(2) ?? []);
@@ -116,25 +124,41 @@
116124
{/if}
117125
</span>
118126

119-
{#if supportedContexts}
120-
<ToggleGroup
121-
bind:value={shared.renderContext}
122-
variant="fill"
123-
color="primary"
124-
inset
125-
gap="px"
126-
size="sm"
127-
>
128-
{#each supportedContexts as context}
129-
<ToggleOption value={context}>{toTitleCase(context)}</ToggleOption>
130-
{/each}
131-
</ToggleGroup>
132-
{/if}
127+
<span class="flex items-center gap-1">
128+
{#if supportedContexts}
129+
<ToggleGroup
130+
bind:value={shared.renderContext}
131+
variant="fill"
132+
color="primary"
133+
inset
134+
gap="px"
135+
size="sm"
136+
>
137+
{#each supportedContexts as context}
138+
<ToggleOption value={context}>{toTitleCase(context)}</ToggleOption>
139+
{/each}
140+
</ToggleGroup>
141+
{/if}
142+
143+
<Toggle let:on={open} let:toggle let:toggleOff>
144+
<Tooltip title="Settings">
145+
<Button iconOnly on:click={toggle}>
146+
<IconSettings class="text-surface-content" />
147+
<Menu {open} on:close={toggleOff} placement="bottom-start" classes={{ menu: 'p-2' }}>
148+
<label class="flex items-center gap-2">
149+
<span class="text-sm text-surface-content">Debug</span>
150+
<Switch bind:checked={shared.debug} />
151+
</label>
152+
</Menu>
153+
</Button>
154+
</Tooltip>
155+
</Toggle>
156+
</span>
133157

134158
{#if status}
135159
<span
136160
class={cls(
137-
'text-sm px-2 rounded-sm',
161+
'text-sm px-2 rounded-sm',
138162
status === 'beta' && 'bg-yellow-500/20 text-yellow-800',
139163
status === 'deprecated' && 'bg-red-500/20 text-red-900'
140164
)}

packages/layerchart/src/routes/docs/components/AnnotationLine/+page.svelte

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
LineChart,
99
type Placement,
1010
} from 'layerchart';
11-
import { Button, Field, Menu, RangeField, Switch, Toggle } from 'svelte-ux';
11+
import { Button, Field, Menu, RangeField, Toggle } from 'svelte-ux';
1212
import { format, sortFunc } from '@layerstack/utils';
1313
1414
import Preview from '$lib/docs/Preview.svelte';
@@ -57,15 +57,11 @@
5757
let renderContext = $derived(
5858
shared.renderContext as ComponentProps<typeof LineChart>['renderContext']
5959
);
60-
let debug = $state(false);
60+
let debug = $derived(shared.debug);
6161
</script>
6262

6363
<h1>Examples</h1>
6464

65-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
66-
<Switch {id} bind:checked={debug} />
67-
</Field>
68-
6965
<h2>Vertical</h2>
7066

7167
<Preview data={data.appleStock}>

packages/layerchart/src/routes/docs/components/AnnotationPoint/+page.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Tooltip,
1010
type Placement,
1111
} from 'layerchart';
12-
import { Button, Field, Menu, RangeField, Switch, Toggle } from 'svelte-ux';
12+
import { Button, Field, Menu, RangeField, Toggle } from 'svelte-ux';
1313
import { format, sortFunc } from '@layerstack/utils';
1414
import { maxIndex } from 'd3-array';
1515
@@ -58,17 +58,11 @@
5858
let radius = $state(4);
5959
6060
let renderContext = $derived(shared.renderContext as 'svg' | 'canvas');
61-
let debug = $state(false);
61+
let debug = $derived(shared.debug);
6262
</script>
6363

6464
<h1>Examples</h1>
6565

66-
<div class="grid grid-cols-[1fr_auto] gap-2">
67-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
68-
<Switch {id} bind:checked={debug} />
69-
</Field>
70-
</div>
71-
7266
<h2>On axis with tooltip</h2>
7367

7468
<Preview data={data.appleStock}>

packages/layerchart/src/routes/docs/components/AnnotationRange/+page.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { ComponentProps } from 'svelte';
33
44
import { AnnotationRange, BarChart, LineChart, type Placement } from 'layerchart';
5-
import { Button, Field, Menu, RangeField, Switch, Toggle } from 'svelte-ux';
5+
import { Button, Field, Menu, RangeField, Toggle } from 'svelte-ux';
66
77
import Preview from '$lib/docs/Preview.svelte';
88
import { createDateSeries } from '$lib/utils/genData.js';
@@ -36,17 +36,11 @@
3636
let renderContext = $derived(
3737
shared.renderContext as ComponentProps<typeof LineChart>['renderContext']
3838
);
39-
let debug = $state(false);
39+
let debug = $derived(shared.debug);
4040
</script>
4141

4242
<h1>Examples</h1>
4343

44-
<div class="grid grid-cols-[1fr_auto] gap-2">
45-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
46-
<Switch {id} bind:checked={debug} />
47-
</Field>
48-
</div>
49-
5044
<h2>Horizontal with pattern, lower bound</h2>
5145

5246
<Preview data={data.appleStock}>

packages/layerchart/src/routes/docs/components/ArcChart/+page.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,11 @@
3232
let renderContext = $derived(
3333
shared.renderContext as ComponentProps<typeof ArcChart>['renderContext']
3434
);
35-
let debug = $state(false);
35+
let debug = $derived(shared.debug);
3636
</script>
3737

3838
<h1>Examples</h1>
3939

40-
<div class="grid grid-cols-[1fr_auto] gap-2">
41-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
42-
<Switch {id} bind:checked={debug} />
43-
</Field>
44-
</div>
45-
4640
<h2>Single value</h2>
4741

4842
<Preview data={[{ key: 'Example', value: 70 }]}>

packages/layerchart/src/routes/docs/components/AreaChart/+page.svelte

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import { group } from 'd3-array';
2424
import { timeDay } from 'd3-time';
2525
import { scaleBand, scalePoint } from 'd3-scale';
26-
import { Button, Field, Kbd, Switch } from 'svelte-ux';
26+
import { Button, Kbd } from 'svelte-ux';
2727
import { format, sortFunc } from '@layerstack/utils';
2828
import { cls } from '@layerstack/tailwind';
2929
@@ -130,7 +130,7 @@
130130
let renderContext = $derived(
131131
shared.renderContext as ComponentProps<typeof AreaChart>['renderContext']
132132
);
133-
let debug = $state(false);
133+
let debug = $derived(shared.debug);
134134
135135
let markerPoints: { date: Date; value: number }[] = $state([]);
136136
let context = $state<ChartContextValue<(typeof denseDateSeriesData)[number]>>(null!);
@@ -166,12 +166,6 @@
166166

167167
<h1>Examples</h1>
168168

169-
<div class="grid grid-cols-[1fr_auto] gap-2">
170-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
171-
<Switch {id} bind:checked={debug} />
172-
</Field>
173-
</div>
174-
175169
<h2>Basic</h2>
176170

177171
<Preview data={dateSeriesData}>

packages/layerchart/src/routes/docs/components/Axis/+page.svelte

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
timeYear,
1212
timeMillisecond,
1313
} from 'd3-time';
14-
import { Field, RangeField, Switch } from 'svelte-ux';
14+
import { RangeField } from 'svelte-ux';
1515
1616
import Preview from '$lib/docs/Preview.svelte';
1717
@@ -52,7 +52,7 @@
5252
5353
let tickSpacing = $state(80); // x-axis default
5454
55-
let debug = $state(false);
55+
let debug = $derived(shared.debug);
5656
</script>
5757

5858
<h1>Examples</h1>
@@ -454,15 +454,7 @@
454454
</div>
455455
</Preview>
456456

457-
<div class="grid grid-cols-[1fr_auto] gap-2 items-end">
458-
<h2>Axis label placements (top/bottom)</h2>
459-
460-
<div class="mb-2 flex gap-6">
461-
<Field label="Debug:" dense labelPlacement="left" let:id>
462-
<Switch {id} bind:checked={debug} />
463-
</Field>
464-
</div>
465-
</div>
457+
<h2>Axis label placements (top/bottom)</h2>
466458

467459
<Preview>
468460
<div class="h-[300px] p-4 border rounded-sm">
@@ -489,15 +481,7 @@
489481
</div>
490482
</Preview>
491483

492-
<div class="grid grid-cols-[1fr_auto] gap-2 items-end">
493-
<h2>Axis label placements (left/right)</h2>
494-
495-
<div class="mb-2 flex gap-6">
496-
<Field label="Debug:" dense labelPlacement="left" let:id>
497-
<Switch {id} bind:checked={debug} />
498-
</Field>
499-
</div>
500-
</div>
484+
<h2>Axis label placements (left/right)</h2>
501485

502486
<Preview>
503487
<div class="h-[300px] p-4 border rounded-sm">
@@ -520,15 +504,7 @@
520504
</div>
521505
</Preview>
522506

523-
<div class="grid grid-cols-[1fr_auto] gap-2 items-end">
524-
<h2>Multiple time axis with same placement (bottom)</h2>
525-
526-
<div class="mb-2 flex gap-6">
527-
<Field label="Debug:" dense labelPlacement="left" let:id>
528-
<Switch {id} bind:checked={debug} />
529-
</Field>
530-
</div>
531-
</div>
507+
<h2>Multiple time axis with same placement (bottom)</h2>
532508

533509
<Preview>
534510
<div class="h-[80px] p-4 border rounded-sm">
@@ -579,15 +555,7 @@
579555
</div>
580556
</Preview>
581557

582-
<div class="grid grid-cols-[1fr_auto] gap-2 items-end">
583-
<h2>Multiple different axis with same placement (right)</h2>
584-
585-
<div class="mb-2 flex gap-6">
586-
<Field label="Debug:" dense labelPlacement="left" let:id>
587-
<Switch {id} bind:checked={debug} />
588-
</Field>
589-
</div>
590-
</div>
558+
<h2>Multiple different axis with same placement (right)</h2>
591559

592560
<Preview>
593561
<div class="h-[300px] p-4 border rounded-sm">

packages/layerchart/src/routes/docs/components/BarChart/+page.svelte

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import Preview from '$lib/docs/Preview.svelte';
2121
import Blockquote from '$lib/docs/Blockquote.svelte';
2222
import { createDateSeries, wideData, longData } from '$lib/utils/genData.js';
23-
import { Field, Switch } from 'svelte-ux';
2423
import { timeMonth } from 'd3-time';
2524
import { interpolate, quantize } from 'd3-interpolate';
2625
import { interpolateSpectral } from 'd3-scale-chromatic';
@@ -105,17 +104,11 @@
105104
];
106105
107106
let renderContext = $derived(shared.renderContext as 'svg' | 'canvas');
108-
let debug = $state(false);
107+
let debug = $derived(shared.debug);
109108
</script>
110109

111110
<h1>Examples</h1>
112111

113-
<div class="grid grid-cols-[1fr_auto] gap-2">
114-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
115-
<Switch {id} bind:checked={debug} />
116-
</Field>
117-
</div>
118-
119112
<h2>Vertical (default)</h2>
120113

121114
<Preview data={dateSeriesData}>

packages/layerchart/src/routes/docs/components/LineChart/+page.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@
8888
let show = $state(true);
8989
9090
let renderContext = $derived(shared.renderContext as 'svg' | 'canvas');
91-
let debug = $state(false);
91+
let debug = $derived(shared.debug);
9292
</script>
9393

9494
<h1>Examples</h1>
9595

96-
<div class="grid grid-cols-[1fr_auto] gap-2">
97-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
98-
<Switch {id} bind:checked={debug} />
99-
</Field>
100-
</div>
101-
10296
<h2>Basic</h2>
10397

10498
<Preview data={dateSeriesData}>

packages/layerchart/src/routes/docs/components/PieChart/+page.svelte

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,11 @@
4646
let renderContext = $derived(
4747
shared.renderContext as ComponentProps<typeof PieChart>['renderContext']
4848
);
49-
let debug = $state(false);
49+
let debug = $derived(shared.debug);
5050
</script>
5151

5252
<h1>Examples</h1>
5353

54-
<div class="grid grid-cols-[1fr_auto] gap-2">
55-
<Field label="Debug" let:id classes={{ container: 'h-full' }}>
56-
<Switch {id} bind:checked={debug} />
57-
</Field>
58-
</div>
59-
6054
<h2>Basic</h2>
6155

6256
<Preview {data}>

0 commit comments

Comments
 (0)