@chemical-x/forms v0.4.1
Chemical X Forms
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, andhandleSubmitto 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/formsThat's it! You can now use Chemical X Forms in your Nuxt app āØ
Install manually:
# Using npm
npm install @chemical-x/formsThen 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.
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago