navStep.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { isFunction } from 'lodash-es';
  4. import classnames from 'classnames';
  5. import { stepsClasses as css } from '@douyinfe/semi-foundation/steps/constants';
  6. import { IconChevronRight } from '@douyinfe/semi-icons';
  7. export interface NavStepProps {
  8. title?: React.ReactNode;
  9. className?: string;
  10. style?: React.CSSProperties;
  11. index?: number;
  12. active?: boolean;
  13. total?: number;
  14. prefixCls?: string;
  15. onChange?: () => void;
  16. onClick?: React.MouseEventHandler<HTMLDivElement>;
  17. }
  18. const NavStep = (props: NavStepProps) => {
  19. const { prefixCls, className, title, style, active, index, total, onClick, onChange, ...restProps } = props;
  20. const classString = classnames(prefixCls, className, {
  21. [`${prefixCls}-active`]: active
  22. });
  23. const handleClick = (e: React.MouseEvent) => {
  24. if (isFunction(onClick)) {
  25. onClick(e);
  26. }
  27. onChange();
  28. };
  29. return (
  30. <div {...restProps} className={classString} style={style} onClick={e => handleClick(e)}>
  31. <div className={`${prefixCls}-container`}>
  32. <div className={`${prefixCls}-content`}>
  33. <div className={`${prefixCls}-title`}>
  34. {title}
  35. </div>
  36. </div>
  37. {index !== total - 1 && (
  38. <div className={`${prefixCls}-icon`}>
  39. <IconChevronRight size="small" />
  40. </div>
  41. )}
  42. </div>
  43. </div>
  44. );
  45. };
  46. NavStep.propTypes = {
  47. prefixCls: PropTypes.string,
  48. title: PropTypes.node,
  49. className: PropTypes.string,
  50. style: PropTypes.object,
  51. onClick: PropTypes.func,
  52. active: PropTypes.bool,
  53. };
  54. NavStep.defaultProps = {
  55. prefixCls: css.ITEM,
  56. active: false,
  57. className: '',
  58. };
  59. export default NavStep;