Skip to content

Commit 2db2824

Browse files
committed
fix: refactoring and story changes
1 parent 3e0a9d3 commit 2db2824

File tree

3 files changed

+106
-98
lines changed

3 files changed

+106
-98
lines changed

packages/react/src/stepper/MdStepper.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ const MdStepper: React.FunctionComponent<MdStepperProps> = ({ activeStep, childr
2727

2828
export default MdStepper;
2929

30-
type StepTitleProps = {
30+
interface StepTitleProps {
3131
title: string;
3232
index: number;
3333
activeStep: number;
34-
};
34+
}
3535

36-
function StepTitle({ title, index, activeStep }: StepTitleProps) {
36+
const StepTitle = ({ title, index, activeStep }: StepTitleProps) => {
3737
if (index === activeStep) {
3838
// Step selected
3939
return (
@@ -67,16 +67,16 @@ function StepTitle({ title, index, activeStep }: StepTitleProps) {
6767
</div>
6868
);
6969
}
70-
}
70+
};
7171

72-
type StepContentProps = {
72+
interface StepContentProps {
7373
index: number;
7474
activeStep: number;
7575
completedContent?: React.ReactNode;
7676
children: React.ReactNode;
77-
};
77+
}
7878

79-
function StepContent({ index, activeStep, completedContent, children }: StepContentProps) {
79+
const StepContent = ({ index, activeStep, completedContent, children }: StepContentProps) => {
8080
if (index === activeStep) {
8181
return (
8282
<div className="md-stepper__step-content-container">
@@ -103,4 +103,4 @@ function StepContent({ index, activeStep, completedContent, children }: StepCont
103103
</div>
104104
);
105105
}
106-
}
106+
};

stories/StepperStories/Stepper.stories.tsx renamed to stories/Stepper.stories.tsx

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Title, Subtitle, Description, Controls, Primary, Markdown } from '@stor
22
import { useArgs } from '@storybook/client-api';
33
import React from 'react';
44

5-
import Readme from '../../packages/css/src/stepper/README.md';
6-
import MdButton from '../../packages/react/src/button/MdButton';
7-
import MdStep from '../../packages/react/src/stepper/MdStep';
8-
import MdStepper from '../../packages/react/src/stepper/MdStepper';
5+
import Readme from '../packages/css/src/stepper/README.md';
6+
import MdButton from '../packages/react/src/button/MdButton';
7+
import MdStep from '../packages/react/src/stepper/MdStep';
8+
import MdStepper from '../packages/react/src/stepper/MdStepper';
99
import type { Args, StoryFn } from '@storybook/react';
1010

1111
export default {
@@ -27,7 +27,7 @@ export default {
2727
},
2828
description: {
2929
// eslint-disable-next-line quotes
30-
component: "Stepper component.<br/><br/>`import { MdStepper } from '@miljodirektoratet/md-react'`",
30+
component: "Stepper component.<br/><br/>`import { MdStepper, MdStep } from '@miljodirektoratet/md-react'`",
3131
},
3232
},
3333
},
@@ -53,9 +53,101 @@ export default {
5353
},
5454
control: { type: 'ReactNode' },
5555
},
56+
MdStep_title: {
57+
type: { name: 'string' },
58+
description: 'Arg for MdStep. The title of the step.',
59+
table: {
60+
type: {
61+
summary: 'string',
62+
},
63+
},
64+
control: { type: 'string' },
65+
},
66+
MdStep_completedContent: {
67+
type: { name: 'ReactNode' },
68+
description: 'Arg for MdStep. The content to show when the step is completed. This is optional',
69+
table: {
70+
type: {
71+
summary: 'ReactNode',
72+
},
73+
},
74+
control: { type: 'ReactNode' },
75+
},
76+
MdStep_children: {
77+
type: { name: 'ReactNode' },
78+
description: 'Arg for MdStep. The content of the step.',
79+
table: {
80+
type: {
81+
summary: 'ReactNode',
82+
},
83+
},
84+
control: { type: 'ReactNode' },
85+
},
5686
},
5787
};
5888

89+
export const Stepper: StoryFn<typeof MdStepper> = (args: Args) => {
90+
const [, updateArgs] = useArgs();
91+
92+
const nextStep = () => {
93+
updateArgs({ activeStep: args.activeStep + 1 });
94+
};
95+
96+
const prevStep = () => {
97+
updateArgs({ activeStep: args.activeStep - 1 });
98+
};
99+
100+
return (
101+
<>
102+
<MdStepper activeStep={args.activeStep}>
103+
<MdStep
104+
title="Step 1"
105+
completedContent={
106+
<>
107+
This is a completed step, which can be shown differently if the &quot;completedContent&quot; prop is
108+
provided
109+
</>
110+
}
111+
>
112+
<div>
113+
This is a step
114+
<MdButton onClick={nextStep} small>
115+
Next
116+
</MdButton>
117+
</div>
118+
</MdStep>
119+
<MdStep
120+
title="Step 2"
121+
completedContent={<>This is what Step 2 looks like when completed, this is completely customizable!</>}
122+
>
123+
<div>
124+
This is the content of a MdStep. It can contain anything you want, text or HTML.
125+
<p>Here is a paragraph!</p>
126+
<MdButton onClick={nextStep} small>
127+
Next
128+
</MdButton>
129+
<MdButton onClick={prevStep} theme="secondary" small>
130+
Previous
131+
</MdButton>
132+
</div>
133+
</MdStep>
134+
<MdStep title="Step 3">
135+
<div>
136+
This is the last step in this example
137+
<MdButton onClick={prevStep} theme="secondary" small>
138+
Previous
139+
</MdButton>
140+
</div>
141+
</MdStep>
142+
</MdStepper>
143+
</>
144+
);
145+
};
146+
Stepper.args = {
147+
activeStep: 1,
148+
};
149+
150+
/*
59151
const Template: StoryFn<typeof MdStepper> = (args: Args) => {
60152
const [, updateArgs] = useArgs();
61153
@@ -117,4 +209,4 @@ const Template: StoryFn<typeof MdStepper> = (args: Args) => {
117209
export const Stepper = Template.bind({});
118210
Stepper.args = {
119211
activeStep: 1,
120-
};
212+
}; */

stories/StepperStories/Step.stories.tsx

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)