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-forms-materialize-css

v1.0.1

Published

A simple dynamic react form component which uses json to render a form with material css styling.

Downloads

5

Readme

react-forms-materialize-css 📋

A simple dynamic react form component which uses json to render a form with material css styling.

NPM JavaScript Style Guide

Install

npm install --save react-forms-materialize-css

Usage

Using react-forms-materialize-css is easy (not baised at all 😏)!

Prequesites ✋

  • You obviously need to make sure that you're using react ^15.0.0 or ^16.0.0.
  • You will need to install materialize-css and load the material icons resource in the head element of your index.html file. You will also have to install the materialize-css npm module
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

Step 1 (Defining our form JSON) 🏃

The react-forms-materialize-css ingests the form JSON and dynamically generates fields and their state variables in the form component. Currently you must find a way to serve this JSON file and this must be served under a /forms route. If you are using create-react-app this is fairly easy just add the json file in a forms folder under the public folder i.e. public > forms > [form-name].json .

Alright! Let's create a simple sign-up form asking for the first name, last name, email, password and an about you free text field. We will also add a submit button so that we can submit this form ( why else would you add a submit button ). We will see how we can add custom handlers in Step #2

[
    {
        "firstName": {
            "textFieldProps": {
                "id": "first_name",
                "placeholder": "First Name",
                "type": "text"
            },
            "labelText": "First Name",
            "icon": "account_circle",
            "classNames": [
                "s6",
                "active"
            ]
        },
        "lastName": {
            "textFieldProps" : {
                "id": "last_name",
                "placeholder": "Last Name",
                "type": "text"
            },
            "labelText": "Last Name",
            "classNames" : [
                "s6",
                "active"
            ]
        }
    },
    {
        "email": {
            "textFieldProps": {
                "id": "email",
                "placeholder": "[email protected]",
                "type": "email"
            },
            "labelText": "email",
            "icon": "email",
            "helperTextText": "Enter your email",
            "dataSuccess": "Valid Email",
            "dataError": "Invalid Email",
            "classNames" : [
                "s12"
            ]
        }
    },
    {
        "aboutYou": {
            "textAreaProps": {
                "id": "about_you",
                "placeholder": "Tell us a little about you"
            },
            "labelText": "About You",
            "classNames": [
                "s12"
            ]
        }
    },
    {
        "submit": {
            "icon": "send",
            "iconRight": true,
            "text": "Submit"
        }
    }
]

Now we add this form JSON to our forms folder or where this file can be served under the route /forms

signupform

Step 2 (Adding our component to our app) 🏃

Now we just need to add our form component

import React from "react";
import "materialize-css/dist/css/materialize.min.css";
import Form from "react-forms-materialize-css"

function App () {
    // we're going to define a submit handler here
    // we can do anything in this function
    // for this example we will create an object and log it to console 
    let handleSubmit = function(event){
        let data = {}
        // the this here will point to the Form component
        for (let item in this.state){
            /* values for the fields will have "Value" appended 
               to their state variable
            */ 
            if (item.indexOf("Value") !== -1) {
                data[item.split("Value")[0]] = this.state[item]
                console.log(item)
            }
        }
        console.log(data)
        event.preventDefault()
    }

    /* we're going to also define a function handle onChange events. Each individual field can be assigned a seperate handler or none at all */
    let handleChange = function(event){
        console.log(
            `${event.target.name} has value ${event.target.value}`
        )
    }
    return (
        <Form formDataFileName="signup.json" classNames={["s12"]}
              onSubmitFunc = {handleSubmit} onChangeFuncs ={{firstName: handleChange}}>
        </Form>
    )
}

export default App;

Step 3 (Start our application) 🏁

itworks

License

MIT © Moro-Code