From 4d34736882936c78cee7f130cec213a35f10d1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yigit=2C=20=C3=96zlem=20=28UIT=29?= Date: Mon, 9 Oct 2023 16:24:15 +0200 Subject: [PATCH] feat: Edit story --- .../radio-group/radio-group.stories.ts | 152 ++++++++++++++---- 1 file changed, 125 insertions(+), 27 deletions(-) diff --git a/packages/components/src/components/radio-group/radio-group.stories.ts b/packages/components/src/components/radio-group/radio-group.stories.ts index a2f97faef..b6e5fc476 100644 --- a/packages/components/src/components/radio-group/radio-group.stories.ts +++ b/packages/components/src/components/radio-group/radio-group.stories.ts @@ -1,5 +1,8 @@ import '../../solid-components'; +import { html } from 'lit-html'; import { storybookDefaults, storybookHelpers, storybookTemplate } from '../../../scripts/storybook/helper'; +import { userEvent } from '@storybook/testing-library'; +import { waitUntil } from '@open-wc/testing-helpers'; const { argTypes, parameters } = storybookDefaults('sd-radio-group'); const { generateTemplate } = storybookTemplate('sd-radio-group'); @@ -18,16 +21,22 @@ export default { args: overrideArgs([ { type: 'slot', - name: 'default', - value: - 'Option 1Option 2Option 3' + name: 'label', + value: ` + + ` }, - { type: 'attribute', name: 'name', value: 'radio-group' }, { type: 'slot', - name: 'label', - value: '' - } + name: 'default', + value: ` + Option 1 + Option 2 + Option 3 + ` + }, + { type: 'attribute', name: 'name', value: 'radio-group' }, + { type: 'attribute', name: 'value', value: '2' } ]), argTypes }; @@ -42,28 +51,54 @@ export const Default = { } }; +/** + * The sd-radio in all possible combinations of `orientation` and `size`. + */ + +export const Orientation = { + parameters: { controls: { exclude: ['orientation', 'size', 'default'] } }, + render: (args: any) => { + return generateTemplate({ + axis: { + x: { type: 'attribute', name: 'orientation' }, + y: { type: 'attribute', name: 'size' } + }, + args + }); + } +}; + /** * Use the disabled attribute to disable a input radio. Clicks will be suppressed until the disabled state is removed */ -export const DisabledAndSize = { - name: 'Disabled × Size', - parameters: { controls: { exclude: ['disabled', 'size', 'default'] } }, +export const Disabled = { + name: 'Disabled x Size', + parameters: { controls: { exclude: ['size', 'default'] } }, render: (args: any) => { return generateTemplate({ axis: { - x: { - type: 'attribute', - name: 'disabled', - values: [false, true] - }, - y: { - type: 'attribute', - name: 'size', - values: ['sm', 'lg'] - } + x: [ + { + type: 'slot', + name: 'default', + title: 'disabled', + values: [ + { + value: + 'Option 1Option 2Option 3', + title: 'true' + }, + { + value: + 'Option 1Option 2Option 3', + title: 'false' + } + ] + } + ], + y: { type: 'attribute', name: 'size' } }, - constants: { type: 'attribute', name: 'disabled', value: true }, args }); } @@ -74,17 +109,80 @@ export const DisabledAndSize = { */ export const Invalid = { - parameters: { controls: { exclude: ['invalid', 'disabled', 'size'] } }, + parameters: { controls: { exclude: ['invalid', 'size', 'error-text'] } }, render: (args: any) => { return generateTemplate({ axis: { - y: [ - { type: 'attribute', name: 'size' }, - { type: 'attribute', name: 'disabled', values: [false, true] } - ] + y: [{ type: 'attribute', name: 'size' }] }, - constants: { type: 'attribute', name: 'invalid', value: true }, + constants: [ + { type: 'attribute', name: 'invalid', value: true }, + { type: 'attribute', name: 'error-text', value: 'Error message' } + ], args }); } }; + +/** + * Use the `required` attribute to mark the element as required. This can be used for form validation purposes. + */ + +export const Required = { + parameters: { controls: { exclude: ['required'] } }, + render: (args: any) => { + return generateTemplate({ + axis: { + x: [{ type: 'attribute', name: 'size' }], + y: { type: 'attribute', name: 'required' } + }, + args + }); + } +}; + +/** + * Use the `form-control`, `form-control-label`, `form-control-input` and `form-control-error-text` part selectors to customize the radio-group. + */ +export const Parts = { + parameters: { + controls: { exclude: ['form-control', 'form-control-label', 'form-control-input', 'form-control-error-text'] } + }, + render: (args: any) => { + return generateTemplate({ + axis: { + y: { + type: 'template', + name: 'sd-radio-group::part(...){outline: solid 2px red}', + values: ['form-control', 'form-control-label', 'form-control-input', 'form-control-error-text'].map(part => { + return { + title: part, + value: `
%TEMPLATE%
` + }; + }) + } + }, + constants: [ + { type: 'template', name: 'width', value: '
%TEMPLATE%
' }, + { type: 'attribute', name: 'error-text', value: 'Error message' } + ], + args + }); + } +}; + +/** + * sd-radio-group are fully accessibile via keyboard. + */ +export const Mouseless = { + render: (args: any) => { + return html`
${generateTemplate({ args })}
`; + }, + + play: async ({ canvasElement }: { canvasElement: HTMLUnknownElement }) => { + const el = canvasElement.querySelector('.mouseless sd-radio-group'); + await waitUntil(() => el?.shadowRoot?.querySelector('label')); + // We have to catch the event as otherwise Storybook will break + await userEvent.type(el!.shadowRoot!.querySelector('label')!, '{return}', { pointerEventsCheck: 0 }); + } +};