feat: create top bar

This commit is contained in:
AkaraChen
2024-11-21 16:19:32 +08:00
parent 13c62f83f4
commit fdcee1cd45
6 changed files with 112 additions and 38 deletions

View File

@ -0,0 +1,34 @@
import type { FC } from 'react'
import type { Step } from './step'
import { StepperStep } from './step'
export type StepperProps = {
steps: Step[]
activeStepIndex: 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) => {
const { steps, activeStepIndex } = props
return <div className='flex items-center gap-3'>
{join(
steps.map((step, index) => (
<StepperStep
key={index}
{...step}
isActive={index === activeStepIndex}
index={index}
/>
)),
<div className="w-4 h-px bg-[#101828]/30" />,
)}
</div>
}

View File

@ -0,0 +1,33 @@
import type { FC } from 'react'
import classNames from '@/utils/classnames'
export type Step = {
name: string
}
export type StepperStepProps = Step & {
index: number
isActive: boolean
}
export const StepperStep: FC<StepperStepProps> = (props) => {
const { name, isActive, index } = props
const label = isActive ? `STEP ${index + 1}` : `${index + 1}`
return <div className='flex items-center gap-2'>
<div className={classNames(
'h-5 px-2 py-1 rounded-3xl flex-col justify-center items-center gap-2 inline-flex',
isActive ? 'bg-[#296cff]' : 'border border-[#101828]/30',
)}>
<div className={classNames(
'text-center text-[10px] font-semibold uppercase leading-3',
isActive ? 'text-white' : 'text-[#676f83]',
)}>
{label}
</div>
</div>
<div className={classNames(
' text-xs font-medium uppercase leading-none',
isActive ? 'text-[#155aef]' : 'text-[#676f83]',
)}>{name}</div>
</div>
}