PagePathNav.tsx 2.0 KB

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