PagePathNav.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import PagePathHierarchicalLink from './PagePathHierarchicalLink';
  7. type Props = {
  8. pagePath: string,
  9. pageId?: string | null,
  10. isSingleLineMode?:boolean,
  11. isCompactMode?:boolean,
  12. }
  13. const CopyDropdown = dynamic(() => import('./Page/CopyDropdown'), { ssr: false });
  14. const PagePathNav: FC<Props> = (props: Props) => {
  15. const {
  16. pageId, pagePath, isSingleLineMode, isCompactMode,
  17. } = props;
  18. const dPagePath = new DevidedPagePath(pagePath, false, true);
  19. const { data: isNotFound } = useIsNotFound();
  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;