From afc42ec2d34dfd4894bf5d5b82940235db42ae85 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 13 Oct 2024 18:02:57 -0400 Subject: [PATCH] select-icon-component --- .../src/lib/components/SelectIcon.svelte | 60 +++++++++++++++ .../playground/[id]/AppControls.svelte | 75 +++++++------------ 2 files changed, 88 insertions(+), 47 deletions(-) create mode 100644 apps/svelte.dev/src/lib/components/SelectIcon.svelte diff --git a/apps/svelte.dev/src/lib/components/SelectIcon.svelte b/apps/svelte.dev/src/lib/components/SelectIcon.svelte new file mode 100644 index 0000000000..31a43144c1 --- /dev/null +++ b/apps/svelte.dev/src/lib/components/SelectIcon.svelte @@ -0,0 +1,60 @@ + + +
+ + +
+ + diff --git a/apps/svelte.dev/src/routes/(authed)/playground/[id]/AppControls.svelte b/apps/svelte.dev/src/routes/(authed)/playground/[id]/AppControls.svelte index 8d04ade60b..accb4f5714 100644 --- a/apps/svelte.dev/src/routes/(authed)/playground/[id]/AppControls.svelte +++ b/apps/svelte.dev/src/routes/(authed)/playground/[id]/AppControls.svelte @@ -11,6 +11,8 @@ import type { Gist, User } from '$lib/db/types'; import type { File } from '@sveltejs/repl'; import { browser } from '$app/environment'; + import SelectIcon from '$lib/components/SelectIcon.svelte'; + import { untrack } from 'svelte'; interface Props { examples: Array<{ title: string; examples: any[] }>; @@ -40,7 +42,7 @@ let downloading = $state(false); let justSaved = $state(false); let justForked = $state(false); - let select: HTMLSelectElement; + let select: any; // TODO why can't i do `select: SelectIcon`? function wait(ms: number) { return new Promise((f) => setTimeout(f, ms)); @@ -214,7 +216,12 @@ export default app;` // the example can be reselected $effect(() => { if (modified) { - select.value = ''; + // this is a little tricky, but: we need to wrap this in untrack + // because otherwise we'll read `select.value` and re-run this + // when we navigate, which we don't want + untrack(() => { + select.value = ''; + }); } }); @@ -222,27 +229,24 @@ export default app;`
-
- - -
+ { + goto(`/playground/${e.currentTarget.value}`); + }} + > + + + {#each examples as section} + + {#each section.examples as example} + + {/each} + + {/each} +