# react-t-shirt-forms

> Simple forms, simple code.

Latest version **0.0.1** (published 2019-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-t-shirt-forms
pnpm add react-t-shirt-forms
yarn add react-t-shirt-forms
bun add react-t-shirt-forms
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-03-12 |
| First published | 2019-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 250.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Stephen Cook |
| Maintainers | stephencookdev |
| Keywords | form, react |

## Links

- npm: https://www.npmjs.com/package/react-t-shirt-forms
- Repository: https://github.com/stephencookdev/react-t-shirt-forms
- Issues: https://github.com/stephencookdev/react-t-shirt-forms/issues
- npm.io page: https://npm.io/package/react-t-shirt-forms

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2019-03-12
- 0.0.1--rc4 (next) — 2019-02-16
- 0.0.1--rc6 — 2019-02-19
- 0.0.1--rc5 — 2019-02-18
- 0.0.1--rc3 — 2019-02-16
- 0.0.1--rc2 — 2019-02-16
- 0.0.1--rc1 — 2019-02-13

## README

# 👕 React T-Shirt Forms

Sometimes life calls for more than a t-shirt. But t-shirts are easy, and comfortable - a good default until you need more.

## Another Form Library?

Making a form in React is hard. Needlessly hard, with a _lot_ of boilerplate - even when using any of the popular React form libraries.

T-Shirt Forms is intended to make creating simple forms simple.

It is powerful enough to handle complex and irregular cases, but it is more heavily geared towards reducing the boilerplate around _regular_ forms.

If your app has lots of complex and irregular forms, then this library is probably not going to be the best solution. I would recommend looking at [Formik](https://github.com/jaredpalmer/formik) instead.

## Installing

```
npm install --save-dev react-t-shirt-forms
```

or

```
yarn add -D react-t-shirt-forms
```

## Usage

### API

See the [API docs](./api).

### Examples

We show some basic examples on this page.

But you can see some more common flows [in the examples](./examples).

### Bare Bones Form

```javascript
import TShirtForm from "react-t-shirt-forms";

// by default no styling is included in your bundle
// but you can pull in a basic CSS file if you like
import "react-t-shirt-forms/dist/stylesheets/basic.min.css";

const formSchema = {
  name: {
    type: "string",
    label: "Name",
    initialValue: "Bruce Wayne"
  },
  email: {
    type: "email",
    label: "Email"
  }
};

const onFormSubmit = async ({ formArgs }) => {
  console.log(JSON.stringify(formArgs, null, 2));
};

const App = () => (
  <TShirtForm schema={formSchema} handleSubmit={onFormSubmit} />
);
```

### Validation

T-Shirt Forms allows integration with any validation library, but comes with out of the box hooks for [yup](https://github.com/jquense/yup).

```javascript
import * as yup from "yup";
import { addValidation, yupSupport } from "react-t-shirt-forms";

// this tells T-Shirt Forms to use `yup` for any validations
// it also adds default validations for common fields
addValidation(yup, yupSupport);
```

Now you can use `yup` validations in your form schema:

```javascript
const formSchema = {
  name: {
    type: "string",
    label: "Name",
    validation: yup()
      .string()
      .min(10)
  }
};
```

### Custom Fields

If you have a custom React component that you need to use for all password inputs, you can specify a global rule for this.

```javascript
import { setSchemaDefaults } from "react-t-shirt-forms";

const MyCustomPasswordInput = ({ onChange, onBlur, value, label }) => (
  <label>
    {label}
    <input
      type="password"
      value={value}
      onChange={e => onChange(e.target.value)}
      onBlur={e => onBlur(e)}
    />
  </label>
);

setSchemaDefaults({
  type: {
    password: {
      component: MyCustomPasswordInput
    }
  }
});
```

and now whenever you use a password input field

```javascript
const formSchema = {
  myPasswordField: {
    type: "password",
    label: "My custom password field"
  }
};
```

you'll see that it's using your `MyCustomPasswordInput` component.

## Bundle Size

T-Shirt Forms makes an effort to be minimal and modular.

Here's a look at its size, after tree-shaking, in different contexts:

- bare bones (21.19 KB / **5.71 KB gzipped**)
- with CSS stylings (29.40 KB / **8.51 KB gzipped**)
- with yup validation (29.45 KB / **8.53 KB gzipped**)

## Contributing

Contributors are welcome! 😊

Check out the [CONTRIBUTING.md](./CONTRIBUTING.md).

## License

[MIT](./LICENSE)

---
_Source: https://npm.io/package/react-t-shirt-forms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
