| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /* eslint-disable jsx-a11y/click-events-have-key-events */
- /* eslint-disable jsx-a11y/no-static-element-interactions */
- import React, { ReactNode } from "react";
- import cls from 'classnames';
- import { cssClasses } from '@douyinfe/semi-foundation/carousel/constants';
- import { CarouselArrowProps } from "./interface";
- import { IconChevronLeft, IconChevronRight } from "@douyinfe/semi-icons";
- import { get, throttle } from 'lodash';
- class CarouselArrow extends React.PureComponent<CarouselArrowProps> {
- renderLeftIcon = () => {
- return get(this.props, 'arrowProps.leftArrow.children', <IconChevronLeft aria-label="Previous index" size="inherit"/>);
- }
- renderRightIcon = () => {
- return get(this.props, 'arrowProps.rightArrow.children', <IconChevronRight aria-label="Next index" size="inherit"/>);
- }
- render(): ReactNode {
- const { type, theme, prev, next, timing } = this.props;
- const classNames = cls( {
- [cssClasses.CAROUSEL_ARROW]: true,
- [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
- [`${cssClasses.CAROUSEL_ARROW}-hover`]: type === 'hover',
- });
- const leftClassNames = cls( {
- [`${cssClasses.CAROUSEL_ARROW}-prev`]: true,
- [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
- });
- const rightClassNames = cls( {
- [`${cssClasses.CAROUSEL_ARROW}-next`]: true,
- [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
- });
- return (
- <div className={classNames}>
- <div
- // role='button'
- className={leftClassNames}
- onClick={throttle(prev, timing)}
- {...get(this.props, 'arrowProps.leftArrow.props')}
- >
- {this.renderLeftIcon()}
- </div>
- <div
- // role='button'
- // tabIndex={0}
- className={rightClassNames}
- onClick={throttle(next, timing)}
- {...get(this.props, 'arrowProps.rightArrow.props')}
- >
- {this.renderRightIcon()}
- </div>
- </div>
- );
- }
- }
- export default CarouselArrow;
|