Skip to content

Commit

Permalink
docs(stepper): improve stories
Browse files Browse the repository at this point in the history
  • Loading branch information
acd02 committed Nov 6, 2024
1 parent 2737a85 commit 4e446a1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
12 changes: 12 additions & 0 deletions packages/components/stepper/src/Stepper.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ import { Stepper } from '@spark-ui/stepper'

<Canvas of={stories.Default} />

### Uncontrolled

Use `defaultValue` prop to set the default value of the stepper. Optionally `onChange` prop can be used to know when the value of the stepper changes.

<Canvas of={stories.Uncontrolled} />

### Controlled

Use `value` and `onChange` props to control the value of the input.

<Canvas of={stories.Controlled} />

### Disabled

Use `disabled` prop to indicate that the stepper is disabled and not interactive.
Expand Down
45 changes: 38 additions & 7 deletions packages/components/stepper/src/Stepper.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Icon } from '@spark-ui/icon'
import { ArrowHorizontalDown } from '@spark-ui/icons/dist/icons/ArrowHorizontalDown'
import { ArrowHorizontalUp } from '@spark-ui/icons/dist/icons/ArrowHorizontalUp'
import { Meta, StoryFn } from '@storybook/react'
import { useState } from 'react'

import { Stepper, StepperProps } from '.'

Expand All @@ -16,13 +17,43 @@ export default meta

const states: StepperProps['state'][] = ['error', 'alert', 'success']

export const Default: StoryFn = _args => (
<Stepper aria-label="Default stepper">
<Stepper.DecrementButton aria-label="Decrement" />
<Stepper.Input />
<Stepper.IncrementButton aria-label="Increment" />
</Stepper>
)
export const Default: StoryFn = _args => {
return (
<Stepper aria-label="Default stepper">
<Stepper.DecrementButton aria-label="Decrement" />
<Stepper.Input />
<Stepper.IncrementButton aria-label="Increment" />
</Stepper>
)
}

export const Uncontrolled: StoryFn = () => {
return (
<Stepper
defaultValue={0}
onChange={v => {
console.log(v)
}}
aria-label="Default stepper"
>
<Stepper.DecrementButton aria-label="Decrement" />
<Stepper.Input />
<Stepper.IncrementButton aria-label="Increment" />
</Stepper>
)
}

export const Controlled: StoryFn = () => {
const [count, setCount] = useState(0)

return (
<Stepper value={count} onChange={setCount} aria-label="Default stepper">
<Stepper.DecrementButton aria-label="Decrement" />
<Stepper.Input />
<Stepper.IncrementButton aria-label="Increment" />
</Stepper>
)
}

export const Disabled: StoryFn = _args => (
<Stepper aria-label="Disabled stepper" disabled onChange={() => console.log('disabled')}>
Expand Down

0 comments on commit 4e446a1

Please sign in to comment.