PagePathNav.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React, { FC } from 'react';
  2. import { DevidedPagePath } from '@growi/core';
  3. import PagePathHierarchicalLink from './PagePathHierarchicalLink';
  4. import CopyDropdown from './Page/CopyDropdown';
  5. import LinkedPagePath from '../models/linked-page-path';
  6. type Props = {
  7. pagePath: string,
  8. pageId?: string | null,
  9. isSingleLineMode?:boolean,
  10. isCompactMode?:boolean,
  11. }
  12. const PagePathNav: FC<Props> = (props: Props) => {
  13. const {
  14. pageId, pagePath, isSingleLineMode, isCompactMode,
  15. } = props;
  16. const dPagePath = new DevidedPagePath(pagePath, false, true);
  17. let formerLink;
  18. let latterLink;
  19. // one line
  20. if (dPagePath.isRoot || dPagePath.isFormerRoot || isSingleLineMode) {
  21. const linkedPagePath = new LinkedPagePath(pagePath);
  22. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePath} />;
  23. }
  24. // two line
  25. else {
  26. const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
  27. const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
  28. formerLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathFormer} />;
  29. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.former} />;
  30. }
  31. const copyDropdownId = `copydropdown${isCompactMode ? '-subnav-compact' : ''}-${pageId}`;
  32. const copyDropdownToggleClassName = 'd-block btn-outline-secondary btn-copy border-0 text-muted p-2';
  33. return (
  34. <div className="grw-page-path-nav">
  35. {formerLink}
  36. <span className="d-flex align-items-center">
  37. <h1 className="m-0">{latterLink}</h1>
  38. { pageId != null && (
  39. <div className="mx-2">
  40. <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
  41. <i className="ti-clipboard"></i>
  42. </CopyDropdown>
  43. </div>
  44. ) }
  45. </span>
  46. </div>
  47. );
  48. };
  49. export default PagePathNav;