@marianmeres/wizard
TypeScript icon, indicating that this package has built-in type declarations

1.7.0 • Public • Published

@marianmeres/wizard

Utility for high level management of wizard data. Agnostic of the actual business or rendering. Store compatible.

Install

$ npm i @marianmeres/wizard

Example usage

const wizard = createWizardStore('foo', {
    steps: [
        { label: 'one', foo: 123 },
        {
            label: 'two',
            canGoNext: false,
            preNext: async (data, { context, wizard, set }) => {
                set({ canGoNext: data.hey === context.hey })
            },
            prePrevious: async (data, { set }) => {
                set({ canGoNext: false, data: {} });
            },
            preReset: async (data, { context, wizard, set }) => {
                // ...
            }
        },
        { label: 'three' },
        { label: 'four' },
    ],
    context: { hey: 'ho' },
    onDone: async ({ steps, context, set }) => '...', // will be called on the last .next()
});

wizard.subscribe(async ({ step, steps }) => {
    // step props
    const { label, index, data, canGoNext, error, isFirst, isLast } = step;

    // do something here...

    // step api
    step.set(/*{ data, error, canGoNext }*/)

    await step.next(data);
    await step.previous();
});

// wizard api
wizard.context; // reference to the context object
await wizard.next(/*data*/);
await wizard.previous();
await wizard.reset();
await wizard.goto(index, stepsData);

See tests for more...

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.7.00latest

Version History

VersionDownloads (Last 7 Days)Published
1.7.00
1.6.10
1.6.00
1.5.00
1.4.10
1.4.00
1.3.10
1.3.00
1.2.00
1.1.00
1.0.00
0.2.80
0.2.70
0.2.60
0.2.50
0.2.40
0.2.30
0.2.20
0.2.10
0.2.00
0.1.30
0.1.20
0.1.10
0.1.00
0.0.70
0.0.60
0.0.50
0.0.40
0.0.30
0.0.20

Package Sidebar

Install

npm i @marianmeres/wizard

Weekly Downloads

0

Version

1.7.0

License

MIT

Unpacked Size

29.9 kB

Total Files

7

Last publish

Collaborators

  • marianmeres