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

semantic-data-form

v0.4.2

Published

Configurable data form based on Semantic UI and Formik

Downloads

114

Readme

semantic-data-form

Easy way to render json based forms suing SemanticUI and Formik

Form data structure

Wrapped with Formik form and Symantic Form Fields having following props:

  • className: set custom class names to form tag.
  • validationSchema: will be yup object for simple and clean validations
  • initialValues: Fromik needs default values to all props it needs to bind, even if there is no initial value is there to bind define a empty structure and set it.
  • onSubmit: fn that will be called on Submit button click
  • onCancel: fn that wtill be called on Cancel button click
  • showCancel: to show Cancel Button, make sure you set onCancel with it. Default is false
  • submitText: set custom Submit button text. Default is "Submit"
  • cancelText: set custom Cancel button text. Default is "Cancel"
  • fieldGroups: of array of Grid.Column wrapped in single Symantic Grird.Row having Fields inside Symantic Form.Group
    • fields: it can be single DataFormField or Array, DataFormField looks like as
      • type: type of field that we want to render, e.g. text, email, dropdown etc.

      • name: name of field, will be used by Formik to bind data with.

      • placeholder: will be used for types: text | email | textArea

      • label: label text for field

      • style: custom style object

      • options: in case of dropDown use it to pass on options

      • disabled: to show disabled input

      • loading: to show loading, works for text and drop down only

      • hideErrorLabel: to stop showing error label

      • render: in default supported types does not meet the requirement, set type = Custom and define render fn, fn will be passed on Formik useField hook data as individual param

Use Case

import React from 'react';
import * as yup from 'yup';

import DataForm, { DataFormFieldType } from 'semantic-data-form';
import { Link } from 'react-router-dom';


const schema = yup.object().shape({
  email: yup.string().email('Invalid email').required('Required'),
  password: yup.string().min(5, 'Must be more than 5 char').required('Required'),
});

export default function MyComponent() {
  return (
    <>
      <DataForm
        validationSchema={schema}
        initialValues={{
          email: '',
          password: '',
        }}
        onSubmit={async (values: any) => {
          await new Promise((resolve) => {
                    setTimeout(resolve, 1000 * 1)
                  }); // simulate save operation
        }}

        width={8}
        fieldGroups={[
          {
            fields: { label: 'Email', name: 'email', type: DataFormFieldType.Email }
          },
          {
            fields: { label: 'Password', name: 'password', type: DataFormFieldType.Password }
          }
        ]}
      />
    </>
  )
};

Examples

check src/containers/ComplexForm for a more complex example

Update History

  • Clear submit form Success/Error message after a interval. Also added a optional cb to get onSubmitError
  • Custom field render param will have extra prop, formProps: FormikProps