From bca874fd3017635d51a917c8f542327a36052c0e Mon Sep 17 00:00:00 2001 From: Maofeng Date: Mon, 28 Sep 2026 23:13:39 +0800 Subject: [PATCH] feat(ui): expose typed overlay handles --- packages/ui/src/components/alert-dialog.tsx | 16 ++++++++++++++-- packages/ui/src/components/drawer.tsx | 9 ++++++--- packages/ui/src/components/sheet.tsx | 13 ++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/ui/src/components/alert-dialog.tsx b/packages/ui/src/components/alert-dialog.tsx index 4bf3293..2211ae4 100644 --- a/packages/ui/src/components/alert-dialog.tsx +++ b/packages/ui/src/components/alert-dialog.tsx @@ -4,11 +4,21 @@ import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog import { cn } from "../lib/utils" import { Button } from "./button" -function AlertDialog({ ...props }: AlertDialogPrimitive.Root.Props) { +type AlertDialogHandle = AlertDialogPrimitive.Handle + +function createAlertDialogHandle(): AlertDialogHandle { + return AlertDialogPrimitive.createHandle() +} + +function AlertDialog({ + ...props +}: AlertDialogPrimitive.Root.Props) { return } -function AlertDialogTrigger({ ...props }: AlertDialogPrimitive.Trigger.Props) { +function AlertDialogTrigger({ + ...props +}: AlertDialogPrimitive.Trigger.Props) { return ( ) @@ -170,6 +180,7 @@ function AlertDialogCancel({ } export { + type AlertDialogHandle, AlertDialog, AlertDialogAction, AlertDialogCancel, @@ -182,4 +193,5 @@ export { AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger, + createAlertDialogHandle, } diff --git a/packages/ui/src/components/drawer.tsx b/packages/ui/src/components/drawer.tsx index c650f8c..b7449eb 100644 --- a/packages/ui/src/components/drawer.tsx +++ b/packages/ui/src/components/drawer.tsx @@ -30,13 +30,13 @@ function createDrawerHandle(): DrawerHandle { return DrawerPrimitive.createHandle() } -function Drawer({ +function Drawer({ modal = true, showSwipeHandle = false, snapPoints, swipeDirection = "down", ...props -}: DrawerPrimitive.Root.Props & { +}: DrawerPrimitive.Root.Props & { showSwipeHandle?: boolean }) { const hasSnapPoints = snapPoints != null && snapPoints.length > 0 @@ -58,7 +58,9 @@ function Drawer({ ) } -function DrawerTrigger({ ...props }: DrawerPrimitive.Trigger.Props) { +function DrawerTrigger({ + ...props +}: DrawerPrimitive.Trigger.Props) { return } @@ -217,6 +219,7 @@ function DrawerDescription({ } export { + type DrawerHandle, Drawer, DrawerPortal, DrawerOverlay, diff --git a/packages/ui/src/components/sheet.tsx b/packages/ui/src/components/sheet.tsx index 8cf80bb..58a7cf3 100644 --- a/packages/ui/src/components/sheet.tsx +++ b/packages/ui/src/components/sheet.tsx @@ -8,15 +8,21 @@ import { Button } from "./button" import { XIcon } from "./icon" import { LocalizedText, uiMessages } from "./i18n" -function createSheetHandle(): SheetPrimitive.Handle { +type SheetHandle = SheetPrimitive.Handle + +function createSheetHandle(): SheetHandle { return SheetPrimitive.createHandle() } -function Sheet({ ...props }: SheetPrimitive.Root.Props) { +function Sheet({ + ...props +}: SheetPrimitive.Root.Props) { return } -function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) { +function SheetTrigger({ + ...props +}: SheetPrimitive.Trigger.Props) { return } @@ -130,6 +136,7 @@ function SheetDescription({ } export { + type SheetHandle, Sheet, SheetTrigger, SheetClose,