indent.tsx 894 B

123456789101112131415161718192021222324252627282930313233343536
  1. import * as React from 'react';
  2. import classNames from 'classnames';
  3. interface IndentProps {
  4. prefixcls: string;
  5. level: number;
  6. isEnd: boolean[];
  7. showLine: boolean
  8. }
  9. const Indent = ({ prefixcls, level, isEnd, showLine }: IndentProps) => {
  10. const baseClassName = `${prefixcls}-indent-unit`;
  11. const list: React.ReactElement[] = [];
  12. for (let i = 0; i < level; i += 1) {
  13. list.push(
  14. <span
  15. key={i}
  16. className={classNames(baseClassName, {
  17. [`${baseClassName}-end`]: isEnd[i],
  18. })}
  19. />,
  20. );
  21. }
  22. return (
  23. <span aria-hidden="true" className={
  24. classNames(`${prefixcls}-indent`, {
  25. [`${prefixcls}-indent-show-line`]: showLine,
  26. })
  27. }>
  28. {list}
  29. </span>
  30. );
  31. };
  32. export default React.memo(Indent);