UEA-PRODEM

This commit is contained in:
2026-06-10 12:14:46 -03:00
parent f54126b9d8
commit 9947565694
5319 changed files with 148520 additions and 129332 deletions
+37 -5
View File
@@ -1,10 +1,26 @@
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as _radix_ui_react_context from '@radix-ui/react-context';
import { Scope } from '@radix-ui/react-context';
import * as React from 'react';
import { Primitive } from '@radix-ui/react-primitive';
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
interface RadioProviderProps {
checked?: boolean;
required?: boolean;
disabled?: boolean;
name?: string;
form?: string;
value?: string | number | readonly string[];
onCheck?(): void;
children?: React.ReactNode;
}
interface RadioTriggerProps extends Omit<React.ComponentPropsWithoutRef<typeof Primitive.button>, keyof RadioProviderProps> {
children?: React.ReactNode;
}
declare const RadioTrigger: React.ForwardRefExoticComponent<RadioTriggerProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface RadioProps$1 extends PrimitiveButtonProps {
interface RadioProps$1 extends Omit<PrimitiveButtonProps, 'checked'> {
checked?: boolean;
required?: boolean;
onCheck?(): void;
@@ -19,7 +35,14 @@ interface RadioIndicatorProps$1 extends PrimitiveSpanProps {
forceMount?: true;
}
declare const RadioIndicator: React.ForwardRefExoticComponent<RadioIndicatorProps$1 & React.RefAttributes<HTMLSpanElement>>;
type InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;
interface RadioBubbleInputProps extends Omit<InputProps, 'checked'> {
}
declare const RadioBubbleInput: React.ForwardRefExoticComponent<RadioBubbleInputProps & React.RefAttributes<HTMLInputElement>>;
type ScopedProps<P> = P & {
__scopeRadioGroup?: Scope;
};
declare const createRadioGroupScope: _radix_ui_react_context.CreateScope;
type RadioGroupContextValue = {
name?: string;
@@ -42,17 +65,26 @@ interface RadioGroupProps extends PrimitiveDivProps {
onValueChange?: RadioGroupContextValue['onValueChange'];
}
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
interface RadioGroupItemProviderProps {
value: string;
disabled?: boolean;
children?: React.ReactNode;
}
declare function RadioGroupItemProvider(props: ScopedProps<RadioGroupItemProviderProps>): react_jsx_runtime.JSX.Element;
interface RadioGroupItemTriggerProps extends React.ComponentPropsWithoutRef<typeof RadioTrigger> {
}
declare const RadioGroupItemTrigger: React.ForwardRefExoticComponent<RadioGroupItemTriggerProps & React.RefAttributes<HTMLButtonElement>>;
type RadioProps = React.ComponentPropsWithoutRef<typeof Radio>;
interface RadioGroupItemProps extends Omit<RadioProps, 'onCheck' | 'name'> {
value: string;
}
declare const RadioGroupItem: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
interface RadioGroupItemBubbleInputProps extends React.ComponentPropsWithoutRef<typeof RadioBubbleInput> {
}
declare const RadioGroupItemBubbleInput: React.ForwardRefExoticComponent<RadioGroupItemBubbleInputProps & React.RefAttributes<HTMLInputElement>>;
type RadioIndicatorProps = React.ComponentPropsWithoutRef<typeof RadioIndicator>;
interface RadioGroupIndicatorProps extends RadioIndicatorProps {
}
declare const RadioGroupIndicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
declare const Root: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
declare const Item: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
declare const Indicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
export { Indicator, Item, RadioGroup, RadioGroupIndicator, type RadioGroupIndicatorProps, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, Root, createRadioGroupScope };
export { RadioGroupIndicator as Indicator, RadioGroupItem as Item, RadioGroup, RadioGroupIndicator, type RadioGroupIndicatorProps, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, RadioGroup as Root, createRadioGroupScope, RadioGroupItemBubbleInput as unstable_ItemBubbleInput, RadioGroupItemProvider as unstable_ItemProvider, RadioGroupItemTrigger as unstable_ItemTrigger, RadioGroupItemBubbleInput as unstable_RadioGroupItemBubbleInput, type RadioGroupItemBubbleInputProps as unstable_RadioGroupItemBubbleInputProps, RadioGroupItemProvider as unstable_RadioGroupItemProvider, type RadioGroupItemProviderProps as unstable_RadioGroupItemProviderProps, RadioGroupItemTrigger as unstable_RadioGroupItemTrigger, type RadioGroupItemTriggerProps as unstable_RadioGroupItemTriggerProps };
+37 -5
View File
@@ -1,10 +1,26 @@
import * as react_jsx_runtime from 'react/jsx-runtime';
import * as _radix_ui_react_context from '@radix-ui/react-context';
import { Scope } from '@radix-ui/react-context';
import * as React from 'react';
import { Primitive } from '@radix-ui/react-primitive';
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
interface RadioProviderProps {
checked?: boolean;
required?: boolean;
disabled?: boolean;
name?: string;
form?: string;
value?: string | number | readonly string[];
onCheck?(): void;
children?: React.ReactNode;
}
interface RadioTriggerProps extends Omit<React.ComponentPropsWithoutRef<typeof Primitive.button>, keyof RadioProviderProps> {
children?: React.ReactNode;
}
declare const RadioTrigger: React.ForwardRefExoticComponent<RadioTriggerProps & React.RefAttributes<HTMLButtonElement>>;
type PrimitiveButtonProps = React.ComponentPropsWithoutRef<typeof Primitive.button>;
interface RadioProps$1 extends PrimitiveButtonProps {
interface RadioProps$1 extends Omit<PrimitiveButtonProps, 'checked'> {
checked?: boolean;
required?: boolean;
onCheck?(): void;
@@ -19,7 +35,14 @@ interface RadioIndicatorProps$1 extends PrimitiveSpanProps {
forceMount?: true;
}
declare const RadioIndicator: React.ForwardRefExoticComponent<RadioIndicatorProps$1 & React.RefAttributes<HTMLSpanElement>>;
type InputProps = React.ComponentPropsWithoutRef<typeof Primitive.input>;
interface RadioBubbleInputProps extends Omit<InputProps, 'checked'> {
}
declare const RadioBubbleInput: React.ForwardRefExoticComponent<RadioBubbleInputProps & React.RefAttributes<HTMLInputElement>>;
type ScopedProps<P> = P & {
__scopeRadioGroup?: Scope;
};
declare const createRadioGroupScope: _radix_ui_react_context.CreateScope;
type RadioGroupContextValue = {
name?: string;
@@ -42,17 +65,26 @@ interface RadioGroupProps extends PrimitiveDivProps {
onValueChange?: RadioGroupContextValue['onValueChange'];
}
declare const RadioGroup: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
interface RadioGroupItemProviderProps {
value: string;
disabled?: boolean;
children?: React.ReactNode;
}
declare function RadioGroupItemProvider(props: ScopedProps<RadioGroupItemProviderProps>): react_jsx_runtime.JSX.Element;
interface RadioGroupItemTriggerProps extends React.ComponentPropsWithoutRef<typeof RadioTrigger> {
}
declare const RadioGroupItemTrigger: React.ForwardRefExoticComponent<RadioGroupItemTriggerProps & React.RefAttributes<HTMLButtonElement>>;
type RadioProps = React.ComponentPropsWithoutRef<typeof Radio>;
interface RadioGroupItemProps extends Omit<RadioProps, 'onCheck' | 'name'> {
value: string;
}
declare const RadioGroupItem: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
interface RadioGroupItemBubbleInputProps extends React.ComponentPropsWithoutRef<typeof RadioBubbleInput> {
}
declare const RadioGroupItemBubbleInput: React.ForwardRefExoticComponent<RadioGroupItemBubbleInputProps & React.RefAttributes<HTMLInputElement>>;
type RadioIndicatorProps = React.ComponentPropsWithoutRef<typeof RadioIndicator>;
interface RadioGroupIndicatorProps extends RadioIndicatorProps {
}
declare const RadioGroupIndicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
declare const Root: React.ForwardRefExoticComponent<RadioGroupProps & React.RefAttributes<HTMLDivElement>>;
declare const Item: React.ForwardRefExoticComponent<RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
declare const Indicator: React.ForwardRefExoticComponent<RadioGroupIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
export { Indicator, Item, RadioGroup, RadioGroupIndicator, type RadioGroupIndicatorProps, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, Root, createRadioGroupScope };
export { RadioGroupIndicator as Indicator, RadioGroupItem as Item, RadioGroup, RadioGroupIndicator, type RadioGroupIndicatorProps, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, RadioGroup as Root, createRadioGroupScope, RadioGroupItemBubbleInput as unstable_ItemBubbleInput, RadioGroupItemProvider as unstable_ItemProvider, RadioGroupItemTrigger as unstable_ItemTrigger, RadioGroupItemBubbleInput as unstable_RadioGroupItemBubbleInput, type RadioGroupItemBubbleInputProps as unstable_RadioGroupItemBubbleInputProps, RadioGroupItemProvider as unstable_RadioGroupItemProvider, type RadioGroupItemProviderProps as unstable_RadioGroupItemProviderProps, RadioGroupItemTrigger as unstable_RadioGroupItemTrigger, type RadioGroupItemTriggerProps as unstable_RadioGroupItemTriggerProps };
+254 -119
View File
@@ -31,13 +31,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
// src/index.ts
var index_exports = {};
__export(index_exports, {
Indicator: () => Indicator,
Item: () => Item2,
Indicator: () => RadioGroupIndicator,
Item: () => RadioGroupItem,
RadioGroup: () => RadioGroup,
RadioGroupIndicator: () => RadioGroupIndicator,
RadioGroupItem: () => RadioGroupItem,
Root: () => Root2,
createRadioGroupScope: () => createRadioGroupScope
Root: () => RadioGroup,
createRadioGroupScope: () => createRadioGroupScope,
unstable_ItemBubbleInput: () => RadioGroupItemBubbleInput,
unstable_ItemProvider: () => RadioGroupItemProvider,
unstable_ItemTrigger: () => RadioGroupItemTrigger,
unstable_RadioGroupItemBubbleInput: () => RadioGroupItemBubbleInput,
unstable_RadioGroupItemProvider: () => RadioGroupItemProvider,
unstable_RadioGroupItemTrigger: () => RadioGroupItemTrigger
});
module.exports = __toCommonJS(index_exports);
@@ -64,61 +70,115 @@ var import_react_primitive = require("@radix-ui/react-primitive");
var import_jsx_runtime = require("react/jsx-runtime");
var RADIO_NAME = "Radio";
var [createRadioContext, createRadioScope] = (0, import_react_context.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] = React.useState(null);
const [bubbleInput, setBubbleInput] = React.useState(null);
const hasConsumerStoppedPropagationRef = React.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 /* @__PURE__ */ (0, import_jsx_runtime.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 = React.forwardRef(
({ __scopeRadio, onClick, ...radioProps }, forwardedRef) => {
const {
checked,
disabled,
value,
setControl,
onCheck,
hasConsumerStoppedPropagationRef,
isFormControl,
bubbleInput
} = useRadioContext(TRIGGER_NAME, __scopeRadio);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, setControl);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.button,
{
type: "button",
role: "radio",
"aria-checked": checked,
"data-state": getState(checked),
"data-disabled": disabled ? "" : void 0,
disabled,
value,
...radioProps,
ref: composedRefs,
onClick: (0, import_primitive.composeEventHandlers)(onClick, (event) => {
if (!checked) onCheck();
if (bubbleInput && isFormControl) {
hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation();
}
})
}
);
}
);
RadioTrigger.displayName = TRIGGER_NAME;
var Radio = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeRadio,
name,
checked = false,
required,
disabled,
value = "on",
onCheck,
form,
...radioProps
} = props;
const [button, setButton] = React.useState(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, (node) => setButton(node));
const hasConsumerStoppedPropagationRef = React.useRef(false);
const isFormControl = button ? form || !!button.closest("form") : true;
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(RadioProvider, { scope: __scopeRadio, checked, disabled, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.button,
{
type: "button",
role: "radio",
"aria-checked": checked,
"data-state": getState(checked),
"data-disabled": disabled ? "" : void 0,
disabled,
value,
...radioProps,
ref: composedRefs,
onClick: (0, import_primitive.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 /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
RadioProvider,
{
__scopeRadio,
checked,
disabled,
required,
onCheck,
name,
form,
value,
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
RadioTrigger,
{
...radioProps,
ref: forwardedRef,
__scopeRadio
}
})
}
),
isFormControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
RadioBubbleInput,
{
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name,
value,
checked,
required,
disabled,
form,
style: { transform: "translateX(-100%)" }
}
)
] });
),
isFormControl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
RadioBubbleInput,
{
__scopeRadio
}
)
] })
}
);
}
);
Radio.displayName = RADIO_NAME;
@@ -141,19 +201,24 @@ var RadioIndicator = React.forwardRef(
RadioIndicator.displayName = INDICATOR_NAME;
var BUBBLE_INPUT_NAME = "RadioBubbleInput";
var RadioBubbleInput = React.forwardRef(
({
__scopeRadio,
control,
checked,
bubbles = true,
...props
}, forwardedRef) => {
const ref = React.useRef(null);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(ref, forwardedRef);
({ __scopeRadio, ...props }, forwardedRef) => {
const {
control,
checked,
required,
disabled,
name,
value,
form,
bubbleInput,
setBubbleInput,
hasConsumerStoppedPropagationRef
} = useRadioContext(BUBBLE_INPUT_NAME, __scopeRadio);
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, setBubbleInput);
const prevChecked = (0, import_react_use_previous.usePrevious)(checked);
const controlSize = (0, import_react_use_size.useSize)(control);
React.useEffect(() => {
const input = ref.current;
const input = bubbleInput;
if (!input) return;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(
@@ -161,18 +226,25 @@ var RadioBubbleInput = React.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 = React.useRef(checked);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_react_primitive.Primitive.input,
{
type: "radio",
"aria-hidden": true,
defaultChecked: checked,
defaultChecked: defaultCheckedRef.current,
required,
disabled,
name,
value,
form,
...props,
tabIndex: -1,
ref: composedRefs,
@@ -182,13 +254,20 @@ var RadioBubbleInput = React.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";
}
@@ -264,62 +343,121 @@ var RadioGroup = React2.forwardRef(
);
RadioGroup.displayName = RADIO_GROUP_NAME;
var ITEM_NAME = "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 /* @__PURE__ */ (0, import_jsx_runtime2.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 = (0, import_react_compose_refs2.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 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RovingFocusGroup.Item,
{
asChild: true,
...rovingFocusGroupScope,
focusable: !disabled,
active: checked,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RadioTrigger,
{
...radioScope,
...triggerProps,
ref: composedRefs,
onKeyDown: (0, import_primitive2.composeEventHandlers)(triggerProps.onKeyDown, (event) => {
if (event.key === "Enter") event.preventDefault();
}),
onFocus: (0, import_primitive2.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_NAME, __scopeRadioGroup);
const isDisabled = context.disabled || disabled;
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
const radioScope = useRadioScope(__scopeRadioGroup);
const ref = React2.useRef(null);
const composedRefs = (0, import_react_compose_refs2.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 /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RovingFocusGroup.Item,
RadioGroupItemProvider,
{
asChild: true,
...rovingFocusGroupScope,
focusable: !isDisabled,
active: checked,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Radio,
{
disabled: isDisabled,
required: context.required,
checked,
...radioScope,
...itemProps,
name: context.name,
ref: composedRefs,
onCheck: () => context.onValueChange(itemProps.value),
onKeyDown: (0, import_primitive2.composeEventHandlers)((event) => {
if (event.key === "Enter") event.preventDefault();
}),
onFocus: (0, import_primitive2.composeEventHandlers)(itemProps.onFocus, () => {
if (isArrowKeyPressedRef.current) ref.current?.click();
})
}
)
__scopeRadioGroup,
value,
disabled,
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RadioGroupItemTrigger,
{
...itemProps,
ref: forwardedRef,
__scopeRadioGroup
}
),
isFormControl && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RadioGroupItemBubbleInput,
{
__scopeRadioGroup
}
)
] })
}
);
}
);
RadioGroupItem.displayName = ITEM_NAME;
var RadioGroupItemBubbleInput = React2.forwardRef((props, forwardedRef) => {
const { __scopeRadioGroup, ...bubbleProps } = props;
const radioScope = useRadioScope(__scopeRadioGroup);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RadioBubbleInput, { ...radioScope, ...bubbleProps, ref: forwardedRef });
});
RadioGroupItemBubbleInput.displayName = ITEM_BUBBLE_INPUT_NAME;
var INDICATOR_NAME2 = "RadioGroupIndicator";
var RadioGroupIndicator = React2.forwardRef(
(props, forwardedRef) => {
@@ -329,7 +467,4 @@ var RadioGroupIndicator = React2.forwardRef(
}
);
RadioGroupIndicator.displayName = INDICATOR_NAME2;
var Root2 = RadioGroup;
var Item2 = RadioGroupItem;
var Indicator = RadioGroupIndicator;
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
+256 -121
View File
@@ -20,64 +20,118 @@ import { useSize } from "@radix-ui/react-use-size";
import { usePrevious } from "@radix-ui/react-use-previous";
import { Presence } from "@radix-ui/react-presence";
import { Primitive } from "@radix-ui/react-primitive";
import { jsx, jsxs } from "react/jsx-runtime";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
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] = React.useState(null);
const [bubbleInput, setBubbleInput] = React.useState(null);
const hasConsumerStoppedPropagationRef = React.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 /* @__PURE__ */ 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 = React.forwardRef(
({ __scopeRadio, onClick, ...radioProps }, forwardedRef) => {
const {
checked,
disabled,
value,
setControl,
onCheck,
hasConsumerStoppedPropagationRef,
isFormControl,
bubbleInput
} = useRadioContext(TRIGGER_NAME, __scopeRadio);
const composedRefs = useComposedRefs(forwardedRef, setControl);
return /* @__PURE__ */ 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 = React.forwardRef(
(props, forwardedRef) => {
const {
__scopeRadio,
name,
checked = false,
required,
disabled,
value = "on",
onCheck,
form,
...radioProps
} = props;
const [button, setButton] = React.useState(null);
const composedRefs = useComposedRefs(forwardedRef, (node) => setButton(node));
const hasConsumerStoppedPropagationRef = React.useRef(false);
const isFormControl = button ? form || !!button.closest("form") : true;
return /* @__PURE__ */ jsxs(RadioProvider, { scope: __scopeRadio, checked, disabled, children: [
/* @__PURE__ */ 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 /* @__PURE__ */ jsx(
RadioProvider,
{
__scopeRadio,
checked,
disabled,
required,
onCheck,
name,
form,
value,
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(
RadioTrigger,
{
...radioProps,
ref: forwardedRef,
__scopeRadio
}
})
}
),
isFormControl && /* @__PURE__ */ jsx(
RadioBubbleInput,
{
control: button,
bubbles: !hasConsumerStoppedPropagationRef.current,
name,
value,
checked,
required,
disabled,
form,
style: { transform: "translateX(-100%)" }
}
)
] });
),
isFormControl && /* @__PURE__ */ jsx(
RadioBubbleInput,
{
__scopeRadio
}
)
] })
}
);
}
);
Radio.displayName = RADIO_NAME;
@@ -100,19 +154,24 @@ var RadioIndicator = React.forwardRef(
RadioIndicator.displayName = INDICATOR_NAME;
var BUBBLE_INPUT_NAME = "RadioBubbleInput";
var RadioBubbleInput = React.forwardRef(
({
__scopeRadio,
control,
checked,
bubbles = true,
...props
}, forwardedRef) => {
const ref = React.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);
React.useEffect(() => {
const input = ref.current;
const input = bubbleInput;
if (!input) return;
const inputProto = window.HTMLInputElement.prototype;
const descriptor = Object.getOwnPropertyDescriptor(
@@ -120,18 +179,25 @@ var RadioBubbleInput = React.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 = React.useRef(checked);
return /* @__PURE__ */ jsx(
Primitive.input,
{
type: "radio",
"aria-hidden": true,
defaultChecked: checked,
defaultChecked: defaultCheckedRef.current,
required,
disabled,
name,
value,
form,
...props,
tabIndex: -1,
ref: composedRefs,
@@ -141,19 +207,26 @@ var RadioBubbleInput = React.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";
}
// src/radio-group.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
var RADIO_GROUP_NAME = "RadioGroup";
var [createRadioGroupContext, createRadioGroupScope] = createContextScope2(RADIO_GROUP_NAME, [
@@ -223,62 +296,121 @@ var RadioGroup = React2.forwardRef(
);
RadioGroup.displayName = RADIO_GROUP_NAME;
var ITEM_NAME = "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 /* @__PURE__ */ jsx2(
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 = useComposedRefs2(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 /* @__PURE__ */ jsx2(
RovingFocusGroup.Item,
{
asChild: true,
...rovingFocusGroupScope,
focusable: !disabled,
active: checked,
children: /* @__PURE__ */ jsx2(
RadioTrigger,
{
...radioScope,
...triggerProps,
ref: composedRefs,
onKeyDown: composeEventHandlers2(triggerProps.onKeyDown, (event) => {
if (event.key === "Enter") event.preventDefault();
}),
onFocus: composeEventHandlers2(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_NAME, __scopeRadioGroup);
const isDisabled = context.disabled || disabled;
const rovingFocusGroupScope = useRovingFocusGroupScope(__scopeRadioGroup);
const radioScope = useRadioScope(__scopeRadioGroup);
const ref = React2.useRef(null);
const composedRefs = useComposedRefs2(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 /* @__PURE__ */ jsx2(
RovingFocusGroup.Item,
RadioGroupItemProvider,
{
asChild: true,
...rovingFocusGroupScope,
focusable: !isDisabled,
active: checked,
children: /* @__PURE__ */ jsx2(
Radio,
{
disabled: isDisabled,
required: context.required,
checked,
...radioScope,
...itemProps,
name: context.name,
ref: composedRefs,
onCheck: () => context.onValueChange(itemProps.value),
onKeyDown: composeEventHandlers2((event) => {
if (event.key === "Enter") event.preventDefault();
}),
onFocus: composeEventHandlers2(itemProps.onFocus, () => {
if (isArrowKeyPressedRef.current) ref.current?.click();
})
}
)
__scopeRadioGroup,
value,
disabled,
internal_do_not_use_render: ({ isFormControl }) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
/* @__PURE__ */ jsx2(
RadioGroupItemTrigger,
{
...itemProps,
ref: forwardedRef,
__scopeRadioGroup
}
),
isFormControl && /* @__PURE__ */ jsx2(
RadioGroupItemBubbleInput,
{
__scopeRadioGroup
}
)
] })
}
);
}
);
RadioGroupItem.displayName = ITEM_NAME;
var RadioGroupItemBubbleInput = React2.forwardRef((props, forwardedRef) => {
const { __scopeRadioGroup, ...bubbleProps } = props;
const radioScope = useRadioScope(__scopeRadioGroup);
return /* @__PURE__ */ jsx2(RadioBubbleInput, { ...radioScope, ...bubbleProps, ref: forwardedRef });
});
RadioGroupItemBubbleInput.displayName = ITEM_BUBBLE_INPUT_NAME;
var INDICATOR_NAME2 = "RadioGroupIndicator";
var RadioGroupIndicator = React2.forwardRef(
(props, forwardedRef) => {
@@ -288,16 +420,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=index.mjs.map
File diff suppressed because one or more lines are too long
+20 -20
View File
@@ -1,6 +1,6 @@
{
"name": "@radix-ui/react-radio-group",
"version": "1.3.8",
"version": "1.4.0",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
@@ -11,25 +11,23 @@
],
"sideEffects": false,
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-direction": "1.1.1",
"@radix-ui/react-roving-focus": "1.1.11",
"@radix-ui/react-use-controllable-state": "1.2.2",
"@radix-ui/react-use-previous": "1.1.1",
"@radix-ui/react-use-size": "1.1.1"
"@radix-ui/react-compose-refs": "1.1.3",
"@radix-ui/primitive": "1.1.4",
"@radix-ui/react-direction": "1.1.2",
"@radix-ui/react-presence": "1.1.6",
"@radix-ui/react-context": "1.1.4",
"@radix-ui/react-primitive": "2.1.5",
"@radix-ui/react-use-previous": "1.1.2",
"@radix-ui/react-use-size": "1.1.2",
"@radix-ui/react-use-controllable-state": "1.2.3",
"@radix-ui/react-roving-focus": "1.1.12"
},
"devDependencies": {
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"eslint": "^9.18.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"typescript": "^5.7.3",
"@repo/eslint-config": "0.0.0",
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"typescript": "^5.9.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0"
},
@@ -50,14 +48,16 @@
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git"
"url": "git+https://github.com/radix-ui/primitives.git",
"directory": "packages/react/radio-group"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "eslint --max-warnings 0 src",
"lint": "oxlint --max-warnings 0 src",
"clean": "rm -rf dist",
"reset": "rm -rf dist node_modules",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},