npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@smart-forms/core

v0.2.0

Published

Framework-agnostic schema, validation, and state for smart-forms

Readme

smart-forms

Schema-driven React form generator. Describe fields as a config array — get inputs, Zod validation, errors, conditional visibility, and submit handling with zero manual JSX wiring for the common case.

Packages

| Package | Description | |---------|-------------| | @smart-forms/core | Framework-agnostic schema, normalize, validation, state, layout | | @smart-forms/react | React bindings: <SmartForm>, useSmartForm, field components | | @smart-forms/theme-default | Default CSS theme |

Install

pnpm add @smart-forms/react @smart-forms/theme-default
# peer: react, react-dom
import { SmartForm } from '@smart-forms/react';
import '@smart-forms/theme-default/styles.css';

Three API tiers (same engine)

1. Declarative <SmartForm>

import { SmartForm } from '@smart-forms/react';
import '@smart-forms/theme-default/styles.css';

const fields = [
  { type: 'email' },
  { type: 'password' },
];

export function Login() {
  return (
    <SmartForm
      fields={fields}
      submitLabel="Sign in"
      onSubmit={(values) => console.log(values)}
    />
  );
}

2. Headless useSmartForm({ fields })

import { useSmartForm } from '@smart-forms/react';

export function CustomLogin() {
  const form = useSmartForm({
    fields: [{ type: 'email' }, { type: 'password' }],
  });

  return (
    <form onSubmit={form.handleSubmit((values) => console.log(values))}>
      <input
        value={String(form.values.email ?? '')}
        onChange={(e) => form.setValue('email', e.target.value)}
        aria-invalid={!!form.errors.email}
      />
      {form.errors.email && <span role="alert">{form.errors.email}</span>}
      <button type="submit" disabled={!form.isValid}>
        Submit
      </button>
    </form>
  );
}

3. Raw Zod schema useSmartForm({ schema })

import { z } from 'zod';
import { useSmartForm } from '@smart-forms/react';

const schema = z.object({
  age: z.number().min(18),
  nickname: z.string().min(2),
});

export function Advanced() {
  const form = useSmartForm({
    schema,
    defaultValues: { age: 18, nickname: '' },
    onSubmit: (values) => console.log(values),
  });

  return (
    <form onSubmit={form.handleSubmit()}>
      {/* your own JSX */}
    </form>
  );
}

Field types

string · email · password · textarea · tel · url · number · checkbox · select · radio · date · file

Shared options: name (optional for email/password/tel/url), label, placeholder, required, disabled, readonly, style, crossValidate, showWhen / hideWhen / enableWhen / disableWhen, asyncValidate, errorDisplay, a11y, customValidator.

Form-level defaults (e.g. { required: true }) apply after type presets and before per-field overrides.

Conditional visibility

{
  type: 'string',
  name: 'companyName',
  required: true,
  showWhen: { field: 'isEmployed', operator: 'equals', value: true },
}

Hidden fields are excluded from validation via a single getActiveFields filter shared by the validator and renderer.

Cross-field validation

{
  type: 'password',
  name: 'confirmPassword',
  required: true,
  crossValidate: [
    { rule: 'matches', field: 'password', message: 'Passwords must match' },
  ],
}

Rules: matches | greaterThan | lessThan | notEquals | custom.

Async validation

{
  type: 'string',
  name: 'username',
  required: true,
  asyncValidate: {
    debounceMs: 400,
    validate: async (value) => {
      const ok = await checkAvailable(String(value));
      return ok || 'Username taken';
    },
  },
}

Async errors merge into the same error map as sync validation.

Layout

<SmartForm
  fields={fields}
  layout={{ columns: 2, gap: '1rem' }}
  onSubmit={...}
/>

Monorepo development

pnpm install
pnpm build
pnpm test

Examples:

pnpm --filter login-form-js dev      # plain JavaScript
pnpm --filter signup-form-ts dev     # TypeScript
pnpm --filter job-application-ts dev # full-featured

Architecture

  • @smart-forms/core has zero React dependency.
  • @smart-forms/react never re-implements validation, normalization, or condition evaluation — it only calls into core.
  • Defaults (label, placeholder, errorDisplay, a11y) and type presets (email → name/required/…) are filled once in normalizeField (preset → form defaults → user).
  • Conditions use one evaluateCondition for show/hide/enable/disable.