-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95722ee
commit 263e556
Showing
7 changed files
with
532 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './stepper' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { useState } from 'react' | ||
import { Story } from '@storybook/react/types-6-0' | ||
import { Box } from '../box' | ||
import { Button } from '../button' | ||
|
||
import { Stepper, StepsType, StepStatus } from './stepper' | ||
import { StepStatusEnum } from '.' | ||
|
||
export default { | ||
title: 'Stepper', | ||
component: Stepper, | ||
} | ||
|
||
const steps: StepsType[] = [ | ||
{ | ||
title: 'Step 1', | ||
description: ' This is step 1', | ||
}, | ||
{ | ||
title: 'Step 2', | ||
description: 'This is step 2.', | ||
}, | ||
{ | ||
title: 'Step 3', | ||
description: 'This is step 3.', | ||
}, | ||
{ | ||
title: 'Step 4', | ||
description: 'This is step 4.', | ||
}, | ||
{ | ||
title: 'Step 5', | ||
description: 'This is step 5.', | ||
}, | ||
] | ||
|
||
const rand = (range: number) => Math.trunc(Math.random() * 1000_000_000) % range | ||
const stepStates: StepStatusEnum[] = ['complete', 'error', 'warning'] | ||
|
||
const Template: Story = (args) => { | ||
const [step, setStep] = useState(1) | ||
const [stepsStatus, setStepsStatus] = useState<StepStatus>({}) | ||
|
||
const increaseStep = () => { | ||
if (step <= args.steps.length) { | ||
setStep(step + 1) | ||
setStepsStatus((prev) => ({ ...prev, [step]: 'complete' })) | ||
} | ||
} | ||
|
||
const decreaseStep = () => { | ||
if (step > 1) { | ||
setStep(step - 1) | ||
setStepsStatus((prev) => ({ | ||
...prev, | ||
[step - 1]: 'none', | ||
})) | ||
} | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Button color="info" variant="ghost" onClick={decreaseStep}> | ||
Decrease Step | ||
</Button> | ||
<Button | ||
csx={{ root: { margin: '0 0 1rem 1rem' } }} | ||
onClick={increaseStep} | ||
color="info" | ||
variant="ghost" | ||
> | ||
Increase Step | ||
</Button> | ||
|
||
<Stepper stepsStatus={stepsStatus} activeStep={step} {...args} /> | ||
</Box> | ||
) | ||
} | ||
|
||
const Template2: Story = (args) => { | ||
const [step, setStep] = useState(1) | ||
const [stepsStatus, setStepsStatus] = useState<StepStatus>({}) | ||
|
||
const increaseStep = () => { | ||
if (step <= args.steps.length) { | ||
setStep(step + 1) | ||
setStepsStatus((prev) => ({ ...prev, [step]: stepStates[rand(3)] })) | ||
} | ||
} | ||
|
||
const decreaseStep = () => { | ||
if (step > 1) { | ||
setStep(step - 1) | ||
setStepsStatus((prev) => ({ | ||
...prev, | ||
[step - 1]: 'none', | ||
})) | ||
} | ||
} | ||
|
||
return ( | ||
<Box> | ||
<Button color="info" variant="ghost" onClick={decreaseStep}> | ||
Decrease Step | ||
</Button> | ||
<Button | ||
csx={{ root: { margin: '0 0 1rem 1rem' } }} | ||
onClick={increaseStep} | ||
color="info" | ||
variant="ghost" | ||
> | ||
Increase Step | ||
</Button> | ||
|
||
<Stepper stepsStatus={stepsStatus} activeStep={step} {...args} /> | ||
</Box> | ||
) | ||
} | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
steps, | ||
color: 'secondary', | ||
} | ||
|
||
export const RandomStepStatus = Template2.bind({}) | ||
RandomStepStatus.args = { | ||
steps, | ||
color: 'secondary', | ||
} |
Oops, something went wrong.