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

@doughtnerd/qwizard-react

v0.0.21

Published

React bindings for [Qwizard Core](https://www.npmjs.com/package/@doughtnerd/qwizard-core)

Downloads

13

Readme

Qwizard React

React bindings for Qwizard Core

Usage

From this library, you will use two main parts of the API:

  • The FormConfig object to build your configs
  • The Form component to render your form

Using FormConfig

This is a helper object to create FormGroupConfigs, FormArrayConfigs, and FormControlConfigs.

To learn more about using the form config types, see Form Config API

import { 
  FormConfig,
  FormControlConfig,
  FormGroupConfig ,
  FormArrayConfig
} from "@doughtnerd/qwizard-react";

const formControl: FormControlConfig = FormConfig.Control('')
const formGroup: FormGroupConfig = FormConfig.Group({})
const formArray: FormArrayConfig = FormConfig.Array([])

Using Form Component

In order for your configs to be useful, you need to use the Form component to render your form.

To learn more about how the component works, see Form API

import { 
  Form,
  FormConfig,
  FormControlConfig,
  FormGroupConfig,
  FormArrayConfig
} from "@doughtnerd/qwizard-react";


function ExampleForm(): JSX.Element {
  const formControl: FormControlConfig = FormConfig.Control('')

  // The config prop will accept any form config type from this library
  return <Form config={formControl} />
}

API

Form Configs

FormControlConfig

This represents a single input on a form, like "First Name" or "State"

import { 
  Form,
  FormConfig,
  FormControlConfig
} from "@doughtnerd/qwizard-react";


const formControl: FormControlConfig = FormConfig.Control('', {
  /**
   * Use renderComponent to specify the component to use to render the input. 
   * You can use any Functional Component here.
   */ 
  renderComponent: MyInput // From MyInput.tsx
  // This is the data used during render
  renderData: {
    /**
     * If you have static props you want to supply to the component, 
     * set them here. They will be passed to your component.
     */ 
    inputProps: {
      id: 'example-input',
      type: 'text'
    },
    // Specify when to run validations. Defaults to blur
    validateOn: 'input',
    // Whether or not to use native HTML spec form validation. Defaults to false.
    enableNativeValidation: false,
    // What to do after the component validates. You shouldn't need to use this.
    onValidated
  }
}, 
  [Validators.notEmpty], // Sync validators go here 
  [] // Async validators go here
)

FormGroupConfig

This represents a grouping of controls on your form.

import { 
  Form,
  FormConfig,
  FormControlConfig,
  FormGroupConfig
} from "@doughtnerd/qwizard-react";


const formControl: FormGroupConfig = FormConfig.Group({
  password: FormConfig.Control(''),
  confirmPassword: FormConfig.Control('')
}, {
  /**
   * Use renderComponent to specify the component to use to render your FormGroupConfig. Optional
   */ 
  renderComponent: ({children, errors}) => {
    return children
  } 
  // This is the data used during render
  renderData: {
    /**
     * You can specify a component to use for all form controls in the group.
     */
    componentTemplate: MyInput
    /**
     * If using componentTemplate, this function allows you
     * to dynamically get props for each component
     */
    propsTemplate: (controlName: string) => {
      return {
        id: controlName
      }
    },
    // Specify when to run validations on children. Defaults to blur.
    validateOn: 'input',
    // If the FormGroupConfig should wait until all child forms validate before validating iteself.
    childrenFirst: false,
    // What to do after the component validates. You shouldn't need to use this.
    onValidated
  }
}, 
  [], // Sync validators for the group go here 
  [] // Async validators for the group go here
)

FormArrayConfig

This represents a grouping of controls on your form.

import { 
  Form,
  FormConfig,
  FormControlConfig,
  FormArrayConfig
} from "@doughtnerd/qwizard-react";


const formControl: FormArrayConfig = FormConfig.Array([
  FormConfig.Control('')
], {
  /**
   * Use renderComponent to specify the component to use to render your FormArrayConfig. Optional
   */ 
  renderComponent: ({children, errors}) => {
    return children
  } 
  // This is the data used during render
  renderData: {
    /**
     * You can specify a component to use for all form controls in the array.
     */
    componentTemplate: MyInput
    /**
     * If using componentTemplate, this function allows you
     * to dynamically get props for each component
     */
    propsTemplate: (index: number) => {
      return {
        id: `example-input-${index}`
      }
    },
    // Specify when to run validations on children. Defaults to blur.
    validateOn: 'input',
    // If the FormArrayConfig should wait until all child forms validate before validating iteself.
    childrenFirst: false,
    // What to do after the component validates. You shouldn't need to use this.
    onValidated
  }
}, 
  [], // Sync validators for the array go here 
  [] // Async validators for the array go here
)

Form Component

This component will render your entire form.


<Form 
  // Your form config goes here
  config={config} 
  // Any props you want to supply to the `form` element go here
  formProps={{style: {display: 'flex'}}}
  // Callback for after the form has validated
  onValidate={
    (results: ValidationResults) => {
      console.log("I've Validated!", results)
    }
  }
  // Callback for when the user submits the form. Prevents default behavior
  onSubmit={
    (event: CustomEvent) => {
      console.log("I'm Submitting!", event.detail)
    }
  }
  // If you'd rather use a function to render the form content (like if you want to reposition the form)
  renderFormContent={
    (childElement: React.ReactNode) => {
      return (
        <>
          <h1>My Cool Form!</h1>
          {childElement}
          <button type="submit">Submit</button>
        </>
      )
    }
  }
  // You can also supply children. They default to rendering below the form
  children={<button type="submit">Submit</button>}
/>

This library was generated with Nx.

Running unit tests

Run nx test react to execute the unit tests via Jest.