@elliemae/ds-wizard 2.3.0-alpha.8 → 2.3.0-next.2
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/cjs/WizardStep.js +72 -0
- package/cjs/WizardSteps.js +66 -0
- package/cjs/blockNames.js +11 -0
- package/cjs/index.js +15 -0
- package/cjs/stories/steps.js +36 -0
- package/cjs/useWizard.js +44 -0
- package/esm/WizardStep.js +63 -0
- package/esm/WizardSteps.js +55 -0
- package/esm/blockNames.js +5 -0
- package/esm/index.js +3 -0
- package/esm/stories/steps.js +28 -0
- package/{dist/esm → esm}/useWizard.js +19 -16
- package/package.json +31 -33
- package/types/DSWizard.stories.d.ts +11 -0
- package/types/WizardStep.d.ts +55 -0
- package/types/WizardSteps.d.ts +31 -0
- package/types/blockNames.d.ts +3 -0
- package/types/index.d.ts +4 -0
- package/types/stories/steps.d.ts +5 -0
- package/types/stories/wizzard-overview.stories.d.ts +1 -0
- package/types/useWizard.d.ts +14 -0
- package/dist/cjs/WizardStep.js +0 -85
- package/dist/cjs/WizardStep.js.map +0 -7
- package/dist/cjs/WizardSteps.js +0 -68
- package/dist/cjs/WizardSteps.js.map +0 -7
- package/dist/cjs/blockNames.js +0 -39
- package/dist/cjs/blockNames.js.map +0 -7
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/stories/steps.js +0 -57
- package/dist/cjs/stories/steps.js.map +0 -7
- package/dist/cjs/useWizard.js +0 -68
- package/dist/cjs/useWizard.js.map +0 -7
- package/dist/esm/WizardStep.js +0 -56
- package/dist/esm/WizardStep.js.map +0 -7
- package/dist/esm/WizardSteps.js +0 -39
- package/dist/esm/WizardSteps.js.map +0 -7
- package/dist/esm/blockNames.js +0 -10
- package/dist/esm/blockNames.js.map +0 -7
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/stories/steps.js +0 -28
- package/dist/esm/stories/steps.js.map +0 -7
- package/dist/esm/useWizard.js.map +0 -7
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var reactDesc = require('react-desc');
|
|
8
|
+
var dsClassnames = require('@elliemae/ds-classnames');
|
|
9
|
+
var dsUtilities = require('@elliemae/ds-utilities');
|
|
10
|
+
var dsIcons = require('@elliemae/ds-icons');
|
|
11
|
+
var blockNames = require('./blockNames.js');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
16
|
+
|
|
17
|
+
var _Checkmark;
|
|
18
|
+
const Item = dsClassnames.aggregatedClasses('div')("".concat(blockNames.indicatorItemBlockName), null, _ref => {
|
|
19
|
+
let {
|
|
20
|
+
active,
|
|
21
|
+
completed
|
|
22
|
+
} = _ref;
|
|
23
|
+
return {
|
|
24
|
+
active,
|
|
25
|
+
completed
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
const Wrapper = dsClassnames.aggregatedClasses('div')("".concat(blockNames.indicatorItemBlockName, "-wrapper"));
|
|
29
|
+
const Label = dsClassnames.aggregatedClasses('span')(blockNames.indicatorItemBlockName, 'label');
|
|
30
|
+
const Bullet = dsClassnames.aggregatedClasses('div')(blockNames.indicatorItemBlockName, 'bullet');
|
|
31
|
+
const BulletWrapper = dsClassnames.aggregatedClasses('div')(blockNames.indicatorItemBlockName, 'bullet-wrapper');
|
|
32
|
+
|
|
33
|
+
function WizardStep(_ref2) {
|
|
34
|
+
let {
|
|
35
|
+
label = '',
|
|
36
|
+
icon = null,
|
|
37
|
+
iconCompleted = _Checkmark || (_Checkmark = /*#__PURE__*/_jsx__default["default"](dsIcons.Checkmark, {})),
|
|
38
|
+
iconActive = null,
|
|
39
|
+
active = false,
|
|
40
|
+
completed = false,
|
|
41
|
+
index = 0
|
|
42
|
+
} = _ref2;
|
|
43
|
+
const currentIcon = React.useMemo(() => {
|
|
44
|
+
if (active) return iconActive;
|
|
45
|
+
if (completed) return iconCompleted;
|
|
46
|
+
return icon;
|
|
47
|
+
}, [active, completed]) || icon;
|
|
48
|
+
const iconWithOptions = React.useMemo(() => /*#__PURE__*/React.isValidElement(currentIcon) ? /*#__PURE__*/React.cloneElement(currentIcon, {
|
|
49
|
+
color: dsUtilities.get(currentIcon, ['props', 'color']) || ['brand-primary', completed ? 600 : 500]
|
|
50
|
+
}) : currentIcon || index + 1, [currentIcon]);
|
|
51
|
+
return /*#__PURE__*/_jsx__default["default"](Item, {
|
|
52
|
+
classProps: {
|
|
53
|
+
active,
|
|
54
|
+
completed
|
|
55
|
+
}
|
|
56
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"](Wrapper, {}, void 0, /*#__PURE__*/_jsx__default["default"](BulletWrapper, {}, void 0, /*#__PURE__*/_jsx__default["default"](Bullet, {}, void 0, iconWithOptions)), /*#__PURE__*/_jsx__default["default"](Label, {}, void 0, label)));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const wizzardStepProps = {
|
|
60
|
+
label: reactDesc.PropTypes.string.description('Step label'),
|
|
61
|
+
icon: reactDesc.PropTypes.oneOfType([reactDesc.PropTypes.element, reactDesc.PropTypes.string]).description('Default icon or number'),
|
|
62
|
+
iconCompleted: reactDesc.PropTypes.element.description('Icon when the step is completed').defaultValue(dsIcons.Checkmark),
|
|
63
|
+
iconActive: reactDesc.PropTypes.element.description('Icon when the step is active'),
|
|
64
|
+
active: reactDesc.PropTypes.bool.description('Whether the step is active or not').defaultValue(false),
|
|
65
|
+
completed: reactDesc.PropTypes.bool.description('Whether the step is completed or not').defaultValue(false),
|
|
66
|
+
index: reactDesc.PropTypes.number.description('Current item index')
|
|
67
|
+
};
|
|
68
|
+
const WizzardStepWithSchema = reactDesc.describe(WizardStep);
|
|
69
|
+
WizzardStepWithSchema.propTypes = wizzardStepProps;
|
|
70
|
+
|
|
71
|
+
exports.WizzardStepWithSchema = WizzardStepWithSchema;
|
|
72
|
+
exports["default"] = WizardStep;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
7
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
11
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
12
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
13
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
14
|
+
var React = require('react');
|
|
15
|
+
var reactDesc = require('react-desc');
|
|
16
|
+
var dsClassnames = require('@elliemae/ds-classnames');
|
|
17
|
+
var WizardStep = require('./WizardStep.js');
|
|
18
|
+
var blockNames = require('./blockNames.js');
|
|
19
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
20
|
+
|
|
21
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
+
|
|
23
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
24
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
25
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
26
|
+
|
|
27
|
+
const _excluded = ["current", "steps", "children"];
|
|
28
|
+
|
|
29
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
30
|
+
|
|
31
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
32
|
+
const StepsWrapper = dsClassnames.aggregatedClasses('div')(blockNames.indicatorBlockName);
|
|
33
|
+
|
|
34
|
+
function WizardSteps(_ref) {
|
|
35
|
+
let {
|
|
36
|
+
current = 0,
|
|
37
|
+
steps,
|
|
38
|
+
children
|
|
39
|
+
} = _ref,
|
|
40
|
+
otherProps = _objectWithoutProperties__default["default"](_ref, _excluded);
|
|
41
|
+
|
|
42
|
+
const items = React.useMemo(() => {
|
|
43
|
+
const mergeStepProps = (step, index) => ({
|
|
44
|
+
index,
|
|
45
|
+
active: current === index,
|
|
46
|
+
completed: index < current
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return steps ? steps.map((step, index) => /*#__PURE__*/jsxRuntime.jsx(WizardStep["default"], _objectSpread(_objectSpread({}, step), mergeStepProps(step, index)), index)) : React__default["default"].Children.map(children, (item, index) => /*#__PURE__*/React.cloneElement(item, mergeStepProps(item, index)));
|
|
50
|
+
}, [current, children]);
|
|
51
|
+
return /*#__PURE__*/jsxRuntime.jsx(StepsWrapper, _objectSpread(_objectSpread({}, otherProps), {}, {
|
|
52
|
+
children: items
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
WizardSteps.Item = WizardStep["default"];
|
|
57
|
+
const wizzardProps = {
|
|
58
|
+
current: reactDesc.PropTypes.number.description('Current active state index').defaultValue(0),
|
|
59
|
+
steps: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,
|
|
60
|
+
children: reactDesc.PropTypes.arrayOf(reactDesc.PropTypes.instanceOf(WizardStep["default"])).description('List of WizardStep components')
|
|
61
|
+
};
|
|
62
|
+
const WizzardWithSchema = reactDesc.describe(WizardSteps);
|
|
63
|
+
WizzardWithSchema.propTypes = wizzardProps;
|
|
64
|
+
|
|
65
|
+
exports.WizzardWithSchema = WizzardWithSchema;
|
|
66
|
+
exports["default"] = WizardSteps;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const wizardBlockName = 'wizard';
|
|
6
|
+
const indicatorBlockName = "".concat(wizardBlockName, "-steps-indicator");
|
|
7
|
+
const indicatorItemBlockName = "".concat(indicatorBlockName, "-step");
|
|
8
|
+
|
|
9
|
+
exports.indicatorBlockName = indicatorBlockName;
|
|
10
|
+
exports.indicatorItemBlockName = indicatorItemBlockName;
|
|
11
|
+
exports.wizardBlockName = wizardBlockName;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var WizardSteps = require('./WizardSteps.js');
|
|
6
|
+
var WizardStep = require('./WizardStep.js');
|
|
7
|
+
var useWizard = require('./useWizard.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.WizardStepsIndicator = WizardSteps["default"];
|
|
12
|
+
exports.WizzardWithSchema = WizardSteps.WizzardWithSchema;
|
|
13
|
+
exports.WizardStep = WizardStep["default"];
|
|
14
|
+
exports.WizzardStepWithSchema = WizardStep.WizzardStepWithSchema;
|
|
15
|
+
exports.useWizard = useWizard;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
require('react');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
+
|
|
10
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
11
|
+
|
|
12
|
+
var _div, _div2, _div3, _div4;
|
|
13
|
+
|
|
14
|
+
const Step1Content = () => _div || (_div = /*#__PURE__*/_jsx__default["default"]("div", {}, void 0, "Step 1 Content"));
|
|
15
|
+
|
|
16
|
+
const Step2Content = () => _div2 || (_div2 = /*#__PURE__*/_jsx__default["default"]("div", {}, void 0, "Step 2 Content"));
|
|
17
|
+
|
|
18
|
+
const Step3Content = () => _div3 || (_div3 = /*#__PURE__*/_jsx__default["default"]("div", {}, void 0, "Step 3 Content"));
|
|
19
|
+
|
|
20
|
+
const Step4Content = () => _div4 || (_div4 = /*#__PURE__*/_jsx__default["default"]("div", {}, void 0, "Step 4 Content"));
|
|
21
|
+
|
|
22
|
+
const steps = [{
|
|
23
|
+
label: 'Step 1',
|
|
24
|
+
content: Step1Content
|
|
25
|
+
}, {
|
|
26
|
+
label: 'Step Lorem Ipsum',
|
|
27
|
+
content: Step2Content
|
|
28
|
+
}, {
|
|
29
|
+
label: 'Step Lorem',
|
|
30
|
+
content: Step3Content
|
|
31
|
+
}, {
|
|
32
|
+
label: 'Step Lorem 4',
|
|
33
|
+
content: Step4Content
|
|
34
|
+
}];
|
|
35
|
+
|
|
36
|
+
exports.steps = steps;
|
package/cjs/useWizard.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var dsUtilities = require('@elliemae/ds-utilities');
|
|
6
|
+
|
|
7
|
+
const checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;
|
|
8
|
+
|
|
9
|
+
const checkCanPrevious = prevIndex => prevIndex - 1 >= 0;
|
|
10
|
+
|
|
11
|
+
const noop = () => null;
|
|
12
|
+
|
|
13
|
+
function useWizard(_ref) {
|
|
14
|
+
let {
|
|
15
|
+
steps: wizardSteps,
|
|
16
|
+
current,
|
|
17
|
+
onNext = noop,
|
|
18
|
+
onPrevious = noop,
|
|
19
|
+
initial = 0
|
|
20
|
+
} = _ref;
|
|
21
|
+
const [currentStep, setCurrentStep] = dsUtilities.useDerivedStateFromProps(current || initial);
|
|
22
|
+
const handleNext = React.useCallback(() => {
|
|
23
|
+
if (checkCanNext(currentStep, wizardSteps)) {
|
|
24
|
+
onNext(currentStep);
|
|
25
|
+
setCurrentStep(currentStep + 1);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const handlePrevious = React.useCallback(() => {
|
|
29
|
+
if (checkCanPrevious(currentStep)) {
|
|
30
|
+
onPrevious(currentStep);
|
|
31
|
+
setCurrentStep(currentStep - 1);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
current: currentStep,
|
|
36
|
+
next: handleNext,
|
|
37
|
+
previous: handlePrevious,
|
|
38
|
+
canNext: checkCanNext(currentStep, wizardSteps),
|
|
39
|
+
canPrevious: checkCanPrevious(currentStep),
|
|
40
|
+
WizardCurrentContent: dsUtilities.get(wizardSteps, [currentStep, 'content'], () => null)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = useWizard;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import { useMemo, isValidElement, cloneElement } from 'react';
|
|
3
|
+
import { PropTypes, describe } from 'react-desc';
|
|
4
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
5
|
+
import { get } from '@elliemae/ds-utilities';
|
|
6
|
+
import { Checkmark } from '@elliemae/ds-icons';
|
|
7
|
+
import { indicatorItemBlockName } from './blockNames.js';
|
|
8
|
+
|
|
9
|
+
var _Checkmark;
|
|
10
|
+
const Item = aggregatedClasses('div')("".concat(indicatorItemBlockName), null, _ref => {
|
|
11
|
+
let {
|
|
12
|
+
active,
|
|
13
|
+
completed
|
|
14
|
+
} = _ref;
|
|
15
|
+
return {
|
|
16
|
+
active,
|
|
17
|
+
completed
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
const Wrapper = aggregatedClasses('div')("".concat(indicatorItemBlockName, "-wrapper"));
|
|
21
|
+
const Label = aggregatedClasses('span')(indicatorItemBlockName, 'label');
|
|
22
|
+
const Bullet = aggregatedClasses('div')(indicatorItemBlockName, 'bullet');
|
|
23
|
+
const BulletWrapper = aggregatedClasses('div')(indicatorItemBlockName, 'bullet-wrapper');
|
|
24
|
+
|
|
25
|
+
function WizardStep(_ref2) {
|
|
26
|
+
let {
|
|
27
|
+
label = '',
|
|
28
|
+
icon = null,
|
|
29
|
+
iconCompleted = _Checkmark || (_Checkmark = /*#__PURE__*/_jsx(Checkmark, {})),
|
|
30
|
+
iconActive = null,
|
|
31
|
+
active = false,
|
|
32
|
+
completed = false,
|
|
33
|
+
index = 0
|
|
34
|
+
} = _ref2;
|
|
35
|
+
const currentIcon = useMemo(() => {
|
|
36
|
+
if (active) return iconActive;
|
|
37
|
+
if (completed) return iconCompleted;
|
|
38
|
+
return icon;
|
|
39
|
+
}, [active, completed]) || icon;
|
|
40
|
+
const iconWithOptions = useMemo(() => /*#__PURE__*/isValidElement(currentIcon) ? /*#__PURE__*/cloneElement(currentIcon, {
|
|
41
|
+
color: get(currentIcon, ['props', 'color']) || ['brand-primary', completed ? 600 : 500]
|
|
42
|
+
}) : currentIcon || index + 1, [currentIcon]);
|
|
43
|
+
return /*#__PURE__*/_jsx(Item, {
|
|
44
|
+
classProps: {
|
|
45
|
+
active,
|
|
46
|
+
completed
|
|
47
|
+
}
|
|
48
|
+
}, void 0, /*#__PURE__*/_jsx(Wrapper, {}, void 0, /*#__PURE__*/_jsx(BulletWrapper, {}, void 0, /*#__PURE__*/_jsx(Bullet, {}, void 0, iconWithOptions)), /*#__PURE__*/_jsx(Label, {}, void 0, label)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const wizzardStepProps = {
|
|
52
|
+
label: PropTypes.string.description('Step label'),
|
|
53
|
+
icon: PropTypes.oneOfType([PropTypes.element, PropTypes.string]).description('Default icon or number'),
|
|
54
|
+
iconCompleted: PropTypes.element.description('Icon when the step is completed').defaultValue(Checkmark),
|
|
55
|
+
iconActive: PropTypes.element.description('Icon when the step is active'),
|
|
56
|
+
active: PropTypes.bool.description('Whether the step is active or not').defaultValue(false),
|
|
57
|
+
completed: PropTypes.bool.description('Whether the step is completed or not').defaultValue(false),
|
|
58
|
+
index: PropTypes.number.description('Current item index')
|
|
59
|
+
};
|
|
60
|
+
const WizzardStepWithSchema = describe(WizardStep);
|
|
61
|
+
WizzardStepWithSchema.propTypes = wizzardStepProps;
|
|
62
|
+
|
|
63
|
+
export { WizzardStepWithSchema, WizardStep as default };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
3
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
4
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
5
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
8
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
9
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
10
|
+
import React, { useMemo, cloneElement } from 'react';
|
|
11
|
+
import { PropTypes, describe } from 'react-desc';
|
|
12
|
+
import { aggregatedClasses } from '@elliemae/ds-classnames';
|
|
13
|
+
import WizardStep from './WizardStep.js';
|
|
14
|
+
import { indicatorBlockName } from './blockNames.js';
|
|
15
|
+
import { jsx } from 'react/jsx-runtime';
|
|
16
|
+
|
|
17
|
+
const _excluded = ["current", "steps", "children"];
|
|
18
|
+
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
|
|
21
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
|
+
const StepsWrapper = aggregatedClasses('div')(indicatorBlockName);
|
|
23
|
+
|
|
24
|
+
function WizardSteps(_ref) {
|
|
25
|
+
let {
|
|
26
|
+
current = 0,
|
|
27
|
+
steps,
|
|
28
|
+
children
|
|
29
|
+
} = _ref,
|
|
30
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
|
31
|
+
|
|
32
|
+
const items = useMemo(() => {
|
|
33
|
+
const mergeStepProps = (step, index) => ({
|
|
34
|
+
index,
|
|
35
|
+
active: current === index,
|
|
36
|
+
completed: index < current
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return steps ? steps.map((step, index) => /*#__PURE__*/jsx(WizardStep, _objectSpread(_objectSpread({}, step), mergeStepProps(step, index)), index)) : React.Children.map(children, (item, index) => /*#__PURE__*/cloneElement(item, mergeStepProps(item, index)));
|
|
40
|
+
}, [current, children]);
|
|
41
|
+
return /*#__PURE__*/jsx(StepsWrapper, _objectSpread(_objectSpread({}, otherProps), {}, {
|
|
42
|
+
children: items
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
WizardSteps.Item = WizardStep;
|
|
47
|
+
const wizzardProps = {
|
|
48
|
+
current: PropTypes.number.description('Current active state index').defaultValue(0),
|
|
49
|
+
steps: PropTypes.arrayOf(PropTypes.shape({})).description('Array of steps objects').defaultValue([]).isRequired,
|
|
50
|
+
children: PropTypes.arrayOf(PropTypes.instanceOf(WizardStep)).description('List of WizardStep components')
|
|
51
|
+
};
|
|
52
|
+
const WizzardWithSchema = describe(WizardSteps);
|
|
53
|
+
WizzardWithSchema.propTypes = wizzardProps;
|
|
54
|
+
|
|
55
|
+
export { WizzardWithSchema, WizardSteps as default };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
2
|
+
import 'react';
|
|
3
|
+
|
|
4
|
+
var _div, _div2, _div3, _div4;
|
|
5
|
+
|
|
6
|
+
const Step1Content = () => _div || (_div = /*#__PURE__*/_jsx("div", {}, void 0, "Step 1 Content"));
|
|
7
|
+
|
|
8
|
+
const Step2Content = () => _div2 || (_div2 = /*#__PURE__*/_jsx("div", {}, void 0, "Step 2 Content"));
|
|
9
|
+
|
|
10
|
+
const Step3Content = () => _div3 || (_div3 = /*#__PURE__*/_jsx("div", {}, void 0, "Step 3 Content"));
|
|
11
|
+
|
|
12
|
+
const Step4Content = () => _div4 || (_div4 = /*#__PURE__*/_jsx("div", {}, void 0, "Step 4 Content"));
|
|
13
|
+
|
|
14
|
+
const steps = [{
|
|
15
|
+
label: 'Step 1',
|
|
16
|
+
content: Step1Content
|
|
17
|
+
}, {
|
|
18
|
+
label: 'Step Lorem Ipsum',
|
|
19
|
+
content: Step2Content
|
|
20
|
+
}, {
|
|
21
|
+
label: 'Step Lorem',
|
|
22
|
+
content: Step3Content
|
|
23
|
+
}, {
|
|
24
|
+
label: 'Step Lorem 4',
|
|
25
|
+
content: Step4Content
|
|
26
|
+
}];
|
|
27
|
+
|
|
28
|
+
export { steps };
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useCallback } from
|
|
3
|
-
import {
|
|
1
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useDerivedStateFromProps, get } from '@elliemae/ds-utilities';
|
|
4
|
+
|
|
4
5
|
const checkCanNext = (prevIndex, array) => array.length > prevIndex + 1;
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
const checkCanPrevious = prevIndex => prevIndex - 1 >= 0;
|
|
8
|
+
|
|
6
9
|
const noop = () => null;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
|
|
11
|
+
function useWizard(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
steps: wizardSteps,
|
|
14
|
+
current,
|
|
15
|
+
onNext = noop,
|
|
16
|
+
onPrevious = noop,
|
|
17
|
+
initial = 0
|
|
18
|
+
} = _ref;
|
|
14
19
|
const [currentStep, setCurrentStep] = useDerivedStateFromProps(current || initial);
|
|
15
20
|
const handleNext = useCallback(() => {
|
|
16
21
|
if (checkCanNext(currentStep, wizardSteps)) {
|
|
@@ -30,10 +35,8 @@ function useWizard({
|
|
|
30
35
|
previous: handlePrevious,
|
|
31
36
|
canNext: checkCanNext(currentStep, wizardSteps),
|
|
32
37
|
canPrevious: checkCanPrevious(currentStep),
|
|
33
|
-
WizardCurrentContent: get(wizardSteps, [currentStep,
|
|
38
|
+
WizardCurrentContent: get(wizardSteps, [currentStep, 'content'], () => null)
|
|
34
39
|
};
|
|
35
40
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=useWizard.js.map
|
|
41
|
+
|
|
42
|
+
export { useWizard as default };
|
package/package.json
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-wizard",
|
|
3
|
-
"version": "2.3.0-
|
|
3
|
+
"version": "2.3.0-next.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Wizard",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"module": "./dist/esm/index.js",
|
|
10
|
-
"main": "./dist/cjs/index.js",
|
|
11
|
-
"types": "./dist/types/index.d.ts",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"main": "./cjs/index.js",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
12
9
|
"exports": {
|
|
13
10
|
".": {
|
|
14
|
-
"import": "./
|
|
15
|
-
"require": "./
|
|
11
|
+
"import": "./esm/index.js",
|
|
12
|
+
"require": "./cjs/index.js"
|
|
16
13
|
},
|
|
17
14
|
"./WizardSteps": {
|
|
18
|
-
"import": "./
|
|
19
|
-
"require": "./
|
|
15
|
+
"import": "./esm/WizardSteps.js",
|
|
16
|
+
"require": "./cjs/WizardSteps.js"
|
|
20
17
|
},
|
|
21
18
|
"./WizardStep": {
|
|
22
|
-
"import": "./
|
|
23
|
-
"require": "./
|
|
19
|
+
"import": "./esm/WizardStep.js",
|
|
20
|
+
"require": "./cjs/WizardStep.js"
|
|
24
21
|
},
|
|
25
22
|
"./useWizard": {
|
|
26
|
-
"import": "./
|
|
27
|
-
"require": "./
|
|
23
|
+
"import": "./esm/useWizard.js",
|
|
24
|
+
"require": "./cjs/useWizard.js"
|
|
28
25
|
},
|
|
29
26
|
"./stories/steps": {
|
|
30
|
-
"import": "./
|
|
31
|
-
"require": "./
|
|
27
|
+
"import": "./esm/stories/steps.js",
|
|
28
|
+
"require": "./cjs/stories/steps.js"
|
|
32
29
|
},
|
|
33
30
|
"./blockNames": {
|
|
34
|
-
"import": "./
|
|
35
|
-
"require": "./
|
|
31
|
+
"import": "./esm/blockNames.js",
|
|
32
|
+
"require": "./cjs/blockNames.js"
|
|
36
33
|
}
|
|
37
34
|
},
|
|
38
35
|
"sideEffects": [
|
|
@@ -44,16 +41,22 @@
|
|
|
44
41
|
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
45
42
|
},
|
|
46
43
|
"engines": {
|
|
47
|
-
"
|
|
48
|
-
"node": ">=
|
|
44
|
+
"npm": ">=7",
|
|
45
|
+
"node": ">=14"
|
|
49
46
|
},
|
|
50
47
|
"author": "ICE MT",
|
|
48
|
+
"scripts": {
|
|
49
|
+
"dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w",
|
|
50
|
+
"prebuild": "exit 0",
|
|
51
|
+
"predev": "exit 0",
|
|
52
|
+
"build": "node ../../scripts/build/build.js"
|
|
53
|
+
},
|
|
51
54
|
"dependencies": {
|
|
52
|
-
"@elliemae/ds-button": "2.3.0-
|
|
53
|
-
"@elliemae/ds-classnames": "2.3.0-
|
|
54
|
-
"@elliemae/ds-icons": "2.3.0-
|
|
55
|
-
"@elliemae/ds-utilities": "2.3.0-
|
|
56
|
-
"@elliemae/ds-wizard": "2.3.0-
|
|
55
|
+
"@elliemae/ds-button": "2.3.0-next.2",
|
|
56
|
+
"@elliemae/ds-classnames": "2.3.0-next.2",
|
|
57
|
+
"@elliemae/ds-icons": "2.3.0-next.2",
|
|
58
|
+
"@elliemae/ds-utilities": "2.3.0-next.2",
|
|
59
|
+
"@elliemae/ds-wizard": "2.3.0-next.2",
|
|
57
60
|
"prop-types": "~15.7.2",
|
|
58
61
|
"react-desc": "~4.1.3"
|
|
59
62
|
},
|
|
@@ -64,12 +67,7 @@
|
|
|
64
67
|
},
|
|
65
68
|
"publishConfig": {
|
|
66
69
|
"access": "public",
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
"scripts": {
|
|
70
|
-
"dev": "cross-env NODE_ENV=development && node ../../scripts/build/build.js -w",
|
|
71
|
-
"prebuild": "exit 0",
|
|
72
|
-
"predev": "exit 0",
|
|
73
|
-
"build": "node ../../scripts/build/build.js"
|
|
70
|
+
"directory": "dist",
|
|
71
|
+
"generateSubmodules": true
|
|
74
72
|
}
|
|
75
73
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export const title: string;
|
|
3
|
+
export { WizardStepsIndicator as component };
|
|
4
|
+
export namespace parameters {
|
|
5
|
+
export { WizzardWithSchema as propsSchemas };
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export default _default;
|
|
9
|
+
export * from "./stories/wizzard-overview.stories";
|
|
10
|
+
import { WizardStepsIndicator } from "@elliemae/ds-wizard";
|
|
11
|
+
import { WizzardWithSchema } from "@elliemae/ds-wizard";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
+
/// <reference types="react" />
|
|
3
|
+
declare function WizardStep({ label, icon, iconCompleted, iconActive, active, completed, index, }: {
|
|
4
|
+
label?: string | undefined;
|
|
5
|
+
icon?: null | undefined;
|
|
6
|
+
iconCompleted?: JSX.Element | undefined;
|
|
7
|
+
iconActive?: null | undefined;
|
|
8
|
+
active?: boolean | undefined;
|
|
9
|
+
completed?: boolean | undefined;
|
|
10
|
+
index?: number | undefined;
|
|
11
|
+
}): JSX.Element;
|
|
12
|
+
declare namespace WizardStep {
|
|
13
|
+
var propTypes: {
|
|
14
|
+
label: {
|
|
15
|
+
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
16
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
17
|
+
};
|
|
18
|
+
isRequired: import("react-desc").PropTypesDescValue;
|
|
19
|
+
};
|
|
20
|
+
icon: {
|
|
21
|
+
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
22
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
23
|
+
};
|
|
24
|
+
isRequired: import("react-desc").PropTypesDescValue;
|
|
25
|
+
};
|
|
26
|
+
iconCompleted: {
|
|
27
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
28
|
+
};
|
|
29
|
+
iconActive: {
|
|
30
|
+
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
31
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
32
|
+
};
|
|
33
|
+
isRequired: import("react-desc").PropTypesDescValue;
|
|
34
|
+
};
|
|
35
|
+
active: {
|
|
36
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
37
|
+
};
|
|
38
|
+
completed: {
|
|
39
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
40
|
+
};
|
|
41
|
+
index: {
|
|
42
|
+
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
43
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
44
|
+
};
|
|
45
|
+
isRequired: import("react-desc").PropTypesDescValue;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
declare const WizzardStepWithSchema: {
|
|
50
|
+
(props?: unknown): JSX.Element;
|
|
51
|
+
propTypes: unknown;
|
|
52
|
+
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
53
|
+
};
|
|
54
|
+
export { WizzardStepWithSchema };
|
|
55
|
+
export default WizardStep;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference path="../../../../shared/typings/react-desc.d.ts" />
|
|
2
|
+
/// <reference types="react" />
|
|
3
|
+
import WizardStep from './WizardStep';
|
|
4
|
+
declare function WizardSteps({ current, steps, children, ...otherProps }: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
current?: number | undefined;
|
|
7
|
+
steps: any;
|
|
8
|
+
children: any;
|
|
9
|
+
}): JSX.Element;
|
|
10
|
+
declare namespace WizardSteps {
|
|
11
|
+
var Item: typeof WizardStep;
|
|
12
|
+
var propTypes: {
|
|
13
|
+
current: {
|
|
14
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
15
|
+
};
|
|
16
|
+
steps: any;
|
|
17
|
+
children: {
|
|
18
|
+
defaultValue(arg: import("react-desc").ReactDescPossibleDefaultValues): {
|
|
19
|
+
deprecated: import("react-desc").PropTypesDescValidator;
|
|
20
|
+
};
|
|
21
|
+
isRequired: import("react-desc").PropTypesDescValue;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
declare const WizzardWithSchema: {
|
|
26
|
+
(props?: unknown): JSX.Element;
|
|
27
|
+
propTypes: unknown;
|
|
28
|
+
toTypescript: () => import("react-desc").TypescriptSchema;
|
|
29
|
+
};
|
|
30
|
+
export { WizzardWithSchema };
|
|
31
|
+
export default WizardSteps;
|