zenform v0.0.0-rc.3
Installation
npm
npm i -S zenformyarn
yarn add zenform
Api
zenform has 2 core components
and a few helper components
Form
Form is top most component, all other components should be its child.
Form Props
onSubmit: ({ values: Object, changeSet: Object, formActions: FormActions }) => voidinitialValues?: Objectvalidations?: (values: Object) => void | Object | Promise<*>validateOnChange?: booleanvalidateOnBlur?: boolean
To render the form , it takes either a function as render prop or child as a function.
This function will have form render props as arguments.
Form Render Props
values: ObjecthandleSubmit: (event?: SyntheticEvent<HTMLFormElement>) => voidresetForm: () => voiderrors: Objecttouched: Objectdata: ObjectactiveField: stringisDirty: booleanisInvalid: booleaninitialValues: ObjectsetFieldValue: (field: string, value: any) => voidsetMultipleFieldValues: (fieldValues: Array<{field: string, value: any}>) => voidsetFieldError: (field: string, error: any) => voidsetMultipleFieldErrors: (fieldErrors: Array<{field: string, error: any}>) => voidsetFieldTouched: (field: string, isTouched: boolean) => voidsetMultipleFieldTouched: (fieldTouched: Array<{field: string, isTouched: boolean}>) => voidsetFieldData: (field: string, data: any) => voidsetMultipleFieldData: (fieldData: Array<{field: string, data: any}>) => voidsetActiveField: (field: string) => void
Field
Field is the actual input component, it should always be a child of Form component.
Field Props
name: stringformat?: (value: any) => anyparse?: (value: any) => anyallowNull?: booleanvalue?: any
To render the field , it takes either a component (string or react component) or a function as render prop or child as a function.
This function will have field render props as arguments.
Field Render Prop
input: Objectname: stringvalue: anyonChange: (Event<*>) => voidonBlur: (Event<*>) => voidonFocus: (Event<*>) => void
meta: Objecterror: anydata: anyisActive: booleanisTouched: boolean
Field Array
Array Field is a helper component for using multiple array input.
Field Array Props
name: string
To render the field array, it takes either a function as render prop or child as a function.
This function will have field array render props as arguments.
Field Array Render Prop
fields: Objectname: string,arrayValues: any[]forEach: (iterator: (name: string, index: number) => void) => voidinsert: (index: number, value: any) => voidmap: (iterator: (name: string, index: number) => any) => any[]move: (from: number, to: number) => voidpop: () => voidpush: (value: any) => voidremove: (index: number) => voidreplace: (index: number, value: any) => voidswap: (indexA: number, indexB: number) => voidunshift: (value: any) => number
Field Observer
A FieldObserver component observes a given field and provides functions to access onChange, onBlur and onFocus on it.
This component doesn't render anything on the dom.
Field Observer Props
name: stringonChange?: (fieldObserverData: FieldObserverData) => voidonBlur?: (fieldObserverData: FieldObserverData) => voidonFocus?: (fieldObserverData: FieldObserverData) => void
where FieldObserverData is an object containing
name: stringvalue: anyformValues: Objectdata: anyisActive: anyisTouched: booleansetFieldValue: (field: string, value: any) => voidsetMultipleFieldValues: (fieldValues: Array<{field: string, value: any}>) => voidsetFieldError: (field: string, error: any) => voidsetMultipleFieldErrors: (fieldErrors: Array<{field: string, error: any}>) => voidsetFieldTouched: (field: string, isTouched: boolean) => voidsetMultipleFieldTouched: (fieldTouched: Array<{field: string, isTouched: boolean}>) => voidsetFieldData: (field: string, data: any) => voidsetMultipleFieldData: (fieldData: Array<{field: string, data: any}>) => voidsetActiveField: (field: string) => void
Form Observer
A FormObserver component observes values of the whole form and provides functions to access onChange on it.
This component doesn't render anything on the dom.
Form Observer Props
onChange?: (formObserverData: FormObserverData) => void
where FormObserverData is an object containing
values: ObjectsetFieldValue: (field: string, value: any) => voidsetMultipleFieldValues: (fieldValues: Array<{field: string, value: any}>) => voidsetFieldError: (field: string, error: any) => voidsetMultipleFieldErrors: (fieldErrors: Array<{field: string, error: any}>) => voidsetFieldTouched: (field: string, isTouched: boolean) => voidsetMultipleFieldTouched: (fieldTouched: Array<{field: string, isTouched: boolean}>) => voidsetFieldData: (field: string, data: any) => voidsetMultipleFieldData: (fieldData: Array<{field: string, data: any}>) => voidsetActiveField: (field: string) => void
Acknowledgment
- Api design
- Lots of code pieces
- Lots of code pieces
License
MIT
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago