PagePathNav.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. pageId :string,
  8. pagePath:string,
  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 text-muted bg-transparent btn-copy border-0 py-0';
  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. <div className="mx-2">
  39. <CopyDropdown pageId={pageId} pagePath={pagePath} dropdownToggleId={copyDropdownId} dropdownToggleClassName={copyDropdownToggleClassName}>
  40. <i className="ti-clipboard"></i>
  41. </CopyDropdown>
  42. </div>
  43. </span>
  44. </div>
  45. );
  46. };
  47. export default PagePathNav;