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

form-validating-widget

v1.0.0

Published

A simple form validating widget

Readme

Form Validating Widget

Form Widget

A customizable and reusable form validation widget built with React, TypeScript, and Tailwind CSS. This widget includes advanced validation, error handling, micro-animations, and customizable styles, all in a production-ready npm package.

Form Validating Widget

A customizable and reusable form validation widget built with React, TypeScript, and Tailwind CSS. This widget includes advanced validation, error handling, micro-animations, and customizable styles, all in a production-ready npm package.

Features

  • Customizable form fields with various input types: text, email, password, tel, and select.
  • Advanced Validation for email, password, username, phone, and gender.
  • Error Handling with error messages displayed under each field.
  • Debouncing & Throttling for optimized form input handling.
  • Tailwind CSS for utility-first styling, with customizable styles.
  • Production-Ready and fully typed with TypeScript.
  • Micro-animations using CSS for smooth transitions and interactions.

Installation

To install the package, run the following npm command:

npm install form-validating-widget

Alternatively, if you're using yarn:

yarn add form-validating-widget

Usage

Importing Components

import { Form, InputField, useValidation } from "form-validating-widget";

Example Usage

Here’s a sample App.tsx to demonstrate how to use the package:

import { useState, useCallback } from "react";
import { Form, InputField, useValidation, debounce, throttle } from "form-validating-widget";

interface FormValues {
  [key: string]: string;
}

const App = () => {
  const { values, errors, handleChange } = useValidation();
  const [submittedData, setSubmittedData] = useState<FormValues | null>(null);

  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();

    const requiredFields = ["email", "password", "username", "phone", "gender"];
    const hasEmptyFields = requiredFields.some(field => !values[field]);
    const hasErrors = Object.values(errors).some(error => error !== null);

    if (!hasEmptyFields && !hasErrors) {
      setSubmittedData({ ...values });
      alert("Form submitted successfully!");
    } else {
      alert("Please fill all fields and fix any errors before submitting!");
    }
  };

  // Apply debounce and throttle to handleChange
  const debouncedHandleChange = useCallback(
    debounce((name: string, value: string, type: string) => {
      handleChange(name, value, type);
    }, 500),
    [handleChange]
  );

  const throttledHandleChange = useCallback(
    throttle((name: string, value: string, type: string) => {
      handleChange(name, value, type);
    }, 1000),
    [handleChange]
  );

  return (
    <div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-50 p-8">
      <div className="max-w-4xl mx-auto grid md:grid-cols-2 gap-8">
        <div className="bg-white rounded-xl shadow-lg p-8">
          <h2 className="text-2xl font-bold mb-6 text-transparent bg-clip-text bg-gradient-to-r from-blue-600 to-indigo-600">
            Registration Form
          </h2>

          <Form onSubmit={handleSubmit}>
            <InputField
              label="Email"
              name="email"
              value={values.email || ""}
              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
                debouncedHandleChange("email", e.target.value, "email")
              }
              error={errors.email}
              type="email"
              placeholder="Enter your email"
            />

            <InputField
              label="Password"
              name="password"
              value={values.password || ""}
              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
                throttledHandleChange("password", e.target.value, "password")
              }
              error={errors.password}
              type="password"
              placeholder="Enter your password"
            />

            <InputField
              label="Username"
              name="username"
              value={values.username || ""}
              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
                debouncedHandleChange("username", e.target.value, "text")
              }
              error={errors.username}
              type="text"
              placeholder="Enter your username"
            />

            <InputField
              label="Phone"
              name="phone"
              value={values.phone || ""}
              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
                throttledHandleChange("phone", e.target.value, "tel")
              }
              error={errors.phone}
              type="tel"
              placeholder="Enter your phone number"
            />

            <InputField
              label="Gender"
              name="gender"
              value={values.gender || ""}
              onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
                debouncedHandleChange("gender", e.target.value, "select")
              }
              error={errors.gender}
              type="select"
              options={["Male", "Female", "Other"]}
            />

            <button type="submit" className="w-full bg-blue-500 text-white py-3 px-6 rounded-lg">
              Submit
            </button>
          </Form>
        </div>

        <div className="bg-white rounded-xl shadow-lg p-8">
          <h2 className="text-2xl font-bold mb-6 text-indigo-600">Submitted Data</h2>
          {submittedData ? (
            <pre className="p-4 bg-gray-100 rounded-lg text-gray-600">
              {JSON.stringify(submittedData, null, 2)}
            </pre>
          ) : (
            <p className="text-gray-500">No data submitted yet</p>
          )}
        </div>
      </div>
    </div>
  );
};

export default App;

API

Form

A wrapper component to handle the form submission.

Props:

  • onSubmit: The callback function that is triggered when the form is submitted.

InputField

An individual input field component that can handle various input types (e.g., text, email, password, tel, select).

Props:

  • label: The label for the input field.
  • name: The name of the input field.
  • value: The value of the input field.
  • onChange: The callback to handle changes in the input.
  • error: The error message, if any, to display below the input.
  • type: The type of input (e.g., text, email, password, tel, select).
  • placeholder: The placeholder text for the input (optional).
  • options: An array of options for the select field (optional).

useValidation

A custom hook for form validation. This hook provides the current form values, errors, and a handleChange function to manage form input changes.

Return Values:

  • values: The current values of the form fields.
  • errors: The current errors for each form field.
  • handleChange: The function to handle form input changes.

Utilities

debounce

A utility function to debounce function calls.

Usage:

debounce((...args) => { /* function body */ }, delay);
  • func: The function to debounce.
  • delay: The delay in milliseconds.

throttle

A utility function to throttle function calls.

Usage:

throttle((...args) => { /* function body */ }, limit);
  • func: The function to throttle.
  • limit: The time interval (in milliseconds) for throttling.