Socket
Socket
Sign inDemoInstall

react-formik-stepper

Package Overview
Dependencies
3
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 1.0.0

3

dist/index.d.ts
/// <reference types="react" />
import 'animate.css';
export declare const FormikStepper: (props: FormikStepperProps) => JSX.Element;
declare const FormikStepper: (props: FormikStepperProps) => JSX.Element;
export default FormikStepper;

@@ -47,2 +47,3 @@ 'use strict';

_excluded2 = ["validation"];
var FormikStepper = function FormikStepper(props) {

@@ -193,3 +194,3 @@ var _child$props;

exports.FormikStepper = FormikStepper;
exports.default = FormikStepper;
//# sourceMappingURL=react-formik-stepper.cjs.development.js.map

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),n=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,r=require("formik"),a=require("yup");function i(){return(i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function o(t,e){if(null==t)return{};var n,r,a={},i=Object.keys(t);for(r=0;r<i.length;r++)e.indexOf(n=i[r])>=0||(a[n]=t[n]);return a}require("animate.css");var u=["children","animate"],c=["validation"],f=function(t){return n.createElement("div",{className:t.transitions},t.children)};exports.FormikStepper=function(t){var s,l=t.children,p=t.animate,m=void 0===p||p,d=o(t,u),v=function(){return n.Children.toArray(l)},_=v().length,h=e.useState(0),y=h[0],b=h[1],O=e.useState({}),S=O[0],g=O[1],j=Array.isArray(l)?l[y]:l,k=Array.isArray(l)?y:0,A=a.object().shape((null==(s=j.props)?void 0:s.validation)||{}),q=function(t){if(t!==y&&!x(t)){var e={};y<t?(e[y]="animate__animated animate__fadeOutLeft",e[t]="animate__animated animate__fadeInRight"):(e[y]="animate__animated animate__fadeOutRight",e[t]="animate__animated animate__fadeInLeft"),g(e),setTimeout((function(){b(t)}),200)}},x=function(t){return t<0||t>=_},E=function(t){return 0===Object.keys(t).length},F=o(j.props,c),I=i({},j,{props:F});return n.createElement(r.Formik,Object.assign({},d,{validationSchema:A}),(function(t){var e=t.validateForm;return n.createElement(f,{transitions:Boolean(m)?S[k]:""},function(t){var e=t.type;return"function"==typeof e||"object"==typeof e}(j)?n.cloneElement(I,{currentStep:y+1,totalSteps:_,nextStep:function(){e().then((function(t){E(t)&&q(y+1)}))},previousStep:function(){return q(y-1)},firstStep:function(){return q(0)},goToStep:function(t){return q(t-1)},lastStep:function(){v().splice(y+1,_).some((function(t){var e;return!(null==(e=t.props)||!e.validation)}))||e().then((function(t){E(t)&&q(_-1)}))}}):j)}))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=require("react"),n=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,r=require("formik"),a=require("yup");function i(){return(i=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function o(t,e){if(null==t)return{};var n,r,a={},i=Object.keys(t);for(r=0;r<i.length;r++)e.indexOf(n=i[r])>=0||(a[n]=t[n]);return a}require("animate.css");var u=["children","animate"],c=["validation"],f=function(t){return n.createElement("div",{className:t.transitions},t.children)};exports.default=function(t){var s,l=t.children,p=t.animate,d=void 0===p||p,m=o(t,u),v=function(){return n.Children.toArray(l)},_=v().length,h=e.useState(0),y=h[0],b=h[1],O=e.useState({}),g=O[0],j=O[1],S=Array.isArray(l)?l[y]:l,A=Array.isArray(l)?y:0,k=a.object().shape((null==(s=S.props)?void 0:s.validation)||{}),q=function(t){if(t!==y&&!x(t)){var e={};y<t?(e[y]="animate__animated animate__fadeOutLeft",e[t]="animate__animated animate__fadeInRight"):(e[y]="animate__animated animate__fadeOutRight",e[t]="animate__animated animate__fadeInLeft"),j(e),setTimeout((function(){b(t)}),200)}},x=function(t){return t<0||t>=_},E=function(t){return 0===Object.keys(t).length},F=o(S.props,c),I=i({},S,{props:F});return n.createElement(r.Formik,Object.assign({},m,{validationSchema:k}),(function(t){var e=t.validateForm;return n.createElement(f,{transitions:Boolean(d)?g[A]:""},function(t){var e=t.type;return"function"==typeof e||"object"==typeof e}(S)?n.cloneElement(I,{currentStep:y+1,totalSteps:_,nextStep:function(){e().then((function(t){E(t)&&q(y+1)}))},previousStep:function(){return q(y-1)},firstStep:function(){return q(0)},goToStep:function(t){return q(t-1)},lastStep:function(){v().splice(y+1,_).some((function(t){var e;return!(null==(e=t.props)||!e.validation)}))||e().then((function(t){E(t)&&q(_-1)}))}}):S)}))};
//# sourceMappingURL=react-formik-stepper.cjs.production.min.js.map

@@ -40,2 +40,3 @@ import React, { useState } from 'react';

_excluded2 = ["validation"];
var FormikStepper = function FormikStepper(props) {

@@ -186,3 +187,3 @@ var _child$props;

export { FormikStepper };
export default FormikStepper;
//# sourceMappingURL=react-formik-stepper.esm.js.map
{
"version": "0.1.0",
"version": "1.0.0",
"license": "MIT",

@@ -37,3 +37,8 @@ "main": "dist/index.js",

"name": "react-formik-stepper",
"author": "Ishak Ertem",
"author": "Ishak Ertem <ertemishakk@gmail.com>",
"description": "A modern flexible step wizard component build for React Formik",
"homepage": "https://github.com/ertemishakk/react-formik-stepper",
"bugs": {
"url": "https://github.com/ertemishakk/react-formik-stepper"
},
"module": "dist/react-formik-stepper.esm.js",

@@ -40,0 +45,0 @@ "size-limit": [

@@ -1,160 +0,101 @@

# TSDX React User Guide
# React Formik Stepper
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
[![npm](https://img.shields.io/npm/dm/react-formik-stepper.svg)](https://www.npmjs.com/package/react-formik-stepper)
> This TSDX setup is meant for developing React component libraries (not apps!) that can be published to NPM. If you’re looking to build a React-based app, you should use `create-react-app`, `razzle`, `nextjs`, `gatsby`, or `react-static`.
A flexible multistep wizard built for React and Formik
> If you’re new to TypeScript and React, checkout [this handy cheatsheet](https://github.com/sw-yx/react-typescript-cheatsheet/)
## Install
## Commands
```bash
npm install --save react-formik-stepper
TSDX scaffolds your new library inside `/src`, and also sets up a [Parcel-based](https://parceljs.org) playground for it inside `/example`.
```
The recommended workflow is to run TSDX in one terminal:
or
```bash
npm start # or yarn start
yarn add react-formik-stepper
```
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
## Import Component
Then run the example inside another:
```bash
cd example
npm i # or yarn to install dependencies
npm start # or yarn start
```js
import FormikStepper from 'react-formik-stepper';
```
The default example imports and live reloads whatever is in `/dist`, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. **No symlinking required**, we use [Parcel's aliasing](https://parceljs.org/module_resolution.html#aliases).
## JSX Syntax
To do a one-off build, use `npm run build` or `yarn build`.
Simply create a wrapper with <FormikStepper></FormikStepper> and each child component will be treated as an individual step.
To run tests, use `npm test` or `yarn test`.
## Configuration
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
### Jest
Jest tests are set up to run with `npm test` or `yarn test`.
### Bundle analysis
Calculates the real cost of your library using [size-limit](https://github.com/ai/size-limit) with `npm run size` and visulize it with `npm run analyze`.
#### Setup Files
This is the folder structure we set up for you:
```txt
/example
index.html
index.tsx # test your component here in a demo app
package.json
tsconfig.json
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
tsconfig.json
```js
<FormikStepper initialValues={{}} onSubmit={}>
<Step1 />
<Step2
validation={{
email: yup.string().required(),
}}
/>
...
<Step5 />
<WhateverComponentName />
</FormikStepper>
```
#### React Testing Library
and then in each step
We do not set up `react-testing-library` for you yet, we welcome contributions and documentation on this.
### Rollup
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
### TypeScript
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
## Continuous Integration
### GitHub Actions
Two actions are added by default:
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
## Optimizations
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
```js
// ./types/index.d.ts
declare var __DEV__: boolean;
import { useFormikContext } from 'formik';
// inside your code...
if (__DEV__) {
console.log('foo');
}
const formik = useFormikContext();
```
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
## Props
## Module Formats
Available in all steps.
CJS, ESModules, and UMD module formats are supported.
| Prop | Data Type |
| ------------ | --------- |
| previousStep | function |
| nextStep | function |
| goToStep | function |
| firstStep | number |
| lastStep | number |
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
## Deploying the Example Playground
The Playground is just a simple [Parcel](https://parceljs.org) app, you can deploy it anywhere you would normally deploy that. Here are some guidelines for **manually** deploying with the Netlify CLI (`npm i -g netlify-cli`):
```bash
cd example # if not already in the example folder
npm run build # builds to dist
netlify deploy # deploy the dist folder
```js
<div>
<!-- Variables -->
<h2>Step {this.props.currentStep}</h2>
<p>Total Steps: {this.props.totalSteps}</p>
<!-- Functions -->
<p><button onClick={this.props.previousStep}>Previous Step</button></p>
<p><button onClick={this.props.nextStep}>Next Step</button></p>
<p><button onClick={()=>this.props.goToStep(2)}>Step 2</button></p>
<p><button onClick={this.props.firstStep}>First Step</button></p>
<p><button onClick={this.props.lastStep}>Last Step</button></p>
</div>
```
Alternatively, if you already have a git repo connected, you can set up continuous deployment with Netlify:
## FormikStepper Props
```bash
netlify init
# build command: yarn build && cd example && yarn && yarn build
# directory to deploy: example/dist
# pick yes for netlify.toml
```
| Prop | Data Type | Description |
| ----------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| initialValues | Values | Initial field values of the form, Formik will make these values available to render methods component as values. https://formik.org/docs/api/formik#initialvalues-values |
| onSubmit | function | Your form submission handler. https://formik.org/docs/api/formik#onsubmit-values-values-formikbag-formikbag--void--promiseany |
| onReset | function | Your optional form reset handler. https://formik.org/docs/api/formik#onreset-values-values-formikbag-formikbag--void |
| validate | function | I suggest using yup for validation in each step. However, validate is a dependency-free, out of the box way to validate your forms. https://formik.org/docs/api/withFormik#validate-values-values-props-props--formikerrorsvalues--promiseany |
| validateOnChange | boolean | Default is true. Determines if form validation should or should not be run after any array manipulations. |
| https://formik.org/docs/api/fieldarray#validateonchange-boolean |
| validateOnBlur | boolean | Default is true. Use this option to run validations on blur events. More specifically, when either handleBlur, setFieldTouched, or setTouched are called |
| https://formik.org/docs/api/withFormik#validateonblur-boolean |
| validateOnMount | boolean | Default is false. Use this option to tell Formik to run validation (at low priority) when the wrapped component mounts and/or initialValues change. |
| https://formik.org/docs/api/withFormik#validateonmount-boolean |
| enableReinitialize | boolean | Default is false. Control whether Formik should reset the form if the wrapped component props change (using deep equality). |
| https://formik.org/docs/api/withFormik#enablereinitialize-boolean |
| animate | boolean | Default is true. Uses animation from [Animate CSS](https://animate.style/) |
## Named Exports
## Step Props
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
## Including Styles
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
## Publishing to NPM
We recommend using [np](https://github.com/sindresorhus/np).
## Usage with Lerna
When creating a new package with TSDX within a project set up with Lerna, you might encounter a `Cannot resolve dependency` error when trying to run the `example` project. To fix that you will need to make changes to the `package.json` file _inside the `example` directory_.
The problem is that due to the nature of how dependencies are installed in Lerna projects, the aliases in the example project's `package.json` might not point to the right place, as those dependencies might have been installed in the root of your Lerna project.
Change the `alias` to point to where those packages are actually installed. This depends on the directory structure of your Lerna project, so the actual path might be different from the diff below.
```diff
"alias": {
- "react": "../node_modules/react",
- "react-dom": "../node_modules/react-dom"
+ "react": "../../../node_modules/react",
+ "react-dom": "../../../node_modules/react-dom"
},
```
An alternative to fixing this problem would be to remove aliases altogether and define the dependencies referenced as aliases as dev dependencies instead. [However, that might cause other problems.](https://github.com/palmerhq/tsdx/issues/64)
| Prop | Data Type | Description |
| ---------- | --------- | ------------------------------- |
| validation | object | Enter validation for each step. |

@@ -13,5 +13,4 @@ interface FormikStepperProps {

validateOnMount?: boolean;
isInitialValid?: boolean | ((props: Props) => boolean);
enableReinitialize?: boolean;
animate?: boolean;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc