npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-form-element-builder

v0.0.4

Published

React Form Builder

Downloads

11

Readme

react-form-builder

Form builder for React. Packages with TailwindCSS.

Installation

npm install react-form-element-builder --save

View-Only Form Usage (Basic)

  1. Import the package(s) you'd like to use.
import { Core, Mantine } from "react-form-element-builder";
  1. Create an array of ViewFormElements thatfor the data you want to display
const [myData, setMyData] = useState<any>({ first: "John", last: "Smith" });
const viewFormElements: Core.IViewFormElement<Mantine.BasicViewTypes>[] = [
    { value: myData.first, type: "text", label: "First", span: 6 },
    { value: myData.last, type: "text", label: "Last", span: 6 },
];
  1. Render the form with the ViewFormBuilder
<Mantine.ViewFormBuilder prefix="viewform_" formElements={viewFormElements} renderer={Mantine.MantineViewRenderer} />

Editable Form Usage (Basic)

  1. Import the package(s) you'd like to use
import { Core, Mantine } from "react-form-element-builder";
  1. Create an array of EditFormElements thatfor the data you want to display
const [myData, setMyData] = useState<any>({ first: "John", last: "Smith" });
const editFormElements: Core.IEditFormElement<Mantine.BasicEditTypes>[] = [
    { 
      value: myData.first, type: "text", label: "First", placeholder: "First", 
      propertyName: "first", disabled: false, span: 6, required: true 
    },

    { 
      value: myData.last, type: "text", label: "Last", placeholder: "Last", 
      propertyName: "last", disabled: false, span: 6, required: true 
    },
];
  1. Render the form with the EditFormBuilder
<Mantine.ViewFormBuilder prefix="viewform_" formElements={viewFormElements} renderer={Mantine.MantineViewRenderer} />

Data Types

Change the type of data for the form elements to control how they will be rendered or edited.

Complete Example (Basic)

import { useState } from "react";
import { Core, Mantine } from "react-form-element-builder";

export default function Home() {
  const [myData, setMyData] = useState<any>({ first: "John", last: "Smith" });
  const viewFormElements: Core.IViewFormElement<Mantine.BasicViewTypes>[] = [
    { value: myData.first, type: "text", label: "Name", span: 6 }
  ];

  const editFormElements: Core.IEditFormElement<Mantine.BasicEditTypes>[] = [
    { 
      value: myData.first, type: "text", label: "First", placeholder: "First", 
      propertyName: "first", disabled: false, span: 6, required: true 
    },

    { 
      value: myData.last, type: "text", label: "Last", placeholder: "Last", 
      propertyName: "last", disabled: false, span: 6, required: true 
    },
  ];  

  return (
    <div>
        <Mantine.ViewFormBuilder 
            prefix="viewform_" 
            formElements={viewFormElements} 
            renderer={Mantine.MantineViewRenderer} 
        />

        <Mantine.EditFormBuilder 
            prefix="editform_"
            formElements={editFormElements}
            onChange={(formElement, value) => {
                setMyData({ ...myData, [formElement.propertyName]: value });
            }}
            renderer={Mantine.MantineEditRenderer}
        />
    </div>
  )
}

Usage (Advanced)

  1. Create a type specifying which datatypes you want to support.
import { BasicViewTypes } from "react-form-element-builder";

export type MyBasicTypes = BasicViewTypes & {
    "myCustomType": "";
}
  1. Create a renderer that renders each datatype that you specified. If you want to reuse existing types, you can simply handle the new types you added and fallback to the preconfigured package for everything else.
import { Core } from "react-form-element-builder";

function basicRenderer(formElement: Core.IViewFormElement<BasicTypes>): JSX.Element | null {
    let el = null;
    switch(formElement.type)
    {
        case "myCustomType":
        el = 
            <>
            <span>{formElement.label}</span>
            <span>{formElement.value ?? "-"}</span>
            </>
        return el;

        // Add additional types here
    }

    // Fallback to MantineViewRender for everything else...
    return Mantine.MantineViewRenderer(formElement);
}
  1. Create an object for all the properties you want in your form
const myFormElements: Core.IViewFormElement<BasicTypes>[] = [
    { value: "John",  type: "text",      label: "First name",  span: 6 },
    { value: "Doe",   type: "text",      label: "Last name",   span: 6 }
    { value: 25,      type: "number",    label: "Age",         span: 4 },
];
  1. Render your form and specify the renderer you want to use
import { editRenderer } from "./../components/editRenderer";

<Core.ViewFormBuilder 
    formElements={myFormElements} 
    prefix="myForm_" 
    renderer={basicRenderer} 
/>

Test

  • yarn storybook

Build/Publish

Rollup

  • yarn rollup

Publish/Deploy

  • Increment version
  • yarn rollup
  • yarn storybook (make sure everything looks ok)
  • npm publish
  • yarn build-storybook
  • Publish the static files to plasmafhir.com/plasma-fhir-react-components

Issues

  • Error: Could not resolve entry module (dist/esm/types/index.d.ts).
    • https://github.com/alexeagleson/template-react-component-library/issues/2