@radix-ui/react-form 0.0.1-rc.1
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 +13 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +575 -0
- package/dist/index.js.map +1 -0
- package/dist/index.module.js +554 -0
- package/dist/index.module.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Label } from "@radix-ui/react-label";
|
|
3
|
+
import * as Radix from "@radix-ui/react-primitive";
|
|
4
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
5
|
+
import { Scope } from "@radix-ui/react-context";
|
|
6
|
+
type ScopedProps<P> = P & {
|
|
7
|
+
__scopeForm?: Scope;
|
|
8
|
+
};
|
|
9
|
+
export const createFormScope: import("@radix-ui/react-context").CreateScope;
|
|
10
|
+
type PrimitiveFormProps = Radix.ComponentPropsWithoutRef<typeof Primitive.form>;
|
|
11
|
+
export interface FormProps extends PrimitiveFormProps {
|
|
12
|
+
onClearServerErrors?(): void;
|
|
13
|
+
}
|
|
14
|
+
export const Root: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
|
|
15
|
+
type PrimitiveDivProps = Radix.ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
16
|
+
export interface FormFieldProps extends PrimitiveDivProps {
|
|
17
|
+
name: string;
|
|
18
|
+
serverInvalid?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export const Field: React.ForwardRefExoticComponent<FormFieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
21
|
+
type LabelProps = Radix.ComponentPropsWithoutRef<typeof Label>;
|
|
22
|
+
export interface FormLabelProps extends LabelProps {
|
|
23
|
+
}
|
|
24
|
+
export const FormLabel: React.ForwardRefExoticComponent<FormLabelProps & React.RefAttributes<HTMLLabelElement>>;
|
|
25
|
+
type PrimitiveInputProps = Radix.ComponentPropsWithoutRef<typeof Primitive.input>;
|
|
26
|
+
export interface FormControlProps extends PrimitiveInputProps {
|
|
27
|
+
}
|
|
28
|
+
export const Control: React.ForwardRefExoticComponent<FormControlProps & React.RefAttributes<HTMLInputElement>>;
|
|
29
|
+
declare const validityMatchers: readonly ["badInput", "patternMismatch", "rangeOverflow", "rangeUnderflow", "stepMismatch", "tooLong", "tooShort", "typeMismatch", "valid", "valueMissing"];
|
|
30
|
+
type ValidityMatcher = typeof validityMatchers[number];
|
|
31
|
+
export interface FormMessageProps extends Omit<FormMessageImplProps, 'name'> {
|
|
32
|
+
match?: ValidityMatcher | CustomMatcher;
|
|
33
|
+
forceMatch?: boolean;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export const Message: React.ForwardRefExoticComponent<FormMessageProps & React.RefAttributes<HTMLSpanElement>>;
|
|
37
|
+
type PrimitiveSpanProps = Radix.ComponentPropsWithoutRef<typeof Primitive.span>;
|
|
38
|
+
interface FormMessageImplProps extends PrimitiveSpanProps {
|
|
39
|
+
name: string;
|
|
40
|
+
}
|
|
41
|
+
export interface FormValidityStateProps {
|
|
42
|
+
children(validity: ValidityState | undefined): React.ReactNode;
|
|
43
|
+
name?: string;
|
|
44
|
+
}
|
|
45
|
+
export const ValidityState: {
|
|
46
|
+
(props: ScopedProps<FormValidityStateProps>): JSX.Element;
|
|
47
|
+
displayName: string;
|
|
48
|
+
};
|
|
49
|
+
type PrimitiveButtonProps = Radix.ComponentPropsWithoutRef<typeof Primitive.button>;
|
|
50
|
+
export interface FormSubmitProps extends PrimitiveButtonProps {
|
|
51
|
+
}
|
|
52
|
+
export const Submit: React.ForwardRefExoticComponent<FormSubmitProps & React.RefAttributes<HTMLButtonElement>>;
|
|
53
|
+
type SyncCustomMatcher = (value: string, formData: FormData) => boolean;
|
|
54
|
+
type AsyncCustomMatcher = (value: string, formData: FormData) => Promise<boolean>;
|
|
55
|
+
type CustomMatcher = SyncCustomMatcher | AsyncCustomMatcher;
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAWA,iBAAiB,CAAC,IAAI,CAAC,GAAG;IAAE,WAAW,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAClD,OAAA,sFAAuE,CAAC;AAuCxE,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,0BAAoB,SAAQ,kBAAkB;IAC5C,mBAAmB,CAAC,IAAI,IAAI,CAAC;CAC9B;AAED,OAAA,MAAM,uFAiIL,CAAC;AAmBF,yBAAyB,MAAM,wBAAwB,CAAC,OAAO,UAAU,GAAG,CAAC,CAAC;AAC9E,+BAAyB,SAAQ,iBAAiB;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,OAAA,MAAM,4FAkBL,CAAC;AAWF,kBAAkB,MAAM,wBAAwB,CAAC,YAAY,CAAC,CAAC;AAC/D,+BAAyB,SAAQ,UAAU;CAAG;AAE9C,OAAA,MAAM,kGAkBL,CAAC;AAWF,2BAA2B,MAAM,wBAAwB,CAAC,OAAO,UAAU,KAAK,CAAC,CAAC;AAClF,iCAA2B,SAAQ,mBAAmB;CAAG;AAEzD,OAAA,MAAM,kGA+IL,CAAC;AAQF,QAAA,MAAM,6KAWI,CAAC;AACX,uBAAuB,uBAAuB,CAAC,MAAM,CAAC,CAAC;AAmBvD,iCAA2B,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACnE,KAAK,CAAC,EAAE,eAAe,GAAG,aAAa,CAAC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,OAAA,MAAM,iGAkBL,CAAC;AAwEF,0BAA0B,MAAM,wBAAwB,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC;AAChF,8BAA+B,SAAQ,kBAAkB;IACvD,IAAI,EAAE,MAAM,CAAC;CACd;AAyBD;IACE,QAAQ,CAAC,QAAQ,EAAE,aAAa,GAAG,SAAS,GAAG,MAAM,SAAS,CAAC;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,OAAA,MAAM;YAA4B,YAAY,sBAAsB,CAAC;;CAOpE,CAAC;AAWF,4BAA4B,MAAM,wBAAwB,CAAC,OAAO,UAAU,MAAM,CAAC,CAAC;AACpF,gCAA0B,SAAQ,oBAAoB;CAAG;AAEzD,OAAA,MAAM,iGAKL,CAAC;AAOF,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC;AACxE,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAClF,qBAAqB,iBAAiB,GAAG,kBAAkB,CAAC","sources":["packages/react/form/src/packages/react/form/src/Form.tsx","packages/react/form/src/packages/react/form/src/index.ts","packages/react/form/src/index.ts"],"sourcesContent":[null,null,"export {\n createFormScope,\n //\n Form,\n FormField,\n FormLabel,\n FormControl,\n FormMessage,\n FormValidityState,\n FormSubmit,\n //\n Root,\n Field,\n Label,\n Control,\n Message,\n ValidityState,\n Submit,\n} from './Form';\n\nexport type {\n FormProps,\n FormFieldProps,\n FormLabelProps,\n FormControlProps,\n FormMessageProps,\n FormValidityStateProps,\n FormSubmitProps,\n} from './Form';\n"],"names":[],"version":3,"file":"index.d.ts.map"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
var $c9wdm$babelruntimehelpersextends = require("@babel/runtime/helpers/extends");
|
|
2
|
+
var $c9wdm$react = require("react");
|
|
3
|
+
var $c9wdm$radixuiprimitive = require("@radix-ui/primitive");
|
|
4
|
+
var $c9wdm$radixuireactcomposerefs = require("@radix-ui/react-compose-refs");
|
|
5
|
+
var $c9wdm$radixuireactcontext = require("@radix-ui/react-context");
|
|
6
|
+
var $c9wdm$radixuireactid = require("@radix-ui/react-id");
|
|
7
|
+
var $c9wdm$radixuireactlabel = require("@radix-ui/react-label");
|
|
8
|
+
var $c9wdm$radixuireactprimitive = require("@radix-ui/react-primitive");
|
|
9
|
+
|
|
10
|
+
function $parcel$export(e, n, v, s) {
|
|
11
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
|
+
}
|
|
13
|
+
function $parcel$interopDefault(a) {
|
|
14
|
+
return a && a.__esModule ? a.default : a;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$parcel$export(module.exports, "createFormScope", () => $5bb15a153bd9c45e$export$299997c7551e97cb);
|
|
18
|
+
$parcel$export(module.exports, "Form", () => $5bb15a153bd9c45e$export$a7fed597f4b8afd8);
|
|
19
|
+
$parcel$export(module.exports, "FormField", () => $5bb15a153bd9c45e$export$56e87bf42978147a);
|
|
20
|
+
$parcel$export(module.exports, "FormLabel", () => $5bb15a153bd9c45e$export$842aba50ed0ce9d7);
|
|
21
|
+
$parcel$export(module.exports, "FormControl", () => $5bb15a153bd9c45e$export$fe5d99d8691b3f62);
|
|
22
|
+
$parcel$export(module.exports, "FormMessage", () => $5bb15a153bd9c45e$export$2e8ae7a1a126169a);
|
|
23
|
+
$parcel$export(module.exports, "FormValidityState", () => $5bb15a153bd9c45e$export$7a93102810e06862);
|
|
24
|
+
$parcel$export(module.exports, "FormSubmit", () => $5bb15a153bd9c45e$export$d0861e5bd09bd9e4);
|
|
25
|
+
$parcel$export(module.exports, "Root", () => $5bb15a153bd9c45e$export$a7fed597f4b8afd8);
|
|
26
|
+
$parcel$export(module.exports, "Field", () => $5bb15a153bd9c45e$export$56e87bf42978147a);
|
|
27
|
+
$parcel$export(module.exports, "Label", () => $5bb15a153bd9c45e$export$842aba50ed0ce9d7);
|
|
28
|
+
$parcel$export(module.exports, "Control", () => $5bb15a153bd9c45e$export$fe5d99d8691b3f62);
|
|
29
|
+
$parcel$export(module.exports, "Message", () => $5bb15a153bd9c45e$export$2e8ae7a1a126169a);
|
|
30
|
+
$parcel$export(module.exports, "ValidityState", () => $5bb15a153bd9c45e$export$7a93102810e06862);
|
|
31
|
+
$parcel$export(module.exports, "Submit", () => $5bb15a153bd9c45e$export$d0861e5bd09bd9e4);
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const [$5bb15a153bd9c45e$var$createFormContext, $5bb15a153bd9c45e$export$299997c7551e97cb] = $c9wdm$radixuireactcontext.createContextScope('Form');
|
|
41
|
+
/* -------------------------------------------------------------------------------------------------
|
|
42
|
+
* Form
|
|
43
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$FORM_NAME = 'Form';
|
|
44
|
+
const [$5bb15a153bd9c45e$var$ValidationProvider, $5bb15a153bd9c45e$var$useValidationContext] = $5bb15a153bd9c45e$var$createFormContext($5bb15a153bd9c45e$var$FORM_NAME);
|
|
45
|
+
const [$5bb15a153bd9c45e$var$AriaDescriptionProvider, $5bb15a153bd9c45e$var$useAriaDescriptionContext] = $5bb15a153bd9c45e$var$createFormContext($5bb15a153bd9c45e$var$FORM_NAME);
|
|
46
|
+
const $5bb15a153bd9c45e$export$a7fed597f4b8afd8 = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
47
|
+
const { __scopeForm: __scopeForm , onClearServerErrors: onClearServerErrors = ()=>{} , ...rootProps } = props;
|
|
48
|
+
const formRef = $c9wdm$react.useRef(null);
|
|
49
|
+
const composedFormRef = $c9wdm$radixuireactcomposerefs.useComposedRefs(forwardedRef, formRef); // native validity per field
|
|
50
|
+
const [validityMap, setValidityMap] = $c9wdm$react.useState({});
|
|
51
|
+
const getFieldValidity = $c9wdm$react.useCallback((fieldName)=>validityMap[fieldName]
|
|
52
|
+
, [
|
|
53
|
+
validityMap
|
|
54
|
+
]);
|
|
55
|
+
const handleFieldValidityChange = $c9wdm$react.useCallback((fieldName, validity)=>setValidityMap((prevValidityMap)=>{
|
|
56
|
+
var _prevValidityMap$fiel;
|
|
57
|
+
return {
|
|
58
|
+
...prevValidityMap,
|
|
59
|
+
[fieldName]: {
|
|
60
|
+
...(_prevValidityMap$fiel = prevValidityMap[fieldName]) !== null && _prevValidityMap$fiel !== void 0 ? _prevValidityMap$fiel : {},
|
|
61
|
+
...validity
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
})
|
|
65
|
+
, []);
|
|
66
|
+
const handleFieldValiditionClear = $c9wdm$react.useCallback((fieldName)=>{
|
|
67
|
+
setValidityMap((prevValidityMap)=>({
|
|
68
|
+
...prevValidityMap,
|
|
69
|
+
[fieldName]: undefined
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
setCustomErrorsMap((prevCustomErrorsMap)=>({
|
|
73
|
+
...prevCustomErrorsMap,
|
|
74
|
+
[fieldName]: {}
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
}, []); // custom matcher entries per field
|
|
78
|
+
const [customMatcherEntriesMap, setCustomMatcherEntriesMap] = $c9wdm$react.useState({});
|
|
79
|
+
const getFieldCustomMatcherEntries = $c9wdm$react.useCallback((fieldName)=>{
|
|
80
|
+
var _customMatcherEntries;
|
|
81
|
+
return (_customMatcherEntries = customMatcherEntriesMap[fieldName]) !== null && _customMatcherEntries !== void 0 ? _customMatcherEntries : [];
|
|
82
|
+
}, [
|
|
83
|
+
customMatcherEntriesMap
|
|
84
|
+
]);
|
|
85
|
+
const handleFieldCustomMatcherAdd = $c9wdm$react.useCallback((fieldName, matcherEntry)=>{
|
|
86
|
+
setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap)=>{
|
|
87
|
+
var _prevCustomMatcherEnt;
|
|
88
|
+
return {
|
|
89
|
+
...prevCustomMatcherEntriesMap,
|
|
90
|
+
[fieldName]: [
|
|
91
|
+
...(_prevCustomMatcherEnt = prevCustomMatcherEntriesMap[fieldName]) !== null && _prevCustomMatcherEnt !== void 0 ? _prevCustomMatcherEnt : [],
|
|
92
|
+
matcherEntry
|
|
93
|
+
]
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}, []);
|
|
97
|
+
const handleFieldCustomMatcherRemove = $c9wdm$react.useCallback((fieldName, matcherEntryId)=>{
|
|
98
|
+
setCustomMatcherEntriesMap((prevCustomMatcherEntriesMap)=>{
|
|
99
|
+
var _prevCustomMatcherEnt2;
|
|
100
|
+
return {
|
|
101
|
+
...prevCustomMatcherEntriesMap,
|
|
102
|
+
[fieldName]: ((_prevCustomMatcherEnt2 = prevCustomMatcherEntriesMap[fieldName]) !== null && _prevCustomMatcherEnt2 !== void 0 ? _prevCustomMatcherEnt2 : []).filter((matcherEntry)=>matcherEntry.id !== matcherEntryId
|
|
103
|
+
)
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}, []); // custom errors per field
|
|
107
|
+
const [customErrorsMap, setCustomErrorsMap] = $c9wdm$react.useState({});
|
|
108
|
+
const getFieldCustomErrors = $c9wdm$react.useCallback((fieldName)=>{
|
|
109
|
+
var _customErrorsMap$fiel;
|
|
110
|
+
return (_customErrorsMap$fiel = customErrorsMap[fieldName]) !== null && _customErrorsMap$fiel !== void 0 ? _customErrorsMap$fiel : {};
|
|
111
|
+
}, [
|
|
112
|
+
customErrorsMap
|
|
113
|
+
]);
|
|
114
|
+
const handleFieldCustomErrorsChange = $c9wdm$react.useCallback((fieldName, customErrors)=>{
|
|
115
|
+
setCustomErrorsMap((prevCustomErrorsMap)=>{
|
|
116
|
+
var _prevCustomErrorsMap$;
|
|
117
|
+
return {
|
|
118
|
+
...prevCustomErrorsMap,
|
|
119
|
+
[fieldName]: {
|
|
120
|
+
...(_prevCustomErrorsMap$ = prevCustomErrorsMap[fieldName]) !== null && _prevCustomErrorsMap$ !== void 0 ? _prevCustomErrorsMap$ : {},
|
|
121
|
+
...customErrors
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}, []); // messageIds per field
|
|
126
|
+
const [messageIdsMap, setMessageIdsMap] = $c9wdm$react.useState({});
|
|
127
|
+
const handleFieldMessageIdAdd = $c9wdm$react.useCallback((fieldName, id)=>{
|
|
128
|
+
setMessageIdsMap((prevMessageIdsMap)=>{
|
|
129
|
+
const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]).add(id);
|
|
130
|
+
return {
|
|
131
|
+
...prevMessageIdsMap,
|
|
132
|
+
[fieldName]: fieldDescriptionIds
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
}, []);
|
|
136
|
+
const handleFieldMessageIdRemove = $c9wdm$react.useCallback((fieldName, id)=>{
|
|
137
|
+
setMessageIdsMap((prevMessageIdsMap)=>{
|
|
138
|
+
const fieldDescriptionIds = new Set(prevMessageIdsMap[fieldName]);
|
|
139
|
+
fieldDescriptionIds.delete(id);
|
|
140
|
+
return {
|
|
141
|
+
...prevMessageIdsMap,
|
|
142
|
+
[fieldName]: fieldDescriptionIds
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}, []);
|
|
146
|
+
const getFieldDescription = $c9wdm$react.useCallback((fieldName)=>{
|
|
147
|
+
var _messageIdsMap$fieldN;
|
|
148
|
+
return Array.from((_messageIdsMap$fieldN = messageIdsMap[fieldName]) !== null && _messageIdsMap$fieldN !== void 0 ? _messageIdsMap$fieldN : []).join(' ') || undefined;
|
|
149
|
+
}, [
|
|
150
|
+
messageIdsMap
|
|
151
|
+
]);
|
|
152
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$ValidationProvider, {
|
|
153
|
+
scope: __scopeForm,
|
|
154
|
+
getFieldValidity: getFieldValidity,
|
|
155
|
+
onFieldValidityChange: handleFieldValidityChange,
|
|
156
|
+
getFieldCustomMatcherEntries: getFieldCustomMatcherEntries,
|
|
157
|
+
onFieldCustomMatcherEntryAdd: handleFieldCustomMatcherAdd,
|
|
158
|
+
onFieldCustomMatcherEntryRemove: handleFieldCustomMatcherRemove,
|
|
159
|
+
getFieldCustomErrors: getFieldCustomErrors,
|
|
160
|
+
onFieldCustomErrorsChange: handleFieldCustomErrorsChange,
|
|
161
|
+
onFieldValiditionClear: handleFieldValiditionClear
|
|
162
|
+
}, /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$AriaDescriptionProvider, {
|
|
163
|
+
scope: __scopeForm,
|
|
164
|
+
onFieldMessageIdAdd: handleFieldMessageIdAdd,
|
|
165
|
+
onFieldMessageIdRemove: handleFieldMessageIdRemove,
|
|
166
|
+
getFieldDescription: getFieldDescription
|
|
167
|
+
}, /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactprimitive.Primitive.form, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({}, rootProps, {
|
|
168
|
+
ref: composedFormRef // focus first invalid control when the form is submitted
|
|
169
|
+
,
|
|
170
|
+
onInvalid: $c9wdm$radixuiprimitive.composeEventHandlers(props.onInvalid, (event)=>{
|
|
171
|
+
const firstInvalidControl = $5bb15a153bd9c45e$var$getFirstInvalidControl(event.currentTarget);
|
|
172
|
+
if (firstInvalidControl === event.target) firstInvalidControl.focus(); // prevent default browser UI for form validation
|
|
173
|
+
event.preventDefault();
|
|
174
|
+
}) // clear server errors when the form is re-submitted
|
|
175
|
+
,
|
|
176
|
+
onSubmit: $c9wdm$radixuiprimitive.composeEventHandlers(props.onSubmit, onClearServerErrors, {
|
|
177
|
+
checkForDefaultPrevented: false
|
|
178
|
+
}) // clear server errors when the form is reset
|
|
179
|
+
,
|
|
180
|
+
onReset: $c9wdm$radixuiprimitive.composeEventHandlers(props.onReset, onClearServerErrors)
|
|
181
|
+
}))));
|
|
182
|
+
});
|
|
183
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$a7fed597f4b8afd8, {
|
|
184
|
+
displayName: $5bb15a153bd9c45e$var$FORM_NAME
|
|
185
|
+
});
|
|
186
|
+
/* -------------------------------------------------------------------------------------------------
|
|
187
|
+
* FormField
|
|
188
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$FIELD_NAME = 'FormField';
|
|
189
|
+
const [$5bb15a153bd9c45e$var$FormFieldProvider, $5bb15a153bd9c45e$var$useFormFieldContext] = $5bb15a153bd9c45e$var$createFormContext($5bb15a153bd9c45e$var$FIELD_NAME);
|
|
190
|
+
const $5bb15a153bd9c45e$export$56e87bf42978147a = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
191
|
+
const { __scopeForm: __scopeForm , name: name , serverInvalid: serverInvalid = false , ...fieldProps } = props;
|
|
192
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$FIELD_NAME, __scopeForm);
|
|
193
|
+
const validity = validationContext.getFieldValidity(name);
|
|
194
|
+
const id = $c9wdm$radixuireactid.useId();
|
|
195
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormFieldProvider, {
|
|
196
|
+
scope: __scopeForm,
|
|
197
|
+
id: id,
|
|
198
|
+
name: name,
|
|
199
|
+
serverInvalid: serverInvalid
|
|
200
|
+
}, /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactprimitive.Primitive.div, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
201
|
+
"data-valid": $5bb15a153bd9c45e$var$getValidAttribute(validity, serverInvalid),
|
|
202
|
+
"data-invalid": $5bb15a153bd9c45e$var$getInvalidAttribute(validity, serverInvalid)
|
|
203
|
+
}, fieldProps, {
|
|
204
|
+
ref: forwardedRef
|
|
205
|
+
})));
|
|
206
|
+
});
|
|
207
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$56e87bf42978147a, {
|
|
208
|
+
displayName: $5bb15a153bd9c45e$var$FIELD_NAME
|
|
209
|
+
});
|
|
210
|
+
/* -------------------------------------------------------------------------------------------------
|
|
211
|
+
* FormLabel
|
|
212
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$LABEL_NAME = 'FormLabel';
|
|
213
|
+
const $5bb15a153bd9c45e$export$842aba50ed0ce9d7 = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
214
|
+
const { __scopeForm: __scopeForm , ...labelProps } = props;
|
|
215
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$LABEL_NAME, __scopeForm);
|
|
216
|
+
const fieldContext = $5bb15a153bd9c45e$var$useFormFieldContext($5bb15a153bd9c45e$var$LABEL_NAME, __scopeForm);
|
|
217
|
+
const htmlFor = labelProps.htmlFor || fieldContext.id;
|
|
218
|
+
const validity = validationContext.getFieldValidity(fieldContext.name);
|
|
219
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactlabel.Label, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
220
|
+
"data-valid": $5bb15a153bd9c45e$var$getValidAttribute(validity, fieldContext.serverInvalid),
|
|
221
|
+
"data-invalid": $5bb15a153bd9c45e$var$getInvalidAttribute(validity, fieldContext.serverInvalid)
|
|
222
|
+
}, labelProps, {
|
|
223
|
+
ref: forwardedRef,
|
|
224
|
+
htmlFor: htmlFor
|
|
225
|
+
}));
|
|
226
|
+
});
|
|
227
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$842aba50ed0ce9d7, {
|
|
228
|
+
displayName: $5bb15a153bd9c45e$var$LABEL_NAME
|
|
229
|
+
});
|
|
230
|
+
/* -------------------------------------------------------------------------------------------------
|
|
231
|
+
* FormControl
|
|
232
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$CONTROL_NAME = 'FormControl';
|
|
233
|
+
const $5bb15a153bd9c45e$export$fe5d99d8691b3f62 = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
234
|
+
const { __scopeForm: __scopeForm , ...controlProps } = props;
|
|
235
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$CONTROL_NAME, __scopeForm);
|
|
236
|
+
const fieldContext = $5bb15a153bd9c45e$var$useFormFieldContext($5bb15a153bd9c45e$var$CONTROL_NAME, __scopeForm);
|
|
237
|
+
const ariaDescriptionContext = $5bb15a153bd9c45e$var$useAriaDescriptionContext($5bb15a153bd9c45e$var$CONTROL_NAME, __scopeForm);
|
|
238
|
+
const ref = $c9wdm$react.useRef(null);
|
|
239
|
+
const composedRef = $c9wdm$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
|
|
240
|
+
const name = controlProps.name || fieldContext.name;
|
|
241
|
+
const id1 = controlProps.id || fieldContext.id;
|
|
242
|
+
const customMatcherEntries = validationContext.getFieldCustomMatcherEntries(name);
|
|
243
|
+
const { onFieldValidityChange: onFieldValidityChange , onFieldCustomErrorsChange: onFieldCustomErrorsChange , onFieldValiditionClear: onFieldValiditionClear } = validationContext;
|
|
244
|
+
const updateControlValidity = $c9wdm$react.useCallback(async (control)=>{
|
|
245
|
+
//------------------------------------------------------------------------------------------
|
|
246
|
+
// 1. first, if we have built-in errors we stop here
|
|
247
|
+
if ($5bb15a153bd9c45e$var$hasBuiltInError(control.validity)) {
|
|
248
|
+
const controlValidity = $5bb15a153bd9c45e$var$validityStateToObject(control.validity);
|
|
249
|
+
onFieldValidityChange(name, controlValidity);
|
|
250
|
+
return;
|
|
251
|
+
} //------------------------------------------------------------------------------------------
|
|
252
|
+
// 2. then gather the form data to give to custom matchers for cross-comparisons
|
|
253
|
+
const formData = control.form ? new FormData(control.form) : new FormData();
|
|
254
|
+
const matcherArgs = [
|
|
255
|
+
control.value,
|
|
256
|
+
formData
|
|
257
|
+
]; //------------------------------------------------------------------------------------------
|
|
258
|
+
// 3. split sync and async custom matcher entries
|
|
259
|
+
const syncCustomMatcherEntries = [];
|
|
260
|
+
const ayncCustomMatcherEntries = [];
|
|
261
|
+
customMatcherEntries.forEach((customMatcherEntry)=>{
|
|
262
|
+
if ($5bb15a153bd9c45e$var$isAsyncCustomMatcherEntry(customMatcherEntry, matcherArgs)) ayncCustomMatcherEntries.push(customMatcherEntry);
|
|
263
|
+
else if ($5bb15a153bd9c45e$var$isSyncCustomMatcherEntry(customMatcherEntry)) syncCustomMatcherEntries.push(customMatcherEntry);
|
|
264
|
+
}); //------------------------------------------------------------------------------------------
|
|
265
|
+
// 4. run sync custom matchers and update control validity / internal validity + errors
|
|
266
|
+
const syncCustomErrors = syncCustomMatcherEntries.map(({ id: id , match: match })=>{
|
|
267
|
+
return [
|
|
268
|
+
id,
|
|
269
|
+
match(...matcherArgs)
|
|
270
|
+
];
|
|
271
|
+
});
|
|
272
|
+
const syncCustomErrorsById = Object.fromEntries(syncCustomErrors);
|
|
273
|
+
const hasSyncCustomErrors = Object.values(syncCustomErrorsById).some(Boolean);
|
|
274
|
+
const hasCustomError = hasSyncCustomErrors;
|
|
275
|
+
control.setCustomValidity(hasCustomError ? $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE : '');
|
|
276
|
+
const controlValidity = $5bb15a153bd9c45e$var$validityStateToObject(control.validity);
|
|
277
|
+
onFieldValidityChange(name, controlValidity);
|
|
278
|
+
onFieldCustomErrorsChange(name, syncCustomErrorsById); //------------------------------------------------------------------------------------------
|
|
279
|
+
// 5. run async custom matchers and update control validity / internal validity + errors
|
|
280
|
+
if (!hasSyncCustomErrors && ayncCustomMatcherEntries.length > 0) {
|
|
281
|
+
const promisedCustomErrors = ayncCustomMatcherEntries.map(({ id: id , match: match })=>match(...matcherArgs).then((matches)=>[
|
|
282
|
+
id,
|
|
283
|
+
matches
|
|
284
|
+
]
|
|
285
|
+
)
|
|
286
|
+
);
|
|
287
|
+
const asyncCustomErrors = await Promise.all(promisedCustomErrors);
|
|
288
|
+
const asyncCustomErrorsById = Object.fromEntries(asyncCustomErrors);
|
|
289
|
+
const hasAsyncCustomErrors = Object.values(asyncCustomErrorsById).some(Boolean);
|
|
290
|
+
const hasCustomError = hasAsyncCustomErrors;
|
|
291
|
+
control.setCustomValidity(hasCustomError ? $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE : '');
|
|
292
|
+
const controlValidity = $5bb15a153bd9c45e$var$validityStateToObject(control.validity);
|
|
293
|
+
onFieldValidityChange(name, controlValidity);
|
|
294
|
+
onFieldCustomErrorsChange(name, asyncCustomErrorsById);
|
|
295
|
+
}
|
|
296
|
+
}, [
|
|
297
|
+
customMatcherEntries,
|
|
298
|
+
name,
|
|
299
|
+
onFieldCustomErrorsChange,
|
|
300
|
+
onFieldValidityChange
|
|
301
|
+
]);
|
|
302
|
+
$c9wdm$react.useEffect(()=>{
|
|
303
|
+
const control = ref.current;
|
|
304
|
+
if (control) {
|
|
305
|
+
// We only want validate on change (native `change` event, not React's `onChange`). This is primarily
|
|
306
|
+
// a UX decision, we don't want to validate on every keystroke and React's `onChange` is the `input` event.
|
|
307
|
+
const handleChange = ()=>updateControlValidity(control)
|
|
308
|
+
;
|
|
309
|
+
control.addEventListener('change', handleChange);
|
|
310
|
+
return ()=>control.removeEventListener('change', handleChange)
|
|
311
|
+
;
|
|
312
|
+
}
|
|
313
|
+
}, [
|
|
314
|
+
updateControlValidity
|
|
315
|
+
]);
|
|
316
|
+
const resetControlValidity = $c9wdm$react.useCallback(()=>{
|
|
317
|
+
const control = ref.current;
|
|
318
|
+
if (control) {
|
|
319
|
+
control.setCustomValidity('');
|
|
320
|
+
onFieldValiditionClear(name);
|
|
321
|
+
}
|
|
322
|
+
}, [
|
|
323
|
+
name,
|
|
324
|
+
onFieldValiditionClear
|
|
325
|
+
]); // reset validity and errors when the form is reset
|
|
326
|
+
$c9wdm$react.useEffect(()=>{
|
|
327
|
+
var _ref$current;
|
|
328
|
+
const form = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.form;
|
|
329
|
+
if (form) {
|
|
330
|
+
form.addEventListener('reset', resetControlValidity);
|
|
331
|
+
return ()=>form.removeEventListener('reset', resetControlValidity)
|
|
332
|
+
;
|
|
333
|
+
}
|
|
334
|
+
}, [
|
|
335
|
+
resetControlValidity
|
|
336
|
+
]); // focus first invalid control when fields are set as invalid by server
|
|
337
|
+
$c9wdm$react.useEffect(()=>{
|
|
338
|
+
const control = ref.current;
|
|
339
|
+
const form = control === null || control === void 0 ? void 0 : control.closest('form');
|
|
340
|
+
if (form && fieldContext.serverInvalid) {
|
|
341
|
+
const firstInvalidControl = $5bb15a153bd9c45e$var$getFirstInvalidControl(form);
|
|
342
|
+
if (firstInvalidControl === control) firstInvalidControl.focus();
|
|
343
|
+
}
|
|
344
|
+
}, [
|
|
345
|
+
fieldContext.serverInvalid
|
|
346
|
+
]);
|
|
347
|
+
const validity = validationContext.getFieldValidity(name);
|
|
348
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactprimitive.Primitive.input, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
349
|
+
"data-valid": $5bb15a153bd9c45e$var$getValidAttribute(validity, fieldContext.serverInvalid),
|
|
350
|
+
"data-invalid": $5bb15a153bd9c45e$var$getInvalidAttribute(validity, fieldContext.serverInvalid),
|
|
351
|
+
"aria-invalid": fieldContext.serverInvalid ? true : undefined,
|
|
352
|
+
"aria-describedby": ariaDescriptionContext.getFieldDescription(name) // disable default browser behaviour of showing built-in error message on hover
|
|
353
|
+
,
|
|
354
|
+
title: ""
|
|
355
|
+
}, controlProps, {
|
|
356
|
+
ref: composedRef,
|
|
357
|
+
id: id1,
|
|
358
|
+
name: name,
|
|
359
|
+
onInvalid: $c9wdm$radixuiprimitive.composeEventHandlers(props.onInvalid, (event)=>{
|
|
360
|
+
const control = event.currentTarget;
|
|
361
|
+
updateControlValidity(control);
|
|
362
|
+
}),
|
|
363
|
+
onChange: $c9wdm$radixuiprimitive.composeEventHandlers(props.onChange, (event)=>{
|
|
364
|
+
// reset validity when user changes value
|
|
365
|
+
resetControlValidity();
|
|
366
|
+
})
|
|
367
|
+
}));
|
|
368
|
+
});
|
|
369
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$fe5d99d8691b3f62, {
|
|
370
|
+
displayName: $5bb15a153bd9c45e$var$CONTROL_NAME
|
|
371
|
+
});
|
|
372
|
+
/* -------------------------------------------------------------------------------------------------
|
|
373
|
+
* FormMessage
|
|
374
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$validityMatchers = [
|
|
375
|
+
'badInput',
|
|
376
|
+
'patternMismatch',
|
|
377
|
+
'rangeOverflow',
|
|
378
|
+
'rangeUnderflow',
|
|
379
|
+
'stepMismatch',
|
|
380
|
+
'tooLong',
|
|
381
|
+
'tooShort',
|
|
382
|
+
'typeMismatch',
|
|
383
|
+
'valid',
|
|
384
|
+
'valueMissing'
|
|
385
|
+
];
|
|
386
|
+
const $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE = 'This value is not valid';
|
|
387
|
+
const $5bb15a153bd9c45e$var$DEFAULT_BUILT_IN_MESSAGES = {
|
|
388
|
+
badInput: $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE,
|
|
389
|
+
patternMismatch: 'This value does not match the required pattern',
|
|
390
|
+
rangeOverflow: 'This value is too large',
|
|
391
|
+
rangeUnderflow: 'This value is too small',
|
|
392
|
+
stepMismatch: 'This value does not match the required step',
|
|
393
|
+
tooLong: 'This value is too long',
|
|
394
|
+
tooShort: 'This value is too short',
|
|
395
|
+
typeMismatch: 'This value does not match the required type',
|
|
396
|
+
valid: undefined,
|
|
397
|
+
valueMissing: 'This value is missing'
|
|
398
|
+
};
|
|
399
|
+
const $5bb15a153bd9c45e$var$MESSAGE_NAME = 'FormMessage';
|
|
400
|
+
const $5bb15a153bd9c45e$export$2e8ae7a1a126169a = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
401
|
+
const { match: match , name: nameProp , ...messageProps } = props;
|
|
402
|
+
const fieldContext = $5bb15a153bd9c45e$var$useFormFieldContext($5bb15a153bd9c45e$var$MESSAGE_NAME, props.__scopeForm);
|
|
403
|
+
const name = nameProp !== null && nameProp !== void 0 ? nameProp : fieldContext.name;
|
|
404
|
+
if (match === undefined) return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormMessageImpl, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({}, messageProps, {
|
|
405
|
+
ref: forwardedRef,
|
|
406
|
+
name: name
|
|
407
|
+
}), props.children || $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE);
|
|
408
|
+
else if (typeof match === 'function') return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormCustomMessage, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
409
|
+
match: match
|
|
410
|
+
}, messageProps, {
|
|
411
|
+
ref: forwardedRef,
|
|
412
|
+
name: name
|
|
413
|
+
}));
|
|
414
|
+
else return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormBuiltInMessage, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
415
|
+
match: match
|
|
416
|
+
}, messageProps, {
|
|
417
|
+
ref: forwardedRef,
|
|
418
|
+
name: name
|
|
419
|
+
}));
|
|
420
|
+
});
|
|
421
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$2e8ae7a1a126169a, {
|
|
422
|
+
displayName: $5bb15a153bd9c45e$var$MESSAGE_NAME
|
|
423
|
+
});
|
|
424
|
+
const $5bb15a153bd9c45e$var$FormBuiltInMessage = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
425
|
+
const { match: match , forceMatch: forceMatch = false , name: name , children: children , ...messageProps } = props;
|
|
426
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$MESSAGE_NAME, messageProps.__scopeForm);
|
|
427
|
+
const validity = validationContext.getFieldValidity(name);
|
|
428
|
+
const matches = forceMatch || (validity === null || validity === void 0 ? void 0 : validity[match]);
|
|
429
|
+
if (matches) return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormMessageImpl, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
430
|
+
ref: forwardedRef
|
|
431
|
+
}, messageProps, {
|
|
432
|
+
name: name
|
|
433
|
+
}), children !== null && children !== void 0 ? children : $5bb15a153bd9c45e$var$DEFAULT_BUILT_IN_MESSAGES[match]);
|
|
434
|
+
return null;
|
|
435
|
+
});
|
|
436
|
+
const $5bb15a153bd9c45e$var$FormCustomMessage = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
437
|
+
const { match: match , forceMatch: forceMatch = false , name: name , id: idProp , children: children , ...messageProps } = props;
|
|
438
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$MESSAGE_NAME, messageProps.__scopeForm);
|
|
439
|
+
const ref = $c9wdm$react.useRef(null);
|
|
440
|
+
const composedRef = $c9wdm$radixuireactcomposerefs.useComposedRefs(forwardedRef, ref);
|
|
441
|
+
const _id = $c9wdm$radixuireactid.useId();
|
|
442
|
+
const id = idProp !== null && idProp !== void 0 ? idProp : _id;
|
|
443
|
+
const customMatcherEntry = $c9wdm$react.useMemo(()=>({
|
|
444
|
+
id: id,
|
|
445
|
+
match: match
|
|
446
|
+
})
|
|
447
|
+
, [
|
|
448
|
+
id,
|
|
449
|
+
match
|
|
450
|
+
]);
|
|
451
|
+
const { onFieldCustomMatcherEntryAdd: onFieldCustomMatcherEntryAdd , onFieldCustomMatcherEntryRemove: onFieldCustomMatcherEntryRemove } = validationContext;
|
|
452
|
+
$c9wdm$react.useEffect(()=>{
|
|
453
|
+
onFieldCustomMatcherEntryAdd(name, customMatcherEntry);
|
|
454
|
+
return ()=>onFieldCustomMatcherEntryRemove(name, customMatcherEntry.id)
|
|
455
|
+
;
|
|
456
|
+
}, [
|
|
457
|
+
customMatcherEntry,
|
|
458
|
+
name,
|
|
459
|
+
onFieldCustomMatcherEntryAdd,
|
|
460
|
+
onFieldCustomMatcherEntryRemove
|
|
461
|
+
]);
|
|
462
|
+
const validity = validationContext.getFieldValidity(name);
|
|
463
|
+
const customErrors = validationContext.getFieldCustomErrors(name);
|
|
464
|
+
const hasMatchingCustomError = customErrors[id];
|
|
465
|
+
const matches = forceMatch || validity && !$5bb15a153bd9c45e$var$hasBuiltInError(validity) && hasMatchingCustomError;
|
|
466
|
+
if (matches) return /*#__PURE__*/ $c9wdm$react.createElement($5bb15a153bd9c45e$var$FormMessageImpl, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
467
|
+
id: id,
|
|
468
|
+
ref: composedRef
|
|
469
|
+
}, messageProps, {
|
|
470
|
+
name: name
|
|
471
|
+
}), children !== null && children !== void 0 ? children : $5bb15a153bd9c45e$var$DEFAULT_INVALID_MESSAGE);
|
|
472
|
+
return null;
|
|
473
|
+
});
|
|
474
|
+
const $5bb15a153bd9c45e$var$FormMessageImpl = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
475
|
+
const { __scopeForm: __scopeForm , id: idProp , name: name , ...messageProps } = props;
|
|
476
|
+
const ariaDescriptionContext = $5bb15a153bd9c45e$var$useAriaDescriptionContext($5bb15a153bd9c45e$var$MESSAGE_NAME, __scopeForm);
|
|
477
|
+
const _id = $c9wdm$radixuireactid.useId();
|
|
478
|
+
const id = idProp !== null && idProp !== void 0 ? idProp : _id;
|
|
479
|
+
const { onFieldMessageIdAdd: onFieldMessageIdAdd , onFieldMessageIdRemove: onFieldMessageIdRemove } = ariaDescriptionContext;
|
|
480
|
+
$c9wdm$react.useEffect(()=>{
|
|
481
|
+
onFieldMessageIdAdd(name, id);
|
|
482
|
+
return ()=>onFieldMessageIdRemove(name, id)
|
|
483
|
+
;
|
|
484
|
+
}, [
|
|
485
|
+
name,
|
|
486
|
+
id,
|
|
487
|
+
onFieldMessageIdAdd,
|
|
488
|
+
onFieldMessageIdRemove
|
|
489
|
+
]);
|
|
490
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactprimitive.Primitive.span, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
491
|
+
id: id
|
|
492
|
+
}, messageProps, {
|
|
493
|
+
ref: forwardedRef
|
|
494
|
+
}));
|
|
495
|
+
});
|
|
496
|
+
/* -------------------------------------------------------------------------------------------------
|
|
497
|
+
* FormValidityState
|
|
498
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$VALIDITY_STATE_NAME = 'FormValidityState';
|
|
499
|
+
const $5bb15a153bd9c45e$export$7a93102810e06862 = (props)=>{
|
|
500
|
+
const { __scopeForm: __scopeForm , name: nameProp , children: children } = props;
|
|
501
|
+
const validationContext = $5bb15a153bd9c45e$var$useValidationContext($5bb15a153bd9c45e$var$VALIDITY_STATE_NAME, __scopeForm);
|
|
502
|
+
const fieldContext = $5bb15a153bd9c45e$var$useFormFieldContext($5bb15a153bd9c45e$var$VALIDITY_STATE_NAME, __scopeForm);
|
|
503
|
+
const name = nameProp !== null && nameProp !== void 0 ? nameProp : fieldContext.name;
|
|
504
|
+
const validity = validationContext.getFieldValidity(name);
|
|
505
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$react.Fragment, null, children(validity));
|
|
506
|
+
};
|
|
507
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$7a93102810e06862, {
|
|
508
|
+
displayName: $5bb15a153bd9c45e$var$VALIDITY_STATE_NAME
|
|
509
|
+
});
|
|
510
|
+
/* -------------------------------------------------------------------------------------------------
|
|
511
|
+
* FormSubmit
|
|
512
|
+
* -----------------------------------------------------------------------------------------------*/ const $5bb15a153bd9c45e$var$SUBMIT_NAME = 'FormSubmit';
|
|
513
|
+
const $5bb15a153bd9c45e$export$d0861e5bd09bd9e4 = /*#__PURE__*/ $c9wdm$react.forwardRef((props, forwardedRef)=>{
|
|
514
|
+
const { __scopeForm: __scopeForm , ...submitProps } = props;
|
|
515
|
+
return /*#__PURE__*/ $c9wdm$react.createElement($c9wdm$radixuireactprimitive.Primitive.button, ($parcel$interopDefault($c9wdm$babelruntimehelpersextends))({
|
|
516
|
+
type: "submit"
|
|
517
|
+
}, submitProps, {
|
|
518
|
+
ref: forwardedRef
|
|
519
|
+
}));
|
|
520
|
+
});
|
|
521
|
+
/*#__PURE__*/ Object.assign($5bb15a153bd9c45e$export$d0861e5bd09bd9e4, {
|
|
522
|
+
displayName: $5bb15a153bd9c45e$var$SUBMIT_NAME
|
|
523
|
+
});
|
|
524
|
+
/* -----------------------------------------------------------------------------------------------*/ function $5bb15a153bd9c45e$var$validityStateToObject(validity) {
|
|
525
|
+
const object = {};
|
|
526
|
+
for(const key in validity)object[key] = validity[key];
|
|
527
|
+
return object;
|
|
528
|
+
}
|
|
529
|
+
function $5bb15a153bd9c45e$var$isHTMLElement(element) {
|
|
530
|
+
return element instanceof HTMLElement;
|
|
531
|
+
}
|
|
532
|
+
function $5bb15a153bd9c45e$var$isFormControl(element) {
|
|
533
|
+
return 'validity' in element;
|
|
534
|
+
}
|
|
535
|
+
function $5bb15a153bd9c45e$var$isInvalid(control) {
|
|
536
|
+
return $5bb15a153bd9c45e$var$isFormControl(control) && (control.validity.valid === false || control.getAttribute('aria-invalid') === 'true');
|
|
537
|
+
}
|
|
538
|
+
function $5bb15a153bd9c45e$var$getFirstInvalidControl(form) {
|
|
539
|
+
const elements = form.elements;
|
|
540
|
+
const [firstInvalidControl] = Array.from(elements).filter($5bb15a153bd9c45e$var$isHTMLElement).filter($5bb15a153bd9c45e$var$isInvalid);
|
|
541
|
+
return firstInvalidControl;
|
|
542
|
+
}
|
|
543
|
+
function $5bb15a153bd9c45e$var$isAsyncCustomMatcherEntry(entry, args) {
|
|
544
|
+
return entry.match.constructor.name === 'AsyncFunction' || $5bb15a153bd9c45e$var$returnsPromise(entry.match, args);
|
|
545
|
+
}
|
|
546
|
+
function $5bb15a153bd9c45e$var$isSyncCustomMatcherEntry(entry) {
|
|
547
|
+
return entry.match.constructor.name === 'Function';
|
|
548
|
+
}
|
|
549
|
+
function $5bb15a153bd9c45e$var$returnsPromise(func, args) {
|
|
550
|
+
return func(...args) instanceof Promise;
|
|
551
|
+
}
|
|
552
|
+
function $5bb15a153bd9c45e$var$hasBuiltInError(validity) {
|
|
553
|
+
let error = false;
|
|
554
|
+
for(const validityKey in validity){
|
|
555
|
+
const key = validityKey;
|
|
556
|
+
if (key !== 'valid' && key !== 'customError' && validity[key]) {
|
|
557
|
+
error = true;
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
return error;
|
|
562
|
+
}
|
|
563
|
+
function $5bb15a153bd9c45e$var$getValidAttribute(validity, serverInvalid) {
|
|
564
|
+
if ((validity === null || validity === void 0 ? void 0 : validity.valid) === true && !serverInvalid) return true;
|
|
565
|
+
return undefined;
|
|
566
|
+
}
|
|
567
|
+
function $5bb15a153bd9c45e$var$getInvalidAttribute(validity, serverInvalid) {
|
|
568
|
+
if ((validity === null || validity === void 0 ? void 0 : validity.valid) === false || serverInvalid) return true;
|
|
569
|
+
return undefined;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
//# sourceMappingURL=index.js.map
|