Merge pull request #73 from reuters-graphics/search-input
Break out the SearchInput from Table into its own component
This commit is contained in:
commit
883ebf823f
7 changed files with 47 additions and 3 deletions
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
25
src/components/SearchInput/SearchInput.stories.svelte
Normal file
25
src/components/SearchInput/SearchInput.stories.svelte
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<script>
|
||||||
|
import { Meta, Template, Story } from '@storybook/addon-svelte-csf';
|
||||||
|
|
||||||
|
// Don't lose the "?raw" in markdown imports!
|
||||||
|
// @ts-ignore
|
||||||
|
import componentDocs from './stories/docs/component.md?raw';
|
||||||
|
|
||||||
|
import SearchInput from './SearchInput.svelte';
|
||||||
|
|
||||||
|
import { withComponentDocs } from '$docs/utils/withParams.js';
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
title: 'Components/SearchInput',
|
||||||
|
component: SearchInput,
|
||||||
|
...withComponentDocs(componentDocs),
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Meta {...meta} />
|
||||||
|
|
||||||
|
<Template let:args>
|
||||||
|
<SearchInput {...args} />
|
||||||
|
</Template>
|
||||||
|
|
||||||
|
<Story name="Default" args="{{}}" />
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
<!-- @component `SearchInput` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-SearchInput--default) -->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
import MagnifyingGlass from './MagnifyingGlass.svelte';
|
import MagnifyingGlass from './MagnifyingGlass.svelte';
|
||||||
|
|
@ -7,7 +8,7 @@
|
||||||
* The placeholder text that appears in the search box.
|
* The placeholder text that appears in the search box.
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
export let searchPlaceholder: string = 'Search in table';
|
export let searchPlaceholder: string = 'Search...';
|
||||||
|
|
||||||
let value = '';
|
let value = '';
|
||||||
$: active = value !== '';
|
$: active = value !== '';
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
17
src/components/SearchInput/stories/docs/component.md
Normal file
17
src/components/SearchInput/stories/docs/component.md
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
Invite users to search for something.
|
||||||
|
|
||||||
|
```svelte
|
||||||
|
<script>
|
||||||
|
import { SearchInput } from '@reuters-graphics/graphics-components';
|
||||||
|
|
||||||
|
function handleSearchInput(event) {
|
||||||
|
const searchText = event.detail.value;
|
||||||
|
// Here's where you might update a variable,
|
||||||
|
// filter a dataset or make an API call
|
||||||
|
// based on the user's input.
|
||||||
|
console.log(`Search for ${searchText}`);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<SearchInput on:search="{handleSearchInput}" />
|
||||||
|
```
|
||||||
|
|
@ -135,7 +135,7 @@
|
||||||
/** Import local helpers */
|
/** Import local helpers */
|
||||||
import Block from '../Block/Block.svelte';
|
import Block from '../Block/Block.svelte';
|
||||||
import Pagination from './Pagination.svelte';
|
import Pagination from './Pagination.svelte';
|
||||||
import Search from './Search.svelte';
|
import SearchInput from '../SearchInput/SearchInput.svelte';
|
||||||
import Select from './Select.svelte';
|
import Select from './Select.svelte';
|
||||||
import SortArrow from './SortArrow.svelte';
|
import SortArrow from './SortArrow.svelte';
|
||||||
import { filterArray, paginateArray, getOptions } from './utils.js';
|
import { filterArray, paginateArray, getOptions } from './utils.js';
|
||||||
|
|
@ -236,7 +236,7 @@
|
||||||
{/if}
|
{/if}
|
||||||
{#if searchable}
|
{#if searchable}
|
||||||
<div class="table--header--search">
|
<div class="table--header--search">
|
||||||
<Search
|
<SearchInput
|
||||||
bind:searchPlaceholder
|
bind:searchPlaceholder
|
||||||
on:search="{handleSearchInput}"
|
on:search="{handleSearchInput}"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ export { default as ReferralBlock } from './components/ReferralBlock/ReferralBlo
|
||||||
export { default as ReutersGraphicsLogo } from './components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte';
|
export { default as ReutersGraphicsLogo } from './components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte';
|
||||||
export { default as ReutersLogo } from './components/ReutersLogo/ReutersLogo.svelte';
|
export { default as ReutersLogo } from './components/ReutersLogo/ReutersLogo.svelte';
|
||||||
export { default as Scroller } from './components/Scroller/Scroller.svelte';
|
export { default as Scroller } from './components/Scroller/Scroller.svelte';
|
||||||
|
export { default as SearchInput } from './components/SearchInput/SearchInput.svelte';
|
||||||
export { default as SEO } from './components/SEO/SEO.svelte';
|
export { default as SEO } from './components/SEO/SEO.svelte';
|
||||||
export { default as Sharer } from './components/Sharer/Sharer.svelte';
|
export { default as Sharer } from './components/Sharer/Sharer.svelte';
|
||||||
export { default as SimpleTimeline } from './components/SimpleTimeline/SimpleTimeline.svelte';
|
export { default as SimpleTimeline } from './components/SimpleTimeline/SimpleTimeline.svelte';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue