Files
supabase/apps/studio/components/interfaces/Database/Functions/CreateFunction/FunctionEditor.tsx
Ivan Vasilov 221ee13f79 feat: Expandable code editor in the Create Function panel (#22000)
* Refactor and remove the CreateFunctionStore.

* Fix a duplicate key in the functions table.

* More fixes for the create-function form.

* Add excluded schemas to schema selector.

* Cleanup the createFunction code after the merge.

* Remove unneeded wrapper fragments.

* Minor fixes for the FormItemLayout stories.

* Refactor the CreateFunction panel using the new FormItemLayout.

* Revert the migration to use FormItemLayout. Will revisit later.

* Add a CSS class for popover content width to match its trigger width. Use it on the schema selector.

* Replace all listboxes with selects.

* Fix the comments.

* Switch to FormItemLayout wherever possible.

* Move the createFunction file to its own folder.

* Refactor the panel to use shadcn components: Sheet, SheetContent and SheetHeader.

* Add showClose prop to the Sheet component.

* Add function editor and a feature to maximize/minimize the code editor.

* Some fixes

* Add sameWidthAsTrigger to the popover component.

* Fix the icon size.

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-03-15 10:36:48 +01:00

60 lines
1.6 KiB
TypeScript

import { Maximize2, Minimize2 } from 'lucide-react'
import SqlEditor from 'components/ui/SqlEditor'
import {
Button,
FormControl_Shadcn_,
TooltipContent_Shadcn_,
TooltipTrigger_Shadcn_,
Tooltip_Shadcn_,
cn,
} from 'ui'
export const FunctionEditor = ({
field,
focused,
setFocused,
}: {
field: any
focused: boolean
setFocused: (b: boolean) => void
}) => {
return (
<div className={cn('rounded-md relative group flex-grow')}>
<FormControl_Shadcn_>
<SqlEditor
defaultValue={field.value}
onInputChange={(value: string | undefined) => {
field.onChange(value)
}}
contextmenu={false}
/>
</FormControl_Shadcn_>
<div
className={cn(
'absolute top-0 right-2 bg-surface-300 border border-strong rounded h-[28px]',
'opacity-0 group-hover:opacity-100 group-hover:top-2 transition-all'
)}
>
<Tooltip_Shadcn_>
<TooltipTrigger_Shadcn_ asChild>
<Button
type="text"
size="tiny"
className={cn(
'px-2 text-foreground-lighter hover:text-foreground',
'transition z-50'
)}
onClick={() => setFocused(!focused)}
icon={focused ? <Minimize2 /> : <Maximize2 />}
></Button>
</TooltipTrigger_Shadcn_>
<TooltipContent_Shadcn_ side="bottom">
{focused ? 'Minimize editor' : 'Maximize editor'}
</TooltipContent_Shadcn_>
</Tooltip_Shadcn_>
</div>
</div>
)
}