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 🙏

© 2024 – Pkg Stats / Ryan Hefner

forms-creator

v1.1.1

Published

A React component for creating dynamic forms with validation using Zod schemas.

Downloads

8

Readme

Forms Creator

A React component for creating dynamic forms with validation using Zod schemas.

Installation

You can install the forms-creator package via npm:
npm install forms-creator
or yarn
yarn add forms-creator

Usage

Importing the Component

import FormCreator from 'forms-creator'

Creating Form Fields

Consider organizing your form field definitions in a forms folder. Each form can have its own file containing the field definitions.

For example, you can create a LoginForm.ts file inside the forms folder:

// forms/LoginForm.ts
import { z } from 'zod'
import { FieldObject } from 'forms-creator/types'

export const loginFormFields: FieldObject[] = [
{
name: "username",
value: "",
type: "text",
label: "Username",
validationSchema: z.string().min(3, "Username must be at least 3 characters long"),
isRequired: true,
errorClassName: "error",
},
{
name: "password",
value: "",
type: "password",
label: "Password",
validationSchema: z.string().min(6, "Password must be at least 6 characters long"),
isRequired: true,
errorClassName: "error",
},
]

Using the FormCreator Component

import { loginFormFields } from './forms/LoginForm'

// Inside your component
<FormCreator className='form' fields={loginFormFields} onSubmit={handleSubmit} submitText='Login' />

Handling Form Submission

import {Typeofy} from "forms-creator"

const handleSubmit = (formData:Typeofy(loginFormFields)) => {
// Handle form submission here
console.log('Form data:', formData)
}

Props

| Prop | Type | Description | | --------------- | ----------------- | ------------------------------------------------------------------------------- | | className | String | CSS class name for styling the form itself. | | fields | Array | An array of FieldObject instances representing form fields. | | onSubmit | Function | A function to handle form submission. It receives the form data as an argument. | | submitText | String (optional) | Text to display on the submit button (default is "Submit"). | | submitClassName | String (optional) | CSS class name for styling the submit button. |

Field Options

| Option | Type | Description | | ---------------- | --------------------------------- | ------------------------------------------------------------------------------------- | | name | String | The name of the form field. | | value | String | Number | Boolean | The initial value of the form field. | | type | String | The type of the form field (text - number - textarea - checkbox - file). | | className | String (optional) | CSS class name for styling the input field. | | parentClassName | String (optional) | CSS class name for styling the parent div of the input field. | | child | React.ReactNode (optional) | React node for rendering additional content inside the parent div of the input field. | | customInput | Custom React Component (optional) | Custom React component for rendering the input field. | | validationSchema | Zod Schema (optional) | Zod schema for validating the input field value. | | label | String (optional) | Label text for the input field. | | isRequired | Boolean (optional) | Boolean indicating whether the input field is required. | | errorClassName | String (optional) | CSS class name for styling the error message. |