Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime error in Slider storybook #2488

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: process value props to number[] or undefined
  • Loading branch information
nayounsang authored and yangwooseong committed Nov 12, 2024
commit e41a8821046ace502cf5d127cbd2c55f645f2f04
52 changes: 39 additions & 13 deletions packages/bezier-react/src/components/Slider/Slider.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type Meta } from '@storybook/react'
import React from 'react'

import { type Meta, type StoryFn } from '@storybook/react'

import { Slider } from './Slider'
import { type SliderProps } from './Slider.types'

const meta: Meta<typeof Slider> = {
component: Slider,
Expand All @@ -25,16 +28,39 @@ const meta: Meta<typeof Slider> = {
}
export default meta

export const Primary = {
args: {
width: 285,
defaultValue: [5],
value: undefined,
disabled: false,
guide: [5],
min: 0,
max: 10,
step: 1,
disableTooltip: false,
},
const Template: StoryFn<SliderProps> = (args) => {
const processedArgs = getProcessedArgs(args)
return <Slider {...processedArgs} />
}

export const Primary = Template.bind({})
Primary.args = {
width: 285,
defaultValue: [5],
value: undefined,
disabled: false,
guide: [5],
min: 0,
max: 10,
step: 1,
disableTooltip: false,
}

const getProcessedArgs = (args: SliderProps): SliderProps => {
return { ...args, value: getProcessedValue(args.value) }
}

const getProcessedValue = (
value: undefined | Record<number, number> | number[]
) => {
if (value === undefined) {
return undefined
}
if (Array.isArray(value) && value.every((item) => typeof item === 'number')) {
return value
}
if (typeof value === 'object' && value !== null) {
return Object.values(value)
}
return value
}