DropendMenu.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { DropdownMenu, DropdownItem } from 'reactstrap';
  4. import type { LabelType } from '~/interfaces/template';
  5. type DropendMenuProps = {
  6. onClickCreateNewPageButtonHandler: () => Promise<void>
  7. onClickCreateTodaysButtonHandler: () => Promise<void>
  8. onClickTemplateButtonHandler?: (label: LabelType) => Promise<void>
  9. todaysPath: string | null,
  10. }
  11. export const DropendMenu = React.memo((props: DropendMenuProps): JSX.Element => {
  12. const {
  13. onClickCreateNewPageButtonHandler,
  14. onClickCreateTodaysButtonHandler,
  15. onClickTemplateButtonHandler,
  16. todaysPath,
  17. } = props;
  18. const { t } = useTranslation('commons');
  19. return (
  20. <DropdownMenu
  21. container="body"
  22. >
  23. <DropdownItem
  24. onClick={onClickCreateNewPageButtonHandler}
  25. >
  26. {t('create_page_dropdown.new_page')}
  27. </DropdownItem>
  28. {todaysPath != null && (
  29. <>
  30. <DropdownItem divider />
  31. <li><span className="text-muted px-3">{t('create_page_dropdown.todays.desc')}</span></li>
  32. <DropdownItem
  33. onClick={onClickCreateTodaysButtonHandler}
  34. >
  35. {todaysPath}
  36. </DropdownItem>
  37. </>
  38. )}
  39. { onClickTemplateButtonHandler != null && (
  40. <>
  41. <DropdownItem divider />
  42. <li><span className="text-muted text-nowrap px-3">{t('create_page_dropdown.template.desc')}</span></li>
  43. <DropdownItem
  44. onClick={() => onClickTemplateButtonHandler('_template')}
  45. >
  46. {t('create_page_dropdown.template.children')}
  47. </DropdownItem>
  48. <DropdownItem
  49. onClick={() => onClickTemplateButtonHandler('__template')}
  50. >
  51. {t('create_page_dropdown.template.descendants')}
  52. </DropdownItem>
  53. </>
  54. ) }
  55. </DropdownMenu>
  56. );
  57. });
  58. DropendMenu.displayName = 'DropendMenu';