Skip to main content

Intro

The @emoney/kyber-forms package can be used to create any type of form. The examples in this readme are oriented from simple to complex.

Fields

Kyber's form components are stateless high level components that encapsulate serialization and validation. Most of them can be used uncontrolled or controlled. Each field component has the following shared props:

Prop NameTypeDescription
descstringThe description for the field.
disabledbooleanWhether or not the field is disabled.
errorTextstringThe error text to display if isInvalid is true.
isInvalidbooleanWhether or not the field is invalid.
isValidbooleanWhether or not the field is valid.
isWarningbooleanWhether or not the field is warning.
labelstringThe label for the field.
namestringThe name of the field. This is used to serialize the form data.
radiusstringThe radius of the field. One of round, square, or pill.
readOnlybooleanWhether or not the field is read only.
renderEndAddOnfunctionA function that returns a React node to render at the end of the field. Use one InputGroup component, Button, or Dropdown.
renderPrefixfunctionA function that returns a React node.
renderStartAddOnfunctionA function that returns a React node to render at the start of the field. Use one InputGroup component, Button, or Dropdown.
renderSuffixfunctionA function that returns a React node.
sizestringThe size of the field. One of sm, md, or lg.
validTextstringThe valid text to display if isValid is true.
warningTextstringThe warning text to display if isWarning is true.

Validation States

Result
Loading...
Live Editor

Addons, Prefixes, and Suffixes

Result
Loading...
Live Editor

Multiple prefixes or suffixes

Some field components (e.g. NumberField) utilize prefixes or suffixes to display controls like the plus and minus spinner. In these cases it may be necessary to set the flex order of your prefix/suffix to make sure it's displayed correctly.

Result
Loading...
Live Editor

Sizes

The size prop can be used to change the size of the field. The default size is md.

Result
Loading...
Live Editor

Radii

The radius prop can control the corner styling of any field component. The default is round. The other options are square and pill.

Result
Loading...
Live Editor

Usage

Form Component

If you need more control over how the form inputs are rendered (E.g. columns or other custom layouts) you can use the individual form components inside of a Kyber Form component. The Form component will still help you manage state and validation while you have direct access to each input component.

Result
Loading...
Live Editor

DataForm Component

If your form is straightforward you can build it using just the DataForm component and an object based schema.

DataForm is only available in the @emoney/kyber-forms package.

Result
Loading...
Live Editor

Self Managed

If you need complete control over the form you can manage state and validation yourself by importing the individual form components and combining them with third party form management and validation libraries. The Kyber team recommends Formik and Yup, but other libraries like React Hook Form can also work.

Note: This example uses the HTML <form> element, not the Kyber Form component.

Result
Loading...
Live Editor