|
1 |
| -import React, { useState } from 'react'; |
2 |
| -import { |
3 |
| - storybookArgTypes, |
4 |
| - StoryMetaType, |
5 |
| - StoryType, |
6 |
| -} from '@lg-tools/storybook-utils'; |
| 1 | +import React from 'react'; |
| 2 | +import { StoryMetaType } from '@lg-tools/storybook-utils'; |
| 3 | +import { StoryObj } from '@storybook/react'; |
7 | 4 |
|
8 |
| -import { WizardFooter } from '.'; |
| 5 | +import { Variant } from '@leafygreen-ui/button'; |
| 6 | +import Icon, { glyphs } from '@leafygreen-ui/icon'; |
9 | 7 |
|
10 |
| -const meta: StoryMetaType<typeof WizardFooter> = { |
| 8 | +import { WizardFooter, type WizardFooterProps } from '.'; |
| 9 | + |
| 10 | +type PrimaryButtonVariant = |
| 11 | + Required<WizardFooterProps>['primaryButtonProps']['variant']; |
| 12 | +interface StoryArgs { |
| 13 | + backButtonText: string; |
| 14 | + backButtonIcon: keyof typeof glyphs; |
| 15 | + cancelButtonText: string; |
| 16 | + primaryButtonText: string; |
| 17 | + primaryButtonIcon: keyof typeof glyphs; |
| 18 | + primaryButtonVariant: PrimaryButtonVariant; |
| 19 | +} |
| 20 | + |
| 21 | +const meta: StoryMetaType<typeof WizardFooter, StoryArgs> = { |
11 | 22 | title: 'Components/Wizard/WizardFooter',
|
12 | 23 | component: WizardFooter,
|
13 | 24 | parameters: {
|
14 | 25 | default: 'LiveExample',
|
| 26 | + controls: { |
| 27 | + exclude: ['backButtonProps', 'cancelButtonProps', 'primaryButtonProps'], |
| 28 | + }, |
15 | 29 | },
|
| 30 | + args: {}, |
16 | 31 | argTypes: {
|
17 |
| - backButtonProps: { control: 'object' }, |
18 |
| - cancelButtonProps: { control: 'object' }, |
19 |
| - primaryButtonProps: { control: 'object' }, |
20 |
| - activeStep: { control: 'number' }, |
21 |
| - totalSteps: { control: 'number' }, |
22 |
| - onStepChange: storybookArgTypes.func, |
23 |
| - isControlled: { control: 'boolean' }, |
| 32 | + backButtonText: { control: 'text' }, |
| 33 | + backButtonIcon: { control: 'select', options: Object.keys(glyphs) }, |
| 34 | + cancelButtonText: { control: 'text' }, |
| 35 | + primaryButtonText: { control: 'text' }, |
| 36 | + primaryButtonIcon: { control: 'select', options: Object.keys(glyphs) }, |
| 37 | + primaryButtonVariant: { |
| 38 | + control: 'select', |
| 39 | + options: [Variant.Primary, Variant.Danger], |
| 40 | + }, |
24 | 41 | },
|
25 | 42 | };
|
26 | 43 |
|
27 | 44 | export default meta;
|
28 | 45 |
|
29 |
| -const Template: StoryType<typeof WizardFooter> = args => { |
30 |
| - const [step, setStep] = useState(args.activeStep || 0); |
31 |
| - |
32 |
| - return ( |
| 46 | +export const LiveExample: StoryObj<StoryArgs> = { |
| 47 | + args: { |
| 48 | + backButtonText: 'Back', |
| 49 | + backButtonIcon: 'ArrowLeft', |
| 50 | + cancelButtonText: 'Cancel', |
| 51 | + primaryButtonText: 'Continue', |
| 52 | + primaryButtonIcon: 'Ellipsis', |
| 53 | + primaryButtonVariant: Variant.Primary, |
| 54 | + }, |
| 55 | + render: args => ( |
33 | 56 | <WizardFooter
|
34 |
| - {...args} |
35 |
| - activeStep={step} |
36 |
| - onStepChange={newStep => { |
37 |
| - setStep(newStep); |
38 |
| - args.onStepChange?.(newStep); |
| 57 | + backButtonProps={{ |
| 58 | + leftGlyph: args.backButtonIcon ? ( |
| 59 | + <Icon glyph={args.backButtonIcon} /> |
| 60 | + ) : undefined, |
| 61 | + children: args.backButtonText, |
| 62 | + }} |
| 63 | + cancelButtonProps={{ |
| 64 | + children: args.cancelButtonText, |
| 65 | + }} |
| 66 | + primaryButtonProps={{ |
| 67 | + leftGlyph: args.primaryButtonIcon ? ( |
| 68 | + <Icon glyph={args.primaryButtonIcon} /> |
| 69 | + ) : undefined, |
| 70 | + children: args.primaryButtonText, |
| 71 | + variant: args.primaryButtonVariant, |
39 | 72 | }}
|
40 | 73 | />
|
41 |
| - ); |
42 |
| -}; |
43 |
| - |
44 |
| -export const LiveExample = Template.bind({}); |
45 |
| -LiveExample.args = { |
46 |
| - activeStep: 1, |
47 |
| - totalSteps: 3, |
48 |
| - backButtonProps: { |
49 |
| - children: 'Back', |
50 |
| - }, |
51 |
| - cancelButtonProps: { |
52 |
| - children: 'Cancel', |
53 |
| - }, |
54 |
| - primaryButtonProps: { |
55 |
| - children: 'Next', |
56 |
| - variant: 'primary', |
57 |
| - }, |
58 |
| -}; |
59 |
| - |
60 |
| -export const FirstStep = Template.bind({}); |
61 |
| -FirstStep.args = { |
62 |
| - activeStep: 0, |
63 |
| - totalSteps: 3, |
64 |
| - cancelButtonProps: { |
65 |
| - children: 'Cancel', |
66 |
| - }, |
67 |
| - primaryButtonProps: { |
68 |
| - children: 'Get Started', |
69 |
| - variant: 'primary', |
70 |
| - }, |
71 |
| -}; |
72 |
| - |
73 |
| -export const LastStep = Template.bind({}); |
74 |
| -LastStep.args = { |
75 |
| - activeStep: 2, |
76 |
| - totalSteps: 3, |
77 |
| - backButtonProps: { |
78 |
| - children: 'Back', |
79 |
| - }, |
80 |
| - cancelButtonProps: { |
81 |
| - children: 'Cancel', |
82 |
| - }, |
83 |
| - primaryButtonProps: { |
84 |
| - children: 'Finish', |
85 |
| - variant: 'primary', |
86 |
| - }, |
87 |
| -}; |
88 |
| - |
89 |
| -export const DangerousAction = Template.bind({}); |
90 |
| -DangerousAction.args = { |
91 |
| - activeStep: 1, |
92 |
| - totalSteps: 2, |
93 |
| - backButtonProps: { |
94 |
| - children: 'Back', |
95 |
| - }, |
96 |
| - cancelButtonProps: { |
97 |
| - children: 'Cancel', |
98 |
| - }, |
99 |
| - primaryButtonProps: { |
100 |
| - children: 'Delete Resource', |
101 |
| - variant: 'danger', |
102 |
| - }, |
103 |
| -}; |
104 |
| - |
105 |
| -export const WithCustomHandlers = Template.bind({}); |
106 |
| -WithCustomHandlers.args = { |
107 |
| - activeStep: 1, |
108 |
| - totalSteps: 3, |
109 |
| - backButtonProps: { |
110 |
| - children: 'Go Back', |
111 |
| - onClick: () => alert('Custom back handler'), |
112 |
| - }, |
113 |
| - cancelButtonProps: { |
114 |
| - children: 'Exit', |
115 |
| - onClick: () => alert('Custom cancel handler'), |
116 |
| - }, |
117 |
| - primaryButtonProps: { |
118 |
| - children: 'Continue', |
119 |
| - variant: 'primary', |
120 |
| - onClick: () => alert('Custom primary handler'), |
121 |
| - }, |
122 |
| -}; |
123 |
| - |
124 |
| -export const MinimalFooter = Template.bind({}); |
125 |
| -MinimalFooter.args = { |
126 |
| - activeStep: 0, |
127 |
| - totalSteps: 1, |
128 |
| - primaryButtonProps: { |
129 |
| - children: 'Done', |
130 |
| - variant: 'primary', |
131 |
| - }, |
| 74 | + ), |
132 | 75 | };
|
0 commit comments