Open source CapCut alternative.
TypeScript
fix(site): keep a dialog's header and footer in view while its body scrolls
David Lee11d8e9ce4c8
diff --git a/site/src/app/su/experiments/ExperimentDialog.tsx b/site/src/app/su/experiments/ExperimentDialog.tsxindex decc967b..55ba1484 100644--- a/site/src/app/su/experiments/ExperimentDialog.tsx+++ b/site/src/app/su/experiments/ExperimentDialog.tsx@@ -15,6 +15,7 @@ import { Field } from "@/app/su/Field";import { Button } from "@/components/ui/button";import {Dialog,+ DialogBody,DialogContent,DialogDescription,DialogFooter,@@ -146,7 +147,7 @@ export function ExperimentDialog({return (<Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-3xl">+ <DialogContent className="sm:max-w-3xl"><DialogHeader><DialogTitle>{existing ? "Edit experiment" : "New experiment"}</DialogTitle><DialogDescription>@@ -155,7 +156,7 @@ export function ExperimentDialog({</DialogDescription></DialogHeader>- <div className="grid gap-5">+ <DialogBody className="grid gap-5"><div className="grid grid-cols-2 gap-3"><Field label="Key" htmlFor="exp-key"><Input@@ -362,7 +363,7 @@ export function ExperimentDialog({))}</ul>) : null}- </div>+ </DialogBody><DialogFooter><Button variant="outline" onClick={() => onOpenChange(false)}>diff --git a/site/src/app/su/promotions/PromotionDialog.tsx b/site/src/app/su/promotions/PromotionDialog.tsxindex 95eed1c5..f83ca9ad 100644--- a/site/src/app/su/promotions/PromotionDialog.tsx+++ b/site/src/app/su/promotions/PromotionDialog.tsx@@ -14,6 +14,7 @@ import { Field } from "@/app/su/Field";import { Button } from "@/components/ui/button";import {Dialog,+ DialogBody,DialogContent,DialogDescription,DialogFooter,@@ -283,7 +284,7 @@ export function PromotionDialog({return (<Dialog open={open} onOpenChange={onOpenChange}>- <DialogContent className="max-h-[90vh] overflow-y-auto sm:max-w-6xl">+ <DialogContent className="sm:max-w-6xl"><DialogHeader><DialogTitle>{readOnly ? draft.name : existing ? "Edit promotion" : "New promotion"}</DialogTitle><DialogDescription>@@ -306,7 +307,7 @@ export function PromotionDialog({) : null}</DialogHeader>- <div className="grid gap-5 lg:grid-cols-2 lg:gap-8">+ <DialogBody className="grid gap-5 lg:grid-cols-2 lg:gap-8"><div className="grid content-start gap-5"><Field label="Name" htmlFor="promo-name"><Input@@ -467,7 +468,7 @@ export function PromotionDialog({) : null}{notice ? <p className="text-sm text-muted-foreground">{notice}</p> : null}</div>- </div>+ </DialogBody><DialogFooter className="gap-2 sm:justify-between"><Button type="button" variant="outline" disabled={busy} onClick={onTest}>diff --git a/site/src/components/ui/dialog.tsx b/site/src/components/ui/dialog.tsxindex 03d0c60f..82bc2156 100644--- a/site/src/components/ui/dialog.tsx+++ b/site/src/components/ui/dialog.tsx@@ -55,7 +55,7 @@ function DialogContent({<DialogPrimitive.Popupdata-slot="dialog-content"className={cn(- "fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",+ "fixed top-1/2 left-1/2 z-50 flex max-h-[calc(100vh-2rem)] w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",className)}{...props}@@ -92,6 +92,18 @@ function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {)}+// The part of a dialog that scrolls. The header, its close button and the+// footer stay in place whatever the body's height.+function DialogBody({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="dialog-body"+ className={cn("-mx-4 -my-1 min-h-0 flex-1 overflow-y-auto px-4 py-1", className)}+ {...props}+ />+ )+}+function DialogFooter({className,showCloseButton = false,@@ -155,6 +167,7 @@ export {DialogDescription,DialogFooter,DialogHeader,+ DialogBody,DialogOverlay,DialogPortal,DialogTitle,