|
1 |
| -import { html } from 'lit'; |
| 1 | +import { html, nothing } from 'lit'; |
2 | 2 | import { type Meta } from '@storybook/web-components';
|
3 | 3 |
|
4 | 4 | import '@justeattakeaway/pie-select';
|
5 |
| -import { type SelectProps } from '@justeattakeaway/pie-select'; |
| 5 | +import { |
| 6 | + defaultProps, |
| 7 | + sizes, |
| 8 | + statusTypes, |
| 9 | + type SelectProps as SelectBaseProps, |
| 10 | +} from '@justeattakeaway/pie-select'; |
| 11 | +import '@justeattakeaway/pie-icons-webc/dist/IconPlaceholder.js'; |
| 12 | +import { ifDefined } from 'lit/directives/if-defined.js'; |
6 | 13 |
|
7 |
| -import { createStory } from '../utilities'; |
| 14 | +import { createStory, type TemplateFunction } from '../utilities'; |
8 | 15 |
|
| 16 | +type SelectProps = SelectBaseProps & { showLeadingIcon: boolean }; |
9 | 17 | type SelectStoryMeta = Meta<SelectProps>;
|
10 | 18 |
|
11 |
| -const defaultArgs: SelectProps = {}; |
| 19 | +const defaultArgs: SelectProps = { |
| 20 | + ...defaultProps, |
| 21 | + name: 'testName', |
| 22 | + showLeadingIcon: false, |
| 23 | +}; |
12 | 24 |
|
13 | 25 | const selectStoryMeta: SelectStoryMeta = {
|
14 | 26 | title: 'Select',
|
15 | 27 | component: 'pie-select',
|
16 |
| - argTypes: {}, |
| 28 | + argTypes: { |
| 29 | + name: { |
| 30 | + description: 'The name of the select (used as a key/value pair with `value`). This is required in order to work properly with forms.', |
| 31 | + control: 'text', |
| 32 | + defaultValue: { |
| 33 | + summary: defaultArgs.name, |
| 34 | + }, |
| 35 | + }, |
| 36 | + disabled: { |
| 37 | + description: 'If true, disables the select field.', |
| 38 | + control: 'boolean', |
| 39 | + defaultValue: { |
| 40 | + summary: defaultProps.disabled, |
| 41 | + }, |
| 42 | + }, |
| 43 | + size: { |
| 44 | + description: 'The size of the select field. Can be `small`, `medium` or `large`. Defaults to `medium`.', |
| 45 | + control: 'select', |
| 46 | + options: sizes, |
| 47 | + defaultValue: { |
| 48 | + summary: defaultProps.size, |
| 49 | + }, |
| 50 | + }, |
| 51 | + assistiveText: { |
| 52 | + description: 'An optional assistive text to display below the select element. Must be provided when the status is success or error.', |
| 53 | + control: 'text', |
| 54 | + defaultValue: { |
| 55 | + summary: '', |
| 56 | + }, |
| 57 | + }, |
| 58 | + status: { |
| 59 | + description: 'The status of the select component / assistive text. Can be default or error.', |
| 60 | + control: 'select', |
| 61 | + options: statusTypes, |
| 62 | + defaultValue: { |
| 63 | + summary: defaultProps.status, |
| 64 | + }, |
| 65 | + }, |
| 66 | + showLeadingIcon: { |
| 67 | + description: '<b>**Not a component prop</b><br><br>Use the `leadingIcon` slot to pass a PIE icon component.', |
| 68 | + control: 'boolean', |
| 69 | + defaultValue: { |
| 70 | + summary: defaultArgs.showLeadingIcon, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }, |
17 | 74 | args: defaultArgs,
|
18 | 75 | parameters: {
|
19 | 76 | design: {
|
20 | 77 | type: 'figma',
|
21 |
| - url: '', |
| 78 | + url: 'https://www.figma.com/design/pPSC73rPin4csb8DiK1CRr/branch/7dcPx40PggJCudTmgHwlk6/%E2%9C%A8-%5BCore%5D-Web-Components-%5BPIE-3%5D?node-id=1573-114525&p=f&m=dev', |
22 | 79 | },
|
23 | 80 | },
|
24 | 81 | };
|
25 | 82 |
|
26 | 83 | export default selectStoryMeta;
|
27 | 84 |
|
28 |
| -// TODO: remove the eslint-disable rule when props are added |
29 |
| -// eslint-disable-next-line no-empty-pattern |
30 |
| -const Template = ({}: SelectProps) => html` |
31 |
| - <pie-select></pie-select> |
32 |
| -`; |
| 85 | +const Template = ({ |
| 86 | + disabled, |
| 87 | + size, |
| 88 | + assistiveText, |
| 89 | + status, |
| 90 | + name, |
| 91 | + showLeadingIcon, |
| 92 | +}: SelectProps) => html` |
| 93 | + <pie-select |
| 94 | + id="${ifDefined(name)}" |
| 95 | + name="${ifDefined(name)}" |
| 96 | + ?disabled="${disabled}" |
| 97 | + size="${ifDefined(size)}" |
| 98 | + assistiveText="${ifDefined(assistiveText)}" |
| 99 | + status=${ifDefined(status)}> |
| 100 | + ${showLeadingIcon ? html`<icon-placeholder slot="leadingIcon"></icon-placeholder>` : nothing} |
| 101 | + </pie-select> |
| 102 | + `; |
| 103 | + |
| 104 | +const WithLabelTemplate: TemplateFunction<SelectProps> = (props: SelectProps) => html` |
| 105 | + <p>Please note, the label is a separate component. See <pie-link href="/?path=/story/form-label">pie-form-label</pie-link>.</p> |
| 106 | + <pie-form-label for="${ifDefined(props.name)}">Label</pie-form-label> |
| 107 | + ${Template(props)} |
| 108 | + `; |
33 | 109 |
|
34 | 110 | export const Default = createStory<SelectProps>(Template, defaultArgs)();
|
| 111 | +export const Labelled = createStory<SelectProps>(WithLabelTemplate, defaultArgs)(); |
0 commit comments