Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(sql-editor): framer motion

Greg Richardsone7b9b0e07793
diff --git a/package-lock.json b/package-lock.json
index 4c5343a3296..f0146dee490 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -30235,8 +30235,7 @@
"node_modules/monaco-editor": {
"version": "0.33.0",
"resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.33.0.tgz",
- "integrity": "sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw==",
- "peer": true
+ "integrity": "sha512-VcRWPSLIUEgQJQIE0pVT8FcGBIgFoxz7jtqctE+IiCxWugD0DwgyQBcZBhdSrdMC84eumoqMZsGl2GTreOzwqw=="
},
"node_modules/moo": {
"version": "0.5.2",
@@ -43418,6 +43417,7 @@
"dayjs": "^1.11.7",
"eslint-config-next": "^13.3.0",
"file-saver": "^2.0.5",
+ "framer-motion": "^6.5.1",
"generate-password": "^1.7.0",
"graphql": "^16.6.0",
"graphql-ws": "^5.11.3",
diff --git a/studio/components/interfaces/SQLEditor/AskAIWidget.tsx b/studio/components/interfaces/SQLEditor/AskAIWidget.tsx
index ec885d9a11d..983506579b3 100644
--- a/studio/components/interfaces/SQLEditor/AskAIWidget.tsx
+++ b/studio/components/interfaces/SQLEditor/AskAIWidget.tsx
@@ -1,3 +1,4 @@
+import { motion } from 'framer-motion'
import { useCallback } from 'react'
import { AiIcon, IconCornerDownLeft, Input } from 'ui'
@@ -10,23 +11,29 @@ const AskAIWidget = () => {
}, [])
return (
- <div className="bg-scale-200 rounded-md p-2 my-2 border border-scale-700 shadow-xl shadow-scale-100 flex flex-col gap-2 text-sm text-scale-1100 max-w-xl">
- <Input
- inputRef={inputRef}
- size="xlarge"
- icon={<AiIcon className="w-4 h-4 ml-1" />}
- inputClassName="bg-scale-100 placeholder:text-scale-900 rounded-sm focus:!border-brand-900"
- iconContainerClassName="transition text-scale-800 peer-focus/input:text-brand-900"
- placeholder="Ask Supabase AI to do something"
- autoFocus
- actions={
- <div className="flex items-center space-x-1 mr-4">
- <IconCornerDownLeft size={16} strokeWidth={1.5} />
- </div>
- }
- />
+ <motion.div
+ initial={{ y: -50 }}
+ animate={{ y: 0 }}
+ className="bg-scale-200 rounded-md p-2 my-2 border border-scale-700 shadow-xl shadow-scale-100 flex flex-col gap-2 text-sm text-scale-1100 max-w-xl"
+ >
+ <motion.div initial={{ y: -25 }} animate={{ y: 0 }}>
+ <Input
+ inputRef={inputRef}
+ size="xlarge"
+ icon={<AiIcon className="w-4 h-4 ml-1" />}
+ inputClassName="bg-scale-100 placeholder:text-scale-900 rounded-sm focus:!border-brand-900"
+ iconContainerClassName="transition text-scale-800 peer-focus/input:text-brand-900"
+ placeholder="Ask Supabase AI to build a query"
+ autoFocus
+ actions={
+ <div className="flex items-center space-x-1 mr-4">
+ <IconCornerDownLeft size={16} strokeWidth={1.5} />
+ </div>
+ }
+ />
+ </motion.div>
AI generated code may be incorrect.
- </div>
+ </motion.div>
)
}
diff --git a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx b/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
index 9a75b0d7b18..512c0a02f30 100644
--- a/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
@@ -13,9 +13,18 @@ export type MonacoEditorProps = {
editorRef: MutableRefObject<IStandaloneCodeEditor | null>
isExecuting: boolean
executeQuery: () => void
+ onOpenAiWidget?: () => void
+ onCloseAiWidget?: () => void
}
-const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditorProps) => {
+const MonacoEditor = ({
+ id,
+ editorRef,
+ isExecuting,
+ executeQuery,
+ onOpenAiWidget,
+ onCloseAiWidget,
+}: MonacoEditorProps) => {
const snap = useSqlEditorStateSnapshot({ sync: true })
const snippet = snap.snippets[id]
@@ -61,6 +70,7 @@ const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditor
if (selection) {
setAiWidgetSelection(selection)
setIsAiWidgetOpen(true)
+ onOpenAiWidget?.()
}
},
})
@@ -87,6 +97,7 @@ const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditor
function onKeyDown(e: KeyboardEvent) {
if (e.key === 'Escape') {
setIsAiWidgetOpen(false)
+ onCloseAiWidget?.()
editor?.focus()
}
}
@@ -96,7 +107,7 @@ const MonacoEditor = ({ id, editorRef, isExecuting, executeQuery }: MonacoEditor
return () => {
window.removeEventListener('keydown', onKeyDown)
}
- }, [editor, isAiWidgetOpen])
+ }, [editor, isAiWidgetOpen, onCloseAiWidget])
function handleEditorChange(value: string | undefined) {
if (id && value) snap.setSql(id, value)
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index ee2d40e492e..8c7743268ac 100644
--- a/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -1,11 +1,11 @@
import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
+import { motion } from 'framer-motion'
import { useLocalStorage } from 'hooks'
import useLatest from 'hooks/misc/useLatest'
-import { detectOS } from 'lib/helpers'
import dynamic from 'next/dynamic'
-import { useCallback, useRef } from 'react'
+import { useCallback, useRef, useState } from 'react'
import Split from 'react-split'
import { getSqlEditorStateSnapshot, useSqlEditorStateSnapshot } from 'state/sql-editor'
import { AiIcon, IconCornerDownLeft, Input } from 'ui'
@@ -86,23 +86,32 @@ const SQLEditor = () => {
}
}, [isExecuting, project])
- const os = detectOS()
+ const [isAiWidgetOpen, setIsAiWidgetOpen] = useState(false)
return (
<div className="flex h-full flex-col">
- <Input
- size="xlarge"
- icon={<AiIcon className="w-4 h-4 ml-1" />}
- inputClassName="bg-transparent rounded-none focus:border-brand-900"
- iconContainerClassName="transition text-scale-800 peer-focus/input:text-brand-900"
- placeholder="Ask Supabase AI to do something"
- actions={
- <div className="flex items-center space-x-1 mr-6">
- {os === 'macos' ? <OptionIcon /> : <p className="text-xs text-scale-1100">ALT</p>}
- <IconCornerDownLeft size={16} strokeWidth={1.5} />
- </div>
- }
- />
+ {!isAiWidgetOpen && (
+ <motion.div
+ layoutId="ask-ai-input"
+ initial={{ scaleY: 1, y: 50 }}
+ animate={{ scaleY: 1, y: 0 }}
+ className="w-full flex justify-center z-[1000] mt-0.5"
+ >
+ <Input
+ size="xlarge"
+ icon={<AiIcon className="w-4 h-4 ml-1" />}
+ inputClassName="py-4 !bg-scale-200 !border-brand-900"
+ iconContainerClassName="transition text-scale-800 text-brand-900"
+ placeholder="Ask Supabase AI to build a query"
+ className="w-full"
+ actions={
+ <div className="flex items-center space-x-1 mr-6">
+ <IconCornerDownLeft size={16} strokeWidth={1.5} />
+ </div>
+ }
+ />
+ </motion.div>
+ )}
<Split
style={{ height: '100%' }}
direction="vertical"
@@ -114,7 +123,10 @@ const SQLEditor = () => {
collapsed={isUtilityPanelCollapsed ? 1 : undefined}
onDragEnd={onDragEnd}
>
- <div className="dark:border-dark flex-grow overflow-y-auto border-b">
+ <motion.div
+ layout="position"
+ className="dark:border-dark flex-grow overflow-y-auto border-b"
+ >
{isLoading ? (
<div className="flex h-full w-full items-center justify-center">Loading...</div>
) : (
@@ -123,9 +135,11 @@ const SQLEditor = () => {
editorRef={editorRef}
isExecuting={isExecuting}
executeQuery={executeQuery}
+ onOpenAiWidget={() => setIsAiWidgetOpen(true)}
+ onCloseAiWidget={() => setIsAiWidgetOpen(false)}
/>
)}
- </div>
+ </motion.div>
<div className="flex flex-col">
{isLoading ? (
<div className="flex h-full w-full items-center justify-center">Loading...</div>
diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
index 95fbc9e51d2..a17307cfde5 100644
--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
@@ -5,6 +5,7 @@ import { observer } from 'mobx-react-lite'
import { useParams, useTelemetryProps } from 'common'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'
import { SqlSnippet } from 'data/content/sql-snippets-query'
+import { motion } from 'framer-motion'
import { useCheckPermissions, useStore } from 'hooks'
import { uuidv4 } from 'lib/helpers'
import { useProfile } from 'lib/profile'
@@ -56,21 +57,34 @@ const SQLTemplates = observer(() => {
return (
<div className="block h-full space-y-8 overflow-y-auto p-6">
<div className="mt-32 mb-32 flex flex-col items-center">
- <h1 className="text-scale-1200 mb-8 text-3xl">What do you want to build?</h1>
- <Input
- size="xlarge"
- inputRef={(inputElement: HTMLInputElement) => inputElement?.focus()}
- icon={<AiIcon className="w-4 h-4 ml-1" />}
- inputClassName=" w-full !border-brand-900 py-4"
- iconContainerClassName="transition text-scale-800 text-brand-900"
- placeholder="Ask Supabase AI to build a query"
- className="w-full max-w-2xl"
- actions={
- <div className="flex items-center space-x-1 mr-6">
- <IconCornerDownLeft size={16} strokeWidth={1.5} />
- </div>
- }
- />
+ <motion.h1
+ className="text-scale-1200 mb-8 text-3xl"
+ initial={{ y: 10, opacity: 0 }}
+ animate={{ y: 0, opacity: 1 }}
+ >
+ What do you want to build?
+ </motion.h1>
+ <motion.div
+ layoutId="ask-ai-input"
+ className="w-full flex justify-center"
+ initial={{ y: -50, opacity: 0 }}
+ animate={{ y: 0, opacity: 1 }}
+ >
+ <Input
+ size="xlarge"
+ inputRef={(inputElement: HTMLInputElement) => inputElement?.focus()}
+ icon={<AiIcon className="w-4 h-4 ml-1" />}
+ inputClassName=" w-full !border-brand-900 py-4"
+ iconContainerClassName="transition text-scale-800 text-brand-900"
+ placeholder="Ask Supabase AI to build a query"
+ className="w-full max-w-2xl"
+ actions={
+ <div className="flex items-center space-x-1 mr-6">
+ <IconCornerDownLeft size={16} strokeWidth={1.5} />
+ </div>
+ }
+ />
+ </motion.div>
</div>
<div>
<div className="mb-4">
diff --git a/studio/package.json b/studio/package.json
index 3239007bea6..f8ce2b18691 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -50,6 +50,7 @@
"dayjs": "^1.11.7",
"eslint-config-next": "^13.3.0",
"file-saver": "^2.0.5",
+ "framer-motion": "^6.5.1",
"generate-password": "^1.7.0",
"graphql": "^16.6.0",
"graphql-ws": "^5.11.3",