PagePathNav.tsx 2.1 KB

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