mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
## What kind of change does this PR introduce? UI polish for split buttons (primary action + dropdown chevron). Follow-up to #49055. ## What is the current behavior? The focus ring sits above the neighbouring half, but the inner edge stays square, so the ring has two sharp corners at the join. ## What is the new behavior? On keyboard focus, the squared-off edge uses a slight radius so the ring matches the outer corners more closely. Resting state is unchanged. Split-button callsites now share the same join classes as the design-system example. | Before | After | | --- | --- | | <img width="1030" height="296" alt="43471" src="https://github.com/user-attachments/assets/9df3bd72-c7ac-4419-ae18-a7e649dc2d66" /> | <img width="1056" height="276" alt="CleanShot 2026-08-17 at 10 45 09@2x" src="https://github.com/user-attachments/assets/52e8a4dc-9c52-45ce-b4d0-f0e7b1b75935" /> | ## To test Tab to each half (labelled button, then chevron). Inner corners of the focus ring should be slightly rounded, not square. 1. [Split with dropdown](https://design-system-git-fix-split-button-focus-radius-supabase.vercel.app/design-system/docs/components/button#split-with-dropdown) (no login) 2. [Access Tokens](https://studio-staging-git-fix-split-button-focus-radius-supabase.vercel.app/dashboard/account/tokens) → Generate new token 3. Any project on [studio staging](https://studio-staging-git-fix-split-button-focus-radius-supabase.vercel.app/dashboard/_/settings/general) → Settings → General → Restart project <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Accessibility** - Added accessible labels to dropdown and export controls. - Improved keyboard-focus visibility, layering, and rounded edge treatment across joined buttons and menus. - Removed misleading or redundant screen-reader text and titles. - **Bug Fixes** - Prevented split-button controls from shrinking or displaying awkward borders and corners. - Refined hover and focus behavior for action buttons throughout settings, database, storage, account, and documentation interfaces. - **Documentation** - Clarified guidance for using overflow menus and responsive split-button actions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
218 lines
5.8 KiB
TypeScript
218 lines
5.8 KiB
TypeScript
import { AiAssistantSource } from 'common/telemetry-constants'
|
|
import { Chatgpt, Claude } from 'icons'
|
|
import { Check, ChevronDown, Copy } from 'lucide-react'
|
|
import Link from 'next/link'
|
|
import { ComponentProps, ReactNode, useEffect, useState } from 'react'
|
|
import {
|
|
AiIconAnimation,
|
|
Button,
|
|
cn,
|
|
copyToClipboard,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuSeparator,
|
|
DropdownMenuTrigger,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
type TelemetrySource = AiAssistantSource
|
|
|
|
const EXTERNAL_AI_TOOLS = [
|
|
{
|
|
label: 'Ask ChatGPT',
|
|
url: 'https://chatgpt.com/',
|
|
promptParam: 'q',
|
|
icon: Chatgpt,
|
|
toolId: 'chatgpt' as const,
|
|
},
|
|
{
|
|
label: 'Ask Claude',
|
|
url: 'https://claude.ai/new',
|
|
promptParam: 'q',
|
|
icon: Claude,
|
|
toolId: 'claude' as const,
|
|
},
|
|
]
|
|
|
|
export interface AiAssistantDropdownItem {
|
|
label: string
|
|
icon?: ReactNode
|
|
href?: string
|
|
onClick?: () => void
|
|
}
|
|
|
|
export interface AiAssistantDropdownProps {
|
|
buildPrompt: () => string
|
|
label: string
|
|
iconOnly?: boolean
|
|
onOpenAssistant: () => void
|
|
onCopyPrompt?: () => void
|
|
telemetrySource?: TelemetrySource
|
|
size?: ComponentProps<typeof Button>['size']
|
|
variant?: ComponentProps<typeof Button>['variant']
|
|
disabled?: boolean
|
|
loading?: boolean
|
|
className?: string
|
|
tooltip?: string
|
|
copyLabel?: string
|
|
showExternalAI?: boolean
|
|
additionalDropdownItems?: AiAssistantDropdownItem[]
|
|
}
|
|
|
|
export function AiAssistantDropdown({
|
|
buildPrompt,
|
|
label,
|
|
iconOnly = false,
|
|
onOpenAssistant,
|
|
onCopyPrompt,
|
|
telemetrySource,
|
|
size = 'tiny',
|
|
variant = 'default',
|
|
disabled = false,
|
|
loading = false,
|
|
className,
|
|
tooltip,
|
|
copyLabel = 'Copy prompt',
|
|
showExternalAI = false,
|
|
additionalDropdownItems,
|
|
}: AiAssistantDropdownProps) {
|
|
const track = useTrack()
|
|
const [showCopied, setShowCopied] = useState(false)
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
|
|
useEffect(() => {
|
|
if (!showCopied) return
|
|
const timer = setTimeout(() => setShowCopied(false), 2000)
|
|
return () => clearTimeout(timer)
|
|
}, [showCopied])
|
|
|
|
const handleCopyPrompt = () => {
|
|
const prompt = buildPrompt()
|
|
copyToClipboard(prompt)
|
|
setShowCopied(true)
|
|
setIsOpen(false)
|
|
onCopyPrompt?.()
|
|
|
|
if (telemetrySource) {
|
|
track('ai_prompt_copied', { source: telemetrySource })
|
|
}
|
|
}
|
|
|
|
const handleOpenExternalAI = (tool: (typeof EXTERNAL_AI_TOOLS)[number]) => {
|
|
const prompt = buildPrompt()
|
|
window.open(
|
|
`${tool.url}?${tool.promptParam}=${encodeURIComponent(prompt)}`,
|
|
'_blank',
|
|
'noreferrer'
|
|
)
|
|
|
|
if (telemetrySource) {
|
|
track('ai_external_tool_clicked', { source: telemetrySource, tool: tool.toolId })
|
|
}
|
|
}
|
|
|
|
const handleOpenAssistant = () => {
|
|
onOpenAssistant()
|
|
|
|
if (telemetrySource) {
|
|
track('ai_assistant_dropdown_button_clicked', { source: telemetrySource })
|
|
}
|
|
}
|
|
|
|
const buttonContent = (
|
|
<div className={cn('flex items-center', iconOnly ? 'gap-0' : 'gap-0')}>
|
|
{/* Main button */}
|
|
<Button
|
|
variant={variant}
|
|
size={size}
|
|
disabled={disabled}
|
|
onClick={handleOpenAssistant}
|
|
icon={<AiIconAnimation size={iconOnly ? 16 : 14} loading={loading} />}
|
|
className={cn(
|
|
'rounded-r-none hover:z-10 focus-visible:z-10 focus-visible:rounded-r-sm',
|
|
iconOnly && 'px-1.5',
|
|
className
|
|
)}
|
|
>
|
|
{!iconOnly && label}
|
|
</Button>
|
|
|
|
{/* Dropdown trigger */}
|
|
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
aria-label="More actions"
|
|
variant={variant}
|
|
size={size}
|
|
disabled={disabled}
|
|
className="shrink-0 rounded-l-none px-[4px] py-[5px] -ml-px focus-visible:z-10 focus-visible:rounded-l-sm"
|
|
icon={<ChevronDown size={12} />}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-44">
|
|
<DropdownMenuItem onClick={handleCopyPrompt} className="gap-2">
|
|
{showCopied ? <Check size={14} className="text-brand" /> : <Copy size={14} />}
|
|
{showCopied ? 'Copied!' : copyLabel}
|
|
</DropdownMenuItem>
|
|
|
|
{showExternalAI && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
{EXTERNAL_AI_TOOLS.map((tool) => (
|
|
<DropdownMenuItem
|
|
key={tool.url}
|
|
className="gap-2"
|
|
onClick={() => handleOpenExternalAI(tool)}
|
|
>
|
|
<tool.icon size={14} />
|
|
{tool.label}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</>
|
|
)}
|
|
|
|
{additionalDropdownItems && additionalDropdownItems.length > 0 && (
|
|
<>
|
|
<DropdownMenuSeparator />
|
|
{additionalDropdownItems.map((item, i) => (
|
|
<DropdownMenuItem key={i} onClick={item.onClick} className="gap-2">
|
|
{item.href ? (
|
|
<Link href={item.href} target="_blank" rel="noreferrer">
|
|
{item.icon}
|
|
{item.label}
|
|
</Link>
|
|
) : (
|
|
<>
|
|
{item.icon}
|
|
{item.label}
|
|
</>
|
|
)}
|
|
</DropdownMenuItem>
|
|
))}
|
|
</>
|
|
)}
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
)
|
|
|
|
// Wrap in tooltip for icon-only mode
|
|
if (iconOnly && tooltip) {
|
|
return (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="inline-flex">{buttonContent}</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom">{tooltip}</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
}
|
|
|
|
return buttonContent
|
|
}
|