Skip to content

Commit

Permalink
Add stories and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DTCurrie committed Aug 29, 2023
1 parent e934722 commit 4a7e9a2
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as Pill } from './pill.svelte';
export { default as Switch } from './switch.svelte';
export { default as Radio } from './radio.svelte';
export { default as Tabs } from './tabs.svelte';
export { useUniqueId } from './unique-id';

export {
default as Tooltip,
Expand All @@ -34,12 +35,13 @@ export {
type TextInputTypes,
} from './input/text-input.svelte';

export { default as Select, type SelectState } from './select/select.svelte';
export { default as SearchableSelect } from './select/searchable-select.svelte';
export { type SortOptions } from './select/search';

export { default as Table, type TableVariant } from './table/table.svelte';
export { default as TableHeader } from './table/table-header.svelte';
export { default as TableHeaderCell } from './table/table-header-cell.svelte';
export { default as TableBody } from './table/table-body.svelte';
export { default as TableRow } from './table/table-row.svelte';
export { default as TableCell } from './table/table-cell.svelte';
export { default as Select, type SelectState } from './select/select.svelte';

export * from './unique-id';
7 changes: 2 additions & 5 deletions packages/core/src/lib/select/searchable-select.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export let options: string[] = [];
export let value: string | undefined = undefined;
export let disabled = false;
export let state: SelectState = 'none';
export let button: { text: string; icon: string } | undefined = undefined;
export let sort: SortOptions = 'default';
export let button: { text: string; icon: string } | undefined = undefined;
export let heading = '';
const dispatch = createEventDispatcher<{
Expand All @@ -31,8 +31,6 @@ const dispatch = createEventDispatcher<{
}>();
const menuId = useUniqueId('searchable-select');
let wrapper: Element;
let menu: HTMLUListElement;
let open = false;
Expand Down Expand Up @@ -166,7 +164,6 @@ $: {
</script>

<div
bind:this={wrapper}
class="relative flex w-full"
use:clickOutside={closeMenu}
>
Expand All @@ -175,7 +172,7 @@ $: {
bind:value
role="combobox"
aria-controls={menuId}
aria-expanded={open ? true : undefined}
aria-expanded={open}
readonly={disabled ? true : undefined}
aria-disabled={disabled ? true : undefined}
type="text"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
import {
Label,
SearchableSelect,
type SelectState,
type SortOptions,
} from '@viamrobotics/prime-core';
export let options: string[] = [];
export let value: string | undefined = undefined;
export let disabled = false;
export let state: SelectState = 'none';
export let sort: SortOptions = 'default';
export let button: { text: string; icon: string } | undefined = undefined;
export let heading = '';
</script>

<Label>
Options:
<SearchableSelect
slot="input"
{options}
{value}
{disabled}
{state}
{sort}
{button}
{heading}
/>
</Label>
109 changes: 109 additions & 0 deletions packages/storybook/src/stories/select/searchable-select.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { Canvas, Meta, Story } from '@storybook/addon-docs';
import { SearchableSelect } from '@viamrobotics/prime-core';
import LabeledSelect from './labeled-searchable-select.svelte';

<Meta
title='Elements/Select/SearchableSelect'
argTypes={{
value: {
description: "The select's value",
control: { type: 'text' },
table: { defaultValue: { summary: '' } },
},
options: {
description: 'The select options',
control: { type: 'object' },
table: {
defaultValue: {
summary: '[]',
},
},
},
disabled: {
description: 'If the select should be readonly and inoperable',
control: { type: 'boolean' },
table: { defaultValue: { summary: false } },
},
state: {
description: 'The state of the select',
control: { type: 'select' },
options: ['warn', 'error', 'none'],
table: { defaultValue: { summary: 'none' } },
},
sort: {
description: 'The sorting/filtering behavior for the select',
control: { type: 'select' },
options: ['default', 'reduce', 'off'],
table: { defaultValue: { summary: 'default' } },
},
button: {
description: 'An optional action button for the select',
control: { type: 'object' },
table: {
defaultValue: { summary: { text: 'Do Something', icon: 'alert' } },
},
},
value: {
description: 'An optional heading to put at the top of the select menu',
control: { type: 'text' },
table: { defaultValue: { summary: 'Search results' } },
},
}}
/>

# Searchable Select

A simple user input for selecting from a list of options. This is an implementation
of the native HTML `<select />` with our styles applied.

<Canvas>
<Story
name='SearchableSelect'
args={{
options: [
'First Option',
'Option 2',
'C.) Option',
'Something Else',
'With A Whole Lot Of Parts',
],
}}
>
{(props) => ({
Component: SearchableSelect,
props,
})}
</Story>
</Canvas>

## Labels

For accessibility, consider wrapping your `<SearchableSelect />` in a `<Label />`. Make
to pass it `slot="input"` to correctly slot it in.

<Canvas>
<Story
name='Labeled Select'
args={{
options: [
'First Option',
'Option 2',
'C.) Option',
'Something Else',
'With A Whole Lot Of Parts',
],
}}
>
{(props) => ({
Component: LabeledSelect,
options: [
'First Option',
'Option 2',
'C.) Option',
'Something Else',
'With A Whole Lot Of Parts',
],
props,
})}
</Story>
</Canvas>
4 changes: 2 additions & 2 deletions packages/storybook/src/stories/select/select.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import LabeledSelect from './labeled-select.svelte';
state: {
description: 'The state of the select',
control: { type: 'select' },
options: ['info', 'warn', 'error', 'none'],
options: ['warn', 'error', 'none'],
table: { defaultValue: { summary: 'none' } },
},
}}
Expand All @@ -42,7 +42,7 @@ of the native HTML `<select />` with our styles applied.
## Labels

For accessibility, consider wrapping your `<Select />` in a `<Label />`. Make
to pass it `slot="select"` to correctly slot it in.
to pass it `slot="input"` to correctly slot it in.

<Canvas>
<Story name='Labeled Select'>
Expand Down

0 comments on commit 4a7e9a2

Please sign in to comment.