mirror of
https://github.com/supabase/supabase.git
synced 2026-10-10 20:05:06 +03:00
## Problem The `_Shadcn_` suffix isn't needed anymore on `HoverCard` components ## Solution Remove it. No other changes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Standardized hover-card component usage across the apps and design system for consistent behavior and markup. * No user-facing changes — hover previews, tooltips, snippet/template previews, and code hover panels retain the same appearance and interactions. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45987) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { X } from 'lucide-react'
|
|
import React from 'react'
|
|
import { Button, HoverCard, HoverCardContent, HoverCardTrigger } from 'ui'
|
|
import { CodeBlock } from 'ui-patterns/CodeBlock'
|
|
|
|
import { type SqlSnippet } from './AIAssistant.types'
|
|
|
|
export const getSnippetLabel = (snippet: SqlSnippet, index: number): string => {
|
|
if (typeof snippet === 'string') {
|
|
return `Snippet ${index + 1}`
|
|
}
|
|
return snippet.label
|
|
}
|
|
|
|
export const getSnippetContent = (snippet: SqlSnippet): string => {
|
|
if (typeof snippet === 'string') {
|
|
return snippet
|
|
}
|
|
return snippet.content
|
|
}
|
|
|
|
interface SnippetRowProps {
|
|
snippets: SqlSnippet[]
|
|
onRemoveSnippet?: (index: number) => void
|
|
className?: string
|
|
}
|
|
|
|
export const SnippetRow: React.FC<SnippetRowProps> = ({
|
|
snippets,
|
|
onRemoveSnippet,
|
|
className = '',
|
|
}) => {
|
|
if (!snippets || snippets.length === 0) return null
|
|
|
|
return (
|
|
<div className={`w-full overflow-x-auto flex ${className}`}>
|
|
{snippets.map((snippet, idx) => (
|
|
<HoverCard key={idx}>
|
|
<HoverCardTrigger asChild>
|
|
<div
|
|
tabIndex={0}
|
|
className="border bg inline-flex gap-1 items-center shrink-0 py-1 pl-2 rounded-full pr-1 text-xs cursor-pointer"
|
|
>
|
|
{getSnippetLabel(snippet, idx)}
|
|
{onRemoveSnippet && (
|
|
<Button
|
|
size="tiny"
|
|
type="text"
|
|
className="h-4! w-4! rounded-full p-0"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onRemoveSnippet(idx)
|
|
}}
|
|
aria-label={`Remove snippet ${idx + 1}`}
|
|
icon={<X strokeWidth={1.5} className="h-3! w-3!" />}
|
|
/>
|
|
)}
|
|
</div>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent className="w-96 max-h-64 overflow-auto p-0">
|
|
<CodeBlock
|
|
hideLineNumbers
|
|
className="text-xs font-mono whitespace-pre-wrap wrap-break-word p-2 border-0"
|
|
language="sql"
|
|
>
|
|
{getSnippetContent(snippet)}
|
|
</CodeBlock>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|