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,