From 4f73b8b71a2de68fce9a0deabb84beb359c4a3fa Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 21 Dec 2019 17:16:15 -0800 Subject: [PATCH 1/3] feat(components): add RadioButtonGroup Closes #25 --- README.md | 1 + .../RadioButton/RadioButton.Skeleton.svelte | 4 +- .../RadioButton/RadioButton.Story.svelte | 5 +- src/components/RadioButton/RadioButton.svelte | 22 +++++++-- .../RadioButtonGroup.Story.svelte | 16 +++++++ .../RadioButtonGroup.stories.js | 40 ++++++++++++++++ .../RadioButtonGroup/RadioButtonGroup.svelte | 46 +++++++++++++++++++ src/components/RadioButtonGroup/index.js | 3 ++ src/index.js | 2 + 9 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 src/components/RadioButtonGroup/RadioButtonGroup.Story.svelte create mode 100644 src/components/RadioButtonGroup/RadioButtonGroup.stories.js create mode 100644 src/components/RadioButtonGroup/RadioButtonGroup.svelte create mode 100644 src/components/RadioButtonGroup/index.js diff --git a/README.md b/README.md index 2b380ed1..0afb9dfa 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Currently, the following components are supported: - ProgressStep - RadioButton - RadioButtonSkeleton +- RadioButtonGroup - Search - SearchSkeleton - SkeletonPlaceholder diff --git a/src/components/RadioButton/RadioButton.Skeleton.svelte b/src/components/RadioButton/RadioButton.Skeleton.svelte index 9bdd89d8..08456576 100644 --- a/src/components/RadioButton/RadioButton.Skeleton.svelte +++ b/src/components/RadioButton/RadioButton.Skeleton.svelte @@ -1,14 +1,14 @@ -
+
diff --git a/src/components/RadioButton/RadioButton.Story.svelte b/src/components/RadioButton/RadioButton.Story.svelte index 688ac99e..6ffc2e4e 100644 --- a/src/components/RadioButton/RadioButton.Story.svelte +++ b/src/components/RadioButton/RadioButton.Story.svelte @@ -8,11 +8,8 @@ - {#if story === 'skeleton'} -
- -
+ {:else} {/if} diff --git a/src/components/RadioButton/RadioButton.svelte b/src/components/RadioButton/RadioButton.svelte index 7c1ae093..56d0f276 100644 --- a/src/components/RadioButton/RadioButton.svelte +++ b/src/components/RadioButton/RadioButton.svelte @@ -9,26 +9,38 @@ export let hideLabel = false; export let labelPosition = 'right'; export let name = ''; - export let props = {}; + export let style = undefined; + import { getContext } from 'svelte'; + import { writable } from 'svelte/store'; import { cx } from '../../lib'; + const ctx = getContext('RadioButtonGroup'); const _class = cx( '--radio-button-wrapper', labelPosition !== 'right' && `--radio-button-wrapper--label-${labelPosition}`, className ); const _innerLabelClass = cx(hideLabel && '--visually-hidden'); + + let selected = ctx ? ctx.selected : writable(checked ? value : undefined); + + if (ctx) { + ctx.add({ id, checked, disabled, value }); + } + + $: checked = $selected === value; -
+
{ - value = event.target.value; + on:change={() => { + if (ctx) { + ctx.update(value); + } }} {id} {name} diff --git a/src/components/RadioButtonGroup/RadioButtonGroup.Story.svelte b/src/components/RadioButtonGroup/RadioButtonGroup.Story.svelte new file mode 100644 index 00000000..391b2f9e --- /dev/null +++ b/src/components/RadioButtonGroup/RadioButtonGroup.Story.svelte @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/src/components/RadioButtonGroup/RadioButtonGroup.stories.js b/src/components/RadioButtonGroup/RadioButtonGroup.stories.js new file mode 100644 index 00000000..10471188 --- /dev/null +++ b/src/components/RadioButtonGroup/RadioButtonGroup.stories.js @@ -0,0 +1,40 @@ +import { withKnobs, text, select, boolean } from '@storybook/addon-knobs'; +import Component from './RadioButtonGroup.Story.svelte'; + +export default { title: 'RadioButtonGroup', decorators: [withKnobs] }; + +const values = { + standard: 'standard', + 'default-selected': 'default-selected', + disabled: 'disabled' +}; + +const orientations = { + 'Horizontal (horizontal)': 'horizontal', + 'Vertical (vertical)': 'vertical' +}; + +const labelPositions = { + 'Left (left)': 'left', + 'Right (right)': 'right' +}; + +export const Default = () => ({ + Component, + props: { + group: { + name: text('The form control name (name in )', 'radio-button-group'), + valueSelected: select( + 'Value of the selected button (valueSelected in )', + values, + 'default-selected' + ), + orientation: select('Radio button orientation (orientation)', orientations, 'horizontal'), + labelPosition: select('Label position (labelPosition)', labelPositions, 'right') + }, + radio: { + disabled: boolean('Disabled (disabled in )', false), + labelText: text('Label text (labelText in )', 'Radio button label') + } + } +}); diff --git a/src/components/RadioButtonGroup/RadioButtonGroup.svelte b/src/components/RadioButtonGroup/RadioButtonGroup.svelte new file mode 100644 index 00000000..34ae296a --- /dev/null +++ b/src/components/RadioButtonGroup/RadioButtonGroup.svelte @@ -0,0 +1,46 @@ + + +
+
+ +
+
diff --git a/src/components/RadioButtonGroup/index.js b/src/components/RadioButtonGroup/index.js new file mode 100644 index 00000000..6e800ebd --- /dev/null +++ b/src/components/RadioButtonGroup/index.js @@ -0,0 +1,3 @@ +import RadioButtonGroup from './RadioButtonGroup.svelte'; + +export default RadioButtonGroup; diff --git a/src/index.js b/src/index.js index ec51b590..035e6f83 100644 --- a/src/index.js +++ b/src/index.js @@ -25,6 +25,7 @@ import ProgressIndicator, { ProgressStep } from './components/ProgressIndicator'; import RadioButton, { RadioButtonSkeleton } from './components/RadioButton'; +import RadioButtonGroup from './components/RadioButtonGroup'; import Search, { SearchSkeleton } from './components/Search'; import SkeletonPlaceholder from './components/SkeletonPlaceholder'; import SkeletonText from './components/SkeletonText'; @@ -80,6 +81,7 @@ export { ProgressStep, RadioButton, RadioButtonSkeleton, + RadioButtonGroup, Search, SearchSkeleton, SelectableTile, From 6c75c8a973652b47a5dfa3d6500fddbcd1f8e030 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 21 Dec 2019 17:18:35 -0800 Subject: [PATCH 2/3] feat(components): add Select, SelectItem, SelectItemGroup Closes #31 --- README.md | 4 + src/components/Select/Select.Skeleton.svelte | 19 ++++ src/components/Select/Select.Story.svelte | 29 +++++ src/components/Select/Select.stories.js | 36 ++++++ src/components/Select/Select.svelte | 110 +++++++++++++++++++ src/components/Select/SelectItem.svelte | 19 ++++ src/components/Select/SelectItemGroup.svelte | 15 +++ src/components/Select/index.js | 6 + src/index.js | 5 + 9 files changed, 243 insertions(+) create mode 100644 src/components/Select/Select.Skeleton.svelte create mode 100644 src/components/Select/Select.Story.svelte create mode 100644 src/components/Select/Select.stories.js create mode 100644 src/components/Select/Select.svelte create mode 100644 src/components/Select/SelectItem.svelte create mode 100644 src/components/Select/SelectItemGroup.svelte create mode 100644 src/components/Select/index.js diff --git a/README.md b/README.md index 0afb9dfa..ac413ff6 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,10 @@ Currently, the following components are supported: - RadioButtonGroup - Search - SearchSkeleton +- Select + - SelectSkeleton + - SelectItem + - SelectItemGroup - SkeletonPlaceholder - SkeletonText - Tag diff --git a/src/components/Select/Select.Skeleton.svelte b/src/components/Select/Select.Skeleton.svelte new file mode 100644 index 00000000..a8b3c90d --- /dev/null +++ b/src/components/Select/Select.Skeleton.svelte @@ -0,0 +1,19 @@ + + +
+ {#if !hideLabel} + + {/if} +
+
+
+
diff --git a/src/components/Select/Select.Story.svelte b/src/components/Select/Select.Story.svelte new file mode 100644 index 00000000..169f9e36 --- /dev/null +++ b/src/components/Select/Select.Story.svelte @@ -0,0 +1,29 @@ + + + +
+ {#if story === 'skeleton'} + + {:else} + + {/if} +
+
diff --git a/src/components/Select/Select.stories.js b/src/components/Select/Select.stories.js new file mode 100644 index 00000000..aa9ce3fd --- /dev/null +++ b/src/components/Select/Select.stories.js @@ -0,0 +1,36 @@ +import { withKnobs, text, boolean } from '@storybook/addon-knobs'; +import Component from './Select.Story.svelte'; + +export default { title: 'Select', decorators: [withKnobs] }; + +const labelPositions = { + 'Left (left)': 'left', + 'Right (right)': 'right' +}; + +export const Default = () => ({ + Component, + props: { + select: { + light: boolean('Light variant (light in )', false), + disabled: boolean('Disabled (disabled in )', false), + invalid: boolean('Show form validation UI (invalid in )', + 'A valid value is required' + ), + labelText: text('Label text (helperText)', 'Select'), + helperText: text('Helper text (helperText)', 'Optional helper text.') + }, + group: { + disabled: boolean('Disabled (disabled in )', false) + } + } +}); + +export const Skeleton = () => ({ + Component, + props: { story: 'skeleton', hideLabel: boolean('No label (hideLabel in { + selected.set(event.target.value); + }} + {id}> + + + + {#if invalid} + + {/if} +
+ {#if invalid} +
{invalidText}
+ {/if} +
+ {#if helperText} +
{helperText}
+ {/if} + {/if} + + {#if !inline} +
+ + + {#if invalid} + + {/if} +
+ {#if invalid} +
{invalidText}
+ {/if} + {/if} +
+
diff --git a/src/components/Select/SelectItem.svelte b/src/components/Select/SelectItem.svelte new file mode 100644 index 00000000..13d17f20 --- /dev/null +++ b/src/components/Select/SelectItem.svelte @@ -0,0 +1,19 @@ + + + diff --git a/src/components/Select/SelectItemGroup.svelte b/src/components/Select/SelectItemGroup.svelte new file mode 100644 index 00000000..af0ff642 --- /dev/null +++ b/src/components/Select/SelectItemGroup.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/src/components/Select/index.js b/src/components/Select/index.js new file mode 100644 index 00000000..b5ab0843 --- /dev/null +++ b/src/components/Select/index.js @@ -0,0 +1,6 @@ +import Select from './Select.svelte'; + +export default Select; +export { default as SelectSkeleton } from './Select.Skeleton.svelte'; +export { default as SelectItem } from './SelectItem.svelte'; +export { default as SelectItemGroup } from './SelectItemGroup.svelte'; diff --git a/src/index.js b/src/index.js index 035e6f83..948910bf 100644 --- a/src/index.js +++ b/src/index.js @@ -27,6 +27,7 @@ import ProgressIndicator, { import RadioButton, { RadioButtonSkeleton } from './components/RadioButton'; import RadioButtonGroup from './components/RadioButtonGroup'; import Search, { SearchSkeleton } from './components/Search'; +import Select, { SelectSkeleton, SelectItem, SelectItemGroup } from './components/Select'; import SkeletonPlaceholder from './components/SkeletonPlaceholder'; import SkeletonText from './components/SkeletonText'; import Tag, { TagSkeleton } from './components/Tag'; @@ -85,6 +86,10 @@ export { Search, SearchSkeleton, SelectableTile, + Select, + SelectSkeleton, + SelectItem, + SelectItemGroup, SkeletonPlaceholder, SkeletonText, Switch, From b8a5d7bdcc16a23f1d6d0d4a3c2d0409d736d8ae Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 21 Dec 2019 17:56:32 -0800 Subject: [PATCH 3/3] refactor(tooltip): forward events, remove external props Supports #7 --- .../TooltipDefinition/TooltipDefinition.Story.svelte | 4 +--- src/components/TooltipDefinition/TooltipDefinition.svelte | 4 ++-- src/components/TooltipIcon/TooltipIcon.svelte | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/TooltipDefinition/TooltipDefinition.Story.svelte b/src/components/TooltipDefinition/TooltipDefinition.Story.svelte index 41a65d14..dba89f2f 100644 --- a/src/components/TooltipDefinition/TooltipDefinition.Story.svelte +++ b/src/components/TooltipDefinition/TooltipDefinition.Story.svelte @@ -4,7 +4,5 @@ -
- Defintion Tooltip -
+ Defintion Tooltip
diff --git a/src/components/TooltipDefinition/TooltipDefinition.svelte b/src/components/TooltipDefinition/TooltipDefinition.svelte index 5fb18c33..848ed274 100644 --- a/src/components/TooltipDefinition/TooltipDefinition.svelte +++ b/src/components/TooltipDefinition/TooltipDefinition.svelte @@ -7,7 +7,7 @@ export let triggerClassName = undefined; export { triggerClassName as triggerClass }; export let tooltipText = ''; - export let props = {}; + export let style = undefined; import { cx } from '../../lib'; @@ -22,7 +22,7 @@ ); -
+