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

@panderalabs/redux-form-semantic

v0.1.2

Published

Multiple components integrating redux-form and semantic-ui-react together for standardized error handling.

Downloads

5

Readme

Redux Form + React SemanticUI Bindings

==============

Multiple helper components binding redux-form and semantic-ui-react together for standardized error handling.

npm install --save redux-form
npm install --save semantic-ui-react
npm install --save @panderalabs/redux-form-semantic

Why do I need this?

Redux Form is an excellent library for managing complex form state in the UI. Semantic UI React is a great library of UI Components (including form components). To make Redux Form work with the components, a certain amount of boilerplate is required to hook up your components to Redux-Form. In some cases, that boilerplate includes having to call events on the Semantic UI component when a change occurs in Redux-Form. This library helps remove that boilerplate and makes it easier to connect your error messaging with your form elements.

How do I use it?

Installation

Install via npm:

npm install --save redux-form
npm install --save semantic-ui-react
npm install --save @panderalabs/redux-form-semantic

Hook up redux-form middleware

Hook up your form to redux-form:

import { createStore, combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form'

const rootReducer = combineReducers({
  // ...your other reducers here
  // you have to pass formReducer under 'form' key,
  // for custom keys look up the docs for 'getFormState'
  form: formReducer
})

const store = createStore(rootReducer)

Wrap a Semantic-UI form with Redux-Form

Create a new Semantic UI form & wrap it in redux-form:

import React from 'react'
import { Field, reduxForm } from 'redux-form'
import { Form } from 'semantic-ui-react';

const ContactForm = props => {
  const { handleSubmit } = props
  return (
    <Form onSubmit={ handleSubmit }>
      { /* form body*/ }
    </Form>
  )
}

ContactForm = reduxForm({
  // a unique name for the form
  form: 'contact'
})(ContactForm)

export default ContactForm;

Add Form Components

import React from 'react'
import { Field, reduxForm } from 'redux-form'
import { Form, Button } from 'semantic-ui-react';
import { TextField } from '@panderalabs/redux-form-semantic'

const ContactForm = props => {
  const { handleSubmit } = props
  return (
    <Form onSubmit={ handleSubmit }>
      <Form.Field>
        <TextField
          name="firstName"
          label="First Name"
          placeholder="Enter First Name"
        />
      </Form.Field>
      <Form.Field>
        <TextField
          name="lastName"
          label="Last Name"
          placeholder="Enter Last Name"
        />
      </Form.Field>
      <Button>Save</Button>
    </Form>
  )
}

export default reduxForm({
  // a unique name for the form
  form: 'contact'
})(ContactForm)

Validate some fields

import React from 'react'
import { Field, reduxForm } from 'redux-form'
import { Form, Button } from 'semantic-ui-react';
import { TextField } from '@panderalabs/redux-form-semantic'

const ContactForm = props => {
  const { handleSubmit } = props
  return (
    <Form onSubmit={ handleSubmit }>
      <Form.Field>
        <TextField
          name="firstName"
          label="First Name"
          placeholder="Enter First Name"
        />
      </Form.Field>
      <Form.Field>
        <TextField
          name="lastName"
          label="Last Name"
          placeholder="Enter Last Name"
        />
      </Form.Field>
      <Button>Save</Button>
    </Form>
  )
}

const Validator = values => ({
  firstName: (!values.firstName || !values.firstName) && 'Required',
  lastName: (!values.lastName || !values.lastName) && 'Required',
});

export default reduxForm({
  // a unique name for the form
  form: 'contact',
  validate: validator,
})(ContactForm)

Implemented Components

Fields are a combination of label, input, error.

  1. TextField
  2. TextAreaField
  3. SelectField
  4. MultiSelectField
  5. CheckboxField
  6. ToggleField
  7. SliderField
  8. RadioField

#Demo

Error Props

To manage how your errors look we have access to a few props

errorPositon: left | right | bottom | top
errorStyles: ['basic', 'pointer']
errorColor: any semantic color

errorColor

Example TextField

import { TextField } from '@panderalabs/redux-form-semantic'

<Form onSubmit={handleSubmit}>
  <TextField
    name="firstName"
    label="First Name"
    placeholder="Enter your first name"
  />
</Form>

Example TextAreaField

import { TextAreaField } from '@panderalabs/redux-form-semantic'

<Form onSubmit={handleSubmit}>
  <TextAreaField
    name="description"
    label="description"
    placeholder="Describe your issue."
  />
<Form>

Example SelectField

import { SelectField } from '@panderalabs/redux-form-semantic'

<Form onSubmit={handleSubmit}>
  <SelectField
    name="vehicle"
    label="Vehicle"
    placeholder="Select your vehicle"
    options=[
      {key: '1', value: 'ford', text: 'Ford'},
      {key: '2', value: 'dodge', text: 'Dodge'},
    ]
  />
<Form>