1.0.3 • Published 5 years ago

@stnew/forms v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

@stnew/forms

Modular form components with some pre-configured form inputs for common use-cases.

npm install @stnew/forms

FormInput

A controlled component that composes an input element with a wrapper element and an optional and extendable indicator component. The indicator component is meant to provide visual indication of valid/invalid states.

import { FormInput } from '@stnew/forms';
Controlled PropsTypeDesc
typestringtype of the input field
valuestringcurrent value of the input field
invalidbooleanshould be true if the current value is invalid
validatedbooleanshould be true if the current value is valid
General PropsTypeDesc
idstringid of the input element
namestringname of the input element
classNamestringclass of the input element
requiredbooleantoggle to make the input field required
autoFocusbooleantoggle to make the input field focused by default
placeholderstringplaceholder text for the input field
customInputIndicatorReactNodeElement to be nested in the existing indicator div element
disableIndicatorbooleanif true, the indicator div element will not be rendered
onChangefunctiononChange callback function
onFocusfunctiononFocus callback function
onBlurfunctiononBlur callback function

ValidatedInput

Component that wraps FormInput and handles validation and state management.

import { ValidatedInput } from '@stnew/forms';
PropsTypeDesc
onValidfunctioncallback for when the input's value is valid
onInvalidfunctioncallback for when the input's value is invalid
onEmptyfunctioncallback for when the input's value is empty
validatorfunctionfunction that takes in the value of the input and returns true if valid, false otherwise
typestringtype of the input element
inputobjectobject will all attributes listed under 'General Props' for FormInput

Others

The package also includes some extentions of ValidatedInput that have built-in validation functions for common use cases. Each of these are the same, but with different validation functions.

  • EmailInput
  • ZipCodeInput
import { EmailInput, ZipCodeInput } from '@stnew/forms';
PropsTypeDesc
onValidfunctioncallback for when the input's value is valid
onInvalidfunctioncallback for when the input's value is invalid
onEmptyfunctioncallback for when the input's value is empty
  • also includes all props listed under 'General Props' for FormInput
1.0.3

5 years ago