@cognitap/radiant 0.0.13 → 0.0.15

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/library/AlertDialog.d.ts +25 -0
  3. package/dist/library/AlertDialog.d.ts.map +1 -0
  4. package/dist/library/AlertDialog.js +56 -0
  5. package/dist/library/AlertDialog.js.map +1 -0
  6. package/dist/library/Dialog.d.ts +7 -1
  7. package/dist/library/Dialog.d.ts.map +1 -1
  8. package/dist/library/Dialog.js +33 -16
  9. package/dist/library/Dialog.js.map +1 -1
  10. package/dist/library/Popover.d.ts +44 -0
  11. package/dist/library/Popover.d.ts.map +1 -0
  12. package/dist/library/Popover.js +94 -0
  13. package/dist/library/Popover.js.map +1 -0
  14. package/dist/library/cn.d.ts.map +1 -1
  15. package/dist/library/cn.js +22 -2
  16. package/dist/library/cn.js.map +1 -1
  17. package/dist/library/index.d.ts +4 -0
  18. package/dist/library/index.d.ts.map +1 -1
  19. package/dist/library/index.js +2 -0
  20. package/dist/library/index.js.map +1 -1
  21. package/dist/library/internal/popover.d.ts +36 -0
  22. package/dist/library/internal/popover.d.ts.map +1 -0
  23. package/dist/library/internal/popover.js +45 -0
  24. package/dist/library/internal/popover.js.map +1 -0
  25. package/dist/library/react/usePopoverSurface.d.ts +10 -0
  26. package/dist/library/react/usePopoverSurface.d.ts.map +1 -0
  27. package/dist/library/react/usePopoverSurface.js +193 -0
  28. package/dist/library/react/usePopoverSurface.js.map +1 -0
  29. package/dist/library/styles.css +1 -1
  30. package/dist/library/themes/components.d.ts +18 -0
  31. package/dist/library/themes/components.d.ts.map +1 -1
  32. package/dist/library/themes/components.js +18 -0
  33. package/dist/library/themes/components.js.map +1 -1
  34. package/docs/architecture.md +13 -7
  35. package/docs/theming.md +1 -1
  36. package/package.json +1 -1
  37. package/src/AlertDialog.tsx +110 -0
  38. package/src/Dialog.tsx +52 -22
  39. package/src/Popover.tsx +201 -0
  40. package/src/cn.ts +22 -2
  41. package/src/index.ts +40 -0
  42. package/src/internal/popover.ts +66 -0
  43. package/src/react/usePopoverSurface.ts +207 -0
  44. package/src/themes/components.ts +18 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.0.15
8
+
9
+ - Add Popover.
10
+
11
+ ## 0.0.14
12
+
13
+ - Add AlertDialog.
14
+
7
15
  ## 0.0.13
8
16
 
9
17
  - Add Combobox.
@@ -18,7 +26,7 @@
18
26
 
19
27
  ## 0.0.10
20
28
 
21
- - Add draggable Switch with Field, forms, sizing and theme overrides.
29
+ - Add draggable Switch with Field, forms, sizing and theming.
22
30
 
23
31
  ## 0.0.9
24
32
 
