You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-smart-fields

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-smart-fields

> A flexible, customizable, and developer-friendly component to generate dynamic form fields in React. Supports all HTML inputs, validation, and styling out of the box.

1.1.6
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

🧹 DynamicFields React Component

npm downloads license

A flexible, fully-styled dynamic form generator built with React and Tailwind CSS, supporting custom input types, validation, and class overrides. Ideal for building forms quickly with full control over design and behavior.

✨ Features

  • 📦 Supports text, number, checkbox, radio, and select fields
  • 💅 Fully customizable via Tailwind-compatible className props
  • 🧠 Built-in required field validation
  • 🧱 Extensible for advanced usage
  • 🌃 Full dark mode support
  • 🔄 Real-time onChange callback with live formData and errors

📦 Installation

Copy the DynamicFields.tsx file into your React project.

Make sure you have Tailwind CSS and React configured in your app.

🚀 Usage

Basic Example

import React from "react";
import DynamicFields from "./DynamicFields";

const fields = [
  {
    name: "username",
    label: "Username",
    type: "text",
    required: true,
  },
  {
    name: "email",
    label: "Email",
    type: "text",
    required: true,
  },
  {
    name: "gender",
    label: "Gender",
    type: "radio",
    required: true,
    options: [
      { label: "Male", value: "male" },
      { label: "Female", value: "female" },
    ],
  },
  {
    name: "country",
    label: "Country",
    type: "select",
    options: [
      { label: "USA", value: "us" },
      { label: "India", value: "in" },
    ],
  },
  {
    name: "subscribe",
    label: "Subscribe",
    type: "checkbox",
  }
];

function App() {
  const handleChange = (data) => {
    console.log("Form Data:", data);
  };

  return (
    <DynamicFields
      fields={fields}
      title="Sign Up"
      description="Please fill all fields"
      onChange={handleChange}
    />
  );
}

⚙️ Props

PropTypeRequiredDescription
fieldsFieldConfig[]✅ YesList of field definitions
onChange(data: Record<string, any>) => void✅ YesCallback on value change
titlestring❌ NoOptional form title
descriptionstring❌ NoOptional description
classNamestring❌ NoWrapper div styling
mainFieldClassNamestring❌ NoClass for the fields wrapper
inputClassNamestring❌ NoApplies to text/number inputs
labelClassNamestring❌ NoApplies to all labels
fieldClassNamestring❌ NoApplied to each field wrapper div
errorClassNamestring❌ NoError message styling
selectClassNamestring❌ Noselect field styling
checkboxClassNamestring❌ NoCheckbox input styling
radioClassNamestring❌ NoRadio input styling
optionClassNamestring❌ NoDropdown option styling

🔧 FieldConfig (field definition)

Each field object can contain:

PropertyTypeRequiredNotes
namestring✅ YesUnique key
labelstring❌ NoDisplay label
type"text", "number", "select", "radio", "checkbox"✅ YesField type
requiredboolean❌ NoShow red asterisk and basic validation
placeholderstring❌ NoPlaceholder (for inputs/selects)
descriptionstring❌ NoOptional helper text
options{ label: string; value: any; }[]Required for select and radioDropdown/Radio values

🎨 Class Mapping

Here's how classes are applied to each section:

SectionClass PropDefault Tailwind Example
Wrapper divclassNamebg-white dark:bg-gray-900
Label textlabelClassNametext-gray-800 dark:text-gray-200
Input fieldsinputClassNamebg-white dark:bg-gray-800
Select dropdownselectClassNamerounded-lg
Radio buttonsradioClassNamerounded-full
CheckboxcheckboxClassNamerounded
Field container divfieldClassNamew-full
Dropdown optionsoptionClassNamehover:bg-gray-100
Error messageserrorClassNametext-red-500

You can override all styles with your own Tailwind classes!

🧪 Advanced Usage: Custom Styling Per Field

You can add inputClassName, labelClassName, or className inside each field:

{
  name: "email",
  label: "Email",
  type: "text",
  inputClassName: "border-purple-500",
  labelClassName: "text-purple-700 font-semibold",
  className: "mb-6",
}

🧑‍💻 Author

Name: Pratik Panchal GitHub: @Pratikpanchal25

📄 License

MIT — Free to use, modify and distribute.

🛠 Contributing

Pull requests are welcome! If you find bugs, feel free to open an issue.

Keywords

DynamicFields

FAQs

Package last updated on 02 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts