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

mgr-form-react

v0.1.0

Published

Simple react form component. Generates a form based on json description

Downloads

1

Readme

mgr-form-react

Work in progress, please do not consider it yet as a working module

Coverage Status

Version until 0.1.0 are DEPRICATED!!! No support will follow.

Current package is under development and has the same name. It has breaking changes (basically it is rewritten from scratch, so nothing left from old version).

Introduction

mgr-form-react allows you to create complicated forms based on JSON description. The form description can be provided via network and so be stored on a server, be loaded from client side and even be shared between clients.

Rendering of form's inputs is done by "renderes". mgr-form-react provides you some default renderers such as input, select, checkbox etc. but you can define and register your own renderers during the application runtime. In the same way you can add validations and transformations to your fields by registering them and using in the field description. Also, you can define disable and hide functions on a field level that will define when the field should be disabled or hidden.

The submission part of the form is rendered in the same way that form's fields. You can use the default renderer for the submission (showing just a button) or create your custom submission renderer.

To know more about capabilities of mgr-form-react please refer to the documentation.

Example

import Form from 'mgr-form-react';

const description = {
  fields: [{
    name: 'username',
    renderer: 'input',
    validators: 'required',
    transformations: 'trim',

    placeholder: 'Username'
  }, {
    name: 'email',
    renderer: 'input',
    validators: ['required', 'email'],
    transformations: 'trim',

    placeholder: 'email',
  }, {
    name: 'age',
    label: 'Your age',
    renderer: 'selector',
    defaultValue: 1,

    options: [{
      label: '0-18',
      value: 0,
    }, {
      label: '19-45',
      value: 1,
    }, {
      label: '46-100',
      value: 2,
    }],
  }],
  submission: {
    renderer: 'button',
    label: 'Submit your data',
  },
};

export default () => (
  <Form description={description} />
);

To see more examples, please refer to the documentation.

Documentation

This package exports a <Form /> component by default and some usefull functions:

  • Form - component exported by default. It is the only exported react component taking the form description in props. Refer to its documentation for more information.
  • validateFormDescription - function that validates the form description. You can use it to validate a form description provided by server or vie third party provider. Read more about this validation function and the shape of description in the validation documentation.
  • registerValidator - function that registers the validation function to be used in a form. Refer to its documentation for more information.
  • registerTransformation - function that registers the transformation function to be used in a form. Refer to its documentation for more information.
  • registerFieldRenderer - function that registers the rendering function to be used in a form in order to render a field. Refer to its documentation for more information.
  • registerSubmissionRenderer - function that registers the rendering function to be used in a form in order to render the submission part. Refer to its documentation for more information.
  • FIELD_RENDERER_PROPS, SUBMISSION_RENDERER_PROPS - Prop. types definitions that describe minimal set of props that should be passed to a rendering functions. Refer to its documentation for more information.