Skip to content

Commit

Permalink
enhance(StepProgress): make value for step progress optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sjschlapbach committed Feb 7, 2024
1 parent d572ef0 commit cfc25dd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/StepProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface StepProgressBaseProps {
cy?: string
test?: string
}
value: number
value?: number
onItemClick: (ix: number, item?: StepItem) => void
displayOffsetLeft?: number
displayOffsetRight?: number
Expand Down Expand Up @@ -122,15 +122,17 @@ export function StepProgress({
data-test={data?.test}
>
{typeof displayOffsetLeft !== 'undefined' &&
value - displayOffsetLeft > 0 && (
(value || 0) - displayOffsetLeft > 0 && (
<button
data-cy={data?.cy ? `${data?.cy}-left` : undefined}
className={twMerge(
className?.override,
'rounded-l px-3 py-1 hover:bg-primary-20 hover:text-primary',
!items && 'bg-primary-60 text-white'
)}
onClick={() => onItemClick(value - 1, items && items[value - 1])}
onClick={() =>
onItemClick((value || 0) - 1, items && items[(value || 0) - 1])
}
>
<FontAwesomeIcon icon={faChevronLeft} />
</button>
Expand All @@ -146,13 +148,13 @@ export function StepProgress({
'flex flex-1 items-center justify-center border-r border-white p-1 last:border-r-0 hover:bg-primary-20 hover:text-primary',
ix === 0 && 'rounded-l',
ix === length - 1 && 'rounded-r',
value > ix && !items && 'bg-primary-60 text-white',
(value || 0) > ix && !items && 'bg-primary-60 text-white',
value === ix && 'bg-gray-400 font-bold text-white',
typeof displayOffsetLeft !== 'undefined' &&
ix < value - displayOffsetLeft &&
ix < (value || 0) - displayOffsetLeft &&
'hidden',
typeof displayOffsetRight !== 'undefined' &&
ix > value + displayOffsetRight &&
ix > (value || 0) + displayOffsetRight &&
'hidden',
formattedElement.className,
value === ix && 'bg-opacity-100'
Expand All @@ -164,14 +166,16 @@ export function StepProgress({
)
})}
{typeof displayOffsetRight !== 'undefined' &&
length > value + displayOffsetRight + 1 && (
length > (value || 0) + displayOffsetRight + 1 && (
<button
data-cy={data?.cy ? `${data?.cy}-right` : undefined}
className={twMerge(
className?.override,
'rounded-r px-3 py-1 hover:bg-primary-20 hover:text-primary'
)}
onClick={() => onItemClick(value + 1, items && items[value + 1])}
onClick={() =>
onItemClick((value || 0) + 1, items && items[(value || 0) + 1])
}
>
<FontAwesomeIcon icon={faChevronRight} />
</button>
Expand Down

0 comments on commit cfc25dd

Please sign in to comment.