-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathcarousel-control-button.tsx
45 lines (39 loc) · 1.36 KB
/
carousel-control-button.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
import React, { FC, SyntheticEvent } from 'react'
import classNames from 'classnames'
import { EbayIcon, Icon } from '../ebay-icon'
import { CarouselControlType, MovementDirection } from './types'
type CarouselControlProps = {
label?: string;
hidden?: boolean;
type: CarouselControlType;
disabled?: boolean;
onClick: (event: SyntheticEvent<HTMLButtonElement>, { direction }) => void;
}
const icon: Record<CarouselControlType, Icon> = {
prev: 'chevronLeft16',
next: 'chevronRight16'
}
const typeToDirection: Record<CarouselControlType, MovementDirection> = {
prev: 'LEFT',
next: 'RIGHT'
}
const CarouselControlButton: FC<CarouselControlProps> = ({ type, label, hidden, disabled, onClick }) => {
const handleOnClick = (event: SyntheticEvent<HTMLButtonElement>) => {
onClick(event, { direction: typeToDirection[type] })
}
return (
<button
className={classNames('carousel__control', `carousel__control--${type}`)}
aria-label={label}
aria-disabled={disabled}
disabled={disabled}
onClick={handleOnClick}>
<EbayIcon
className={classNames('icon', `icon--carousel-${type}`)}
focusable={false}
name={icon[type]}
aria-hidden={hidden} />
</button>
)
}
export default CarouselControlButton