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

react-form-craft

v1.4.12

Published

A lightweight, flexible form building library for React applications with TypeScript support.

Readme

React Form Craft

A lightweight, flexible form building library for React applications with TypeScript support.

Features

  • 🔧 Easy form setup with declarative configuration
  • 🧩 Built-in form elements (Input, Select, Checkbox)
  • 🛠 Custom control components support
  • ✅ Validation support
  • 🔄 Form state management
  • 🎨 Customizable styling

Installation

npm install react-form-craft

Basic Usage

import { useState } from 'react';
import { 
    FormCraft, 
    type ValidationErrors, 
    type FormCraftOnChange,
    type FormCraftHandleSubmitParams
} from 'react-form-craft';

function MyForm() {
  const formState = {
      name: '',
      email: '',
      role: 'user',
      agreeToTerms: false
  };

  const fields = [
    {
      name: 'name',
      placeholder: 'Enter your name'
    },
    {
      name: 'email',
      placeholder: 'Enter your email',
      control: (props) => <CustomInput {...props} errorMsg={props.error} />  
    },
    {
      name: 'role',
      type: 'select',
      options: [
        { value: 'user', label: 'User' },
        { value: 'admin', label: 'Admin' }
      ]
    },
    {
      name: 'agreeToTerms',
      type: 'checkbox'
    },
    {
      name: 'radio',
      type: 'radio',
      options: ['radio1', 'radio2', 'radio3'],
      placeholder: 'Radio',
    }, 
    {
      name: 'group example',
      type: 'group', 
      group: [
        {
          name: 'name',
          placeholder: 'Enter name',
        },
        {
          name: 'agree_with_policy',
          type: 'checkbox',
          placeholder: 'Do you agree with user policy?',
        },
      ],
    },    
  ];

  const validationRules = {
    name: { 
        required: {
            value: true,
            message: 'Name is required',
        },
        maxLength: {
            value: 10,
            message: 'Name is too long',
        },
        minLength: {
            value: 1,
            message: 'Name is too short',
        },
    },
    email: { 
        required: true, 
        customRule: (value?: string) => {
            if (value && !value.includes('@')) {
                return { value, message: 'Email is invalid' };
            }
        },
    },
    age: {
      range: {
        value: [18, 100],
      },
    }
  };

  const handleSubmit = async ({ state, payload, errors }: FormCraftHandleSubmitParams) => {
      console.log('state', state);
      console.log('payload', payload);
      console.log('errors', errors);
      // if you want to reset form data then return void
      // else return payload(changed state) or state(initial state)
      return payload;
  };

  const handleChange = ({ field, value }: FormCraftOnChange) => {
      console.log('field', field);
      console.log('value', value);
      // Process field data
  };

  return (
    <FormCraft
      fields={fields}
      state={formState}
      submit={handleSubmit}
      onChange={handleChange}
      validationRules={validationRules}
      className="my-form"
      btnSubmit={<button type='submit' className="submit-btn">Submit Form</button>}
    />
  );
}

See examples in src/app

API Reference

Props FormCraft

| Prop | Type | Required | Description | | --- |-----------------------------------------------------------------------------| --- | --- | | fields | FormCraftField[] | Yes | Array of field configurations | | state | any | Yes | Form state object | | submit | ({ state, payload, errors }: FormCraftHandleSubmitParams) => Promise<any> | Yes | Submit handler function | | btnSubmit | ReactNode | No | Custom submit button | | className | string | No | CSS class for form element | | onChange | ({ field, value }: FormCraftOnChange) => void | No | Form change handler | | validationRules | ValidationRules | No | Validation rules for fields |

Interface FormCraftField

interface FormCraftField {
  name: string;
  type?: 
      'text' | 
      'email' | 
      'password' | 
      'select' | 
      'checkbox' | 
      'textarea' | 
      'file' | 
      'number' | 
      'date' |
      'radio' |
      'group' |
      string;
  placeholder?: string;
  options?: Array<{ value: string; label: string }>;
  control?: ReactElement | ComponentType<any>;
  onChange?: (e: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void;
  [key: string]: any;
}

Custom Form Controls

You can provide custom form controls using the property: control

import { MyCustomInput } from './components';

const fields = [
  {
    name: 'customField',
    control: <MyCustomInput className="custom-input" />
  }
];

const fields2 = [
    {
        name: 'customField',
        control: MyCustomInput
    }
];

Validation

FormCraft supports validation rules:

const validationRules = {
  username: { 
    required: {
      value: true,
      message: 'Name is required',
    },
    maxLength: {
      value: 10,
      message: 'Name is too long',
    },
    minLength: {
      value: 1,
      message: 'Name is too short',
    }
  },
  email: {
    ...
    email: {
      value: true,
      message: 'Email is invalid',
    },
    customRule: (value?: string) => {
      if (value && !value.includes('@')) {
        return { value, message: 'Email is invalid' };
      }
    }
  },
  age: {
    range: {
      value: [18, 100],
    },
  },
  birthday: {
    range: {
      value: [new Date(1991, 0, 1), new Date(2025, 0, 1)],
    },
  },
  ...
};

License

MIT