Skip to content

codeparl/form-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vue Form Builder

npm version License: MIT

A powerful, flexible, and customizable form builder component library for Vue 3 applications. Build dynamic forms with drag-and-drop functionality, multiple field types, internationalization support, and seamless integration with your existing Vue ecosystem.

✨ Features

  • πŸš€ Vue 3 + TypeScript - Built with modern Vue 3 Composition API and full TypeScript support
  • 🎯 Drag & Drop - Intuitive drag-and-drop interface for building forms
  • πŸ“ Multiple Field Types - Text, Number, Textarea, Select, Checkbox, Radio, Date, File, Button, Heading, Paragraph, Hidden
  • 🌍 Internationalization - Multi-language support (English, French, Spanish, Arabic, Russian, Chinese)
  • 🎨 Customizable Styling - Built with Tailwind CSS and Naive UI components
  • πŸ“± Responsive Design - Works seamlessly on desktop and mobile devices
  • πŸ’Ύ Export/Import - Save and load form configurations as JSON
  • 🧩 Component-based - Easy to integrate with existing Vue applications
  • πŸ”§ Highly Configurable - Extensive customization options
  • πŸ“Š Form Rendering - Built-in form renderer component

πŸ“¦ Installation

NPM

npm install form-builder

Yarn

yarn add form-builder

PNPM

pnpm add form-builder

πŸš€ Quick Start

Basic Usage

<template>
  <FormBuilder @save="handleSave" />
</template>

<script setup lang="ts">
import { FormBuilder } from 'form-builder'

const handleSave = sections => {
  console.log('Form saved:', sections)
}
</script>

With Options

<template>
  <FormBuilder :options="formBuilderOptions" :sections="initialSections" @save="handleSave" />
</template>

<script setup lang="ts">
import { FormBuilder } from 'form-builder'

const formBuilderOptions = {
  language: 'en',
  allowExport: true,
  allowImport: true,
}

const initialSections = [
  {
    id: 'section-1',
    title: 'Personal Information',
    fields: [
      {
        id: 'name',
        type: 'text',
        label: 'Full Name',
        required: true,
        placeholder: 'Enter your full name',
      },
    ],
  },
]

const handleSave = sections => {
  console.log('Form saved:', sections)
}
</script>

Form Rendering

<template>
  <div>
    <h2>Form Preview</h2>
    <FormRenderer :sections="formSections" @update="handleFormUpdate" />
  </div>
</template>

<script setup lang="ts">
import { FormRenderer } from 'form-builder'

const handleFormUpdate = formData => {
  console.log('Form data updated:', formData)
}
</script>

πŸ“š API Reference

FormBuilder Component

Props

Prop Type Default Description
options FormBuilderOptions {} Configuration options for the form builder
sections FormSection[] [] Initial form sections

Events

Event Payload Description
save FormSection[] Emitted when form is saved

FormBuilderOptions

interface FormBuilderOptions {
  language?: 'en' | 'fr' | 'es' | 'ar' | 'ru' | 'zh'
  allowExport?: boolean
  allowImport?: boolean
}

FormRenderer Component

Props

Prop Type Default Description
sections FormSection[] [] Form sections to render

Events

Event Payload Description
update Record<string, any> Emitted when form data changes

FormSection Interface

interface FormSection {
  id: string
  title?: string
  fields: FormField[]
  editable?: boolean
}

FormField Interface

interface FormField {
  id: string
  type: string
  subType?: string
  name: string
  label: string
  required?: boolean
  value?: any
  editable?: boolean
  category?: FieldCategory
  class?: string
  placeholder?: string
  helpText?: string
  min?: number
  max?: number
  step?: number
  options?: SelectOption[]
  multiple?: boolean
}

🎯 Available Field Types

Field Type Description Icon
text Single-line text input πŸ“
number Numeric input πŸ”’
textarea Multi-line text input πŸ“„
select Dropdown selection πŸ“‹
checkbox Checkbox input β˜‘οΈ
radio Radio button group πŸ”˜
date Date picker πŸ“…
file File upload πŸ“Ž
button Action button πŸ”˜
heading Section heading πŸ“°
paragraph Text paragraph πŸ“–
hidden Hidden input field πŸ‘οΈβ€πŸ—¨οΈ

