@monimesl/dot-renderer-react 0.1.0-alpha.7 → 0.1.0-alpha.9
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/README.md +39 -1
- package/dist/LICENSE-PHOSPHOR +21 -21
- package/dist/_virtual/_rolldown/runtime.js +14 -0
- package/dist/_virtual/builtin_esm-external-require-react.js +9 -0
- package/dist/color.js +105 -0
- package/dist/components/amount-input.d.ts +6 -0
- package/dist/components/amount-input.js +106 -0
- package/dist/components/button.d.ts +6 -0
- package/dist/components/button.js +42 -0
- package/dist/components/carousel.d.ts +6 -0
- package/dist/components/carousel.js +254 -0
- package/dist/components/chip.d.ts +6 -0
- package/dist/components/chip.js +41 -0
- package/dist/components/code-input.d.ts +6 -0
- package/dist/components/code-input.js +97 -0
- package/dist/components/detail-row.d.ts +6 -0
- package/dist/components/detail-row.js +40 -0
- package/dist/components/divider.d.ts +6 -0
- package/dist/components/divider.js +18 -0
- package/dist/components/empty-state.d.ts +6 -0
- package/dist/components/empty-state.js +66 -0
- package/dist/components/feedback.d.ts +8 -0
- package/dist/components/feedback.js +85 -0
- package/dist/components/field-box.js +44 -0
- package/dist/components/field.js +43 -0
- package/dist/components/footer.d.ts +6 -0
- package/dist/components/footer.js +24 -0
- package/dist/components/grid.d.ts +7 -0
- package/dist/components/grid.js +98 -0
- package/dist/components/icon-artwork.js +74 -0
- package/dist/components/icon.d.ts +6 -0
- package/dist/components/icon.js +40 -0
- package/dist/components/image.d.ts +6 -0
- package/dist/components/image.js +40 -0
- package/dist/components/index.d.ts +30 -0
- package/dist/components/index.js +72 -0
- package/dist/components/input.d.ts +6 -0
- package/dist/components/input.js +86 -0
- package/dist/components/link.d.ts +6 -0
- package/dist/components/link.js +39 -0
- package/dist/components/list.d.ts +7 -0
- package/dist/components/list.js +143 -0
- package/dist/components/option-place.js +9 -0
- package/dist/components/option.d.ts +6 -0
- package/dist/components/option.js +43 -0
- package/dist/components/padding.d.ts +2 -0
- package/dist/components/padding.js +27 -0
- package/dist/components/pressable.js +17 -0
- package/dist/components/qr-code.d.ts +6 -0
- package/dist/components/qr-code.js +58 -0
- package/dist/components/scroll.d.ts +6 -0
- package/dist/components/scroll.js +55 -0
- package/dist/components/select.d.ts +6 -0
- package/dist/components/select.js +92 -0
- package/dist/components/sheet.d.ts +8 -0
- package/dist/components/sheet.js +105 -0
- package/dist/components/skeleton.d.ts +6 -0
- package/dist/components/skeleton.js +55 -0
- package/dist/components/spinner.d.ts +6 -0
- package/dist/components/spinner.js +48 -0
- package/dist/components/tabs.d.ts +7 -0
- package/dist/components/tabs.js +91 -0
- package/dist/components/text-area.d.ts +6 -0
- package/dist/components/text-area.js +42 -0
- package/dist/components/text.d.ts +6 -0
- package/dist/components/text.js +46 -0
- package/dist/components/toast.d.ts +6 -0
- package/dist/components/toast.js +56 -0
- package/dist/components/toggles.d.ts +9 -0
- package/dist/components/toggles.js +149 -0
- package/dist/components/tokens.js +37 -0
- package/dist/components/tones.js +24 -0
- package/dist/components/typed-text.js +28 -0
- package/dist/components/view.d.ts +6 -0
- package/dist/components/view.js +51 -0
- package/dist/index.d.ts +35 -64
- package/dist/index.js +32 -22636
- package/dist/page-root.d.ts +2 -0
- package/dist/page-root.js +20 -0
- package/dist/portal.js +8 -0
- package/dist/renderer.d.ts +17 -0
- package/dist/renderer.js +33 -0
- package/dist/root.d.ts +10 -0
- package/dist/root.js +51 -0
- package/dist/styles.css +95 -1
- package/dist/theme.d.ts +25 -0
- package/dist/theme.js +84 -0
- package/dist/types.d.ts +7 -0
- package/dist/vendor/@base-ui/react/checkbox/indicator/CheckboxIndicator.js +51 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRoot.js +265 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/checkbox/root/CheckboxRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/checkbox/utils/getCheckboxStateAttributesMapping.js +15 -0
- package/dist/vendor/@base-ui/react/checkbox-group/CheckboxGroupContext.js +10 -0
- package/dist/vendor/@base-ui/react/dialog/backdrop/DialogBackdrop.js +40 -0
- package/dist/vendor/@base-ui/react/dialog/close/DialogClose.js +39 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopup.js +92 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopupCssVars.js +8 -0
- package/dist/vendor/@base-ui/react/dialog/popup/DialogPopupDataAttributes.js +7 -0
- package/dist/vendor/@base-ui/react/dialog/portal/DialogPortal.js +38 -0
- package/dist/vendor/@base-ui/react/dialog/portal/DialogPortalContext.js +13 -0
- package/dist/vendor/@base-ui/react/dialog/root/DialogRoot.js +16 -0
- package/dist/vendor/@base-ui/react/dialog/root/DialogRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/dialog/root/useDialogRoot.js +77 -0
- package/dist/vendor/@base-ui/react/dialog/root/useRenderDialogRoot.js +65 -0
- package/dist/vendor/@base-ui/react/dialog/store/DialogStore.js +70 -0
- package/dist/vendor/@base-ui/react/dialog/title/DialogTitle.js +25 -0
- package/dist/vendor/@base-ui/react/dialog/utils/stateAttributesMapping.js +17 -0
- package/dist/vendor/@base-ui/react/field/control/FieldControlDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/field/item/FieldItemContext.js +10 -0
- package/dist/vendor/@base-ui/react/field/root/useFieldValidation.js +18 -0
- package/dist/vendor/@base-ui/react/fieldset/root/FieldsetRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingFocusManager.js +477 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingPortal.js +165 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingRootStore.js +65 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/components/FloatingTree.js +22 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/hooks/useDismiss.js +373 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/hooks/useSyncedFloatingRootContext.js +58 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/composite.js +40 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/constants.js +5 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/createAttribute.js +6 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/createEventEmitter.js +18 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/element.js +26 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/enqueueFocus.js +25 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/event.js +25 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/markOthers.js +116 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/nodes.js +16 -0
- package/dist/vendor/@base-ui/react/floating-ui-react/utils/tabbable.js +135 -0
- package/dist/vendor/@base-ui/react/internals/TransitionStatusDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/internals/composite/composite.js +89 -0
- package/dist/vendor/@base-ui/react/internals/composite/constants.js +4 -0
- package/dist/vendor/@base-ui/react/internals/composite/item/CompositeItem.js +21 -0
- package/dist/vendor/@base-ui/react/internals/composite/item/useCompositeItem.js +31 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/CompositeList.js +180 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/CompositeListContext.js +15 -0
- package/dist/vendor/@base-ui/react/internals/composite/list/useCompositeListItem.js +54 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/CompositeRoot.js +62 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/CompositeRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/internals/composite/root/useCompositeRoot.js +170 -0
- package/dist/vendor/@base-ui/react/internals/constants.js +18 -0
- package/dist/vendor/@base-ui/react/internals/createBaseUIEventDetails.js +40 -0
- package/dist/vendor/@base-ui/react/internals/direction-context/DirectionContext.js +10 -0
- package/dist/vendor/@base-ui/react/internals/field-constants/constants.js +33 -0
- package/dist/vendor/@base-ui/react/internals/field-register-control/useRegisterFieldControl.js +40 -0
- package/dist/vendor/@base-ui/react/internals/field-root-context/FieldRootContext.js +45 -0
- package/dist/vendor/@base-ui/react/internals/form-context/FormContext.js +18 -0
- package/dist/vendor/@base-ui/react/internals/getStateAttributesProps.js +17 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/LabelableContext.js +24 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/useAriaLabelledBy.js +35 -0
- package/dist/vendor/@base-ui/react/internals/labelable-provider/useLabelableId.js +57 -0
- package/dist/vendor/@base-ui/react/internals/reason-parts.js +14 -0
- package/dist/vendor/@base-ui/react/internals/serializeValue.js +12 -0
- package/dist/vendor/@base-ui/react/internals/stateAttributesMapping.js +11 -0
- package/dist/vendor/@base-ui/react/internals/use-button/useButton.js +137 -0
- package/dist/vendor/@base-ui/react/internals/useAnimationsFinished.js +94 -0
- package/dist/vendor/@base-ui/react/internals/useBaseUiId.js +13 -0
- package/dist/vendor/@base-ui/react/internals/useOpenChangeComplete.js +28 -0
- package/dist/vendor/@base-ui/react/internals/useRenderElement.js +109 -0
- package/dist/vendor/@base-ui/react/internals/useTransitionStatus.js +70 -0
- package/dist/vendor/@base-ui/react/internals/useValueChanged.js +15 -0
- package/dist/vendor/@base-ui/react/merge-props/mergeProps.js +153 -0
- package/dist/vendor/@base-ui/react/radio/indicator/RadioIndicator.js +46 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRoot.js +179 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/radio/root/RadioRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/radio/utils/stateAttributesMapping.js +14 -0
- package/dist/vendor/@base-ui/react/radio-group/RadioGroup.js +170 -0
- package/dist/vendor/@base-ui/react/radio-group/RadioGroupContext.js +10 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRoot.js +170 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRootContext.js +13 -0
- package/dist/vendor/@base-ui/react/switch/root/SwitchRootDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/switch/stateAttributesMapping.js +12 -0
- package/dist/vendor/@base-ui/react/switch/thumb/SwitchThumb.js +25 -0
- package/dist/vendor/@base-ui/react/tabs/list/TabsList.js +98 -0
- package/dist/vendor/@base-ui/react/tabs/list/TabsListContext.js +13 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRoot.js +213 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRootContext.js +16 -0
- package/dist/vendor/@base-ui/react/tabs/root/TabsRootDataAttributes.js +8 -0
- package/dist/vendor/@base-ui/react/tabs/root/stateAttributesMapping.js +5 -0
- package/dist/vendor/@base-ui/react/tabs/tab/TabsTab.js +137 -0
- package/dist/vendor/@base-ui/react/utils/CommonPopupDataAttributes.js +24 -0
- package/dist/vendor/@base-ui/react/utils/CommonTriggerDataAttributes.js +11 -0
- package/dist/vendor/@base-ui/react/utils/FocusGuard.js +32 -0
- package/dist/vendor/@base-ui/react/utils/InternalBackdrop.js +30 -0
- package/dist/vendor/@base-ui/react/utils/dispatchClickWithModifiers.js +25 -0
- package/dist/vendor/@base-ui/react/utils/popupStateMapping.js +22 -0
- package/dist/vendor/@base-ui/react/utils/popups/popupStoreUtils.js +247 -0
- package/dist/vendor/@base-ui/react/utils/popups/popupTriggerMap.js +96 -0
- package/dist/vendor/@base-ui/react/utils/popups/store.js +94 -0
- package/dist/vendor/@base-ui/react/utils/resolveClassName.js +13 -0
- package/dist/vendor/@base-ui/react/utils/resolveRef.js +11 -0
- package/dist/vendor/@base-ui/react/utils/resolveStyle.js +13 -0
- package/dist/vendor/@base-ui/react/utils/useFocusableWhenDisabled.js +30 -0
- package/dist/vendor/@base-ui/utils/addEventListener.js +12 -0
- package/dist/vendor/@base-ui/utils/createLogOnce.js +20 -0
- package/dist/vendor/@base-ui/utils/empty.js +6 -0
- package/dist/vendor/@base-ui/utils/error.js +5 -0
- package/dist/vendor/@base-ui/utils/fastHooks.js +68 -0
- package/dist/vendor/@base-ui/utils/formatErrorMessage.js +27 -0
- package/dist/vendor/@base-ui/utils/getDefaultFormSubmitter.js +25 -0
- package/dist/vendor/@base-ui/utils/getReactElementRef.js +14 -0
- package/dist/vendor/@base-ui/utils/inertValue.js +8 -0
- package/dist/vendor/@base-ui/utils/isElementDisabled.js +6 -0
- package/dist/vendor/@base-ui/utils/mergeCleanups.js +14 -0
- package/dist/vendor/@base-ui/utils/mergeObjects.js +11 -0
- package/dist/vendor/@base-ui/utils/owner.js +7 -0
- package/dist/vendor/@base-ui/utils/platform/engine.js +8 -0
- package/dist/vendor/@base-ui/utils/platform/env.js +6 -0
- package/dist/vendor/@base-ui/utils/platform/os.js +15 -0
- package/dist/vendor/@base-ui/utils/platform/screen-reader.js +9 -0
- package/dist/vendor/@base-ui/utils/platform/shared.js +36 -0
- package/dist/vendor/@base-ui/utils/reactVersion.js +8 -0
- package/dist/vendor/@base-ui/utils/safeReact.js +13 -0
- package/dist/vendor/@base-ui/utils/shadowDom.js +26 -0
- package/dist/vendor/@base-ui/utils/store/ReactStore.js +181 -0
- package/dist/vendor/@base-ui/utils/store/Store.js +102 -0
- package/dist/vendor/@base-ui/utils/store/useStore.js +97 -0
- package/dist/vendor/@base-ui/utils/useAnimationFrame.js +87 -0
- package/dist/vendor/@base-ui/utils/useControlled.js +52 -0
- package/dist/vendor/@base-ui/utils/useId.js +32 -0
- package/dist/vendor/@base-ui/utils/useIsoLayoutEffect.js +7 -0
- package/dist/vendor/@base-ui/utils/useMergedRefs.js +87 -0
- package/dist/vendor/@base-ui/utils/useOnMount.js +12 -0
- package/dist/vendor/@base-ui/utils/useRefWithInit.js +18 -0
- package/dist/vendor/@base-ui/utils/useScrollLock.js +206 -0
- package/dist/vendor/@base-ui/utils/useStableCallback.js +38 -0
- package/dist/vendor/@base-ui/utils/useTimeout.js +43 -0
- package/dist/vendor/@base-ui/utils/useValueAsRef.js +27 -0
- package/dist/vendor/@base-ui/utils/visuallyHidden.js +23 -0
- package/dist/vendor/@base-ui/utils/warn.js +5 -0
- package/dist/vendor/@floating-ui/utils/dist/floating-ui.utils.dom.js +49 -0
- package/dist/vendor/uqr/dist/index.js +858 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js +74 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js +77 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +69 -0
- package/dist/vendor/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +64 -0
- package/dist/vendor/use-sync-external-store/shim/index.js +11 -0
- package/dist/vendor/use-sync-external-store/shim/with-selector.js +11 -0
- package/package.json +8 -14
- package/dist/garra-versions.json +0 -7
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useRenderElement } from "../../internals/useRenderElement.js";
|
|
3
|
+
import { useTransitionStatus } from "../../internals/useTransitionStatus.js";
|
|
4
|
+
import { useOpenChangeComplete } from "../../internals/useOpenChangeComplete.js";
|
|
5
|
+
import { stateAttributesMapping } from "../utils/stateAttributesMapping.js";
|
|
6
|
+
import { useRadioRootContext } from "../root/RadioRootContext.js";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio/indicator/RadioIndicator.mjs
|
|
9
|
+
/**
|
|
10
|
+
* Indicates whether the radio button is selected.
|
|
11
|
+
* Renders a `<span>` element.
|
|
12
|
+
*
|
|
13
|
+
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio)
|
|
14
|
+
*/
|
|
15
|
+
const RadioIndicator = /*#__PURE__*/ React.forwardRef(function RadioIndicator(componentProps, forwardedRef) {
|
|
16
|
+
const { render, className, style, keepMounted = false, ...elementProps } = componentProps;
|
|
17
|
+
const rootState = useRadioRootContext();
|
|
18
|
+
const rendered = rootState.checked;
|
|
19
|
+
const { mounted, transitionStatus, setMounted } = useTransitionStatus(rendered);
|
|
20
|
+
const state = {
|
|
21
|
+
...rootState,
|
|
22
|
+
transitionStatus
|
|
23
|
+
};
|
|
24
|
+
const indicatorRef = React.useRef(null);
|
|
25
|
+
const shouldRender = keepMounted || mounted;
|
|
26
|
+
const element = useRenderElement("span", componentProps, {
|
|
27
|
+
ref: [forwardedRef, indicatorRef],
|
|
28
|
+
state,
|
|
29
|
+
props: elementProps,
|
|
30
|
+
stateAttributesMapping
|
|
31
|
+
});
|
|
32
|
+
useOpenChangeComplete({
|
|
33
|
+
batch: true,
|
|
34
|
+
enabled: !rendered,
|
|
35
|
+
open: rendered,
|
|
36
|
+
ref: indicatorRef,
|
|
37
|
+
onComplete() {
|
|
38
|
+
if (!rendered) setMounted(false);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (!shouldRender) return null;
|
|
42
|
+
return element;
|
|
43
|
+
});
|
|
44
|
+
if (process.env.NODE_ENV !== "production") RadioIndicator.displayName = "RadioIndicator";
|
|
45
|
+
//#endregion
|
|
46
|
+
export { RadioIndicator };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMergedRefs } from "../../../utils/useMergedRefs.js";
|
|
3
|
+
import { EMPTY_OBJECT, NOOP } from "../../../utils/empty.js";
|
|
4
|
+
import { useRenderElement } from "../../internals/useRenderElement.js";
|
|
5
|
+
import { useIsoLayoutEffect } from "../../../utils/useIsoLayoutEffect.js";
|
|
6
|
+
import { dispatchClickWithModifiers } from "../../utils/dispatchClickWithModifiers.js";
|
|
7
|
+
import { useButton } from "../../internals/use-button/useButton.js";
|
|
8
|
+
import { none } from "../../internals/reason-parts.js";
|
|
9
|
+
import { createChangeEventDetails } from "../../internals/createBaseUIEventDetails.js";
|
|
10
|
+
import { useBaseUiId } from "../../internals/useBaseUiId.js";
|
|
11
|
+
import { visuallyHidden, visuallyHiddenInput } from "../../../utils/visuallyHidden.js";
|
|
12
|
+
import { ACTIVE_COMPOSITE_ITEM } from "../../internals/composite/constants.js";
|
|
13
|
+
import { useFieldRootContext } from "../../internals/field-root-context/FieldRootContext.js";
|
|
14
|
+
import { useFieldItemContext } from "../../field/item/FieldItemContext.js";
|
|
15
|
+
import { useLabelableContext } from "../../internals/labelable-provider/LabelableContext.js";
|
|
16
|
+
import { useAriaLabelledBy } from "../../internals/labelable-provider/useAriaLabelledBy.js";
|
|
17
|
+
import { useLabelableId } from "../../internals/labelable-provider/useLabelableId.js";
|
|
18
|
+
import { stateAttributesMapping } from "../utils/stateAttributesMapping.js";
|
|
19
|
+
import { CompositeItem } from "../../internals/composite/item/CompositeItem.js";
|
|
20
|
+
import { useRadioGroupContext } from "../../radio-group/RadioGroupContext.js";
|
|
21
|
+
import { serializeValue } from "../../internals/serializeValue.js";
|
|
22
|
+
import { RadioRootContext } from "./RadioRootContext.js";
|
|
23
|
+
import * as React from "react";
|
|
24
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
25
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio/root/RadioRoot.mjs
|
|
26
|
+
/**
|
|
27
|
+
* Represents the radio button itself.
|
|
28
|
+
* Renders a `<span>` element and a hidden `<input>` beside.
|
|
29
|
+
*
|
|
30
|
+
* Documentation: [Base UI Radio](https://base-ui.com/react/components/radio)
|
|
31
|
+
*/
|
|
32
|
+
const RadioRoot = /*#__PURE__*/ React.forwardRef(function RadioRoot(componentProps, forwardedRef) {
|
|
33
|
+
const { render, className, disabled: disabledProp = false, readOnly: readOnlyProp = false, required: requiredProp = false, "aria-labelledby": ariaLabelledByProp, value, inputRef: inputRefProp, nativeButton = false, id: idProp, style, ...elementProps } = componentProps;
|
|
34
|
+
const groupContext = useRadioGroupContext();
|
|
35
|
+
const { disabled: disabledGroup, readOnly: readOnlyGroup, required: requiredGroup, form: formGroup, checkedValue, touched = false, validation, name, setCheckedValue = NOOP, setTouched = NOOP, registerInputRef = NOOP } = groupContext ?? {};
|
|
36
|
+
const { setTouched: setFieldTouched, setFilled, state: fieldState, disabled: fieldDisabled } = useFieldRootContext();
|
|
37
|
+
const fieldItemContext = useFieldItemContext();
|
|
38
|
+
const { labelId, getDescriptionProps } = useLabelableContext();
|
|
39
|
+
const disabled = fieldDisabled || fieldItemContext.disabled || disabledGroup || disabledProp;
|
|
40
|
+
const readOnly = readOnlyGroup || readOnlyProp;
|
|
41
|
+
const required = requiredGroup || requiredProp;
|
|
42
|
+
const form = formGroup;
|
|
43
|
+
const checked = groupContext ? checkedValue === value : value === "";
|
|
44
|
+
const radioRef = React.useRef(null);
|
|
45
|
+
const inputRef = React.useRef(null);
|
|
46
|
+
const registerFieldInput = validation?.registerInput;
|
|
47
|
+
const registerInput = React.useCallback((element) => registerFieldInput?.(element, {
|
|
48
|
+
controlRef: radioRef,
|
|
49
|
+
value: void 0
|
|
50
|
+
}), [registerFieldInput]);
|
|
51
|
+
const mergedInputRef = useMergedRefs(inputRefProp, inputRef, registerInputRef, registerInput);
|
|
52
|
+
useIsoLayoutEffect(() => {
|
|
53
|
+
if (inputRef.current?.checked) setFilled(true);
|
|
54
|
+
}, [setFilled]);
|
|
55
|
+
useIsoLayoutEffect(() => {
|
|
56
|
+
if (!inputRef.current) return;
|
|
57
|
+
if (disabled && checked) {
|
|
58
|
+
registerInputRef(null);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
registerInputRef(inputRef.current);
|
|
62
|
+
}, [
|
|
63
|
+
checked,
|
|
64
|
+
disabled,
|
|
65
|
+
registerInputRef
|
|
66
|
+
]);
|
|
67
|
+
const id = useBaseUiId();
|
|
68
|
+
const inputId = useLabelableId({ id: idProp });
|
|
69
|
+
const hiddenInputId = nativeButton ? void 0 : inputId;
|
|
70
|
+
const rootProps = {
|
|
71
|
+
role: "radio",
|
|
72
|
+
"aria-checked": checked,
|
|
73
|
+
"aria-labelledby": useAriaLabelledBy(ariaLabelledByProp, labelId, inputRef, !nativeButton, hiddenInputId),
|
|
74
|
+
[ACTIVE_COMPOSITE_ITEM]: checked ? "" : void 0,
|
|
75
|
+
id: nativeButton ? inputId : id,
|
|
76
|
+
onKeyDown(event) {
|
|
77
|
+
if (event.key === "Enter") event.preventDefault();
|
|
78
|
+
},
|
|
79
|
+
onClick(event) {
|
|
80
|
+
if (event.defaultPrevented || disabled || readOnly) return;
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
const input = inputRef.current;
|
|
83
|
+
if (!input) return;
|
|
84
|
+
dispatchClickWithModifiers(input, event);
|
|
85
|
+
},
|
|
86
|
+
onFocus(event) {
|
|
87
|
+
if (event.defaultPrevented || disabled || readOnly || !touched) return;
|
|
88
|
+
inputRef.current?.click();
|
|
89
|
+
setTouched(false);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const { getButtonProps, buttonRef } = useButton({
|
|
93
|
+
disabled,
|
|
94
|
+
native: nativeButton,
|
|
95
|
+
composite: false
|
|
96
|
+
});
|
|
97
|
+
const inputProps = {
|
|
98
|
+
type: "radio",
|
|
99
|
+
ref: mergedInputRef,
|
|
100
|
+
form,
|
|
101
|
+
id: hiddenInputId,
|
|
102
|
+
name,
|
|
103
|
+
tabIndex: -1,
|
|
104
|
+
style: name ? visuallyHiddenInput : visuallyHidden,
|
|
105
|
+
"aria-hidden": true,
|
|
106
|
+
...value !== void 0 ? { value: serializeValue(value) } : EMPTY_OBJECT,
|
|
107
|
+
disabled,
|
|
108
|
+
checked,
|
|
109
|
+
required,
|
|
110
|
+
readOnly,
|
|
111
|
+
onChange(event) {
|
|
112
|
+
if (event.nativeEvent.defaultPrevented) return;
|
|
113
|
+
if (disabled || readOnly || value === void 0) return;
|
|
114
|
+
const details = createChangeEventDetails(none, event.nativeEvent);
|
|
115
|
+
setCheckedValue(value, details);
|
|
116
|
+
if (details.isCanceled) return;
|
|
117
|
+
setFieldTouched(true);
|
|
118
|
+
},
|
|
119
|
+
onClick(event) {
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
},
|
|
122
|
+
onFocus() {
|
|
123
|
+
radioRef.current?.focus();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const state = React.useMemo(() => ({
|
|
127
|
+
...fieldState,
|
|
128
|
+
required,
|
|
129
|
+
disabled,
|
|
130
|
+
readOnly,
|
|
131
|
+
checked
|
|
132
|
+
}), [
|
|
133
|
+
fieldState,
|
|
134
|
+
disabled,
|
|
135
|
+
readOnly,
|
|
136
|
+
checked,
|
|
137
|
+
required
|
|
138
|
+
]);
|
|
139
|
+
const contextValue = state;
|
|
140
|
+
const isRadioGroup = groupContext !== void 0;
|
|
141
|
+
const refs = [
|
|
142
|
+
forwardedRef,
|
|
143
|
+
radioRef,
|
|
144
|
+
buttonRef
|
|
145
|
+
];
|
|
146
|
+
const props = [
|
|
147
|
+
rootProps,
|
|
148
|
+
elementProps,
|
|
149
|
+
getButtonProps,
|
|
150
|
+
getDescriptionProps,
|
|
151
|
+
validation ? (validationProps) => validation.getValidationProps(disabled, validationProps) : EMPTY_OBJECT
|
|
152
|
+
];
|
|
153
|
+
const element = useRenderElement("span", componentProps, {
|
|
154
|
+
enabled: !isRadioGroup,
|
|
155
|
+
state,
|
|
156
|
+
ref: refs,
|
|
157
|
+
props,
|
|
158
|
+
stateAttributesMapping
|
|
159
|
+
});
|
|
160
|
+
return /*#__PURE__*/ jsxs(RadioRootContext.Provider, {
|
|
161
|
+
value: contextValue,
|
|
162
|
+
children: [isRadioGroup ? /*#__PURE__*/ jsx(CompositeItem, {
|
|
163
|
+
tag: "span",
|
|
164
|
+
render,
|
|
165
|
+
className,
|
|
166
|
+
style,
|
|
167
|
+
state,
|
|
168
|
+
refs,
|
|
169
|
+
props,
|
|
170
|
+
stateAttributesMapping
|
|
171
|
+
}) : element, /*#__PURE__*/ jsx("input", {
|
|
172
|
+
...inputProps,
|
|
173
|
+
suppressHydrationWarning: true
|
|
174
|
+
})]
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
if (process.env.NODE_ENV !== "production") RadioRoot.displayName = "RadioRoot";
|
|
178
|
+
//#endregion
|
|
179
|
+
export { RadioRoot };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import formatErrorMessage from "../../../utils/formatErrorMessage.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio/root/RadioRootContext.mjs
|
|
5
|
+
const RadioRootContext = /*#__PURE__*/ React.createContext(void 0);
|
|
6
|
+
if (process.env.NODE_ENV !== "production") RadioRootContext.displayName = "RadioRootContext";
|
|
7
|
+
function useRadioRootContext() {
|
|
8
|
+
const value = React.useContext(RadioRootContext);
|
|
9
|
+
if (value === void 0) throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: RadioRootContext is missing. Radio parts must be placed within <Radio.Root>." : formatErrorMessage(52));
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { RadioRootContext, useRadioRootContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio/root/RadioRootDataAttributes.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Present when the radio is checked.
|
|
4
|
+
*/
|
|
5
|
+
const checked = "data-checked";
|
|
6
|
+
/**
|
|
7
|
+
* Present when the radio is not checked.
|
|
8
|
+
*/
|
|
9
|
+
const unchecked = "data-unchecked";
|
|
10
|
+
//#endregion
|
|
11
|
+
export { checked, unchecked };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { transitionStatusMapping } from "../../internals/stateAttributesMapping.js";
|
|
2
|
+
import { fieldValidityMapping } from "../../internals/field-constants/constants.js";
|
|
3
|
+
import { checked, unchecked } from "../root/RadioRootDataAttributes.js";
|
|
4
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio/utils/stateAttributesMapping.mjs
|
|
5
|
+
const stateAttributesMapping = {
|
|
6
|
+
checked(value) {
|
|
7
|
+
if (value) return { [checked]: "" };
|
|
8
|
+
return { [unchecked]: "" };
|
|
9
|
+
},
|
|
10
|
+
...transitionStatusMapping,
|
|
11
|
+
...fieldValidityMapping
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { stateAttributesMapping };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useStableCallback } from "../../utils/useStableCallback.js";
|
|
3
|
+
import { useBaseUiId } from "../internals/useBaseUiId.js";
|
|
4
|
+
import { contains } from "../../utils/shadowDom.js";
|
|
5
|
+
import { SHIFT } from "../internals/composite/composite.js";
|
|
6
|
+
import { useValueChanged } from "../internals/useValueChanged.js";
|
|
7
|
+
import { useControlled } from "../../utils/useControlled.js";
|
|
8
|
+
import { CompositeRoot } from "../internals/composite/root/CompositeRoot.js";
|
|
9
|
+
import { fieldValidityMapping } from "../internals/field-constants/constants.js";
|
|
10
|
+
import { useFieldRootContext } from "../internals/field-root-context/FieldRootContext.js";
|
|
11
|
+
import { useRegisterFieldControl } from "../internals/field-register-control/useRegisterFieldControl.js";
|
|
12
|
+
import { useFormContext } from "../internals/form-context/FormContext.js";
|
|
13
|
+
import { useLabelableContext } from "../internals/labelable-provider/LabelableContext.js";
|
|
14
|
+
import { RadioGroupContext } from "./RadioGroupContext.js";
|
|
15
|
+
import { isEligibleInput } from "../field/root/useFieldValidation.js";
|
|
16
|
+
import { useFieldsetRootContext } from "../fieldset/root/FieldsetRootContext.js";
|
|
17
|
+
import * as React from "react";
|
|
18
|
+
import { jsx } from "react/jsx-runtime";
|
|
19
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio-group/RadioGroup.mjs
|
|
20
|
+
const MODIFIER_KEYS = [SHIFT];
|
|
21
|
+
/**
|
|
22
|
+
* Provides a shared state to a series of radio buttons.
|
|
23
|
+
* Renders a `<div>` element.
|
|
24
|
+
*
|
|
25
|
+
* Documentation: [Base UI Radio Group](https://base-ui.com/react/components/radio)
|
|
26
|
+
*/
|
|
27
|
+
const RadioGroup = /*#__PURE__*/ React.forwardRef(function RadioGroup(componentProps, forwardedRef) {
|
|
28
|
+
const { render, className, disabled: disabledProp, readOnly, required, onValueChange: onValueChangeProp, value: externalValue, defaultValue, form, name: nameProp, inputRef: inputRefProp, id: idProp, style, ...elementProps } = componentProps;
|
|
29
|
+
const { setTouched: setFieldTouched, setFocused, validationMode, name: fieldName, disabled: fieldDisabled, state: fieldState, validation, setDirty, setFilled, validityData } = useFieldRootContext();
|
|
30
|
+
const { labelId } = useLabelableContext();
|
|
31
|
+
const { clearErrors, elementRef } = useFormContext();
|
|
32
|
+
const fieldsetContext = useFieldsetRootContext(true);
|
|
33
|
+
const disabled = fieldDisabled || disabledProp;
|
|
34
|
+
const name = fieldName ?? nameProp;
|
|
35
|
+
const id = useBaseUiId(idProp);
|
|
36
|
+
const [checkedValue, setCheckedValueUnwrapped] = useControlled({
|
|
37
|
+
controlled: externalValue,
|
|
38
|
+
default: defaultValue,
|
|
39
|
+
name: "RadioGroup",
|
|
40
|
+
state: "value"
|
|
41
|
+
});
|
|
42
|
+
const [touched, setTouched] = React.useState(false);
|
|
43
|
+
const setCheckedValue = useStableCallback((value, eventDetails) => {
|
|
44
|
+
onValueChangeProp?.(value, eventDetails);
|
|
45
|
+
if (eventDetails.isCanceled) return;
|
|
46
|
+
setCheckedValueUnwrapped(value);
|
|
47
|
+
});
|
|
48
|
+
const getInputControl = validation.getInputControl;
|
|
49
|
+
const controlRef = React.useMemo(() => ({ get current() {
|
|
50
|
+
return getInputControl();
|
|
51
|
+
} }), [getInputControl]);
|
|
52
|
+
const groupInputRef = React.useRef(null);
|
|
53
|
+
const firstEnabledInputRef = React.useRef(null);
|
|
54
|
+
function setInputRef(hiddenInput) {
|
|
55
|
+
let cleanup = void 0;
|
|
56
|
+
if (inputRefProp) {
|
|
57
|
+
if (typeof inputRefProp === "function") cleanup = inputRefProp(hiddenInput);
|
|
58
|
+
else inputRefProp.current = hiddenInput;
|
|
59
|
+
}
|
|
60
|
+
groupInputRef.current = hiddenInput;
|
|
61
|
+
return cleanup;
|
|
62
|
+
}
|
|
63
|
+
const registerInputRef = useStableCallback((input) => {
|
|
64
|
+
if (!input || input.disabled) return;
|
|
65
|
+
if (!firstEnabledInputRef.current) firstEnabledInputRef.current = input;
|
|
66
|
+
const currentInput = groupInputRef.current;
|
|
67
|
+
const cleanup = input.checked || currentInput == null || currentInput.disabled ? setInputRef(input) : void 0;
|
|
68
|
+
return () => {
|
|
69
|
+
if (firstEnabledInputRef.current === input) firstEnabledInputRef.current = null;
|
|
70
|
+
if (groupInputRef.current === input) {
|
|
71
|
+
if (cleanup) {
|
|
72
|
+
cleanup();
|
|
73
|
+
groupInputRef.current = null;
|
|
74
|
+
} else setInputRef(null);
|
|
75
|
+
} else cleanup?.();
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const getFormValue = useStableCallback(() => {
|
|
79
|
+
const formElement = elementRef.current;
|
|
80
|
+
if (!formElement) return checkedValue ?? null;
|
|
81
|
+
for (const input of validation.registeredInputs.keys()) if (input.checked && isEligibleInput(input, formElement)) return checkedValue ?? null;
|
|
82
|
+
return null;
|
|
83
|
+
});
|
|
84
|
+
useRegisterFieldControl(controlRef, id, checkedValue ?? null, getFormValue, !disabled, nameProp);
|
|
85
|
+
useValueChanged(checkedValue, () => {
|
|
86
|
+
clearErrors(name);
|
|
87
|
+
setDirty(checkedValue !== validityData.initialValue);
|
|
88
|
+
setFilled(checkedValue != null);
|
|
89
|
+
validation.change(checkedValue);
|
|
90
|
+
const fallbackInput = firstEnabledInputRef.current;
|
|
91
|
+
if (checkedValue == null && fallbackInput && !fallbackInput.disabled) setInputRef(fallbackInput);
|
|
92
|
+
});
|
|
93
|
+
const ariaLabelledby = labelId ?? fieldsetContext?.legendId;
|
|
94
|
+
const state = {
|
|
95
|
+
...fieldState,
|
|
96
|
+
disabled: disabled ?? false,
|
|
97
|
+
required: required ?? false,
|
|
98
|
+
readOnly: readOnly ?? false
|
|
99
|
+
};
|
|
100
|
+
const contextValue = React.useMemo(() => ({
|
|
101
|
+
checkedValue,
|
|
102
|
+
disabled,
|
|
103
|
+
form,
|
|
104
|
+
validation,
|
|
105
|
+
name,
|
|
106
|
+
readOnly,
|
|
107
|
+
registerInputRef,
|
|
108
|
+
required,
|
|
109
|
+
setCheckedValue,
|
|
110
|
+
setTouched,
|
|
111
|
+
touched
|
|
112
|
+
}), [
|
|
113
|
+
checkedValue,
|
|
114
|
+
disabled,
|
|
115
|
+
form,
|
|
116
|
+
validation,
|
|
117
|
+
name,
|
|
118
|
+
readOnly,
|
|
119
|
+
registerInputRef,
|
|
120
|
+
required,
|
|
121
|
+
setCheckedValue,
|
|
122
|
+
setTouched,
|
|
123
|
+
touched
|
|
124
|
+
]);
|
|
125
|
+
const defaultProps = {
|
|
126
|
+
id: idProp,
|
|
127
|
+
role: "radiogroup",
|
|
128
|
+
"aria-required": required || void 0,
|
|
129
|
+
"aria-disabled": disabled || void 0,
|
|
130
|
+
"aria-readonly": readOnly || void 0,
|
|
131
|
+
"aria-labelledby": ariaLabelledby,
|
|
132
|
+
onFocus() {
|
|
133
|
+
setFocused(true);
|
|
134
|
+
},
|
|
135
|
+
onBlur(event) {
|
|
136
|
+
if (!contains(event.currentTarget, event.relatedTarget)) {
|
|
137
|
+
setFieldTouched(true);
|
|
138
|
+
setFocused(false);
|
|
139
|
+
if (validationMode === "onBlur") validation.commit(checkedValue);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
onKeyDownCapture(event) {
|
|
143
|
+
if (event.key.startsWith("Arrow")) {
|
|
144
|
+
setTouched(true);
|
|
145
|
+
setFocused(true);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return /*#__PURE__*/ jsx(RadioGroupContext.Provider, {
|
|
150
|
+
value: contextValue,
|
|
151
|
+
children: /*#__PURE__*/ jsx(CompositeRoot, {
|
|
152
|
+
render,
|
|
153
|
+
className,
|
|
154
|
+
style,
|
|
155
|
+
state,
|
|
156
|
+
props: [
|
|
157
|
+
defaultProps,
|
|
158
|
+
elementProps,
|
|
159
|
+
(props) => validation.getValidationProps(disabled ?? false, props)
|
|
160
|
+
],
|
|
161
|
+
refs: [forwardedRef],
|
|
162
|
+
stateAttributesMapping: fieldValidityMapping,
|
|
163
|
+
enableHomeAndEndKeys: false,
|
|
164
|
+
modifierKeys: MODIFIER_KEYS
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
if (process.env.NODE_ENV !== "production") RadioGroup.displayName = "RadioGroup";
|
|
169
|
+
//#endregion
|
|
170
|
+
export { RadioGroup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/radio-group/RadioGroupContext.mjs
|
|
4
|
+
const RadioGroupContext = /*#__PURE__*/ React.createContext(void 0);
|
|
5
|
+
if (process.env.NODE_ENV !== "production") RadioGroupContext.displayName = "RadioGroupContext";
|
|
6
|
+
function useRadioGroupContext() {
|
|
7
|
+
return React.useContext(RadioGroupContext);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { RadioGroupContext, useRadioGroupContext };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMergedRefs } from "../../../utils/useMergedRefs.js";
|
|
3
|
+
import { EMPTY_OBJECT } from "../../../utils/empty.js";
|
|
4
|
+
import { useRenderElement } from "../../internals/useRenderElement.js";
|
|
5
|
+
import { useIsoLayoutEffect } from "../../../utils/useIsoLayoutEffect.js";
|
|
6
|
+
import { dispatchClickWithModifiers } from "../../utils/dispatchClickWithModifiers.js";
|
|
7
|
+
import { useButton } from "../../internals/use-button/useButton.js";
|
|
8
|
+
import { none } from "../../internals/reason-parts.js";
|
|
9
|
+
import { createChangeEventDetails } from "../../internals/createBaseUIEventDetails.js";
|
|
10
|
+
import { useBaseUiId } from "../../internals/useBaseUiId.js";
|
|
11
|
+
import { visuallyHidden, visuallyHiddenInput } from "../../../utils/visuallyHidden.js";
|
|
12
|
+
import { useValueChanged } from "../../internals/useValueChanged.js";
|
|
13
|
+
import { useControlled } from "../../../utils/useControlled.js";
|
|
14
|
+
import { useFieldRootContext } from "../../internals/field-root-context/FieldRootContext.js";
|
|
15
|
+
import { useRegisterFieldControl } from "../../internals/field-register-control/useRegisterFieldControl.js";
|
|
16
|
+
import { useFormContext } from "../../internals/form-context/FormContext.js";
|
|
17
|
+
import { useLabelableContext } from "../../internals/labelable-provider/LabelableContext.js";
|
|
18
|
+
import { useAriaLabelledBy } from "../../internals/labelable-provider/useAriaLabelledBy.js";
|
|
19
|
+
import { useLabelableId } from "../../internals/labelable-provider/useLabelableId.js";
|
|
20
|
+
import { SwitchRootContext } from "./SwitchRootContext.js";
|
|
21
|
+
import { stateAttributesMapping } from "../stateAttributesMapping.js";
|
|
22
|
+
import * as React from "react";
|
|
23
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
24
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/switch/root/SwitchRoot.mjs
|
|
25
|
+
/**
|
|
26
|
+
* Represents the switch itself.
|
|
27
|
+
* Renders a `<span>` element and a hidden `<input>` beside.
|
|
28
|
+
*
|
|
29
|
+
* Documentation: [Base UI Switch](https://base-ui.com/react/components/switch)
|
|
30
|
+
*/
|
|
31
|
+
const SwitchRoot = /*#__PURE__*/ React.forwardRef(function SwitchRoot(componentProps, forwardedRef) {
|
|
32
|
+
const { checked: checkedProp, className, defaultChecked, "aria-labelledby": ariaLabelledByProp, form, id: idProp, inputRef: externalInputRef, name: nameProp, nativeButton = false, onCheckedChange, readOnly = false, required = false, disabled: disabledProp = false, render, uncheckedValue, value, style, ...elementProps } = componentProps;
|
|
33
|
+
const { clearErrors } = useFormContext();
|
|
34
|
+
const { state: fieldState, setTouched, setDirty, validityData, setFilled, setFocused, validationMode, disabled: fieldDisabled, name: fieldName, validation } = useFieldRootContext();
|
|
35
|
+
const { labelId } = useLabelableContext();
|
|
36
|
+
const disabled = fieldDisabled || disabledProp;
|
|
37
|
+
const name = fieldName ?? nameProp;
|
|
38
|
+
const inputRef = React.useRef(null);
|
|
39
|
+
const handleInputRef = useMergedRefs(inputRef, externalInputRef, validation.inputRef);
|
|
40
|
+
const switchRef = React.useRef(null);
|
|
41
|
+
const id = useBaseUiId();
|
|
42
|
+
const controlId = useLabelableId({ id: idProp });
|
|
43
|
+
const hiddenInputId = nativeButton ? void 0 : controlId;
|
|
44
|
+
const [checked, setCheckedState] = useControlled({
|
|
45
|
+
controlled: checkedProp,
|
|
46
|
+
default: Boolean(defaultChecked),
|
|
47
|
+
name: "Switch",
|
|
48
|
+
state: "checked"
|
|
49
|
+
});
|
|
50
|
+
useRegisterFieldControl(switchRef, id, checked, void 0, !disabled, nameProp);
|
|
51
|
+
useIsoLayoutEffect(() => {
|
|
52
|
+
setFilled(checked);
|
|
53
|
+
}, [checked, setFilled]);
|
|
54
|
+
useValueChanged(checked, () => {
|
|
55
|
+
clearErrors(name);
|
|
56
|
+
setDirty(checked !== validityData.initialValue);
|
|
57
|
+
validation.change(checked);
|
|
58
|
+
});
|
|
59
|
+
const { getButtonProps, buttonRef } = useButton({
|
|
60
|
+
disabled,
|
|
61
|
+
native: nativeButton
|
|
62
|
+
});
|
|
63
|
+
const ariaLabelledBy = useAriaLabelledBy(ariaLabelledByProp, labelId, inputRef, !nativeButton, hiddenInputId);
|
|
64
|
+
const rootProps = {
|
|
65
|
+
id: nativeButton ? controlId : id,
|
|
66
|
+
role: "switch",
|
|
67
|
+
"aria-checked": checked,
|
|
68
|
+
"aria-readonly": readOnly || void 0,
|
|
69
|
+
"aria-required": required || void 0,
|
|
70
|
+
"aria-labelledby": ariaLabelledBy,
|
|
71
|
+
onFocus() {
|
|
72
|
+
if (!disabled) setFocused(true);
|
|
73
|
+
},
|
|
74
|
+
onBlur() {
|
|
75
|
+
const element = inputRef.current;
|
|
76
|
+
if (!element || disabled) return;
|
|
77
|
+
setTouched(true);
|
|
78
|
+
setFocused(false);
|
|
79
|
+
if (validationMode === "onBlur") validation.commit(element.checked);
|
|
80
|
+
},
|
|
81
|
+
onClick(event) {
|
|
82
|
+
if (readOnly || disabled) return;
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
const input = inputRef.current;
|
|
85
|
+
if (!input) return;
|
|
86
|
+
dispatchClickWithModifiers(input, event);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const inputProps = {
|
|
90
|
+
...validation.getValidationProps(disabled),
|
|
91
|
+
checked,
|
|
92
|
+
disabled,
|
|
93
|
+
form,
|
|
94
|
+
id: hiddenInputId,
|
|
95
|
+
name,
|
|
96
|
+
required,
|
|
97
|
+
style: name ? visuallyHiddenInput : visuallyHidden,
|
|
98
|
+
tabIndex: -1,
|
|
99
|
+
type: "checkbox",
|
|
100
|
+
"aria-hidden": true,
|
|
101
|
+
ref: handleInputRef,
|
|
102
|
+
onChange(event) {
|
|
103
|
+
if (event.nativeEvent.defaultPrevented) return;
|
|
104
|
+
if (readOnly) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const nextChecked = event.currentTarget.checked;
|
|
109
|
+
const eventDetails = createChangeEventDetails(none, event.nativeEvent);
|
|
110
|
+
onCheckedChange?.(nextChecked, eventDetails);
|
|
111
|
+
if (eventDetails.isCanceled) return;
|
|
112
|
+
setCheckedState(nextChecked);
|
|
113
|
+
},
|
|
114
|
+
onClick(event) {
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
},
|
|
117
|
+
onFocus() {
|
|
118
|
+
switchRef.current?.focus();
|
|
119
|
+
},
|
|
120
|
+
...value !== void 0 ? { value } : EMPTY_OBJECT
|
|
121
|
+
};
|
|
122
|
+
const state = React.useMemo(() => ({
|
|
123
|
+
...fieldState,
|
|
124
|
+
checked,
|
|
125
|
+
disabled,
|
|
126
|
+
readOnly,
|
|
127
|
+
required
|
|
128
|
+
}), [
|
|
129
|
+
fieldState,
|
|
130
|
+
checked,
|
|
131
|
+
disabled,
|
|
132
|
+
readOnly,
|
|
133
|
+
required
|
|
134
|
+
]);
|
|
135
|
+
const element = useRenderElement("span", componentProps, {
|
|
136
|
+
state,
|
|
137
|
+
ref: [
|
|
138
|
+
forwardedRef,
|
|
139
|
+
switchRef,
|
|
140
|
+
buttonRef
|
|
141
|
+
],
|
|
142
|
+
props: [
|
|
143
|
+
rootProps,
|
|
144
|
+
elementProps,
|
|
145
|
+
getButtonProps,
|
|
146
|
+
(props) => validation.getValidationProps(disabled, props)
|
|
147
|
+
],
|
|
148
|
+
stateAttributesMapping
|
|
149
|
+
});
|
|
150
|
+
return /*#__PURE__*/ jsxs(SwitchRootContext.Provider, {
|
|
151
|
+
value: state,
|
|
152
|
+
children: [
|
|
153
|
+
element,
|
|
154
|
+
!checked && name && uncheckedValue !== void 0 && /*#__PURE__*/ jsx("input", {
|
|
155
|
+
type: "hidden",
|
|
156
|
+
form,
|
|
157
|
+
name,
|
|
158
|
+
value: uncheckedValue,
|
|
159
|
+
disabled
|
|
160
|
+
}),
|
|
161
|
+
/*#__PURE__*/ jsx("input", {
|
|
162
|
+
...inputProps,
|
|
163
|
+
suppressHydrationWarning: true
|
|
164
|
+
})
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
if (process.env.NODE_ENV !== "production") SwitchRoot.displayName = "SwitchRoot";
|
|
169
|
+
//#endregion
|
|
170
|
+
export { SwitchRoot };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import formatErrorMessage from "../../../utils/formatErrorMessage.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/switch/root/SwitchRootContext.mjs
|
|
5
|
+
const SwitchRootContext = /*#__PURE__*/ React.createContext(void 0);
|
|
6
|
+
if (process.env.NODE_ENV !== "production") SwitchRootContext.displayName = "SwitchRootContext";
|
|
7
|
+
function useSwitchRootContext() {
|
|
8
|
+
const context = React.useContext(SwitchRootContext);
|
|
9
|
+
if (context === void 0) throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: SwitchRootContext is missing. Switch parts must be placed within <Switch.Root>." : formatErrorMessage(63));
|
|
10
|
+
return context;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SwitchRootContext, useSwitchRootContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/switch/root/SwitchRootDataAttributes.mjs
|
|
2
|
+
/**
|
|
3
|
+
* Present when the switch is checked.
|
|
4
|
+
*/
|
|
5
|
+
const checked = "data-checked";
|
|
6
|
+
/**
|
|
7
|
+
* Present when the switch is not checked.
|
|
8
|
+
*/
|
|
9
|
+
const unchecked = "data-unchecked";
|
|
10
|
+
//#endregion
|
|
11
|
+
export { checked, unchecked };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fieldValidityMapping } from "../internals/field-constants/constants.js";
|
|
2
|
+
import { checked, unchecked } from "./root/SwitchRootDataAttributes.js";
|
|
3
|
+
//#region ../../../node_modules/.pnpm/@base-ui+react@1.8.0_@date-fns+tz@1.5.0_@types+react@19.3.0_date-fns@4.4.0_react-dom@19.3.0_react@19.3.0__react@19.3.0/node_modules/@base-ui/react/switch/stateAttributesMapping.mjs
|
|
4
|
+
const stateAttributesMapping = {
|
|
5
|
+
...fieldValidityMapping,
|
|
6
|
+
checked(value) {
|
|
7
|
+
if (value) return { [checked]: "" };
|
|
8
|
+
return { [unchecked]: "" };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { stateAttributesMapping };
|