import React, { HTMLProps, Ref } from 'react'
import { SectionProps } from '../Section'
import { FormStore } from './FormStore'
import { InputType } from './Input'
export type FormProps = Omit &
Pick, 'action' | 'method' | 'target' | 'name'> & {
nodeRef?: Ref
submitButton?: string | boolean
fields?: A
errors?: FormErrors
onSubmit?: (
e: React.FormEvent,
values: FormValues,
) => FormErrors | Promise>
children?: React.ReactNode
useForm?: FormStore
size?: number
}
export type FormValues = { [key in keyof FormFieldsObj]: any }
export type FormFieldsObj = { [key: string]: FormFieldType }
/**
* Used to describe if any errors exist on the form.
* If falsy, no problem, if truthful, shows an error.
* Maps to fields.
* */
export type FormErrors = { [key in keyof A]: string } | string | null | true | void
export type FormFieldType =
| {
label: string
type?: InputType
value?: any
required?: boolean
description?: string
validate?: (val: any) => string
}
| {
label: string
type: 'select'
value: { label: string; value: string }[]
required?: boolean
description?: string
validate?: (val: any) => string
}
| {
label: string
type: 'custom'
children: React.ReactNode
value?: any
required?: boolean
validate?: (val: any) => string
}
export type FormStoreProps = Pick, 'fields' | 'errors'>