0.13.4 • Published 2 years ago

react-wizardry v0.13.4

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

License npm bundle size (version) Snyk Version

react-wizardry is a data-driven smart wizard component for creating powerful forms with in built validations.


demo

Demo

  • ⚡Data driven API
  • ✅In built validations
  • 💪Built with Typescript
  • 💡Intuitive stepper interface
  • 🎨Customizable Theme

📦 Installation

Install the package via npm or yarn

npm install react-wizardry
yarn add react-wizardry

🚀 Getting Started

The component takes a pages collection and renders the pages in a stepper interface.The pages appear in the order they are passed in the pages collection.

The example shows a simple wizard with two pages.

<Wizard
  pages={[
    {
      title: "Introduction",
      fields: [
        {
          label: "Name",
          name: "name",
          type: "text",
          isRequired: true,
        },
      ],
  },
  {
    title: "Contact",
    fields: [
      {
        label: "Email",
        name: "email",
        type: "email",
        isRequired: true,
      },
    ],
 }
},

⚙️ Properties

NameDescriptionDefault
bodyHeightSets the height of the form body500
highlightFieldsOnValidationHighlights the fields when the validation fails or succeedsfalse
onFinishCallback executed on final step
pagesCollection of Page object
RTLEnables right to left modefalse
showStepperTitlesUse this prop to display page titles under the stepper pointsfalse
silentValidation errors are flagged subtly. Validation messages are displayed only when the mouse is hovered over the fieldfalse
stepperItemWidthSets the width of each stepper item"200px"
strictValidation rules are applied to all inputs that have been marked for validation or that are required.The component prevents the user from moving on until the current step's errors have been fixedfalse
themeTheme object for customized styling

Page

Page object is at the core of the wizard. Page object is used to define the title, description, fields, and validation rules for a page.

NameDescriptionType
fieldsFields of the PageArray
finishMessageCustom message to be displayed on finish operationString
globalFormErrorMessageGlobal error message to be displayed on validation failuresString
isActiveIndicates whether the page is active or notBoolean
onChangeCallback executed when any of the Form field value changes(Internal)Function
stateState of the Page. can be NOT_VALIDATED, SUCCESS, FAIL,String
titleTitle of the PageString

Every page is in the NOT_VALIDATED state by default.

Here is an examples how to define pages in the wizard. We are defining two pages with two fields.

<Wizard
  pages={[
    {
      title: "Introduction",
      fields: [
        {
          label: "First Name",
          name: "firstName",
          type: "text",
          isRequired: true,
        },
        {
          label: "Last Name",
          name: "lastName",
          type: "text",
          isRequired: true,
        },
      ],
  },
  {
    title: "Contact",
    fields: [
      {
        label: "Email",
        name: "email",
        type: "email",
        isRequired: true,
      },
      {
        name: "Phone number",
        label: "Phone",
        type: "phone",
        isRequired: true,
      },
    ],
 }
},

Form field

Form field represents an input field in the wizard. Form field is used to define the label, type, validation rules, and other properties.

NameDescriptionType
isRequiredMarks the field as requiredboolean
labelLabel for the fieldstring
nameName of the Fieldstring
selectOptionsUse this prop when type is "select"Array
typeType of FieldInputType
validateEnables validation for the fieldboolean
validationMessageCustom validation message to be shown on validation failureboolean

Fields marked as required are automatically validated. If you set isRequired to false and validate to true, the wizard will validate and flag the errors, but the step itself will not be marked as invalid.

In the example below we are defining two fields and making them required.

<Wizard
  pages={[
    {
      title: "Introduction",
      fields: [
        {
          label: "First Name",
          name: "firstName",
          type: "text",
          isRequired: true,
        },
        {
          label: "Last Name",
          name: "lastName",
          type: "text",
          validate: true,
        },
      ],
  },
]}

Here only the First Name field is required. The last name field will be validated if the user enters a value.

Form field types

Form field supports the following types:

  • text: Text input field
  • email: Email input field
  • phone: Phone input field
  • number: Number input field
  • password: Password input field
  • textarea: Textarea input field
  • select: Select input field
  • checkbox: Checkbox input field
  • radio: Radio input field
  • datetime: DateTime input field
  • file: File input field

All the above input types comes with inbuilt validation.

Accessing the wizard data

The onFinish callback receives the wizard data with each key representing a page.

For the getting started example, the onFinish callback will receive an object with the following structure:

{
  "introduction": {
    "firstName": "<entered name>",
    "lastName": "<entered name>",
  },
  "contact": {
    "email": "<entered email id>";
    "phone": "<entered phone number>",
  }
}

Custom validation messages

Validation messages are enabled by default for all fields. However, the validationMessage property allows you to customize the message for each field.

<Wizard
  pages={[
    {
      title: "Introduction",
      fields: [
        {
          label: "First Name",
          name: "firstName",
          type: "text",
          isRequired: true,
          validationMessage: "Please enter your first name",
        },
      ],
  },
]}

Custom icons

You can change the icons on the stepper head by giving the icons prop an array of icons as react components.

<Wizard
  ...
  icons={[
    <User key="usr" />,
    <Box key="box" />,
    <Twitter key="twitter" />,
    <Dollar key="dollar" />,
  ]}
/>

🎨 Theme

Customize the look and feel of the Wizard through the theme object.

NameDescriptionData TypeDefault
backgroundBackground color of the wizardstring#f8f8f8
failColour to signify failed statestring#de1738
formFieldBackgroundBackground color of the Form fieldstring#ffffff
formFieldBorderBorder colour of the form fieldstring#dcdcdc
inputBackgroundBackground color of the native input controlstring#e8e8e8
inputTextColorFore color of the text inside the native input controlstring#000000
primaryPrimary colour. This color will be the predominant colorstring#007fff
successColour to signify a success statestring#1db954
tabColorColour of the tabstring#f8f8f8
tabLineColorColour of the line that runs through all the tabsstring#ccc
textColorColour of all textsstring#000000

Here is a short example of how to use the theme object.

<Wizard
  theme={{
    primary: "#007fff",
    background: "#000",
    textColor: "#fff",
    formFieldBackground: "#282828",
    formFieldBorder: "#000",
    success: "#519259",
    fail: "#cf352e",
    inputBackground: "#464646",
    inputTextColor: "#fff",
    tabLineColor: "#464646",
    tabColor: "#7d7d7d",
  }}
/>

CodeSandbox examples

  1. Basic Wizard
  2. Complex Wizard
  3. Wizard with custom theme
  4. Custom Icons
  5. RTL
  6. Silent Mode
  7. Display stepper titles

⛏️ Built With

  • React - A JavaScript library for building user interfaces.
  • Typescript - TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • SCSS - A CSS preprocessor and compiler.
  • Webpack - Webpack is a module bundler that packs multiple modules into a single file.
  • Eslint - ESLint is a linter for JavaScript and JSX.
  • Prettier - Prettier is a tool to format code.

✍️ Authors

0.11.0

2 years ago

0.12.0

2 years ago

0.13.0

2 years ago

0.13.1

2 years ago

0.13.2

2 years ago

0.13.3

2 years ago

0.13.4

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago