mirror of
https://github.com/supabase/supabase.git
synced 2026-10-09 11:25:06 +03:00
## 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>
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"
|
|
variant="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>
|
|
)
|
|
}
|