UEA-PRODEM
This commit is contained in:
+264
-129
@@ -1,31 +1,31 @@
|
||||
"use client";
|
||||
import {
|
||||
Presence
|
||||
} from "./chunk-THQIQPZA.js";
|
||||
import {
|
||||
createCollection,
|
||||
useDirection,
|
||||
usePrevious,
|
||||
useSize
|
||||
} from "./chunk-BZDTGYB5.js";
|
||||
} from "./chunk-MN52RY2D.js";
|
||||
import {
|
||||
Primitive,
|
||||
Presence,
|
||||
composeEventHandlers,
|
||||
createContextScope,
|
||||
useCallbackRef,
|
||||
useControllableState,
|
||||
useId
|
||||
} from "./chunk-VURJIDBW.js";
|
||||
import "./chunk-YF4B4G2L.js";
|
||||
} from "./chunk-TU5XDRIH.js";
|
||||
import {
|
||||
Primitive
|
||||
} from "./chunk-QPQFA2HW.js";
|
||||
import {
|
||||
useComposedRefs
|
||||
} from "./chunk-2VUH7NEY.js";
|
||||
} from "./chunk-7O5GCKER.js";
|
||||
import "./chunk-UEHR66ST.js";
|
||||
import {
|
||||
require_jsx_runtime
|
||||
} from "./chunk-2YVA4HRZ.js";
|
||||
} from "./chunk-LPULNKJF.js";
|
||||
import {
|
||||
require_react
|
||||
} from "./chunk-WUR7D6NS.js";
|
||||
} from "./chunk-42LCURWG.js";
|
||||
import {
|
||||
__toESM
|
||||
} from "./chunk-G3PMV62Z.js";
|
||||
@@ -252,61 +252,115 @@ var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
|
||||
var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
|
||||
var RADIO_NAME = "Radio";
|
||||
var [createRadioContext, createRadioScope] = createContextScope(RADIO_NAME);
|
||||
var [RadioProvider, useRadioContext] = createRadioContext(RADIO_NAME);
|
||||
var [RadioProviderImpl, useRadioContext] = createRadioContext(RADIO_NAME);
|
||||
function RadioProvider(props) {
|
||||
const {
|
||||
__scopeRadio,
|
||||
checked = false,
|
||||
children,
|
||||
disabled,
|
||||
form,
|
||||
name,
|
||||
onCheck,
|
||||
required,
|
||||
value = "on",
|
||||
// @ts-expect-error
|
||||
internal_do_not_use_render
|
||||
} = props;
|
||||
const [control, setControl] = React3.useState(null);
|
||||
const [bubbleInput, setBubbleInput] = React3.useState(null);
|
||||
const hasConsumerStoppedPropagationRef = React3.useRef(false);
|
||||
const isFormControl = control ? !!form || !!control.closest("form") : (
|
||||
// We set this to true by default so that events bubble to forms without JS (SSR)
|
||||
true
|
||||
);
|
||||
const context = {
|
||||
checked,
|
||||
disabled,
|
||||
required,
|
||||
name,
|
||||
form,
|
||||
value,
|
||||
control,
|
||||
setControl,
|
||||
hasConsumerStoppedPropagationRef,
|
||||
isFormControl,
|
||||
bubbleInput,
|
||||
setBubbleInput,
|
||||
onCheck: () => onCheck?.()
|
||||
};
|
||||
return (0, import_jsx_runtime2.jsx)(RadioProviderImpl, { scope: __scopeRadio, ...context, children: isFunction(internal_do_not_use_render) ? internal_do_not_use_render(context) : children });
|
||||
}
|
||||
var TRIGGER_NAME = "RadioTrigger";
|
||||
var RadioTrigger = React3.forwardRef(
|
||||
({ __scopeRadio, onClick, ...radioProps }, forwardedRef) => {
|
||||
const {
|
||||
checked,
|
||||
disabled,
|
||||
value,
|
||||
setControl,
|
||||
onCheck,
|
||||
hasConsumerStoppedPropagationRef,
|
||||
isFormControl,
|
||||
bubbleInput
|
||||
} = useRadioContext(TRIGGER_NAME, __scopeRadio);
|
||||
const composedRefs = useComposedRefs(forwardedRef, setControl);
|
||||
return (0, import_jsx_runtime2.jsx)(
|
||||
Primitive.button,
|
||||
{
|
||||
type: "button",
|
||||
role: "radio",
|
||||
"aria-checked": checked,
|
||||
"data-state": getState(checked),
|
||||
"data-disabled": disabled ? "" : void 0,
|
||||
disabled,
|
||||
value,
|
||||
...radioProps,
|
||||
ref: composedRefs,
|
||||
onClick: composeEventHandlers(onClick, (event) => {
|
||||
if (!checked) onCheck();
|
||||
if (bubbleInput && isFormControl) {
|
||||
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
||||
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
||||
}
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
RadioTrigger.displayName = TRIGGER_NAME;
|
||||
var Radio = React3.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
const {
|
||||
__scopeRadio,
|
||||
name,
|
||||
checked = false,
|
||||
required,
|
||||
disabled,
|
||||
value = "on",
|
||||
onCheck,
|
||||
form,
|
||||
...radioProps
|
||||
} = props;
|
||||
const [button, setButton] = React3.useState(null);
|
||||
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
|
||||
const hasConsumerStoppedPropagationRef = React3.useRef(false);
|
||||
const isFormControl = button ? form || !!button.closest("form") : true;
|
||||
return (0, import_jsx_runtime2.jsxs)(RadioProvider, { scope: __scopeRadio, checked, disabled, children: [
|
||||
(0, import_jsx_runtime2.jsx)(
|
||||
Primitive.button,
|
||||
{
|
||||
type: "button",
|
||||
role: "radio",
|
||||
"aria-checked": checked,
|
||||
"data-state": getState(checked),
|
||||
"data-disabled": disabled ? "" : void 0,
|
||||
disabled,
|
||||
value,
|
||||
...radioProps,
|
||||
ref: composedRefs,
|
||||
onClick: composeEventHandlers(props.onClick, (event) => {
|
||||
if (!checked) onCheck?.();
|
||||
if (isFormControl) {
|
||||
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
||||
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
|
||||
const { __scopeRadio, name, checked, required, disabled, value, onCheck, form, ...radioProps } = props;
|
||||
return (0, import_jsx_runtime2.jsx)(
|
||||
RadioProvider,
|
||||
{
|
||||
__scopeRadio,
|
||||
checked,
|
||||
disabled,
|
||||
required,
|
||||
onCheck,
|
||||
name,
|
||||
form,
|
||||
value,
|
||||
internal_do_not_use_render: ({ isFormControl }) => (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
||||
(0, import_jsx_runtime2.jsx)(
|
||||
RadioTrigger,
|
||||
{
|
||||
...radioProps,
|
||||
ref: forwardedRef,
|
||||
__scopeRadio
|
||||
}
|
||||
})
|
||||
}
|
||||
),
|
||||
isFormControl && (0, import_jsx_runtime2.jsx)(
|
||||
RadioBubbleInput,
|
||||
{
|
||||
control: button,
|
||||
bubbles: !hasConsumerStoppedPropagationRef.current,
|
||||
name,
|
||||
value,
|
||||
checked,
|
||||
required,
|
||||
disabled,
|
||||
form,
|
||||
style: { transform: "translateX(-100%)" }
|
||||
}
|
||||
)
|
||||
] });
|
||||
),
|
||||
isFormControl && (0, import_jsx_runtime2.jsx)(
|
||||
RadioBubbleInput,
|
||||
{
|
||||
__scopeRadio
|
||||
}
|
||||
)
|
||||
] })
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
Radio.displayName = RADIO_NAME;
|
||||
@@ -329,19 +383,24 @@ var RadioIndicator = React3.forwardRef(
|
||||
RadioIndicator.displayName = INDICATOR_NAME;
|
||||
var BUBBLE_INPUT_NAME = "RadioBubbleInput";
|
||||
var RadioBubbleInput = React3.forwardRef(
|
||||
({
|
||||
__scopeRadio,
|
||||
control,
|
||||
checked,
|
||||
bubbles = true,
|
||||
...props
|
||||
}, forwardedRef) => {
|
||||
const ref = React3.useRef(null);
|
||||
const composedRefs = useComposedRefs(ref, forwardedRef);
|
||||
({ __scopeRadio, ...props }, forwardedRef) => {
|
||||
const {
|
||||
control,
|
||||
checked,
|
||||
required,
|
||||
disabled,
|
||||
name,
|
||||
value,
|
||||
form,
|
||||
bubbleInput,
|
||||
setBubbleInput,
|
||||
hasConsumerStoppedPropagationRef
|
||||
} = useRadioContext(BUBBLE_INPUT_NAME, __scopeRadio);
|
||||
const composedRefs = useComposedRefs(forwardedRef, setBubbleInput);
|
||||
const prevChecked = usePrevious(checked);
|
||||
const controlSize = useSize(control);
|
||||
React3.useEffect(() => {
|
||||
const input = ref.current;
|
||||
const input = bubbleInput;
|
||||
if (!input) return;
|
||||
const inputProto = window.HTMLInputElement.prototype;
|
||||
const descriptor = Object.getOwnPropertyDescriptor(
|
||||
@@ -349,18 +408,25 @@ var RadioBubbleInput = React3.forwardRef(
|
||||
"checked"
|
||||
);
|
||||
const setChecked = descriptor.set;
|
||||
const bubbles = !hasConsumerStoppedPropagationRef.current;
|
||||
if (prevChecked !== checked && setChecked) {
|
||||
const event = new Event("click", { bubbles });
|
||||
setChecked.call(input, checked);
|
||||
input.dispatchEvent(event);
|
||||
}
|
||||
}, [prevChecked, checked, bubbles]);
|
||||
}, [bubbleInput, prevChecked, checked, hasConsumerStoppedPropagationRef]);
|
||||
const defaultCheckedRef = React3.useRef(checked);
|
||||
return (0, import_jsx_runtime2.jsx)(
|
||||
Primitive.input,
|
||||
{
|
||||
type: "radio",
|
||||
"aria-hidden": true,
|
||||
defaultChecked: checked,
|
||||
defaultChecked: defaultCheckedRef.current,
|
||||
required,
|
||||
disabled,
|
||||
name,
|
||||
value,
|
||||
form,
|
||||
...props,
|
||||
tabIndex: -1,
|
||||
ref: composedRefs,
|
||||
@@ -370,13 +436,20 @@ var RadioBubbleInput = React3.forwardRef(
|
||||
position: "absolute",
|
||||
pointerEvents: "none",
|
||||
opacity: 0,
|
||||
margin: 0
|
||||
margin: 0,
|
||||
// We transform because the input is absolutely positioned but we have
|
||||
// rendered it **after** the button. This pulls it back to sit on top
|
||||
// of the button.
|
||||
transform: "translateX(-100%)"
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
RadioBubbleInput.displayName = BUBBLE_INPUT_NAME;
|
||||
function isFunction(value) {
|
||||
return typeof value === "function";
|
||||
}
|
||||
function getState(checked) {
|
||||
return checked ? "checked" : "unchecked";
|
||||
}
|
||||
@@ -449,62 +522,121 @@ var RadioGroup = React2.forwardRef(
|
||||
);
|
||||
RadioGroup.displayName = RADIO_GROUP_NAME;
|
||||
var ITEM_NAME2 = "RadioGroupItem";
|
||||
var ITEM_PROVIDER_NAME = "RadioGroupItemProvider";
|
||||
var ITEM_TRIGGER_NAME = "RadioGroupItemTrigger";
|
||||
var ITEM_BUBBLE_INPUT_NAME = "RadioGroupItemBubbleInput";
|
||||
function RadioGroupItemProvider(props) {
|
||||
const {
|
||||
__scopeRadioGroup,
|
||||
value,
|
||||
disabled,
|
||||
children,
|
||||
// @ts-expect-error
|
||||
internal_do_not_use_render
|
||||
} = props;
|
||||
const context = useRadioGroupContext(ITEM_PROVIDER_NAME, __scopeRadioGroup);
|
||||
const radioScope = useRadioScope(__scopeRadioGroup);
|
||||
const isDisabled = context.disabled || disabled;
|
||||
return (0, import_jsx_runtime3.jsx)(
|
||||
RadioProvider,
|
||||
{
|
||||
...radioScope,
|
||||
checked: context.value === value,
|
||||
disabled: isDisabled,
|
||||
required: context.required,
|
||||
name: context.name,
|
||||
value,
|
||||
onCheck: () => context.onValueChange(value),
|
||||
internal_do_not_use_render,
|
||||
children
|
||||
}
|
||||
);
|
||||
}
|
||||
var RadioGroupItemTrigger = React2.forwardRef((props, forwardedRef) => {
|
||||
const { __scopeRadioGroup, ...triggerProps } = props;
|
||||
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
|
||||
const radioScope = useRadioScope(__scopeRadioGroup);
|
||||
const { checked, disabled } = useRadioContext(ITEM_TRIGGER_NAME, radioScope.__scopeRadio);
|
||||
const ref = React2.useRef(null);
|
||||
const composedRefs = useComposedRefs(forwardedRef, ref);
|
||||
const isArrowKeyPressedRef = React2.useRef(false);
|
||||
React2.useEffect(() => {
|
||||
const handleKeyDown = (event) => {
|
||||
if (ARROW_KEYS.includes(event.key)) {
|
||||
isArrowKeyPressedRef.current = true;
|
||||
}
|
||||
};
|
||||
const handleKeyUp = () => isArrowKeyPressedRef.current = false;
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
document.addEventListener("keyup", handleKeyUp);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
document.removeEventListener("keyup", handleKeyUp);
|
||||
};
|
||||
}, []);
|
||||
return (0, import_jsx_runtime3.jsx)(
|
||||
Item,
|
||||
{
|
||||
asChild: true,
|
||||
...rovingFocusGroupScope,
|
||||
focusable: !disabled,
|
||||
active: checked,
|
||||
children: (0, import_jsx_runtime3.jsx)(
|
||||
RadioTrigger,
|
||||
{
|
||||
...radioScope,
|
||||
...triggerProps,
|
||||
ref: composedRefs,
|
||||
onKeyDown: composeEventHandlers(triggerProps.onKeyDown, (event) => {
|
||||
if (event.key === "Enter") event.preventDefault();
|
||||
}),
|
||||
onFocus: composeEventHandlers(triggerProps.onFocus, () => {
|
||||
if (isArrowKeyPressedRef.current) {
|
||||
ref.current?.click();
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
RadioGroupItemTrigger.displayName = ITEM_TRIGGER_NAME;
|
||||
var RadioGroupItem = React2.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
const { __scopeRadioGroup, disabled, ...itemProps } = props;
|
||||
const context = useRadioGroupContext(ITEM_NAME2, __scopeRadioGroup);
|
||||
const isDisabled = context.disabled || disabled;
|
||||
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
|
||||
const radioScope = useRadioScope(__scopeRadioGroup);
|
||||
const ref = React2.useRef(null);
|
||||
const composedRefs = useComposedRefs(forwardedRef, ref);
|
||||
const checked = context.value === itemProps.value;
|
||||
const isArrowKeyPressedRef = React2.useRef(false);
|
||||
React2.useEffect(() => {
|
||||
const handleKeyDown = (event) => {
|
||||
if (ARROW_KEYS.includes(event.key)) {
|
||||
isArrowKeyPressedRef.current = true;
|
||||
}
|
||||
};
|
||||
const handleKeyUp = () => isArrowKeyPressedRef.current = false;
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
document.addEventListener("keyup", handleKeyUp);
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeyDown);
|
||||
document.removeEventListener("keyup", handleKeyUp);
|
||||
};
|
||||
}, []);
|
||||
const { __scopeRadioGroup, value, disabled, ...itemProps } = props;
|
||||
return (0, import_jsx_runtime3.jsx)(
|
||||
Item,
|
||||
RadioGroupItemProvider,
|
||||
{
|
||||
asChild: true,
|
||||
...rovingFocusGroupScope,
|
||||
focusable: !isDisabled,
|
||||
active: checked,
|
||||
children: (0, import_jsx_runtime3.jsx)(
|
||||
Radio,
|
||||
{
|
||||
disabled: isDisabled,
|
||||
required: context.required,
|
||||
checked,
|
||||
...radioScope,
|
||||
...itemProps,
|
||||
name: context.name,
|
||||
ref: composedRefs,
|
||||
onCheck: () => context.onValueChange(itemProps.value),
|
||||
onKeyDown: composeEventHandlers((event) => {
|
||||
if (event.key === "Enter") event.preventDefault();
|
||||
}),
|
||||
onFocus: composeEventHandlers(itemProps.onFocus, () => {
|
||||
if (isArrowKeyPressedRef.current) ref.current?.click();
|
||||
})
|
||||
}
|
||||
)
|
||||
__scopeRadioGroup,
|
||||
value,
|
||||
disabled,
|
||||
internal_do_not_use_render: ({ isFormControl }) => (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
||||
(0, import_jsx_runtime3.jsx)(
|
||||
RadioGroupItemTrigger,
|
||||
{
|
||||
...itemProps,
|
||||
ref: forwardedRef,
|
||||
__scopeRadioGroup
|
||||
}
|
||||
),
|
||||
isFormControl && (0, import_jsx_runtime3.jsx)(
|
||||
RadioGroupItemBubbleInput,
|
||||
{
|
||||
__scopeRadioGroup
|
||||
}
|
||||
)
|
||||
] })
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
RadioGroupItem.displayName = ITEM_NAME2;
|
||||
var RadioGroupItemBubbleInput = React2.forwardRef((props, forwardedRef) => {
|
||||
const { __scopeRadioGroup, ...bubbleProps } = props;
|
||||
const radioScope = useRadioScope(__scopeRadioGroup);
|
||||
return (0, import_jsx_runtime3.jsx)(RadioBubbleInput, { ...radioScope, ...bubbleProps, ref: forwardedRef });
|
||||
});
|
||||
RadioGroupItemBubbleInput.displayName = ITEM_BUBBLE_INPUT_NAME;
|
||||
var INDICATOR_NAME2 = "RadioGroupIndicator";
|
||||
var RadioGroupIndicator = React2.forwardRef(
|
||||
(props, forwardedRef) => {
|
||||
@@ -514,16 +646,19 @@ var RadioGroupIndicator = React2.forwardRef(
|
||||
}
|
||||
);
|
||||
RadioGroupIndicator.displayName = INDICATOR_NAME2;
|
||||
var Root2 = RadioGroup;
|
||||
var Item2 = RadioGroupItem;
|
||||
var Indicator = RadioGroupIndicator;
|
||||
export {
|
||||
Indicator,
|
||||
Item2 as Item,
|
||||
RadioGroupIndicator as Indicator,
|
||||
RadioGroupItem as Item,
|
||||
RadioGroup,
|
||||
RadioGroupIndicator,
|
||||
RadioGroupItem,
|
||||
Root2 as Root,
|
||||
createRadioGroupScope
|
||||
RadioGroup as Root,
|
||||
createRadioGroupScope,
|
||||
RadioGroupItemBubbleInput as unstable_ItemBubbleInput,
|
||||
RadioGroupItemProvider as unstable_ItemProvider,
|
||||
RadioGroupItemTrigger as unstable_ItemTrigger,
|
||||
RadioGroupItemBubbleInput as unstable_RadioGroupItemBubbleInput,
|
||||
RadioGroupItemProvider as unstable_RadioGroupItemProvider,
|
||||
RadioGroupItemTrigger as unstable_RadioGroupItemTrigger
|
||||
};
|
||||
//# sourceMappingURL=@radix-ui_react-radio-group.js.map
|
||||
|
||||
Reference in New Issue
Block a user