@evinvest/uikit 0.25.0 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,7 +66,7 @@ function AlertDialogOverlay({ className, ...props }) {
66
66
  function AlertDialogContent({ className, children, ...props }) {
67
67
  const { open, setOpen, triggerRef } = useAlertDialog();
68
68
  const { isPresent, ref: presRef } = usePresence(open);
69
- const focusRef = useFocusScope(open);
69
+ const focusRef = useFocusScope(open, { returnFocusTo: triggerRef });
70
70
  const dismissRef = useDismissableLayer({
71
71
  enabled: open,
72
72
  onDismiss: () => setOpen(false),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/alert-dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { buttonVariants } from \"./button\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n ALERT_DIALOG_CONTENT,\n ALERT_DIALOG_DESCRIPTION,\n ALERT_DIALOG_FOOTER,\n ALERT_DIALOG_HEADER,\n ALERT_DIALOG_OVERLAY,\n ALERT_DIALOG_TITLE,\n} from \"../generated/alert-dialog\";\n\ninterface AlertDialogContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst AlertDialogContext = React.createContext<AlertDialogContextValue | null>(null);\n\nfunction useAlertDialog(): AlertDialogContextValue {\n const ctx = React.useContext(AlertDialogContext);\n if (!ctx) throw new Error(\"AlertDialog parts must be used within <AlertDialog>\");\n return ctx;\n}\n\nexport interface AlertDialogProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function AlertDialog({ open, defaultOpen = false, onOpenChange, children }: AlertDialogProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <AlertDialogContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </AlertDialogContext.Provider>\n );\n}\n\nexport interface AlertDialogTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function AlertDialogTrigger({ asChild = false, onClick, ...props }: AlertDialogTriggerProps) {\n const { open, setOpen, triggerRef } = useAlertDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"alert-dialog-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function AlertDialogOverlay({ className, ...props }: AlertDialogOverlayProps) {\n const { open, setOpen } = useAlertDialog();\n return (\n <div\n data-slot=\"alert-dialog-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(ALERT_DIALOG_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogContentProps extends React.ComponentProps<\"div\"> {}\n\nexport function AlertDialogContent({ className, children, ...props }: AlertDialogContentProps) {\n const { open, setOpen, triggerRef } = useAlertDialog();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open);\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n if (!isPresent) return null;\n return (\n <Portal>\n <AlertDialogOverlay />\n <div\n data-slot=\"alert-dialog-content\"\n role=\"alertdialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(ALERT_DIALOG_CONTENT, className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n </div>\n </Portal>\n );\n}\n\nexport function AlertDialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"alert-dialog-header\"\n className={cn(ALERT_DIALOG_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"alert-dialog-footer\"\n className={cn(ALERT_DIALOG_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"alert-dialog-title\"\n className={cn(ALERT_DIALOG_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"alert-dialog-description\"\n className={cn(ALERT_DIALOG_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n\nexport interface AlertDialogActionProps extends React.ComponentProps<\"button\"> {}\n\nexport function AlertDialogAction({ className, onClick, ...props }: AlertDialogActionProps) {\n const { setOpen } = useAlertDialog();\n return (\n <button\n data-slot=\"alert-dialog-action\"\n className={cn(buttonVariants(), className)}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogCancelProps extends React.ComponentProps<\"button\"> {}\n\nexport function AlertDialogCancel({ className, onClick, ...props }: AlertDialogCancelProps) {\n const { setOpen } = useAlertDialog();\n return (\n <button\n data-slot=\"alert-dialog-cancel\"\n className={cn(buttonVariants({ variant: \"outline\" }), className)}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n on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AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,qBAAqB,SAAS;AAAA,MAC3C,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,iBAAiB,EAAE,WAAW,GAAG,MAAM,GAA+B;AACpF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,oBAAoB,SAAS;AAAA,MAC1C,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,uBAAuB,EAAE,WAAW,GAAG,MAAM,GAA8B;AACzF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,0BAA0B,SAAS;AAAA,MAChD,GAAG;AAAA;AAAA,EACN;AAEJ;AAIO,SAAS,kBAAkB,EAAE,WAAW,SAAS,GAAG,MAAM,GAA2B;AAC1F,QAAM,EAAE,QAAQ,IAAI,eAAe;AACnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,GAAG,SAAS;AAAA,MACzC,SAAS,CAAC,MAA2C;AACnD,kBAAU,CAAC;AACX,gBAAQ,KAAK;AAAA,MACf;AAAA,MACC,GAAI;AAAA;AAAA,EACP;AAEJ;AAIO,SAAS,kBAAkB,EAAE,WAAW,SAAS,GAAG,MAAM,GAA2B;AAC1F,QAAM,EAAE,QAAQ,IAAI,eAAe;AACnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,EAAE,SAAS,UAAU,CAAC,GAAG,SAAS;AAAA,MAC/D,SAAS,CAAC,MAA2C;AACnD,kBAAU,CAAC;AACX,gBAAQ,KAAK;AAAA,MACf;AAAA,MACC,GAAI;AAAA;AAAA,EACP;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/alert-dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { buttonVariants } from \"./button\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n ALERT_DIALOG_CONTENT,\n ALERT_DIALOG_DESCRIPTION,\n ALERT_DIALOG_FOOTER,\n ALERT_DIALOG_HEADER,\n ALERT_DIALOG_OVERLAY,\n ALERT_DIALOG_TITLE,\n} from \"../generated/alert-dialog\";\n\ninterface AlertDialogContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst AlertDialogContext = React.createContext<AlertDialogContextValue | null>(null);\n\nfunction useAlertDialog(): AlertDialogContextValue {\n const ctx = React.useContext(AlertDialogContext);\n if (!ctx) throw new Error(\"AlertDialog parts must be used within <AlertDialog>\");\n return ctx;\n}\n\nexport interface AlertDialogProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function AlertDialog({ open, defaultOpen = false, onOpenChange, children }: AlertDialogProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <AlertDialogContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </AlertDialogContext.Provider>\n );\n}\n\nexport interface AlertDialogTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function AlertDialogTrigger({ asChild = false, onClick, ...props }: AlertDialogTriggerProps) {\n const { open, setOpen, triggerRef } = useAlertDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"alert-dialog-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function AlertDialogOverlay({ className, ...props }: AlertDialogOverlayProps) {\n const { open, setOpen } = useAlertDialog();\n return (\n <div\n data-slot=\"alert-dialog-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(ALERT_DIALOG_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogContentProps extends React.ComponentProps<\"div\"> {}\n\nexport function AlertDialogContent({ className, children, ...props }: AlertDialogContentProps) {\n const { open, setOpen, triggerRef } = useAlertDialog();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open, { returnFocusTo: triggerRef });\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n if (!isPresent) return null;\n return (\n <Portal>\n <AlertDialogOverlay />\n <div\n data-slot=\"alert-dialog-content\"\n role=\"alertdialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(ALERT_DIALOG_CONTENT, className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n </div>\n </Portal>\n );\n}\n\nexport function AlertDialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"alert-dialog-header\"\n className={cn(ALERT_DIALOG_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"alert-dialog-footer\"\n className={cn(ALERT_DIALOG_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"alert-dialog-title\"\n className={cn(ALERT_DIALOG_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function AlertDialogDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"alert-dialog-description\"\n className={cn(ALERT_DIALOG_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n\nexport interface AlertDialogActionProps extends React.ComponentProps<\"button\"> {}\n\nexport function AlertDialogAction({ className, onClick, ...props }: AlertDialogActionProps) {\n const { setOpen } = useAlertDialog();\n return (\n <button\n data-slot=\"alert-dialog-action\"\n className={cn(buttonVariants(), className)}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface AlertDialogCancelProps extends React.ComponentProps<\"button\"> {}\n\nexport function AlertDialogCancel({ className, onClick, ...props }: AlertDialogCancelProps) {\n const { setOpen } = useAlertDialog();\n return (\n <button\n data-slot=\"alert-dialog-cancel\"\n className={cn(buttonVariants({ variant: \"outline\" }), className)}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n"],"mappings":";AAkDI,cAuDA,YAvDA;AAhDJ,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,MAAM,qBAAqB,MAAM,cAA8C,IAAI;AAEnF,SAAS,iBAA0C;AACjD,QAAM,MAAM,MAAM,WAAW,kBAAkB;AAC/C,MAAI,CAAC,IAAK,OAAM,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,kBAAkB,EAAE,WAAW,SAAS,GAAG,MAAM,GAA2B;AAC1F,QAAM,EAAE,QAAQ,IAAI,eAAe;AACnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,GAAG,SAAS;AAAA,MACzC,SAAS,CAAC,MAA2C;AACnD,kBAAU,CAAC;AACX,gBAAQ,KAAK;AAAA,MACf;AAAA,MACC,GAAI;AAAA;AAAA,EACP;AAEJ;AAIO,SAAS,kBAAkB,EAAE,WAAW,SAAS,GAAG,MAAM,GAA2B;AAC1F,QAAM,EAAE,QAAQ,IAAI,eAAe;AACnC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,EAAE,SAAS,UAAU,CAAC,GAAG,SAAS;AAAA,MAC/D,SAAS,CAAC,MAA2C;AACnD,kBAAU,CAAC;AACX,gBAAQ,KAAK;AAAA,MACf;AAAA,MACC,GAAI;AAAA;AAAA,EACP;AAEJ;","names":[]}
@@ -86,11 +86,12 @@ function DialogContent({
86
86
  className,
87
87
  children,
88
88
  showCloseButton = true,
89
+ initialFocus = "first",
89
90
  ...props
90
91
  }) {
91
92
  const { open, setOpen, triggerRef } = useDialog();
92
93
  const { isPresent, ref: presRef } = usePresence(open);
93
- const focusRef = useFocusScope(open);
94
+ const focusRef = useFocusScope(open, { initialFocus, returnFocusTo: triggerRef });
94
95
  const dismissRef = useDismissableLayer({
95
96
  enabled: open,
96
97
  onDismiss: () => setOpen(false),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n DIALOG_CLOSE,\n DIALOG_CONTENT,\n DIALOG_DESCRIPTION,\n DIALOG_FOOTER,\n DIALOG_HEADER,\n DIALOG_OVERLAY,\n DIALOG_TITLE,\n} from \"../generated/dialog\";\n\ninterface DialogContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst DialogContext = React.createContext<DialogContextValue | null>(null);\n\nfunction useDialog(): DialogContextValue {\n const ctx = React.useContext(DialogContext);\n if (!ctx) throw new Error(\"Dialog parts must be used within <Dialog>\");\n return ctx;\n}\n\nexport interface DialogProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function Dialog({ open, defaultOpen = false, onOpenChange, children }: DialogProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <DialogContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </DialogContext.Provider>\n );\n}\n\nexport interface DialogTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DialogTrigger({ asChild = false, onClick, ...props }: DialogTriggerProps) {\n const { open, setOpen, triggerRef } = useDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"dialog-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport type DialogPortalProps = { children?: React.ReactNode };\n\nexport function DialogPortal({ children }: DialogPortalProps) {\n return <>{children}</>;\n}\n\nexport interface DialogOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function DialogOverlay({ className, ...props }: DialogOverlayProps) {\n const { open, setOpen } = useDialog();\n return (\n <div\n data-slot=\"dialog-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(DIALOG_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nconst XIcon = (props: React.SVGProps<SVGSVGElement>) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...props}\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n);\n\nexport interface DialogContentProps extends React.ComponentProps<\"div\"> {\n showCloseButton?: boolean;\n}\n\nexport function DialogContent({\n className,\n children,\n showCloseButton = true,\n ...props\n}: DialogContentProps) {\n const { open, setOpen, triggerRef } = useDialog();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open);\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n React.useEffect(() => {\n if (!open) return;\n const prev = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n return () => {\n document.body.style.overflow = prev;\n };\n }, [open]);\n if (!isPresent) return null;\n return (\n <Portal>\n <DialogOverlay />\n <div\n data-slot=\"dialog-content\"\n role=\"dialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(DIALOG_CONTENT, className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n {showCloseButton && (\n <button\n type=\"button\"\n data-slot=\"dialog-close\"\n onClick={() => setOpen(false)}\n className={DIALOG_CLOSE}\n >\n <XIcon />\n <span className=\"sr-only\">Close</span>\n </button>\n )}\n </div>\n </Portal>\n );\n}\n\nexport interface DialogCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DialogClose({ asChild = false, onClick, ...props }: DialogCloseProps) {\n const { setOpen } = useDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"dialog-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport function DialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"dialog-header\"\n className={cn(DIALOG_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function DialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"dialog-footer\"\n className={cn(DIALOG_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function DialogTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"dialog-title\"\n className={cn(DIALOG_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function DialogDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"dialog-description\"\n className={cn(DIALOG_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";AAkDI,SA8BK,UA9BL,KA0GM,YA1GN;AAhDJ,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,MAAM,gBAAgB,MAAM,cAAyC,IAAI;AAEzE,SAAS,YAAgC;AACvC,QAAM,MAAM,MAAM,WAAW,aAAa;AAC1C,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,2CAA2C;AACrE,SAAO;AACT;AASO,SAAS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,KACF;AAEJ;AAMO,SAAS,YAAY,EAAE,UAAU,OAAO,SAAS,GAAG,MAAM,GAAqB;AACpF,QAAM,EAAE,QAAQ,IAAI,UAAU;AAC9B,QAAM,OAAO,UAAU,OAAO;AAC9B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,SAAS,CAAC,MAA2C;AACnD,kBAAU,CAAC;AACX,gBAAQ,KAAK;AAAA,MACf;AAAA,MACC,GAAI;AAAA;AAAA,EACP;AAEJ;AAEO,SAAS,aAAa,EAAE,WAAW,GAAG,MAAM,GAAgC;AACjF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,SAAS;AAAA,MACrC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,aAAa,EAAE,WAAW,GAAG,MAAM,GAAgC;AACjF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,eAAe,SAAS;AAAA,MACrC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,YAAY,EAAE,WAAW,GAAG,MAAM,GAA+B;AAC/E,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,cAAc,SAAS;AAAA,MACpC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,kBAAkB,EAAE,WAAW,GAAG,MAAM,GAA8B;AACpF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,oBAAoB,SAAS;AAAA,MAC1C,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/dialog.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { type InitialFocus, useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n DIALOG_CLOSE,\n DIALOG_CONTENT,\n DIALOG_DESCRIPTION,\n DIALOG_FOOTER,\n DIALOG_HEADER,\n DIALOG_OVERLAY,\n DIALOG_TITLE,\n} from \"../generated/dialog\";\n\ninterface DialogContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst DialogContext = React.createContext<DialogContextValue | null>(null);\n\nfunction useDialog(): DialogContextValue {\n const ctx = React.useContext(DialogContext);\n if (!ctx) throw new Error(\"Dialog parts must be used within <Dialog>\");\n return ctx;\n}\n\nexport interface DialogProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function Dialog({ open, defaultOpen = false, onOpenChange, children }: DialogProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <DialogContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </DialogContext.Provider>\n );\n}\n\nexport interface DialogTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DialogTrigger({ asChild = false, onClick, ...props }: DialogTriggerProps) {\n const { open, setOpen, triggerRef } = useDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"dialog-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport type DialogPortalProps = { children?: React.ReactNode };\n\nexport function DialogPortal({ children }: DialogPortalProps) {\n return <>{children}</>;\n}\n\nexport interface DialogOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function DialogOverlay({ className, ...props }: DialogOverlayProps) {\n const { open, setOpen } = useDialog();\n return (\n <div\n data-slot=\"dialog-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(DIALOG_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nconst XIcon = (props: React.SVGProps<SVGSVGElement>) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...props}\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n);\n\nexport interface DialogContentProps extends React.ComponentProps<\"div\"> {\n showCloseButton?: boolean;\n /** Where focus lands on open. Default `first` — a dialog is usually a short form. */\n initialFocus?: InitialFocus;\n}\n\nexport function DialogContent({\n className,\n children,\n showCloseButton = true,\n initialFocus = \"first\",\n ...props\n}: DialogContentProps) {\n const { open, setOpen, triggerRef } = useDialog();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open, { initialFocus, returnFocusTo: triggerRef });\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n React.useEffect(() => {\n if (!open) return;\n const prev = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n return () => {\n document.body.style.overflow = prev;\n };\n }, [open]);\n if (!isPresent) return null;\n return (\n <Portal>\n <DialogOverlay />\n <div\n data-slot=\"dialog-content\"\n role=\"dialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(DIALOG_CONTENT, className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n {showCloseButton && (\n <button\n type=\"button\"\n data-slot=\"dialog-close\"\n onClick={() => setOpen(false)}\n className={DIALOG_CLOSE}\n >\n <XIcon />\n <span className=\"sr-only\">Close</span>\n </button>\n )}\n </div>\n </Portal>\n );\n}\n\nexport interface DialogCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DialogClose({ asChild = false, onClick, ...props }: DialogCloseProps) {\n const { setOpen } = useDialog();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"dialog-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport function DialogHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"dialog-header\"\n className={cn(DIALOG_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function DialogFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"dialog-footer\"\n className={cn(DIALOG_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function DialogTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"dialog-title\"\n className={cn(DIALOG_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function DialogDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"dialog-description\"\n className={cn(DIALOG_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";AAkDI,SA8BK,UA9BL,KA6GM,YA7GN;AAhDJ,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAA4B,qBAAqB;AACjD,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,M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40,15 +40,17 @@ function Drawer({
40
40
  defaultValue: defaultOpen,
41
41
  ...onOpenChange ? { onChange: onOpenChange } : {}
42
42
  });
43
- return /* @__PURE__ */ jsx(DrawerContext.Provider, { value: { open: isOpen, setOpen, direction }, children: /* @__PURE__ */ jsx("div", { "data-slot": "drawer", children }) });
43
+ const triggerRef = React.useRef(null);
44
+ return /* @__PURE__ */ jsx(DrawerContext.Provider, { value: { open: isOpen, setOpen, direction, triggerRef }, children: /* @__PURE__ */ jsx("div", { "data-slot": "drawer", children }) });
44
45
  }
45
46
  function DrawerTrigger({ asChild = false, onClick, ...props }) {
46
- const { setOpen } = useDrawer();
47
+ const { setOpen, triggerRef } = useDrawer();
47
48
  const Comp = asChild ? Slot : "button";
48
49
  return /* @__PURE__ */ jsx(
49
50
  Comp,
50
51
  {
51
52
  "data-slot": "drawer-trigger",
53
+ ref: triggerRef,
52
54
  onClick: (e) => {
53
55
  onClick?.(e);
54
56
  setOpen(true);
@@ -207,11 +209,11 @@ function useDrawerDrag(opts) {
207
209
  };
208
210
  }
209
211
  function DrawerContent({ className, children, ...props }) {
210
- const { open, setOpen, direction } = useDrawer();
212
+ const { open, setOpen, direction, triggerRef } = useDrawer();
211
213
  const [present, setPresent] = React.useState(open);
212
214
  if (open && !present) setPresent(true);
213
215
  const closing = present && !open;
214
- const scopeRef = useFocusScope(open);
216
+ const scopeRef = useFocusScope(open, { returnFocusTo: triggerRef });
215
217
  const panelRef = React.useRef(null);
216
218
  const scrimRef = React.useRef(null);
217
219
  const openedAtRef = React.useRef(0);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n DRAWER_BODY,\n DRAWER_CONTENT_BASE,\n DRAWER_DESCRIPTION,\n DRAWER_FOOTER,\n DRAWER_HANDLE,\n DRAWER_HEADER,\n DRAWER_OVERLAY,\n DRAWER_TITLE,\n drawerDirectionClasses,\n type DrawerDirection,\n} from \"../generated/drawer\";\n\nexport type { DrawerDirection };\n\n// Drag-to-dismiss tuning (pointer physics, TS-only — Rust stays render-only).\n// Values from Vaul: a release past 25% of the panel's size along the drag\n// axis, or a flick faster than 0.4px/ms, closes; anything short snaps back.\n// Drags are refused for the first 500ms after opening so the enter finishes.\nconst CLOSE_THRESHOLD = 0.25;\nconst VELOCITY_THRESHOLD = 0.4;\nconst DRAG_AFTER_OPEN_MS = 500;\n// The closing node is dropped on its exit `transitionend`; this is the safety\n// net for when that never fires (display:none ancestor, tab hidden, a full\n// drag that left the panel exactly at its off-screen transform). Just past\n// the 500ms transition in motion.css.\nconst EXIT_FALLBACK_MS = 600;\n\ninterface DrawerContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n direction: DrawerDirection;\n}\n\nconst DrawerContext = React.createContext<DrawerContextValue | null>(null);\n\nfunction useDrawer(): DrawerContextValue {\n const ctx = React.useContext(DrawerContext);\n if (!ctx) throw new Error(\"Drawer parts must be used within <Drawer>\");\n return ctx;\n}\n\nexport interface DrawerProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n direction?: DrawerDirection;\n children?: React.ReactNode;\n}\n\nexport function Drawer({\n open,\n defaultOpen = false,\n onOpenChange,\n direction = \"bottom\",\n children,\n}: DrawerProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n return (\n <DrawerContext.Provider value={{ open: isOpen, setOpen, direction }}>\n <div data-slot=\"drawer\">{children}</div>\n </DrawerContext.Provider>\n );\n}\n\nexport interface DrawerTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DrawerTrigger({ asChild = false, onClick, ...props }: DrawerTriggerProps) {\n const { setOpen } = useDrawer();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"drawer-trigger\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface DrawerCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DrawerClose({ asChild = false, onClick, ...props }: DrawerCloseProps) {\n const { setOpen } = useDrawer();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"drawer-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\n/**\n * Standalone scrim, redundant with the one {@link DrawerContent} renders (as in\n * shadcn). Mounted only while open; the animated exit lives on the content's\n * own scrim.\n */\nexport function DrawerOverlay({ className, ...props }: React.ComponentProps<\"div\">) {\n const { open, setOpen } = useDrawer();\n if (!open) return null;\n return (\n <div\n data-slot=\"drawer-overlay\"\n data-state=\"open\"\n onClick={() => setOpen(false)}\n className={cn(DRAWER_OVERLAY, className)}\n {...props}\n />\n );\n}\n\n// Positive delta = the finger moved towards the docked edge (bottom: down,\n// top: up, right: right, left: left), i.e. the closing direction.\nconst EDGE_SIGN: Record<DrawerDirection, 1 | -1> = {\n bottom: 1,\n top: -1,\n right: 1,\n left: -1,\n};\n\nfunction isVertical(direction: DrawerDirection): boolean {\n return direction === \"bottom\" || direction === \"top\";\n}\n\nfunction translateAlong(direction: DrawerDirection, px: number): string {\n return isVertical(direction) ? `translate3d(0, ${px}px, 0)` : `translate3d(${px}px, 0, 0)`;\n}\n\n// Vaul's over-drag curve: the panel barely moves past its docked edge. Only\n// starts displacing once the finger has gone ~6px (log(v + 1) > 2); before\n// that the curve is negative, which reads as \"stay home\".\nfunction dampen(px: number): number {\n return Math.max(8 * (Math.log(px + 1) - 2), 0);\n}\n\n// Vaul's `shouldDrag`, minus snap points. `towardsEdge` false = the user is\n// pulling the panel further open, which on a vertical sheet is the scroll\n// gesture — hand it to the scroller. The scroll walk is vertical-only: a\n// horizontal sheet never competes with its body's vertical scroll.\nfunction shouldDrag(\n target: EventTarget | null,\n panel: HTMLElement,\n direction: DrawerDirection,\n towardsEdge: boolean,\n): boolean {\n if (!(target instanceof Element)) return false;\n if (target.tagName === \"SELECT\") return false; // https://github.com/emilkowalski/vaul/issues/483\n if (target.closest(\"[data-vaul-no-drag]\")) return false;\n if (!isVertical(direction)) return true;\n if (!towardsEdge) return false;\n const selection = window.getSelection?.()?.toString();\n if (selection && selection.length > 0) return false;\n // any scroller between the finger and the panel that isn't at its top owns\n // the gesture; the user can scroll up and the next move re-asks\n let el: Element | null = target;\n while (el && el !== panel) {\n if (el.scrollHeight > el.clientHeight && el.scrollTop > 0) return false;\n el = el.parentElement;\n }\n return true;\n}\n\ninterface DragGesture {\n pointerId: number;\n // the element under the finger at pointerdown — once the panel captures the\n // pointer, every later event's `target` is the panel itself, and the scroll\n // walk in `shouldDrag` would never see the scroller it started in\n target: EventTarget | null;\n start: number; // clientX/Y along the axis\n time: number;\n size: number; // panel extent along the axis, for the close threshold + scrim fade\n allowed: boolean | null; // null = undecided; true sticks for the gesture (Vaul's isAllowedToDrag)\n delta: number;\n}\n\n// ── drag-to-dismiss (Vaul pointer physics) ────────────────────────────────\n// No React state on the hot path: the gesture lives in a ref and every move is\n// one inline `transform` write on the panel plus one `opacity` write on the\n// scrim. Not a CSS var: a custom-property change re-resolves inherited values\n// across the whole subtree, per move.\nfunction useDrawerDrag(opts: {\n panelRef: React.RefObject<HTMLDivElement | null>;\n scrimRef: React.RefObject<HTMLDivElement | null>;\n direction: DrawerDirection;\n open: boolean;\n present: boolean;\n openedAtRef: React.RefObject<number>;\n onClose: () => void;\n}) {\n const { panelRef, scrimRef, direction, open, present, openedAtRef, onClose } = opts;\n const dragRef = React.useRef<DragGesture | null>(null);\n\n // Native scroll suppression. Once a gesture is allowed, the browser must not\n // turn the same touch into a scroll/overscroll of a body sitting at its top —\n // that would pointercancel us mid-drag. Pointer events precede the compat\n // touch events, so `allowed` is already decided when this runs. React's\n // onTouchMove is passive, hence the manual listener.\n React.useEffect(() => {\n if (!present) return;\n const panel = panelRef.current;\n if (!panel) return;\n const onTouchMove = (e: TouchEvent) => {\n if (dragRef.current?.allowed) e.preventDefault();\n };\n panel.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n return () => panel.removeEventListener(\"touchmove\", onTouchMove);\n }, [present, panelRef]);\n\n const axisPos = (e: React.PointerEvent) => (isVertical(direction) ? e.clientY : e.clientX);\n\n const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n const panel = panelRef.current;\n // one gesture at a time: a second finger must not reset the first one's\n // state and leave the panel stranded mid-drag\n if (!panel || e.button > 0 || !open || dragRef.current) return;\n const target = e.target as HTMLElement;\n if (target.closest('[data-slot=\"drawer-close\"]')) return;\n // React bubbles portal events (a Select's listbox, a Popover) through the\n // tree; a drag can only start from the panel's own DOM\n if (!panel.contains(target)) return;\n const rect = panel.getBoundingClientRect();\n dragRef.current = {\n pointerId: e.pointerId,\n target,\n start: axisPos(e),\n time: Date.now(),\n size: isVertical(direction) ? rect.height : rect.width,\n allowed: null,\n delta: 0,\n };\n // Capture on the element under the finger, not the panel (Vaul does the\n // same): a click's target is the common ancestor of pointerdown and\n // pointerup, so capturing on the panel would steal every click from the\n // buttons and links inside. No preventDefault either — inputs inside the\n // sheet must still focus on tap.\n try {\n target.setPointerCapture?.(e.pointerId);\n } catch {\n // jsdom / unsupported — capture is a nice-to-have, the drag works without it\n }\n };\n\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n const panel = panelRef.current;\n if (!drag || !panel) return;\n const delta = (axisPos(e) - drag.start) * EDGE_SIGN[direction];\n drag.delta = delta;\n if (!drag.allowed) {\n if (Date.now() - openedAtRef.current < DRAG_AFTER_OPEN_MS) return;\n // refused on this move only — the user may scroll the body to its top\n // and carry on, so the gesture stays alive\n if (!shouldDrag(drag.target, panel, direction, delta > 0)) return;\n drag.allowed = true;\n panel.setAttribute(\"data-dragging\", \"true\"); // CSS drops the transitions for 1:1 tracking\n scrimRef.current?.setAttribute(\"data-dragging\", \"true\");\n }\n const scrim = scrimRef.current;\n if (delta < 0) {\n panel.style.transform = translateAlong(direction, -dampen(-delta) * EDGE_SIGN[direction]);\n if (scrim) scrim.style.opacity = \"1\";\n return;\n }\n panel.style.transform = translateAlong(direction, delta * EDGE_SIGN[direction]);\n if (scrim) {\n scrim.style.opacity = `${Math.min(1, Math.max(0, 1 - delta / drag.size))}`;\n }\n };\n\n // Release hands styling back to the CSS: with the inline transform gone and\n // data-dragging cleared in the same frame, the restored transition carries\n // the panel from wherever the finger left it — home on a snap-back, or (with\n // data-state=closed committed by `onClose` in the same frame) straight off.\n const endGesture = (e: React.PointerEvent<HTMLDivElement>, cancelled: boolean) => {\n const drag = dragRef.current;\n const panel = panelRef.current;\n if (!drag || !panel || e.pointerId !== drag.pointerId) return;\n dragRef.current = null;\n try {\n (drag.target as HTMLElement).releasePointerCapture?.(drag.pointerId);\n } catch {\n // jsdom / unsupported\n }\n if (!drag.allowed) return;\n panel.removeAttribute(\"data-dragging\");\n panel.style.transform = \"\";\n const scrim = scrimRef.current;\n if (scrim) {\n scrim.removeAttribute(\"data-dragging\");\n scrim.style.opacity = \"\";\n }\n if (cancelled || drag.delta <= 0) return;\n const dt = Date.now() - drag.time;\n const velocity = dt > 0 ? drag.delta / dt : 0;\n if (velocity > VELOCITY_THRESHOLD || drag.delta >= drag.size * CLOSE_THRESHOLD) {\n onClose();\n }\n };\n\n return {\n onPointerDown,\n onPointerMove,\n onPointerUp: (e: React.PointerEvent<HTMLDivElement>) => endGesture(e, false),\n onPointerCancel: (e: React.PointerEvent<HTMLDivElement>) => endGesture(e, true),\n };\n}\n\n/**\n * The panel plus its scrim. Presence outlives `open`: once it turns false the\n * panel flips to `data-state=\"closed\"` and is unmounted when its exit\n * `transform` transition ends (or the fallback timer fires). Re-opening\n * mid-exit just flips the state back and the same transition carries the\n * panel home. Drag-to-dismiss is TS-only pointer physics; opt a region out\n * with `data-vaul-no-drag`.\n */\nexport function DrawerContent({ className, children, ...props }: React.ComponentProps<\"div\">) {\n const { open, setOpen, direction } = useDrawer();\n // Derived during render so the panel is in the same commit that opened it —\n // the enter keyframe plays on insertion, no mount flip needed.\n const [present, setPresent] = React.useState(open);\n if (open && !present) setPresent(true);\n const closing = present && !open;\n\n const scopeRef = useFocusScope(open);\n const panelRef = React.useRef<HTMLDivElement | null>(null);\n const scrimRef = React.useRef<HTMLDivElement | null>(null);\n const openedAtRef = React.useRef(0);\n\n React.useEffect(() => {\n if (open) openedAtRef.current = Date.now();\n }, [open]);\n\n React.useEffect(() => {\n if (!open) return;\n const prev = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n return () => {\n document.body.style.overflow = prev;\n };\n }, [open]);\n\n // Safety net for a missed exit transitionend; the cleanup is what cancels it\n // on re-open.\n React.useEffect(() => {\n if (!closing) return;\n const id = setTimeout(() => setPresent(false), EXIT_FALLBACK_MS);\n return () => clearTimeout(id);\n }, [closing]);\n\n const drag = useDrawerDrag({\n panelRef,\n scrimRef,\n direction,\n open,\n present,\n openedAtRef,\n onClose: () => setOpen(false),\n });\n\n if (!present) return null;\n const state = closing ? \"closed\" : \"open\";\n return (\n <Portal>\n <div\n ref={scrimRef}\n data-slot=\"drawer-overlay\"\n data-state={state}\n className={DRAWER_OVERLAY}\n onClick={() => setOpen(false)}\n />\n <div\n role=\"dialog\"\n aria-modal=\"true\"\n data-slot=\"drawer-content\"\n data-state={state}\n data-vaul-drawer-direction={direction}\n ref={mergeRefs(scopeRef, panelRef)}\n onKeyDown={(e) => {\n if (e.key === \"Escape\") setOpen(false);\n }}\n // transitionend bubbles from children (a hover on a button inside),\n // so pin it to the panel's own exit transform\n onTransitionEnd={(e) => {\n if (closing && e.propertyName === \"transform\" && e.target === e.currentTarget) {\n setPresent(false);\n }\n }}\n onPointerDown={drag.onPointerDown}\n onPointerMove={drag.onPointerMove}\n onPointerUp={drag.onPointerUp}\n onPointerCancel={drag.onPointerCancel}\n className={cn(DRAWER_CONTENT_BASE, drawerDirectionClasses[direction], className)}\n {...(props as Record<string, unknown>)}\n >\n {direction === \"bottom\" ? (\n <div\n data-slot=\"drawer-handle\"\n className={DRAWER_HANDLE}\n />\n ) : null}\n <div\n data-slot=\"drawer-body\"\n className={DRAWER_BODY}\n >\n {children}\n </div>\n </div>\n </Portal>\n );\n}\n\nexport function DrawerHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-header\"\n className={cn(DRAWER_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-footer\"\n className={cn(DRAWER_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerTitle({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-title\"\n className={cn(DRAWER_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerDescription({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-description\"\n className={cn(DRAWER_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";AAyEM,cAiUA,YAjUA;AAvEN,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQP,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;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,MACV,WAAW,GAAG,eAAe,SAAS;AAAA,MACrC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,YAAY,EAAE,WAAW,GAAG,MAAM,GAAgC;AAChF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,cAAc,SAAS;AAAA,MACpC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,kBAAkB,EAAE,WAAW,GAAG,MAAM,GAAgC;AACtF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,oBAAoB,SAAS;AAAA,MAC1C,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/drawer.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n DRAWER_BODY,\n DRAWER_CONTENT_BASE,\n DRAWER_DESCRIPTION,\n DRAWER_FOOTER,\n DRAWER_HANDLE,\n DRAWER_HEADER,\n DRAWER_OVERLAY,\n DRAWER_TITLE,\n drawerDirectionClasses,\n type DrawerDirection,\n} from \"../generated/drawer\";\n\nexport type { DrawerDirection };\n\n// Drag-to-dismiss tuning (pointer physics, TS-only — Rust stays render-only).\n// Values from Vaul: a release past 25% of the panel's size along the drag\n// axis, or a flick faster than 0.4px/ms, closes; anything short snaps back.\n// Drags are refused for the first 500ms after opening so the enter finishes.\nconst CLOSE_THRESHOLD = 0.25;\nconst VELOCITY_THRESHOLD = 0.4;\nconst DRAG_AFTER_OPEN_MS = 500;\n// The closing node is dropped on its exit `transitionend`; this is the safety\n// net for when that never fires (display:none ancestor, tab hidden, a full\n// drag that left the panel exactly at its off-screen transform). Just past\n// the 500ms transition in motion.css.\nconst EXIT_FALLBACK_MS = 600;\n\ninterface DrawerContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n direction: DrawerDirection;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst DrawerContext = React.createContext<DrawerContextValue | null>(null);\n\nfunction useDrawer(): DrawerContextValue {\n const ctx = React.useContext(DrawerContext);\n if (!ctx) throw new Error(\"Drawer parts must be used within <Drawer>\");\n return ctx;\n}\n\nexport interface DrawerProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n direction?: DrawerDirection;\n children?: React.ReactNode;\n}\n\nexport function Drawer({\n open,\n defaultOpen = false,\n onOpenChange,\n direction = \"bottom\",\n children,\n}: DrawerProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <DrawerContext.Provider value={{ open: isOpen, setOpen, direction, triggerRef }}>\n <div data-slot=\"drawer\">{children}</div>\n </DrawerContext.Provider>\n );\n}\n\nexport interface DrawerTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DrawerTrigger({ asChild = false, onClick, ...props }: DrawerTriggerProps) {\n const { setOpen, triggerRef } = useDrawer();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"drawer-trigger\"\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface DrawerCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function DrawerClose({ asChild = false, onClick, ...props }: DrawerCloseProps) {\n const { setOpen } = useDrawer();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"drawer-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\n/**\n * Standalone scrim, redundant with the one {@link DrawerContent} renders (as in\n * shadcn). Mounted only while open; the animated exit lives on the content's\n * own scrim.\n */\nexport function DrawerOverlay({ className, ...props }: React.ComponentProps<\"div\">) {\n const { open, setOpen } = useDrawer();\n if (!open) return null;\n return (\n <div\n data-slot=\"drawer-overlay\"\n data-state=\"open\"\n onClick={() => setOpen(false)}\n className={cn(DRAWER_OVERLAY, className)}\n {...props}\n />\n );\n}\n\n// Positive delta = the finger moved towards the docked edge (bottom: down,\n// top: up, right: right, left: left), i.e. the closing direction.\nconst EDGE_SIGN: Record<DrawerDirection, 1 | -1> = {\n bottom: 1,\n top: -1,\n right: 1,\n left: -1,\n};\n\nfunction isVertical(direction: DrawerDirection): boolean {\n return direction === \"bottom\" || direction === \"top\";\n}\n\nfunction translateAlong(direction: DrawerDirection, px: number): string {\n return isVertical(direction) ? `translate3d(0, ${px}px, 0)` : `translate3d(${px}px, 0, 0)`;\n}\n\n// Vaul's over-drag curve: the panel barely moves past its docked edge. Only\n// starts displacing once the finger has gone ~6px (log(v + 1) > 2); before\n// that the curve is negative, which reads as \"stay home\".\nfunction dampen(px: number): number {\n return Math.max(8 * (Math.log(px + 1) - 2), 0);\n}\n\n// Vaul's `shouldDrag`, minus snap points. `towardsEdge` false = the user is\n// pulling the panel further open, which on a vertical sheet is the scroll\n// gesture — hand it to the scroller. The scroll walk is vertical-only: a\n// horizontal sheet never competes with its body's vertical scroll.\nfunction shouldDrag(\n target: EventTarget | null,\n panel: HTMLElement,\n direction: DrawerDirection,\n towardsEdge: boolean,\n): boolean {\n if (!(target instanceof Element)) return false;\n if (target.tagName === \"SELECT\") return false; // https://github.com/emilkowalski/vaul/issues/483\n if (target.closest(\"[data-vaul-no-drag]\")) return false;\n if (!isVertical(direction)) return true;\n if (!towardsEdge) return false;\n const selection = window.getSelection?.()?.toString();\n if (selection && selection.length > 0) return false;\n // any scroller between the finger and the panel that isn't at its top owns\n // the gesture; the user can scroll up and the next move re-asks\n let el: Element | null = target;\n while (el && el !== panel) {\n if (el.scrollHeight > el.clientHeight && el.scrollTop > 0) return false;\n el = el.parentElement;\n }\n return true;\n}\n\ninterface DragGesture {\n pointerId: number;\n // the element under the finger at pointerdown — once the panel captures the\n // pointer, every later event's `target` is the panel itself, and the scroll\n // walk in `shouldDrag` would never see the scroller it started in\n target: EventTarget | null;\n start: number; // clientX/Y along the axis\n time: number;\n size: number; // panel extent along the axis, for the close threshold + scrim fade\n allowed: boolean | null; // null = undecided; true sticks for the gesture (Vaul's isAllowedToDrag)\n delta: number;\n}\n\n// ── drag-to-dismiss (Vaul pointer physics) ────────────────────────────────\n// No React state on the hot path: the gesture lives in a ref and every move is\n// one inline `transform` write on the panel plus one `opacity` write on the\n// scrim. Not a CSS var: a custom-property change re-resolves inherited values\n// across the whole subtree, per move.\nfunction useDrawerDrag(opts: {\n panelRef: React.RefObject<HTMLDivElement | null>;\n scrimRef: React.RefObject<HTMLDivElement | null>;\n direction: DrawerDirection;\n open: boolean;\n present: boolean;\n openedAtRef: React.RefObject<number>;\n onClose: () => void;\n}) {\n const { panelRef, scrimRef, direction, open, present, openedAtRef, onClose } = opts;\n const dragRef = React.useRef<DragGesture | null>(null);\n\n // Native scroll suppression. Once a gesture is allowed, the browser must not\n // turn the same touch into a scroll/overscroll of a body sitting at its top —\n // that would pointercancel us mid-drag. Pointer events precede the compat\n // touch events, so `allowed` is already decided when this runs. React's\n // onTouchMove is passive, hence the manual listener.\n React.useEffect(() => {\n if (!present) return;\n const panel = panelRef.current;\n if (!panel) return;\n const onTouchMove = (e: TouchEvent) => {\n if (dragRef.current?.allowed) e.preventDefault();\n };\n panel.addEventListener(\"touchmove\", onTouchMove, { passive: false });\n return () => panel.removeEventListener(\"touchmove\", onTouchMove);\n }, [present, panelRef]);\n\n const axisPos = (e: React.PointerEvent) => (isVertical(direction) ? e.clientY : e.clientX);\n\n const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n const panel = panelRef.current;\n // one gesture at a time: a second finger must not reset the first one's\n // state and leave the panel stranded mid-drag\n if (!panel || e.button > 0 || !open || dragRef.current) return;\n const target = e.target as HTMLElement;\n if (target.closest('[data-slot=\"drawer-close\"]')) return;\n // React bubbles portal events (a Select's listbox, a Popover) through the\n // tree; a drag can only start from the panel's own DOM\n if (!panel.contains(target)) return;\n const rect = panel.getBoundingClientRect();\n dragRef.current = {\n pointerId: e.pointerId,\n target,\n start: axisPos(e),\n time: Date.now(),\n size: isVertical(direction) ? rect.height : rect.width,\n allowed: null,\n delta: 0,\n };\n // Capture on the element under the finger, not the panel (Vaul does the\n // same): a click's target is the common ancestor of pointerdown and\n // pointerup, so capturing on the panel would steal every click from the\n // buttons and links inside. No preventDefault either — inputs inside the\n // sheet must still focus on tap.\n try {\n target.setPointerCapture?.(e.pointerId);\n } catch {\n // jsdom / unsupported — capture is a nice-to-have, the drag works without it\n }\n };\n\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const drag = dragRef.current;\n const panel = panelRef.current;\n if (!drag || !panel) return;\n const delta = (axisPos(e) - drag.start) * EDGE_SIGN[direction];\n drag.delta = delta;\n if (!drag.allowed) {\n if (Date.now() - openedAtRef.current < DRAG_AFTER_OPEN_MS) return;\n // refused on this move only — the user may scroll the body to its top\n // and carry on, so the gesture stays alive\n if (!shouldDrag(drag.target, panel, direction, delta > 0)) return;\n drag.allowed = true;\n panel.setAttribute(\"data-dragging\", \"true\"); // CSS drops the transitions for 1:1 tracking\n scrimRef.current?.setAttribute(\"data-dragging\", \"true\");\n }\n const scrim = scrimRef.current;\n if (delta < 0) {\n panel.style.transform = translateAlong(direction, -dampen(-delta) * EDGE_SIGN[direction]);\n if (scrim) scrim.style.opacity = \"1\";\n return;\n }\n panel.style.transform = translateAlong(direction, delta * EDGE_SIGN[direction]);\n if (scrim) {\n scrim.style.opacity = `${Math.min(1, Math.max(0, 1 - delta / drag.size))}`;\n }\n };\n\n // Release hands styling back to the CSS: with the inline transform gone and\n // data-dragging cleared in the same frame, the restored transition carries\n // the panel from wherever the finger left it — home on a snap-back, or (with\n // data-state=closed committed by `onClose` in the same frame) straight off.\n const endGesture = (e: React.PointerEvent<HTMLDivElement>, cancelled: boolean) => {\n const drag = dragRef.current;\n const panel = panelRef.current;\n if (!drag || !panel || e.pointerId !== drag.pointerId) return;\n dragRef.current = null;\n try {\n (drag.target as HTMLElement).releasePointerCapture?.(drag.pointerId);\n } catch {\n // jsdom / unsupported\n }\n if (!drag.allowed) return;\n panel.removeAttribute(\"data-dragging\");\n panel.style.transform = \"\";\n const scrim = scrimRef.current;\n if (scrim) {\n scrim.removeAttribute(\"data-dragging\");\n scrim.style.opacity = \"\";\n }\n if (cancelled || drag.delta <= 0) return;\n const dt = Date.now() - drag.time;\n const velocity = dt > 0 ? drag.delta / dt : 0;\n if (velocity > VELOCITY_THRESHOLD || drag.delta >= drag.size * CLOSE_THRESHOLD) {\n onClose();\n }\n };\n\n return {\n onPointerDown,\n onPointerMove,\n onPointerUp: (e: React.PointerEvent<HTMLDivElement>) => endGesture(e, false),\n onPointerCancel: (e: React.PointerEvent<HTMLDivElement>) => endGesture(e, true),\n };\n}\n\n/**\n * The panel plus its scrim. Presence outlives `open`: once it turns false the\n * panel flips to `data-state=\"closed\"` and is unmounted when its exit\n * `transform` transition ends (or the fallback timer fires). Re-opening\n * mid-exit just flips the state back and the same transition carries the\n * panel home. Drag-to-dismiss is TS-only pointer physics; opt a region out\n * with `data-vaul-no-drag`.\n */\nexport function DrawerContent({ className, children, ...props }: React.ComponentProps<\"div\">) {\n const { open, setOpen, direction, triggerRef } = useDrawer();\n // Derived during render so the panel is in the same commit that opened it —\n // the enter keyframe plays on insertion, no mount flip needed.\n const [present, setPresent] = React.useState(open);\n if (open && !present) setPresent(true);\n const closing = present && !open;\n\n const scopeRef = useFocusScope(open, { returnFocusTo: triggerRef });\n const panelRef = React.useRef<HTMLDivElement | null>(null);\n const scrimRef = React.useRef<HTMLDivElement | null>(null);\n const openedAtRef = React.useRef(0);\n\n React.useEffect(() => {\n if (open) openedAtRef.current = Date.now();\n }, [open]);\n\n React.useEffect(() => {\n if (!open) return;\n const prev = document.body.style.overflow;\n document.body.style.overflow = \"hidden\";\n return () => {\n document.body.style.overflow = prev;\n };\n }, [open]);\n\n // Safety net for a missed exit transitionend; the cleanup is what cancels it\n // on re-open.\n React.useEffect(() => {\n if (!closing) return;\n const id = setTimeout(() => setPresent(false), EXIT_FALLBACK_MS);\n return () => clearTimeout(id);\n }, [closing]);\n\n const drag = useDrawerDrag({\n panelRef,\n scrimRef,\n direction,\n open,\n present,\n openedAtRef,\n onClose: () => setOpen(false),\n });\n\n if (!present) return null;\n const state = closing ? \"closed\" : \"open\";\n return (\n <Portal>\n <div\n ref={scrimRef}\n data-slot=\"drawer-overlay\"\n data-state={state}\n className={DRAWER_OVERLAY}\n onClick={() => setOpen(false)}\n />\n <div\n role=\"dialog\"\n aria-modal=\"true\"\n data-slot=\"drawer-content\"\n data-state={state}\n data-vaul-drawer-direction={direction}\n ref={mergeRefs(scopeRef, panelRef)}\n onKeyDown={(e) => {\n if (e.key === \"Escape\") setOpen(false);\n }}\n // transitionend bubbles from children (a hover on a button inside),\n // so pin it to the panel's own exit transform\n onTransitionEnd={(e) => {\n if (closing && e.propertyName === \"transform\" && e.target === e.currentTarget) {\n setPresent(false);\n }\n }}\n onPointerDown={drag.onPointerDown}\n onPointerMove={drag.onPointerMove}\n onPointerUp={drag.onPointerUp}\n onPointerCancel={drag.onPointerCancel}\n className={cn(DRAWER_CONTENT_BASE, drawerDirectionClasses[direction], className)}\n {...(props as Record<string, unknown>)}\n >\n {direction === \"bottom\" ? (\n <div\n data-slot=\"drawer-handle\"\n className={DRAWER_HANDLE}\n />\n ) : null}\n <div\n data-slot=\"drawer-body\"\n className={DRAWER_BODY}\n >\n {children}\n </div>\n </div>\n </Portal>\n );\n}\n\nexport function DrawerHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-header\"\n className={cn(DRAWER_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-footer\"\n className={cn(DRAWER_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerTitle({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-title\"\n className={cn(DRAWER_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function DrawerDescription({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"drawer-description\"\n className={cn(DRAWER_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";AA2EM,cAkUA,YAlUA;AAzEN,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQP,MAAM,kBAAkB;AACxB,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;AAK3B,MAAM,mBAAmB;AASzB,MAAM,gBAAgB,MAAM,cAAyC,IAAI;AAEzE,SAAS,YAAgC;AACvC,QAAM,MAAM,MAAM,WAAW,aAAa;AAC1C,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,2CAA2C;AACrE,SAAO;AACT;AAUO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA,cAAc;AAAA,EACd;AAAA,EACA,YAAY;AAAA,EACZ;AACF,GAAgB;AACd,QAAM,CAAC,QAAQ,OAAO,IAAI,qBAA8B;AAAA,IACtD,GAAI,SAAS,SAAY,EAAE,OAAO,KAAK,IAAI,CAAC;AAAA,IAC5C,cA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A,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,oBAAoB,SAAS;AAAA,MAC1C,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
@@ -0,0 +1,73 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { cn } from "../lib/cn.js";
4
+ const LIST_ROWS = "flex w-full min-w-0 flex-col divide-y divide-border";
5
+ const listRowsVariants = {
6
+ plain: "",
7
+ card: "[--ev-list-row-x:1rem]"
8
+ };
9
+ function ListRows({ variant = "plain", className, ...props }) {
10
+ return /* @__PURE__ */ jsx(
11
+ "ul",
12
+ {
13
+ "data-slot": "list-rows",
14
+ "data-variant": variant,
15
+ className: cn(LIST_ROWS, listRowsVariants[variant], className),
16
+ ...props
17
+ }
18
+ );
19
+ }
20
+ const LIST_ROW = "flex min-w-0 items-center justify-between gap-3 px-[var(--ev-list-row-x,0px)] py-3";
21
+ function ListRow({ label, description, value, className, children, ...props }) {
22
+ return /* @__PURE__ */ jsxs(
23
+ "li",
24
+ {
25
+ "data-slot": "list-row",
26
+ className: cn(LIST_ROW, className),
27
+ ...props,
28
+ children: [
29
+ (label != null || description != null) && /* @__PURE__ */ jsx(ListRowLabel, { description, children: label }),
30
+ value != null && /* @__PURE__ */ jsx(ListRowValue, { children: value }),
31
+ children
32
+ ]
33
+ }
34
+ );
35
+ }
36
+ function ListRowLabel({ description, className, children, ...props }) {
37
+ return /* @__PURE__ */ jsxs(
38
+ "div",
39
+ {
40
+ "data-slot": "list-row-label",
41
+ className: cn("flex min-w-0 flex-1 flex-col gap-0.5", className),
42
+ ...props,
43
+ children: [
44
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-ink", children }),
45
+ description != null && /* @__PURE__ */ jsx(
46
+ "span",
47
+ {
48
+ "data-slot": "list-row-description",
49
+ className: "text-xs leading-snug text-ink-soft",
50
+ children: description
51
+ }
52
+ )
53
+ ]
54
+ }
55
+ );
56
+ }
57
+ function ListRowValue({ className, ...props }) {
58
+ return /* @__PURE__ */ jsx(
59
+ "span",
60
+ {
61
+ "data-slot": "list-row-value",
62
+ className: cn("min-w-0 truncate text-right text-sm tabular-nums text-ink-soft", className),
63
+ ...props
64
+ }
65
+ );
66
+ }
67
+ export {
68
+ ListRow,
69
+ ListRowLabel,
70
+ ListRowValue,
71
+ ListRows
72
+ };
73
+ //# sourceMappingURL=list-rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/list-rows.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../lib/cn\";\n\n// The phone form of a table: a list of label/value rows split by hairlines.\n// A table scrolled sideways on a phone hides the trailing columns — usually the\n// date and the action, the reason the list was opened. TS-only (README\n// \"Limitations\").\n\nexport type ListRowsVariant = \"plain\" | \"card\";\n\nconst LIST_ROWS = \"flex w-full min-w-0 flex-col divide-y divide-border\";\n\n// `plain` sits in a container that already pads (a padded card, a section);\n// `card` is edge to edge in a `TableCard`, so the rows pad themselves and the\n// hairlines run the card's full width. The inset travels as a custom property,\n// as the table's cell padding does, so a row's own `px-*` still wins.\nconst listRowsVariants: Record<ListRowsVariant, string> = {\n plain: \"\",\n card: \"[--ev-list-row-x:1rem]\",\n};\n\nexport interface ListRowsProps extends React.ComponentProps<\"ul\"> {\n variant?: ListRowsVariant;\n}\n\nexport function ListRows({ variant = \"plain\", className, ...props }: ListRowsProps) {\n return (\n <ul\n data-slot=\"list-rows\"\n data-variant={variant}\n className={cn(LIST_ROWS, listRowsVariants[variant], className)}\n {...props}\n />\n );\n}\n\nconst LIST_ROW = \"flex min-w-0 items-center justify-between gap-3 px-[var(--ev-list-row-x,0px)] py-3\";\n\n// `<li value>` is an ordinal for `<ol>`; in an unordered list of rows the name\n// is far more useful for the trailing figure.\nexport interface ListRowProps extends Omit<React.ComponentProps<\"li\">, \"value\"> {\n /** The row's title. Omit it (and `value`) to lay the row out yourself. */\n label?: React.ReactNode;\n /** A caption a step down under the label. */\n description?: React.ReactNode;\n /** Trailing value, right-aligned and truncated rather than pushing the row wide. */\n value?: React.ReactNode;\n}\n\n/**\n * One row: label (and description) leading, value trailing, then `children`\n * (a badge, an action). With neither `label` nor `value` the children are the\n * whole row.\n */\nexport function ListRow({ label, description, value, className, children, ...props }: ListRowProps) {\n return (\n <li\n data-slot=\"list-row\"\n className={cn(LIST_ROW, className)}\n {...props}\n >\n {(label != null || description != null) && (\n <ListRowLabel description={description}>{label}</ListRowLabel>\n )}\n {value != null && <ListRowValue>{value}</ListRowValue>}\n {children}\n </li>\n );\n}\n\nexport interface ListRowLabelProps extends Omit<React.ComponentProps<\"div\">, \"title\"> {\n description?: React.ReactNode;\n}\n\n/** The leading block on its own, for a row you compose by hand. */\nexport function ListRowLabel({ description, className, children, ...props }: ListRowLabelProps) {\n return (\n <div\n data-slot=\"list-row-label\"\n className={cn(\"flex min-w-0 flex-1 flex-col gap-0.5\", className)}\n {...props}\n >\n <span className=\"text-sm font-medium text-ink\">{children}</span>\n {description != null && (\n <span\n data-slot=\"list-row-description\"\n className=\"text-xs leading-snug text-ink-soft\"\n >\n {description}\n </span>\n )}\n </div>\n );\n}\n\n/**\n * The trailing value. It shares the label's type step, so the muted tone and\n * the lighter weight are what keep the label reading first; digits are tabular\n * so a figure in one row lines up with the next.\n */\nexport function ListRowValue({ className, ...props }: React.ComponentProps<\"span\">) {\n return (\n <span\n data-slot=\"list-row-value\"\n className={cn(\"min-w-0 truncate text-right text-sm tabular-nums text-ink-soft\", className)}\n {...props}\n />\n );\n}\n"],"mappings":"AA2BI,cA6BA,YA7BA;AA3BJ,YAAY,WAAW;AACvB,SAAS,UAAU;AASnB,MAAM,YAAY;AAMlB,MAAM,mBAAoD;AAAA,EACxD,OAAO;AAAA,EACP,MAAM;AACR;AAMO,SAAS,SAAS,EAAE,UAAU,SAAS,WAAW,GAAG,MAAM,GAAkB;AAClF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,gBAAc;AAAA,MACd,WAAW,GAAG,WAAW,iBAAiB,OAAO,GAAG,SAAS;AAAA,MAC5D,GAAG;AAAA;AAAA,EACN;AAEJ;AAEA,MAAM,WAAW;AAkBV,SAAS,QAAQ,EAAE,OAAO,aAAa,OAAO,WAAW,UAAU,GAAG,MAAM,GAAiB;AAClG,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,UAAU,SAAS;AAAA,MAChC,GAAG;AAAA,MAEF;AAAA,kBAAS,QAAQ,eAAe,SAChC,oBAAC,gBAAa,aAA2B,iBAAM;AAAA,QAEhD,SAAS,QAAQ,oBAAC,gBAAc,iBAAM;AAAA,QACtC;AAAA;AAAA;AAAA,EACH;AAEJ;AAOO,SAAS,aAAa,EAAE,aAAa,WAAW,UAAU,GAAG,MAAM,GAAsB;AAC9F,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,wCAAwC,SAAS;AAAA,MAC9D,GAAG;AAAA,MAEJ;AAAA,4BAAC,UAAK,WAAU,gCAAgC,UAAS;AAAA,QACxD,eAAe,QACd;AAAA,UAAC;AAAA;AAAA,YACC,aAAU;AAAA,YACV,WAAU;AAAA,YAET;AAAA;AAAA,QACH;AAAA;AAAA;AAAA,EAEJ;AAEJ;AAOO,SAAS,aAAa,EAAE,WAAW,GAAG,MAAM,GAAiC;AAClF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,kEAAkE,SAAS;AAAA,MACxF,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
@@ -89,10 +89,16 @@ const XIcon = (props) => /* @__PURE__ */ jsx(
89
89
  children: /* @__PURE__ */ jsx("path", { d: "M18 6 6 18M6 6l12 12" })
90
90
  }
91
91
  );
92
- function SheetContent({ className, children, side = "right", ...props }) {
92
+ function SheetContent({
93
+ className,
94
+ children,
95
+ side = "right",
96
+ initialFocus = "container",
97
+ ...props
98
+ }) {
93
99
  const { open, setOpen, triggerRef } = useSheet();
94
100
  const { isPresent, ref: presRef } = usePresence(open);
95
- const focusRef = useFocusScope(open);
101
+ const focusRef = useFocusScope(open, { initialFocus, returnFocusTo: triggerRef });
96
102
  const dismissRef = useDismissableLayer({
97
103
  enabled: open,
98
104
  onDismiss: () => setOpen(false),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n SHEET_CLOSE,\n SHEET_CONTENT,\n SHEET_DESCRIPTION,\n SHEET_FOOTER,\n SHEET_HEADER,\n SHEET_OVERLAY,\n SHEET_SIDE_BOTTOM,\n SHEET_SIDE_LEFT,\n SHEET_SIDE_RIGHT,\n SHEET_SIDE_TOP,\n SHEET_TITLE,\n} from \"../generated/sheet\";\n\ninterface SheetContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst SheetContext = React.createContext<SheetContextValue | null>(null);\n\nfunction useSheet(): SheetContextValue {\n const ctx = React.useContext(SheetContext);\n if (!ctx) throw new Error(\"Sheet parts must be used within <Sheet>\");\n return ctx;\n}\n\nexport interface SheetProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function Sheet({ open, defaultOpen = false, onOpenChange, children }: SheetProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <SheetContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </SheetContext.Provider>\n );\n}\n\nexport interface SheetTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function SheetTrigger({ asChild = false, onClick, ...props }: SheetTriggerProps) {\n const { open, setOpen, triggerRef } = useSheet();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"sheet-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface SheetOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function SheetOverlay({ className, ...props }: SheetOverlayProps) {\n const { open, setOpen } = useSheet();\n return (\n <div\n data-slot=\"sheet-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(SHEET_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nconst sheetSideClasses = {\n right: SHEET_SIDE_RIGHT,\n left: SHEET_SIDE_LEFT,\n top: SHEET_SIDE_TOP,\n bottom: SHEET_SIDE_BOTTOM,\n} as const;\n\nconst XIcon = (props: React.SVGProps<SVGSVGElement>) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...props}\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n);\n\nexport interface SheetContentProps extends React.ComponentProps<\"div\"> {\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n}\n\nexport function SheetContent({ className, children, side = \"right\", ...props }: SheetContentProps) {\n const { open, setOpen, triggerRef } = useSheet();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open);\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n if (!isPresent) return null;\n return (\n <Portal>\n <SheetOverlay />\n <div\n data-slot=\"sheet-content\"\n role=\"dialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(SHEET_CONTENT, sheetSideClasses[side], className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n <button\n type=\"button\"\n data-slot=\"sheet-close\"\n onClick={() => setOpen(false)}\n className={SHEET_CLOSE}\n >\n <XIcon className=\"size-4\" />\n <span className=\"sr-only\">Close</span>\n </button>\n </div>\n </Portal>\n );\n}\n\nexport interface SheetCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function SheetClose({ asChild = false, onClick, ...props }: SheetCloseProps) {\n const { setOpen } = useSheet();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"sheet-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport function SheetHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"sheet-header\"\n className={cn(SHEET_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function SheetFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"sheet-footer\"\n className={cn(SHEET_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function SheetTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"sheet-title\"\n className={cn(SHEET_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function SheetDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"sheet-description\"\n className={cn(SHEET_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";A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AA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,mBAAmB,SAAS;AAAA,MACzC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../src/components/sheet.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"../lib/cn\";\nimport { useControllableState } from \"../primitives/use-controllable-state\";\nimport { useDismissableLayer } from \"../primitives/dismissable-layer\";\nimport { type InitialFocus, useFocusScope } from \"../primitives/focus-scope\";\nimport { usePresence } from \"../primitives/presence\";\nimport { mergeRefs } from \"../primitives/merge-refs\";\nimport { Portal } from \"../primitives/portal\";\nimport { Slot } from \"../primitives/slot\";\nimport {\n SHEET_CLOSE,\n SHEET_CONTENT,\n SHEET_DESCRIPTION,\n SHEET_FOOTER,\n SHEET_HEADER,\n SHEET_OVERLAY,\n SHEET_SIDE_BOTTOM,\n SHEET_SIDE_LEFT,\n SHEET_SIDE_RIGHT,\n SHEET_SIDE_TOP,\n SHEET_TITLE,\n} from \"../generated/sheet\";\n\ninterface SheetContextValue {\n open: boolean;\n setOpen: (next: boolean) => void;\n triggerRef: React.RefObject<HTMLElement | null>;\n}\n\nconst SheetContext = React.createContext<SheetContextValue | null>(null);\n\nfunction useSheet(): SheetContextValue {\n const ctx = React.useContext(SheetContext);\n if (!ctx) throw new Error(\"Sheet parts must be used within <Sheet>\");\n return ctx;\n}\n\nexport interface SheetProps {\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: React.ReactNode;\n}\n\nexport function Sheet({ open, defaultOpen = false, onOpenChange, children }: SheetProps) {\n const [isOpen, setOpen] = useControllableState<boolean>({\n ...(open !== undefined ? { value: open } : {}),\n defaultValue: defaultOpen,\n ...(onOpenChange ? { onChange: onOpenChange } : {}),\n });\n const triggerRef = React.useRef<HTMLElement | null>(null);\n return (\n <SheetContext.Provider value={{ open: isOpen, setOpen, triggerRef }}>\n {children}\n </SheetContext.Provider>\n );\n}\n\nexport interface SheetTriggerProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function SheetTrigger({ asChild = false, onClick, ...props }: SheetTriggerProps) {\n const { open, setOpen, triggerRef } = useSheet();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"sheet-trigger\"\n aria-expanded={open}\n ref={triggerRef as React.Ref<HTMLButtonElement>}\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(true);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport interface SheetOverlayProps extends React.ComponentProps<\"div\"> {}\n\nexport function SheetOverlay({ className, ...props }: SheetOverlayProps) {\n const { open, setOpen } = useSheet();\n return (\n <div\n data-slot=\"sheet-overlay\"\n data-state={open ? \"open\" : \"closed\"}\n onClick={() => setOpen(false)}\n className={cn(SHEET_OVERLAY, className)}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nconst sheetSideClasses = {\n right: SHEET_SIDE_RIGHT,\n left: SHEET_SIDE_LEFT,\n top: SHEET_SIDE_TOP,\n bottom: SHEET_SIDE_BOTTOM,\n} as const;\n\nconst XIcon = (props: React.SVGProps<SVGSVGElement>) => (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n {...props}\n >\n <path d=\"M18 6 6 18M6 6l12 12\" />\n </svg>\n);\n\nexport interface SheetContentProps extends React.ComponentProps<\"div\"> {\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /**\n * Where focus lands on open. Default `container`: a sheet is a panel of\n * content, and its first Tab stop is as likely an action as a field — the\n * panel itself takes focus and the first Tab reaches the first control.\n */\n initialFocus?: InitialFocus;\n}\n\nexport function SheetContent({\n className,\n children,\n side = \"right\",\n initialFocus = \"container\",\n ...props\n}: SheetContentProps) {\n const { open, setOpen, triggerRef } = useSheet();\n const { isPresent, ref: presRef } = usePresence(open);\n const focusRef = useFocusScope(open, { initialFocus, returnFocusTo: triggerRef });\n const dismissRef = useDismissableLayer({\n enabled: open,\n onDismiss: () => setOpen(false),\n exclude: [triggerRef],\n });\n if (!isPresent) return null;\n return (\n <Portal>\n <SheetOverlay />\n <div\n data-slot=\"sheet-content\"\n role=\"dialog\"\n aria-modal=\"true\"\n data-state={open ? \"open\" : \"closed\"}\n ref={mergeRefs(focusRef, dismissRef, presRef as React.Ref<HTMLDivElement>)}\n className={cn(SHEET_CONTENT, sheetSideClasses[side], className)}\n {...(props as Record<string, unknown>)}\n >\n {children}\n <button\n type=\"button\"\n data-slot=\"sheet-close\"\n onClick={() => setOpen(false)}\n className={SHEET_CLOSE}\n >\n <XIcon className=\"size-4\" />\n <span className=\"sr-only\">Close</span>\n </button>\n </div>\n </Portal>\n );\n}\n\nexport interface SheetCloseProps extends React.ComponentProps<\"button\"> {\n asChild?: boolean;\n}\n\nexport function SheetClose({ asChild = false, onClick, ...props }: SheetCloseProps) {\n const { setOpen } = useSheet();\n const Comp = asChild ? Slot : \"button\";\n return (\n <Comp\n data-slot=\"sheet-close\"\n onClick={(e: React.MouseEvent<HTMLButtonElement>) => {\n onClick?.(e);\n setOpen(false);\n }}\n {...(props as Record<string, unknown>)}\n />\n );\n}\n\nexport function SheetHeader({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"sheet-header\"\n className={cn(SHEET_HEADER, className)}\n {...props}\n />\n );\n}\n\nexport function SheetFooter({ className, ...props }: React.ComponentProps<\"div\">) {\n return (\n <div\n data-slot=\"sheet-footer\"\n className={cn(SHEET_FOOTER, className)}\n {...props}\n />\n );\n}\n\nexport function SheetTitle({ className, ...props }: React.ComponentProps<\"h2\">) {\n return (\n <h2\n data-slot=\"sheet-title\"\n className={cn(SHEET_TITLE, className)}\n {...props}\n />\n );\n}\n\nexport function SheetDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n return (\n <p\n data-slot=\"sheet-description\"\n className={cn(SHEET_DESCRIPTION, className)}\n {...props}\n />\n );\n}\n"],"mappings":";AAsDI,cAyGI,YAzGJ;AApDJ,YAAY,WAAW;AACvB,SAAS,UAAU;AACnB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAA4B,qBAAqB;AACjD,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,MAAM,eAAe,MAAM,cAAwC,IAAI;AAEvE,SAAS,WAA8B;AACrC,QAAM,MAAM,MAAM,WAAW,YAAY;AACzC,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,yCAAyC;AACnE,SAAO;AACT;AASO,SAAS,MAAM,EAAE,MAAM,cAAc,OAAO,cAAc,SAAS,GAAe;AACvF,QAAM,CAAC,QAAQ,OAAO,IAAI,qBAA8B;AAAA,IACtD,GAAI,SAAS,SAAY,EAAE,OAAO,KAAK,IAAI,CAAC;AAAA,IAC5C,cAAc;AAAA,IACd,GAAI,eAAe,EAAE,UAAU,aAAa,IAAI,CAAC;AAAA,EACnD,CAAC;AACD,QAAM,aAAa,MAAM,OAA2B,IAAI;AACxD,SACE,oBAAC,aAAa,UAAb,EAAsB,OAAO,EAAE,MAAM,QAAQ,SAAS,WAAW,GAC/D,UACH;AAEJ;AAMO,SAAS,aAAa,EAAE,UAAU,OAAO,SAAS,GAAG,MAAM,GAAsB;AACtF,QAAM,EAAE,MAAM,SAAS,WAAW,IAAI,SAAS;AAC/C,QAAM,OAAO,UAAU,OAAO;AAC9B,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,iBAAe;AAAA,MACf,KAAK;AAAA,MACL,SAAS,CAAC,MAA2C;A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C,aAAU;AAAA,MACV,WAAW,GAAG,aAAa,SAAS;AAAA,MACnC,GAAG;AAAA;AAAA,EACN;AAEJ;AAEO,SAAS,iBAAiB,EAAE,WAAW,GAAG,MAAM,GAA8B;AACnF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,aAAU;AAAA,MACV,WAAW,GAAG,mBAAmB,SAAS;AAAA,MACzC,GAAG;AAAA;AAAA,EACN;AAEJ;","names":[]}
@@ -1,5 +1,5 @@
1
- const ALERT_DIALOG_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50";
2
- const ALERT_DIALOG_CONTENT = "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 sm:max-w-lg";
1
+ const ALERT_DIALOG_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50";
2
+ const ALERT_DIALOG_CONTENT = "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 data-[state=closed]:fill-mode-forwards outline-hidden sm:max-w-lg";
3
3
  const ALERT_DIALOG_HEADER = "flex flex-col gap-2 text-center sm:text-left";
4
4
  const ALERT_DIALOG_FOOTER = "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end";
5
5
  const ALERT_DIALOG_TITLE = "text-lg font-semibold";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generated/alert-dialog.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const ALERT_DIALOG_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\";\n\nexport const ALERT_DIALOG_CONTENT = \"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 sm:max-w-lg\";\n\nexport const ALERT_DIALOG_HEADER = \"flex flex-col gap-2 text-center sm:text-left\";\n\nexport const ALERT_DIALOG_FOOTER = \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\";\n\nexport const ALERT_DIALOG_TITLE = \"text-lg font-semibold\";\n\nexport const ALERT_DIALOG_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,uBAAuB;AAE7B,MAAM,uBAAuB;AAE7B,MAAM,sBAAsB;AAE5B,MAAM,sBAAsB;AAE5B,MAAM,qBAAqB;AAE3B,MAAM,2BAA2B;","names":[]}
1
+ {"version":3,"sources":["../../src/generated/alert-dialog.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const ALERT_DIALOG_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50\";\n\nexport const ALERT_DIALOG_CONTENT = \"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 data-[state=closed]:fill-mode-forwards outline-hidden sm:max-w-lg\";\n\nexport const ALERT_DIALOG_HEADER = \"flex flex-col gap-2 text-center sm:text-left\";\n\nexport const ALERT_DIALOG_FOOTER = \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\";\n\nexport const ALERT_DIALOG_TITLE = \"text-lg font-semibold\";\n\nexport const ALERT_DIALOG_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,uBAAuB;AAE7B,MAAM,uBAAuB;AAE7B,MAAM,sBAAsB;AAE5B,MAAM,sBAAsB;AAE5B,MAAM,qBAAqB;AAE3B,MAAM,2BAA2B;","names":[]}
@@ -1,6 +1,6 @@
1
- const DIALOG_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50";
2
- const DIALOG_CONTENT = "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 sm:max-w-lg";
3
- const DIALOG_CLOSE = "ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
1
+ const DIALOG_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50";
2
+ const DIALOG_CONTENT = "bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 data-[state=closed]:fill-mode-forwards outline-hidden sm:max-w-lg";
3
+ const DIALOG_CLOSE = "ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4";
4
4
  const DIALOG_HEADER = "flex flex-col gap-2 text-center sm:text-left";
5
5
  const DIALOG_FOOTER = "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end";
6
6
  const DIALOG_TITLE = "text-lg leading-none font-semibold";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generated/dialog.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const DIALOG_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\";\n\nexport const DIALOG_CONTENT = \"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 sm:max-w-lg\";\n\nexport const DIALOG_CLOSE = \"ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\";\n\nexport const DIALOG_HEADER = \"flex flex-col gap-2 text-center sm:text-left\";\n\nexport const DIALOG_FOOTER = \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\";\n\nexport const DIALOG_TITLE = \"text-lg leading-none font-semibold\";\n\nexport const DIALOG_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,eAAe;AAErB,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../../src/generated/dialog.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const DIALOG_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 duration-200 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50\";\n\nexport const DIALOG_CONTENT = \"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border border-border p-6 shadow-lg duration-200 data-[state=closed]:fill-mode-forwards outline-hidden sm:max-w-lg\";\n\nexport const DIALOG_CLOSE = \"ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\";\n\nexport const DIALOG_HEADER = \"flex flex-col gap-2 text-center sm:text-left\";\n\nexport const DIALOG_FOOTER = \"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end\";\n\nexport const DIALOG_TITLE = \"text-lg leading-none font-semibold\";\n\nexport const DIALOG_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,iBAAiB;AAEvB,MAAM,iBAAiB;AAEvB,MAAM,eAAe;AAErB,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,qBAAqB;","names":[]}
@@ -5,7 +5,7 @@ const drawerDirectionClasses = {
5
5
  "left": "inset-y-0 left-0 w-3/4 flex-row border-r sm:max-w-sm",
6
6
  "right": "inset-y-0 right-0 w-3/4 flex-row border-l sm:max-w-sm"
7
7
  };
8
- const DRAWER_OVERLAY = "fixed inset-0 z-50 bg-black/50";
8
+ const DRAWER_OVERLAY = "fixed inset-0 z-50 bg-black/50 data-[state=closed]:pointer-events-none";
9
9
  const DRAWER_HANDLE = "bg-muted mx-auto mt-4 h-2 w-[100px] shrink-0 rounded-full";
10
10
  const DRAWER_BODY = "flex min-h-0 flex-1 flex-col overflow-y-auto";
11
11
  const DRAWER_HEADER = "flex flex-col gap-0.5 p-4 text-center sm:gap-1.5 sm:text-left";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generated/drawer.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const DRAWER_CONTENT_BASE = \"bg-background fixed z-50 flex h-auto border border-border\";\n\nexport const drawerDirectionClasses = {\n \"bottom\": \"inset-x-0 bottom-0 mt-24 max-h-[80vh] flex-col rounded-t-lg border-b-0\",\n \"top\": \"inset-x-0 top-0 mb-24 max-h-[80vh] flex-col rounded-b-lg border-t-0\",\n \"left\": \"inset-y-0 left-0 w-3/4 flex-row border-r sm:max-w-sm\",\n \"right\": \"inset-y-0 right-0 w-3/4 flex-row border-l sm:max-w-sm\",\n} as const;\nexport type DrawerDirection = keyof typeof drawerDirectionClasses;\n\nexport const DRAWER_OVERLAY = \"fixed inset-0 z-50 bg-black/50\";\n\nexport const DRAWER_HANDLE = \"bg-muted mx-auto mt-4 h-2 w-[100px] shrink-0 rounded-full\";\n\nexport const DRAWER_BODY = \"flex min-h-0 flex-1 flex-col overflow-y-auto\";\n\nexport const DRAWER_HEADER = \"flex flex-col gap-0.5 p-4 text-center sm:gap-1.5 sm:text-left\";\n\nexport const DRAWER_FOOTER = \"mt-auto flex flex-col gap-2 p-4\";\n\nexport const DRAWER_TITLE = \"text-ink font-semibold\";\n\nexport const DRAWER_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,sBAAsB;AAE5B,MAAM,yBAAyB;AAAA,EACpC,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AACX;AAGO,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB;AAEtB,MAAM,cAAc;AAEpB,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../../src/generated/drawer.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const DRAWER_CONTENT_BASE = \"bg-background fixed z-50 flex h-auto border border-border\";\n\nexport const drawerDirectionClasses = {\n \"bottom\": \"inset-x-0 bottom-0 mt-24 max-h-[80vh] flex-col rounded-t-lg border-b-0\",\n \"top\": \"inset-x-0 top-0 mb-24 max-h-[80vh] flex-col rounded-b-lg border-t-0\",\n \"left\": \"inset-y-0 left-0 w-3/4 flex-row border-r sm:max-w-sm\",\n \"right\": \"inset-y-0 right-0 w-3/4 flex-row border-l sm:max-w-sm\",\n} as const;\nexport type DrawerDirection = keyof typeof drawerDirectionClasses;\n\nexport const DRAWER_OVERLAY = \"fixed inset-0 z-50 bg-black/50 data-[state=closed]:pointer-events-none\";\n\nexport const DRAWER_HANDLE = \"bg-muted mx-auto mt-4 h-2 w-[100px] shrink-0 rounded-full\";\n\nexport const DRAWER_BODY = \"flex min-h-0 flex-1 flex-col overflow-y-auto\";\n\nexport const DRAWER_HEADER = \"flex flex-col gap-0.5 p-4 text-center sm:gap-1.5 sm:text-left\";\n\nexport const DRAWER_FOOTER = \"mt-auto flex flex-col gap-2 p-4\";\n\nexport const DRAWER_TITLE = \"text-ink font-semibold\";\n\nexport const DRAWER_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,sBAAsB;AAE5B,MAAM,yBAAyB;AAAA,EACpC,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AACX;AAGO,MAAM,iBAAiB;AAEvB,MAAM,gBAAgB;AAEtB,MAAM,cAAc;AAEpB,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,eAAe;AAErB,MAAM,qBAAqB;","names":[]}
@@ -1,6 +1,6 @@
1
- const SHEET_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50";
2
- const SHEET_CONTENT = "bg-background border-border data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500";
3
- const SHEET_CLOSE = "ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none";
1
+ const SHEET_OVERLAY = "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50";
2
+ const SHEET_CONTENT = "bg-background border-border data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=closed]:fill-mode-forwards outline-hidden";
3
+ const SHEET_CLOSE = "ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none";
4
4
  const SHEET_SIDE_RIGHT = "data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm";
5
5
  const SHEET_SIDE_LEFT = "data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm";
6
6
  const SHEET_SIDE_TOP = "data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/generated/sheet.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const SHEET_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50\";\n\nexport const SHEET_CONTENT = \"bg-background border-border data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500\";\n\nexport const SHEET_CLOSE = \"ring-offset-background focus:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none\";\n\nexport const SHEET_SIDE_RIGHT = \"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm\";\n\nexport const SHEET_SIDE_LEFT = \"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm\";\n\nexport const SHEET_SIDE_TOP = \"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b\";\n\nexport const SHEET_SIDE_BOTTOM = \"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t\";\n\nexport const SHEET_HEADER = \"flex flex-col gap-1.5 p-4\";\n\nexport const SHEET_FOOTER = \"mt-auto flex flex-col gap-2 p-4\";\n\nexport const SHEET_TITLE = \"text-ink font-semibold\";\n\nexport const SHEET_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,cAAc;AAEpB,MAAM,mBAAmB;AAEzB,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAE1B,MAAM,eAAe;AAErB,MAAM,eAAe;AAErB,MAAM,cAAc;AAEpB,MAAM,oBAAoB;","names":[]}
1
+ {"version":3,"sources":["../../src/generated/sheet.ts"],"sourcesContent":["// AUTO-GENERATED by `nix run .#gen` — do not edit.\n\nexport const SHEET_OVERLAY = \"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=closed]:fill-mode-forwards data-[state=closed]:pointer-events-none fixed inset-0 z-50 bg-black/50\";\n\nexport const SHEET_CONTENT = \"bg-background border-border data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=closed]:fill-mode-forwards outline-hidden\";\n\nexport const SHEET_CLOSE = \"ring-offset-background focus-visible:ring-ring absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-hidden disabled:pointer-events-none\";\n\nexport const SHEET_SIDE_RIGHT = \"data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm\";\n\nexport const SHEET_SIDE_LEFT = \"data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm\";\n\nexport const SHEET_SIDE_TOP = \"data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b\";\n\nexport const SHEET_SIDE_BOTTOM = \"data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t\";\n\nexport const SHEET_HEADER = \"flex flex-col gap-1.5 p-4\";\n\nexport const SHEET_FOOTER = \"mt-auto flex flex-col gap-2 p-4\";\n\nexport const SHEET_TITLE = \"text-ink font-semibold\";\n\nexport const SHEET_DESCRIPTION = \"text-ink-soft text-sm\";\n"],"mappings":"AAEO,MAAM,gBAAgB;AAEtB,MAAM,gBAAgB;AAEtB,MAAM,cAAc;AAEpB,MAAM,mBAAmB;AAEzB,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAEvB,MAAM,oBAAoB;AAE1B,MAAM,eAAe;AAErB,MAAM,eAAe;AAErB,MAAM,cAAc;AAEpB,MAAM,oBAAoB;","names":[]}
package/dist/index.d.ts CHANGED
@@ -138,16 +138,34 @@ declare function useFloating(opts: {
138
138
  offset?: number;
139
139
  }): FloatingResult;
140
140
 
141
+ /**
142
+ * Where focus lands when the scope opens. `first` is the first Tab stop inside
143
+ * (an input, an alert dialog's least destructive action); `container` is the
144
+ * scope root itself, so a reader starts at the top and the first Tab reaches the
145
+ * first control — right for a panel of content, where the first stop may be an
146
+ * action one keypress away from firing.
147
+ */
148
+ type InitialFocus = "first" | "container";
149
+ interface FocusScopeOptions {
150
+ /** Default `first`; falls back to the container when nothing inside is focusable. */
151
+ initialFocus?: InitialFocus;
152
+ /**
153
+ * Where focus goes back on close when the element focused before opening is
154
+ * no use: `<body>` (Safari does not focus a clicked button), or detached (the
155
+ * opener was re-rendered away). Pass the overlay's trigger.
156
+ */
157
+ returnFocusTo?: React.RefObject<HTMLElement | null>;
158
+ }
141
159
  /**
142
160
  * Traps Tab focus inside the returned ref's subtree and restores focus to the
143
161
  * previously-focused element on unmount — the dep-light core of dialogs/menus,
144
- * replacing `@radix-ui/react-focus-scope`. On mount, focuses the first
145
- * focusable (or the container itself).
162
+ * replacing `@radix-ui/react-focus-scope`. On mount, focuses per
163
+ * `initialFocus`; the root gets `tabindex="-1"` whenever it is the target.
146
164
  *
147
165
  * Rust dialogs rely on the browser's native focus order within a fixed overlay;
148
166
  * see the README "Limitations".
149
167
  */
150
- declare function useFocusScope(enabled: boolean): React.RefObject<HTMLDivElement | null>;
168
+ declare function useFocusScope(enabled: boolean, { initialFocus, returnFocusTo }?: FocusScopeOptions): React.RefObject<HTMLDivElement | null>;
151
169
 
152
170
  /**
153
171
  * Keeps an overlay mounted through its exit animation. Enter animations
@@ -1277,8 +1295,10 @@ interface DialogOverlayProps extends React.ComponentProps<"div"> {
1277
1295
  declare function DialogOverlay({ className, ...props }: DialogOverlayProps): React.JSX.Element;
1278
1296
  interface DialogContentProps extends React.ComponentProps<"div"> {
1279
1297
  showCloseButton?: boolean;
1298
+ /** Where focus lands on open. Default `first` — a dialog is usually a short form. */
1299
+ initialFocus?: InitialFocus;
1280
1300
  }
1281
- declare function DialogContent({ className, children, showCloseButton, ...props }: DialogContentProps): React.JSX.Element | null;
1301
+ declare function DialogContent({ className, children, showCloseButton, initialFocus, ...props }: DialogContentProps): React.JSX.Element | null;
1282
1302
  interface DialogCloseProps extends React.ComponentProps<"button"> {
1283
1303
  asChild?: boolean;
1284
1304
  }
@@ -1332,8 +1352,14 @@ interface SheetOverlayProps extends React.ComponentProps<"div"> {
1332
1352
  declare function SheetOverlay({ className, ...props }: SheetOverlayProps): React.JSX.Element;
1333
1353
  interface SheetContentProps extends React.ComponentProps<"div"> {
1334
1354
  side?: "top" | "right" | "bottom" | "left";
1355
+ /**
1356
+ * Where focus lands on open. Default `container`: a sheet is a panel of
1357
+ * content, and its first Tab stop is as likely an action as a field — the
1358
+ * panel itself takes focus and the first Tab reaches the first control.
1359
+ */
1360
+ initialFocus?: InitialFocus;
1335
1361
  }
1336
- declare function SheetContent({ className, children, side, ...props }: SheetContentProps): React.JSX.Element | null;
1362
+ declare function SheetContent({ className, children, side, initialFocus, ...props }: SheetContentProps): React.JSX.Element | null;
1337
1363
  interface SheetCloseProps extends React.ComponentProps<"button"> {
1338
1364
  asChild?: boolean;
1339
1365
  }
@@ -16,15 +16,25 @@ function focusable(root) {
16
16
  (el) => el.offsetWidth > 0 || el.offsetHeight > 0 || el === document.activeElement
17
17
  );
18
18
  }
19
- function useFocusScope(enabled) {
19
+ function usable(el) {
20
+ return !!el && el !== document.body && el.isConnected;
21
+ }
22
+ function focusRoot(root) {
23
+ if (!root.hasAttribute("tabindex")) root.tabIndex = -1;
24
+ root.focus();
25
+ }
26
+ function useFocusScope(enabled, { initialFocus = "first", returnFocusTo } = {}) {
20
27
  const ref = React.useRef(null);
28
+ const fallbackRef = React.useRef(returnFocusTo);
29
+ fallbackRef.current = returnFocusTo;
21
30
  React.useEffect(() => {
22
31
  if (!enabled) return;
23
32
  const root = ref.current;
24
33
  if (!root) return;
25
34
  const previouslyFocused = document.activeElement;
26
- const first = focusable(root)[0];
27
- (first ?? root).focus();
35
+ const first = initialFocus === "first" ? focusable(root)[0] : void 0;
36
+ if (first) first.focus();
37
+ else focusRoot(root);
28
38
  function onKeyDown(event) {
29
39
  if (event.key !== "Tab" || !root) return;
30
40
  const items = focusable(root);
@@ -35,7 +45,10 @@ function useFocusScope(enabled) {
35
45
  const firstEl = items[0];
36
46
  const lastEl = items[items.length - 1];
37
47
  const active = document.activeElement;
38
- if (event.shiftKey && active === firstEl) {
48
+ if (active === root) {
49
+ event.preventDefault();
50
+ (event.shiftKey ? lastEl : firstEl).focus();
51
+ } else if (event.shiftKey && active === firstEl) {
39
52
  event.preventDefault();
40
53
  lastEl.focus();
41
54
  } else if (!event.shiftKey && active === lastEl) {
@@ -46,9 +59,12 @@ function useFocusScope(enabled) {
46
59
  root.addEventListener("keydown", onKeyDown);
47
60
  return () => {
48
61
  root.removeEventListener("keydown", onKeyDown);
49
- previouslyFocused?.focus?.();
62
+ const active = document.activeElement;
63
+ if (active && active !== document.body && !root.contains(active)) return;
64
+ const target = usable(previouslyFocused) ? previouslyFocused : fallbackRef.current?.current;
65
+ if (usable(target)) target.focus({ preventScroll: true });
50
66
  };
51
- }, [enabled]);
67
+ }, [enabled, initialFocus]);
52
68
  return ref;
53
69
  }
54
70
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/primitives/focus-scope.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\n// `tabindex=\"-1\"` opts an element out of Tab order whatever its tag, so the\n// exclusion goes on every branch — otherwise a roving-tabindex grid's parked\n// cells would count as tab stops.\nconst FOCUSABLE = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"textarea:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"[tabindex]\",\n]\n .map(sel => `${sel}:not([tabindex=\"-1\"])`)\n .join(\",\");\n\n/**\n * Every enabled, Tab-reachable candidate under `root` in DOM (= Tab) order,\n * before the layout-based visibility filter; `tabindex=\"-1\"` is skipped on any\n * tag. For content that is fully visible while it exists (a popover), this is\n * the tab order itself. Internal to the kit.\n */\nexport function focusCandidates(root: HTMLElement): HTMLElement[] {\n return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE));\n}\n\nfunction focusable(root: HTMLElement): HTMLElement[] {\n return focusCandidates(root).filter(\n (el) => el.offsetWidth > 0 || el.offsetHeight > 0 || el === document.activeElement,\n );\n}\n\n/**\n * Traps Tab focus inside the returned ref's subtree and restores focus to the\n * previously-focused element on unmount — the dep-light core of dialogs/menus,\n * replacing `@radix-ui/react-focus-scope`. On mount, focuses the first\n * focusable (or the container itself).\n *\n * Rust dialogs rely on the browser's native focus order within a fixed overlay;\n * see the README \"Limitations\".\n */\nexport function useFocusScope(enabled: boolean): React.RefObject<HTMLDivElement | null> {\n const ref = React.useRef<HTMLDivElement | null>(null);\n\n React.useEffect(() => {\n if (!enabled) return;\n const root = ref.current;\n if (!root) return;\n\n const previouslyFocused = document.activeElement as HTMLElement | null;\n const first = focusable(root)[0];\n (first ?? root).focus();\n\n function onKeyDown(event: KeyboardEvent) {\n if (event.key !== \"Tab\" || !root) return;\n const items = focusable(root);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const firstEl = items[0]!;\n const lastEl = items[items.length - 1]!;\n const active = document.activeElement;\n if (event.shiftKey && active === firstEl) {\n event.preventDefault();\n lastEl.focus();\n } else if (!event.shiftKey && active === lastEl) {\n event.preventDefault();\n firstEl.focus();\n }\n }\n\n root.addEventListener(\"keydown\", onKeyDown);\n return () => {\n root.removeEventListener(\"keydown\", onKeyDown);\n previouslyFocused?.focus?.();\n };\n }, [enabled]);\n\n return ref;\n}\n"],"mappings":";AAEA,YAAY,WAAW;AAKvB,MAAM,YAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EACG,IAAI,SAAO,GAAG,GAAG,uBAAuB,EACxC,KAAK,GAAG;AAQJ,SAAS,gBAAgB,MAAkC;AAChE,SAAO,MAAM,KAAK,KAAK,iBAA8B,SAAS,CAAC;AACjE;AAEA,SAAS,UAAU,MAAkC;AACnD,SAAO,gBAAgB,IAAI,EAAE;AAAA,IAC3B,CAAC,OAAO,GAAG,cAAc,KAAK,GAAG,eAAe,KAAK,OAAO,SAAS;AAAA,EACvE;AACF;AAWO,SAAS,cAAc,SAA0D;AACtF,QAAM,MAAM,MAAM,OAA8B,IAAI;AAEpD,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,QAAS;AACd,UAAM,OAAO,IAAI;AACjB,QAAI,CAAC,KAAM;AAEX,UAAM,oBAAoB,SAAS;AACnC,UAAM,QAAQ,UAAU,IAAI,EAAE,CAAC;AAC/B,KAAC,SAAS,MAAM,MAAM;AAEtB,aAAS,UAAU,OAAsB;AACvC,UAAI,MAAM,QAAQ,SAAS,CAAC,KAAM;AAClC,YAAM,QAAQ,UAAU,IAAI;AAC5B,UAAI,MAAM,WAAW,GAAG;AACtB,cAAM,eAAe;AACrB;AAAA,MACF;AACA,YAAM,UAAU,MAAM,CAAC;AACvB,YAAM,SAAS,MAAM,MAAM,SAAS,CAAC;AACrC,YAAM,SAAS,SAAS;AACxB,UAAI,MAAM,YAAY,WAAW,SAAS;AACxC,cAAM,eAAe;AACrB,eAAO,MAAM;AAAA,MACf,WAAW,CAAC,MAAM,YAAY,WAAW,QAAQ;AAC/C,cAAM,eAAe;AACrB,gBAAQ,MAAM;AAAA,MAChB;AAAA,IACF;AAEA,SAAK,iBAAiB,WAAW,SAAS;AAC1C,WAAO,MAAM;AACX,WAAK,oBAAoB,WAAW,SAAS;AAC7C,yBAAmB,QAAQ;AAAA,IAC7B;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/primitives/focus-scope.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\n// `tabindex=\"-1\"` opts an element out of Tab order whatever its tag, so the\n// exclusion goes on every branch — otherwise a roving-tabindex grid's parked\n// cells would count as tab stops.\nconst FOCUSABLE = [\n \"a[href]\",\n \"button:not([disabled])\",\n \"textarea:not([disabled])\",\n \"input:not([disabled])\",\n \"select:not([disabled])\",\n \"[tabindex]\",\n]\n .map(sel => `${sel}:not([tabindex=\"-1\"])`)\n .join(\",\");\n\n/**\n * Every enabled, Tab-reachable candidate under `root` in DOM (= Tab) order,\n * before the layout-based visibility filter; `tabindex=\"-1\"` is skipped on any\n * tag. For content that is fully visible while it exists (a popover), this is\n * the tab order itself. Internal to the kit.\n */\nexport function focusCandidates(root: HTMLElement): HTMLElement[] {\n return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE));\n}\n\nfunction focusable(root: HTMLElement): HTMLElement[] {\n return focusCandidates(root).filter(\n (el) => el.offsetWidth > 0 || el.offsetHeight > 0 || el === document.activeElement,\n );\n}\n\n/**\n * Where focus lands when the scope opens. `first` is the first Tab stop inside\n * (an input, an alert dialog's least destructive action); `container` is the\n * scope root itself, so a reader starts at the top and the first Tab reaches the\n * first control — right for a panel of content, where the first stop may be an\n * action one keypress away from firing.\n */\nexport type InitialFocus = \"first\" | \"container\";\n\nexport interface FocusScopeOptions {\n /** Default `first`; falls back to the container when nothing inside is focusable. */\n initialFocus?: InitialFocus;\n /**\n * Where focus goes back on close when the element focused before opening is\n * no use: `<body>` (Safari does not focus a clicked button), or detached (the\n * opener was re-rendered away). Pass the overlay's trigger.\n */\n returnFocusTo?: React.RefObject<HTMLElement | null>;\n}\n\nfunction usable(el: HTMLElement | null | undefined): el is HTMLElement {\n return !!el && el !== document.body && el.isConnected;\n}\n\n// A `<div>` without a tabindex ignores `.focus()`, so a scope with no Tab stops\n// used to leave focus on the trigger behind the scrim. `-1` makes the root\n// focusable by script (and by a click on its empty area, which keeps focus in\n// the scope) without adding it to the Tab order.\nfunction focusRoot(root: HTMLElement) {\n if (!root.hasAttribute(\"tabindex\")) root.tabIndex = -1;\n root.focus();\n}\n\n/**\n * Traps Tab focus inside the returned ref's subtree and restores focus to the\n * previously-focused element on unmount — the dep-light core of dialogs/menus,\n * replacing `@radix-ui/react-focus-scope`. On mount, focuses per\n * `initialFocus`; the root gets `tabindex=\"-1\"` whenever it is the target.\n *\n * Rust dialogs rely on the browser's native focus order within a fixed overlay;\n * see the README \"Limitations\".\n */\nexport function useFocusScope(\n enabled: boolean,\n { initialFocus = \"first\", returnFocusTo }: FocusScopeOptions = {},\n): React.RefObject<HTMLDivElement | null> {\n const ref = React.useRef<HTMLDivElement | null>(null);\n // Read at close, not captured at open: a trigger re-rendered while the\n // overlay was up is a new node by then.\n const fallbackRef = React.useRef(returnFocusTo);\n fallbackRef.current = returnFocusTo;\n\n React.useEffect(() => {\n if (!enabled) return;\n const root = ref.current;\n if (!root) return;\n\n const previouslyFocused = document.activeElement as HTMLElement | null;\n const first = initialFocus === \"first\" ? focusable(root)[0] : undefined;\n if (first) first.focus();\n else focusRoot(root);\n\n function onKeyDown(event: KeyboardEvent) {\n if (event.key !== \"Tab\" || !root) return;\n const items = focusable(root);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const firstEl = items[0]!;\n const lastEl = items[items.length - 1]!;\n const active = document.activeElement;\n // From the root itself Shift+Tab would leave the scope for whatever\n // precedes the portal, so both directions are steered explicitly.\n if (active === root) {\n event.preventDefault();\n (event.shiftKey ? lastEl : firstEl).focus();\n } else if (event.shiftKey && active === firstEl) {\n event.preventDefault();\n lastEl.focus();\n } else if (!event.shiftKey && active === lastEl) {\n event.preventDefault();\n firstEl.focus();\n }\n }\n\n root.addEventListener(\"keydown\", onKeyDown);\n return () => {\n root.removeEventListener(\"keydown\", onKeyDown);\n // Focus that already left the scope (a click outside landed on a field)\n // is the user's; only focus still inside, or dropped to <body>, returns.\n const active = document.activeElement;\n if (active && active !== document.body && !root.contains(active)) return;\n const target = usable(previouslyFocused) ? previouslyFocused : fallbackRef.current?.current;\n if (usable(target)) target.focus({ preventScroll: true });\n };\n }, [enabled, initialFocus]);\n\n return ref;\n}\n"],"mappings":";AAEA,YAAY,WAAW;AAKvB,MAAM,YAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,EACG,IAAI,SAAO,GAAG,GAAG,uBAAuB,EACxC,KAAK,GAAG;AAQJ,SAAS,gBAAgB,MAAkC;AAChE,SAAO,MAAM,KAAK,KAAK,iBAA8B,SAAS,CAAC;AACjE;AAEA,SAAS,UAAU,MAAkC;AACnD,SAAO,gBAAgB,IAAI,EAAE;AAAA,IAC3B,CAAC,OAAO,GAAG,cA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,MAAM;AACX,WAAK,oBAAoB,WAAW,SAAS;AAG7C,YAAM,SAAS,SAAS;AACxB,UAAI,UAAU,WAAW,SAAS,QAAQ,CAAC,KAAK,SAAS,MAAM,EAAG;AAClE,YAAM,SAAS,OAAO,iBAAiB,IAAI,oBAAoB,YAAY,SAAS;AACpF,UAAI,OAAO,MAAM,EAAG,QAAO,MAAM,EAAE,eAAe,KAAK,CAAC;AAAA,IAC1D;AAAA,EACF,GAAG,CAAC,SAAS,YAAY,CAAC;AAE1B,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evinvest/uikit",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Dep-light React UI kit: shadcn-semantics components with zero @radix-ui / cva, mirroring the ev_lib::uikit Rust feature. Ships the shared design tokens.",
5
5
  "license": "BlueOak-1.0.0",
6
6
  "publishConfig": {
package/styles/theme.css CHANGED
@@ -1,7 +1,8 @@
1
1
  /* AUTO-GENERATED by `nix run .#gen` from the repo-root theme.css — do not edit. */
2
2
  /*
3
- * Toast (sonner) and Drawer enter/exit motion, the entrances (rise / stagger / settled /
4
- * skeleton) and the app-shell markers, shared by both ports. Imported by the token
3
+ * Toast (sonner) and Drawer enter/exit motion, the reduced-motion fade for Sheet and
4
+ * the dialogs, the entrances (rise / stagger / settled / skeleton) and the app-shell
5
+ * markers, shared by both ports. Imported by the token
5
6
  * sheets so the lifecycle ships with the theme contract.
6
7
  */
7
8
 
@@ -307,6 +308,30 @@
307
308
  }
308
309
  }
309
310
 
311
+ /* ── Sheet and dialogs under reduced motion ──────────────────────────────────
312
+ Both ports animate these with tw-animate-css (`animate-in` / `animate-out` +
313
+ `slide-*` / `zoom-*`), whose `enter` / `exit` keyframes read the
314
+ --tw-enter-* / --tw-exit-* variables the slide and zoom utilities set. Zeroing
315
+ the travel and the scale here leaves a fade: the dialogs already fade, the
316
+ sheet does not, so its opacity is set too. The keyframes still run on their
317
+ usual clock, so the TS port's exit `animationend` unmount is untouched.
318
+ Unlayered, like the rest of this sheet, so it outranks those utilities
319
+ without !important. */
320
+ @media (prefers-reduced-motion: reduce) {
321
+ [data-slot="sheet-content"],
322
+ [data-slot="dialog-content"],
323
+ [data-slot="alert-dialog-content"] {
324
+ --tw-enter-translate-x: 0;
325
+ --tw-enter-translate-y: 0;
326
+ --tw-exit-translate-x: 0;
327
+ --tw-exit-translate-y: 0;
328
+ --tw-enter-scale: 1;
329
+ --tw-exit-scale: 1;
330
+ --tw-enter-opacity: 0;
331
+ --tw-exit-opacity: 0;
332
+ }
333
+ }
334
+
310
335
  /* ── Entrances: rise, stagger, settled, skeleton ─────────────────────────────
311
336
  One keyframe for every "arriving" thing, driven by attributes so a consumer
312
337
  without a motion library (and a Server Component) gets it for free:
package/styles/tokens.css CHANGED
@@ -41,8 +41,9 @@
41
41
  */
42
42
 
43
43
  /*
44
- * Toast (sonner) and Drawer enter/exit motion, the entrances (rise / stagger / settled /
45
- * skeleton) and the app-shell markers, shared by both ports. Imported by the token
44
+ * Toast (sonner) and Drawer enter/exit motion, the reduced-motion fade for Sheet and
45
+ * the dialogs, the entrances (rise / stagger / settled / skeleton) and the app-shell
46
+ * markers, shared by both ports. Imported by the token
46
47
  * sheets so the lifecycle ships with the theme contract.
47
48
  */
48
49
 
@@ -348,6 +349,30 @@
348
349
  }
349
350
  }
350
351
 
352
+ /* ── Sheet and dialogs under reduced motion ──────────────────────────────────
353
+ Both ports animate these with tw-animate-css (`animate-in` / `animate-out` +
354
+ `slide-*` / `zoom-*`), whose `enter` / `exit` keyframes read the
355
+ --tw-enter-* / --tw-exit-* variables the slide and zoom utilities set. Zeroing
356
+ the travel and the scale here leaves a fade: the dialogs already fade, the
357
+ sheet does not, so its opacity is set too. The keyframes still run on their
358
+ usual clock, so the TS port's exit `animationend` unmount is untouched.
359
+ Unlayered, like the rest of this sheet, so it outranks those utilities
360
+ without !important. */
361
+ @media (prefers-reduced-motion: reduce) {
362
+ [data-slot="sheet-content"],
363
+ [data-slot="dialog-content"],
364
+ [data-slot="alert-dialog-content"] {
365
+ --tw-enter-translate-x: 0;
366
+ --tw-enter-translate-y: 0;
367
+ --tw-exit-translate-x: 0;
368
+ --tw-exit-translate-y: 0;
369
+ --tw-enter-scale: 1;
370
+ --tw-exit-scale: 1;
371
+ --tw-enter-opacity: 0;
372
+ --tw-exit-opacity: 0;
373
+ }
374
+ }
375
+
351
376
  /* ── Entrances: rise, stagger, settled, skeleton ─────────────────────────────
352
377
  One keyframe for every "arriving" thing, driven by attributes so a consumer
353
378
  without a motion library (and a Server Component) gets it for free: