DropendMenu.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { DropdownMenu, DropdownItem } from 'reactstrap';
  4. import { 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. <DropdownItem divider />
  40. <li><span className="text-muted text-nowrap px-3">{t('create_page_dropdown.template.desc')}</span></li>
  41. <DropdownItem
  42. onClick={() => onClickTemplateButtonHandler('_template')}
  43. >
  44. {t('create_page_dropdown.template.children')}
  45. </DropdownItem>
  46. <DropdownItem
  47. onClick={() => onClickTemplateButtonHandler('__template')}
  48. >
  49. {t('create_page_dropdown.template.descendants')}
  50. </DropdownItem>
  51. </DropdownMenu>
  52. );
  53. });
  54. DropendMenu.displayName = 'DropendMenu';