0.4.1 • Published 11 months ago

@chemical-x/forms v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Chemical X Forms

npm version npm downloads License Node.js Test Suite Nuxt

A fully type-safe, schema-driven form library that gives you superpowers.Comes with a minimal composition API that prioritizes developer experience and form correctness. 🚧 this library is not production ready yet.

šŸ”ļø Features

  • Compact API – Minimal yet expressive API surface with core functions like useForm, register, and handleSubmit to reduce boilerplate.
  • Abstract Schema Support – Integrates with validation libraries like Zod for type-safe schemas and automatic validation.
  • v-register Directive – One SSR-safe directive that automatically tracks everything.
  • Full State Tracking – Automatically tracks field states (value, touched, dirty status, validation errors, etc).
  • TypeScript Friendly – Fully type-safe, with advanced form type inference from your schema.

🪩 Installation

Install with Nuxi:

npx nuxi module add @chemical-x/forms

That's it! You can now use Chemical X Forms in your Nuxt app ✨

Install manually:

# Using npm
npm install @chemical-x/forms

Then add the module to your nuxt.config.ts:

export default defineNuxtConfig({
  modules: ["@chemical-x/forms"],
});

šŸŖ„ Usage

Basic Example

<script setup lang="ts">
import { z } from "zod";

// Define your schema
const schema = z.object({ planet: z.string() });

// Create your form
const { getFieldState, register, key } = useForm({ schema });

// Get the state of the 'planet' field
const planetState = getFieldState("planet");
</script>

<template>
  <div>
    <h1>Planet Form</h1>

    <input
      v-register="register('planet')"
      placeholder="Enter your favorite planet"
    />

    <p>Planet field State:</p>
    <pre>{{ JSON.stringify(planetState, null, 2) }}</pre>
    <hr />
  </div>
</template>

Core API Functions

note: detailed documentation coming soon

useForm(options?) – Initializes form state. Abstract schema required.

v-register – Custom, SSR-safe directive for registering components with Chemical X

register(name: string) – Binds a field to form state.

handleSubmit(onSubmit, onError?) – Handles submission with validation.

getValue(name: string) – Retrieves a field value.

setValue(name: string, value: any) – Updates a field programmatically.

getFieldState(name: string) – Returns field state (value, touched, errors, etc.).

šŸ„‡ Advanced Features

  • Fully SSR Safe – Fully Nuxt 3-compatible with hydration-safe bindings.

  • Validation Handling – Displays schema validation errors automatically.

  • Performance Optimizations – Efficient reactive updates for optimal performance.

🪪 License

@chemical-x/forms is released under the MIT License. See the LICENSE file for details.

0.4.1

11 months ago

0.4.0

11 months ago

0.3.29

11 months ago

0.3.28

11 months ago

0.3.27

11 months ago

0.3.26

11 months ago

0.3.25

11 months ago

0.3.24

11 months ago

0.3.23

11 months ago

0.3.22

11 months ago

0.3.21

11 months ago

0.3.20

11 months ago

0.3.19

11 months ago

0.3.18

11 months ago

0.3.17

11 months ago

0.3.16

11 months ago

0.3.15

11 months ago

0.3.14

11 months ago

0.3.13

11 months ago

0.3.12

11 months ago

0.3.11

11 months ago

0.3.10

11 months ago

0.3.9

11 months ago

0.3.8

11 months ago

0.3.7

11 months ago

0.3.6

11 months ago

0.3.5

11 months ago

0.3.4

11 months ago

0.3.3

11 months ago

0.3.2

11 months ago

0.3.1

11 months ago

0.3.0

11 months ago

0.2.8

12 months ago

0.2.7

12 months ago

0.2.6

12 months ago

0.2.5

12 months ago

0.2.4

12 months ago

0.2.3

12 months ago

0.2.2

12 months ago

0.2.1

12 months ago

0.2.0

12 months ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago