peterrwilson99 / form-builder-mui

https://form-builder-ts.vercel.app
0 stars 0 forks source link

Form Builder Mui

Form Builder Mui is a React library that allows you to create and view forms using Material-UI components. It provides a user-friendly interface for building forms and a form viewer to display and interact with the created forms.

Demo

A demo can be found here, displaying the core functionality of the components.

Features

Installation

Installing using npm

npm install form-builder-mui

Local Install

  1. Clone the repository:

    git clone https://github.com/peterrwilson99/form-builder-ts
  2. Install the dependencies:

    cd form-builder-mui/package
    npm install

Usage

Builder

The Builder component is responsible for creating and customizing forms. Here are the props it accepts:

Example usage

import { Box } from "@mui/material";
import Builder from "form-builder-mui/build/Builder";
import React from "react";

function FormBuilderExample({ form }) {
  const handleSave = (data) => {
    // handle saving of form data
    console.log(data);
  };

  return (
    <Box>
      <Builder form={form ?? []} saveForm={handleSave} />
    </Box>
  );
}

export default FormBuilderExample;

Viewer

The Viewer component displays and interacts with the forms created using the Builder. It accepts the following props:

Example usage

import { Box } from "@mui/material";
import Viewer from "form-builder-mui/build/Viewer";
import React from "react";

function FormViewerExample({ form }) {
  const onSubmit = (data) => {
    // handle submission of form data
    console.log(data);
  };

  const onSubmitPartial = (data) => {
    // handle submission of partial form data
    console.log(data);
  };

  return (
    <Box>
      <Viewer
        form={form}
        onSubmit={onSubmit}
        onSubmitPartial={onSubmitPartial}
        preview={false} // set to true to hide submit buttons
        disabled={false} // set to true to disable form and hide submit buttons
      />
    </Box>
  );
}

export default FormViewerExample;

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or feature requests, please open an issue or submit a pull request.