Skip to content
/ fresh Public
forked from leveluptuts/fresh

A fresh forms library for React. Highly opinionated, dead simple API.

Notifications You must be signed in to change notification settings

Yonben/fresh

 
 

Repository files navigation

@leveluptuts/fresh

YO! That's fresh (too fresh)

Bboy Headspinhttps

NPM

Demo

https://fresh.leveluptutorials.com/

Install

construction.gif

Use at your own risk, rapidly changing / not working.

construction.gif

yarn add @leveluptuts/fresh

Usage

A basic form

import { Form, Field } from '@leveluptuts/fresh';

<Form
  onSubmit={({ data }) => {
    console.log(data);
  }}
>
  <Field>Name</Field>
  <Field type="number">Number</Field>
  <Field type="select" options={options} />
</Form>;

A slightly less basic form

import { Form, Field } from '@leveluptuts/fresh';

<Form onSubmit={onSubmit}>
  <Field>Name</Field>
  <Field type="email">Email</Field>
  <Field type="password">Password</Field>
  <Field type="tags">Tags</Field>
  <Field type="number">Number</Field>
  <Field required type="select" options={options}>
    Type
  </Field>
  <Field type="textarea">Text Area</Field>
  <Field type="markdown">Markdown</Field>
  <Field type="toggle">Markdown</Field>
</Form>;

API

Form

The wrapper around your fields.

Prop Type Default Description
onSubmit func () => {} Can be any of the following types. text (default), email, number, select, password, tags. (See types below)
buttons boolean true if submit and cancel are shown
cancelButton boolean true if cancel is shown
disabled boolean false if the form is disabled

Field

Common API - The props that are common among all fields

The common API is shared among all elements. Type specific fields are found below.

Prop Type Default Description
type string 'text' Can be any of the following types. text (default), email, number, select, password, tags. (See types below)
required boolean false if a field is required
label boolean true if a field has a label

type - password

Prop Type Default Description
strength boolean true Shows or hides the password strength meter below the field

type - select

Prop Type Default Description
options array of strings [] The text and values of a select list. *Object support coming soon

Errors

Not complete / in use yet, just standard html 5 validation

FAQ

Can I customize this component in my own way?

This library makes some calls to keep the API easy to use and maintain. Using it with another library that tries to bring it's own inputs in isn't really needed at this time.

Contributing

yarn yarn start

(in another tab) to run example

cd example yarn yarn start

Prior Art and Inspirations

I am huge fan of simple, easy APIs that take care of 90% of jobs easily. One form library I really enjoyed was https://kozea.github.io/formol/ . The API was simple in all of the ways that I love, but there were some aspects of the library that just didn't fit for us and our workflow. I wanted to make something that was more simple, but just as easy but with more configuration options. I'm also inspired by AutoForm for Meteor https://github.com/aldeed/meteor-autoform for future generation features.

License

MIT © leveluptuts

About

A fresh forms library for React. Highly opinionated, dead simple API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.5%
  • HTML 1.7%
  • CSS 0.8%