item.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, { PureComponent } from 'react';
  2. import cls from 'classnames';
  3. import { noop } from 'lodash';
  4. import PropTypes from 'prop-types';
  5. import { cssClasses, strings } from '@douyinfe/semi-foundation/timeline/constants';
  6. import '@douyinfe/semi-foundation/timeline/timeline.scss';
  7. export interface TimelineItemProps {
  8. color?: string;
  9. time?: React.ReactNode;
  10. type?: 'default' | 'ongoing' | 'success' | 'warning' | 'error';
  11. dot?: React.ReactNode;
  12. extra?: React.ReactNode;
  13. position?: 'left' | 'right';
  14. className?: string;
  15. style?: React.CSSProperties;
  16. onClick?: React.MouseEventHandler<HTMLLIElement>;
  17. }
  18. const prefixCls = cssClasses.ITEM;
  19. export default class Item extends PureComponent<TimelineItemProps> {
  20. static propTypes = {
  21. color: PropTypes.string,
  22. time: PropTypes.node,
  23. type: PropTypes.oneOf(strings.ITEM_TYPE),
  24. dot: PropTypes.node,
  25. extra: PropTypes.node,
  26. position: PropTypes.oneOf(strings.ITEM_POS),
  27. className: PropTypes.string,
  28. style: PropTypes.object,
  29. onClick: PropTypes.func,
  30. };
  31. static defaultProps = {
  32. type: 'default',
  33. time: '',
  34. onClick: noop,
  35. };
  36. render() {
  37. const {
  38. className,
  39. color,
  40. children,
  41. dot,
  42. type,
  43. style,
  44. time,
  45. extra,
  46. onClick,
  47. } = this.props;
  48. const itemCls = cls(prefixCls,
  49. className
  50. );
  51. const dotCls = cls({
  52. [`${prefixCls}-head`]: true,
  53. [`${prefixCls}-head-custom`]: dot,
  54. [`${prefixCls}-head-${type}`]: type,
  55. });
  56. const dotStyle = color ? { style: { backgroundColor: color } } : null;
  57. return (
  58. <li className={itemCls} style={style} onClick={onClick}>
  59. <div className={`${prefixCls}-tail`} aria-hidden />
  60. <div
  61. className={dotCls}
  62. aria-hidden
  63. {...dotStyle}
  64. >
  65. {dot}
  66. </div>
  67. <div className={`${prefixCls}-content`}>
  68. {children}
  69. {extra && <div className={`${prefixCls}-content-extra`}>{extra}</div>}
  70. {time && <div className={`${prefixCls}-content-time`}>{time}</div>}
  71. </div>
  72. </li>
  73. );
  74. }
  75. }