CarouselArrow.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* eslint-disable jsx-a11y/click-events-have-key-events */
  2. /* eslint-disable jsx-a11y/no-static-element-interactions */
  3. import React, { ReactNode } from "react";
  4. import cls from 'classnames';
  5. import { cssClasses } from '@douyinfe/semi-foundation/carousel/constants';
  6. import { CarouselArrowProps } from "./interface";
  7. import { IconChevronLeft, IconChevronRight } from "@douyinfe/semi-icons";
  8. import { get, throttle } from 'lodash';
  9. class CarouselArrow extends React.PureComponent<CarouselArrowProps> {
  10. renderLeftIcon = () => {
  11. return get(this.props, 'arrowProps.leftArrow.children', <IconChevronLeft aria-label="Previous index" size="inherit"/>);
  12. }
  13. renderRightIcon = () => {
  14. return get(this.props, 'arrowProps.rightArrow.children', <IconChevronRight aria-label="Next index" size="inherit"/>);
  15. }
  16. render(): ReactNode {
  17. const { type, theme, prev, next, timing } = this.props;
  18. const classNames = cls( {
  19. [cssClasses.CAROUSEL_ARROW]: true,
  20. [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
  21. [`${cssClasses.CAROUSEL_ARROW}-hover`]: type === 'hover',
  22. });
  23. const leftClassNames = cls( {
  24. [`${cssClasses.CAROUSEL_ARROW}-prev`]: true,
  25. [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
  26. });
  27. const rightClassNames = cls( {
  28. [`${cssClasses.CAROUSEL_ARROW}-next`]: true,
  29. [`${cssClasses.CAROUSEL_ARROW}-${theme}`]: theme,
  30. });
  31. return (
  32. <div className={classNames}>
  33. <div
  34. // role='button'
  35. className={leftClassNames}
  36. onClick={throttle(prev, timing)}
  37. {...get(this.props, 'arrowProps.leftArrow.props')}
  38. >
  39. {this.renderLeftIcon()}
  40. </div>
  41. <div
  42. // role='button'
  43. // tabIndex={0}
  44. className={rightClassNames}
  45. onClick={throttle(next, timing)}
  46. {...get(this.props, 'arrowProps.rightArrow.props')}
  47. >
  48. {this.renderRightIcon()}
  49. </div>
  50. </div>
  51. );
  52. }
  53. }
  54. export default CarouselArrow;