full-project-search-button.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import React, { FC, useMemo } from 'react'
  2. import OLTooltip from '@/shared/components/ol/ol-tooltip'
  3. import classnames from 'classnames'
  4. import MaterialIcon from '@/shared/components/material-icon'
  5. import { useLayoutContext } from '@/shared/context/layout-context'
  6. import { useTranslation } from 'react-i18next'
  7. import { TooltipProps } from '@/shared/components/tooltip'
  8. import { isMac } from '@/shared/utils/os'
  9. import { sendSearchEvent } from '@/features/event-tracking/search-events'
  10. const FullProjectSearchButton: FC = () => {
  11. const { projectSearchIsOpen, setProjectSearchIsOpen } = useLayoutContext()
  12. const { t } = useTranslation()
  13. const tooltipProps: Pick<
  14. TooltipProps,
  15. 'id' | 'description' | 'overlayProps'
  16. > = useMemo(
  17. () => ({
  18. id: 'search',
  19. description: (
  20. <>
  21. <div>{t('search_project')}</div>
  22. <div>{isMac ? '⇧⌘F' : 'Ctrl+Shift+F'}</div>
  23. </>
  24. ),
  25. overlayProps: { placement: 'bottom' },
  26. }),
  27. [t]
  28. )
  29. return (
  30. <OLTooltip {...tooltipProps}>
  31. <button
  32. className={classnames('btn', {
  33. active: projectSearchIsOpen,
  34. })}
  35. onClick={() => {
  36. if (!projectSearchIsOpen) {
  37. sendSearchEvent('search-open', {
  38. searchType: 'full-project',
  39. method: 'button',
  40. location: 'toolbar',
  41. })
  42. }
  43. setProjectSearchIsOpen(value => !value)
  44. }}
  45. tabIndex={-1}
  46. data-active={projectSearchIsOpen}
  47. >
  48. <MaterialIcon type="search" accessibilityLabel={t('search')} />
  49. </button>
  50. </OLTooltip>
  51. )
  52. }
  53. export default FullProjectSearchButton