🌍 Internationalization

The library supports multiple languages out of the box:

  • πŸ‡ΊπŸ‡Έ English (en)
  • πŸ‡«πŸ‡· French (fr)
  • πŸ‡ͺπŸ‡Έ Spanish (es)
  • πŸ‡ΈπŸ‡¦ Arabic (ar)
  • πŸ‡·πŸ‡Ί Russian (ru)
  • πŸ‡¨πŸ‡³ Chinese (zh)

Custom Language

import { FormBuilder } from 'form-builder'

// Add custom language
const customMessages = {
  field: {
    text: 'Champ de texte',
    button: 'Bouton',
    // ... other translations
  }
}

// Use in component
<FormBuilder :options="{ language: 'custom' }" />

🎨 Styling & Theming

The library uses Tailwind CSS for styling and Naive UI for components. You can customize the appearance by:

Custom CSS

/* Override default styles */
.form-builder {
  /* Your custom styles */
}

.form-builder .field-item {
  /* Custom field styling */
}

Theme Configuration

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        'form-builder-primary': '#your-color',
      },
    },
  },
}

πŸ“± Examples

Basic Form Builder

<template>
  <div class="container mx-auto p-4">
    <FormBuilder
      :options="{
        language: 'en',
        allowExport: true,
        allowImport: true,
      }"
      @save="handleSave"
    />
  </div>
</template>

<script setup lang="ts">
import { FormBuilder } from 'form-builder'

const handleSave = sections => {
  // Handle form save
  console.log('Saved sections:', sections)
}
</script>

Advanced Usage with Validation

<template>
  <div class="container mx-auto p-4">
    <FormBuilder :options="builderOptions" :sections="initialSections" @save="handleSave" />

    <div class="mt-8">
      <h3 class="text-lg font-semibold mb-4">Form Preview</h3>
      <FormRenderer :sections="formSections" @update="handleFormUpdate" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { FormBuilder, FormRenderer } from 'form-builder'
import { ref } from 'vue'

const formSections = ref([])

const builderOptions = {
  language: 'en',
  allowExport: true,
  allowImport: true,
}

const initialSections = [
  {
    id: 'contact-info',
    title: 'Contact Information',
    fields: [
      {
        id: 'email',
        type: 'text',
        label: 'Email Address',
        required: true,
        placeholder: 'Enter your email',
      },
      {
        id: 'phone',
        type: 'text',
        label: 'Phone Number',
        placeholder: 'Enter your phone number',
      },
    ],
  },
]

const handleSave = sections => {
  formSections.value = sections
  console.log('Form saved:', sections)
}

const handleFormUpdate = formData => {
  console.log('Form data:', formData)
}
</script>

πŸ”§ Development

Prerequisites

  • Node.js 16+
  • Vue 3.5+
  • TypeScript 5+

Setup

# Clone the repository
git clone https://github.com/codeparl/form-builder.git
cd form-builder

# Install dependencies
pnpm install

# Start development server
pnpm dev

# Build for production
pnpm build

# Run tests
pnpm test

# Lint code
pnpm lint

Project Structure

src/
β”œβ”€β”€ components/          # Vue components
β”‚   β”œβ”€β”€ FormBuilder.vue  # Main form builder component
β”‚   β”œβ”€β”€ FormRenderer.vue # Form rendering component
β”‚   β”œβ”€β”€ fields/          # Field components
β”‚   └── ...
β”œβ”€β”€ composable/          # Vue composables
β”œβ”€β”€ config/             # Configuration files
β”œβ”€β”€ css/                # Stylesheets
β”œβ”€β”€ data/               # Data and constants
β”œβ”€β”€ i18n/               # Internationalization
β”œβ”€β”€ types/              # TypeScript definitions
└── index.ts            # Main entry point

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support

πŸ”„ Changelog

See CHANGES.md for a list of changes and version history.


Made with ❀️ by Hassan Mugabo

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published