fix: unique key

pull/12097/head
AkaraChen 1 year ago
parent ab76266993
commit 6dc20ee809

@ -1,4 +1,4 @@
import type { FC } from 'react' import { type FC, Fragment } from 'react'
import type { Step } from './step' import type { Step } from './step'
import { StepperStep } from './step' import { StepperStep } from './step'
@ -7,28 +7,21 @@ export type StepperProps = {
activeIndex: number activeIndex: number
} }
function join<T, R = T>(array: T[], sep: R): Array<T | R> {
return array.reduce((acc, item, index) => {
if (index === 0)
return [item]
return acc.concat([sep, item])
}, [] as Array<T | R>)
}
export const Stepper: FC<StepperProps> = (props) => { export const Stepper: FC<StepperProps> = (props) => {
const { steps, activeIndex } = props const { steps, activeIndex } = props
return <div className='flex items-center gap-3'> return <div className='flex items-center gap-3'>
{join( {steps.map((step, index) => {
steps.map((step, index) => ( const isLast = index === steps.length - 1
return (
<Fragment key={index}>
<StepperStep <StepperStep
key={index}
{...step} {...step}
activeIndex={activeIndex} activeIndex={activeIndex}
index={index} index={index}
/> />
)), {!isLast && <div className="w-4 h-px bg-text-quaternary" />}
<div className="w-4 h-px bg-text-quaternary" />, </Fragment>
)} )
})}
</div> </div>
} }

Loading…
Cancel
Save