@octanejs/radix 0.1.31 → 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.
- package/dist/cjs/AccessibleIcon.cjs +56 -0
- package/dist/cjs/Accordion.cjs +272 -0
- package/dist/cjs/AlertDialog.cjs +144 -0
- package/dist/cjs/Arrow.cjs +43 -0
- package/dist/cjs/AspectRatio.cjs +56 -0
- package/dist/cjs/Avatar.cjs +150 -0
- package/dist/cjs/Checkbox.cjs +281 -0
- package/dist/cjs/Collapsible.cjs +176 -0
- package/dist/cjs/ContextMenu.cjs +315 -0
- package/dist/cjs/Dialog.cjs +291 -0
- package/dist/cjs/DismissableLayer.cjs +382 -0
- package/dist/cjs/DropdownMenu.cjs +296 -0
- package/dist/cjs/FocusScope.cjs +257 -0
- package/dist/cjs/Form.cjs +537 -0
- package/dist/cjs/HoverCard.cjs +309 -0
- package/dist/cjs/Label.cjs +42 -0
- package/dist/cjs/Menu.cjs +925 -0
- package/dist/cjs/Menubar.cjs +475 -0
- package/dist/cjs/NavigationMenu.cjs +942 -0
- package/dist/cjs/OneTimePasswordField.cjs +729 -0
- package/dist/cjs/PasswordToggleField.cjs +377 -0
- package/dist/cjs/Popover.cjs +340 -0
- package/dist/cjs/Popper.cjs +368 -0
- package/dist/cjs/Portal.cjs +40 -0
- package/dist/cjs/Presence.cjs +183 -0
- package/dist/cjs/Primitive.cjs +63 -0
- package/dist/cjs/Progress.cjs +111 -0
- package/dist/cjs/Radio.cjs +240 -0
- package/dist/cjs/RadioGroup.cjs +216 -0
- package/dist/cjs/RovingFocusGroup.cjs +253 -0
- package/dist/cjs/ScrollArea.cjs +828 -0
- package/dist/cjs/Select.cjs +1429 -0
- package/dist/cjs/Separator.cjs +51 -0
- package/dist/cjs/Slider.cjs +634 -0
- package/dist/cjs/Slot.cjs +97 -0
- package/dist/cjs/Switch.cjs +253 -0
- package/dist/cjs/Tabs.cjs +195 -0
- package/dist/cjs/Toast.cjs +733 -0
- package/dist/cjs/Toggle.cjs +54 -0
- package/dist/cjs/ToggleGroup.cjs +174 -0
- package/dist/cjs/Toolbar.cjs +165 -0
- package/dist/cjs/Tooltip.cjs +628 -0
- package/dist/cjs/VisuallyHidden.cjs +52 -0
- package/dist/cjs/collection.cjs +95 -0
- package/dist/cjs/compose-event-handlers.cjs +35 -0
- package/dist/cjs/compose-refs.cjs +68 -0
- package/dist/cjs/context.cjs +96 -0
- package/dist/cjs/direction.cjs +41 -0
- package/dist/cjs/focus-guards.cjs +76 -0
- package/dist/cjs/index.cjs +174 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/scroll-lock.cjs +67 -0
- package/dist/cjs/use-callback-ref.cjs +47 -0
- package/dist/cjs/use-effect-event.cjs +52 -0
- package/dist/cjs/use-is-hydrated.cjs +43 -0
- package/dist/cjs/use-previous.cjs +47 -0
- package/dist/cjs/use-size.cjs +69 -0
- package/dist/cjs/useControllableState.cjs +80 -0
- package/dist/cjs/useId.cjs +36 -0
- package/package.json +14 -7
|
@@ -0,0 +1,253 @@
|
|
|
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 RovingFocusGroup_exports = {};
|
|
20
|
+
__export(RovingFocusGroup_exports, {
|
|
21
|
+
Item: () => Item,
|
|
22
|
+
Root: () => Root,
|
|
23
|
+
RovingFocusGroup: () => Root,
|
|
24
|
+
RovingFocusGroupItem: () => Item,
|
|
25
|
+
createRovingFocusGroupContext: () => createRovingFocusGroupContext,
|
|
26
|
+
createRovingFocusGroupScope: () => createRovingFocusGroupScope
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(RovingFocusGroup_exports);
|
|
29
|
+
var import_octane = require("octane");
|
|
30
|
+
var import_collection = require("./collection.cjs");
|
|
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_Primitive = require("./Primitive.cjs");
|
|
36
|
+
var import_useControllableState = require("./useControllableState.cjs");
|
|
37
|
+
var import_useId = require("./useId.cjs");
|
|
38
|
+
const ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus";
|
|
39
|
+
const EVENT_OPTIONS = { bubbles: false, cancelable: true };
|
|
40
|
+
const [Collection, useCollection, createCollectionScope] = (0, import_collection.createCollection)("RovingFocusGroup");
|
|
41
|
+
const [createRovingFocusGroupContext, createRovingFocusGroupScope] = (0, import_context.createContextScope)(
|
|
42
|
+
"RovingFocusGroup",
|
|
43
|
+
[createCollectionScope]
|
|
44
|
+
);
|
|
45
|
+
const [RovingFocusProvider, useRovingFocusContext] = createRovingFocusGroupContext("RovingFocusGroup");
|
|
46
|
+
function Root(props) {
|
|
47
|
+
return (0, import_octane.createElement)(Collection.Provider, {
|
|
48
|
+
scope: props?.__scopeRovingFocusGroup,
|
|
49
|
+
children: (0, import_octane.createElement)(Collection.Slot, {
|
|
50
|
+
scope: props?.__scopeRovingFocusGroup,
|
|
51
|
+
children: (0, import_octane.createElement)(RovingFocusGroupImpl, props)
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function RovingFocusGroupImpl(props) {
|
|
56
|
+
const slot = (0, import_internal.S)("RovingFocusGroupImpl");
|
|
57
|
+
const {
|
|
58
|
+
__scopeRovingFocusGroup,
|
|
59
|
+
orientation,
|
|
60
|
+
loop = false,
|
|
61
|
+
dir,
|
|
62
|
+
currentTabStopId: currentTabStopIdProp,
|
|
63
|
+
defaultCurrentTabStopId,
|
|
64
|
+
onCurrentTabStopIdChange,
|
|
65
|
+
onEntryFocus,
|
|
66
|
+
preventScrollOnEntryFocus = false,
|
|
67
|
+
ref: forwardedRef,
|
|
68
|
+
...groupProps
|
|
69
|
+
} = props ?? {};
|
|
70
|
+
const ref = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ref"));
|
|
71
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, (0, import_internal.subSlot)(slot, "refs"));
|
|
72
|
+
const direction = dir === "rtl" ? "rtl" : "ltr";
|
|
73
|
+
const [currentTabStopId, setCurrentTabStopId] = (0, import_useControllableState.useControllableState)(
|
|
74
|
+
{
|
|
75
|
+
prop: currentTabStopIdProp,
|
|
76
|
+
defaultProp: defaultCurrentTabStopId ?? null,
|
|
77
|
+
onChange: onCurrentTabStopIdChange
|
|
78
|
+
},
|
|
79
|
+
(0, import_internal.subSlot)(slot, "stop")
|
|
80
|
+
);
|
|
81
|
+
const [isTabbingBackOut, setIsTabbingBackOut] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "backout"));
|
|
82
|
+
const handleEntryFocus = (0, import_octane.useEffectEvent)(onEntryFocus ?? (() => {
|
|
83
|
+
}), (0, import_internal.subSlot)(slot, "entry"));
|
|
84
|
+
const getItems = useCollection(__scopeRovingFocusGroup, (0, import_internal.subSlot)(slot, "items"));
|
|
85
|
+
const isClickFocusRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "clickFocus"));
|
|
86
|
+
const [focusableItemsCount, setFocusableItemsCount] = (0, import_octane.useState)(0, (0, import_internal.subSlot)(slot, "count"));
|
|
87
|
+
(0, import_octane.useEffect)(
|
|
88
|
+
() => {
|
|
89
|
+
const node = ref.current;
|
|
90
|
+
if (node) {
|
|
91
|
+
node.addEventListener(ENTRY_FOCUS, handleEntryFocus);
|
|
92
|
+
return () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[],
|
|
96
|
+
(0, import_internal.subSlot)(slot, "e:entry")
|
|
97
|
+
);
|
|
98
|
+
return (0, import_octane.createElement)(RovingFocusProvider, {
|
|
99
|
+
scope: __scopeRovingFocusGroup,
|
|
100
|
+
orientation,
|
|
101
|
+
dir: direction,
|
|
102
|
+
loop,
|
|
103
|
+
currentTabStopId,
|
|
104
|
+
onItemFocus: (0, import_octane.useCallback)(
|
|
105
|
+
(tabStopId) => setCurrentTabStopId(tabStopId),
|
|
106
|
+
[setCurrentTabStopId],
|
|
107
|
+
(0, import_internal.subSlot)(slot, "onFocus")
|
|
108
|
+
),
|
|
109
|
+
onItemShiftTab: (0, import_octane.useCallback)(() => setIsTabbingBackOut(true), [], (0, import_internal.subSlot)(slot, "shiftTab")),
|
|
110
|
+
onFocusableItemAdd: (0, import_octane.useCallback)(
|
|
111
|
+
() => setFocusableItemsCount((prev) => prev + 1),
|
|
112
|
+
[],
|
|
113
|
+
(0, import_internal.subSlot)(slot, "add")
|
|
114
|
+
),
|
|
115
|
+
onFocusableItemRemove: (0, import_octane.useCallback)(
|
|
116
|
+
() => setFocusableItemsCount((prev) => prev - 1),
|
|
117
|
+
[],
|
|
118
|
+
(0, import_internal.subSlot)(slot, "remove")
|
|
119
|
+
),
|
|
120
|
+
children: (0, import_octane.createElement)(import_Primitive.Primitive.div, {
|
|
121
|
+
tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
|
|
122
|
+
"data-orientation": orientation,
|
|
123
|
+
...groupProps,
|
|
124
|
+
ref: composedRefs,
|
|
125
|
+
style: { outline: "none", ...props.style },
|
|
126
|
+
onMouseDown: (0, import_compose_event_handlers.composeEventHandlers)(props.onMouseDown, () => {
|
|
127
|
+
isClickFocusRef.current = true;
|
|
128
|
+
}),
|
|
129
|
+
onFocus: (0, import_compose_event_handlers.composeEventHandlers)(props.onFocus, (event) => {
|
|
130
|
+
const isKeyboardFocus = !isClickFocusRef.current;
|
|
131
|
+
if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
|
|
132
|
+
const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
|
|
133
|
+
event.currentTarget.dispatchEvent(entryFocusEvent);
|
|
134
|
+
if (!entryFocusEvent.defaultPrevented) {
|
|
135
|
+
const items = getItems().filter((item) => item.focusable);
|
|
136
|
+
const activeItem = items.find((item) => item.active);
|
|
137
|
+
const currentItem = items.find((item) => item.id === currentTabStopId);
|
|
138
|
+
const candidateItems = [activeItem, currentItem, ...items].filter(Boolean);
|
|
139
|
+
const candidateNodes = candidateItems.map((item) => item.ref.current);
|
|
140
|
+
focusFirst(candidateNodes, preventScrollOnEntryFocus);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
isClickFocusRef.current = false;
|
|
144
|
+
}),
|
|
145
|
+
onBlur: (0, import_compose_event_handlers.composeEventHandlers)(props.onBlur, () => setIsTabbingBackOut(false))
|
|
146
|
+
})
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function Item(props) {
|
|
150
|
+
const slot = (0, import_internal.S)("RovingFocusGroupItem");
|
|
151
|
+
const {
|
|
152
|
+
__scopeRovingFocusGroup,
|
|
153
|
+
focusable = true,
|
|
154
|
+
active = false,
|
|
155
|
+
tabStopId,
|
|
156
|
+
children,
|
|
157
|
+
...itemProps
|
|
158
|
+
} = props ?? {};
|
|
159
|
+
const autoId = (0, import_useId.useId)((0, import_internal.subSlot)(slot, "id"));
|
|
160
|
+
const id = tabStopId || autoId;
|
|
161
|
+
const context = useRovingFocusContext("RovingFocusGroupItem", __scopeRovingFocusGroup);
|
|
162
|
+
const isCurrentTabStop = context.currentTabStopId === id;
|
|
163
|
+
const getItems = useCollection(__scopeRovingFocusGroup, (0, import_internal.subSlot)(slot, "items"));
|
|
164
|
+
const { onFocusableItemAdd, onFocusableItemRemove, currentTabStopId } = context;
|
|
165
|
+
(0, import_octane.useEffect)(
|
|
166
|
+
() => {
|
|
167
|
+
if (focusable) {
|
|
168
|
+
onFocusableItemAdd();
|
|
169
|
+
return () => onFocusableItemRemove();
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
[focusable, onFocusableItemAdd, onFocusableItemRemove],
|
|
173
|
+
(0, import_internal.subSlot)(slot, "e:count")
|
|
174
|
+
);
|
|
175
|
+
return (0, import_octane.createElement)(Collection.ItemSlot, {
|
|
176
|
+
scope: __scopeRovingFocusGroup,
|
|
177
|
+
id,
|
|
178
|
+
focusable,
|
|
179
|
+
active,
|
|
180
|
+
children: (0, import_octane.createElement)(import_Primitive.Primitive.span, {
|
|
181
|
+
tabIndex: isCurrentTabStop ? 0 : -1,
|
|
182
|
+
"data-orientation": context.orientation,
|
|
183
|
+
...itemProps,
|
|
184
|
+
onMouseDown: (0, import_compose_event_handlers.composeEventHandlers)(props.onMouseDown, (event) => {
|
|
185
|
+
if (!focusable) event.preventDefault();
|
|
186
|
+
else context.onItemFocus(id);
|
|
187
|
+
}),
|
|
188
|
+
onFocus: (0, import_compose_event_handlers.composeEventHandlers)(props.onFocus, () => context.onItemFocus(id)),
|
|
189
|
+
onKeyDown: (0, import_compose_event_handlers.composeEventHandlers)(props.onKeyDown, (event) => {
|
|
190
|
+
if (event.key === "Tab" && event.shiftKey) {
|
|
191
|
+
context.onItemShiftTab();
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (event.target !== event.currentTarget) return;
|
|
195
|
+
const focusIntent = getFocusIntent(event, context.orientation, context.dir);
|
|
196
|
+
if (focusIntent !== void 0) {
|
|
197
|
+
if (event.metaKey || event.ctrlKey || event.altKey || event.shiftKey) return;
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
const items = getItems().filter((item) => item.focusable);
|
|
200
|
+
let candidateNodes = items.map((item) => item.ref.current);
|
|
201
|
+
if (focusIntent === "last") candidateNodes.reverse();
|
|
202
|
+
else if (focusIntent === "prev" || focusIntent === "next") {
|
|
203
|
+
if (focusIntent === "prev") candidateNodes.reverse();
|
|
204
|
+
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
|
205
|
+
candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
|
|
206
|
+
}
|
|
207
|
+
setTimeout(() => focusFirst(candidateNodes));
|
|
208
|
+
}
|
|
209
|
+
}),
|
|
210
|
+
children: typeof children === "function" ? children({ isCurrentTabStop, hasTabStop: currentTabStopId != null }) : children
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const MAP_KEY_TO_FOCUS_INTENT = {
|
|
215
|
+
ArrowLeft: "prev",
|
|
216
|
+
ArrowUp: "prev",
|
|
217
|
+
ArrowRight: "next",
|
|
218
|
+
ArrowDown: "next",
|
|
219
|
+
PageUp: "first",
|
|
220
|
+
Home: "first",
|
|
221
|
+
PageDown: "last",
|
|
222
|
+
End: "last"
|
|
223
|
+
};
|
|
224
|
+
function getDirectionAwareKey(key, dir) {
|
|
225
|
+
if (dir !== "rtl") return key;
|
|
226
|
+
return key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
|
227
|
+
}
|
|
228
|
+
function getFocusIntent(event, orientation, dir) {
|
|
229
|
+
const key = getDirectionAwareKey(event.key, dir);
|
|
230
|
+
if (orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) return void 0;
|
|
231
|
+
if (orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)) return void 0;
|
|
232
|
+
return MAP_KEY_TO_FOCUS_INTENT[key];
|
|
233
|
+
}
|
|
234
|
+
function focusFirst(candidates, preventScroll = false) {
|
|
235
|
+
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
|
236
|
+
for (const candidate of candidates) {
|
|
237
|
+
if (candidate === PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
238
|
+
candidate.focus({ preventScroll });
|
|
239
|
+
if (document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT) return;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function wrapArray(array, startIndex) {
|
|
243
|
+
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
|
244
|
+
}
|
|
245
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
246
|
+
0 && (module.exports = {
|
|
247
|
+
Item,
|
|
248
|
+
Root,
|
|
249
|
+
RovingFocusGroup,
|
|
250
|
+
RovingFocusGroupItem,
|
|
251
|
+
createRovingFocusGroupContext,
|
|
252
|
+
createRovingFocusGroupScope
|
|
253
|
+
});
|