PagePathNav.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. 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. const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { ssr: false });
  18. let formerLink;
  19. let latterLink;
  20. // one line
  21. if (dPagePath.isRoot || dPagePath.isFormerRoot || isSingleLineMode) {
  22. const linkedPagePath = new LinkedPagePath(pagePath);
  23. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePath} />;
  24. }
  25. // two line
  26. else {
  27. const linkedPagePathFormer = new LinkedPagePath(dPagePath.former);
  28. const linkedPagePathLatter = new LinkedPagePath(dPagePath.latter);
  29. formerLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathFormer} />;
  30. latterLink = <PagePathHierarchicalLink linkedPagePath={linkedPagePathLatter} basePath={dPagePath.former} />;
  31. }
  32. const copyDropdownId = `copydropdown${isCompactMode ? '-subnav-compact' : ''}-${pageId}`;
  33. const copyDropdownToggleClassName = 'd-block btn-outline-secondary btn-copy border-0 text-muted p-2';
  34. return (
  35. <div className="grw-page-path-nav">
  36. {formerLink}
  37. <span className="d-flex align-items-center">
  38. <h1 className="m-0">{latterLink}</h1>
  39. { pageId != null && (
  40. <div className="mx-2">
  41. <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
  42. <i className="ti-clipboard"></i>
  43. </CopyDropdown>
  44. </div>
  45. ) }
  46. </span>
  47. </div>
  48. );
  49. };
  50. export default PagePathNav;