@tamagui/form 2.7.7 → 3.0.0-beta.643.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/dist/cjs/Form.cjs +223 -67
- package/dist/cjs/Form.native.cjs +347 -0
- package/dist/cjs/Form.native.js +326 -68
- package/dist/cjs/Form.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Form.mjs +200 -49
- package/dist/esm/Form.mjs.map +1 -1
- package/dist/esm/Form.native.js +303 -51
- package/dist/esm/Form.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Form.mjs +200 -49
- package/dist/jsx/Form.mjs.map +1 -1
- package/dist/jsx/Form.native.cjs +347 -0
- package/dist/jsx/Form.native.js +326 -68
- package/dist/jsx/Form.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +5 -4
- package/src/Form.tsx +318 -47
- package/types/Form.d.ts +63 -16
- package/types/Form.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/src/Form.tsx
CHANGED
|
@@ -1,48 +1,80 @@
|
|
|
1
|
-
import type { ViewProps } from '@tamagui/core'
|
|
2
|
-
import {
|
|
1
|
+
import type { TamaguiEventDetails, ViewProps } from '@tamagui/core'
|
|
2
|
+
import { createStyledContext, createStyledHOC, isWeb, styled, View } from '@tamagui/core'
|
|
3
|
+
import { focusFocusable } from '@tamagui/focusable'
|
|
3
4
|
import { composeEventHandlers, withStaticProperties } from '@tamagui/helpers'
|
|
5
|
+
import * as React from 'react'
|
|
4
6
|
|
|
5
7
|
const FORM_NAME = 'Form'
|
|
8
|
+
const EMPTY_ERRORS: FormErrors = {}
|
|
6
9
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export type FormValidationMode = 'onSubmit' | 'onBlur' | 'onChange'
|
|
11
|
+
export type FormErrors = Record<string, string | string[]>
|
|
12
|
+
export type FormValues = Record<string, any>
|
|
13
|
+
|
|
14
|
+
export type FormFieldRegistration = {
|
|
15
|
+
name?: string
|
|
16
|
+
controlId?: string
|
|
17
|
+
controlRef: React.MutableRefObject<any>
|
|
18
|
+
getValue: () => unknown
|
|
19
|
+
validate: () => void
|
|
20
|
+
validityData: {
|
|
21
|
+
state: {
|
|
22
|
+
valid: boolean | null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type FormRegistryContextValue = {
|
|
28
|
+
validationMode: FormValidationMode
|
|
29
|
+
errors: FormErrors
|
|
30
|
+
formElementRef: React.MutableRefObject<HTMLFormElement | null>
|
|
31
|
+
submitAttemptedRef: React.MutableRefObject<boolean>
|
|
32
|
+
clearErrors: (name?: string) => void
|
|
33
|
+
getValues: () => FormValues
|
|
34
|
+
registerField: (id: string, registration: FormFieldRegistration) => () => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const defaultSubmitAttemptedRef = { current: false }
|
|
38
|
+
const defaultFormElementRef = { current: null }
|
|
39
|
+
|
|
40
|
+
export const FormRegistryContext = React.createContext<FormRegistryContextValue>({
|
|
41
|
+
validationMode: 'onSubmit',
|
|
42
|
+
errors: EMPTY_ERRORS,
|
|
43
|
+
formElementRef: defaultFormElementRef,
|
|
44
|
+
submitAttemptedRef: defaultSubmitAttemptedRef,
|
|
45
|
+
clearErrors: () => {},
|
|
46
|
+
getValues: () => ({}),
|
|
47
|
+
registerField: () => () => {},
|
|
10
48
|
})
|
|
11
49
|
|
|
12
|
-
|
|
13
|
-
* Context
|
|
14
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
50
|
+
export const useFormRegistryContext = () => React.useContext(FormRegistryContext)
|
|
15
51
|
|
|
16
|
-
type
|
|
17
|
-
onSubmit?: () => unknown
|
|
52
|
+
type FormTriggerContextValue = {
|
|
53
|
+
onSubmit?: (event?: unknown) => unknown
|
|
18
54
|
}
|
|
19
55
|
|
|
20
|
-
export const FormContext = createStyledContext<
|
|
56
|
+
export const FormContext = createStyledContext<FormTriggerContextValue>({
|
|
21
57
|
onSubmit: undefined,
|
|
22
|
-
}
|
|
58
|
+
})
|
|
23
59
|
|
|
24
60
|
export const { useStyledContext: useFormContext, Provider: FormProvider } = FormContext
|
|
25
61
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
export type FormProps = ViewProps & FormExtraProps
|
|
31
|
-
|
|
32
|
-
/* -------------------------------------------------------------------------------------------------
|
|
33
|
-
* FormTrigger
|
|
34
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
62
|
+
export const FormFrame = styled(View, {
|
|
63
|
+
displayName: FORM_NAME,
|
|
64
|
+
render: 'form',
|
|
65
|
+
})
|
|
35
66
|
|
|
36
67
|
const FormTriggerFrame = styled(View, {
|
|
37
|
-
|
|
68
|
+
displayName: 'FormTrigger',
|
|
38
69
|
})
|
|
39
70
|
|
|
40
71
|
export interface FormTriggerProps extends ViewProps {
|
|
41
72
|
scope?: string
|
|
42
73
|
}
|
|
43
74
|
|
|
44
|
-
export const FormTrigger =
|
|
45
|
-
|
|
75
|
+
export const FormTrigger = createStyledHOC(
|
|
76
|
+
FormTriggerFrame,
|
|
77
|
+
(props: FormTriggerProps, forwardedRef) => {
|
|
46
78
|
const { scope, children, onPress, ...triggerProps } = props
|
|
47
79
|
const context = useFormContext(scope)
|
|
48
80
|
|
|
@@ -51,7 +83,7 @@ export const FormTrigger = FormTriggerFrame.styleable<FormTriggerProps>(
|
|
|
51
83
|
role="button"
|
|
52
84
|
{...triggerProps}
|
|
53
85
|
ref={forwardedRef}
|
|
54
|
-
onPress={composeEventHandlers(onPress, context.onSubmit)}
|
|
86
|
+
onPress={composeEventHandlers(onPress, context.onSubmit as any)}
|
|
55
87
|
>
|
|
56
88
|
{children}
|
|
57
89
|
</FormTriggerFrame>
|
|
@@ -59,28 +91,267 @@ export const FormTrigger = FormTriggerFrame.styleable<FormTriggerProps>(
|
|
|
59
91
|
}
|
|
60
92
|
)
|
|
61
93
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
94
|
+
export type FormSubmitEventDetails = TamaguiEventDetails<
|
|
95
|
+
'submit' | 'trigger-press',
|
|
96
|
+
unknown
|
|
97
|
+
>
|
|
98
|
+
|
|
99
|
+
export interface FormActions {
|
|
100
|
+
validate: (fieldName?: string) => void
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
type FormExtraProps<FormValue extends FormValues = FormValues> = {
|
|
104
|
+
scope?: string
|
|
105
|
+
validationMode?: FormValidationMode
|
|
106
|
+
errors?: FormErrors
|
|
107
|
+
actionsRef?: React.RefObject<FormActions | null>
|
|
108
|
+
onSubmit?: (values: FormValue, details: FormSubmitEventDetails) => void | Promise<void>
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type FormProps<FormValue extends FormValues = FormValues> = Omit<
|
|
112
|
+
ViewProps,
|
|
113
|
+
'onSubmit'
|
|
114
|
+
> &
|
|
115
|
+
FormExtraProps<FormValue>
|
|
116
|
+
|
|
117
|
+
function hasError(errors: FormErrors, name?: string) {
|
|
118
|
+
if (!name || !Object.hasOwn(errors, name)) {
|
|
119
|
+
return false
|
|
120
|
+
}
|
|
121
|
+
const error = errors[name]
|
|
122
|
+
return Array.isArray(error) ? error.length > 0 : Boolean(error)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const FormComponent = createStyledHOC(
|
|
126
|
+
FormFrame,
|
|
127
|
+
function Form(
|
|
128
|
+
{
|
|
129
|
+
scope,
|
|
130
|
+
validationMode = 'onSubmit',
|
|
131
|
+
errors: externalErrors,
|
|
132
|
+
actionsRef,
|
|
133
|
+
onSubmit,
|
|
134
|
+
...props
|
|
135
|
+
}: FormExtraProps,
|
|
136
|
+
forwardedRef
|
|
137
|
+
) {
|
|
138
|
+
const registryRef = React.useRef(new Map<string, FormFieldRegistration>())
|
|
139
|
+
const formElementRef = React.useRef<HTMLFormElement | null>(null)
|
|
140
|
+
const submittedRef = React.useRef(false)
|
|
141
|
+
const submitAttemptedRef = React.useRef(false)
|
|
142
|
+
const pendingSubmitDetailsRef = React.useRef<FormSubmitEventDetails | null>(null)
|
|
143
|
+
const onSubmitRef = React.useRef(onSubmit)
|
|
144
|
+
onSubmitRef.current = onSubmit
|
|
145
|
+
|
|
146
|
+
const [errors, setErrors] = React.useState<FormErrors>(externalErrors ?? EMPTY_ERRORS)
|
|
147
|
+
const errorsRef = React.useRef(errors)
|
|
148
|
+
errorsRef.current = errors
|
|
149
|
+
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
const next = externalErrors ?? EMPTY_ERRORS
|
|
152
|
+
errorsRef.current = next
|
|
153
|
+
setErrors(next)
|
|
154
|
+
}, [externalErrors])
|
|
155
|
+
|
|
156
|
+
const registerField = React.useCallback(
|
|
157
|
+
(id: string, registration: FormFieldRegistration) => {
|
|
158
|
+
registryRef.current.set(id, registration)
|
|
159
|
+
return () => {
|
|
160
|
+
if (registryRef.current.get(id) === registration) {
|
|
161
|
+
registryRef.current.delete(id)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
[]
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
const getValues = React.useCallback(() => {
|
|
169
|
+
const values: FormValues = {}
|
|
170
|
+
for (const field of registryRef.current.values()) {
|
|
171
|
+
if (field.name) {
|
|
172
|
+
values[field.name] = field.getValue()
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return values
|
|
176
|
+
}, [])
|
|
83
177
|
|
|
84
|
-
|
|
178
|
+
const clearErrors = React.useCallback((name?: string) => {
|
|
179
|
+
if (!name || !hasError(errorsRef.current, name)) {
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
const next = { ...errorsRef.current }
|
|
183
|
+
delete next[name]
|
|
184
|
+
errorsRef.current = next
|
|
185
|
+
setErrors(next)
|
|
186
|
+
}, [])
|
|
187
|
+
|
|
188
|
+
const focusFirstInvalid = React.useCallback(() => {
|
|
189
|
+
let hasInvalid = false
|
|
190
|
+
|
|
191
|
+
for (const field of registryRef.current.values()) {
|
|
192
|
+
if (
|
|
193
|
+
!hasError(errorsRef.current, field.name) &&
|
|
194
|
+
field.validityData.state.valid !== false
|
|
195
|
+
) {
|
|
196
|
+
continue
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
hasInvalid = true
|
|
200
|
+
const control = field.controlRef.current as {
|
|
201
|
+
focus?: () => void
|
|
202
|
+
select?: () => void
|
|
203
|
+
tagName?: string
|
|
204
|
+
} | null
|
|
205
|
+
|
|
206
|
+
if (isWeb && control?.focus) {
|
|
207
|
+
control.focus()
|
|
208
|
+
if (control.tagName === 'INPUT' || control.tagName === 'TEXTAREA') {
|
|
209
|
+
control.select?.()
|
|
210
|
+
}
|
|
211
|
+
return true
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (!isWeb && field.controlId) {
|
|
215
|
+
focusFocusable(field.controlId)
|
|
216
|
+
return true
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (control?.focus) {
|
|
220
|
+
control.focus()
|
|
221
|
+
return true
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return hasInvalid
|
|
226
|
+
}, [])
|
|
227
|
+
|
|
228
|
+
const performSubmit = React.useCallback(
|
|
229
|
+
(details: FormSubmitEventDetails) => {
|
|
230
|
+
submitAttemptedRef.current = true
|
|
231
|
+
|
|
232
|
+
for (const field of registryRef.current.values()) {
|
|
233
|
+
field.validate()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (focusFirstInvalid()) {
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
submittedRef.current = true
|
|
241
|
+
void onSubmitRef.current?.(getValues(), details)
|
|
242
|
+
},
|
|
243
|
+
[focusFirstInvalid, getValues]
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
const requestSubmit = React.useCallback(
|
|
247
|
+
(event?: any) => {
|
|
248
|
+
event?.preventDefault?.()
|
|
249
|
+
const details: FormSubmitEventDetails = {
|
|
250
|
+
reason: 'trigger-press',
|
|
251
|
+
event: event?.nativeEvent ?? event,
|
|
252
|
+
trigger: event?.currentTarget,
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (isWeb && formElementRef.current?.requestSubmit) {
|
|
256
|
+
pendingSubmitDetailsRef.current = details
|
|
257
|
+
formElementRef.current.requestSubmit()
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
performSubmit(details)
|
|
262
|
+
},
|
|
263
|
+
[performSubmit]
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
React.useEffect(() => {
|
|
267
|
+
if (!submittedRef.current) {
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
submittedRef.current = false
|
|
271
|
+
focusFirstInvalid()
|
|
272
|
+
}, [errors, focusFirstInvalid])
|
|
273
|
+
|
|
274
|
+
React.useImperativeHandle(
|
|
275
|
+
actionsRef,
|
|
276
|
+
() => ({
|
|
277
|
+
validate(fieldName?: string) {
|
|
278
|
+
if (fieldName) {
|
|
279
|
+
for (const field of registryRef.current.values()) {
|
|
280
|
+
if (field.name === fieldName) {
|
|
281
|
+
field.validate()
|
|
282
|
+
return
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
for (const field of registryRef.current.values()) {
|
|
289
|
+
field.validate()
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
[]
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
const registryContext = React.useMemo<FormRegistryContextValue>(
|
|
297
|
+
() => ({
|
|
298
|
+
validationMode,
|
|
299
|
+
errors,
|
|
300
|
+
formElementRef,
|
|
301
|
+
submitAttemptedRef,
|
|
302
|
+
clearErrors,
|
|
303
|
+
getValues,
|
|
304
|
+
registerField,
|
|
305
|
+
}),
|
|
306
|
+
[clearErrors, errors, getValues, registerField, validationMode]
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
return (
|
|
310
|
+
<FormRegistryContext.Provider value={registryContext}>
|
|
311
|
+
<FormProvider scope={scope} onSubmit={requestSubmit}>
|
|
312
|
+
<FormFrame
|
|
313
|
+
{...(props as any)}
|
|
314
|
+
ref={(element: any) => {
|
|
315
|
+
formElementRef.current = element
|
|
316
|
+
if (typeof forwardedRef === 'function') {
|
|
317
|
+
forwardedRef(element)
|
|
318
|
+
} else if (forwardedRef) {
|
|
319
|
+
forwardedRef.current = element
|
|
320
|
+
}
|
|
321
|
+
}}
|
|
322
|
+
noValidate
|
|
323
|
+
onSubmit={(event: any) => {
|
|
324
|
+
event.preventDefault()
|
|
325
|
+
const pendingDetails = pendingSubmitDetailsRef.current
|
|
326
|
+
pendingSubmitDetailsRef.current = null
|
|
327
|
+
performSubmit(
|
|
328
|
+
pendingDetails ?? {
|
|
329
|
+
reason: 'submit',
|
|
330
|
+
event: event.nativeEvent ?? event,
|
|
331
|
+
trigger: event.nativeEvent?.submitter,
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
</FormProvider>
|
|
337
|
+
</FormRegistryContext.Provider>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
type FormComponentType = <FormValue extends FormValues = FormValues>(
|
|
343
|
+
props: FormProps<FormValue> & { ref?: React.Ref<any> }
|
|
344
|
+
) => React.ReactElement
|
|
345
|
+
|
|
346
|
+
export const Form = withStaticProperties(FormComponent as FormComponentType, {
|
|
85
347
|
Trigger: FormTrigger,
|
|
86
348
|
})
|
|
349
|
+
|
|
350
|
+
export namespace Form {
|
|
351
|
+
export type Actions = FormActions
|
|
352
|
+
export type Errors = FormErrors
|
|
353
|
+
export type Props<FormValue extends FormValues = FormValues> = FormProps<FormValue>
|
|
354
|
+
export type SubmitEventDetails = FormSubmitEventDetails
|
|
355
|
+
export type ValidationMode = FormValidationMode
|
|
356
|
+
export type Values<FormValue extends FormValues = FormValues> = FormValue
|
|
357
|
+
}
|
package/types/Form.d.ts
CHANGED
|
@@ -1,26 +1,73 @@
|
|
|
1
|
-
import type { ViewProps } from '@tamagui/core';
|
|
2
|
-
|
|
3
|
-
type
|
|
4
|
-
|
|
1
|
+
import type { TamaguiEventDetails, ViewProps } from '@tamagui/core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export type FormValidationMode = 'onSubmit' | 'onBlur' | 'onChange';
|
|
4
|
+
export type FormErrors = Record<string, string | string[]>;
|
|
5
|
+
export type FormValues = Record<string, any>;
|
|
6
|
+
export type FormFieldRegistration = {
|
|
7
|
+
name?: string;
|
|
8
|
+
controlId?: string;
|
|
9
|
+
controlRef: React.MutableRefObject<any>;
|
|
10
|
+
getValue: () => unknown;
|
|
11
|
+
validate: () => void;
|
|
12
|
+
validityData: {
|
|
13
|
+
state: {
|
|
14
|
+
valid: boolean | null;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
5
17
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
18
|
+
type FormRegistryContextValue = {
|
|
19
|
+
validationMode: FormValidationMode;
|
|
20
|
+
errors: FormErrors;
|
|
21
|
+
formElementRef: React.MutableRefObject<HTMLFormElement | null>;
|
|
22
|
+
submitAttemptedRef: React.MutableRefObject<boolean>;
|
|
23
|
+
clearErrors: (name?: string) => void;
|
|
24
|
+
getValues: () => FormValues;
|
|
25
|
+
registerField: (id: string, registration: FormFieldRegistration) => () => void;
|
|
26
|
+
};
|
|
27
|
+
export declare const FormRegistryContext: React.Context<FormRegistryContextValue>;
|
|
28
|
+
export declare const useFormRegistryContext: () => FormRegistryContextValue;
|
|
29
|
+
type FormTriggerContextValue = {
|
|
30
|
+
onSubmit?: (event?: unknown) => unknown;
|
|
31
|
+
};
|
|
32
|
+
export declare const FormContext: import("@tamagui/core").StyledContext<FormTriggerContextValue, "onSubmit">;
|
|
33
|
+
export declare const useFormContext: (scope?: string) => FormTriggerContextValue, FormProvider: React.Provider<FormTriggerContextValue> & React.ProviderExoticComponent<Partial<FormTriggerContextValue> & {
|
|
34
|
+
children?: React.ReactNode;
|
|
9
35
|
scope?: string;
|
|
10
36
|
}>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
37
|
+
export declare const FormFrame: React.FunctionComponent<Omit<import("@tamagui/core").RNTamaguiViewNonStyleProps, keyof import("@tamagui/core").StackStyleBase> & import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase> & import("@tamagui/core").WithShorthands<import("@tamagui/core").WithThemeValues<import("@tamagui/core").StackStyleBase>> & {
|
|
38
|
+
ref?: React.Ref<import("@tamagui/core").TamaguiElement> | undefined;
|
|
39
|
+
}> & import("@tamagui/core").StaticComponentObject<import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}, import("@tamagui/core").StaticConfigPublic> & Omit<import("@tamagui/core").StaticConfigPublic, "staticConfig"> & {
|
|
40
|
+
__tama: [import("@tamagui/core").TamaDefer, import("@tamagui/core").TamaguiElement, import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}, import("@tamagui/core").StaticConfigPublic];
|
|
14
41
|
};
|
|
15
|
-
export type FormProps = ViewProps & FormExtraProps;
|
|
16
42
|
export interface FormTriggerProps extends ViewProps {
|
|
17
43
|
scope?: string;
|
|
18
44
|
}
|
|
19
|
-
export declare const FormTrigger: import("@tamagui/core").TamaguiComponent<Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}>, keyof FormTriggerProps> & FormTriggerProps, import("@tamagui/core").
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
45
|
+
export declare const FormTrigger: import("@tamagui/core").TamaguiComponent<Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}>, keyof FormTriggerProps> & FormTriggerProps, import("react-native").View | (HTMLElement & import("@tamagui/core").TamaguiElementMethods), import("@tamagui/core").RNTamaguiViewNonStyleProps & FormTriggerProps, import("@tamagui/core").StackStyleBase, {}, import("@tamagui/core").StaticConfigPublic>;
|
|
46
|
+
export type FormSubmitEventDetails = TamaguiEventDetails<'submit' | 'trigger-press', unknown>;
|
|
47
|
+
export interface FormActions {
|
|
48
|
+
validate: (fieldName?: string) => void;
|
|
49
|
+
}
|
|
50
|
+
type FormExtraProps<FormValue extends FormValues = FormValues> = {
|
|
51
|
+
scope?: string;
|
|
52
|
+
validationMode?: FormValidationMode;
|
|
53
|
+
errors?: FormErrors;
|
|
54
|
+
actionsRef?: React.RefObject<FormActions | null>;
|
|
55
|
+
onSubmit?: (values: FormValue, details: FormSubmitEventDetails) => void | Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
export type FormProps<FormValue extends FormValues = FormValues> = Omit<ViewProps, 'onSubmit'> & FormExtraProps<FormValue>;
|
|
58
|
+
type FormComponentType = <FormValue extends FormValues = FormValues>(props: FormProps<FormValue> & {
|
|
59
|
+
ref?: React.Ref<any>;
|
|
60
|
+
}) => React.ReactElement;
|
|
61
|
+
export declare const Form: FormComponentType & {
|
|
62
|
+
Trigger: import("@tamagui/core").TamaguiComponent<Omit<import("@tamagui/core").GetFinalProps<import("@tamagui/core").RNTamaguiViewNonStyleProps, import("@tamagui/core").StackStyleBase, {}>, keyof FormTriggerProps> & FormTriggerProps, import("react-native").View | (HTMLElement & import("@tamagui/core").TamaguiElementMethods), import("@tamagui/core").RNTamaguiViewNonStyleProps & FormTriggerProps, import("@tamagui/core").StackStyleBase, {}, import("@tamagui/core").StaticConfigPublic>;
|
|
24
63
|
};
|
|
64
|
+
export declare namespace Form {
|
|
65
|
+
type Actions = FormActions;
|
|
66
|
+
type Errors = FormErrors;
|
|
67
|
+
type Props<FormValue extends FormValues = FormValues> = FormProps<FormValue>;
|
|
68
|
+
type SubmitEventDetails = FormSubmitEventDetails;
|
|
69
|
+
type ValidationMode = FormValidationMode;
|
|
70
|
+
type Values<FormValue extends FormValues = FormValues> = FormValue;
|
|
71
|
+
}
|
|
25
72
|
export {};
|
|
26
73
|
//# sourceMappingURL=Form.d.ts.map
|
package/types/Form.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../src/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAInE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAA;AACnE,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE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IAAI,SAAS,CAAC,SAAS,CAAC,CAAA;IACnF,KAAY,kBAAkB,GAAG,sBAAsB,CAAA;IACvD,KAAY,cAAc,GAAG,kBAAkB,CAAA;IAC/C,KAAY,MAAM,CAAC,SAAS,SAAS,UAAU,GAAG,UAAU,IAAI,SAAS,CAAA;CAC1E"}
|
package/dist/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/jsx/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|
package/dist/jsx/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc","ignoreList":[]}
|