# @wibmw/custom-form

> Custom element to build a custom form with data validation easily

Latest version **0.0.5** (published 2023-01-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install @wibmw/custom-form
pnpm add @wibmw/custom-form
yarn add @wibmw/custom-form
bun add @wibmw/custom-form
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2023-01-14 |
| First published | 2023-01-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 40 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | WIBMW |
| Maintainers | wibmw |
| Keywords | form, custom, input, select, validation, datepicker, react, typescript, awesome, best, fast, lite, simple, easy |

## Links

- npm: https://www.npmjs.com/package/@wibmw/custom-form
- Repository: https://github.com/wibmw/custom-form
- Homepage: https://github.com/wibmw/custom-form#readme
- Issues: https://github.com/wibmw/custom-form/issues
- npm.io page: https://npm.io/package/@wibmw/custom-form

## 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.5 (latest) — 2023-01-14
- 0.0.4 — 2023-01-13
- 0.0.3 — 2023-01-13
- 0.0.2 — 2023-01-13
- 0.0.1 — 2023-01-13

## README

# Custom Form

An Easy React Customizable Form

[![NPM version][npm-image]][npm-url]

## 🚀 Getting Started

Using [`yarn`]():

```bash
yarn add @wibmw\custom-form
```

## ✨ Usage

How to use `CustomInput` or `CustomSelect` in your project:

```javascript
import {CustomInput, CustomSelect }from 'custom-form'

export default () => {
  // Form Sate
  const [formState, setFormState] = useState(initForm),
  const Options = [
    { value: '', text: '--Choose an option--' },
    { value: 'sales', text: 'Sales' },
    { value: 'marketing', text: 'Marketing' },
  ]
  // Form Validation and Store in the database
  const save = (event) => {
      const fieldsNumber = Object.keys(formState).filter((fieldName) => fieldName.includes('Valid')).length,
        countValid = Object.values(formState).filter(Boolean).length / 2,
        element = event.target

      if (fieldsNumber === countValid) {
        // If all fields are valid then create the employee and open the modal
        clearValidationMessage(element)
        createNewEmployee(formState)
      } else {
        // Else show an error message
        setValidationMessage(element, 'The form is not fullfilled correctly')
      }
    }
  return (
   <>
      {/** *********** Page ******************/}
      <main className='...'>
        <section className='...'>
          {/** *********** Form ******************/}
          <form>
            {/** *********** Firstname Input ******************/}
            <Input
                name='firstName'
                label='First Name'
                regexp={/^[a-zA-Zéèàçùê -]{2,50}$/}
                message='Invalid First Name !'
                setFormState={setFormState}
                type='text' // or 'date' for a datepicker
            />
            {/** *********** State Selelct ******************/}
            <CustomSelect
                name='state'
                label='State'
                options={stateOptions}
                message='Invalid State !'
                setFormState={setFormState}
            />
            {/** *********** Button ******************/}
            <div onClick={async (e) => {await save(e)}} >
              Save
            </div>
          </form>
        </section>
      </main>
    </>
  )
}

const initForm = {
  firstName: '',
  state: '',
  isFirstNameValid: false,
  isStateValid: false,
}

```

## 📌 Input Props

| Prop           | Type                                        | Default | Required |
| -------------- | ------------------------------------------- | ------- | -------- |
| `name`         | String                                      |         | Yes      |
| `label`        | String                                      |         | Yes      |
| `regexp`       | RegExp                                      |         | Yes      |
| `message`      | String                                      |         | No       |
| `type`         | String                                      |         | Yes      |
| `setFormState` | React.Dispatch<React.SetStateAction<IForm>> |         | Yes      |

## 📌 Select Props

| Prop           | Type                                        | Default | Required |
| -------------- | ------------------------------------------- | ------- | -------- |
| `name`         | String                                      |         | Yes      |
| `label`        | String                                      |         | Yes      |
| `message`      | String                                      |         | No       |
| `options`      | [{value, text}]                             |         | Yes      |
| `setFormState` | React.Dispatch<React.SetStateAction<IForm>> |         | Yes      |

## ✌️ License
[MIT](https://opensource.org/licenses/MIT)

[npm-url]: https://www.npmjs.com/package/@wibmw/custom-form

---
_Source: https://npm.io/package/@wibmw/custom-form · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
