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

@ppm-team/wizard-stepper

v0.1.21

Published

Wizard stepper

Downloads

2

Readme

Wizzard Stepper

Disclaimer !

This project is experimental and is being tested for now

Intro

For stepper creation, use WizzardStepperFactory class. There is required parameter called steps which defines all the basic steps for Stepper

const Factory = new WizzardStepperFactory({
  steps: [
    { key: 'info', label: 'Contant info' },
    { key: 'payment', label: 'Payment info' },
  ],
})

It's also possible to define requires param, with the value of:

  • ALL_BEFORE - All preceding steps must be finished
  • STEP_BEFORE - The step preceding this step must be finished
  • NONE - Step is always enabled

Default is STEP_BEFORE

const Factory = new WizzardStepperFactory({
  steps: [
    { key: 'info', label: 'Contant info' },
    { key: 'payment', label: 'Payment info', requires: WizzardStepRequiresEnum.ALL_BEFORE },
    { key: 'recap', label: 'Recap', requires: WizzardStepRequiresEnum.NONE },
  ],
})

Usage - Step

For correct behaviour, given part of application push be wrapped with Provider from WizzardStepperFactory, like so:

// src/App.tsx

import { Stepper } from './Stepper'

const App: React.VFC = () => {
  return (
    <Factory.Provider>
      <Stepper />
    </Factory.Provider>
  )
}

For Stepper to register that given step exists, <Step> component must be used. Stepper does not display steps without it being explicitly defined with <Step> component

// src/Stepper.tsx

import { InfoStep } from './InfoStep'

export const Stepper: React.VFC = () => {
  return (
    <Factory.Step name="info">
      <InfoStep />
    </Factory.Step>
  )
}

You can also access the step context inside of the given Step, or you can access wizzards context

// src/InfoStep.tsx

import { InfoStep } from './InfoStep';

export const InfoStep: React.VFC = () => {
  const ctx = Factory.useStepContext('info');
  const wizzardCtx = Factory.useWizzardContext()

  return (
    ...
  )
};

Minimal example

type NewFormType = {
    first: { first: number }
    second: { second: number }
    third: { third: number }
}

const Factory = new WizzardStepperFactory<NewFormType>({
    steps: [
        { key: 'first', label: 'First step' },
        { key: 'second', label: 'Second step' },
        { key: 'third', label: 'Third step' },
    ],
    HeaderRenderer: ({ children }) => {
        return <div style={{ display: 'flex', alignItems: 'center' }}>{children}</div>
    },
    StepRenderer: ({ step, isActive, setStep }) => {
        return (
            <>
                <button disabled={!isActive} onClick={() => setStep()}>
        {step.label}
        </button>
        </>
    )
    },
    StepContentRenderer: ({ isSelected, children }) => {
        if (!isSelected) return null

        return <>{children}</>
    },
    ProviderRenderer: ({ children }) => {
        return (
            <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
        {children}
        </div>
    )
    },
})

const _First = () => {
    const { submitData } = Factory.useStepContext('first')
    return (
        <>
            <button onClick={() => submitData({ first: 200 })}>Next</button>
    </>
)
}
const _Second = () => {
    const { submitData } = Factory.useStepContext('second')
    return (
        <>
            <button onClick={() => submitData()}>Next 2</button>
    </>
)
}
const _Third = () => {
    const { submitData } = Factory.useStepContext('third')
    return (
        <>
            <button onClick={() => submitData()}>Finish</button>
    </>
)
}

const WizardProcess: React.FC = () => {
    const handleSubmit: WizzardStepperHandleSubmit<NewFormType> = (values, allValues) => {
        // eslint-disable-next-line no-console
        console.log('SUBMIT', values, { ...allValues })
    }

    const onStepChange: WizzardStepperOnStepChange<NewFormType> = (step) => {
        // eslint-disable-next-line no-console
        console.log(step)
    }
    
    return (
        <Factory.Provider defaultValues={{ first: { first: 0 },}} handleSubmit={handleSubmit} onStepChange={onStepChange}
                          initiallyLoadStep="second">
    <Factory.StepperHeader />

    <Factory.Step name="first">
        <_First />
        </Factory.Step>

        <Factory.Step name="second">
        <_Second />
        </Factory.Step>

        <Factory.Step name="third">
        <_Third />
        </Factory.Step>
        </Factory.Provider>
)
}

TODO

Stepper Mode

Je možné zvolit dva typy módu stepperu.

  • REVEAL_ALL - Stepper zobrazí všechny kroky "on mount"
  • REVEAL_EACH - Stepper zobrazí kroky postupně, podle toho jak jsou vyplňovány