Skip to content

Commit ca28900

Browse files
committed
update Footer
1 parent e578be0 commit ca28900

File tree

3 files changed

+61
-175
lines changed

3 files changed

+61
-175
lines changed
Lines changed: 58 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,75 @@
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';
74

8-
import { WizardFooter } from '.';
5+
import { Variant } from '@leafygreen-ui/button';
6+
import Icon, { glyphs } from '@leafygreen-ui/icon';
97

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> = {
1122
title: 'Components/Wizard/WizardFooter',
1223
component: WizardFooter,
1324
parameters: {
1425
default: 'LiveExample',
26+
controls: {
27+
exclude: ['backButtonProps', 'cancelButtonProps', 'primaryButtonProps'],
28+
},
1529
},
30+
args: {},
1631
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+
},
2441
},
2542
};
2643

2744
export default meta;
2845

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 => (
3356
<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,
3972
}}
4073
/>
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+
),
13275
};

packages/wizard/src/WizardFooter/WizardFooter.tsx

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,14 @@ export function WizardFooter({
88
backButtonProps,
99
cancelButtonProps,
1010
primaryButtonProps,
11-
activeStep = 0,
12-
totalSteps = 1,
13-
onStepChange,
14-
isControlled: _isControlled,
1511
}: WizardFooterProps) {
1612
// Handle back button click
17-
const handleBackClick = () => {
18-
if (activeStep > 0) {
19-
onStepChange?.(activeStep - 1);
20-
}
21-
};
22-
23-
// Handle primary button click (forward navigation)
24-
const handlePrimaryClick = () => {
25-
if (activeStep < totalSteps - 1) {
26-
onStepChange?.(activeStep + 1);
27-
}
28-
};
29-
30-
// Merge navigation handlers with user-provided props
31-
const mergedBackButtonProps = backButtonProps
32-
? {
33-
...backButtonProps,
34-
onClick: (event: React.MouseEvent<HTMLButtonElement>) => {
35-
backButtonProps.onClick?.(event);
36-
if (!event.defaultPrevented) {
37-
handleBackClick();
38-
}
39-
},
40-
}
41-
: undefined;
42-
43-
const mergedPrimaryButtonProps = primaryButtonProps
44-
? {
45-
...primaryButtonProps,
46-
onClick: (event: React.MouseEvent<HTMLButtonElement>) => {
47-
primaryButtonProps.onClick?.(event);
48-
if (!event.defaultPrevented) {
49-
handlePrimaryClick();
50-
}
51-
},
52-
}
53-
: undefined;
54-
55-
// Hide back button if we're on the first step
56-
const finalBackButtonProps =
57-
activeStep === 0 ? undefined : mergedBackButtonProps;
5813

5914
return (
6015
<FormFooter
61-
backButtonProps={finalBackButtonProps}
16+
backButtonProps={backButtonProps}
6217
cancelButtonProps={cancelButtonProps}
63-
primaryButtonProps={
64-
mergedPrimaryButtonProps || { children: 'Next', variant: 'primary' }
65-
}
18+
primaryButtonProps={primaryButtonProps}
6619
/>
6720
);
6821
}

packages/wizard/src/WizardFooter/WizardFooter.types.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,5 @@ export interface WizardFooterProps {
1414
/**
1515
* Props for the primary button (right-most button)
1616
*/
17-
primaryButtonProps?: FormFooterProps['primaryButtonProps'];
18-
19-
// Internal props passed by the Wizard component
20-
/** @internal */
21-
activeStep?: number;
22-
/** @internal */
23-
totalSteps?: number;
24-
/** @internal */
25-
onStepChange?: (step: number) => void;
26-
/** @internal */
27-
isControlled?: boolean;
17+
primaryButtonProps: FormFooterProps['primaryButtonProps'];
2818
}

0 commit comments

Comments
 (0)