0.4.1 • Published 7 months ago

@chemical-x/forms v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 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

7 months ago

0.4.0

7 months ago

0.3.29

7 months ago

0.3.28

7 months ago

0.3.27

7 months ago

0.3.26

8 months ago

0.3.25

8 months ago

0.3.24

8 months ago

0.3.23

8 months ago

0.3.22

8 months ago

0.3.21

8 months ago

0.3.20

8 months ago

0.3.19

8 months ago

0.3.18

8 months ago

0.3.17

8 months ago

0.3.16

8 months ago

0.3.15

8 months ago

0.3.14

8 months ago

0.3.13

8 months ago

0.3.12

8 months ago

0.3.11

8 months ago

0.3.10

8 months ago

0.3.9

8 months ago

0.3.8

8 months ago

0.3.7

8 months ago

0.3.6

8 months ago

0.3.5

8 months ago

0.3.4

8 months ago

0.3.3

8 months ago

0.3.2

8 months ago

0.3.1

8 months ago

0.3.0

8 months ago

0.2.8

8 months ago

0.2.7

8 months ago

0.2.6

8 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.2.3

8 months ago

0.2.2

8 months ago

0.2.1

8 months ago

0.2.0

8 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago

0.0.17

9 months ago

0.0.16

9 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago