menu-bar-option.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import DropdownListItem from '@/shared/components/dropdown/dropdown-list-item'
  2. import { DropdownItem } from '@/shared/components/dropdown/dropdown-menu'
  3. import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
  4. import { useNestableDropdown } from '@/shared/hooks/use-nestable-dropdown'
  5. import { MouseEventHandler, ReactNode, useCallback } from 'react'
  6. type MenuBarOptionProps = {
  7. title: string
  8. onClick?: MouseEventHandler
  9. disabled?: boolean
  10. leadingIcon?: ReactNode
  11. trailingIcon?: ReactNode
  12. href?: string
  13. target?: string
  14. rel?: string
  15. eventKey?: string
  16. }
  17. export const MenuBarOption = ({
  18. title,
  19. onClick: clickHandler,
  20. href,
  21. disabled,
  22. leadingIcon,
  23. trailingIcon,
  24. target,
  25. rel,
  26. eventKey,
  27. }: MenuBarOptionProps) => {
  28. const { setSelected } = useNestableDropdown()
  29. const { sendEvent } = useEditorAnalytics()
  30. const onClick: MouseEventHandler = useCallback(
  31. e => {
  32. if (eventKey) {
  33. sendEvent('menu-bar-option-click', { key: eventKey })
  34. }
  35. return clickHandler?.(e)
  36. },
  37. [clickHandler, eventKey, sendEvent]
  38. )
  39. return (
  40. <DropdownListItem>
  41. <DropdownItem
  42. onMouseEnter={() => setSelected(null)}
  43. onClick={onClick}
  44. disabled={disabled}
  45. leadingIcon={leadingIcon}
  46. trailingIcon={trailingIcon}
  47. href={href}
  48. rel={rel}
  49. target={target}
  50. >
  51. {title}
  52. </DropdownItem>
  53. </DropdownListItem>
  54. )
  55. }