|
| 1 | +import React, { type FC } from 'react' |
| 2 | +import { tv } from 'tailwind-variants' |
| 3 | + |
| 4 | +import { Heading } from '../Heading' |
| 5 | +import { SectioningFragment } from '../SectioningContent/SectioningContent' |
| 6 | + |
| 7 | +import { StepCounter } from './StepCounter' |
| 8 | + |
| 9 | +import type { HorizontalStep } from './types' |
| 10 | + |
| 11 | +const horizontallStepItem = tv({ |
| 12 | + slots: { |
| 13 | + wrapper: [ |
| 14 | + 'shr-group/stepItem', |
| 15 | + // 長いステップ名が来ても等幅にする |
| 16 | + 'shr-flex-1', |
| 17 | + ], |
| 18 | + headingWrapper: 'shr-flex shr-flex-col shr-items-center shr-gap-0.5', |
| 19 | + stepCounterWrapper: 'shr-self-stretch shr-flex shr-items-center', |
| 20 | + beforeLine: [ |
| 21 | + 'group-first/stepItem:shr-bg-transparent', |
| 22 | + 'shr-grow shr-h-[theme(borderWidth.2)] shr-bg-border', |
| 23 | + 'forced-colors:shr-bg-[ButtonBorder]', |
| 24 | + ], |
| 25 | + afterLine: [ |
| 26 | + 'group-last/stepItem:shr-bg-transparent', |
| 27 | + // compoundSlots で書けるが、variants の上書きが複雑になるため切り出していない |
| 28 | + 'shr-grow shr-h-[theme(borderWidth.2)] shr-bg-border', |
| 29 | + 'forced-colors:shr-bg-[ButtonBorder]', |
| 30 | + ], |
| 31 | + heading: 'shr-px-0.25 shr-text-sm shr-text-center', |
| 32 | + }, |
| 33 | + variants: { |
| 34 | + status: { |
| 35 | + completed: { |
| 36 | + afterLine: ['shr-bg-main', 'forced-colors:shr-bg-[Highlight]'], |
| 37 | + }, |
| 38 | + closed: {}, |
| 39 | + }, |
| 40 | + current: { |
| 41 | + true: { |
| 42 | + heading: 'shr-font-bold', |
| 43 | + }, |
| 44 | + false: {}, |
| 45 | + }, |
| 46 | + isPrevStepCompleted: { |
| 47 | + true: { |
| 48 | + beforeLine: ['shr-bg-main', 'forced-colors:shr-bg-[Highlight]'], |
| 49 | + }, |
| 50 | + false: {}, |
| 51 | + }, |
| 52 | + }, |
| 53 | + compoundVariants: [ |
| 54 | + { |
| 55 | + status: ['completed', 'closed'], |
| 56 | + current: false, |
| 57 | + className: { |
| 58 | + heading: 'shr-text-grey', |
| 59 | + }, |
| 60 | + }, |
| 61 | + ], |
| 62 | +}) |
| 63 | + |
| 64 | +type Props = HorizontalStep & { |
| 65 | + /** ステップ数 */ |
| 66 | + stepNumber?: number |
| 67 | + /** 現在地かどうか */ |
| 68 | + current: boolean |
| 69 | + /** 前のステップが完了しているかどうか */ |
| 70 | + isPrevStepCompleted?: boolean |
| 71 | +} |
| 72 | + |
| 73 | +export const HorizontalStepItem: FC<Props> = ({ |
| 74 | + stepNumber, |
| 75 | + label, |
| 76 | + status, |
| 77 | + current, |
| 78 | + isPrevStepCompleted, |
| 79 | +}) => { |
| 80 | + const statusType = typeof status === 'object' ? status.type : status |
| 81 | + const { wrapper, headingWrapper, stepCounterWrapper, beforeLine, afterLine, heading } = |
| 82 | + horizontallStepItem({ |
| 83 | + status: statusType, |
| 84 | + current, |
| 85 | + isPrevStepCompleted, |
| 86 | + }) |
| 87 | + |
| 88 | + return ( |
| 89 | + <li aria-current={current} className={wrapper()}> |
| 90 | + <SectioningFragment> |
| 91 | + <div className={headingWrapper()}> |
| 92 | + <div className={stepCounterWrapper()}> |
| 93 | + <span className={beforeLine()} /> |
| 94 | + <StepCounter status={status} current={current} stepNumber={stepNumber} /> |
| 95 | + <span className={afterLine()} /> |
| 96 | + </div> |
| 97 | + <Heading type="sectionTitle" className={heading()}> |
| 98 | + {label} |
| 99 | + </Heading> |
| 100 | + </div> |
| 101 | + </SectioningFragment> |
| 102 | + </li> |
| 103 | + ) |
| 104 | +} |
0 commit comments