search bar
This commit is contained in:
parent
fd5df38dcf
commit
3c4582bb6a
5 changed files with 35 additions and 53 deletions
|
|
@ -1,4 +1,12 @@
|
||||||
Invite users to search for something.
|
import { Meta, Canvas } from '@storybook/blocks';
|
||||||
|
|
||||||
|
import * as SearchInputStories from './SearchInput.stories.svelte';
|
||||||
|
|
||||||
|
<Meta of={SearchInputStories} />
|
||||||
|
|
||||||
|
# SearchInput
|
||||||
|
|
||||||
|
The `SearchInput` component creates a search bar.
|
||||||
|
|
||||||
```svelte
|
```svelte
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -13,5 +21,7 @@ Invite users to search for something.
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SearchInput on:search="{handleSearchInput}" />
|
<SearchInput on:search={handleSearchInput} />
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<Canvas of={SearchInputStories.Demo} />
|
||||||
|
|
@ -1,26 +1,11 @@
|
||||||
<script module lang="ts">
|
<script module lang="ts">
|
||||||
// @ts-ignore raw
|
import { defineMeta } from '@storybook/addon-svelte-csf';
|
||||||
import componentDocs from './stories/docs/component.md?raw';
|
|
||||||
|
|
||||||
import SearchInput from './SearchInput.svelte';
|
import SearchInput from './SearchInput.svelte';
|
||||||
|
|
||||||
import { withComponentDocs } from '$lib/docs/utils/withParams.js';
|
const { Story } = defineMeta({
|
||||||
|
|
||||||
export const meta = {
|
|
||||||
title: 'Components/Controls/SearchInput',
|
title: 'Components/Controls/SearchInput',
|
||||||
component: SearchInput,
|
component: SearchInput,
|
||||||
...withComponentDocs(componentDocs),
|
});
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<Story name="Demo" />
|
||||||
import { Template, Story } from '@storybook/addon-svelte-csf';
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<Template >
|
|
||||||
{#snippet children({ args })}
|
|
||||||
<SearchInput {...args} />
|
|
||||||
{/snippet}
|
|
||||||
</Template>
|
|
||||||
|
|
||||||
<Story name="Default" args="{{}}" />
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
<!-- @component `SearchInput` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-controls-searchinput--docs) -->
|
<!-- @component `SearchInput` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-controls-searchinput--docs) -->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte';
|
import MagnifyingGlass from './components/MagnifyingGlass.svelte';
|
||||||
import MagnifyingGlass from './MagnifyingGlass.svelte';
|
import X from './components/X.svelte';
|
||||||
import X from './X.svelte';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
/**
|
/** The placeholder text that appears in the search box.*/
|
||||||
* The placeholder text that appears in the search box.
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
searchPlaceholder?: string;
|
searchPlaceholder?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -17,16 +13,8 @@
|
||||||
let value = $state('');
|
let value = $state('');
|
||||||
let active = $derived(value !== '');
|
let active = $derived(value !== '');
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
function input(event) {
|
|
||||||
value = event.target.value;
|
|
||||||
dispatch('search', { value });
|
|
||||||
}
|
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
value = '';
|
value = '';
|
||||||
dispatch('search', { value: '' });
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -38,24 +26,23 @@
|
||||||
id="search--input"
|
id="search--input"
|
||||||
class="search--input body-caption pl-8"
|
class="search--input body-caption pl-8"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="{searchPlaceholder}"
|
placeholder={searchPlaceholder}
|
||||||
oninput="{input}"
|
|
||||||
bind:value
|
bind:value
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="search--x absolute"
|
class="search--x absolute"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
class:invisible="{!active}"
|
class:invisible={!active}
|
||||||
onclick="{clear}"
|
onclick={clear}
|
||||||
onkeyup="{clear}"
|
onkeyup={clear}
|
||||||
>
|
>
|
||||||
<X />
|
<X />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use '../../scss/mixins' as *;
|
@use '../../scss/mixins' as mixins;
|
||||||
|
|
||||||
.search {
|
.search {
|
||||||
width: 250px;
|
width: 250px;
|
||||||
|
|
@ -64,11 +51,11 @@
|
||||||
top: 0.55rem;
|
top: 0.55rem;
|
||||||
width: 1.5rem;
|
width: 1.5rem;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
fill: $theme-colour-brand-rules;
|
fill: mixins.$theme-colour-brand-rules;
|
||||||
}
|
}
|
||||||
.search--input {
|
.search--input {
|
||||||
height: 2.15rem;
|
height: 2.15rem;
|
||||||
border: 1px solid $theme-colour-brand-rules;
|
border: 1px solid mixins.$theme-colour-brand-rules;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
@ -78,7 +65,7 @@
|
||||||
top: 0.55rem;
|
top: 0.55rem;
|
||||||
width: 1.5rem;
|
width: 1.5rem;
|
||||||
height: 1.5rem;
|
height: 1.5rem;
|
||||||
fill: $theme-colour-text-primary;
|
fill: mixins.$theme-colour-text-primary;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
&.invisible {
|
&.invisible {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,11 @@
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use '../../scss/mixins' as *;
|
@use '../../../scss/mixins' as mixins;
|
||||||
svg {
|
svg {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
path {
|
path {
|
||||||
fill: $theme-colour-brand-rules;
|
fill: mixins.$theme-colour-brand-rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
|
@ -20,14 +20,14 @@
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use '../../scss/mixins' as *;
|
@use '../../../scss/mixins' as mixins;
|
||||||
svg {
|
svg {
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
path {
|
path {
|
||||||
fill: $theme-colour-brand-rules;
|
fill: mixins.$theme-colour-brand-rules;
|
||||||
}
|
}
|
||||||
rect {
|
rect {
|
||||||
fill: $theme-colour-background;
|
fill: mixins.$theme-colour-background;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2 KiB |
Loading…
Reference in a new issue