Skip to content

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

Feat/non centered dialog option (#29776)

Jonathan Summers-Muir637167a27b87
diff --git a/apps/design-system/__registry__/index.tsx b/apps/design-system/__registry__/index.tsx
index 1eb10a6990e..ba7caca35fa 100644
--- a/apps/design-system/__registry__/index.tsx
+++ b/apps/design-system/__registry__/index.tsx
@@ -654,6 +654,17 @@ export const Index: Record<string, any> = {
subcategory: "undefined",
chunks: []
},
+ "dialog-centered-off": {
+ name: "dialog-centered-off",
+ type: "components:example",
+ registryDependencies: ["dialog","button"],
+ component: React.lazy(() => import("@/registry/default/example/dialog-centered-off")),
+ source: "",
+ files: ["registry/default/example/dialog-centered-off.tsx"],
+ category: "undefined",
+ subcategory: "undefined",
+ chunks: []
+ },
"drawer-demo": {
name: "drawer-demo",
type: "components:example",
diff --git a/apps/design-system/content/docs/components/dialog.mdx b/apps/design-system/content/docs/components/dialog.mdx
index 47d29e96eb6..b8f9ae549d6 100644
--- a/apps/design-system/content/docs/components/dialog.mdx
+++ b/apps/design-system/content/docs/components/dialog.mdx
@@ -13,44 +13,6 @@ source:
<ComponentPreview name="dialog-demo" peekCode wide />
-## Installation
-
-<Tabs defaultValue="cli">
-
-<TabsList>
- <TabsTrigger value="cli">CLI</TabsTrigger>
- <TabsTrigger value="manual">Manual</TabsTrigger>
-</TabsList>
-<TabsContent value="cli">
-
-```bash
-npx shadcn-ui@latest add dialog
-```
-
-</TabsContent>
-
-<TabsContent value="manual">
-
-<Steps>
-
-<Step>Install the following dependencies:</Step>
-
-```bash
-npm install @radix-ui/react-dialog
-```
-
-<Step>Copy and paste the following code into your project.</Step>
-
-<ComponentSource name="dialog" />
-
-<Step>Update the import paths to match your project setup.</Step>
-
-</Steps>
-
-</TabsContent>
-
-</Tabs>
-
## Usage
```tsx
@@ -85,6 +47,23 @@ import {
<ComponentPreview name="dialog-close-button" />
+### Centered behaviour
+
+You can control whether the dialog is centered by passing `centered={false}` to the `DialogContent` component.
+
+```tsx {3}
+<Dialog>
+ <ContextMenuTrigger>Click here</ContextMenuTrigger>
+ <DialogContent centered={false}>
+ {/*
+ * Content in here
+ */}
+ </DialogContent>
+</Dialog>
+```
+
+<ComponentPreview name="dialog-centered-off" />
+
## Notes
To activate the `Dialog` component from within a `Context Menu` or `Dropdown Menu`, you must encase the `Context Menu` or
@@ -93,7 +72,7 @@ To activate the `Dialog` component from within a `Context Menu` or `Dropdown Men
```tsx {14-25}
<Dialog>
<ContextMenu>
- <ContextMenuTrigger>Right click</ContextMenuTrigger>
+ <ContextMenuTrigger>Dialog not centered</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Open</ContextMenuItem>
<ContextMenuItem>Download</ContextMenuItem>
diff --git a/apps/design-system/registry/default/example/dialog-centered-off.tsx b/apps/design-system/registry/default/example/dialog-centered-off.tsx
new file mode 100644
index 00000000000..54713321a25
--- /dev/null
+++ b/apps/design-system/registry/default/example/dialog-centered-off.tsx
@@ -0,0 +1,46 @@
+import { Button, DialogSection, DialogSectionSeparator } from 'ui'
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from 'ui'
+import { Input_Shadcn_ } from 'ui'
+import { Label_Shadcn_ } from 'ui'
+
+export default function DialogDemo() {
+ return (
+ <Dialog>
+ <DialogTrigger asChild>
+ <Button type="default">Edit Profile</Button>
+ </DialogTrigger>
+ <DialogContent className="sm:max-w-[425px]" centered={false}>
+ <DialogHeader padding={'small'}>
+ <DialogTitle>This dialog is not centered.</DialogTitle>
+ <DialogDescription>This dialog is not centered.</DialogDescription>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <DialogSection className="space-y-4" padding={'small'}>
+ <div>
+ <Label_Shadcn_ htmlFor="name" className="text-right">
+ Name
+ </Label_Shadcn_>
+ <Input_Shadcn_ id="name" defaultValue="Pedro Duarte" className="col-span-3" />
+ </div>
+ <div>
+ <Label_Shadcn_ htmlFor="username" className="text-right">
+ Username
+ </Label_Shadcn_>
+ <Input_Shadcn_ id="username" defaultValue="@peduarte" className="col-span-3" />
+ </div>
+ </DialogSection>
+ <DialogFooter padding={'small'}>
+ <Button htmlType="submit">Save changes</Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/apps/design-system/registry/examples.ts b/apps/design-system/registry/examples.ts
index cd11b55aee5..eab719afe0e 100644
--- a/apps/design-system/registry/examples.ts
+++ b/apps/design-system/registry/examples.ts
@@ -431,6 +431,12 @@ export const examples: Registry = [
registryDependencies: ['dialog', 'button'],
files: ['example/dialog-close-button.tsx'],
},
+ {
+ name: 'dialog-centered-off',
+ type: 'components:example',
+ registryDependencies: ['dialog', 'button'],
+ files: ['example/dialog-centered-off.tsx'],
+ },
{
name: 'drawer-demo',
type: 'components:example',
diff --git a/apps/studio/components/interfaces/Home/Connect/Connect.tsx b/apps/studio/components/interfaces/Home/Connect/Connect.tsx
index 2478ade775a..71517f29d5f 100644
--- a/apps/studio/components/interfaces/Home/Connect/Connect.tsx
+++ b/apps/studio/components/interfaces/Home/Connect/Connect.tsx
@@ -150,7 +150,7 @@ const Connect = () => {
<span>Connect</span>
</Button>
</DialogTrigger>
- <DialogContent className={cn('sm:max-w-5xl p-0')}>
+ <DialogContent className={cn('sm:max-w-5xl p-0')} centered={false}>
<DialogHeader className="pb-3">
<DialogTitle>Connect to your project</DialogTitle>
<DialogDescription>
diff --git a/packages/ui/src/components/shadcn/ui/dialog.tsx b/packages/ui/src/components/shadcn/ui/dialog.tsx
index c87b4f5ebf7..2fecce3a366 100644
--- a/packages/ui/src/components/shadcn/ui/dialog.tsx
+++ b/packages/ui/src/components/shadcn/ui/dialog.tsx
@@ -37,13 +37,14 @@ DialogPortal.displayName = DialogPrimitive.Portal.displayName
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
- React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
->(({ className, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> & { centered?: boolean }
+>(({ className, centered = true, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
'bg-black/40 backdrop-blur-sm',
- 'z-50 fixed inset-0 grid place-items-center overflow-y-auto data-closed:animate-overlay-hide',
+ 'z-50 fixed inset-0 grid place-items-center overflow-y-auto data-closed:animate-overlay-hide py-8',
+ !centered && 'flex flex-col flex-start pb-8 sm:pt-12 md:pt-20 lg:pt-32 xl:pt-40 px-5',
className
)}
{...props}
@@ -53,8 +54,7 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
const DialogContentVariants = cva(
cn(
- 'my-8',
- 'relative z-50 grid w-full border shadow-md dark:shadow-sm duration-200',
+ 'relative z-50 w-full border shadow-md dark:shadow-sm',
'data-[state=open]:animate-in data-[state=closed]:animate-out',
'data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95',
'data-[state=closed]:slide-out-to-left-[0%] data-[state=closed]:slide-out-to-top-[0%]',
@@ -86,26 +86,32 @@ const DialogContent = React.forwardRef<
VariantProps<typeof DialogContentVariants> & {
hideClose?: boolean
dialogOverlayProps?: React.ComponentPropsWithoutRef<typeof DialogOverlay>
+ centered?: boolean
}
->(({ className, children, size, hideClose, dialogOverlayProps, ...props }, ref) => (
- <DialogPortal>
- <DialogOverlay {...dialogOverlayProps}>
- <DialogPrimitive.Content
- ref={ref}
- className={cn(DialogContentVariants({ size }), className)}
- {...props}
- >
- {children}
- {!hideClose && (
- <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-20 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-foreground-muted">
- <X className="h-4 w-4" />
- <span className="sr-only">Close</span>
- </DialogPrimitive.Close>
- )}
- </DialogPrimitive.Content>
- </DialogOverlay>
- </DialogPortal>
-))
+>(
+ (
+ { className, children, size, hideClose, dialogOverlayProps, centered = true, ...props },
+ ref
+ ) => (
+ <DialogPortal>
+ <DialogOverlay centered={centered} {...dialogOverlayProps}>
+ <DialogPrimitive.Content
+ ref={ref}
+ className={cn(DialogContentVariants({ size }), className)}
+ {...props}
+ >
+ {children}
+ {!hideClose && (
+ <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-20 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-foreground-muted">
+ <X className="h-4 w-4" />
+ <span className="sr-only">Close</span>
+ </DialogPrimitive.Close>
+ )}
+ </DialogPrimitive.Content>
+ </DialogOverlay>
+ </DialogPortal>
+ )
+)
DialogContent.displayName = DialogPrimitive.Content.displayName
const DialogHeader = React.forwardRef<