Giter VIP home page Giter VIP logo

react-ux-forms's Introduction

react-ux-forms

Build Status peerDependencies Status devDependency Status

react-ux-forms is a style and component agnostic <Form/> React.Component which handles the user feedback and validation in a UX oriented, less disturbing way.

Why would you even bother reading this README.md further?

react-ux-forms starts with the basic features you need:

  • It's style agnostic from the ground up, meaning that you can use your own components for inputs, buttons and sections of the Form.
  • It's validation approach is tested in many projects and turned out the be the less frustrating one for users.
  • Validators are configured in the same structure as you might know it from the webpack@2 rules config property.
  • Form actions (buttons) are simple to configure and come with predefined behavior to avoid form submissions with fatal validation errors.
  • Basic feedback props like onChange and onSubmit.

it also supports many advanced features:

  • Smooth integration with state containers such as redux.
  • Advanced callback props for several internal events such as onValidate, onInValidate and onSubmitFailed.
  • You can add n rules to each property of the Form and even introduce your own types / severity.
  • You decide the priority of each rule based on the index in the rules array.
  • Each rule can be triggered by either a Function or a RegExp.
  • Extendable in every way - Props on React elements and properties of each rule get propagated to the Components you specify via the props of the <Form/> Component.

Installation

# fancy-pantsy yarn
yarn add react-ux-forms

# or npm
npm i -S react-ux-forms

Examples

The following example is a simple single-column form with a custom TextInput, Button and ValidationMessage component. For the full example and even more advanced ones, checkout the examples/ folder.

Don't miss out on the API description further down below!

import React from 'react';
import Form from 'react-ux-forms';

export default props => {
	const {values, properties, onSubmit, onChange} = this.props;

	return (
		<Form
			ActionComponent={MyButton}
			ValidationMessageComponent={MyValidationMessage}

			actions={myActions}
			rulesById={myRulesByPropertyId}
			valuesById={values}

			onChange={onChange}
			onSubmit={onSubmit}
			>
			{properties.map((props, i) => (
				<Form.Item
					{...props}
					key={i}
					value={values[props.id]}
					/>
			))}
		</Form>
	);
};

API

<Form/>

props.ActionComponent

The Component that gets rendered for each action below the <form/>. The component recieves the full action object as it's props, so you are free to extend it at any point. The only restriction is that you have to provide a type which equals either submit, reset or button, this is not only reasonable for semantics, but is also a pointer for the <Form/> to attach a predefined onClick handler to it.

Actions of type submit will trigger the onSubmit prop of the <Form/> only after a full validation for all rules was executed and if no rule with the severity error is passing its test. Actions of type reset will trigger the onChange prop of the <Form/> for each key of the valuesById prop with an second argument of undefined.

props.ValidationMessageComponent

The React.Component that gets rendered for each validation message. The component recieves the full object of the passing rule, except for the test, since we haven't found a usecase for it in the ValidationMessageComponent as of now - Wanna change that? Open a issue and lets talk about it :)

The ValidationMessageComponent also recieves an isValid prop, on which you can decide to render it if it equals false or hide it / return null if it equals true.

props.actions

You can define n actions, as described on top, all properties get forwarded to the ActionComponent. An example would be:

const actions = [{
	type: 'submit',
	children: 'You better submit dat form'
}];
props.rulesById

The rules for each property of your form referenced by it's id. The structure is inspired by the webpack@2 configuration, since most React developers should be familiar with it. A rule gets triggered/activated if either it's test property that can be a Function or RegExp returns a truthy value, or if the rule object contains a truthy forced property. An example would be:

const rulesByPropertyId = {
	email: [{
		test: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
		message: 'Awesome, you have entered a valid email address.',
		severity: 'success'
	}]
};
props.valuesById

The values for each property of your form referenced by it's id. An example would be:

const valuesById = {
	email: '[email protected]'
};
props.onValidate

A handler that gets called once a property got succcessfully validated (Meaning that no rule with the severity of error is triggered). It's getting called with the id of the validated property.

props.onInValidate

A handler that gets called once a property failed the validation (Meaning that at least one rule with the severity of error is triggered). It's getting called with the id of the invalid property.

props.onChange

A handler that gets called after your target component triggers the onChange prop and the validation was executed.

props.onSubmit

A handler that gets called after the user clicked on an action component with a type of submit and the validation succeeded.

props.onSubmitFailed

A handler that gets called after the user clicked on an action component with a type of submit and the validation failed. It's only argument is the internal validationResultsById object, on which you can render additional warnings if you want to.

props.itemWrapperProps

An optional props object that gets forwarded to each wrapping <div/> of a <Form.Item/>.

props.actionsWrapperProps

An optional props object that gets forwarded to the wrapping <div/> of all form actions. Defaults to {style: {textAlign: 'right'}}.

props.onChangeValidationIds

