@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.
- 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,111 @@
|
|
|
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 Progress_exports = {};
|
|
20
|
+
__export(Progress_exports, {
|
|
21
|
+
Indicator: () => Indicator,
|
|
22
|
+
Progress: () => Root,
|
|
23
|
+
ProgressIndicator: () => Indicator,
|
|
24
|
+
Root: () => Root,
|
|
25
|
+
createProgressScope: () => createProgressScope
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(Progress_exports);
|
|
28
|
+
var import_octane = require("octane");
|
|
29
|
+
var import_context = require("./context.cjs");
|
|
30
|
+
var import_Primitive = require("./Primitive.cjs");
|
|
31
|
+
const DEFAULT_MAX = 100;
|
|
32
|
+
const [createProgressContext, createProgressScope] = (0, import_context.createContextScope)("Progress");
|
|
33
|
+
const [ProgressProvider, useProgressContext] = createProgressContext("Progress");
|
|
34
|
+
function Root(props) {
|
|
35
|
+
const {
|
|
36
|
+
__scopeProgress,
|
|
37
|
+
value: valueProp = null,
|
|
38
|
+
max: maxProp,
|
|
39
|
+
getValueLabel = defaultGetValueLabel,
|
|
40
|
+
...progressProps
|
|
41
|
+
} = props ?? {};
|
|
42
|
+
if ((maxProp || maxProp === 0) && !isValidMaxNumber(maxProp)) {
|
|
43
|
+
console.error(getInvalidMaxError(`${maxProp}`, "Progress"));
|
|
44
|
+
}
|
|
45
|
+
const max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX;
|
|
46
|
+
if (valueProp !== null && !isValidValueNumber(valueProp, max)) {
|
|
47
|
+
console.error(getInvalidValueError(`${valueProp}`, "Progress"));
|
|
48
|
+
}
|
|
49
|
+
const value = isValidValueNumber(valueProp, max) ? valueProp : null;
|
|
50
|
+
const valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0;
|
|
51
|
+
return (0, import_octane.createElement)(ProgressProvider, {
|
|
52
|
+
scope: __scopeProgress,
|
|
53
|
+
value,
|
|
54
|
+
max,
|
|
55
|
+
children: (0, import_octane.createElement)(import_Primitive.Primitive.div, {
|
|
56
|
+
"aria-valuemax": max,
|
|
57
|
+
"aria-valuemin": 0,
|
|
58
|
+
"aria-valuenow": isNumber(value) ? value : void 0,
|
|
59
|
+
"aria-valuetext": valueLabel,
|
|
60
|
+
role: "progressbar",
|
|
61
|
+
"data-state": getProgressState(value, max),
|
|
62
|
+
"data-value": value ?? void 0,
|
|
63
|
+
"data-max": max,
|
|
64
|
+
...progressProps
|
|
65
|
+
})
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function Indicator(props) {
|
|
69
|
+
const { __scopeProgress, ...indicatorProps } = props ?? {};
|
|
70
|
+
const context = useProgressContext("ProgressIndicator", __scopeProgress);
|
|
71
|
+
return (0, import_octane.createElement)(import_Primitive.Primitive.div, {
|
|
72
|
+
"data-state": getProgressState(context.value, context.max),
|
|
73
|
+
"data-value": context.value ?? void 0,
|
|
74
|
+
"data-max": context.max,
|
|
75
|
+
...indicatorProps
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function getProgressState(value, maxValue) {
|
|
79
|
+
return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
|
|
80
|
+
}
|
|
81
|
+
function defaultGetValueLabel(value, max) {
|
|
82
|
+
return `${Math.round(value / max * 100)}%`;
|
|
83
|
+
}
|
|
84
|
+
function isNumber(value) {
|
|
85
|
+
return typeof value === "number";
|
|
86
|
+
}
|
|
87
|
+
function isValidMaxNumber(max) {
|
|
88
|
+
return isNumber(max) && !isNaN(max) && max > 0;
|
|
89
|
+
}
|
|
90
|
+
function isValidValueNumber(value, max) {
|
|
91
|
+
return isNumber(value) && !isNaN(value) && value <= max && value >= 0;
|
|
92
|
+
}
|
|
93
|
+
function getInvalidMaxError(propValue, componentName) {
|
|
94
|
+
return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid max values. Defaulting to \`${DEFAULT_MAX}\`.`;
|
|
95
|
+
}
|
|
96
|
+
function getInvalidValueError(propValue, componentName) {
|
|
97
|
+
return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be:
|
|
98
|
+
- a positive number
|
|
99
|
+
- less than the value passed to \`max\` (or ${DEFAULT_MAX} if no \`max\` prop is set)
|
|
100
|
+
- \`null\` or \`undefined\` if the progress is indeterminate.
|
|
101
|
+
|
|
102
|
+
Defaulting to \`null\`.`;
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
Indicator,
|
|
107
|
+
Progress,
|
|
108
|
+
ProgressIndicator,
|
|
109
|
+
Root,
|
|
110
|
+
createProgressScope
|
|
111
|
+
});
|
|
@@ -0,0 +1,240 @@
|
|
|
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 Radio_exports = {};
|
|
20
|
+
__export(Radio_exports, {
|
|
21
|
+
Radio: () => Radio,
|
|
22
|
+
RadioBubbleInput: () => RadioBubbleInput,
|
|
23
|
+
RadioIndicator: () => RadioIndicator,
|
|
24
|
+
RadioProvider: () => RadioProvider,
|
|
25
|
+
RadioTrigger: () => RadioTrigger,
|
|
26
|
+
createRadioScope: () => createRadioScope,
|
|
27
|
+
useRadioContext: () => useRadioContext
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(Radio_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_use_previous = require("./use-previous.cjs");
|
|
38
|
+
var import_use_size = require("./use-size.cjs");
|
|
39
|
+
const RADIO_NAME = "Radio";
|
|
40
|
+
const [createRadioContext, createRadioScope] = (0, import_context.createContextScope)(RADIO_NAME);
|
|
41
|
+
const [RadioProviderImpl, useRadioContextImpl] = createRadioContext(RADIO_NAME);
|
|
42
|
+
const useRadioContext = useRadioContextImpl;
|
|
43
|
+
function RadioProvider(props) {
|
|
44
|
+
const slot = (0, import_internal.S)("Radio.Provider");
|
|
45
|
+
const {
|
|
46
|
+
__scopeRadio,
|
|
47
|
+
checked = false,
|
|
48
|
+
children,
|
|
49
|
+
disabled,
|
|
50
|
+
form,
|
|
51
|
+
name,
|
|
52
|
+
onCheck,
|
|
53
|
+
required,
|
|
54
|
+
value = "on",
|
|
55
|
+
internal_do_not_use_render
|
|
56
|
+
} = props ?? {};
|
|
57
|
+
const [control, setControl] = (0, import_octane.useState)(null, (0, import_internal.subSlot)(slot, "control"));
|
|
58
|
+
const [bubbleInput, setBubbleInput] = (0, import_octane.useState)(
|
|
59
|
+
null,
|
|
60
|
+
(0, import_internal.subSlot)(slot, "input")
|
|
61
|
+
);
|
|
62
|
+
const hasConsumerStoppedPropagationRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "stopped"));
|
|
63
|
+
const isFormControl = control ? !!form || !!control.closest("form") : (
|
|
64
|
+
// We set this to true by default so that events bubble to forms without JS (SSR)
|
|
65
|
+
true
|
|
66
|
+
);
|
|
67
|
+
const context = {
|
|
68
|
+
checked,
|
|
69
|
+
disabled,
|
|
70
|
+
required,
|
|
71
|
+
name,
|
|
72
|
+
form,
|
|
73
|
+
value,
|
|
74
|
+
control,
|
|
75
|
+
setControl,
|
|
76
|
+
hasConsumerStoppedPropagationRef,
|
|
77
|
+
isFormControl,
|
|
78
|
+
bubbleInput,
|
|
79
|
+
setBubbleInput,
|
|
80
|
+
onCheck: () => onCheck?.()
|
|
81
|
+
};
|
|
82
|
+
return (0, import_octane.createElement)(RadioProviderImpl, {
|
|
83
|
+
scope: __scopeRadio,
|
|
84
|
+
...context,
|
|
85
|
+
children: isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function RadioTrigger(props) {
|
|
89
|
+
const slot = (0, import_internal.S)("Radio.Trigger");
|
|
90
|
+
const { __scopeRadio, onClick, ref: forwardedRef, ...radioProps } = props ?? {};
|
|
91
|
+
const {
|
|
92
|
+
checked,
|
|
93
|
+
disabled,
|
|
94
|
+
value,
|
|
95
|
+
setControl,
|
|
96
|
+
onCheck,
|
|
97
|
+
hasConsumerStoppedPropagationRef,
|
|
98
|
+
isFormControl,
|
|
99
|
+
bubbleInput
|
|
100
|
+
} = useRadioContext("RadioTrigger", __scopeRadio);
|
|
101
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setControl, (0, import_internal.subSlot)(slot, "refs"));
|
|
102
|
+
return (0, import_octane.createElement)(import_Primitive.Primitive.button, {
|
|
103
|
+
type: "button",
|
|
104
|
+
role: "radio",
|
|
105
|
+
"aria-checked": checked,
|
|
106
|
+
"data-state": getState(checked),
|
|
107
|
+
"data-disabled": disabled ? "" : void 0,
|
|
108
|
+
disabled,
|
|
109
|
+
value,
|
|
110
|
+
...radioProps,
|
|
111
|
+
ref: composedRefs,
|
|
112
|
+
onClick: (0, import_compose_event_handlers.composeEventHandlers)(onClick, (event) => {
|
|
113
|
+
if (!checked) onCheck();
|
|
114
|
+
if (bubbleInput && isFormControl) {
|
|
115
|
+
hasConsumerStoppedPropagationRef.current = event.cancelBubble;
|
|
116
|
+
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function Radio(props) {
|
|
122
|
+
const {
|
|
123
|
+
__scopeRadio,
|
|
124
|
+
name,
|
|
125
|
+
checked,
|
|
126
|
+
required,
|
|
127
|
+
disabled,
|
|
128
|
+
value,
|
|
129
|
+
onCheck,
|
|
130
|
+
form,
|
|
131
|
+
ref: forwardedRef,
|
|
132
|
+
...radioProps
|
|
133
|
+
} = props ?? {};
|
|
134
|
+
return (0, import_octane.createElement)(RadioProvider, {
|
|
135
|
+
__scopeRadio,
|
|
136
|
+
checked,
|
|
137
|
+
disabled,
|
|
138
|
+
required,
|
|
139
|
+
onCheck,
|
|
140
|
+
name,
|
|
141
|
+
form,
|
|
142
|
+
value,
|
|
143
|
+
internal_do_not_use_render: ({ isFormControl }) => [
|
|
144
|
+
(0, import_octane.createElement)(RadioTrigger, {
|
|
145
|
+
key: "trigger",
|
|
146
|
+
...radioProps,
|
|
147
|
+
ref: forwardedRef,
|
|
148
|
+
__scopeRadio
|
|
149
|
+
}),
|
|
150
|
+
isFormControl ? (0, import_octane.createElement)(RadioBubbleInput, { key: "bubble", __scopeRadio }) : null
|
|
151
|
+
]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function RadioIndicator(props) {
|
|
155
|
+
const { __scopeRadio, forceMount, ...indicatorProps } = props ?? {};
|
|
156
|
+
const context = useRadioContext("RadioIndicator", __scopeRadio);
|
|
157
|
+
return (0, import_octane.createElement)(import_Presence.Presence, {
|
|
158
|
+
present: forceMount || context.checked,
|
|
159
|
+
children: (0, import_octane.createElement)(import_Primitive.Primitive.span, {
|
|
160
|
+
"data-state": getState(context.checked),
|
|
161
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
162
|
+
...indicatorProps
|
|
163
|
+
})
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function RadioBubbleInput(props) {
|
|
167
|
+
const slot = (0, import_internal.S)("Radio.BubbleInput");
|
|
168
|
+
const { __scopeRadio, ref: forwardedRef, ...inputProps } = props ?? {};
|
|
169
|
+
const {
|
|
170
|
+
control,
|
|
171
|
+
checked,
|
|
172
|
+
required,
|
|
173
|
+
disabled,
|
|
174
|
+
name,
|
|
175
|
+
value,
|
|
176
|
+
form,
|
|
177
|
+
bubbleInput,
|
|
178
|
+
setBubbleInput,
|
|
179
|
+
hasConsumerStoppedPropagationRef
|
|
180
|
+
} = useRadioContext("RadioBubbleInput", __scopeRadio);
|
|
181
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setBubbleInput, (0, import_internal.subSlot)(slot, "refs"));
|
|
182
|
+
const prevChecked = (0, import_use_previous.usePrevious)(checked, (0, import_internal.subSlot)(slot, "prev"));
|
|
183
|
+
const controlSize = (0, import_use_size.useSize)(control, (0, import_internal.subSlot)(slot, "size"));
|
|
184
|
+
(0, import_octane.useEffect)(
|
|
185
|
+
() => {
|
|
186
|
+
const input = bubbleInput;
|
|
187
|
+
if (!input) return;
|
|
188
|
+
const bubbles = !hasConsumerStoppedPropagationRef.current;
|
|
189
|
+
if (prevChecked !== checked) {
|
|
190
|
+
input.dispatchEvent(new Event("click", { bubbles }));
|
|
191
|
+
input.dispatchEvent(new Event("change", { bubbles }));
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
[bubbleInput, prevChecked, checked, hasConsumerStoppedPropagationRef],
|
|
195
|
+
(0, import_internal.subSlot)(slot, "e:bubble")
|
|
196
|
+
);
|
|
197
|
+
return (0, import_octane.createElement)(import_Primitive.Primitive.input, {
|
|
198
|
+
type: "radio",
|
|
199
|
+
"aria-hidden": true,
|
|
200
|
+
// Live CONTROLLED checked (octane React-parity — see Checkbox.ts). The runtime's
|
|
201
|
+
// event-restore also re-syncs radio-group cousins after a dispatched `click`.
|
|
202
|
+
checked,
|
|
203
|
+
required,
|
|
204
|
+
disabled,
|
|
205
|
+
name,
|
|
206
|
+
value,
|
|
207
|
+
form,
|
|
208
|
+
...inputProps,
|
|
209
|
+
tabIndex: -1,
|
|
210
|
+
ref: composedRefs,
|
|
211
|
+
style: {
|
|
212
|
+
...props?.style,
|
|
213
|
+
...controlSize,
|
|
214
|
+
position: "absolute",
|
|
215
|
+
pointerEvents: "none",
|
|
216
|
+
opacity: 0,
|
|
217
|
+
margin: 0,
|
|
218
|
+
// We transform because the input is absolutely positioned but we have
|
|
219
|
+
// rendered it **after** the button. This pulls it back to sit on top
|
|
220
|
+
// of the button.
|
|
221
|
+
transform: "translateX(-100%)"
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function isFunction(value) {
|
|
226
|
+
return typeof value === "function";
|
|
227
|
+
}
|
|
228
|
+
function getState(checked) {
|
|
229
|
+
return checked ? "checked" : "unchecked";
|
|
230
|
+
}
|
|
231
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
+
0 && (module.exports = {
|
|
233
|
+
Radio,
|
|
234
|
+
RadioBubbleInput,
|
|
235
|
+
RadioIndicator,
|
|
236
|
+
RadioProvider,
|
|
237
|
+
RadioTrigger,
|
|
238
|
+
createRadioScope,
|
|
239
|
+
useRadioContext
|
|
240
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var RadioGroup_exports = {};
|
|
30
|
+
__export(RadioGroup_exports, {
|
|
31
|
+
Indicator: () => Indicator,
|
|
32
|
+
Item: () => Item,
|
|
33
|
+
RadioGroup: () => Root,
|
|
34
|
+
RadioGroupIndicator: () => Indicator,
|
|
35
|
+
RadioGroupItem: () => Item,
|
|
36
|
+
RadioGroupItemBubbleInput: () => ItemBubbleInput,
|
|
37
|
+
RadioGroupItemProvider: () => ItemProvider,
|
|
38
|
+
RadioGroupItemTrigger: () => ItemTrigger,
|
|
39
|
+
Root: () => Root,
|
|
40
|
+
createRadioGroupScope: () => createRadioGroupScope
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(RadioGroup_exports);
|
|
43
|
+
var import_octane = require("octane");
|
|
44
|
+
var import_compose_event_handlers = require("./compose-event-handlers.cjs");
|
|
45
|
+
var import_compose_refs = require("./compose-refs.cjs");
|
|
46
|
+
var import_context = require("./context.cjs");
|
|
47
|
+
var import_direction = require("./direction.cjs");
|
|
48
|
+
var import_internal = require("./internal.cjs");
|
|
49
|
+
var import_Primitive = require("./Primitive.cjs");
|
|
50
|
+
var import_Radio = require("./Radio.cjs");
|
|
51
|
+
var RovingFocusGroup = __toESM(require("./RovingFocusGroup.cjs"), 1);
|
|
52
|
+
var import_RovingFocusGroup = require("./RovingFocusGroup.cjs");
|
|
53
|
+
var import_useControllableState = require("./useControllableState.cjs");
|
|
54
|
+
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
55
|
+
const RADIO_GROUP_NAME = "RadioGroup";
|
|
56
|
+
const [createRadioGroupContext, createRadioGroupScope] = (0, import_context.createContextScope)(RADIO_GROUP_NAME, [
|
|
57
|
+
import_RovingFocusGroup.createRovingFocusGroupScope,
|
|
58
|
+
import_Radio.createRadioScope
|
|
59
|
+
]);
|
|
60
|
+
const useRovingFocusGroupScope = (0, import_RovingFocusGroup.createRovingFocusGroupScope)();
|
|
61
|
+
const useRadioScope = (0, import_Radio.createRadioScope)();
|
|
62
|
+
const [RadioGroupProvider, useRadioGroupContext] = createRadioGroupContext(RADIO_GROUP_NAME);
|
|
63
|
+
function Root(props) {
|
|
64
|
+
const slot = (0, import_internal.S)("RadioGroup.Root");
|
|
65
|
+
const {
|
|
66
|
+
__scopeRadioGroup,
|
|
67
|
+
name,
|
|
68
|
+
defaultValue,
|
|
69
|
+
value: valueProp,
|
|
70
|
+
required = false,
|
|
71
|
+
disabled = false,
|
|
72
|
+
orientation,
|
|
73
|
+
dir,
|
|
74
|
+
loop = true,
|
|
75
|
+
onValueChange,
|
|
76
|
+
ref: forwardedRef,
|
|
77
|
+
...groupProps
|
|
78
|
+
} = props ?? {};
|
|
79
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "rfs"));
|
|
80
|
+
const direction = (0, import_direction.useDirection)(dir);
|
|
81
|
+
const [value, setValue] = (0, import_useControllableState.useControllableState)(
|
|
82
|
+
{ prop: valueProp, defaultProp: defaultValue ?? null, onChange: onValueChange },
|
|
83
|
+
(0, import_internal.subSlot)(slot, "value")
|
|
84
|
+
);
|
|
85
|
+
return (0, import_octane.createElement)(RadioGroupProvider, {
|
|
86
|
+
scope: __scopeRadioGroup,
|
|
87
|
+
name,
|
|
88
|
+
required,
|
|
89
|
+
disabled,
|
|
90
|
+
value,
|
|
91
|
+
onValueChange: setValue,
|
|
92
|
+
children: (0, import_octane.createElement)(RovingFocusGroup.Root, {
|
|
93
|
+
asChild: true,
|
|
94
|
+
...rovingFocusGroupScope,
|
|
95
|
+
orientation,
|
|
96
|
+
dir: direction,
|
|
97
|
+
loop,
|
|
98
|
+
children: (0, import_octane.createElement)(import_Primitive.Primitive.div, {
|
|
99
|
+
role: "radiogroup",
|
|
100
|
+
"aria-required": required,
|
|
101
|
+
"aria-orientation": orientation,
|
|
102
|
+
"data-disabled": disabled ? "" : void 0,
|
|
103
|
+
dir: direction,
|
|
104
|
+
...groupProps,
|
|
105
|
+
ref: forwardedRef
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function ItemProvider(props) {
|
|
111
|
+
const slot = (0, import_internal.S)("RadioGroup.ItemProvider");
|
|
112
|
+
const { __scopeRadioGroup, value, disabled, children, internal_do_not_use_render } = props;
|
|
113
|
+
const context = useRadioGroupContext("RadioGroupItemProvider", __scopeRadioGroup);
|
|
114
|
+
const radioScope = useRadioScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "radio"));
|
|
115
|
+
const isDisabled = context.disabled || disabled;
|
|
116
|
+
return (0, import_octane.createElement)(import_Radio.RadioProvider, {
|
|
117
|
+
...radioScope,
|
|
118
|
+
checked: context.value === value,
|
|
119
|
+
disabled: isDisabled,
|
|
120
|
+
required: context.required,
|
|
121
|
+
name: context.name,
|
|
122
|
+
value,
|
|
123
|
+
onCheck: () => context.onValueChange(value),
|
|
124
|
+
internal_do_not_use_render,
|
|
125
|
+
children
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function ItemTrigger(props) {
|
|
129
|
+
const slot = (0, import_internal.S)("RadioGroup.ItemTrigger");
|
|
130
|
+
const { __scopeRadioGroup, ref: forwardedRef, ...triggerProps } = props;
|
|
131
|
+
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "rfs"));
|
|
132
|
+
const radioScope = useRadioScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "radio"));
|
|
133
|
+
const { checked, disabled } = (0, import_Radio.useRadioContext)("RadioGroupItemTrigger", radioScope.__scopeRadio);
|
|
134
|
+
const ref = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "ref"));
|
|
135
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, (0, import_internal.subSlot)(slot, "refs"));
|
|
136
|
+
const isArrowKeyPressedRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "arrow"));
|
|
137
|
+
(0, import_octane.useEffect)(
|
|
138
|
+
() => {
|
|
139
|
+
const handleKeyDown = (event) => {
|
|
140
|
+
if (ARROW_KEYS.includes(event.key)) {
|
|
141
|
+
isArrowKeyPressedRef.current = true;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const handleKeyUp = () => isArrowKeyPressedRef.current = false;
|
|
145
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
146
|
+
document.addEventListener("keyup", handleKeyUp);
|
|
147
|
+
return () => {
|
|
148
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
149
|
+
document.removeEventListener("keyup", handleKeyUp);
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
[],
|
|
153
|
+
(0, import_internal.subSlot)(slot, "e:keys")
|
|
154
|
+
);
|
|
155
|
+
return (0, import_octane.createElement)(RovingFocusGroup.Item, {
|
|
156
|
+
asChild: true,
|
|
157
|
+
...rovingFocusGroupScope,
|
|
158
|
+
focusable: !disabled,
|
|
159
|
+
active: checked,
|
|
160
|
+
children: (0, import_octane.createElement)(import_Radio.RadioTrigger, {
|
|
161
|
+
...radioScope,
|
|
162
|
+
...triggerProps,
|
|
163
|
+
ref: composedRefs,
|
|
164
|
+
onKeyDown: (0, import_compose_event_handlers.composeEventHandlers)(triggerProps.onKeyDown, (event) => {
|
|
165
|
+
if (event.key === "Enter") event.preventDefault();
|
|
166
|
+
}),
|
|
167
|
+
onFocus: (0, import_compose_event_handlers.composeEventHandlers)(triggerProps.onFocus, () => {
|
|
168
|
+
if (isArrowKeyPressedRef.current) {
|
|
169
|
+
ref.current?.click();
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function Item(props) {
|
|
176
|
+
const { __scopeRadioGroup, value, disabled, ref: forwardedRef, ...itemProps } = props ?? {};
|
|
177
|
+
return (0, import_octane.createElement)(ItemProvider, {
|
|
178
|
+
__scopeRadioGroup,
|
|
179
|
+
value,
|
|
180
|
+
disabled,
|
|
181
|
+
internal_do_not_use_render: ({ isFormControl }) => [
|
|
182
|
+
(0, import_octane.createElement)(ItemTrigger, {
|
|
183
|
+
key: "trigger",
|
|
184
|
+
...itemProps,
|
|
185
|
+
ref: forwardedRef,
|
|
186
|
+
__scopeRadioGroup
|
|
187
|
+
}),
|
|
188
|
+
isFormControl ? (0, import_octane.createElement)(ItemBubbleInput, { key: "bubble", __scopeRadioGroup }) : null
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function ItemBubbleInput(props) {
|
|
193
|
+
const slot = (0, import_internal.S)("RadioGroup.ItemBubbleInput");
|
|
194
|
+
const { __scopeRadioGroup, ...bubbleProps } = props;
|
|
195
|
+
const radioScope = useRadioScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "radio"));
|
|
196
|
+
return (0, import_octane.createElement)(import_Radio.RadioBubbleInput, { ...radioScope, ...bubbleProps });
|
|
197
|
+
}
|
|
198
|
+
function Indicator(props) {
|
|
199
|
+
const slot = (0, import_internal.S)("RadioGroup.Indicator");
|
|
200
|
+
const { __scopeRadioGroup, ...indicatorProps } = props ?? {};
|
|
201
|
+
const radioScope = useRadioScope(__scopeRadioGroup, (0, import_internal.subSlot)(slot, "radio"));
|
|
202
|
+
return (0, import_octane.createElement)(import_Radio.RadioIndicator, { ...radioScope, ...indicatorProps });
|
|
203
|
+
}
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
Indicator,
|
|
207
|
+
Item,
|
|
208
|
+
RadioGroup,
|
|
209
|
+
RadioGroupIndicator,
|
|
210
|
+
RadioGroupItem,
|
|
211
|
+
RadioGroupItemBubbleInput,
|
|
212
|
+
RadioGroupItemProvider,
|
|
213
|
+
RadioGroupItemTrigger,
|
|
214
|
+
Root,
|
|
215
|
+
createRadioGroupScope
|
|
216
|
+
});
|