1.0.2 • Published 5 months ago
jm_dynamicform v1.0.2
React Dynamic Form Builder
A powerful and flexible dynamic form builder for React applications. Build complex forms with multiple input types, validation, conditional logic, and more.
Features
- 🎨 Multiple input types (text, dropdown, checkbox, color picker, signature pad, etc.)
- ✨ Beautiful UI with Tailwind CSS
- 🔄 Conditional logic
- ✅ Built-in validation
- 📱 Fully responsive
- 🎯 TypeScript support
- 🎨 Customizable themes
- 📦 Zero dependencies (except React and minimal UI libraries)
Installation
npm install react-dynamic-form-builder
Quick Start
import { FormBuilder, FormConfig, FormData } from 'react-dynamic-form-builder';
function App() {
const handleSubmit = (data: FormData) => {
console.log('Form data:', data);
};
const config: FormConfig = {
form: {
style: "subheadings",
showHeader: true,
headerTitle: "My Form",
headerSubTitle: "Please fill out the information",
buttons: {
primary: {
backgroundColor: "#2563eb",
hoverBackgroundColor: "#1d4ed8",
textColor: "#ffffff",
focusRingColor: "#3b82f6"
},
secondary: {
backgroundColor: "#f9fafb",
hoverBackgroundColor: "#f3f4f6",
textColor: "#374151",
focusRingColor: "#6b7280"
}
}
},
sections: [
{
section_id: "personal_info",
section_name: "Personal Information",
order: 1,
description: "Basic details",
showHeader: true
}
],
questions: [
{
question_id: "name",
question_text: "What is your name?",
question_style: "text",
mandatory: "yes",
validations: [],
placeholder_text: "Enter your name",
section_id: "personal_info",
order: 1,
field_width: "full"
}
]
};
return <FormBuilder config={config} onSubmit={handleSubmit} />;
}
Available Question Types
text
- Single line text inputtextarea
- Multi-line text inputdropdown
- Single select dropdowncheckbox
- Single checkboxradio buttons
- Radio button groupmulti-select dropdown
- Multiple select dropdowncolor picker
- Color selectiondate picker
- Date selectionfile upload
- File upload with previewsignature pad
- Signature captureslider
- Numeric slider
Configuration
Form Configuration
The form configuration object (FormConfig
) has three main sections:
form
- General form settingssections
- Form sectionsquestions
- Form questions
Form Settings
interface FormStyle {
style: "tabs" | "subheadings";
showHeader: boolean;
headerTitle: string;
headerSubTitle: string;
buttons: {
primary: ButtonStyle;
secondary: ButtonStyle;
};
}
Section Configuration
interface Section {
section_id: string;
section_name: string;
order: number;
description: string;
showHeader?: boolean;
}
Question Configuration
interface Question {
question_id: string;
question_text: string;
question_style: string;
mandatory: "yes" | "no";
validations: ValidationRule[];
dependency_question_id: string;
dependency_answers: string[];
placeholder_text: string;
help_text: string;
default_value: any;
order: number;
field_width: "full" | "half";
section_id: string;
visibility: "visible" | "hidden";
options?: Option[];
}
Validation
Add validation rules to questions:
validations: [
{
pattern: "^[A-Za-z\\s]+$",
error_message: "Only letters are allowed"
},
{
pattern: "^.{3,}$",
error_message: "Minimum 3 characters required"
}
]
Conditional Logic
Make questions appear based on other answers:
{
question_id: "has_pet",
question_text: "Do you have a pet?",
question_style: "checkbox",
// ...
},
{
question_id: "pet_name",
question_text: "What's your pet's name?",
question_style: "text",
dependency_question_id: "has_pet",
dependency_answers: [true],
// ...
}
Styling
The form uses Tailwind CSS for styling. You can customize the appearance by:
- Using your own Tailwind configuration
- Customizing the button styles in the form config
- Overriding CSS classes
TypeScript Support
The package includes full TypeScript definitions. Import types:
import type {
FormConfig,
FormData,
Question,
Section,
ValidationRule,
Option
} from 'react-dynamic-form-builder';
Development
- Clone the repository
- Install dependencies:
npm install
- Start development server:
npm run dev
- Build:
npm run build
License
MIT