Files
supabase/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
Gildas Garcia 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## 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>
2026-06-16 23:59:58 +02:00

51 lines
1.7 KiB
TypeScript

import { AiIconAnimation, 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'
export const AssistantButton = () => {
const { activeSidebar, toggleSidebar } = useSidebarManagerSnapshot()
const isAIAssistantHotkeyEnabled = useIsShortcutEnabled(SHORTCUT_IDS.AI_ASSISTANT_TOGGLE)
const track = useTrack()
const isOpen = activeSidebar?.id === SIDEBAR_KEYS.AI_ASSISTANT
return (
<ButtonTooltip
variant="outline"
size="tiny"
id="assistant-trigger"
className={cn(
'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0',
isOpen && 'bg-foreground text-background'
)}
onClick={() => {
track('header_assistant_button_clicked')
toggleSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
}}
tooltip={{
content: {
className: 'p-1 pl-2.5',
text: (
<div className="flex items-center gap-2.5">
<span>AI Assistant</span>
{isAIAssistantHotkeyEnabled && <KeyboardShortcut keys={['Meta', 'I']} />}
</div>
),
},
}}
>
<AiIconAnimation
allowHoverEffect={false}
size={16}
className={cn(isOpen && 'text-background')}
/>
<span className="sr-only">AI Assistant</span>
</ButtonTooltip>
)
}