Skip to content

Commit 40fc02f

Browse files
committed
feat: implement Sidebar usage on Simple playground example.
1 parent dab1824 commit 40fc02f

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

playground/components/asyncStep.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useMockMutation } from '../hooks';
66

77
type Props = {
88
number: number;
9+
name?: string;
910
};
1011

1112
const MOCK = [

playground/components/sidebar.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { styled } from 'goober';
2+
import * as React from 'react';
3+
4+
import { useWizard } from '../../dist';
5+
import { Button } from '../modules/common';
6+
7+
export const Nav = styled('nav')`
8+
display: flex;
9+
justify-content: center;
10+
flex-direction: column;
11+
gap: 0;
12+
13+
& > ul {
14+
list-style: none;
15+
margin: 0;
16+
padding: 0;
17+
}
18+
19+
@media screen and (min-width: 768px) {
20+
flex-direction: row;
21+
gap: 1rem;
22+
23+
& > p {
24+
margin: initial;
25+
}
26+
}
27+
`;
28+
29+
const Sidebar: React.FC = () => {
30+
const { activeStep, stepCount, goToStep, stepNames } = useWizard();
31+
32+
return (
33+
<Nav>
34+
{stepCount > 0 && (
35+
<ul>
36+
{stepNames.map((stepName, index) => (
37+
<li key={index}>
38+
<Button
39+
label={stepName.name}
40+
onClick={() => goToStep(stepName.number - 1)}
41+
disabled={stepName.number - 1 > activeStep}
42+
>
43+
{stepName.name}
44+
</Button>
45+
</li>
46+
))}
47+
</ul>
48+
)}
49+
</Nav>
50+
);
51+
};
52+
53+
export default Sidebar;

playground/components/step.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useWizard } from '../../dist';
66
type Props = {
77
number: number;
88
withCallback?: boolean;
9+
name?: string;
910
};
1011

1112
const Container = styled('div')`

playground/modules/wizard/simple/index.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
import { styled } from 'goober';
12
import * as React from 'react';
23

34
import { Wizard } from '../../../../dist';
45
import { AsyncStep, Footer, Step } from '../../../components';
6+
import Sidebar from '../../../components/sidebar';
57
import Section from '../../common/section';
68

9+
const Flex = styled('div')`
10+
display: flex;
11+
width: 100%;
12+
gap: 1rem;
13+
14+
& > :nth-child(2) {
15+
flex-grow: 1;
16+
}
17+
`;
18+
719
const SimpleSection: React.FC = () => {
820
return (
921
<Section title="Simple wizard" description="mix of async and sync steps">
1022
<Wizard
1123
footer={<Footer />}
24+
sidebar={<Sidebar />}
1225
onStepChange={(stepIndex) => alert(`New step index is ${stepIndex}`)}
26+
sidebarAndStepWrapper={<Flex />}
1327
>
14-
<AsyncStep number={1} />
15-
<Step number={2} />
16-
<AsyncStep number={3} />
17-
<Step number={4} />
28+
<AsyncStep number={1} name="Async Step 1" />
29+
<Step number={2} name="Step 2" />
30+
<AsyncStep number={3} name="Async Step 3" />
31+
<Step number={4} name="Step 4" />
1832
</Wizard>
1933
</Section>
2034
);

0 commit comments

Comments
 (0)