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