mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
96d43099bb
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { SqlEditor } from 'icons'
|
|
import { cn, KeyboardShortcut } from 'ui'
|
|
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useIsShortcutEnabled } from '@/state/shortcuts/useIsShortcutEnabled'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
const InlineEditorKeyboardTooltip = () => {
|
|
const hotkeyEnabled = useIsShortcutEnabled(SHORTCUT_IDS.INLINE_EDITOR_TOGGLE)
|
|
|
|
return hotkeyEnabled ? <KeyboardShortcut keys={['Meta', 'E']} /> : null
|
|
}
|
|
|
|
export const InlineEditorButton = () => {
|
|
const { activeSidebar, toggleSidebar } = useSidebarManagerSnapshot()
|
|
const isOpen = activeSidebar?.id === SIDEBAR_KEYS.EDITOR_PANEL
|
|
const track = useTrack()
|
|
|
|
const handleClick = () => {
|
|
track('header_inline_editor_button_clicked')
|
|
toggleSidebar(SIDEBAR_KEYS.EDITOR_PANEL)
|
|
}
|
|
|
|
return (
|
|
<ButtonTooltip
|
|
variant="outline"
|
|
size="tiny"
|
|
id="editor-trigger"
|
|
className={cn(
|
|
'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 text-foreground-light hover:text-foreground',
|
|
isOpen && 'bg-foreground text-background hover:text-background'
|
|
)}
|
|
onClick={handleClick}
|
|
tooltip={{
|
|
content: {
|
|
className: 'p-1 pl-2.5',
|
|
text: (
|
|
<div className="flex items-center gap-2.5">
|
|
<span>SQL Editor</span>
|
|
<InlineEditorKeyboardTooltip />
|
|
</div>
|
|
),
|
|
},
|
|
}}
|
|
>
|
|
<SqlEditor size={16} strokeWidth={1.5} />
|
|
<span className="sr-only">SQL Editor</span>
|
|
</ButtonTooltip>
|
|
)
|
|
}
|