PagePathLabel.jsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { DevidedPagePath } from '@growi/core';
  4. export const PagePathLabel = (props) => {
  5. const dPagePath = new DevidedPagePath(props.page.path, false, true);
  6. let classNames = [''];
  7. classNames = classNames.concat(props.additionalClassNames);
  8. if (props.isLatterOnly) {
  9. return <span className={classNames.join(' ')}>{dPagePath.latter}</span>;
  10. }
  11. if (props.isFormerOnly) {
  12. const textElem = dPagePath.isFormerRoot
  13. ? <>/</>
  14. : <>{dPagePath.former}</>;
  15. return <span className={classNames.join(' ')}>{textElem}</span>;
  16. }
  17. const textElem = dPagePath.isRoot
  18. ? <><strong>/</strong></>
  19. : <>{dPagePath.former}/<strong>{dPagePath.latter}</strong></>;
  20. return <span className={classNames.join(' ')}>{textElem}</span>;
  21. };
  22. PagePathLabel.propTypes = {
  23. page: PropTypes.object.isRequired,
  24. isLatterOnly: PropTypes.bool,
  25. isFormerOnly: PropTypes.bool,
  26. additionalClassNames: PropTypes.arrayOf(PropTypes.string),
  27. };
  28. PagePathLabel.defaultProps = {
  29. additionalClassNames: [],
  30. };