@@ -0,0 +1,25 @@
1
+ import { type DialogProps, type DialogState, type DialogContentProps, type DialogTitleProps, type DialogDescriptionProps, type DialogTriggerProps, type DialogRenderProps } from './Dialog.js';
2
+ /** Always modal. Backdrop clicks never dismiss an urgent decision. */
3
+ export type AlertDialogProps = DialogProps & {
4
+ modal?: never;
5
+ closeOnBackdrop?: never;
6
+ };
7
+ export type AlertDialogState = DialogState;
8
+ export type AlertDialogRenderProps = DialogRenderProps;
9
+ export type AlertDialogTriggerProps = DialogTriggerProps;
10
+ export type AlertDialogContentProps = Omit<DialogContentProps, 'role' | 'aria-modal'>;
11
+ export type AlertDialogTitleProps = DialogTitleProps;
12
+ export type AlertDialogDescriptionProps = DialogDescriptionProps;
13
+ export type AlertDialogActionProps = DialogTriggerProps;
14
+ export type AlertDialogCancelProps = DialogTriggerProps;
15
+ export declare function useAlertDialog(): AlertDialogState | null;
16
+ export declare function AlertDialog(props: AlertDialogProps): import("react").JSX.Element;
17
+ export declare function AlertDialogTrigger(props: AlertDialogTriggerProps): import("react").JSX.Element;
18
+ export declare function AlertDialogContent(props: AlertDialogContentProps): import("react").JSX.Element;
19
+ export declare function AlertDialogTitle(props: AlertDialogTitleProps): import("react").JSX.Element;
20
+ export declare function AlertDialogDescription(props: AlertDialogDescriptionProps): import("react").JSX.Element;
21
+ /** Runs the caller's action, then requests close unless the action prevents default. */
22
+ export declare function AlertDialogAction(props: AlertDialogActionProps): import("react").JSX.Element;
23
+ /** Focuses the safe choice on every native open, including when it follows the action. */
24
+ export declare function AlertDialogCancel({ autoFocus, ref, ...props }: AlertDialogCancelProps): import("react").JSX.Element;
25
+ //# sourceMappingURL=AlertDialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlertDialog.d.ts","sourceRoot":"","sources":["../../src/AlertDialog.tsx"],"names":[],"mappings":"AAGA,OAAO,EASL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAA;AAIpB,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,eAAe,CAAC,EAAE,KAAK,CAAA;CAAE,CAAA;AACvF,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAA;AAC1C,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAA;AACtD,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,CAAA;AACxD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,YAAY,CAAC,CAAA;AACrF,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,CAAA;AACpD,MAAM,MAAM,2BAA2B,GAAG,sBAAsB,CAAA;AAChE,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AACvD,MAAM,MAAM,sBAAsB,GAAG,kBAAkB,CAAA;AAEvD,wBAAgB,cAAc,IAAI,gBAAgB,GAAG,IAAI,CAIxD;AAQD,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,+BASlD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,+BAGhE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,+BAGhE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,+BAG5D;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,+BAGxE;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,+BAQ9D;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,EAAE,SAAgB,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,EAAE,sBAAsB,+BAoB5F"}
@@ -0,0 +1,56 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useCallback } from 'react';
4
+ import { DialogRoot, DialogTrigger, DialogContent, DialogTitle, DialogDescription, DialogClose, useDialog, useDialogFamily } from './Dialog.js';
5
+ import { joinIds } from './internal/ids.js';
6
+ import { useComposedRefs } from './react/useComposedRefs.js';
7
+ export function useAlertDialog() {
8
+ const state = useDialog();
9
+ const family = useDialogFamily();
10
+ return family === 'alert-dialog' ? state : null;
11
+ }
12
+ function useAlertDialogContext() {
13
+ const state = useAlertDialog();
14
+ if (!state)
15
+ throw new Error('AlertDialog parts must render inside AlertDialog.');
16
+ return state;
17
+ }
18
+ export function AlertDialog(props) {
19
+ return (_jsx(DialogRoot, { ...props, family: "alert-dialog", modal: true, closeOnBackdrop: false }));
20
+ }
21
+ export function AlertDialogTrigger(props) {
22
+ useAlertDialogContext();
23
+ return _jsx(DialogTrigger, { ...props });
24
+ }
25
+ export function AlertDialogContent(props) {
26
+ useAlertDialogContext();
27
+ return _jsx(DialogContent, { ...props });
28
+ }
29
+ export function AlertDialogTitle(props) {
30
+ useAlertDialogContext();
31
+ return _jsx(DialogTitle, { ...props });
32
+ }
33
+ export function AlertDialogDescription(props) {
34
+ useAlertDialogContext();
35
+ return _jsx(DialogDescription, { ...props });
36
+ }
37
+ /** Runs the caller's action, then requests close unless the action prevents default. */
38
+ export function AlertDialogAction(props) {
39
+ useAlertDialogContext();
40
+ return (_jsx(DialogClose, { ...props, "data-slot": joinIds('alert-dialog-action', props['data-slot']) }));
41
+ }
42
+ /** Focuses the safe choice on every native open, including when it follows the action. */
43
+ export function AlertDialogCancel({ autoFocus = true, ref, ...props }) {
44
+ useAlertDialogContext();
45
+ const autofocusRef = useCallback((node) => {
46
+ // React's autoFocus focuses on mount; the native dialog also needs the attribute on reopen.
47
+ if (node)
48
+ node.autofocus = autoFocus;
49
+ }, [autoFocus]);
50
+ const hostRef = useComposedRefs(autofocusRef, ref);
51
+ return (_jsx(DialogClose, { ...props, ref: hostRef,
52
+ // Cancel is the safe initial target inside a native modal decision.
53
+ // oxlint-disable-next-line jsx-a11y/no-autofocus
54
+ autoFocus: autoFocus, "data-slot": joinIds('alert-dialog-cancel', props['data-slot']) }));
55
+ }
56
+ //# sourceMappingURL=AlertDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlertDialog.js","sourceRoot":"","sources":["../../src/AlertDialog.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AACnC,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,eAAe,EAQhB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAa5D,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,SAAS,EAAE,CAAA;IACzB,MAAM,MAAM,GAAG,eAAe,EAAE,CAAA;IAChC,OAAO,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AACjD,CAAC;AAED,SAAS,qBAAqB;IAC5B,MAAM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;QAC5F,IAAI,IAAI;YAAE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IACtC,CAAC,EACD,CAAC,SAAS,CAAC,CACZ,CAAA;IACD,MAAM,OAAO,GAAG,eAAe,CAAC,YAAY,EAAE,GAAG,CAAC,CAAA;IAClD,OAAO,CACL,KAAC,WAAW,OACN,KAAK,EACT,GAAG,EAAE,OAAO;QACZ,oEAAoE;QACpE,iDAAiD;QACjD,SAAS,EAAE,SAAS,eACT,OAAO,CAAC,qBAAqB,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,GAC7D,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport { useCallback } from 'react'\nimport {\n DialogRoot,\n DialogTrigger,\n DialogContent,\n DialogTitle,\n DialogDescription,\n DialogClose,\n useDialog,\n useDialogFamily,\n type DialogProps,\n type DialogState,\n type DialogContentProps,\n type DialogTitleProps,\n type DialogDescriptionProps,\n type DialogTriggerProps,\n type DialogRenderProps\n} from './Dialog.js'\nimport { joinIds } from './internal/ids.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\n\n/** Always modal. Backdrop clicks never dismiss an urgent decision. */\nexport type AlertDialogProps = DialogProps & { modal?: never; closeOnBackdrop?: never }\nexport type AlertDialogState = DialogState\nexport type AlertDialogRenderProps = DialogRenderProps\nexport type AlertDialogTriggerProps = DialogTriggerProps\nexport type AlertDialogContentProps = Omit<DialogContentProps, 'role' | 'aria-modal'>\nexport type AlertDialogTitleProps = DialogTitleProps\nexport type AlertDialogDescriptionProps = DialogDescriptionProps\nexport type AlertDialogActionProps = DialogTriggerProps\nexport type AlertDialogCancelProps = DialogTriggerProps\n\nexport function useAlertDialog(): AlertDialogState | null {\n const state = useDialog()\n const family = useDialogFamily()\n return family === 'alert-dialog' ? state : null\n}\n\nfunction useAlertDialogContext() {\n const state = useAlertDialog()\n if (!state) throw new Error('AlertDialog parts must render inside AlertDialog.')\n return state\n}\n\nexport function AlertDialog(props: AlertDialogProps) {\n return (\n <DialogRoot\n {...props}\n family=\"alert-dialog\"\n modal\n closeOnBackdrop={false}\n />\n )\n}\n\nexport function AlertDialogTrigger(props: AlertDialogTriggerProps) {\n useAlertDialogContext()\n return <DialogTrigger {...props} />\n}\n\nexport function AlertDialogContent(props: AlertDialogContentProps) {\n useAlertDialogContext()\n return <DialogContent {...props} />\n}\n\nexport function AlertDialogTitle(props: AlertDialogTitleProps) {\n useAlertDialogContext()\n return <DialogTitle {...props} />\n}\n\nexport function AlertDialogDescription(props: AlertDialogDescriptionProps) {\n useAlertDialogContext()\n return <DialogDescription {...props} />\n}\n\n/** Runs the caller's action, then requests close unless the action prevents default. */\nexport function AlertDialogAction(props: AlertDialogActionProps) {\n useAlertDialogContext()\n return (\n <DialogClose\n {...props}\n data-slot={joinIds('alert-dialog-action', props['data-slot'])}\n />\n )\n}\n\n/** Focuses the safe choice on every native open, including when it follows the action. */\nexport function AlertDialogCancel({ autoFocus = true, ref, ...props }: AlertDialogCancelProps) {\n useAlertDialogContext()\n const autofocusRef = useCallback(\n (node: HTMLButtonElement | null) => {\n // React's autoFocus focuses on mount; the native dialog also needs the attribute on reopen.\n if (node) node.autofocus = autoFocus\n },\n [autoFocus]\n )\n const hostRef = useComposedRefs(autofocusRef, ref)\n return (\n <DialogClose\n {...props}\n ref={hostRef}\n // Cancel is the safe initial target inside a native modal decision.\n // oxlint-disable-next-line jsx-a11y/no-autofocus\n autoFocus={autoFocus}\n data-slot={joinIds('alert-dialog-cancel', props['data-slot'])}\n />\n )\n}\n"]}
@@ -44,8 +44,14 @@ export type DialogDescriptionProps = Omit<ComponentProps<'p'>, 'style'> & {
44
44
  style?: ThemeStyle;
45
45
  };
46
46
  export type DialogCloseProps = DialogTriggerProps;
47
+ /** Private composition seam for AlertDialog; not exported from the package. */
48
+ export declare function useDialogFamily(): "dialog" | "alert-dialog";
47
49
  export declare function useDialog(): DialogState | null;
48
- export declare function Dialog({ open, defaultOpen, onOpenChange, modal, closeOnBackdrop, closeOnEscape, children }: DialogProps): import("react").JSX.Element;
50
+ export declare function Dialog(props: DialogProps): import("react").JSX.Element;
51
+ /** Private shared owner: both families keep the same native lifecycle. */
52
+ export declare function DialogRoot({ open, defaultOpen, onOpenChange, modal, closeOnBackdrop, closeOnEscape, children, family }: DialogProps & {
53
+ family?: 'dialog' | 'alert-dialog';
54
+ }): import("react").JSX.Element;
49
55
  export declare function DialogTrigger(props: DialogTriggerProps): import("react").JSX.Element;
50
56
  export declare function DialogContent({ motion, className, onClick, onCancel, onClose, ref, ...props }: DialogContentProps): import("react").JSX.Element;
51
57
  export declare function DialogTitle({ className, children, ...props }: DialogTitleProps): import("react").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../src/Dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAc,SAAS,EAAE,MAAM,OAAO,CAAA;AAGlE,OAAO,EAAU,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAQ9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAoDzD,MAAM,MAAM,WAAW,GAAG,CACtB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,GACtC;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,CAC9C,GAAG;IACF,uFAAuF;IACvF,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,iGAAiG;IACjG,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,qGAAqG;IACrG,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oGAAoG;IACpG,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,OAAO,CAA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CtD;AA2BD,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,+BAOtD;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAkB,EAClB,SAAS,EACT,OAAO,EACP,QAAQ,EACR,OAAO,EACP,GAAG,EACH,GAAG,KAAK,EACT,EAAE,kBAAkB,+BA4EpB;AAED,wBAAgB,WAAW,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,gBAAgB,+BAa9E;AAED,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,sBAAsB,+BAehF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,+BAOlD"}
@@ -56,6 +56,11 @@ const dialogDescriptionVariants = cva([
56
56
  'forced-colors:text-[CanvasText]'
57
57
  ]);
58
58
  const DialogContext = createContext(null);
59
+ const DialogFamilyContext = createContext('dialog');
60
+ /** Private composition seam for AlertDialog; not exported from the package. */
61
+ export function useDialogFamily() {
62
+ return useContext(DialogFamilyContext);
63
+ }
59
64
  export function useDialog() {
60
65
  return useContext(DialogContext);
61
66
  }
@@ -65,7 +70,11 @@ function useDialogContext() {
65
70
  throw new Error('Dialog parts must render inside Dialog.');
66
71
  return dialog;
67
72
  }
