InlineEditorButton.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { SqlEditor } from 'icons'
  2. import { cn, KeyboardShortcut } from 'ui'
  3. import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
  4. import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
  5. import { useTrack } from '@/lib/telemetry/track'
  6. import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
  7. import { useIsShortcutEnabled } from '@/state/shortcuts/useIsShortcutEnabled'
  8. import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
  9. const InlineEditorKeyboardTooltip = () => {
  10. const hotkeyEnabled = useIsShortcutEnabled(SHORTCUT_IDS.INLINE_EDITOR_TOGGLE)
  11. return hotkeyEnabled ? <KeyboardShortcut keys={['Meta', 'E']} /> : null
  12. }
  13. export const InlineEditorButton = () => {
  14. const { activeSidebar, toggleSidebar } = useSidebarManagerSnapshot()
  15. const isOpen = activeSidebar?.id === SIDEBAR_KEYS.EDITOR_PANEL
  16. const track = useTrack()
  17. const handleClick = () => {
  18. track('header_inline_editor_button_clicked')
  19. toggleSidebar(SIDEBAR_KEYS.EDITOR_PANEL)
  20. }
  21. return (
  22. <ButtonTooltip
  23. type="outline"
  24. size="tiny"
  25. id="editor-trigger"
  26. className={cn(
  27. 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 text-foreground-light hover:text-foreground',
  28. isOpen && 'bg-foreground text-background hover:text-background'
  29. )}
  30. onClick={handleClick}
  31. tooltip={{
  32. content: {
  33. className: 'p-1 pl-2.5',
  34. text: (
  35. <div className="flex items-center gap-2.5">
  36. <span>SQL Editor</span>
  37. <InlineEditorKeyboardTooltip />
  38. </div>
  39. ),
  40. },
  41. }}
  42. >
  43. <SqlEditor size={16} strokeWidth={1.5} />
  44. <span className="sr-only">SQL Editor</span>
  45. </ButtonTooltip>
  46. )
  47. }