-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathebay-progress-step.tsx
58 lines (52 loc) · 1.66 KB
/
ebay-progress-step.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { Children, FC, ReactElement, ReactNode } from 'react'
import classNames from 'classnames'
import { EbayIcon, Icon } from '../ebay-icon'
import { StepState } from './types'
import { EbayProgressTitle } from './index'
export type EbayProgressStepProps = {
state?: StepState;
current?: boolean;
className?: string;
children?: ReactNode;
}
const typeIcons: { [key in StepState]: Icon } = {
complete: 'stepperConfirmation24',
attention: 'stepperAttention24',
upcoming: 'stepperUpcoming24',
active: 'stepperConfirmation24'
}
const EbayProgressStep: FC<EbayProgressStepProps> = ({
current,
state = 'complete',
children,
className,
...rest
}) => {
const childrenArray = Children.toArray(children) as ReactElement[]
const title = childrenArray.find(child => child.type === EbayProgressTitle)
const text = childrenArray.filter(child => child.type !== EbayProgressTitle)
const stepClassNames = classNames(
className,
'progress-stepper__item',
{ 'progress-stepper__item--attention': state === 'attention' }
)
const icon = typeIcons[state]
const ariaLabel = current ? 'current' : state
return (
<div
{...rest}
className={stepClassNames}
role="listitem"
aria-current={current ? 'step' : undefined}
>
<div className="progress-stepper__icon">
{icon && <EbayIcon name={icon} aria-label={ariaLabel} />}
</div>
<div className="progress-stepper__text">
{title}
{text}
</div>
</div>
)
}
export default EbayProgressStep