Skip to content

brijr/forms

Repository files navigation

Forms - Form Builder & Component Registry

Website: forms.bridger.to

A powerful form builder built with Next.js, React, Tanstack Forms, and shadcn/ui. This project features a drag-and-drop form builder component and a shareable component registry for seamless reuse.

Quick Install

npx shadcn@latest add https://forms.bridger.to/r/form-builder.json

This automatically installs all dependencies including the inline-edit component.


Features

  • 🎨 Visual Form Builder – Intuitive drag-and-drop UI for designing forms
  • πŸ“ Flexible Field Types – Text, email, phone, number, textarea, select, radio, checkbox, switch, slider, and more
  • βœ… Form Validation – Built-in validation powered by Zod schemas
  • 🎯 Component Registry – Easily install components via the shadcn CLI
  • ⚑ shadcn/ui Compatible – Built on top of shadcn/ui for great design and flexibility

Getting Started

Prerequisites

  • Node.js 18+
  • pnpm (recommended), or npm/yarn

Installation

# Clone the repository
git clone https://github.com/brijr/forms.git
cd forms

# Install dependencies
pnpm install

# Start the development server
pnpm dev

Visit http://localhost:3000 to use the form builder.


Component Registry

This project provides a shadcn-compatible component registry for easy integration into other projects.

Available Components

Inline Edit

A click-to-edit component supporting both single-line and multiline inline editing.

Registry Dependencies: input, textarea

Form Builder

A fully-featured form builder with drag-and-drop, field validation, and form rendering.

Registry Dependencies: inline-edit, button, input, textarea, select, checkbox, radio-group, switch, slider, field, dialog, label, dropdown-menu, sidebar

NPM Dependencies: @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities, @tanstack/react-form, @tanstack/zod-form-adapter, zod, sonner, lucide-react


Building the Registry

To generate the registry files:

pnpm run registry:build

This command creates JSON bundles in public/r/ for use by the shadcn CLI.


Installing Components

Install the form builder (includes all dependencies):

npx shadcn@latest add https://forms.bridger.to/r/form-builder.json

Or install just the inline-edit component:

npx shadcn@latest add https://forms.bridger.to/r/inline-edit.json

Local Development

npx shadcn@latest add http://localhost:3000/r/form-builder.json

Note: Components will be installed to components/forms/ directory. The inline-edit component will be installed to components/ui/inline-edit/.


Using the Form Builder

After installation, you can use the FormBuilder component:

import { FormBuilder } from "@/components/form-builder";

export default function Page() {
  return <FormBuilder />;
}

Using JSON Utilities

The form builder includes JSON import/export utilities that can be used independently:

import {
  downloadFormConfig,
  parseFormConfig,
  type FormConfig
} from "@/components/form-builder";

// Export a form configuration to JSON
const formConfig: FormConfig = {
  id: "form_123",
  title: "My Form",
  fields: [...]
};

downloadFormConfig(formConfig); // Downloads as JSON file

// Parse and validate an imported form configuration
const jsonString = `{"id": "form_123", "title": "My Form", "fields": []}`;
const config = parseFormConfig(jsonString);
if (config) {
  // Use the validated config
  console.log(config);
}

Available Exports

From @/components/form-builder:

Components:

  • FormBuilder - The main form builder component
  • FormRenderer - Component to render forms from configuration

Hooks:

  • useFormBuilder - Hook for form state management (fields, selection, view mode, CRUD operations)

Types:

  • FormConfig - Complete form configuration
  • FieldConfig - Individual field configuration
  • FieldType - Available field types
  • FieldOption - Options for select/radio/checkbox fields
  • ValidationRule - Validation rules for fields
  • ViewMode - Builder view modes ("builder" | "preview" | "json")

Utilities:

  • downloadFormConfig(formConfig) - Export form config as JSON file
  • parseFormConfig(jsonString) - Parse and validate JSON form config
  • createDefaultField(type, index) - Create a field with defaults
  • createEmptyForm() - Create an empty form configuration
  • generateFormSchema(config) - Generate Zod schema for form validation
  • getDefaultValues(config) - Extract default values from config
  • FIELD_TYPES - Array of available field type configurations
  • CATEGORIES - Field type categories for the toolbox

Registry Structure

registry/
β”œβ”€β”€ inline-edit/
β”‚   └── inline-edit.tsx
└── form-builder/
    β”œβ”€β”€ lib/
    β”‚   β”œβ”€β”€ form-config.ts
    β”‚   └── form-utils.ts
    β”œβ”€β”€ field-editor.tsx
    β”œβ”€β”€ field-preview.tsx
    β”œβ”€β”€ field-toolbox.tsx
    β”œβ”€β”€ floating-controls.tsx
    β”œβ”€β”€ form-builder.tsx
    β”œβ”€β”€ form-renderer.tsx
    β”œβ”€β”€ index.ts
    β”œβ”€β”€ option-list.tsx
    β”œβ”€β”€ sortable-field.tsx
    └── use-form-builder.ts

Installation Structure: When installed via shadcn, everything goes into components/form-builder/:

components/
β”œβ”€β”€ form-builder/
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ form-config.ts
β”‚   β”‚   └── form-utils.ts
β”‚   β”œβ”€β”€ field-editor.tsx
β”‚   β”œβ”€β”€ field-preview.tsx
β”‚   β”œβ”€β”€ field-toolbox.tsx
β”‚   β”œβ”€β”€ floating-controls.tsx
β”‚   β”œβ”€β”€ form-builder.tsx
β”‚   β”œβ”€β”€ form-renderer.tsx
β”‚   β”œβ”€β”€ index.ts
β”‚   β”œβ”€β”€ option-list.tsx
β”‚   β”œβ”€β”€ sortable-field.tsx
β”‚   └── use-form-builder.ts
└── ui/
    └── inline-edit.tsx

Project Structure

β”œβ”€β”€ app/                    # Next.js app directory
β”œβ”€β”€ components/
β”‚   └── ui/                # shadcn/ui components
β”œβ”€β”€ lib/                   # Shared utilities
β”œβ”€β”€ registry/              # Component registry (source of truth)
β”‚   β”œβ”€β”€ form-builder/      # Form builder components
β”‚   └── inline-edit/       # Inline edit component
β”œβ”€β”€ public/
β”‚   └── r/                 # Generated registry JSON files
└── registry.json         # Registry entry point

Development

Scripts

  • pnpm dev – Start development server
  • pnpm build – Build for production
  • pnpm start – Run production server
  • pnpm lint – Run ESLint
  • pnpm registry:build – Build registry JSON files

Learn More


License

MIT

About

An Open Source Form Builder using React, shadcn/ui, Tanstack Form, and Typescript

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published