@octanejs/base-ui 0.1.30 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/accordion.cjs +497 -0
- package/dist/cjs/alert-dialog.cjs +65 -0
- package/dist/cjs/avatar.cjs +234 -0
- package/dist/cjs/button.cjs +54 -0
- package/dist/cjs/checkbox-group.cjs +165 -0
- package/dist/cjs/checkbox.cjs +475 -0
- package/dist/cjs/collapsible.cjs +700 -0
- package/dist/cjs/context-menu.cjs +257 -0
- package/dist/cjs/csp-provider.cjs +40 -0
- package/dist/cjs/dialog.cjs +741 -0
- package/dist/cjs/direction-provider.cjs +35 -0
- package/dist/cjs/field.cjs +559 -0
- package/dist/cjs/fieldset.cjs +101 -0
- package/dist/cjs/form.cjs +177 -0
- package/dist/cjs/index.cjs +133 -0
- package/dist/cjs/input.cjs +32 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/menu.cjs +2420 -0
- package/dist/cjs/menubar.cjs +132 -0
- package/dist/cjs/merge-props.cjs +34 -0
- package/dist/cjs/meter.cjs +169 -0
- package/dist/cjs/number-field.cjs +812 -0
- package/dist/cjs/popover.cjs +966 -0
- package/dist/cjs/preview-card.cjs +632 -0
- package/dist/cjs/progress.cjs +206 -0
- package/dist/cjs/radio-group.cjs +264 -0
- package/dist/cjs/radio.cjs +327 -0
- package/dist/cjs/separator.cjs +44 -0
- package/dist/cjs/slider.cjs +1384 -0
- package/dist/cjs/switch.cjs +306 -0
- package/dist/cjs/tabs.cjs +727 -0
- package/dist/cjs/toast.cjs +1766 -0
- package/dist/cjs/toggle-group.cjs +118 -0
- package/dist/cjs/toggle.cjs +121 -0
- package/dist/cjs/tooltip.cjs +835 -0
- package/dist/cjs/unstable-use-media-query.cjs +79 -0
- package/dist/cjs/use-render.cjs +40 -0
- package/dist/cjs/utils/CSPContext.cjs +38 -0
- package/dist/cjs/utils/CheckboxGroupContext.cjs +40 -0
- package/dist/cjs/utils/CompositeRootContext.cjs +40 -0
- package/dist/cjs/utils/ContextMenuRootContext.cjs +42 -0
- package/dist/cjs/utils/DirectionContext.cjs +34 -0
- package/dist/cjs/utils/FloatingPortalLite.cjs +47 -0
- package/dist/cjs/utils/InternalBackdrop.cjs +49 -0
- package/dist/cjs/utils/MenubarContext.cjs +40 -0
- package/dist/cjs/utils/RadioGroupContext.cjs +34 -0
- package/dist/cjs/utils/RequestQueue.cjs +111 -0
- package/dist/cjs/utils/TimeoutManager.cjs +50 -0
- package/dist/cjs/utils/ToggleGroupContext.cjs +40 -0
- package/dist/cjs/utils/adaptiveOriginMiddleware.cjs +94 -0
- package/dist/cjs/utils/addEventListener.cjs +33 -0
- package/dist/cjs/utils/areArraysEqual.cjs +30 -0
- package/dist/cjs/utils/clamp.cjs +30 -0
- package/dist/cjs/utils/closePart.cjs +70 -0
- package/dist/cjs/utils/collapsibleOpenStateMapping.cjs +42 -0
- package/dist/cjs/utils/composeRefs.cjs +68 -0
- package/dist/cjs/utils/composite/CompositeItem.cjs +59 -0
- package/dist/cjs/utils/composite/CompositeList.cjs +177 -0
- package/dist/cjs/utils/composite/CompositeListContext.cjs +43 -0
- package/dist/cjs/utils/composite/CompositeRoot.cjs +118 -0
- package/dist/cjs/utils/composite/grid-utils.cjs +343 -0
- package/dist/cjs/utils/composite/gridNavigation.cjs +92 -0
- package/dist/cjs/utils/composite/keys.cjs +174 -0
- package/dist/cjs/utils/composite/list-utils.cjs +90 -0
- package/dist/cjs/utils/composite/useCompositeItem.cjs +63 -0
- package/dist/cjs/utils/composite/useCompositeListItem.cjs +104 -0
- package/dist/cjs/utils/composite/useCompositeRoot.cjs +263 -0
- package/dist/cjs/utils/constants.cjs +56 -0
- package/dist/cjs/utils/contains.cjs +46 -0
- package/dist/cjs/utils/createChangeEventDetails.cjs +92 -0
- package/dist/cjs/utils/dom.cjs +35 -0
- package/dist/cjs/utils/empty.cjs +34 -0
- package/dist/cjs/utils/field/FieldItemContext.cjs +34 -0
- package/dist/cjs/utils/field/FieldRootContext.cjs +80 -0
- package/dist/cjs/utils/field/FormContext.cjs +41 -0
- package/dist/cjs/utils/field/LabelableContext.cjs +43 -0
- package/dist/cjs/utils/field/LabelableProvider.cjs +115 -0
- package/dist/cjs/utils/field/constants.cjs +68 -0
- package/dist/cjs/utils/field/getCombinedFieldValidityData.cjs +36 -0
- package/dist/cjs/utils/field/useAriaLabelledBy.cjs +87 -0
- package/dist/cjs/utils/field/useFieldControlRegistration.cjs +165 -0
- package/dist/cjs/utils/field/useFieldValidation.cjs +285 -0
- package/dist/cjs/utils/field/useLabel.cjs +99 -0
- package/dist/cjs/utils/field/useLabelableId.cjs +105 -0
- package/dist/cjs/utils/field/useRegisterFieldControl.cjs +60 -0
- package/dist/cjs/utils/findRootOwnerId.cjs +37 -0
- package/dist/cjs/utils/floating/FloatingDelayGroup.cjs +219 -0
- package/dist/cjs/utils/floating/FloatingFocusManager.cjs +685 -0
- package/dist/cjs/utils/floating/FloatingPortal.cjs +230 -0
- package/dist/cjs/utils/floating/FloatingRootStore.cjs +87 -0
- package/dist/cjs/utils/floating/FloatingTree.cjs +86 -0
- package/dist/cjs/utils/floating/FloatingTreeStore.cjs +41 -0
- package/dist/cjs/utils/floating/FocusGuard.cjs +54 -0
- package/dist/cjs/utils/floating/composite.cjs +42 -0
- package/dist/cjs/utils/floating/constants.cjs +34 -0
- package/dist/cjs/utils/floating/createAttribute.cjs +30 -0
- package/dist/cjs/utils/floating/createEventEmitter.cjs +44 -0
- package/dist/cjs/utils/floating/element.cjs +103 -0
- package/dist/cjs/utils/floating/enqueueFocus.cjs +51 -0
- package/dist/cjs/utils/floating/event.cjs +65 -0
- package/dist/cjs/utils/floating/getEmptyRootContext.cjs +42 -0
- package/dist/cjs/utils/floating/gridNavigation.cjs +45 -0
- package/dist/cjs/utils/floating/markOthers.cjs +181 -0
- package/dist/cjs/utils/floating/nodes.cjs +48 -0
- package/dist/cjs/utils/floating/safePolygon.cjs +301 -0
- package/dist/cjs/utils/floating/tabbable.cjs +242 -0
- package/dist/cjs/utils/floating/types.cjs +16 -0
- package/dist/cjs/utils/floating/useClick.cjs +153 -0
- package/dist/cjs/utils/floating/useClientPoint.cjs +225 -0
- package/dist/cjs/utils/floating/useDismiss.cjs +506 -0
- package/dist/cjs/utils/floating/useFloating.cjs +186 -0
- package/dist/cjs/utils/floating/useFloatingRootContext.cjs +75 -0
- package/dist/cjs/utils/floating/useFocus.cjs +184 -0
- package/dist/cjs/utils/floating/useHoverFloatingInteraction.cjs +231 -0
- package/dist/cjs/utils/floating/useHoverInteractionSharedState.cjs +113 -0
- package/dist/cjs/utils/floating/useHoverReferenceInteraction.cjs +380 -0
- package/dist/cjs/utils/floating/useHoverShared.cjs +65 -0
- package/dist/cjs/utils/floating/useListNavigation.cjs +665 -0
- package/dist/cjs/utils/floating/useSyncedFloatingRootContext.cjs +91 -0
- package/dist/cjs/utils/floating/useTypeahead.cjs +187 -0
- package/dist/cjs/utils/formatNumber.cjs +60 -0
- package/dist/cjs/utils/generateId.cjs +32 -0
- package/dist/cjs/utils/getCssDimensions.cjs +42 -0
- package/dist/cjs/utils/getDefaultFormSubmitter.cjs +42 -0
- package/dist/cjs/utils/getDisabledMountTransitionStyles.cjs +32 -0
- package/dist/cjs/utils/getElementRef.cjs +35 -0
- package/dist/cjs/utils/getPseudoElementBounds.cjs +56 -0
- package/dist/cjs/utils/getStateAttributesProps.cjs +46 -0
- package/dist/cjs/utils/hideMiddleware.cjs +42 -0
- package/dist/cjs/utils/inertValue.cjs +30 -0
- package/dist/cjs/utils/matchesFocusVisible.cjs +38 -0
- package/dist/cjs/utils/mergeCleanups.cjs +37 -0
- package/dist/cjs/utils/mergeObjects.cjs +39 -0
- package/dist/cjs/utils/mergeProps.cjs +182 -0
- package/dist/cjs/utils/noop.cjs +29 -0
- package/dist/cjs/utils/number/constants.cjs +34 -0
- package/dist/cjs/utils/number/parse.cjs +258 -0
- package/dist/cjs/utils/number/types.cjs +16 -0
- package/dist/cjs/utils/number/validate.cjs +104 -0
- package/dist/cjs/utils/owner.cjs +35 -0
- package/dist/cjs/utils/platform.cjs +83 -0
- package/dist/cjs/utils/popupStateMapping.cjs +74 -0
- package/dist/cjs/utils/popups/index.cjs +39 -0
- package/dist/cjs/utils/popups/inlineRect.cjs +218 -0
- package/dist/cjs/utils/popups/popupStoreUtils.cjs +379 -0
- package/dist/cjs/utils/popups/popupTriggerMap.cjs +76 -0
- package/dist/cjs/utils/popups/store.cjs +118 -0
- package/dist/cjs/utils/popups/useTriggerFocusGuards.cjs +72 -0
- package/dist/cjs/utils/resolveAriaLabelledBy.cjs +35 -0
- package/dist/cjs/utils/resolveClassName.cjs +30 -0
- package/dist/cjs/utils/resolveRef.cjs +33 -0
- package/dist/cjs/utils/resolveStyle.cjs +30 -0
- package/dist/cjs/utils/serializeValue.cjs +40 -0
- package/dist/cjs/utils/slider/asc.cjs +30 -0
- package/dist/cjs/utils/slider/getMidpoint.cjs +34 -0
- package/dist/cjs/utils/slider/getPushedThumbValues.cjs +73 -0
- package/dist/cjs/utils/slider/getSliderValue.cjs +42 -0
- package/dist/cjs/utils/slider/replaceArrayItemAtIndex.cjs +33 -0
- package/dist/cjs/utils/slider/resolveThumbCollision.cjs +155 -0
- package/dist/cjs/utils/slider/roundValueToStep.cjs +45 -0
- package/dist/cjs/utils/slider/validateMinimumDistance.cjs +40 -0
- package/dist/cjs/utils/slider/valueArrayToPercentages.cjs +36 -0
- package/dist/cjs/utils/store/ReactStore.cjs +135 -0
- package/dist/cjs/utils/store/Store.cjs +83 -0
- package/dist/cjs/utils/store/createSelector.cjs +74 -0
- package/dist/cjs/utils/store/useStore.cjs +51 -0
- package/dist/cjs/utils/stringifyLocale.cjs +36 -0
- package/dist/cjs/utils/useAnchorPositioning.cjs +421 -0
- package/dist/cjs/utils/useAnchoredPopupScrollLock.cjs +59 -0
- package/dist/cjs/utils/useAnimationFrame.cjs +93 -0
- package/dist/cjs/utils/useAnimationsFinished.cjs +98 -0
- package/dist/cjs/utils/useBaseUiId.cjs +36 -0
- package/dist/cjs/utils/useButton.cjs +177 -0
- package/dist/cjs/utils/useCheckboxGroupParent.cjs +114 -0
- package/dist/cjs/utils/useControlled.cjs +47 -0
- package/dist/cjs/utils/useEnhancedClickHandler.cjs +60 -0
- package/dist/cjs/utils/useFocusableWhenDisabled.cjs +77 -0
- package/dist/cjs/utils/useForcedRerendering.cjs +35 -0
- package/dist/cjs/utils/useIsHydrating.cjs +44 -0
- package/dist/cjs/utils/useMixedToggleClickHandler.cjs +66 -0
- package/dist/cjs/utils/useOnFirstRender.cjs +35 -0
- package/dist/cjs/utils/useOnMount.cjs +36 -0
- package/dist/cjs/utils/useOpenChangeComplete.cjs +57 -0
- package/dist/cjs/utils/useOpenInteractionType.cjs +69 -0
- package/dist/cjs/utils/usePopupAutoResize.cjs +191 -0
- package/dist/cjs/utils/usePopupViewport.cjs +283 -0
- package/dist/cjs/utils/usePositioner.cjs +53 -0
- package/dist/cjs/utils/usePressAndHold.cjs +51 -0
- package/dist/cjs/utils/usePreviousValue.cjs +47 -0
- package/dist/cjs/utils/useRefWithInit.cjs +41 -0
- package/dist/cjs/utils/useRegisteredLabelId.cjs +48 -0
- package/dist/cjs/utils/useRenderElement.cjs +106 -0
- package/dist/cjs/utils/useScrollLock.cjs +232 -0
- package/dist/cjs/utils/useStableCallback.cjs +41 -0
- package/dist/cjs/utils/useTimeout.cjs +66 -0
- package/dist/cjs/utils/useTransitionStatus.cjs +116 -0
- package/dist/cjs/utils/useValueAsRef.cjs +43 -0
- package/dist/cjs/utils/useValueChanged.cjs +55 -0
- package/dist/cjs/utils/valueToPercent.cjs +30 -0
- package/dist/cjs/utils/visuallyHidden.cjs +49 -0
- package/package.json +20 -8
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var direction_provider_exports = {};
|
|
20
|
+
__export(direction_provider_exports, {
|
|
21
|
+
DirectionProvider: () => DirectionProvider,
|
|
22
|
+
useDirection: () => import_DirectionContext.useDirection
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(direction_provider_exports);
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_DirectionContext = require("./utils/DirectionContext.cjs");
|
|
27
|
+
function DirectionProvider(props) {
|
|
28
|
+
const { direction = "ltr" } = props;
|
|
29
|
+
return (0, import_octane.createElement)(import_DirectionContext.DirectionContext.Provider, { value: direction, children: props.children });
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
DirectionProvider,
|
|
34
|
+
useDirection
|
|
35
|
+
});
|
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var field_exports = {};
|
|
20
|
+
__export(field_exports, {
|
|
21
|
+
Field: () => Field,
|
|
22
|
+
useFieldRootContext: () => import_FieldRootContext2.useFieldRootContext
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(field_exports);
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_internal = require("./internal.cjs");
|
|
27
|
+
var import_useRenderElement = require("./utils/useRenderElement.cjs");
|
|
28
|
+
var import_owner = require("./utils/owner.cjs");
|
|
29
|
+
var import_createChangeEventDetails = require("./utils/createChangeEventDetails.cjs");
|
|
30
|
+
var import_useControlled = require("./utils/useControlled.cjs");
|
|
31
|
+
var import_useStableCallback = require("./utils/useStableCallback.cjs");
|
|
32
|
+
var import_constants = require("./utils/field/constants.cjs");
|
|
33
|
+
var import_FieldRootContext = require("./utils/field/FieldRootContext.cjs");
|
|
34
|
+
var import_FieldItemContext = require("./utils/field/FieldItemContext.cjs");
|
|
35
|
+
var import_FieldRootContext2 = require("./utils/field/FieldRootContext.cjs");
|
|
36
|
+
var import_FieldItemContext2 = require("./utils/field/FieldItemContext.cjs");
|
|
37
|
+
var import_FormContext = require("./utils/field/FormContext.cjs");
|
|
38
|
+
var import_LabelableContext = require("./utils/field/LabelableContext.cjs");
|
|
39
|
+
var import_LabelableProvider = require("./utils/field/LabelableProvider.cjs");
|
|
40
|
+
var import_useLabelableId = require("./utils/field/useLabelableId.cjs");
|
|
41
|
+
var import_useLabel = require("./utils/field/useLabel.cjs");
|
|
42
|
+
var import_useRegisterFieldControl = require("./utils/field/useRegisterFieldControl.cjs");
|
|
43
|
+
var import_useFieldValidation = require("./utils/field/useFieldValidation.cjs");
|
|
44
|
+
var import_useFieldControlRegistration = require("./utils/field/useFieldControlRegistration.cjs");
|
|
45
|
+
var import_getCombinedFieldValidityData = require("./utils/field/getCombinedFieldValidityData.cjs");
|
|
46
|
+
var import_fieldset = require("./fieldset.cjs");
|
|
47
|
+
var import_useTransitionStatus = require("./utils/useTransitionStatus.cjs");
|
|
48
|
+
var import_useOpenChangeComplete = require("./utils/useOpenChangeComplete.cjs");
|
|
49
|
+
var import_useBaseUiId = require("./utils/useBaseUiId.cjs");
|
|
50
|
+
function activeElement(doc) {
|
|
51
|
+
return doc.activeElement;
|
|
52
|
+
}
|
|
53
|
+
function FieldRootInner(props) {
|
|
54
|
+
const slot = (0, import_internal.S)("FieldRootInner");
|
|
55
|
+
const { errors, validationMode: formValidationMode, submitAttemptedRef } = (0, import_FormContext.useFormContext)();
|
|
56
|
+
const {
|
|
57
|
+
render,
|
|
58
|
+
className,
|
|
59
|
+
validate: validateProp,
|
|
60
|
+
validationDebounceTime = 0,
|
|
61
|
+
validationMode = formValidationMode,
|
|
62
|
+
name,
|
|
63
|
+
disabled: disabledProp = false,
|
|
64
|
+
invalid: invalidProp,
|
|
65
|
+
dirty: dirtyProp,
|
|
66
|
+
touched: touchedProp,
|
|
67
|
+
actionsRef,
|
|
68
|
+
style,
|
|
69
|
+
ref,
|
|
70
|
+
...elementProps
|
|
71
|
+
} = props;
|
|
72
|
+
const disabledFieldset = (0, import_fieldset.useFieldsetRootContext)(true)?.disabled;
|
|
73
|
+
const validate = (0, import_useStableCallback.useStableCallback)(validateProp || (() => null), (0, import_internal.subSlot)(slot, "validate"));
|
|
74
|
+
const disabled = disabledFieldset || disabledProp;
|
|
75
|
+
const [touchedState, setTouchedUnwrapped] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "touched"));
|
|
76
|
+
const [dirtyState, setDirtyUnwrapped] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "dirty"));
|
|
77
|
+
const [filled, setFilled] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "filled"));
|
|
78
|
+
const [focused, setFocused] = (0, import_octane.useState)(false, (0, import_internal.subSlot)(slot, "focused"));
|
|
79
|
+
const dirty = dirtyProp ?? dirtyState;
|
|
80
|
+
const touched = touchedProp ?? touchedState;
|
|
81
|
+
const markedDirtyRef = (0, import_octane.useRef)(dirty, (0, import_internal.subSlot)(slot, "markedDirty"));
|
|
82
|
+
const registeredFieldIdRef = (0, import_octane.useRef)(void 0, (0, import_internal.subSlot)(slot, "regId"));
|
|
83
|
+
const [registeredFieldName, setRegisteredFieldName] = (0, import_octane.useState)(
|
|
84
|
+
void 0,
|
|
85
|
+
(0, import_internal.subSlot)(slot, "regName")
|
|
86
|
+
);
|
|
87
|
+
const effectiveName = name ?? registeredFieldName;
|
|
88
|
+
(0, import_octane.useLayoutEffect)(
|
|
89
|
+
() => {
|
|
90
|
+
if (dirtyProp !== void 0) {
|
|
91
|
+
markedDirtyRef.current = dirtyProp;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
[dirtyProp],
|
|
95
|
+
(0, import_internal.subSlot)(slot, "e:markedDirty")
|
|
96
|
+
);
|
|
97
|
+
const getRegisteredFieldId = (0, import_octane.useCallback)(
|
|
98
|
+
() => registeredFieldIdRef.current,
|
|
99
|
+
[],
|
|
100
|
+
(0, import_internal.subSlot)(slot, "getRegId")
|
|
101
|
+
);
|
|
102
|
+
const setRegisteredFieldId = (0, import_octane.useCallback)(
|
|
103
|
+
(id) => {
|
|
104
|
+
registeredFieldIdRef.current = id;
|
|
105
|
+
},
|
|
106
|
+
[],
|
|
107
|
+
(0, import_internal.subSlot)(slot, "setRegId")
|
|
108
|
+
);
|
|
109
|
+
const setDirty = (0, import_useStableCallback.useStableCallback)(
|
|
110
|
+
(value) => {
|
|
111
|
+
if (dirtyProp !== void 0) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (value) {
|
|
115
|
+
markedDirtyRef.current = true;
|
|
116
|
+
}
|
|
117
|
+
setDirtyUnwrapped(value);
|
|
118
|
+
},
|
|
119
|
+
(0, import_internal.subSlot)(slot, "setDirty")
|
|
120
|
+
);
|
|
121
|
+
const setTouched = (0, import_useStableCallback.useStableCallback)(
|
|
122
|
+
(value) => {
|
|
123
|
+
if (touchedProp !== void 0) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
setTouchedUnwrapped(value);
|
|
127
|
+
},
|
|
128
|
+
(0, import_internal.subSlot)(slot, "setTouched")
|
|
129
|
+
);
|
|
130
|
+
const shouldValidateOnChange = (0, import_useStableCallback.useStableCallback)(
|
|
131
|
+
() => validationMode === "onChange" || validationMode === "onSubmit" && submitAttemptedRef.current,
|
|
132
|
+
(0, import_internal.subSlot)(slot, "shouldValidate")
|
|
133
|
+
);
|
|
134
|
+
const formError = effectiveName && Object.hasOwn(errors, effectiveName) ? errors[effectiveName] : null;
|
|
135
|
+
const hasFormError = !!(Array.isArray(formError) ? formError.length : formError);
|
|
136
|
+
const invalid = invalidProp === true || hasFormError;
|
|
137
|
+
const [validityData, setValidityData] = (0, import_octane.useState)(
|
|
138
|
+
{ state: import_constants.DEFAULT_VALIDITY_STATE, error: "", errors: [], value: null, initialValue: null },
|
|
139
|
+
(0, import_internal.subSlot)(slot, "validityData")
|
|
140
|
+
);
|
|
141
|
+
const valid = disabled ? null : !invalid && validityData.state.valid;
|
|
142
|
+
const state = (0, import_octane.useMemo)(
|
|
143
|
+
() => ({ disabled, touched, dirty, valid, filled, focused }),
|
|
144
|
+
[disabled, touched, dirty, valid, filled, focused],
|
|
145
|
+
(0, import_internal.subSlot)(slot, "state")
|
|
146
|
+
);
|
|
147
|
+
const validation = (0, import_useFieldValidation.useFieldValidation)(
|
|
148
|
+
{
|
|
149
|
+
setValidityData,
|
|
150
|
+
validate,
|
|
151
|
+
validityData,
|
|
152
|
+
validationDebounceTime,
|
|
153
|
+
invalid,
|
|
154
|
+
markedDirtyRef,
|
|
155
|
+
state,
|
|
156
|
+
shouldValidateOnChange,
|
|
157
|
+
getRegisteredFieldId
|
|
158
|
+
},
|
|
159
|
+
(0, import_internal.subSlot)(slot, "validation")
|
|
160
|
+
);
|
|
161
|
+
const [validateFieldControl, registerFieldControl] = (0, import_useFieldControlRegistration.useFieldControlRegistration)(
|
|
162
|
+
{
|
|
163
|
+
commit: validation.commit,
|
|
164
|
+
invalid,
|
|
165
|
+
markedDirtyRef,
|
|
166
|
+
name,
|
|
167
|
+
setRegisteredFieldName,
|
|
168
|
+
setRegisteredFieldId,
|
|
169
|
+
setValidityData,
|
|
170
|
+
validityData
|
|
171
|
+
},
|
|
172
|
+
(0, import_internal.subSlot)(slot, "controlReg")
|
|
173
|
+
);
|
|
174
|
+
(0, import_octane.useImperativeHandle)(
|
|
175
|
+
actionsRef,
|
|
176
|
+
() => ({ validate: validateFieldControl }),
|
|
177
|
+
[validateFieldControl],
|
|
178
|
+
(0, import_internal.subSlot)(slot, "imperative")
|
|
179
|
+
);
|
|
180
|
+
const contextValue = (0, import_octane.useMemo)(
|
|
181
|
+
() => ({
|
|
182
|
+
invalid,
|
|
183
|
+
name: effectiveName,
|
|
184
|
+
validityData,
|
|
185
|
+
setValidityData,
|
|
186
|
+
disabled,
|
|
187
|
+
touched,
|
|
188
|
+
setTouched,
|
|
189
|
+
dirty,
|
|
190
|
+
setDirty,
|
|
191
|
+
filled,
|
|
192
|
+
setFilled,
|
|
193
|
+
focused,
|
|
194
|
+
setFocused,
|
|
195
|
+
validate,
|
|
196
|
+
validationMode,
|
|
197
|
+
validationDebounceTime,
|
|
198
|
+
shouldValidateOnChange,
|
|
199
|
+
state,
|
|
200
|
+
markedDirtyRef,
|
|
201
|
+
registerFieldControl,
|
|
202
|
+
validation
|
|
203
|
+
}),
|
|
204
|
+
[
|
|
205
|
+
invalid,
|
|
206
|
+
effectiveName,
|
|
207
|
+
validityData,
|
|
208
|
+
disabled,
|
|
209
|
+
touched,
|
|
210
|
+
setTouched,
|
|
211
|
+
dirty,
|
|
212
|
+
setDirty,
|
|
213
|
+
filled,
|
|
214
|
+
setFilled,
|
|
215
|
+
focused,
|
|
216
|
+
setFocused,
|
|
217
|
+
validate,
|
|
218
|
+
validationMode,
|
|
219
|
+
validationDebounceTime,
|
|
220
|
+
shouldValidateOnChange,
|
|
221
|
+
state,
|
|
222
|
+
registerFieldControl,
|
|
223
|
+
validation
|
|
224
|
+
],
|
|
225
|
+
(0, import_internal.subSlot)(slot, "ctx")
|
|
226
|
+
);
|
|
227
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
228
|
+
"div",
|
|
229
|
+
{ render, className, style },
|
|
230
|
+
{ ref, state, props: elementProps, stateAttributesMapping: import_constants.fieldValidityMapping },
|
|
231
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
232
|
+
);
|
|
233
|
+
return (0, import_octane.createElement)(import_FieldRootContext.FieldRootContext.Provider, { value: contextValue, children: element });
|
|
234
|
+
}
|
|
235
|
+
function FieldRoot(props) {
|
|
236
|
+
return (0, import_octane.createElement)(import_LabelableProvider.LabelableProvider, {
|
|
237
|
+
children: (0, import_octane.createElement)(FieldRootInner, props)
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function FieldControl(props) {
|
|
241
|
+
const slot = (0, import_internal.S)("FieldControl");
|
|
242
|
+
const {
|
|
243
|
+
render,
|
|
244
|
+
className,
|
|
245
|
+
id: idProp,
|
|
246
|
+
name: nameProp,
|
|
247
|
+
value: valueProp,
|
|
248
|
+
disabled: disabledProp = false,
|
|
249
|
+
onValueChange,
|
|
250
|
+
defaultValue,
|
|
251
|
+
autoFocus = false,
|
|
252
|
+
style,
|
|
253
|
+
ref,
|
|
254
|
+
...elementProps
|
|
255
|
+
} = props;
|
|
256
|
+
const {
|
|
257
|
+
state: fieldState,
|
|
258
|
+
name: fieldName,
|
|
259
|
+
disabled: fieldDisabled,
|
|
260
|
+
setTouched,
|
|
261
|
+
setDirty,
|
|
262
|
+
validityData,
|
|
263
|
+
setFocused,
|
|
264
|
+
setFilled,
|
|
265
|
+
validationMode,
|
|
266
|
+
validation
|
|
267
|
+
} = (0, import_FieldRootContext2.useFieldRootContext)();
|
|
268
|
+
const { clearErrors } = (0, import_FormContext.useFormContext)();
|
|
269
|
+
const disabled = fieldDisabled || disabledProp;
|
|
270
|
+
const name = fieldName ?? nameProp;
|
|
271
|
+
const state = { ...fieldState, disabled };
|
|
272
|
+
const { labelId } = (0, import_LabelableContext.useLabelableContext)();
|
|
273
|
+
const id = (0, import_useLabelableId.useLabelableId)({ id: idProp }, (0, import_internal.subSlot)(slot, "id"));
|
|
274
|
+
const inputRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "inputRef"));
|
|
275
|
+
(0, import_octane.useLayoutEffect)(
|
|
276
|
+
() => {
|
|
277
|
+
const hasExternalValue = valueProp != null;
|
|
278
|
+
if (validation.inputRef.current?.value || hasExternalValue && valueProp !== "") {
|
|
279
|
+
setFilled(true);
|
|
280
|
+
} else if (hasExternalValue && valueProp === "") {
|
|
281
|
+
setFilled(false);
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
[validation.inputRef, setFilled, valueProp],
|
|
285
|
+
(0, import_internal.subSlot)(slot, "e:filled")
|
|
286
|
+
);
|
|
287
|
+
(0, import_octane.useLayoutEffect)(
|
|
288
|
+
() => {
|
|
289
|
+
if (autoFocus && inputRef.current === activeElement((0, import_owner.ownerDocument)(inputRef.current))) {
|
|
290
|
+
setFocused(true);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
[autoFocus, setFocused],
|
|
294
|
+
(0, import_internal.subSlot)(slot, "e:autofocus")
|
|
295
|
+
);
|
|
296
|
+
const [valueUnwrapped] = (0, import_useControlled.useControlled)(
|
|
297
|
+
{ controlled: valueProp, default: defaultValue, name: "FieldControl", state: "value" },
|
|
298
|
+
(0, import_internal.subSlot)(slot, "value")
|
|
299
|
+
);
|
|
300
|
+
const isControlled = valueProp !== void 0;
|
|
301
|
+
const value = isControlled ? valueUnwrapped : void 0;
|
|
302
|
+
const getValueFromInput = (0, import_useStableCallback.useStableCallback)(
|
|
303
|
+
() => validation.inputRef.current?.value,
|
|
304
|
+
(0, import_internal.subSlot)(slot, "getValue")
|
|
305
|
+
);
|
|
306
|
+
(0, import_useRegisterFieldControl.useRegisterFieldControl)(
|
|
307
|
+
validation.inputRef,
|
|
308
|
+
id,
|
|
309
|
+
value,
|
|
310
|
+
getValueFromInput,
|
|
311
|
+
!disabled,
|
|
312
|
+
nameProp,
|
|
313
|
+
(0, import_internal.subSlot)(slot, "register")
|
|
314
|
+
);
|
|
315
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
316
|
+
"input",
|
|
317
|
+
{ render, className, style },
|
|
318
|
+
{
|
|
319
|
+
ref: [ref, inputRef],
|
|
320
|
+
state,
|
|
321
|
+
props: [
|
|
322
|
+
{
|
|
323
|
+
id,
|
|
324
|
+
disabled,
|
|
325
|
+
name,
|
|
326
|
+
ref: validation.inputRef,
|
|
327
|
+
"aria-labelledby": labelId,
|
|
328
|
+
autoFocus: autoFocus || void 0,
|
|
329
|
+
...isControlled ? { value } : { defaultValue },
|
|
330
|
+
onInput(event) {
|
|
331
|
+
const inputValue = event.currentTarget.value;
|
|
332
|
+
onValueChange?.(inputValue, (0, import_createChangeEventDetails.createChangeEventDetails)(import_createChangeEventDetails.REASONS.none, event));
|
|
333
|
+
setDirty(inputValue !== validityData.initialValue);
|
|
334
|
+
setFilled(inputValue !== "");
|
|
335
|
+
if (!event.defaultPrevented) {
|
|
336
|
+
clearErrors(name);
|
|
337
|
+
validation.change(inputValue);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
onFocus() {
|
|
341
|
+
setFocused(true);
|
|
342
|
+
},
|
|
343
|
+
onBlur(event) {
|
|
344
|
+
setTouched(true);
|
|
345
|
+
setFocused(false);
|
|
346
|
+
if (validationMode === "onBlur") {
|
|
347
|
+
validation.commit(event.currentTarget.value);
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
onKeyDown(event) {
|
|
351
|
+
if (event.currentTarget.tagName === "INPUT" && event.key === "Enter") {
|
|
352
|
+
setTouched(true);
|
|
353
|
+
validation.commit(event.currentTarget.value);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
elementProps,
|
|
358
|
+
(p) => validation.getValidationProps(disabled, p)
|
|
359
|
+
],
|
|
360
|
+
stateAttributesMapping: import_constants.fieldValidityMapping
|
|
361
|
+
},
|
|
362
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
function FieldLabel(props) {
|
|
366
|
+
const slot = (0, import_internal.S)("FieldLabel");
|
|
367
|
+
const { render, className, style, id: idProp, nativeLabel = true, ref, ...elementProps } = props;
|
|
368
|
+
const fieldRootContext = (0, import_FieldRootContext2.useFieldRootContext)(false);
|
|
369
|
+
const fieldItemContext = (0, import_FieldItemContext2.useFieldItemContext)();
|
|
370
|
+
const { labelId } = (0, import_LabelableContext.useLabelableContext)();
|
|
371
|
+
const state = {
|
|
372
|
+
...fieldRootContext.state,
|
|
373
|
+
disabled: fieldRootContext.disabled || fieldItemContext.disabled
|
|
374
|
+
};
|
|
375
|
+
const labelRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "labelRef"));
|
|
376
|
+
const labelProps = (0, import_useLabel.useLabel)(
|
|
377
|
+
{ id: labelId ?? idProp, native: nativeLabel },
|
|
378
|
+
(0, import_internal.subSlot)(slot, "label")
|
|
379
|
+
);
|
|
380
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
381
|
+
"label",
|
|
382
|
+
{ render, className, style },
|
|
383
|
+
{
|
|
384
|
+
ref: [ref, labelRef],
|
|
385
|
+
state,
|
|
386
|
+
props: [labelProps, elementProps],
|
|
387
|
+
stateAttributesMapping: import_constants.fieldValidityMapping
|
|
388
|
+
},
|
|
389
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
function FieldDescription(props) {
|
|
393
|
+
const slot = (0, import_internal.S)("FieldDescription");
|
|
394
|
+
const { render, id: idProp, className, style, ref, ...elementProps } = props;
|
|
395
|
+
const id = (0, import_useBaseUiId.useBaseUiId)(idProp, (0, import_internal.subSlot)(slot, "id"));
|
|
396
|
+
const fieldRootContext = (0, import_FieldRootContext2.useFieldRootContext)(false);
|
|
397
|
+
const fieldItemContext = (0, import_FieldItemContext2.useFieldItemContext)();
|
|
398
|
+
const { setMessageIds } = (0, import_LabelableContext.useLabelableContext)();
|
|
399
|
+
const state = {
|
|
400
|
+
...fieldRootContext.state,
|
|
401
|
+
disabled: fieldRootContext.disabled || fieldItemContext.disabled
|
|
402
|
+
};
|
|
403
|
+
(0, import_octane.useLayoutEffect)(
|
|
404
|
+
() => {
|
|
405
|
+
if (!id) {
|
|
406
|
+
return void 0;
|
|
407
|
+
}
|
|
408
|
+
setMessageIds((v) => v.concat(id));
|
|
409
|
+
return () => {
|
|
410
|
+
setMessageIds((v) => v.filter((item) => item !== id));
|
|
411
|
+
};
|
|
412
|
+
},
|
|
413
|
+
[id, setMessageIds],
|
|
414
|
+
(0, import_internal.subSlot)(slot, "e:register")
|
|
415
|
+
);
|
|
416
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
417
|
+
"p",
|
|
418
|
+
{ render, className, style },
|
|
419
|
+
{ ref, state, props: [{ id }, elementProps], stateAttributesMapping: import_constants.fieldValidityMapping },
|
|
420
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
const errorStateAttributesMapping = {
|
|
424
|
+
...import_constants.fieldValidityMapping,
|
|
425
|
+
...import_useTransitionStatus.transitionStatusMapping
|
|
426
|
+
};
|
|
427
|
+
function FieldError(props) {
|
|
428
|
+
const slot = (0, import_internal.S)("FieldError");
|
|
429
|
+
const { render, id: idProp, className, match, style, children, ref, ...elementProps } = props;
|
|
430
|
+
const id = (0, import_useBaseUiId.useBaseUiId)(idProp, (0, import_internal.subSlot)(slot, "id"));
|
|
431
|
+
const { validityData, state: fieldState, name } = (0, import_FieldRootContext2.useFieldRootContext)(false);
|
|
432
|
+
const { setMessageIds } = (0, import_LabelableContext.useLabelableContext)();
|
|
433
|
+
const { errors } = (0, import_FormContext.useFormContext)();
|
|
434
|
+
const formError = name && Object.hasOwn(errors, name) ? errors[name] : null;
|
|
435
|
+
const hasFormError = !!(Array.isArray(formError) ? formError.length : formError);
|
|
436
|
+
const hasSpecificMatch = typeof match === "string";
|
|
437
|
+
let rendered = false;
|
|
438
|
+
if (match === true) {
|
|
439
|
+
rendered = true;
|
|
440
|
+
} else if (fieldState.disabled) {
|
|
441
|
+
rendered = false;
|
|
442
|
+
} else if (hasSpecificMatch) {
|
|
443
|
+
rendered = Boolean(validityData.state[match]);
|
|
444
|
+
} else {
|
|
445
|
+
rendered = hasFormError || validityData.state.valid === false;
|
|
446
|
+
}
|
|
447
|
+
const { mounted, transitionStatus, setMounted } = (0, import_useTransitionStatus.useTransitionStatus)(
|
|
448
|
+
rendered,
|
|
449
|
+
(0, import_internal.subSlot)(slot, "ts")
|
|
450
|
+
);
|
|
451
|
+
(0, import_octane.useLayoutEffect)(
|
|
452
|
+
() => {
|
|
453
|
+
if (!rendered || !id) {
|
|
454
|
+
return void 0;
|
|
455
|
+
}
|
|
456
|
+
setMessageIds((v) => v.concat(id));
|
|
457
|
+
return () => {
|
|
458
|
+
setMessageIds((v) => v.filter((item) => item !== id));
|
|
459
|
+
};
|
|
460
|
+
},
|
|
461
|
+
[rendered, id, setMessageIds],
|
|
462
|
+
(0, import_internal.subSlot)(slot, "e:register")
|
|
463
|
+
);
|
|
464
|
+
const errorRef = (0, import_octane.useRef)(null, (0, import_internal.subSlot)(slot, "errorRef"));
|
|
465
|
+
let error = validityData.error;
|
|
466
|
+
if (!hasSpecificMatch && hasFormError) {
|
|
467
|
+
error = formError;
|
|
468
|
+
} else if (validityData.errors.length > 1) {
|
|
469
|
+
error = validityData.errors;
|
|
470
|
+
}
|
|
471
|
+
let errorMessage = error ?? "";
|
|
472
|
+
if (Array.isArray(error)) {
|
|
473
|
+
errorMessage = error.length > 1 ? (0, import_octane.createElement)("ul", {
|
|
474
|
+
children: error.map(
|
|
475
|
+
(message) => (0, import_octane.createElement)("li", { key: message, children: message })
|
|
476
|
+
)
|
|
477
|
+
}) : error[0];
|
|
478
|
+
}
|
|
479
|
+
const state = { ...fieldState, transitionStatus };
|
|
480
|
+
(0, import_useOpenChangeComplete.useOpenChangeComplete)(
|
|
481
|
+
{
|
|
482
|
+
open: rendered,
|
|
483
|
+
ref: errorRef,
|
|
484
|
+
onComplete() {
|
|
485
|
+
if (!rendered) {
|
|
486
|
+
setMounted(false);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
(0, import_internal.subSlot)(slot, "occ")
|
|
491
|
+
);
|
|
492
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
493
|
+
"div",
|
|
494
|
+
{ render, className, style },
|
|
495
|
+
{
|
|
496
|
+
ref: [ref, errorRef],
|
|
497
|
+
state,
|
|
498
|
+
props: [{ id, children: children ?? errorMessage }, elementProps],
|
|
499
|
+
stateAttributesMapping: errorStateAttributesMapping
|
|
500
|
+
},
|
|
501
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
502
|
+
);
|
|
503
|
+
if (!mounted) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
return element;
|
|
507
|
+
}
|
|
508
|
+
function FieldValidity(props) {
|
|
509
|
+
const slot = (0, import_internal.S)("FieldValidity");
|
|
510
|
+
const { children } = props;
|
|
511
|
+
const { validityData, invalid } = (0, import_FieldRootContext2.useFieldRootContext)(false);
|
|
512
|
+
const combined = (0, import_octane.useMemo)(
|
|
513
|
+
() => (0, import_getCombinedFieldValidityData.getCombinedFieldValidityData)(validityData, invalid),
|
|
514
|
+
[validityData, invalid],
|
|
515
|
+
(0, import_internal.subSlot)(slot, "combined")
|
|
516
|
+
);
|
|
517
|
+
const isInvalid = combined.state.valid === false;
|
|
518
|
+
const { transitionStatus } = (0, import_useTransitionStatus.useTransitionStatus)(isInvalid, (0, import_internal.subSlot)(slot, "ts"));
|
|
519
|
+
const fieldValidityState = (0, import_octane.useMemo)(
|
|
520
|
+
() => ({ ...combined, validity: combined.state, transitionStatus }),
|
|
521
|
+
[combined, transitionStatus],
|
|
522
|
+
(0, import_internal.subSlot)(slot, "state")
|
|
523
|
+
);
|
|
524
|
+
return children(fieldValidityState);
|
|
525
|
+
}
|
|
526
|
+
function FieldItem(props) {
|
|
527
|
+
const slot = (0, import_internal.S)("FieldItem");
|
|
528
|
+
const { render, className, style, disabled: disabledProp = false, ref, ...elementProps } = props;
|
|
529
|
+
const { state: fieldState, disabled: rootDisabled } = (0, import_FieldRootContext2.useFieldRootContext)(false);
|
|
530
|
+
const disabled = rootDisabled || disabledProp;
|
|
531
|
+
const state = { ...fieldState, disabled };
|
|
532
|
+
const fieldItemContextValue = (0, import_octane.useMemo)(() => ({ disabled }), [disabled], (0, import_internal.subSlot)(slot, "ctx"));
|
|
533
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
534
|
+
"div",
|
|
535
|
+
{ render, className, style },
|
|
536
|
+
{ ref, state, props: elementProps, stateAttributesMapping: import_constants.fieldValidityMapping },
|
|
537
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
538
|
+
);
|
|
539
|
+
return (0, import_octane.createElement)(import_LabelableProvider.LabelableProvider, {
|
|
540
|
+
children: (0, import_octane.createElement)(import_FieldItemContext.FieldItemContext.Provider, {
|
|
541
|
+
value: fieldItemContextValue,
|
|
542
|
+
children: element
|
|
543
|
+
})
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
const Field = {
|
|
547
|
+
Root: FieldRoot,
|
|
548
|
+
Control: FieldControl,
|
|
549
|
+
Label: FieldLabel,
|
|
550
|
+
Description: FieldDescription,
|
|
551
|
+
Error: FieldError,
|
|
552
|
+
Validity: FieldValidity,
|
|
553
|
+
Item: FieldItem
|
|
554
|
+
};
|
|
555
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
556
|
+
0 && (module.exports = {
|
|
557
|
+
Field,
|
|
558
|
+
useFieldRootContext
|
|
559
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fieldset_exports = {};
|
|
20
|
+
__export(fieldset_exports, {
|
|
21
|
+
Fieldset: () => Fieldset,
|
|
22
|
+
useFieldsetRootContext: () => useFieldsetRootContext
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(fieldset_exports);
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_internal = require("./internal.cjs");
|
|
27
|
+
var import_useRenderElement = require("./utils/useRenderElement.cjs");
|
|
28
|
+
var import_useBaseUiId = require("./utils/useBaseUiId.cjs");
|
|
29
|
+
const FieldsetRootContext = (0, import_octane.createContext)(void 0);
|
|
30
|
+
function useFieldsetRootContext(optional = false) {
|
|
31
|
+
const context = (0, import_octane.useContext)(FieldsetRootContext);
|
|
32
|
+
if (!context && !optional) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"Base UI: FieldsetRootContext is missing. Fieldset parts must be placed within <Fieldset.Root>."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return context;
|
|
38
|
+
}
|
|
39
|
+
function FieldsetRoot(props) {
|
|
40
|
+
const slot = (0, import_internal.S)("FieldsetRoot");
|
|
41
|
+
const { render, className, style, disabled: disabledProp = false, ref, ...elementProps } = props;
|
|
42
|
+
const [legendId, setLegendId] = (0, import_octane.useState)(
|
|
43
|
+
void 0,
|
|
44
|
+
(0, import_internal.subSlot)(slot, "legendId")
|
|
45
|
+
);
|
|
46
|
+
const parentDisabled = useFieldsetRootContext(true)?.disabled;
|
|
47
|
+
const disabled = parentDisabled || disabledProp;
|
|
48
|
+
const state = { disabled };
|
|
49
|
+
const element = (0, import_useRenderElement.useRenderElement)(
|
|
50
|
+
"fieldset",
|
|
51
|
+
{ render, className, style },
|
|
52
|
+
{
|
|
53
|
+
ref,
|
|
54
|
+
state,
|
|
55
|
+
props: [{ "aria-labelledby": legendId, disabled }, elementProps]
|
|
56
|
+
},
|
|
57
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
58
|
+
);
|
|
59
|
+
const contextValue = (0, import_octane.useMemo)(
|
|
60
|
+
() => ({ legendId, setLegendId, disabled }),
|
|
61
|
+
[legendId, setLegendId, disabled],
|
|
62
|
+
(0, import_internal.subSlot)(slot, "ctx")
|
|
63
|
+
);
|
|
64
|
+
return (0, import_octane.createElement)(FieldsetRootContext.Provider, { value: contextValue, children: element });
|
|
65
|
+
}
|
|
66
|
+
function FieldsetLegend(props) {
|
|
67
|
+
const slot = (0, import_internal.S)("FieldsetLegend");
|
|
68
|
+
const { render, className, style, id: idProp, ref, ...elementProps } = props;
|
|
69
|
+
const { disabled, setLegendId } = useFieldsetRootContext();
|
|
70
|
+
const id = (0, import_useBaseUiId.useBaseUiId)(idProp, (0, import_internal.subSlot)(slot, "id"));
|
|
71
|
+
(0, import_octane.useLayoutEffect)(
|
|
72
|
+
() => {
|
|
73
|
+
setLegendId(id);
|
|
74
|
+
return () => {
|
|
75
|
+
setLegendId(void 0);
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
[setLegendId, id],
|
|
79
|
+
(0, import_internal.subSlot)(slot, "e:legendId")
|
|
80
|
+
);
|
|
81
|
+
const state = { disabled: disabled ?? false };
|
|
82
|
+
return (0, import_useRenderElement.useRenderElement)(
|
|
83
|
+
"div",
|
|
84
|
+
{ render, className, style },
|
|
85
|
+
{
|
|
86
|
+
state,
|
|
87
|
+
ref,
|
|
88
|
+
props: [{ id }, elementProps]
|
|
89
|
+
},
|
|
90
|
+
(0, import_internal.subSlot)(slot, "re")
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const Fieldset = {
|
|
94
|
+
Root: FieldsetRoot,
|
|
95
|
+
Legend: FieldsetLegend
|
|
96
|
+
};
|
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
+
0 && (module.exports = {
|
|
99
|
+
Fieldset,
|
|
100
|
+
useFieldsetRootContext
|
|
101
|
+
});
|