If your <Form.Item/> target component does not support the onBlur prop (e.g. CheckBoxes), or if you want to display the validations as soon as the user changes a value even initially, pass in an array of ID's as this prop.

props.children

The React elements that get recursively traversed and rendered. Note that you should keep the depth as small as possible to avoid performance problems, we do NOT use the cloneElement() API of React but we still want you to keep it in mind that there might be performance implications for really large forms. If you expirience such issues, please submit an issue or PR so that we can work on it and improve this world for the better.

<Form.Item/>

The <Form.Item/> component is the second pillar of this package. Use it to express your form items, note that props like onChange and onBlur are overridden internally, use the onChange on the <Form/> instead.

props.Component

The component that gets rendered, any additional props to the <Form.Item/> will getpropagated to the specified component.

props.id

The identifier under which the <Form/> will lookup the value and rules.

props.invalidPropName

The prop name which will be used to propagate an additional prop to your target component that indicates if the validation result is fatal (error) or not. If you don't want this prop to be specified at all, pass in either null, false, undefined or an empty string.

<Form.Section/>

Use the <Form.Section/> component if you want to structure your Form using grids or boxes, note that this component will just render your specified Component, no additional HTML. We introduced this component to keep the recursive lookup for <Form.Item/>'s as small as possible.

props.Component

The component that gets rendered, any additional props to the <Form.Item/> will get propagated to the specified component.

Contributing

Releases

Releases are automatically triggered by each CI build depending on the commit message. Take a look at https://github.com/Inkdpixels/commit-analyzer for a full list of commit tags and the corresponding release type.

License

MIT - See the current LICENSE.md.

react-ux-forms's People

Contributors

greenkeeper[bot] avatar inkdpixels avatar

react-ux-forms's Issues

An in-range update of cross-env is breaking the build 🚨

Version 3.2.0 of cross-env just got published.

Branch Build failing 🚨
Dependency cross-env
Current Version 3.1.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As cross-env is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details
Release Notes v3.2.0

<a name"3.2.0">

3.2.0 (2017-03-04)

Features

  • revamp: revamp the entire lib (backward compatible) (#63) (dad00c46)
Commits

The new version differs by 4 commits .

  • dad00c4 feat(revamp): revamp the entire lib (backward compatible) (#63)
  • e33a85c docs(README): Add doc for cross-var. (#58)
  • 5e590ec docs(README): added how to use cross-env to run npm sub-scripts (#53)
  • afdb2de docs(README): mention Bash on Windows (#49)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of eslint-plugin-react is breaking the build 🚨

Version 6.10.1 of eslint-plugin-react just got published.

Branch Build failing 🚨
Dependency eslint-plugin-react
Current Version 6.10.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As eslint-plugin-react is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
Release Notes v6.10.1

Fixed

Commits

The new version differs by 11 commits .

  • ab03af8 Update CHANGELOG and bump version
  • b646485 Merge pull request #1089 from benstepp/bs-multicomp-false-positives
  • c038899 Bug fix for false positives with no-multi-comp
  • 8148833 [Fix] Update void-dom-elements-no-children createElement checks
  • c45ab86 Merge pull request #1081 from webOS101/jsx-indent-fix
  • 7863a5c Fix jsx-indent single line jsx
  • 416deff Update void-dom-elements-no-children
  • 22f3638 Merge pull request #1077 from iancmyers/fix-jsx-indent-template-conditional
  • c6f4a5e Fix error caused by templates in ConditionalExpressions (jsx-indent)
  • a4b6a85 Merge pull request #1058 from kentcdodds/pr/jsx-indent-tabs-fix
  • 6e5f688 [Fix] jsx-indent with tabs (fixes #1057)

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of sinon is breaking the build 🚨

Version 4.1.6 of sinon was just published.

Branch Build failing 🚨
Dependency sinon
Current Version 4.1.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 10 commits.

  • 68c37ed Update docs/changelog.md and set new release id in docs/_config.yml
  • cd8ae51 Add release documentation for v4.1.6
  • 29e80be 4.1.6
  • a5c59a5 Update History.md and AUTHORS for new release
  • 0ae60b6 Merge pull request #1653 from mroderick/upgrade-dependencies
  • dcd4191 Upgrade browserify to latest
  • a316f02 Upgrade markdownlint-cli to latest
  • 78ebdb3 Upgrade lint-staged to latest
  • fcf967b Upgrade dependency supports-color
  • 7c3cb4f Enable StaleBot with default configuration (#1649)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of babel-eslint is breaking the build 🚨

Version 8.1.0 of babel-eslint was just published.

Branch Build failing 🚨
Dependency babel-eslint
Current Version 8.0.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

babel-eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes v8.1.0

Use ESLint's API to customize scope analysis and avoid monkeypatching: #542

Commits

The new version differs by 3 commits.

  • 893a5e3 8.1.0
  • bba9d00 Re-add parseNoPatch function (accidentally removed) (#557)
  • dbc6546 Use new scopeManager/visitorKeys APIs (#542)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.