Files
supabase/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.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

57 lines
1.6 KiB
TypeScript

import { Maximize2, Minimize2 } from 'lucide-react'
import { Button, cn, FormControl, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import CodeEditor from '@/components/ui/CodeEditor/CodeEditor'
export const FunctionEditor = ({
field,
language,
focused,
setFocused,
}: {
field: any
language: string
focused: boolean
setFocused: (b: boolean) => void
}) => {
return (
<div className={cn('rounded-md relative group grow')}>
<FormControl>
{language !== undefined && (
<CodeEditor
id="database-functions-editor"
language="pgsql"
placeholder={language === 'plpgsql' ? `BEGIN\n\nEND;` : undefined}
value={field.value}
onInputChange={field.onChange}
/>
)}
</FormControl>
<div
className={cn(
'absolute top-0 right-2 bg-surface-300 border border-strong rounded-sm h-[28px]',
'opacity-0 group-hover:opacity-100 group-hover:top-2 transition-all'
)}
>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="text"
size="tiny"
className={cn(
'px-1.5 text-foreground-lighter hover:text-foreground',
'transition z-50'
)}
onClick={() => setFocused(!focused)}
icon={focused ? <Minimize2 /> : <Maximize2 />}
/>
</TooltipTrigger>
<TooltipContent side="bottom">
{focused ? 'Minimize editor' : 'Maximize editor'}
</TooltipContent>
</Tooltip>
</div>
</div>
)
}