0.1.0 • Published 7 months ago

react-form-model-controller v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

react-form-model-controller

Boosts productivity through TypeScript IDE support, streamlines data serialization/deserialization and validation, and offers customizable UI with render props for seamless server communication. A class model-based React form system utilizing decorators and metadata reflection.

Description

This form system enhances productivity with TypeScript IDE support, simplifies data serialization/deserialization and validation, and provides customizable UI with render props for seamless server communication.

Demo

Get Started

  • npm install react-form-model-controller
  • yarn add react-form-model-controller
  • pnpm add react-form-model-controller

Features

Fully Supported TypeScript

  • Our form system is built with full TypeScript support, ensuring that you can take full advantage of IDE assistance. This means better code completion, error detection, and overall productivity enhancements as you build your forms.

    IDE-support

Frees you from dealing with server-side data interface changes

  • Say goodbye to the headaches of data serialization and deserialization. With our Mapper decorators, you can separate concerns between UI and server data handling. This allows you to focus solely on the UI, making your code more maintainable and adaptable to server changes without any hassle
  • Has mapper layer for data serialization/deserialization. just annotated @Mapper.Read / @Mapper.Write. model-class

Built-in Validation

  • Form validation is a critical aspect of any form management system. Our library comes with built-in validation support, ensuring your forms handle user input correctly and efficiently. You can define your validation logic and put it in to Field componet validator prop. validation

Customizable UI with Render Props

  • Flexibility is at the core of our system. Using the render props pattern, you can tailor the UI to meet your specific needs. Whether you need a simple form or a complex, highly customized interface, our system provides the tools to make it happen.

Basic Usage

  1. Define model and create hook. basic-model
  1. Use created hook in your component. basic-component

Caveat

  • Check your codebase settings(env) for decorator syntax.

APIS

Field Component Props

TargetDescriptionTypeRequired
nameName of the field defined in the modelstringrequired
refValuesFields that will trigger re-rendering and are included in the valuesArray<keyof TFormModel>optional
validatorFunction to validate the field(value: T) => string \| null \| undefinedoptional
validateOnMountWhether to validate the field when it is mountedbooleanoptional

Field Component Children Arguments (Render-Props Arguments)

TargetDescriptionType
valueValue of the fieldTValue
valuesValues of the fields passed in refValuesPartial<TFormModel>
errorError messagestring \| undefined \| null
fieldHandlerHandler for the field corresponding to the Field component(TValue) => void
getFieldHandlerGetter for a specific field handler(key: TKey, value: TFormModel[TKey]) => void
getComplexFieldHandlerGetter for a handler used in complex field settings(key: TKey, path: string (inferred by TypeScript), value: TValue) => void

Controller

TargetDescriptionType
setValueUpdates the value of a specific field(key: TKey, value: TFormModel[TKey]) => void
setValuesUpdates the entire form model(values: TFormModel) => void
validateValidates a specific field(key: TKey) => boolean
validateAllValidates all fields(key: TKey, value: TFormModel[TKey]) => boolean
undoUndoes the last update (experimental)() => void
resetResets the form to its initial state() => void
subscribeSubscribes to changes in specific form values. Listens for changes in the specified keys and triggers the provided callback function when those values change.(keys: TKey[], listener: (values: Pick<NonNullable<TFormModel>, TKey>) => void
readFetches data from the server, converts it to the model format, and sets the form(data: DataResponse) => void
writeConverts model data to the format expected by the server() => WriteResult(server expected data)
0.1.0

7 months ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago