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

react-harry-potter

v1.3.4

Published

> "I solemnly swear I am up to no good." > > \-- _Harry Potter_

Downloads

6

Readme

React Harry Potter · npm version

"I solemnly swear I am up to no good."

-- Harry Potter

What is this?

react-harry-potter is a React component library that helps you build a multi-step control flow, otherwise known as a Wizard. You're responsible for actually building the screens, and then stating where you want them to be placed, but beyond that react-harry-potter actually maintains the flow-related state.

As a developer, you are given the power to interact with and control the Wizard using some easy functions from the 'nav' object that is passed down to all of it's children, you have some easy and required ones, and also some potentially dangerous ones.

You have all the tools, I leave it up to you to use them properly (:

Demo

Get Started

  • run
npm install --save react-harry-potter
  • require into project, more specifics below
import Wizard, { withPersist } from 'react-harry-potter';

Building the Wizard itself

  • import the Wizard
  • import your components / screens that you want the wizard to render
import Wizard  from 'react-harry-potter';
import { InputOne, InputTwo, InputThree } from './components';
  • build your onComplete method that handles what you want to do with the data
handleComplete(data) {
    console.log(data);
}
  • actually build the wizard and render it somewhere
<Wizard onComplete={this.handleComplete}>
    <InputOne>
    <InputTwo>
    <InputThree>
</Wizard>

Modifying your components to work with the Wizard

  • import the persist HoC and wrap them with it
  • Call the allow function from the nav object somewhere appropriate
import { withPersist } from 'react-harry-potter';

const InputOne = (props) => {
    props.nav.allow();

    return (
        <div> Screen One! </div>
    );
}

export default withPersist(InputOne);

Example

import React, { Component } from 'react';
import Wizard from 'react-harry-potter';

import { InputOne, InputTwo, InputThree } from './components';

class App extends Component {
  handleComplete(data) {
    // This is where you decide what to do with the data at the end. 
    // I'm logging it, but you could just as easily make a POST request with it.

    console.log(data);
  }

  render() {
    return (
      <Wizard onComplete={this.handleComplete}>
        <InputOne />
        <InputTwo />
        <InputThree />
      </Wizard>
    );
  }
}

export default App;
import React, { Component } from 'react';
import { withPersist } from 'react-harry-potter';

class InputOne extends Component {
  constructor() {
    super();
    this.props.nav.allow();
  }

  render() {
    return (
        <div> Screen One </div>
    );
  }
}

export default withPersist(InputOne);

Running the Demo

npm install
npm start
open http://localhost:8080

<Wizard> API

Required Props:

onComplete(data): function

Used to explain what you want to do with the data, maybe log it or send a POST request.

Optional Props:

start: number, default: 0

Start the Wizard off at a different initial screen.

showTextProgressBar: bool, default: false

Show a "Step {current} out of {total}." progress indicator.

showPercentageProgress: bool, default: false

Show progress html element that uses the percentage completed so far.

disallowEnterKey: bool, default: false

Deny user the ability to press enter to try to move up in the Wizard.

clearOnClose: bool, default: false

Should wizard clear it's state and all children state when closed?

onCompleteText: string, default: 'Thanks for completing!',

What to render once the user has finished the wizard.

nextButtonText: string, default: 'Next',

What to put in the text of the Next Button.

prevButtonText: string, default: 'Prev',

What to put in the text of the Prev Button.

submitButtonText: string, default: 'Submit',

What to put in the text of the Submit Button.

CSS Props:

Pass in a style object to any of the following to change how they look.

containerStyle,
buttonNavContainerStyle,
buttonStyle,
prevButtonStyle,
nextButtonStyle,
submitButtonStyle,
textProgressStyle,
percentageProgressStyle

If not a fan of style objects, feel free to pass in CSS class names as well.

containerCls,
buttonNavContainerCls,
buttonCls,
prevButtonCls,
nextButtonCls,
submitButtonCls,
textProgressCls,
percentageProgressCls

<Child> API

Methods given to each <Child> element in a <Wizard>

Each Child is given a nav object that the developer can use to help create their screens. If the screens have already been created it'll only take minor modifications to use with the wizard.

allow:

  • Activates the Next button to allow the user to move up in the component.
  • You may want to call this in componentDidUpdate to verify the user has put in all the data completely and accurately, if so they can move on in the Wizard.
  • You may also want to just call it immediately in the constructor, to allow them to move on immediately in case of optional fields.

deny:

  • The opposite of allow, disabled the next button. Use as the second half of your componentDidUpdate check, where if they failed to complete or have an error somewhere, you can deny.

allowBack and denyBack:

  • Similar to allow and deny, just for the Prev button.

jump(componentName):

  • Will find a component and jump to it specifically.
  • A bit dangerous to use since this won't cause the normal validation checks for Prev and Next.

jumpToIndex(index):

  • Will change to a specific index.
  • Also a bit dangerous to use since this won't cause the normal validation checks for Prev and Next.
  • Potentially more dangerous than jump, since this can't account for screen reorders.

reset:

  • Reset the state of the wizard, back to start page, which is not always 0.

getAllData:

  • Gets all data for the Wizard as is.
  • Maybe you want to show the user the data before they submit?

clearAllData:

  • Clear all data so far. This will only clear the saved data.
  • You might be looking for reset?
  • Maybe you want to show the user the data before they submit?