Let your data build your UI, with Astro components
Find a file
2022-10-01 13:28:18 +02:00
.vscode Initial commit 2022-09-25 20:09:11 +02:00
demo initial demo app 2022-10-01 13:07:05 +02:00
src feat: support all HTML input types 2022-10-01 13:28:18 +02:00
test chore: remove unused code 2022-09-27 17:38:12 +02:00
.editorconfig Initial commit 2022-09-25 20:09:11 +02:00
.eslintignore Initial commit 2022-09-25 20:09:11 +02:00
.eslintrc.cjs Initial commit 2022-09-25 20:09:11 +02:00
.gitignore docs: project readme 2022-09-25 21:38:24 +02:00
.prettierrc.cjs Initial commit 2022-09-25 20:09:11 +02:00
index.ts feat: multiple controls 2022-09-25 21:33:19 +02:00
package-lock.json chore: deps for demo app 2022-10-01 13:08:39 +02:00
package.json chore: script for running the demo app 2022-10-01 13:10:53 +02:00
README.md docs: update plan for validation 2022-10-01 09:26:29 +02:00
tsconfig.json Initial commit 2022-09-25 20:09:11 +02:00

Astro Reactive Form 🔥

npm npm npm github

The Reactive Form component for Astro 🔥

All contributions are welcome.

Installation

npm i astro-reactive-form

Usage

---
import Form, { FormControl, FormGroup } from 'astro-reactive-form';

// example of a form control
const radio: FormControl = {
  name: 'is-good-looking',
  type: 'radio',
  label: 'Is Good Looking?',
  value: 'checked',
  labelPosition: 'right',
};

const form = new FormGroup([
  // this is just an array of FormControl
  {
    name: 'first-name',
    value: 'Ayo',
    label: 'First Name',
  },
  {
    name: 'last-name',
    value: 'Ayco',
    label: 'Last Name',
  },
  {
    name: 'is-awesome',
    type: 'checkbox',
    label: 'Is Awesome?',
    value: 'checked',
    labelPosition: 'right',
  },
  radio, // the form control we declared earlier
]);
---

<Form formGroups={[form]} />

Screenshots

Result of example above:

Screen Shot 2022-09-27 at 5 41 46 PM

Example of multiple form groups:

Screen Shot 2022-09-27 at 10 44 03 PM

Future Plans

Currently this only supports very basic form creation, but the goal of the project is ambitious:

  1. Validator library for common validation scenarios
    1. Client-side validation
    2. Server-side validation
    3. validation hooks - onFocus, onBlur, onSubmit
  2. Themes - unstyled, light mode, dark mode, compact, large
  3. FormGroup class
    1. get(controlName: string) - returns the FormControl with matching name
    2. statusChanges - observable that emits the form status when it changes
    3. valueChanges - observable that emits the values of all controls when they change
  4. FormControl class
    1. setValue(value) - set the value of the control programmatically
    2. statusChanges - observable that emits the control status when it changes
    3. valueChanges - observable that emits the control value when it changes
    4. value - property that reflects the control value

... and so much more

All contributions are welcome. Let's make the fastest web form component powered by Astro