From 3c4582bb6af5efd3c8af3972c9dfe59f1ef6f5bd Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Tue, 25 Mar 2025 09:46:50 -0700 Subject: [PATCH 1/2] search bar --- .../docs/component.md => SearchInput.mdx} | 14 ++++++- .../SearchInput/SearchInput.stories.svelte | 23 ++---------- src/components/SearchInput/SearchInput.svelte | 37 ++++++------------- .../{ => components}/MagnifyingGlass.svelte | 6 +-- .../SearchInput/{ => components}/X.svelte | 8 ++-- 5 files changed, 35 insertions(+), 53 deletions(-) rename src/components/SearchInput/{stories/docs/component.md => SearchInput.mdx} (54%) rename src/components/SearchInput/{ => components}/MagnifyingGlass.svelte (94%) rename src/components/SearchInput/{ => components}/X.svelte (93%) diff --git a/src/components/SearchInput/stories/docs/component.md b/src/components/SearchInput/SearchInput.mdx similarity index 54% rename from src/components/SearchInput/stories/docs/component.md rename to src/components/SearchInput/SearchInput.mdx index 1adc87e4..cd743181 100644 --- a/src/components/SearchInput/stories/docs/component.md +++ b/src/components/SearchInput/SearchInput.mdx @@ -1,4 +1,12 @@ -Invite users to search for something. +import { Meta, Canvas } from '@storybook/blocks'; + +import * as SearchInputStories from './SearchInput.stories.svelte'; + + + +# SearchInput + +The `SearchInput` component creates a search bar. ```svelte - + ``` + + \ No newline at end of file diff --git a/src/components/SearchInput/SearchInput.stories.svelte b/src/components/SearchInput/SearchInput.stories.svelte index 55fbdf5a..bca718e7 100644 --- a/src/components/SearchInput/SearchInput.stories.svelte +++ b/src/components/SearchInput/SearchInput.stories.svelte @@ -1,26 +1,11 @@ - - - - - + \ No newline at end of file diff --git a/src/components/SearchInput/SearchInput.svelte b/src/components/SearchInput/SearchInput.svelte index b0761c69..c89a83dc 100644 --- a/src/components/SearchInput/SearchInput.svelte +++ b/src/components/SearchInput/SearchInput.svelte @@ -1,14 +1,10 @@ @@ -38,24 +26,23 @@ id="search--input" class="search--input body-caption pl-8" type="text" - placeholder="{searchPlaceholder}" - oninput="{input}" + placeholder={searchPlaceholder} bind:value />
+ \ No newline at end of file diff --git a/src/components/SearchInput/MagnifyingGlass.svelte b/src/components/SearchInput/components/MagnifyingGlass.svelte similarity index 94% rename from src/components/SearchInput/MagnifyingGlass.svelte rename to src/components/SearchInput/components/MagnifyingGlass.svelte index 1310ae96..c144a167 100644 --- a/src/components/SearchInput/MagnifyingGlass.svelte +++ b/src/components/SearchInput/components/MagnifyingGlass.svelte @@ -11,11 +11,11 @@ + \ No newline at end of file diff --git a/src/components/SearchInput/X.svelte b/src/components/SearchInput/components/X.svelte similarity index 93% rename from src/components/SearchInput/X.svelte rename to src/components/SearchInput/components/X.svelte index 8dfdf8c1..a774df7f 100644 --- a/src/components/SearchInput/X.svelte +++ b/src/components/SearchInput/components/X.svelte @@ -20,14 +20,14 @@ + \ No newline at end of file From 12f6515710ef16d32255014cbe07909d2e8f1b0e Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Mon, 31 Mar 2025 15:09:02 -0700 Subject: [PATCH 2/2] adds onsearch --- src/components/SearchInput/SearchInput.mdx | 18 ++++++++++-------- .../SearchInput/SearchInput.stories.svelte | 15 ++++++++++++++- src/components/SearchInput/SearchInput.svelte | 14 ++++++++++++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/components/SearchInput/SearchInput.mdx b/src/components/SearchInput/SearchInput.mdx index cd743181..6c347cd5 100644 --- a/src/components/SearchInput/SearchInput.mdx +++ b/src/components/SearchInput/SearchInput.mdx @@ -12,16 +12,18 @@ The `SearchInput` component creates a search bar. - + ``` - \ No newline at end of file + diff --git a/src/components/SearchInput/SearchInput.stories.svelte b/src/components/SearchInput/SearchInput.stories.svelte index bca718e7..ae596d55 100644 --- a/src/components/SearchInput/SearchInput.stories.svelte +++ b/src/components/SearchInput/SearchInput.stories.svelte @@ -8,4 +8,17 @@ }); - \ No newline at end of file + + + + + diff --git a/src/components/SearchInput/SearchInput.svelte b/src/components/SearchInput/SearchInput.svelte index c89a83dc..01e78d05 100644 --- a/src/components/SearchInput/SearchInput.svelte +++ b/src/components/SearchInput/SearchInput.svelte @@ -6,15 +6,23 @@ interface Props { /** The placeholder text that appears in the search box.*/ searchPlaceholder?: string; + /** Optional function that runs when the input value changes. */ + onsearch?: (newValue: string) => void; } - let { searchPlaceholder = 'Search...' }: Props = $props(); + let { searchPlaceholder = 'Search...', onsearch }: Props = $props(); let value = $state(''); let active = $derived(value !== ''); function clear() { value = ''; + if (onsearch) onsearch(value); // Call the prop to update the parent when cleared + } + + function oninput(event: Event) { + value = (event.target as HTMLInputElement).value; + if (onsearch) onsearch(value); // Update the parent on every input change } @@ -22,12 +30,14 @@
+
\ No newline at end of file +