68
- export function Dialog({ open, defaultOpen, onOpenChange, modal = true, closeOnBackdrop = true, closeOnEscape = true, children }) {
73
+ export function Dialog(props) {
74
+ return _jsx(DialogRoot, { ...props });
75
+ }
76
+ /** Private shared owner: both families keep the same native lifecycle. */
77
+ export function DialogRoot({ open, defaultOpen, onOpenChange, modal = true, closeOnBackdrop = true, closeOnEscape = true, children, family = 'dialog' }) {
69
78
  const contentId = useId();
70
79
  const titleId = useId();
71
80
  const descriptionId = useId();
@@ -76,20 +85,21 @@ export function Dialog({ open, defaultOpen, onOpenChange, modal = true, closeOnB
76
85
  initialValue: false,
77
86
  onChange: onOpenChange
78
87
  });
79
- return (_jsx(DialogContext.Provider, { value: {
80
- open: isOpen,
81
- setOpen,
82
- contentId,
83
- titleId,
84
- descriptionId,
85
- modal,
86
- closeOnBackdrop,
87
- closeOnEscape,
88
- controlled
89
- }, children: children }));
88
+ return (_jsx(DialogFamilyContext.Provider, { value: family, children: _jsx(DialogContext.Provider, { value: {
89
+ open: isOpen,
90
+ setOpen,
91
+ contentId,
92
+ titleId,
93
+ descriptionId,
94
+ modal,
95
+ closeOnBackdrop,
96
+ closeOnEscape,
97
+ controlled
98
+ }, children: children }) }));
90
99
  }
91
100
  function DialogAction({ action, ...props }) {
92
101
  const dialog = useDialogContext();
102
+ const family = useDialogFamily();
93
103
  const slot = action === 'open' ? 'button dialog-trigger' : 'button dialog-close';
94
104
  const buttonProps = {
95
105
  ...props,
@@ -100,7 +110,9 @@ function DialogAction({ action, ...props }) {
100
110
  'aria-controls': dialog.contentId
101
111
  }
102
112
  : {}),
103
- 'data-slot': slot,
113
+ 'data-slot': joinIds(slot, family === 'alert-dialog'
114
+ ? `alert-dialog-${action === 'open' ? 'trigger' : 'close'}`
115
+ : undefined, props['data-slot']),
104
116
  onClick: composeAction(props.onClick, () => dialog.setOpen(action === 'open'))
105
117
  };
106
118
  return _jsx(Button, { ...buttonProps });
@@ -110,6 +122,7 @@ export function DialogTrigger(props) {
110
122
  }
111
123
  export function DialogContent({ motion = 'inherit', className, onClick, onCancel, onClose, ref, ...props }) {
112
124
  const dialog = useDialogContext();
125
+ const family = useDialogFamily();
113
126
  const nodeRef = useRef(null);
114
127
  const transition = useTransitionHost('dialog', ref, motion === 'off' || callerOwnsPress(props.style, className));
115
128
  const hostRef = useComposedRefs(nodeRef, transition.active ? transition.ref : ref);
@@ -143,7 +156,7 @@ export function DialogContent({ motion = 'inherit', className, onClick, onCancel
143
156
  if (dialogIsOpen(node))
144
157
  closeDialog(node);
145
158
  }, [dialog.modal, dialog.open, generation]);
146
- return (_jsx("dialog", { ...props, open: undefined, ref: hostRef, "aria-describedby": joinIds(dialog.descriptionId, props['aria-describedby']), "aria-labelledby": props['aria-label'] ? props['aria-labelledby'] : dialog.titleId, className: cn(dialogVariants(), className), "data-slot": "dialog", "data-state": dialog.open ? 'open' : 'closed', id: dialog.contentId, onCancel: event => {
159
+ return (_jsx("dialog", { ...props, open: undefined, ref: hostRef, role: family === 'alert-dialog' ? 'alertdialog' : props.role, "aria-modal": family === 'alert-dialog' ? true : props['aria-modal'], "aria-describedby": joinIds(dialog.descriptionId, props['aria-describedby']), "aria-labelledby": props['aria-label'] ? props['aria-labelledby'] : dialog.titleId, className: cn(dialogVariants(), className), "data-slot": family === 'alert-dialog' ? 'dialog alert-dialog' : 'dialog', "data-state": dialog.open ? 'open' : 'closed', id: dialog.contentId, onCancel: event => {
147
160
  // cancel and close bubble, so a nested dialog must not dismiss its parent.
148
161
  if (event.target !== event.currentTarget)
149
162
  return;
@@ -171,11 +184,15 @@ export function DialogContent({ motion = 'inherit', className, onClick, onCancel
171
184
  }
172
185
  export function DialogTitle({ className, children, ...props }) {
173
186
  const dialog = useDialogContext();
174
- return (_jsx("h2", { ...props, className: cn(dialogTitleVariants(), className), "data-slot": "dialog-title", id: dialog.titleId, children: children }));
187
+ const family = useDialogFamily();
188
+ return (_jsx("h2", { ...props, className: cn(dialogTitleVariants(), className), "data-slot": family === 'alert-dialog' ? 'dialog-title alert-dialog-title' : 'dialog-title', id: dialog.titleId, children: children }));
175
189
  }
176
190
  export function DialogDescription({ className, ...props }) {
177
191
  const dialog = useDialogContext();
178
- return (_jsx("p", { ...props, className: cn(dialogDescriptionVariants(), className), "data-slot": "dialog-description", id: dialog.descriptionId }));
192
+ const family = useDialogFamily();
193
+ return (_jsx("p", { ...props, className: cn(dialogDescriptionVariants(), className), "data-slot": family === 'alert-dialog'
194
+ ? 'dialog-description alert-dialog-description'
195
+ : 'dialog-description', id: dialog.descriptionId }));
179
196
  }
180
197
  export function DialogClose(props) {
181
198
  return (_jsx(DialogAction, { ...props, action: "close" }));
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.js","sourceRoot":"","sources":["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AAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE,CAAA;QACX,OAAM;IACR,CAAC;IACD,6DAA6D;IAC7D,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAC/B,CAAC;AAED,SAAS,WAAW,CAAC,IAAuB;IAC1C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;QAAE,OAAM;IAC/B,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,EAAE,CAAA;QACZ,OAAM;IACR,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC;AAED,SAAS,eAAe,CAAC,KAAoC;IAC3D,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,aAAa;QAAE,OAAO,KAAK,CAAA;IACtD,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAC,qBAAqB,EAAE,CAAA;IACvD,IAAI,GAAG,CAAC,KAAK,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrD,OAAO,CACL,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,IAAI;QACxB,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK;QACzB,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG;QACvB,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC,MAAM,CAC3B,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport type { ComponentProps, MouseEvent, ReactNode } from 'react'\nimport { createContext, useContext, useEffect, useId, useRef, useState } from 'react'\nimport { cva } from 'class-variance-authority'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { callerOwnsPress } from './motion/pressPolicy.js'\nimport { useTransitionHost } from './motion/host.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nconst colorMotionClass =\n 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none'\n\nconst dialogVariants = cva([\n colorMotionClass,\n 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)]',\n 'box-border text-start antialiased',\n '[&:not([open])]:hidden',\n 'open:m-auto open:grid open:overflow-auto open:overscroll-contain',\n 'open:max-h-[min(40rem,calc(100dvh-2rem))]',\n 'open:w-[min(calc(100%-2rem),var(--rad-dialog-width,32rem))]',\n 'open:gap-[var(--rad-dialog-gap,var(--rad-surface-gap,1rem))]',\n 'open:p-[var(--rad-dialog-padding,var(--rad-surface-padding,1.5rem))]',\n 'rounded-[var(--rad-dialog-radius,var(--rad-surface-radius,0.75rem))]',\n '[corner-shape:var(--rad-dialog-corner-shape,var(--rad-surface-corner-shape,round))]',\n '[border-width:var(--rad-dialog-border-width,var(--rad-surface-border-width,1px))]',\n '[border-style:var(--rad-dialog-border-style,var(--rad-surface-border-style,solid))]',\n '[border-color:var(--rad-dialog-border-color,var(--rad-color-border,oklch(0.885_0.005_286)))]',\n 'bg-[var(--rad-dialog-background,var(--rad-color-surface,oklch(1_0_0)))]',\n '[backdrop-filter:var(--rad-dialog-backdrop-filter,none)]',\n '[color:var(--rad-dialog-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',\n '[box-shadow:var(--rad-dialog-shadow,var(--rad-surface-overlay-shadow,0_24px_64px_-16px_rgb(0_0_0/0.3)))]',\n 'backdrop:[background:var(--rad-dialog-backdrop,var(--rad-surface-backdrop,rgb(0_0_0/0.45)))]',\n 'focus-visible:outline-solid',\n 'focus-visible:[outline-color:var(--rad-dialog-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',\n 'focus-visible:[outline-width:var(--rad-dialog-focus-width,var(--rad-focus-width,2px))]',\n 'focus-visible:[outline-offset:var(--rad-dialog-focus-offset,var(--rad-focus-offset,2px))]',\n 'focus-visible:[outline-style:var(--rad-dialog-focus-style,var(--rad-focus-style,solid))]',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]',\n 'forced-colors:backdrop:[background:CanvasText]'\n])\n\nconst dialogTitleVariants = cva([\n colorMotionClass,\n 'm-0 min-w-0 break-words',\n 'font-[family-name:var(--rad-typography-roles-ui-title-family,system-ui,sans-serif)] tracking-[var(--rad-typography-roles-ui-title-letter-spacing,-0.015em)]',\n 'text-[length:var(--rad-dialog-title-size,var(--rad-typography-roles-ui-title-size,1.125rem))] leading-[var(--rad-typography-roles-ui-title-line-height,1.3)]',\n 'font-[number:var(--rad-dialog-title-weight,var(--rad-typography-roles-ui-title-weight,600))]',\n 'forced-colors:text-[CanvasText]'\n])\n\nconst dialogDescriptionVariants = cva([\n colorMotionClass,\n 'm-0 min-w-0 break-words',\n '[color:var(--rad-dialog-description-color,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))]',\n 'font-[family-name:var(--rad-typography-roles-ui-supporting-family,system-ui,sans-serif)] font-[number:var(--rad-typography-roles-ui-supporting-weight,400)] tracking-[var(--rad-typography-roles-ui-supporting-letter-spacing,0em)]',\n 'text-[length:var(--rad-dialog-description-size,var(--rad-typography-roles-ui-supporting-size,0.8125rem))] leading-[var(--rad-typography-roles-ui-supporting-line-height,1.5)]',\n 'forced-colors:text-[CanvasText]'\n])\n\nexport type DialogProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n /** A change request. The controlled owner may decline it; prop syncs do not notify. */\n onOpenChange?: (open: boolean) => void\n /** `true` calls `showModal()`. `false` calls `show()` and leaves the rest of the page active. */\n modal?: boolean\n /** Modal only. A backdrop click is a click on the dialog whose point lies outside its border box. */\n closeOnBackdrop?: boolean\n /** Modal only. The browser closes a modal dialog on Escape unless the cancel event is cancelled. */\n closeOnEscape?: boolean\n children?: ReactNode\n}\n\nexport type DialogState = {\n open: boolean\n setOpen: (open: boolean) => void\n contentId: string\n titleId: string\n descriptionId: string\n modal: boolean\n closeOnBackdrop: boolean\n closeOnEscape: boolean\n controlled: boolean\n}\n\nexport type DialogRenderProps = ButtonRenderProps\n\n/** Button props/render/ref contract, with protected dialog relationships. */\nexport type DialogTriggerProps = ButtonProps\n\nexport type DialogContentProps = Omit<ComponentProps<'dialog'>, 'open' | 'style'> & {\n style?: ThemeStyle\n /** Opt-in MotionProvider presentation; native close and focus never wait for an exit. */\n motion?: 'inherit' | 'off'\n}\n\nexport type DialogTitleProps = Omit<ComponentProps<'h2'>, 'style'> & { style?: ThemeStyle }\n\nexport type DialogDescriptionProps = Omit<ComponentProps<'p'>, 'style'> & { style?: ThemeStyle }\n\nexport type DialogCloseProps = DialogTriggerProps\n\nconst DialogContext = createContext<DialogState | null>(null)\n\nexport function useDialog(): DialogState | null {\n return useContext(DialogContext)\n}\n\nfunction useDialogContext() {\n const dialog = useDialog()\n if (!dialog) throw new Error('Dialog parts must render inside Dialog.')\n return dialog\n}\n\nexport function Dialog({\n open,\n defaultOpen,\n onOpenChange,\n modal = true,\n closeOnBackdrop = true,\n closeOnEscape = true,\n children\n}: DialogProps) {\n const contentId = useId()\n const titleId = useId()\n const descriptionId = useId()\n const {\n value: isOpen,\n request: setOpen,\n controlled\n } = useControllableState({\n name: 'Dialog',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n\n return (\n <DialogContext.Provider\n value={{\n open: isOpen,\n setOpen,\n contentId,\n titleId,\n descriptionId,\n modal,\n closeOnBackdrop,\n closeOnEscape,\n controlled\n }}\n >\n {children}\n </DialogContext.Provider>\n )\n}\n\nfunction DialogAction({ action, ...props }: DialogTriggerProps & { action: 'open' | 'close' }) {\n const dialog = useDialogContext()\n const slot = action === 'open' ? 'button dialog-trigger' : 'button dialog-close'\n const buttonProps: ButtonProps = {\n ...props,\n ...(action === 'open'\n ? {\n 'aria-haspopup': 'dialog',\n 'aria-expanded': dialog.open,\n 'aria-controls': dialog.contentId\n }\n : {}),\n 'data-slot': slot,\n onClick: composeAction(props.onClick, () => dialog.setOpen(action === 'open'))\n }\n return <Button {...buttonProps} />\n}\n\nexport function DialogTrigger(props: DialogTriggerProps) {\n return (\n <DialogAction\n {...props}\n action=\"open\"\n />\n )\n}\n\nexport function DialogContent({\n motion = 'inherit',\n className,\n onClick,\n onCancel,\n onClose,\n ref,\n ...props\n}: DialogContentProps) {\n const dialog = useDialogContext()\n const nodeRef = useRef<HTMLDialogElement>(null)\n const transition = useTransitionHost<HTMLDialogElement>(\n 'dialog',\n ref,\n motion === 'off' || callerOwnsPress(props.style, className)\n )\n const hostRef = useComposedRefs(nodeRef, transition.active ? transition.ref : ref)\n const unmounting = useRef(false)\n const previousModal = useRef(dialog.modal)\n // Bumps after the browser closes a dialog whose controlled `open` value is still true.\n const [generation, setGeneration] = useState(0)\n\n useEffect(() => {\n unmounting.current = false\n const node = nodeRef.current\n return () => {\n unmounting.current = true\n if (node) closeDialog(node)\n }\n }, [])\n\n useEffect(() => {\n const node = nodeRef.current\n if (!node || generation < 0) return\n if (previousModal.current !== dialog.modal) {\n // The platform cannot change an already-open dialog's modal mode in place.\n closeDialog(node)\n previousModal.current = dialog.modal\n }\n if (dialog.open) {\n if (!dialogIsOpen(node)) openDialog(node, dialog.modal)\n return\n }\n if (dialogIsOpen(node)) closeDialog(node)\n }, [dialog.modal, dialog.open, generation])\n\n return (\n // Backdrop clicks are pointer hit tests on the dialog element. Escape uses the cancel event.\n // oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n {...props}\n open={undefined}\n ref={hostRef}\n aria-describedby={joinIds(dialog.descriptionId, props['aria-describedby'])}\n aria-labelledby={props['aria-label'] ? props['aria-labelledby'] : dialog.titleId}\n className={cn(dialogVariants(), className)}\n data-slot=\"dialog\"\n data-state={dialog.open ? 'open' : 'closed'}\n id={dialog.contentId}\n onCancel={event => {\n // cancel and close bubble, so a nested dialog must not dismiss its parent.\n if (event.target !== event.currentTarget) return\n onCancel?.(event)\n if (!dialog.closeOnEscape) event.preventDefault()\n }}\n onClick={composeAction(onClick, event => {\n if (!dialog.modal || !dialog.closeOnBackdrop) return\n if (!isBackdropClick(event)) return\n dialog.setOpen(false)\n })}\n onClose={event => {\n if (event.target !== event.currentTarget) return\n onClose?.(event)\n // close() queues its event. StrictMode cleanup or a consumer can reopen\n // this same native dialog before that event arrives.\n if (unmounting.current || !dialog.open || dialogIsOpen(event.currentTarget)) return\n dialog.setOpen(false)\n if (dialog.controlled) setGeneration(current => current + 1)\n }}\n />\n )\n}\n\nexport function DialogTitle({ className, children, ...props }: DialogTitleProps) {\n const dialog = useDialogContext()\n return (\n <h2\n {...props}\n className={cn(dialogTitleVariants(), className)}\n data-slot=\"dialog-title\"\n id={dialog.titleId}\n >\n {children}\n </h2>\n )\n}\n\nexport function DialogDescription({ className, ...props }: DialogDescriptionProps) {\n const dialog = useDialogContext()\n return (\n <p\n {...props}\n className={cn(dialogDescriptionVariants(), className)}\n data-slot=\"dialog-description\"\n id={dialog.descriptionId}\n />\n )\n}\n\nexport function DialogClose(props: DialogCloseProps) {\n return (\n <DialogAction\n {...props}\n action=\"close\"\n />\n )\n}\n\nfunction dialogIsOpen(node: HTMLDialogElement) {\n return node.hasAttribute('open')\n}\n\nfunction openDialog(node: HTMLDialogElement, modal: boolean) {\n if (dialogIsOpen(node)) return\n if (modal && typeof node.showModal === 'function') {\n node.showModal()\n return\n }\n if (!modal && typeof node.show === 'function') {\n node.show()\n return\n }\n // Without dialog methods, the attribute still marks it open.\n node.setAttribute('open', '')\n}\n\nfunction closeDialog(node: HTMLDialogElement) {\n if (!dialogIsOpen(node)) return\n if (typeof node.close === 'function') {\n node.close()\n return\n }\n node.removeAttribute('open')\n}\n\nfunction isBackdropClick(event: MouseEvent<HTMLDialogElement>) {\n if (event.target !== event.currentTarget) return false\n const box = event.currentTarget.getBoundingClientRect()\n if (box.width === 0 && box.height === 0) return false\n return (\n event.clientX < box.left ||\n event.clientX > box.right ||\n event.clientY < box.top ||\n event.clientY > box.bottom\n )\n}\n"]}
1
+ {"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../src/Dialog.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACrF,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAC9C,OAAO,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAA;AAGtE,MAAM,gBAAgB,GACpB,mGAAmG,CAAA;AAErG,MAAM,cAAc,GAAG,GAAG,CAAC;IACzB,gBAAgB;IAChB,sVAAsV;IACtV,mCAAmC;IACnC,wBAAwB;IACxB,kEAAkE;IAClE,2CAA2C;IAC3C,6DAA6D;IAC7D,8DAA8D;IAC9D,sEAAsE;IACtE,sEAAsE;IACtE,qFAAqF;IACrF,mFAAmF;IACn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client'\n\nimport type { ComponentProps, MouseEvent, ReactNode } from 'react'\nimport { createContext, useContext, useEffect, useId, useRef, useState } from 'react'\nimport { cva } from 'class-variance-authority'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { callerOwnsPress } from './motion/pressPolicy.js'\nimport { useTransitionHost } from './motion/host.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nconst colorMotionClass =\n 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none'\n\nconst dialogVariants = cva([\n colorMotionClass,\n 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)]',\n 'box-border text-start antialiased',\n '[&:not([open])]:hidden',\n 'open:m-auto open:grid open:overflow-auto open:overscroll-contain',\n 'open:max-h-[min(40rem,calc(100dvh-2rem))]',\n 'open:w-[min(calc(100%-2rem),var(--rad-dialog-width,32rem))]',\n 'open:gap-[var(--rad-dialog-gap,var(--rad-surface-gap,1rem))]',\n 'open:p-[var(--rad-dialog-padding,var(--rad-surface-padding,1.5rem))]',\n 'rounded-[var(--rad-dialog-radius,var(--rad-surface-radius,0.75rem))]',\n '[corner-shape:var(--rad-dialog-corner-shape,var(--rad-surface-corner-shape,round))]',\n '[border-width:var(--rad-dialog-border-width,var(--rad-surface-border-width,1px))]',\n '[border-style:var(--rad-dialog-border-style,var(--rad-surface-border-style,solid))]',\n '[border-color:var(--rad-dialog-border-color,var(--rad-color-border,oklch(0.885_0.005_286)))]',\n 'bg-[var(--rad-dialog-background,var(--rad-color-surface,oklch(1_0_0)))]',\n '[backdrop-filter:var(--rad-dialog-backdrop-filter,none)]',\n '[color:var(--rad-dialog-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))]',\n '[box-shadow:var(--rad-dialog-shadow,var(--rad-surface-overlay-shadow,0_24px_64px_-16px_rgb(0_0_0/0.3)))]',\n 'backdrop:[background:var(--rad-dialog-backdrop,var(--rad-surface-backdrop,rgb(0_0_0/0.45)))]',\n 'focus-visible:outline-solid',\n 'focus-visible:[outline-color:var(--rad-dialog-focus-color,var(--rad-color-focus,oklch(0.55_0.13_255)))]',\n 'focus-visible:[outline-width:var(--rad-dialog-focus-width,var(--rad-focus-width,2px))]',\n 'focus-visible:[outline-offset:var(--rad-dialog-focus-offset,var(--rad-focus-offset,2px))]',\n 'focus-visible:[outline-style:var(--rad-dialog-focus-style,var(--rad-focus-style,solid))]',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]',\n 'forced-colors:backdrop:[background:CanvasText]'\n])\n\nconst dialogTitleVariants = cva([\n colorMotionClass,\n 'm-0 min-w-0 break-words',\n 'font-[family-name:var(--rad-typography-roles-ui-title-family,system-ui,sans-serif)] tracking-[var(--rad-typography-roles-ui-title-letter-spacing,-0.015em)]',\n 'text-[length:var(--rad-dialog-title-size,var(--rad-typography-roles-ui-title-size,1.125rem))] leading-[var(--rad-typography-roles-ui-title-line-height,1.3)]',\n 'font-[number:var(--rad-dialog-title-weight,var(--rad-typography-roles-ui-title-weight,600))]',\n 'forced-colors:text-[CanvasText]'\n])\n\nconst dialogDescriptionVariants = cva([\n colorMotionClass,\n 'm-0 min-w-0 break-words',\n '[color:var(--rad-dialog-description-color,var(--rad-color-muted-foreground,oklch(0.45_0.01_286)))]',\n 'font-[family-name:var(--rad-typography-roles-ui-supporting-family,system-ui,sans-serif)] font-[number:var(--rad-typography-roles-ui-supporting-weight,400)] tracking-[var(--rad-typography-roles-ui-supporting-letter-spacing,0em)]',\n 'text-[length:var(--rad-dialog-description-size,var(--rad-typography-roles-ui-supporting-size,0.8125rem))] leading-[var(--rad-typography-roles-ui-supporting-line-height,1.5)]',\n 'forced-colors:text-[CanvasText]'\n])\n\nexport type DialogProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n /** A change request. The controlled owner may decline it; prop syncs do not notify. */\n onOpenChange?: (open: boolean) => void\n /** `true` calls `showModal()`. `false` calls `show()` and leaves the rest of the page active. */\n modal?: boolean\n /** Modal only. A backdrop click is a click on the dialog whose point lies outside its border box. */\n closeOnBackdrop?: boolean\n /** Modal only. The browser closes a modal dialog on Escape unless the cancel event is cancelled. */\n closeOnEscape?: boolean\n children?: ReactNode\n}\n\nexport type DialogState = {\n open: boolean\n setOpen: (open: boolean) => void\n contentId: string\n titleId: string\n descriptionId: string\n modal: boolean\n closeOnBackdrop: boolean\n closeOnEscape: boolean\n controlled: boolean\n}\n\nexport type DialogRenderProps = ButtonRenderProps\n\n/** Button props/render/ref contract, with protected dialog relationships. */\nexport type DialogTriggerProps = ButtonProps\n\nexport type DialogContentProps = Omit<ComponentProps<'dialog'>, 'open' | 'style'> & {\n style?: ThemeStyle\n /** Opt-in MotionProvider presentation; native close and focus never wait for an exit. */\n motion?: 'inherit' | 'off'\n}\n\nexport type DialogTitleProps = Omit<ComponentProps<'h2'>, 'style'> & { style?: ThemeStyle }\n\nexport type DialogDescriptionProps = Omit<ComponentProps<'p'>, 'style'> & { style?: ThemeStyle }\n\nexport type DialogCloseProps = DialogTriggerProps\n\nconst DialogContext = createContext<DialogState | null>(null)\nconst DialogFamilyContext = createContext<'dialog' | 'alert-dialog'>('dialog')\n\n/** Private composition seam for AlertDialog; not exported from the package. */\nexport function useDialogFamily() {\n return useContext(DialogFamilyContext)\n}\n\nexport function useDialog(): DialogState | null {\n return useContext(DialogContext)\n}\n\nfunction useDialogContext() {\n const dialog = useDialog()\n if (!dialog) throw new Error('Dialog parts must render inside Dialog.')\n return dialog\n}\n\nexport function Dialog(props: DialogProps) {\n return <DialogRoot {...props} />\n}\n\n/** Private shared owner: both families keep the same native lifecycle. */\nexport function DialogRoot({\n open,\n defaultOpen,\n onOpenChange,\n modal = true,\n closeOnBackdrop = true,\n closeOnEscape = true,\n children,\n family = 'dialog'\n}: DialogProps & { family?: 'dialog' | 'alert-dialog' }) {\n const contentId = useId()\n const titleId = useId()\n const descriptionId = useId()\n const {\n value: isOpen,\n request: setOpen,\n controlled\n } = useControllableState({\n name: 'Dialog',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n\n return (\n <DialogFamilyContext.Provider value={family}>\n <DialogContext.Provider\n value={{\n open: isOpen,\n setOpen,\n contentId,\n titleId,\n descriptionId,\n modal,\n closeOnBackdrop,\n closeOnEscape,\n controlled\n }}\n >\n {children}\n </DialogContext.Provider>\n </DialogFamilyContext.Provider>\n )\n}\n\nfunction DialogAction({ action, ...props }: DialogTriggerProps & { action: 'open' | 'close' }) {\n const dialog = useDialogContext()\n const family = useDialogFamily()\n const slot = action === 'open' ? 'button dialog-trigger' : 'button dialog-close'\n const buttonProps: ButtonProps = {\n ...props,\n ...(action === 'open'\n ? {\n 'aria-haspopup': 'dialog',\n 'aria-expanded': dialog.open,\n 'aria-controls': dialog.contentId\n }\n : {}),\n 'data-slot': joinIds(\n slot,\n family === 'alert-dialog'\n ? `alert-dialog-${action === 'open' ? 'trigger' : 'close'}`\n : undefined,\n props['data-slot']\n ),\n onClick: composeAction(props.onClick, () => dialog.setOpen(action === 'open'))\n }\n return <Button {...buttonProps} />\n}\n\nexport function DialogTrigger(props: DialogTriggerProps) {\n return (\n <DialogAction\n {...props}\n action=\"open\"\n />\n )\n}\n\nexport function DialogContent({\n motion = 'inherit',\n className,\n onClick,\n onCancel,\n onClose,\n ref,\n ...props\n}: DialogContentProps) {\n const dialog = useDialogContext()\n const family = useDialogFamily()\n const nodeRef = useRef<HTMLDialogElement>(null)\n const transition = useTransitionHost<HTMLDialogElement>(\n 'dialog',\n ref,\n motion === 'off' || callerOwnsPress(props.style, className)\n )\n const hostRef = useComposedRefs(nodeRef, transition.active ? transition.ref : ref)\n const unmounting = useRef(false)\n const previousModal = useRef(dialog.modal)\n // Bumps after the browser closes a dialog whose controlled `open` value is still true.\n const [generation, setGeneration] = useState(0)\n\n useEffect(() => {\n unmounting.current = false\n const node = nodeRef.current\n return () => {\n unmounting.current = true\n if (node) closeDialog(node)\n }\n }, [])\n\n useEffect(() => {\n const node = nodeRef.current\n if (!node || generation < 0) return\n if (previousModal.current !== dialog.modal) {\n // The platform cannot change an already-open dialog's modal mode in place.\n closeDialog(node)\n previousModal.current = dialog.modal\n }\n if (dialog.open) {\n if (!dialogIsOpen(node)) openDialog(node, dialog.modal)\n return\n }\n if (dialogIsOpen(node)) closeDialog(node)\n }, [dialog.modal, dialog.open, generation])\n\n return (\n // Backdrop clicks are pointer hit tests on the dialog element. Escape uses the cancel event.\n // oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions\n <dialog\n {...props}\n open={undefined}\n ref={hostRef}\n role={family === 'alert-dialog' ? 'alertdialog' : props.role}\n aria-modal={family === 'alert-dialog' ? true : props['aria-modal']}\n aria-describedby={joinIds(dialog.descriptionId, props['aria-describedby'])}\n aria-labelledby={props['aria-label'] ? props['aria-labelledby'] : dialog.titleId}\n className={cn(dialogVariants(), className)}\n data-slot={family === 'alert-dialog' ? 'dialog alert-dialog' : 'dialog'}\n data-state={dialog.open ? 'open' : 'closed'}\n id={dialog.contentId}\n onCancel={event => {\n // cancel and close bubble, so a nested dialog must not dismiss its parent.\n if (event.target !== event.currentTarget) return\n onCancel?.(event)\n if (!dialog.closeOnEscape) event.preventDefault()\n }}\n onClick={composeAction(onClick, event => {\n if (!dialog.modal || !dialog.closeOnBackdrop) return\n if (!isBackdropClick(event)) return\n dialog.setOpen(false)\n })}\n onClose={event => {\n if (event.target !== event.currentTarget) return\n onClose?.(event)\n // close() queues its event. StrictMode cleanup or a consumer can reopen\n // this same native dialog before that event arrives.\n if (unmounting.current || !dialog.open || dialogIsOpen(event.currentTarget)) return\n dialog.setOpen(false)\n if (dialog.controlled) setGeneration(current => current + 1)\n }}\n />\n )\n}\n\nexport function DialogTitle({ className, children, ...props }: DialogTitleProps) {\n const dialog = useDialogContext()\n const family = useDialogFamily()\n return (\n <h2\n {...props}\n className={cn(dialogTitleVariants(), className)}\n data-slot={family === 'alert-dialog' ? 'dialog-title alert-dialog-title' : 'dialog-title'}\n id={dialog.titleId}\n >\n {children}\n </h2>\n )\n}\n\nexport function DialogDescription({ className, ...props }: DialogDescriptionProps) {\n const dialog = useDialogContext()\n const family = useDialogFamily()\n return (\n <p\n {...props}\n className={cn(dialogDescriptionVariants(), className)}\n data-slot={\n family === 'alert-dialog'\n ? 'dialog-description alert-dialog-description'\n : 'dialog-description'\n }\n id={dialog.descriptionId}\n />\n )\n}\n\nexport function DialogClose(props: DialogCloseProps) {\n return (\n <DialogAction\n {...props}\n action=\"close\"\n />\n )\n}\n\nfunction dialogIsOpen(node: HTMLDialogElement) {\n return node.hasAttribute('open')\n}\n\nfunction openDialog(node: HTMLDialogElement, modal: boolean) {\n if (dialogIsOpen(node)) return\n if (modal && typeof node.showModal === 'function') {\n node.showModal()\n return\n }\n if (!modal && typeof node.show === 'function') {\n node.show()\n return\n }\n // Without dialog methods, the attribute still marks it open.\n node.setAttribute('open', '')\n}\n\nfunction closeDialog(node: HTMLDialogElement) {\n if (!dialogIsOpen(node)) return\n if (typeof node.close === 'function') {\n node.close()\n return\n }\n node.removeAttribute('open')\n}\n\nfunction isBackdropClick(event: MouseEvent<HTMLDialogElement>) {\n if (event.target !== event.currentTarget) return false\n const box = event.currentTarget.getBoundingClientRect()\n if (box.width === 0 && box.height === 0) return false\n return (\n event.clientX < box.left ||\n event.clientX > box.right ||\n event.clientY < box.top ||\n event.clientY > box.bottom\n )\n}\n"]}
@@ -0,0 +1,44 @@
1
+ import { type ComponentProps, type ReactNode, type RefObject } from 'react';
2
+ import { type ButtonProps, type ButtonRenderProps } from './Button.js';
3
+ import type { PopoverSide, PopoverAlign } from './internal/popover.js';
4
+ import type { ThemeStyle } from './themes/defineTheme.js';
5
+ export type { PopoverSide, PopoverAlign } from './internal/popover.js';
6
+ export type PopoverProps = ({
7
+ open: boolean;
8
+ defaultOpen?: never;
9
+ } | {
10
+ open?: undefined;
11
+ defaultOpen?: boolean;
12
+ }) & {
13
+ onOpenChange?: (open: boolean) => void;
14
+ children?: ReactNode;
15
+ };
16
+ export type PopoverState = {
17
+ open: boolean;
18
+ setOpen: (open: boolean) => void;
19
+ contentId: string;
20
+ };
21
+ export declare function usePopover(): PopoverState | null;
22
+ export declare function Popover({ open, defaultOpen, onOpenChange, children }: PopoverProps): import("react").JSX.Element;
23
+ export type PopoverTriggerProps = ButtonProps;
24
+ export type PopoverCloseProps = ButtonProps;
25
+ export type PopoverRenderProps = ButtonRenderProps;
26
+ export type PopoverPortalProps = {
27
+ children?: ReactNode;
28
+ };
29
+ export type PopoverContentProps = Omit<ComponentProps<'div'>, 'style' | 'popover' | 'id'> & {
30
+ style?: ThemeStyle;
31
+ side?: PopoverSide;
32
+ align?: PopoverAlign;
33
+ sideOffset?: number;
34
+ collisionPadding?: number;
35
+ /** Keep focus on the opener by default; optionally focus a descendant on each open. */
36
+ initialFocusRef?: RefObject<HTMLElement | null>;
37
+ motion?: 'inherit' | 'off';
38
+ };
39
+ export declare function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps): import("react").JSX.Element;
40
+ export declare function PopoverClose({ onClick, ...props }: PopoverCloseProps): import("react").JSX.Element;
41
+ /** The local portal preserves theme, native form ownership and modal ancestry. */
42
+ export declare function PopoverPortal({ children }: PopoverPortalProps): import("react").ReactPortal | null;
43
+ export declare function PopoverContent({ ref, className, side, align, sideOffset, collisionPadding, initialFocusRef, motion, ...props }: PopoverContentProps): import("react").JSX.Element;
44
+ //# sourceMappingURL=Popover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popover.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,SAAS,CAAA;CAAE,CAAA;AACzD,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAAC,GAAG;IAC1F,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,uFAAuF;IACvF,eAAe,CAAC,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAC/C,MAAM,CAAC,EAAE,SAAS,GAAG,KAAK,CAAA;CAC3B,CAAA;AAED,wBAAgB,cAAc,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,mBAAmB,+BAe7E;AACD,wBAAgB,YAAY,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,+BAWpE;AACD,kFAAkF;AAClF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,EAAE,kBAAkB,sCAK7D;AAgBD,wBAAgB,cAAc,CAAC,EAC7B,GAAG,EACH,SAAS,EACT,IAAe,EACf,KAAe,EACf,UAAc,EACd,gBAAoB,EACpB,eAAe,EACf,MAAkB,EAClB,GAAG,KAAK,EACT,EAAE,mBAAmB,+BAsCrB"}
@@ -0,0 +1,94 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useId, useRef, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { Button } from './Button.js';
6
+ import { cn } from './cn.js';
7
+ import { composeAction } from './internal/events.js';
8
+ import { joinIds } from './internal/ids.js';
9
+ import { useControllableState } from './react/useControllableState.js';
10
+ import { useComposedRefs } from './react/useComposedRefs.js';
11
+ import { usePopoverSurface } from './react/usePopoverSurface.js';
12
+ import { useTransitionHost } from './motion/host.js';
13
+ const PopoverContext = createContext(null);
14
+ export function usePopover() {
15
+ return useContext(PopoverContext);
16
+ }
17
+ function usePopoverContext() {
18
+ const value = useContext(PopoverContext);
19
+ if (!value)
20
+ throw new Error('Popover parts must render inside Popover.');
21
+ return value;
22
+ }
23
+ export function Popover({ open, defaultOpen, onOpenChange, children }) {
24
+ const state = useControllableState({
25
+ name: 'Popover',
26
+ value: open,
27
+ defaultValue: defaultOpen,
28
+ initialValue: false,
29
+ onChange: onOpenChange
30
+ });
31
+ const contentId = useId();
32
+ const [trigger, setTrigger] = useState(null);
33
+ const content = useRef(null);
34
+ const restoreFocus = useRef(true);
35
+ const setOpen = (next) => {
36
+ restoreFocus.current = true;
37
+ state.request(next);
38
+ };
39
+ const close = (restore) => {
40
+ restoreFocus.current = restore;
41
+ state.request(false);
42
+ };
43
+ return (_jsx(PopoverContext.Provider, { value: {
44
+ open: state.value,
45
+ setOpen,
46
+ contentId,
47
+ trigger,
48
+ setTrigger,
49
+ content,
50
+ restoreFocus,
51
+ close
52
+ }, children: children }));
53
+ }
54
+ export function PopoverTrigger({ ref, onClick, ...props }) {
55
+ const popover = usePopoverContext();
56
+ const hostRef = useComposedRefs(popover.setTrigger, ref);
57
+ return (_jsx(Button, { ...props, ref: hostRef, popoverTarget: undefined, popoverTargetAction: undefined, "aria-controls": popover.contentId, "aria-expanded": popover.open, "data-slot": joinIds('popover-trigger', props['data-slot']), onClick: composeAction(onClick, () => popover.setOpen(!popover.open)) }));
58
+ }
59
+ export function PopoverClose({ onClick, ...props }) {
60
+ const popover = usePopoverContext();
61
+ return (_jsx(Button, { ...props, popoverTarget: undefined, popoverTargetAction: undefined, "data-slot": joinIds('popover-close', props['data-slot']), onClick: composeAction(onClick, () => popover.close(true)) }));
62
+ }
63
+ /** The local portal preserves theme, native form ownership and modal ancestry. */
64
+ export function PopoverPortal({ children }) {
65
+ const popover = usePopoverContext();
66
+ return popover.trigger?.parentElement
67
+ ? createPortal(children, popover.trigger.parentElement)
68
+ : null;
69
+ }
70
+ const surfaceClass = [
71
+ 'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-auto overscroll-contain text-start antialiased',
72
+ '[&:not(:popover-open)]:hidden',
73
+ 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] w-[var(--rad-popover-width,20rem)] max-w-[var(--_rad-popover-max-width,calc(100vw-1rem))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]',
74
+ 'grid gap-[var(--rad-popover-gap,var(--rad-surface-gap,1rem))] p-[var(--rad-popover-padding,var(--rad-surface-padding,1.5rem))]',
75
+ 'rounded-[var(--rad-popover-radius,var(--rad-surface-radius,0.75rem))] [corner-shape:var(--rad-popover-corner-shape,var(--rad-surface-corner-shape,round))]',
76
+ '[border-width:var(--rad-popover-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-popover-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-popover-border-color,var(--rad-color-border))]',
77
+ 'bg-[var(--rad-popover-background,var(--rad-color-surface,white))] [color:var(--rad-popover-color,var(--rad-color-foreground))] [box-shadow:var(--rad-popover-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))] [backdrop-filter:var(--rad-popover-backdrop-filter,none)]',
78
+ 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',
79
+ 'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-popover-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-popover-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-popover-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-popover-focus-style,var(--rad-focus-style,solid))]',
80
+ 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none',
81
+ 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'
82
+ ].join(' ');
83
+ export function PopoverContent({ ref, className, side = 'bottom', align = 'start', sideOffset = 8, collisionPadding = 8, initialFocusRef, motion = 'inherit', ...props }) {
84
+ const popover = usePopoverContext();
85
+ if (![sideOffset, collisionPadding].every(value => Number.isFinite(value) && value >= 0))
86
+ throw new TypeError('Popover offsets and padding must be finite, nonnegative numbers.');
87
+ const hostRef = useComposedRefs(popover.content, ref);
88
+ const { ref: transitionRef, active: motionActive, off: motionOff } = useTransitionHost('popup', hostRef, motion === 'off');
89
+ usePopoverSurface(popover.content, popover.trigger, popover.open, popover.close, popover.restoreFocus, { side, align, sideOffset, collisionPadding, initialFocusRef });
90
+ return (_jsx("div", { ...props, ref: transitionRef, id: popover.contentId, popover: "manual", "data-slot": "popover-content", "data-state": popover.open ? 'open' : 'closed', "data-side": side, "data-align": align, "data-motion": motion, className: cn(surfaceClass, motionActive &&
91
+ !motionOff &&
92
+ 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100', className) }));
93
+ }
94
+ //# sourceMappingURL=Popover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Popover.js","sourceRoot":"","sources":["../../src/Popover.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EACL,aAAa,EACb,UAAU,EACV,KAAK,EACL,MAAM,EACN,QAAQ,EAIT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,MAAM,EAA4C,MAAM,aAAa,CAAA;AAC9E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C,OAAO,EAAE,oBAAoB,EAAE,MAA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;IACzD,iBAAiB,CACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,YAAY,EACpB,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,CAC/D,CAAA;IACD,OAAO,CACL,iBACM,KAAK,EACT,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,OAAO,CAAC,SAAS,EACrB,OAAO,EAAC,QAAQ,eACN,iBAAiB,gBACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,eACjC,IAAI,gBACH,KAAK,iBACJ,MAAM,EACnB,SAAS,EAAE,EAAE,CACX,YAAY,EACZ,YAAY;YACV,CAAC,SAAS;YACV,+DAA+D,EACjE,SAAS,CACV,GACD,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\n\nimport {\n createContext,\n useContext,\n useId,\n useRef,\n useState,\n type ComponentProps,\n type ReactNode,\n type RefObject\n} from 'react'\nimport { createPortal } from 'react-dom'\nimport { Button, type ButtonProps, type ButtonRenderProps } from './Button.js'\nimport { cn } from './cn.js'\nimport { composeAction } from './internal/events.js'\nimport { joinIds } from './internal/ids.js'\nimport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nimport { useControllableState } from './react/useControllableState.js'\nimport { useComposedRefs } from './react/useComposedRefs.js'\nimport { usePopoverSurface } from './react/usePopoverSurface.js'\nimport { useTransitionHost } from './motion/host.js'\nimport type { ThemeStyle } from './themes/defineTheme.js'\n\nexport type { PopoverSide, PopoverAlign } from './internal/popover.js'\nexport type PopoverProps = (\n | { open: boolean; defaultOpen?: never }\n | { open?: undefined; defaultOpen?: boolean }\n) & {\n onOpenChange?: (open: boolean) => void\n children?: ReactNode\n}\nexport type PopoverState = { open: boolean; setOpen: (open: boolean) => void; contentId: string }\ntype Context = PopoverState & {\n trigger: HTMLButtonElement | null\n setTrigger: (node: HTMLButtonElement | null) => void\n content: RefObject<HTMLDivElement | null>\n restoreFocus: RefObject<boolean>\n close: (restore: boolean) => void\n}\nconst PopoverContext = createContext<Context | null>(null)\nexport function usePopover(): PopoverState | null {\n return useContext(PopoverContext)\n}\nfunction usePopoverContext() {\n const value = useContext(PopoverContext)\n if (!value) throw new Error('Popover parts must render inside Popover.')\n return value\n}\nexport function Popover({ open, defaultOpen, onOpenChange, children }: PopoverProps) {\n const state = useControllableState({\n name: 'Popover',\n value: open,\n defaultValue: defaultOpen,\n initialValue: false,\n onChange: onOpenChange\n })\n const contentId = useId()\n const [trigger, setTrigger] = useState<HTMLButtonElement | null>(null)\n const content = useRef<HTMLDivElement>(null)\n const restoreFocus = useRef(true)\n const setOpen = (next: boolean) => {\n restoreFocus.current = true\n state.request(next)\n }\n const close = (restore: boolean) => {\n restoreFocus.current = restore\n state.request(false)\n }\n return (\n <PopoverContext.Provider\n value={{\n open: state.value,\n setOpen,\n contentId,\n trigger,\n setTrigger,\n content,\n restoreFocus,\n close\n }}\n >\n {children}\n </PopoverContext.Provider>\n )\n}\n\nexport type PopoverTriggerProps = ButtonProps\nexport type PopoverCloseProps = ButtonProps\nexport type PopoverRenderProps = ButtonRenderProps\nexport type PopoverPortalProps = { children?: ReactNode }\nexport type PopoverContentProps = Omit<ComponentProps<'div'>, 'style' | 'popover' | 'id'> & {\n style?: ThemeStyle\n side?: PopoverSide\n align?: PopoverAlign\n sideOffset?: number\n collisionPadding?: number\n /** Keep focus on the opener by default; optionally focus a descendant on each open. */\n initialFocusRef?: RefObject<HTMLElement | null>\n motion?: 'inherit' | 'off'\n}\n\nexport function PopoverTrigger({ ref, onClick, ...props }: PopoverTriggerProps) {\n const popover = usePopoverContext()\n const hostRef = useComposedRefs(popover.setTrigger, ref)\n return (\n <Button\n {...props}\n ref={hostRef}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n aria-controls={popover.contentId}\n aria-expanded={popover.open}\n data-slot={joinIds('popover-trigger', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.setOpen(!popover.open))}\n />\n )\n}\nexport function PopoverClose({ onClick, ...props }: PopoverCloseProps) {\n const popover = usePopoverContext()\n return (\n <Button\n {...props}\n popoverTarget={undefined}\n popoverTargetAction={undefined}\n data-slot={joinIds('popover-close', props['data-slot'])}\n onClick={composeAction(onClick, () => popover.close(true))}\n />\n )\n}\n/** The local portal preserves theme, native form ownership and modal ancestry. */\nexport function PopoverPortal({ children }: PopoverPortalProps) {\n const popover = usePopoverContext()\n return popover.trigger?.parentElement\n ? createPortal(children, popover.trigger.parentElement)\n : null\n}\n\nconst surfaceClass = [\n 'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-auto overscroll-contain text-start antialiased',\n '[&:not(:popover-open)]:hidden',\n 'left-[var(--_rad-popover-left,0px)] top-[var(--_rad-popover-top,0px)] w-[var(--rad-popover-width,20rem)] max-w-[var(--_rad-popover-max-width,calc(100vw-1rem))] max-h-[var(--_rad-popover-max-height,calc(100dvh-1rem))]',\n 'grid gap-[var(--rad-popover-gap,var(--rad-surface-gap,1rem))] p-[var(--rad-popover-padding,var(--rad-surface-padding,1.5rem))]',\n 'rounded-[var(--rad-popover-radius,var(--rad-surface-radius,0.75rem))] [corner-shape:var(--rad-popover-corner-shape,var(--rad-surface-corner-shape,round))]',\n '[border-width:var(--rad-popover-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-popover-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-popover-border-color,var(--rad-color-border))]',\n 'bg-[var(--rad-popover-background,var(--rad-color-surface,white))] [color:var(--rad-popover-color,var(--rad-color-foreground))] [box-shadow:var(--rad-popover-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))] [backdrop-filter:var(--rad-popover-backdrop-filter,none)]',\n 'font-[family-name:var(--rad-typography-roles-ui-body-family,system-ui,sans-serif)] text-[length:var(--rad-typography-roles-ui-body-size,0.875rem)] font-[number:var(--rad-typography-roles-ui-body-weight,400)] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',\n 'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-popover-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-popover-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-popover-focus-offset,var(--rad-focus-offset,2px))] focus-visible:[outline-style:var(--rad-popover-focus-style,var(--rad-focus-style,solid))]',\n 'transition-colors duration-[var(--rad-motion-color-duration,150ms)] motion-reduce:transition-none',\n 'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'\n].join(' ')\n\nexport function PopoverContent({\n ref,\n className,\n side = 'bottom',\n align = 'start',\n sideOffset = 8,\n collisionPadding = 8,\n initialFocusRef,\n motion = 'inherit',\n ...props\n}: PopoverContentProps) {\n const popover = usePopoverContext()\n if (![sideOffset, collisionPadding].every(value => Number.isFinite(value) && value >= 0))\n throw new TypeError('Popover offsets and padding must be finite, nonnegative numbers.')\n const hostRef = useComposedRefs(popover.content, ref)\n const {\n ref: transitionRef,\n active: motionActive,\n off: motionOff\n } = useTransitionHost('popup', hostRef, motion === 'off')\n usePopoverSurface(\n popover.content,\n popover.trigger,\n popover.open,\n popover.close,\n popover.restoreFocus,\n { side, align, sideOffset, collisionPadding, initialFocusRef }\n )\n return (\n <div\n {...props}\n ref={transitionRef}\n id={popover.contentId}\n popover=\"manual\"\n data-slot=\"popover-content\"\n data-state={popover.open ? 'open' : 'closed'}\n data-side={side}\n data-align={align}\n data-motion={motion}\n className={cn(\n surfaceClass,\n motionActive &&\n !motionOff &&\n 'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',\n className\n )}\n />\n )\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/cn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAOpC,eAAO,MAAM,EAAE,EAAE,UAiIf,CAAA"}
1
+ {"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/cn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAOpC,eAAO,MAAM,EAAE,EAAE,UAqJf,CAAA"}