@octanejs/radix 0.1.32 → 0.1.33

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 (60) hide show
  1. package/dist/cjs/AccessibleIcon.cjs +56 -0
  2. package/dist/cjs/Accordion.cjs +272 -0
  3. package/dist/cjs/AlertDialog.cjs +144 -0
  4. package/dist/cjs/Arrow.cjs +43 -0
  5. package/dist/cjs/AspectRatio.cjs +56 -0
  6. package/dist/cjs/Avatar.cjs +150 -0
  7. package/dist/cjs/Checkbox.cjs +281 -0
  8. package/dist/cjs/Collapsible.cjs +176 -0
  9. package/dist/cjs/ContextMenu.cjs +315 -0
  10. package/dist/cjs/Dialog.cjs +291 -0
  11. package/dist/cjs/DismissableLayer.cjs +382 -0
  12. package/dist/cjs/DropdownMenu.cjs +296 -0
  13. package/dist/cjs/FocusScope.cjs +257 -0
  14. package/dist/cjs/Form.cjs +537 -0
  15. package/dist/cjs/HoverCard.cjs +309 -0
  16. package/dist/cjs/Label.cjs +42 -0
  17. package/dist/cjs/Menu.cjs +925 -0
  18. package/dist/cjs/Menubar.cjs +475 -0
  19. package/dist/cjs/NavigationMenu.cjs +942 -0
  20. package/dist/cjs/OneTimePasswordField.cjs +729 -0
  21. package/dist/cjs/PasswordToggleField.cjs +377 -0
  22. package/dist/cjs/Popover.cjs +340 -0
  23. package/dist/cjs/Popper.cjs +368 -0
  24. package/dist/cjs/Portal.cjs +40 -0
  25. package/dist/cjs/Presence.cjs +183 -0
  26. package/dist/cjs/Primitive.cjs +63 -0
  27. package/dist/cjs/Progress.cjs +111 -0
  28. package/dist/cjs/Radio.cjs +240 -0
  29. package/dist/cjs/RadioGroup.cjs +216 -0
  30. package/dist/cjs/RovingFocusGroup.cjs +253 -0
  31. package/dist/cjs/ScrollArea.cjs +828 -0
  32. package/dist/cjs/Select.cjs +1429 -0
  33. package/dist/cjs/Separator.cjs +51 -0
  34. package/dist/cjs/Slider.cjs +634 -0
  35. package/dist/cjs/Slot.cjs +97 -0
  36. package/dist/cjs/Switch.cjs +253 -0
  37. package/dist/cjs/Tabs.cjs +195 -0
  38. package/dist/cjs/Toast.cjs +733 -0
  39. package/dist/cjs/Toggle.cjs +54 -0
  40. package/dist/cjs/ToggleGroup.cjs +174 -0
  41. package/dist/cjs/Toolbar.cjs +165 -0
  42. package/dist/cjs/Tooltip.cjs +628 -0
  43. package/dist/cjs/VisuallyHidden.cjs +52 -0
  44. package/dist/cjs/collection.cjs +95 -0
  45. package/dist/cjs/compose-event-handlers.cjs +35 -0
  46. package/dist/cjs/compose-refs.cjs +68 -0
  47. package/dist/cjs/context.cjs +96 -0
  48. package/dist/cjs/direction.cjs +41 -0
  49. package/dist/cjs/focus-guards.cjs +76 -0
  50. package/dist/cjs/index.cjs +174 -0
  51. package/dist/cjs/internal.cjs +51 -0
  52. package/dist/cjs/scroll-lock.cjs +67 -0
  53. package/dist/cjs/use-callback-ref.cjs +47 -0
  54. package/dist/cjs/use-effect-event.cjs +52 -0
  55. package/dist/cjs/use-is-hydrated.cjs +43 -0
  56. package/dist/cjs/use-previous.cjs +47 -0
  57. package/dist/cjs/use-size.cjs +69 -0
  58. package/dist/cjs/useControllableState.cjs +80 -0
  59. package/dist/cjs/useId.cjs +36 -0
  60. package/package.json +14 -7
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Avatar_exports = {};
20
+ __export(Avatar_exports, {
21
+ Avatar: () => Root,
22
+ AvatarFallback: () => Fallback,
23
+ AvatarImage: () => Image,
24
+ Fallback: () => Fallback,
25
+ Image: () => Image,
26
+ Root: () => Root,
27
+ createAvatarScope: () => createAvatarScope
28
+ });
29
+ module.exports = __toCommonJS(Avatar_exports);
30
+ var import_octane = require("octane");
31
+ var import_context = require("./context.cjs");
32
+ var import_internal = require("./internal.cjs");
33
+ var import_Primitive = require("./Primitive.cjs");
34
+ const [createAvatarContext, createAvatarScope] = (0, import_context.createContextScope)("Avatar");
35
+ const [AvatarProvider, useAvatarContext] = createAvatarContext("Avatar");
36
+ function Root(props) {
37
+ const slot = (0, import_internal.S)("Avatar.Root");
38
+ const { __scopeAvatar, ...avatarProps } = props ?? {};
39
+ const [imageLoadingStatus, setImageLoadingStatus] = (0, import_octane.useState)(
40
+ "idle",
41
+ (0, import_internal.subSlot)(slot, "status")
42
+ );
43
+ return (0, import_octane.createElement)(AvatarProvider, {
44
+ scope: __scopeAvatar,
45
+ imageLoadingStatus,
46
+ setImageLoadingStatus,
47
+ children: (0, import_octane.createElement)(import_Primitive.Primitive.span, avatarProps)
48
+ });
49
+ }
50
+ function Image(props) {
51
+ const slot = (0, import_internal.S)("Avatar.Image");
52
+ const { __scopeAvatar, src, onLoadingStatusChange, ...imageProps } = props ?? {};
53
+ const context = useAvatarContext("AvatarImage", __scopeAvatar);
54
+ const imageLoadingStatus = useImageLoadingStatus(
55
+ src,
56
+ {
57
+ referrerPolicy: imageProps.referrerPolicy,
58
+ crossOrigin: imageProps.crossOrigin,
59
+ loadingStatus: context.imageLoadingStatus,
60
+ setLoadingStatus: context.setImageLoadingStatus
61
+ },
62
+ slot
63
+ );
64
+ const handleLoadingStatusChange = (0, import_octane.useEffectEvent)(
65
+ (status) => {
66
+ onLoadingStatusChange?.(status);
67
+ },
68
+ (0, import_internal.subSlot)(slot, "cb")
69
+ );
70
+ const loadingStatusRef = (0, import_octane.useRef)(imageLoadingStatus, (0, import_internal.subSlot)(slot, "prev"));
71
+ (0, import_octane.useLayoutEffect)(
72
+ () => {
73
+ const previousLoadingStatus = loadingStatusRef.current;
74
+ loadingStatusRef.current = imageLoadingStatus;
75
+ if (imageLoadingStatus !== previousLoadingStatus) {
76
+ handleLoadingStatusChange(imageLoadingStatus);
77
+ }
78
+ },
79
+ [imageLoadingStatus],
80
+ (0, import_internal.subSlot)(slot, "e:change")
81
+ );
82
+ return imageLoadingStatus === "loaded" ? (0, import_octane.createElement)(import_Primitive.Primitive.img, { ...imageProps, src }) : null;
83
+ }
84
+ function Fallback(props) {
85
+ const slot = (0, import_internal.S)("Avatar.Fallback");
86
+ const { __scopeAvatar, delayMs, ...fallbackProps } = props ?? {};
87
+ const context = useAvatarContext("AvatarFallback", __scopeAvatar);
88
+ const [canRender, setCanRender] = (0, import_octane.useState)(delayMs === void 0, (0, import_internal.subSlot)(slot, "can"));
89
+ (0, import_octane.useEffect)(
90
+ () => {
91
+ if (delayMs !== void 0) {
92
+ const timerId = window.setTimeout(() => setCanRender(true), delayMs);
93
+ return () => window.clearTimeout(timerId);
94
+ }
95
+ },
96
+ [delayMs],
97
+ (0, import_internal.subSlot)(slot, "e:delay")
98
+ );
99
+ return canRender && context.imageLoadingStatus !== "loaded" ? (0, import_octane.createElement)(import_Primitive.Primitive.span, fallbackProps) : null;
100
+ }
101
+ function useImageLoadingStatus(src, {
102
+ loadingStatus,
103
+ setLoadingStatus,
104
+ referrerPolicy,
105
+ crossOrigin
106
+ }, slot) {
107
+ (0, import_octane.useLayoutEffect)(
108
+ () => {
109
+ if (!src) {
110
+ setLoadingStatus("error");
111
+ return;
112
+ }
113
+ const image = new window.Image();
114
+ const handleLoad = (event) => {
115
+ const img = event.currentTarget;
116
+ setLoadingStatus(getImageLoadingStatus(img));
117
+ };
118
+ const handleError = () => setLoadingStatus("error");
119
+ image.addEventListener("load", handleLoad);
120
+ image.addEventListener("error", handleError);
121
+ if (referrerPolicy) {
122
+ image.referrerPolicy = referrerPolicy;
123
+ }
124
+ image.crossOrigin = crossOrigin ?? null;
125
+ image.src = src;
126
+ setLoadingStatus(getImageLoadingStatus(image));
127
+ return () => {
128
+ image.removeEventListener("load", handleLoad);
129
+ image.removeEventListener("error", handleError);
130
+ setLoadingStatus("idle");
131
+ };
132
+ },
133
+ [src, crossOrigin, referrerPolicy],
134
+ (0, import_internal.subSlot)(slot, "e:load")
135
+ );
136
+ return loadingStatus;
137
+ }
138
+ function getImageLoadingStatus(image) {
139
+ return image.complete ? image.naturalWidth > 0 ? "loaded" : "error" : "loading";
140
+ }
141
+ // Annotate the CommonJS export names for ESM import in node:
142
+ 0 && (module.exports = {
143
+ Avatar,
144
+ AvatarFallback,
145
+ AvatarImage,
146
+ Fallback,
147
+ Image,
148
+ Root,
149
+ createAvatarScope
150
+ });
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Checkbox_exports = {};
20
+ __export(Checkbox_exports, {
21
+ BubbleInput: () => BubbleInput,
22
+ Checkbox: () => Root,
23
+ CheckboxBubbleInput: () => BubbleInput,
24
+ CheckboxIndicator: () => Indicator,
25
+ CheckboxProvider: () => Provider,
26
+ CheckboxTrigger: () => Trigger,
27
+ Indicator: () => Indicator,
28
+ Provider: () => Provider,
29
+ Root: () => Root,
30
+ Trigger: () => Trigger,
31
+ createCheckboxScope: () => createCheckboxScope
32
+ });
33
+ module.exports = __toCommonJS(Checkbox_exports);
34
+ var import_octane = require("octane");
35
+ var import_compose_event_handlers = require("./compose-event-handlers.cjs");
36
+ var import_compose_refs = require("./compose-refs.cjs");
37
+ var import_context = require("./context.cjs");
38
+ var import_internal = require("./internal.cjs");
39
+ var import_Presence = require("./Presence.cjs");
40
+ var import_Primitive = require("./Primitive.cjs");
41
+ var import_use_previous = require("./use-previous.cjs");
42
+ var import_use_size = require("./use-size.cjs");
43
+ var import_useControllableState = require("./useControllableState.cjs");
44
+ const CHECKBOX_NAME = "Checkbox";
45
+ const [createCheckboxContext, createCheckboxScope] = (0, import_context.createContextScope)(CHECKBOX_NAME);
46
+ const [CheckboxProviderImpl, useCheckboxContext] = createCheckboxContext(CHECKBOX_NAME);
47
+ function Provider(props) {
48
+ const slot = (0, import_internal.S)("Checkbox.Provider");
49
+ const {
50
+ __scopeCheckbox,
51
+ checked: checkedProp,
52
+ children,
53
+ defaultChecked,
54
+ disabled,
55
+ form,
56
+ name,
57
+ onCheckedChange,
58
+ required,
59
+ value = "on",
60
+ internal_do_not_use_render
61
+ } = props ?? {};
62
+ const [checked, setChecked] = (0, import_useControllableState.useControllableState)(
63
+ { prop: checkedProp, defaultProp: defaultChecked ?? false, onChange: onCheckedChange },
64
+ (0, import_internal.subSlot)(slot, "checked")
65
+ );
66
+ const [control, setControl] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "control"));
67
+ const [bubbleInput, setBubbleInput] = (0, import_octane.useState)(
68
+ null,
69
+ (0, import_internal.subSlot)(slot, "input")
70
+ );
71
+ const hasConsumerStoppedPropagationRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "stopped"));
72
+ const isFormControl = control ? !!form || !!control.closest("form") : (
73
+ // We set this to true by default so that events bubble to forms without JS (SSR)
74
+ true
75
+ );
76
+ const context = {
77
+ checked,
78
+ disabled,
79
+ setChecked,
80
+ control,
81
+ setControl,
82
+ name,
83
+ form,
84
+ value,
85
+ hasConsumerStoppedPropagationRef,
86
+ required,
87
+ defaultChecked: isIndeterminate(defaultChecked) ? false : defaultChecked,
88
+ isFormControl,
89
+ bubbleInput,
90
+ setBubbleInput
91
+ };
92
+ return (0, import_octane.createElement)(CheckboxProviderImpl, {
93
+ scope: __scopeCheckbox,
94
+ ...context,
95
+ children: isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
96
+ });
97
+ }
98
+ function Trigger(props) {
99
+ const slot = (0, import_internal.S)("Checkbox.Trigger");
100
+ const { __scopeCheckbox, onKeyDown, onClick, ref: forwardedRef, ...checkboxProps } = props ?? {};
101
+ const {
102
+ control,
103
+ value,
104
+ disabled,
105
+ checked,
106
+ required,
107
+ setControl,
108
+ setChecked,
109
+ hasConsumerStoppedPropagationRef,
110
+ isFormControl,
111
+ bubbleInput
112
+ } = useCheckboxContext("CheckboxTrigger", __scopeCheckbox);
113
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setControl, (0, import_internal.subSlot)(slot, "refs"));
114
+ const initialCheckedStateRef = (0, import_octane.useRef)(checked, (0, import_internal.subSlot)(slot, "initial"));
115
+ (0, import_octane.useEffect)(
116
+ () => {
117
+ const form = control?.form;
118
+ if (form) {
119
+ const reset = () => setChecked(initialCheckedStateRef.current);
120
+ form.addEventListener("reset", reset);
121
+ return () => form.removeEventListener("reset", reset);
122
+ }
123
+ },
124
+ [control, setChecked],
125
+ (0, import_internal.subSlot)(slot, "e:reset")
126
+ );
127
+ return (0, import_octane.createElement)(import_Primitive.Primitive.button, {
128
+ type: "button",
129
+ role: "checkbox",
130
+ "aria-checked": isIndeterminate(checked) ? "mixed" : checked,
131
+ "aria-required": required,
132
+ "data-state": getState(checked),
133
+ "data-disabled": disabled ? "" : void 0,
134
+ disabled,
135
+ value,
136
+ ...checkboxProps,
137
+ ref: composedRefs,
138
+ onKeyDown: (0, import_compose_event_handlers.composeEventHandlers)(onKeyDown, (event) => {
139
+ if (event.key === "Enter") event.preventDefault();
140
+ }),
141
+ onClick: (0, import_compose_event_handlers.composeEventHandlers)(onClick, (event) => {
142
+ setChecked((prevChecked) => isIndeterminate(prevChecked) ? true : !prevChecked);
143
+ if (bubbleInput && isFormControl) {
144
+ hasConsumerStoppedPropagationRef.current = event.cancelBubble;
145
+ if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
146
+ }
147
+ })
148
+ });
149
+ }
150
+ function Root(props) {
151
+ const {
152
+ __scopeCheckbox,
153
+ name,
154
+ checked,
155
+ defaultChecked,
156
+ required,
157
+ disabled,
158
+ value,
159
+ onCheckedChange,
160
+ form,
161
+ ref: forwardedRef,
162
+ ...checkboxProps
163
+ } = props ?? {};
164
+ return (0, import_octane.createElement)(Provider, {
165
+ __scopeCheckbox,
166
+ checked,
167
+ defaultChecked,
168
+ disabled,
169
+ required,
170
+ onCheckedChange,
171
+ name,
172
+ form,
173
+ value,
174
+ internal_do_not_use_render: ({ isFormControl }) => [
175
+ (0, import_octane.createElement)(Trigger, {
176
+ key: "trigger",
177
+ ...checkboxProps,
178
+ ref: forwardedRef,
179
+ __scopeCheckbox
180
+ }),
181
+ isFormControl ? (0, import_octane.createElement)(BubbleInput, { key: "bubble", __scopeCheckbox }) : null
182
+ ]
183
+ });
184
+ }
185
+ function Indicator(props) {
186
+ const { __scopeCheckbox, forceMount, ...indicatorProps } = props ?? {};
187
+ const context = useCheckboxContext("CheckboxIndicator", __scopeCheckbox);
188
+ return (0, import_octane.createElement)(import_Presence.Presence, {
189
+ present: forceMount || isIndeterminate(context.checked) || context.checked === true,
190
+ children: (0, import_octane.createElement)(import_Primitive.Primitive.span, {
191
+ "data-state": getState(context.checked),
192
+ "data-disabled": context.disabled ? "" : void 0,
193
+ ...indicatorProps,
194
+ style: { pointerEvents: "none", ...props?.style }
195
+ })
196
+ });
197
+ }
198
+ function BubbleInput(props) {
199
+ const slot = (0, import_internal.S)("Checkbox.BubbleInput");
200
+ const { __scopeCheckbox, ref: forwardedRef, ...inputProps } = props ?? {};
201
+ const {
202
+ control,
203
+ hasConsumerStoppedPropagationRef,
204
+ checked,
205
+ required,
206
+ disabled,
207
+ name,
208
+ value,
209
+ form,
210
+ bubbleInput,
211
+ setBubbleInput
212
+ } = useCheckboxContext("CheckboxBubbleInput", __scopeCheckbox);
213
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setBubbleInput, (0, import_internal.subSlot)(slot, "refs"));
214
+ const prevChecked = (0, import_use_previous.usePrevious)(checked, (0, import_internal.subSlot)(slot, "prev"));
215
+ const controlSize = (0, import_use_size.useSize)(control, (0, import_internal.subSlot)(slot, "size"));
216
+ (0, import_octane.useEffect)(
217
+ () => {
218
+ const input = bubbleInput;
219
+ if (!input) return;
220
+ const bubbles = !hasConsumerStoppedPropagationRef.current;
221
+ if (prevChecked !== checked) {
222
+ input.indeterminate = isIndeterminate(checked);
223
+ input.dispatchEvent(new Event("click", { bubbles }));
224
+ input.dispatchEvent(new Event("change", { bubbles }));
225
+ }
226
+ },
227
+ [bubbleInput, prevChecked, checked, hasConsumerStoppedPropagationRef],
228
+ (0, import_internal.subSlot)(slot, "e:bubble")
229
+ );
230
+ return (0, import_octane.createElement)(import_Primitive.Primitive.input, {
231
+ type: "checkbox",
232
+ "aria-hidden": true,
233
+ // Live CONTROLLED checked (octane React-parity): the runtime writes the DOM
234
+ // property, mirrors only the INITIAL state to the attribute, and reasserts
235
+ // the property on every commit / after event flushes.
236
+ checked: isIndeterminate(checked) ? false : checked,
237
+ required,
238
+ disabled,
239
+ name,
240
+ value,
241
+ form,
242
+ ...inputProps,
243
+ tabIndex: -1,
244
+ ref: composedRefs,
245
+ style: {
246
+ ...props?.style,
247
+ ...controlSize,
248
+ position: "absolute",
249
+ pointerEvents: "none",
250
+ opacity: 0,
251
+ margin: 0,
252
+ // We transform because the input is absolutely positioned but we have
253
+ // rendered it **after** the button. This pulls it back to sit on top
254
+ // of the button.
255
+ transform: "translateX(-100%)"
256
+ }
257
+ });
258
+ }
259
+ function isFunction(value) {
260
+ return typeof value === "function";
261
+ }
262
+ function isIndeterminate(checked) {
263
+ return checked === "indeterminate";
264
+ }
265
+ function getState(checked) {
266
+ return isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
267
+ }
268
+ // Annotate the CommonJS export names for ESM import in node:
269
+ 0 && (module.exports = {
270
+ BubbleInput,
271
+ Checkbox,
272
+ CheckboxBubbleInput,
273
+ CheckboxIndicator,
274
+ CheckboxProvider,
275
+ CheckboxTrigger,
276
+ Indicator,
277
+ Provider,
278
+ Root,
279
+ Trigger,
280
+ createCheckboxScope
281
+ });
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Collapsible_exports = {};
20
+ __export(Collapsible_exports, {
21
+ Collapsible: () => Root,
22
+ Content: () => Content,
23
+ Root: () => Root,
24
+ Trigger: () => Trigger,
25
+ createCollapsibleContext: () => createCollapsibleContext,
26
+ createCollapsibleScope: () => createCollapsibleScope,
27
+ useCollapsibleContext: () => useCollapsibleContext
28
+ });
29
+ module.exports = __toCommonJS(Collapsible_exports);
30
+ var import_octane = require("octane");
31
+ var import_compose_event_handlers = require("./compose-event-handlers.cjs");
32
+ var import_compose_refs = require("./compose-refs.cjs");
33
+ var import_context = require("./context.cjs");
34
+ var import_internal = require("./internal.cjs");
35
+ var import_Presence = require("./Presence.cjs");
36
+ var import_Primitive = require("./Primitive.cjs");
37
+ var import_useControllableState = require("./useControllableState.cjs");
38
+ var import_useId = require("./useId.cjs");
39
+ const [createCollapsibleContext, createCollapsibleScope] = (0, import_context.createContextScope)("Collapsible");
40
+ const [CollapsibleProvider, useCollapsibleContext] = createCollapsibleContext("Collapsible");
41
+ function getState(open) {
42
+ return open ? "open" : "closed";
43
+ }
44
+ function Root(props) {
45
+ const slot = (0, import_internal.S)("Collapsible.Root");
46
+ const {
47
+ __scopeCollapsible,
48
+ open: openProp,
49
+ defaultOpen,
50
+ disabled,
51
+ onOpenChange,
52
+ ...rest
53
+ } = props ?? {};
54
+ const [open, setOpen] = (0, import_useControllableState.useControllableState)(
55
+ { prop: openProp, defaultProp: defaultOpen ?? false, onChange: onOpenChange },
56
+ (0, import_internal.subSlot)(slot, "open")
57
+ );
58
+ const contentId = (0, import_useId.useId)((0, import_internal.subSlot)(slot, "id"));
59
+ const onOpenToggle = (0, import_octane.useCallback)(
60
+ () => setOpen((prev) => !prev),
61
+ [setOpen],
62
+ (0, import_internal.subSlot)(slot, "toggle")
63
+ );
64
+ return (0, import_octane.createElement)(CollapsibleProvider, {
65
+ scope: __scopeCollapsible,
66
+ contentId,
67
+ disabled,
68
+ open,
69
+ onOpenToggle,
70
+ children: (0, import_octane.createElement)(import_Primitive.Primitive.div, {
71
+ "data-state": getState(open),
72
+ "data-disabled": disabled ? "" : void 0,
73
+ ...rest
74
+ })
75
+ });
76
+ }
77
+ function Trigger(props) {
78
+ const { __scopeCollapsible, ...rest } = props ?? {};
79
+ const context = useCollapsibleContext("CollapsibleTrigger", __scopeCollapsible);
80
+ return (0, import_octane.createElement)(import_Primitive.Primitive.button, {
81
+ type: "button",
82
+ // Radix parity: only reference the content while it's expanded.
83
+ "aria-controls": context.open ? context.contentId : void 0,
84
+ "aria-expanded": context.open || false,
85
+ "data-state": getState(context.open),
86
+ "data-disabled": context.disabled ? "" : void 0,
87
+ disabled: context.disabled,
88
+ ...rest,
89
+ onClick: (0, import_compose_event_handlers.composeEventHandlers)(rest.onClick, context.onOpenToggle)
90
+ });
91
+ }
92
+ function Content(props) {
93
+ const { __scopeCollapsible, forceMount, ...contentProps } = props ?? {};
94
+ const context = useCollapsibleContext("CollapsibleContent", __scopeCollapsible);
95
+ return (0, import_octane.createElement)(import_Presence.Presence, {
96
+ present: forceMount || context.open,
97
+ children: ({ present }) => (0, import_octane.createElement)(ContentImpl, { ...contentProps, __scopeCollapsible, present })
98
+ });
99
+ }
100
+ function ContentImpl(props) {
101
+ const slot = (0, import_internal.S)("Collapsible.ContentImpl");
102
+ const {
103
+ __scopeCollapsible,
104
+ present,
105
+ children,
106
+ ref: forwardedRef,
107
+ style,
108
+ ...contentProps
109
+ } = props;
110
+ const context = useCollapsibleContext("CollapsibleContent", __scopeCollapsible);
111
+ const [isPresent, setIsPresent] = (0, import_octane.useState)(present, (0, import_internal.subSlot)(slot, "present"));
112
+ const rRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ref"));
113
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, rRef, (0, import_internal.subSlot)(slot, "refs"));
114
+ const heightRef = (0, import_octane.useRef)(0, (0, import_internal.subSlot)(slot, "h"));
115
+ const widthRef = (0, import_octane.useRef)(0, (0, import_internal.subSlot)(slot, "w"));
116
+ const isOpen = context.open || isPresent;
117
+ const isMountAnimationPreventedRef = (0, import_octane.useRef)(isOpen, (0, import_internal.subSlot)(slot, "prevent"));
118
+ const originalStylesRef = (0, import_octane.useRef)(void 0, (0, import_internal.subSlot)(slot, "orig"));
119
+ (0, import_octane.useEffect)(
120
+ () => {
121
+ const raf = requestAnimationFrame(() => isMountAnimationPreventedRef.current = false);
122
+ return () => cancelAnimationFrame(raf);
123
+ },
124
+ [],
125
+ (0, import_internal.subSlot)(slot, "e:mount")
126
+ );
127
+ (0, import_octane.useLayoutEffect)(
128
+ () => {
129
+ const node = rRef.current;
130
+ if (node) {
131
+ originalStylesRef.current = originalStylesRef.current || {
132
+ transitionDuration: node.style.transitionDuration,
133
+ animationName: node.style.animationName
134
+ };
135
+ node.style.transitionDuration = "0s";
136
+ node.style.animationName = "none";
137
+ const rect = node.getBoundingClientRect();
138
+ heightRef.current = rect.height;
139
+ widthRef.current = rect.width;
140
+ if (!isMountAnimationPreventedRef.current) {
141
+ node.style.transitionDuration = originalStylesRef.current.transitionDuration;
142
+ node.style.animationName = originalStylesRef.current.animationName;
143
+ }
144
+ setIsPresent(present);
145
+ }
146
+ },
147
+ [context.open, present],
148
+ (0, import_internal.subSlot)(slot, "e:measure")
149
+ );
150
+ const height = heightRef.current;
151
+ const width = widthRef.current;
152
+ return (0, import_octane.createElement)(import_Primitive.Primitive.div, {
153
+ "data-state": getState(context.open),
154
+ "data-disabled": context.disabled ? "" : void 0,
155
+ id: context.contentId,
156
+ hidden: !isOpen,
157
+ ...contentProps,
158
+ ref: composedRefs,
159
+ style: {
160
+ "--radix-collapsible-content-height": height ? `${height}px` : void 0,
161
+ "--radix-collapsible-content-width": width ? `${width}px` : void 0,
162
+ ...style
163
+ },
164
+ children: isOpen ? children : null
165
+ });
166
+ }
167
+ // Annotate the CommonJS export names for ESM import in node:
168
+ 0 && (module.exports = {
169
+ Collapsible,
170
+ Content,
171
+ Root,
172
+ Trigger,
173
+ createCollapsibleContext,
174
+ createCollapsibleScope,
175
+ useCollapsibleContext
176
+ });