@elliemae/ds-wizard 3.17.0-next.10 → 3.17.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/WizardSteps.js +1 -1
- package/dist/cjs/WizardSteps.js.map +2 -2
- package/dist/cjs/useWizard.js +7 -4
- package/dist/cjs/useWizard.js.map +2 -2
- package/dist/esm/WizardSteps.js +1 -1
- package/dist/esm/WizardSteps.js.map +2 -2
- package/dist/esm/useWizard.js +9 -6
- package/dist/esm/useWizard.js.map +2 -2
- package/dist/types/useWizard.d.ts +3 -3
- package/package.json +5 -5
package/dist/cjs/WizardSteps.js
CHANGED
|
@@ -48,7 +48,7 @@ const WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {
|
|
|
48
48
|
completed: index < current
|
|
49
49
|
});
|
|
50
50
|
return steps ? steps.map((step, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_WizardStep.default, { ...step, ...mergeStepProps(step, index) }, index)) : import_react.default.Children.map(children, (item, index) => (0, import_react.cloneElement)(item, mergeStepProps(item, index)));
|
|
51
|
-
}, [current, children]);
|
|
51
|
+
}, [current, children, steps]);
|
|
52
52
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StepsWrapper, { ...otherProps, children: items });
|
|
53
53
|
};
|
|
54
54
|
WizardSteps.Item = import_WizardStep.default;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/WizardSteps.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable indent */\n/* eslint-disable react/no-array-index-key */\nimport React, { cloneElement, useMemo } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport WizardStep from './WizardStep.js';\nimport { indicatorBlockName } from './blockNames.js';\n\nconst StepsWrapper = aggregatedClasses('div')(indicatorBlockName);\n\nconst WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {\n const items = useMemo(() => {\n const mergeStepProps = (step, index) => ({\n index,\n active: current === index,\n completed: index < current,\n });\n\n return steps\n ? steps.map((step, index) => <WizardStep key={index} {...step} {...mergeStepProps(step, index)} />)\n : React.Children.map(children, (item, index) => cloneElement(item, mergeStepProps(item, index)));\n }, [current, children]);\n\n return <StepsWrapper {...otherProps}>{items}</StepsWrapper>;\n};\n\nWizardSteps.Item = WizardStep;\n\nconst wizzardProps = {\n current: PropTypes.number.description('Current active state index').defaultValue(0),\n steps: PropTypes.arrayOf(PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,\n children: PropTypes.arrayOf(PropTypes.instanceOf(WizardStep)).description('List of WizardStep components'),\n};\n\nWizardSteps.propTypes = wizzardProps;\nWizardSteps.displayName = 'WizardSteps';\nconst WizzardWithSchema = describe(WizardSteps);\nWizzardWithSchema.propTypes = wizzardProps;\n\nexport { WizzardWithSchema };\nexport default WizardSteps;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADmBY;AAjBnC,mBAA6C;AAC7C,8BAAoC;AACpC,2BAAkC;AAClC,wBAAuB;AACvB,wBAAmC;AAEnC,MAAM,mBAAe,wCAAkB,KAAK,EAAE,oCAAkB;AAEhE,MAAM,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,UAAU,GAAG,WAAW,MAAM;AACvE,QAAM,YAAQ,sBAAQ,MAAM;AAC1B,UAAM,iBAAiB,CAAC,MAAM,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,YAAY;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,WAAO,QACH,MAAM,IAAI,CAAC,MAAM,UAAU,4CAAC,kBAAAA,SAAA,EAAwB,GAAG,MAAO,GAAG,eAAe,MAAM,KAAK,KAA/C,KAAkD,CAAE,IAChG,aAAAC,QAAM,SAAS,IAAI,UAAU,CAAC,MAAM,cAAU,2BAAa,MAAM,eAAe,MAAM,KAAK,CAAC,CAAC;AAAA,EACnG,GAAG,CAAC,SAAS,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable indent */\n/* eslint-disable react/no-array-index-key */\nimport React, { cloneElement, useMemo } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport WizardStep from './WizardStep.js';\nimport { indicatorBlockName } from './blockNames.js';\n\nconst StepsWrapper = aggregatedClasses('div')(indicatorBlockName);\n\nconst WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {\n const items = useMemo(() => {\n const mergeStepProps = (step, index) => ({\n index,\n active: current === index,\n completed: index < current,\n });\n\n return steps\n ? steps.map((step, index) => <WizardStep key={index} {...step} {...mergeStepProps(step, index)} />)\n : React.Children.map(children, (item, index) => cloneElement(item, mergeStepProps(item, index)));\n }, [current, children, steps]);\n\n return <StepsWrapper {...otherProps}>{items}</StepsWrapper>;\n};\n\nWizardSteps.Item = WizardStep;\n\nconst wizzardProps = {\n current: PropTypes.number.description('Current active state index').defaultValue(0),\n steps: PropTypes.arrayOf(PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,\n children: PropTypes.arrayOf(PropTypes.instanceOf(WizardStep)).description('List of WizardStep components'),\n};\n\nWizardSteps.propTypes = wizzardProps;\nWizardSteps.displayName = 'WizardSteps';\nconst WizzardWithSchema = describe(WizardSteps);\nWizzardWithSchema.propTypes = wizzardProps;\n\nexport { WizzardWithSchema };\nexport default WizardSteps;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADmBY;AAjBnC,mBAA6C;AAC7C,8BAAoC;AACpC,2BAAkC;AAClC,wBAAuB;AACvB,wBAAmC;AAEnC,MAAM,mBAAe,wCAAkB,KAAK,EAAE,oCAAkB;AAEhE,MAAM,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,UAAU,GAAG,WAAW,MAAM;AACvE,QAAM,YAAQ,sBAAQ,MAAM;AAC1B,UAAM,iBAAiB,CAAC,MAAM,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,YAAY;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,WAAO,QACH,MAAM,IAAI,CAAC,MAAM,UAAU,4CAAC,kBAAAA,SAAA,EAAwB,GAAG,MAAO,GAAG,eAAe,MAAM,KAAK,KAA/C,KAAkD,CAAE,IAChG,aAAAC,QAAM,SAAS,IAAI,UAAU,CAAC,MAAM,cAAU,2BAAa,MAAM,eAAe,MAAM,KAAK,CAAC,CAAC;AAAA,EACnG,GAAG,CAAC,SAAS,UAAU,KAAK,CAAC;AAE7B,SAAO,4CAAC,gBAAc,GAAG,YAAa,iBAAM;AAC9C;AAEA,YAAY,OAAO,kBAAAD;AAEnB,MAAM,eAAe;AAAA,EACnB,SAAS,kCAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EAClF,OAAO,kCAAU,QAAQ,kCAAU,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,wBAAwB,EAAE,aAAa,CAAC,CAAC,EAAE;AAAA,EACrG,UAAU,kCAAU,QAAQ,kCAAU,WAAW,kBAAAA,OAAU,CAAC,EAAE,YAAY,+BAA+B;AAC3G;AAEA,YAAY,YAAY;AACxB,YAAY,cAAc;AAC1B,MAAM,wBAAoB,kCAAS,WAAW;AAC9C,kBAAkB,YAAY;AAG9B,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["WizardStep", "React"]
|
|
7
7
|
}
|
package/dist/cjs/useWizard.js
CHANGED
|
@@ -36,21 +36,24 @@ var import_react = require("react");
|
|
|
36
36
|
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
37
37
|
const checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;
|
|
38
38
|
const checkCanPrevious = (prevIndex) => prevIndex - 1 >= 0;
|
|
39
|
-
const noop = () => null;
|
|
39
|
+
const noop = (currentStep) => null;
|
|
40
40
|
function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {
|
|
41
|
-
const [currentStep, setCurrentStep] = (0,
|
|
41
|
+
const [currentStep, setCurrentStep] = (0, import_react.useState)(initial);
|
|
42
|
+
(0, import_react.useEffect)(() => {
|
|
43
|
+
setCurrentStep(current);
|
|
44
|
+
}, [current]);
|
|
42
45
|
const handleNext = (0, import_react.useCallback)(() => {
|
|
43
46
|
if (checkCanNext(currentStep, wizardSteps)) {
|
|
44
47
|
onNext(currentStep);
|
|
45
48
|
setCurrentStep(currentStep + 1);
|
|
46
49
|
}
|
|
47
|
-
});
|
|
50
|
+
}, [currentStep, wizardSteps, onNext]);
|
|
48
51
|
const handlePrevious = (0, import_react.useCallback)(() => {
|
|
49
52
|
if (checkCanPrevious(currentStep)) {
|
|
50
53
|
onPrevious(currentStep);
|
|
51
54
|
setCurrentStep(currentStep - 1);
|
|
52
55
|
}
|
|
53
|
-
});
|
|
56
|
+
}, [currentStep, onPrevious]);
|
|
54
57
|
return {
|
|
55
58
|
current: currentStep,
|
|
56
59
|
next: handleNext,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useWizard.tsx", "../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { useCallback } from 'react';\nimport { get, useDerivedStateFromProps } from '@elliemae/ds-utilities';\n\nconst checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;\nconst checkCanPrevious = (prevIndex) => prevIndex - 1 >= 0;\n\nconst noop = () => null;\n\nexport default function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {\n const [currentStep, setCurrentStep] =
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,
|
|
4
|
+
"sourcesContent": ["import { useEffect, useCallback, useState } from 'react';\nimport { get, useDerivedStateFromProps } from '@elliemae/ds-utilities';\n\nconst checkCanNext = (prevIndex: number, array: any[]): boolean => array.length > prevIndex + 1;\nconst checkCanPrevious = (prevIndex: number): boolean => prevIndex - 1 >= 0;\n\nconst noop = (currentStep: any) => null;\n\nexport default function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {\n const [currentStep, setCurrentStep] = useState(initial);\n\n useEffect(() => {\n setCurrentStep(current);\n }, [current]);\n\n const handleNext = useCallback(() => {\n if (checkCanNext(currentStep, wizardSteps)) {\n onNext(currentStep);\n setCurrentStep(currentStep + 1);\n }\n }, [currentStep, wizardSteps, onNext]);\n\n const handlePrevious = useCallback(() => {\n if (checkCanPrevious(currentStep)) {\n onPrevious(currentStep);\n setCurrentStep(currentStep - 1);\n }\n }, [currentStep, onPrevious]);\n\n return {\n current: currentStep,\n next: handleNext,\n previous: handlePrevious,\n canNext: checkCanNext(currentStep, wizardSteps),\n canPrevious: checkCanPrevious(currentStep),\n WizardCurrentContent: get(wizardSteps, [currentStep, 'content'], () => null),\n };\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAiD;AACjD,0BAA8C;AAE9C,MAAM,eAAe,CAAC,WAAmB,UAA0B,MAAM,SAAS,YAAY;AAC9F,MAAM,mBAAmB,CAAC,cAA+B,YAAY,KAAK;AAE1E,MAAM,OAAO,CAAC,gBAAqB;AAEpB,SAAR,UAA2B,EAAE,OAAO,aAAa,SAAS,SAAS,MAAM,aAAa,MAAM,UAAU,EAAE,GAAG;AAChH,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAS,OAAO;AAEtD,8BAAU,MAAM;AACd,mBAAe,OAAO;AAAA,EACxB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,iBAAa,0BAAY,MAAM;AACnC,QAAI,aAAa,aAAa,WAAW,GAAG;AAC1C,aAAO,WAAW;AAClB,qBAAe,cAAc,CAAC;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,aAAa,aAAa,MAAM,CAAC;AAErC,QAAM,qBAAiB,0BAAY,MAAM;AACvC,QAAI,iBAAiB,WAAW,GAAG;AACjC,iBAAW,WAAW;AACtB,qBAAe,cAAc,CAAC;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,CAAC;AAE5B,SAAO;AAAA,IACH,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS,aAAa,aAAa,WAAW;AAAA,IAC9C,aAAa,iBAAiB,WAAW;AAAA,IACzC,0BAAsB,yBAAI,aAAa,CAAC,aAAa,SAAS,GAAG,MAAM,IAAI;AAAA,EAC/E;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/WizardSteps.js
CHANGED
|
@@ -14,7 +14,7 @@ const WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {
|
|
|
14
14
|
completed: index < current
|
|
15
15
|
});
|
|
16
16
|
return steps ? steps.map((step, index) => /* @__PURE__ */ jsx(WizardStep, { ...step, ...mergeStepProps(step, index) }, index)) : React2.Children.map(children, (item, index) => cloneElement(item, mergeStepProps(item, index)));
|
|
17
|
-
}, [current, children]);
|
|
17
|
+
}, [current, children, steps]);
|
|
18
18
|
return /* @__PURE__ */ jsx(StepsWrapper, { ...otherProps, children: items });
|
|
19
19
|
};
|
|
20
20
|
WizardSteps.Item = WizardStep;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/WizardSteps.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable indent */\n/* eslint-disable react/no-array-index-key */\nimport React, { cloneElement, useMemo } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport WizardStep from './WizardStep.js';\nimport { indicatorBlockName } from './blockNames.js';\n\nconst StepsWrapper = aggregatedClasses('div')(indicatorBlockName);\n\nconst WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {\n const items = useMemo(() => {\n const mergeStepProps = (step, index) => ({\n index,\n active: current === index,\n completed: index < current,\n });\n\n return steps\n ? steps.map((step, index) => <WizardStep key={index} {...step} {...mergeStepProps(step, index)} />)\n : React.Children.map(children, (item, index) => cloneElement(item, mergeStepProps(item, index)));\n }, [current, children]);\n\n return <StepsWrapper {...otherProps}>{items}</StepsWrapper>;\n};\n\nWizardSteps.Item = WizardStep;\n\nconst wizzardProps = {\n current: PropTypes.number.description('Current active state index').defaultValue(0),\n steps: PropTypes.arrayOf(PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,\n children: PropTypes.arrayOf(PropTypes.instanceOf(WizardStep)).description('List of WizardStep components'),\n};\n\nWizardSteps.propTypes = wizzardProps;\nWizardSteps.displayName = 'WizardSteps';\nconst WizzardWithSchema = describe(WizardSteps);\nWizzardWithSchema.propTypes = wizzardProps;\n\nexport { WizzardWithSchema };\nexport default WizardSteps;\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACmBY;AAjBnC,OAAOA,UAAS,cAAc,eAAe;AAC7C,SAAS,UAAU,iBAAiB;AACpC,SAAS,yBAAyB;AAClC,OAAO,gBAAgB;AACvB,SAAS,0BAA0B;AAEnC,MAAM,eAAe,kBAAkB,KAAK,EAAE,kBAAkB;AAEhE,MAAM,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,UAAU,GAAG,WAAW,MAAM;AACvE,QAAM,QAAQ,QAAQ,MAAM;AAC1B,UAAM,iBAAiB,CAAC,MAAM,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,YAAY;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,WAAO,QACH,MAAM,IAAI,CAAC,MAAM,UAAU,oBAAC,cAAwB,GAAG,MAAO,GAAG,eAAe,MAAM,KAAK,KAA/C,KAAkD,CAAE,IAChGA,OAAM,SAAS,IAAI,UAAU,CAAC,MAAM,UAAU,aAAa,MAAM,eAAe,MAAM,KAAK,CAAC,CAAC;AAAA,EACnG,GAAG,CAAC,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable indent */\n/* eslint-disable react/no-array-index-key */\nimport React, { cloneElement, useMemo } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { aggregatedClasses } from '@elliemae/ds-classnames';\nimport WizardStep from './WizardStep.js';\nimport { indicatorBlockName } from './blockNames.js';\n\nconst StepsWrapper = aggregatedClasses('div')(indicatorBlockName);\n\nconst WizardSteps = ({ current = 0, steps, children, ...otherProps }) => {\n const items = useMemo(() => {\n const mergeStepProps = (step, index) => ({\n index,\n active: current === index,\n completed: index < current,\n });\n\n return steps\n ? steps.map((step, index) => <WizardStep key={index} {...step} {...mergeStepProps(step, index)} />)\n : React.Children.map(children, (item, index) => cloneElement(item, mergeStepProps(item, index)));\n }, [current, children, steps]);\n\n return <StepsWrapper {...otherProps}>{items}</StepsWrapper>;\n};\n\nWizardSteps.Item = WizardStep;\n\nconst wizzardProps = {\n current: PropTypes.number.description('Current active state index').defaultValue(0),\n steps: PropTypes.arrayOf(PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,\n children: PropTypes.arrayOf(PropTypes.instanceOf(WizardStep)).description('List of WizardStep components'),\n};\n\nWizardSteps.propTypes = wizzardProps;\nWizardSteps.displayName = 'WizardSteps';\nconst WizzardWithSchema = describe(WizardSteps);\nWizzardWithSchema.propTypes = wizzardProps;\n\nexport { WizzardWithSchema };\nexport default WizardSteps;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACmBY;AAjBnC,OAAOA,UAAS,cAAc,eAAe;AAC7C,SAAS,UAAU,iBAAiB;AACpC,SAAS,yBAAyB;AAClC,OAAO,gBAAgB;AACvB,SAAS,0BAA0B;AAEnC,MAAM,eAAe,kBAAkB,KAAK,EAAE,kBAAkB;AAEhE,MAAM,cAAc,CAAC,EAAE,UAAU,GAAG,OAAO,UAAU,GAAG,WAAW,MAAM;AACvE,QAAM,QAAQ,QAAQ,MAAM;AAC1B,UAAM,iBAAiB,CAAC,MAAM,WAAW;AAAA,MACvC;AAAA,MACA,QAAQ,YAAY;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,WAAO,QACH,MAAM,IAAI,CAAC,MAAM,UAAU,oBAAC,cAAwB,GAAG,MAAO,GAAG,eAAe,MAAM,KAAK,KAA/C,KAAkD,CAAE,IAChGA,OAAM,SAAS,IAAI,UAAU,CAAC,MAAM,UAAU,aAAa,MAAM,eAAe,MAAM,KAAK,CAAC,CAAC;AAAA,EACnG,GAAG,CAAC,SAAS,UAAU,KAAK,CAAC;AAE7B,SAAO,oBAAC,gBAAc,GAAG,YAAa,iBAAM;AAC9C;AAEA,YAAY,OAAO;AAEnB,MAAM,eAAe;AAAA,EACnB,SAAS,UAAU,OAAO,YAAY,4BAA4B,EAAE,aAAa,CAAC;AAAA,EAClF,OAAO,UAAU,QAAQ,UAAU,MAAM,CAAC,CAAC,CAAC,EAAE,YAAY,wBAAwB,EAAE,aAAa,CAAC,CAAC,EAAE;AAAA,EACrG,UAAU,UAAU,QAAQ,UAAU,WAAW,UAAU,CAAC,EAAE,YAAY,+BAA+B;AAC3G;AAEA,YAAY,YAAY;AACxB,YAAY,cAAc;AAC1B,MAAM,oBAAoB,SAAS,WAAW;AAC9C,kBAAkB,YAAY;AAG9B,IAAO,sBAAQ;",
|
|
6
6
|
"names": ["React"]
|
|
7
7
|
}
|
package/dist/esm/useWizard.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { useCallback } from "react";
|
|
3
|
-
import { get
|
|
2
|
+
import { useEffect, useCallback, useState } from "react";
|
|
3
|
+
import { get } from "@elliemae/ds-utilities";
|
|
4
4
|
const checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;
|
|
5
5
|
const checkCanPrevious = (prevIndex) => prevIndex - 1 >= 0;
|
|
6
|
-
const noop = () => null;
|
|
6
|
+
const noop = (currentStep) => null;
|
|
7
7
|
function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {
|
|
8
|
-
const [currentStep, setCurrentStep] =
|
|
8
|
+
const [currentStep, setCurrentStep] = useState(initial);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setCurrentStep(current);
|
|
11
|
+
}, [current]);
|
|
9
12
|
const handleNext = useCallback(() => {
|
|
10
13
|
if (checkCanNext(currentStep, wizardSteps)) {
|
|
11
14
|
onNext(currentStep);
|
|
12
15
|
setCurrentStep(currentStep + 1);
|
|
13
16
|
}
|
|
14
|
-
});
|
|
17
|
+
}, [currentStep, wizardSteps, onNext]);
|
|
15
18
|
const handlePrevious = useCallback(() => {
|
|
16
19
|
if (checkCanPrevious(currentStep)) {
|
|
17
20
|
onPrevious(currentStep);
|
|
18
21
|
setCurrentStep(currentStep - 1);
|
|
19
22
|
}
|
|
20
|
-
});
|
|
23
|
+
}, [currentStep, onPrevious]);
|
|
21
24
|
return {
|
|
22
25
|
current: currentStep,
|
|
23
26
|
next: handleNext,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/useWizard.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback } from 'react';\nimport { get, useDerivedStateFromProps } from '@elliemae/ds-utilities';\n\nconst checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;\nconst checkCanPrevious = (prevIndex) => prevIndex - 1 >= 0;\n\nconst noop = () => null;\n\nexport default function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {\n const [currentStep, setCurrentStep] =
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useEffect, useCallback, useState } from 'react';\nimport { get, useDerivedStateFromProps } from '@elliemae/ds-utilities';\n\nconst checkCanNext = (prevIndex: number, array: any[]): boolean => array.length > prevIndex + 1;\nconst checkCanPrevious = (prevIndex: number): boolean => prevIndex - 1 >= 0;\n\nconst noop = (currentStep: any) => null;\n\nexport default function useWizard({ steps: wizardSteps, current, onNext = noop, onPrevious = noop, initial = 0 }) {\n const [currentStep, setCurrentStep] = useState(initial);\n\n useEffect(() => {\n setCurrentStep(current);\n }, [current]);\n\n const handleNext = useCallback(() => {\n if (checkCanNext(currentStep, wizardSteps)) {\n onNext(currentStep);\n setCurrentStep(currentStep + 1);\n }\n }, [currentStep, wizardSteps, onNext]);\n\n const handlePrevious = useCallback(() => {\n if (checkCanPrevious(currentStep)) {\n onPrevious(currentStep);\n setCurrentStep(currentStep - 1);\n }\n }, [currentStep, onPrevious]);\n\n return {\n current: currentStep,\n next: handleNext,\n previous: handlePrevious,\n canNext: checkCanNext(currentStep, wizardSteps),\n canPrevious: checkCanPrevious(currentStep),\n WizardCurrentContent: get(wizardSteps, [currentStep, 'content'], () => null),\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,WAAW,aAAa,gBAAgB;AACjD,SAAS,WAAqC;AAE9C,MAAM,eAAe,CAAC,WAAmB,UAA0B,MAAM,SAAS,YAAY;AAC9F,MAAM,mBAAmB,CAAC,cAA+B,YAAY,KAAK;AAE1E,MAAM,OAAO,CAAC,gBAAqB;AAEpB,SAAR,UAA2B,EAAE,OAAO,aAAa,SAAS,SAAS,MAAM,aAAa,MAAM,UAAU,EAAE,GAAG;AAChH,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,OAAO;AAEtD,YAAU,MAAM;AACd,mBAAe,OAAO;AAAA,EACxB,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,aAAa,YAAY,MAAM;AACnC,QAAI,aAAa,aAAa,WAAW,GAAG;AAC1C,aAAO,WAAW;AAClB,qBAAe,cAAc,CAAC;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,aAAa,aAAa,MAAM,CAAC;AAErC,QAAM,iBAAiB,YAAY,MAAM;AACvC,QAAI,iBAAiB,WAAW,GAAG;AACjC,iBAAW,WAAW;AACtB,qBAAe,cAAc,CAAC;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,aAAa,UAAU,CAAC;AAE5B,SAAO;AAAA,IACH,SAAS;AAAA,IACT,MAAM;AAAA,IACN,UAAU;AAAA,IACV,SAAS,aAAa,aAAa,WAAW;AAAA,IAC9C,aAAa,iBAAiB,WAAW;AAAA,IACzC,sBAAsB,IAAI,aAAa,CAAC,aAAa,SAAS,GAAG,MAAM,IAAI;AAAA,EAC/E;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export default function useWizard({ steps: wizardSteps, current, onNext, onPrevious, initial }: {
|
|
2
2
|
steps: any;
|
|
3
3
|
current: any;
|
|
4
|
-
onNext?: (() => null) | undefined;
|
|
5
|
-
onPrevious?: (() => null) | undefined;
|
|
4
|
+
onNext?: ((currentStep: any) => null) | undefined;
|
|
5
|
+
onPrevious?: ((currentStep: any) => null) | undefined;
|
|
6
6
|
initial?: number | undefined;
|
|
7
7
|
}): {
|
|
8
|
-
current:
|
|
8
|
+
current: number;
|
|
9
9
|
next: () => void;
|
|
10
10
|
previous: () => void;
|
|
11
11
|
canNext: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-wizard",
|
|
3
|
-
"version": "3.17.0-next.
|
|
3
|
+
"version": "3.17.0-next.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Wizard",
|
|
6
6
|
"files": [
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"indent": 4
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@elliemae/ds-classnames": "3.17.0-next.
|
|
59
|
-
"@elliemae/ds-icons": "3.17.0-next.
|
|
60
|
-
"@elliemae/ds-props-helpers": "3.17.0-next.
|
|
61
|
-
"@elliemae/ds-utilities": "3.17.0-next.
|
|
58
|
+
"@elliemae/ds-classnames": "3.17.0-next.11",
|
|
59
|
+
"@elliemae/ds-icons": "3.17.0-next.11",
|
|
60
|
+
"@elliemae/ds-props-helpers": "3.17.0-next.11",
|
|
61
|
+
"@elliemae/ds-utilities": "3.17.0-next.11"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
64
|
"lodash": "^4.17.21",
|