@cloudflare/component-multistep-modal 4.0.39 → 5.0.1
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/types.d.ts +8 -0
- package/es/MultistepModal.js +39 -5
- package/es/index.js +1 -0
- package/es/types.js +7 -1
- package/lib/MultistepModal.js +72 -16
- package/lib/index.js +8 -0
- package/lib/types.js +10 -1
- package/package.json +1 -1
- package/src/MultistepModal.tsx +43 -6
- package/src/index.ts +1 -0
- package/src/types.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b30668d911: Modified MultiStep Modal to not call the nextOnClick callback when cancelOnClick is activated
|
|
8
|
+
|
|
9
|
+
## 5.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- 0c59dd3257: - Refactored to allow the cancel CTA to be customizable as a secondary CTA at each step. This PR modifies the multistep modal component to accept custom cancel click behavior and label at each step, so that we can use the `Cancel Button` as a Secondary CTA instead of the traditional closing of the modal. It can be configure at each step to move forward, backward or use the default behavior of closing the modal in addition to executing custom code in the `cancelOnClick` callback. Another feature is the ability to provide a custom `cancelLabel` at each step.
|
|
14
|
+
|
|
3
15
|
## 4.0.39
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export declare enum OnCancelClickBehaviour {
|
|
3
|
+
DEFAULT = "default",
|
|
4
|
+
ADVANCE = "advance",
|
|
5
|
+
BACK = "back"
|
|
6
|
+
}
|
|
2
7
|
export interface IStepItem {
|
|
3
8
|
content: JSX.Element;
|
|
4
9
|
nextLabel?: string | JSX.Element;
|
|
5
10
|
nextDisabled?: boolean;
|
|
6
11
|
nextLoading?: boolean;
|
|
7
12
|
nextOnClick?: () => Promise<boolean> | boolean;
|
|
13
|
+
cancelOnClick?: () => Promise<boolean> | boolean;
|
|
8
14
|
hideBack?: boolean;
|
|
9
15
|
hideCancel?: boolean;
|
|
10
16
|
progressLabel?: string | JSX.Element | null;
|
|
17
|
+
cancelLabel?: JSX.Element;
|
|
18
|
+
onCancelClickBehaviour?: OnCancelClickBehaviour;
|
|
11
19
|
}
|
package/es/MultistepModal.js
CHANGED
|
@@ -13,6 +13,7 @@ import { createComponent } from '@cloudflare/style-container';
|
|
|
13
13
|
import { Progress } from '@cloudflare/component-progress';
|
|
14
14
|
import { Trans } from '@cloudflare/intl-react';
|
|
15
15
|
import { TID } from './constants';
|
|
16
|
+
import { OnCancelClickBehaviour } from './types';
|
|
16
17
|
|
|
17
18
|
var getElements = (steps, step) => {
|
|
18
19
|
if (!steps || !steps[step]) {
|
|
@@ -21,7 +22,10 @@ var getElements = (steps, step) => {
|
|
|
21
22
|
nextLabel: 'Next step',
|
|
22
23
|
nextDisabled: false,
|
|
23
24
|
nextOnClick: () => true,
|
|
24
|
-
progress: undefined
|
|
25
|
+
progress: undefined,
|
|
26
|
+
cancelLabel: undefined,
|
|
27
|
+
cancelOnClick: () => true,
|
|
28
|
+
onCancelClickBehaviour: OnCancelClickBehaviour.DEFAULT
|
|
25
29
|
};
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -33,11 +37,14 @@ var getElements = (steps, step) => {
|
|
|
33
37
|
nextOnClick: steps[step].nextOnClick,
|
|
34
38
|
hideBack: steps[step].hideBack,
|
|
35
39
|
hideCancel: steps[step].hideCancel,
|
|
40
|
+
cancelLabel: steps[step].cancelLabel,
|
|
41
|
+
cancelOnClick: steps[step].cancelOnClick,
|
|
36
42
|
progress: steps[step].progressLabel ? steps.map((_step, index) => ({
|
|
37
43
|
id: index,
|
|
38
44
|
label: _step.progressLabel || '',
|
|
39
45
|
disabled: true
|
|
40
|
-
})) : undefined
|
|
46
|
+
})) : undefined,
|
|
47
|
+
onCancelClickBehaviour: steps[step].onCancelClickBehaviour
|
|
41
48
|
};
|
|
42
49
|
};
|
|
43
50
|
|
|
@@ -93,7 +100,10 @@ class MultistepModal extends React.Component {
|
|
|
93
100
|
nextOnClick,
|
|
94
101
|
hideBack,
|
|
95
102
|
hideCancel,
|
|
96
|
-
progress
|
|
103
|
+
progress,
|
|
104
|
+
cancelLabel,
|
|
105
|
+
cancelOnClick,
|
|
106
|
+
onCancelClickBehaviour
|
|
97
107
|
} = getElements(renderSteps(step), step);
|
|
98
108
|
return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen ? /*#__PURE__*/React.createElement(TestDummy, {
|
|
99
109
|
id: TID.MODAL_OPEN
|
|
@@ -130,9 +140,33 @@ class MultistepModal extends React.Component {
|
|
|
130
140
|
spaced: true
|
|
131
141
|
}, !hideCancel && /*#__PURE__*/React.createElement(Button, {
|
|
132
142
|
type: "default",
|
|
133
|
-
onClick: (
|
|
143
|
+
onClick: /*#__PURE__*/_asyncToGenerator(function* () {
|
|
144
|
+
if (cancelOnClick) {
|
|
145
|
+
yield cancelOnClick(); // Advance to the next Step
|
|
146
|
+
|
|
147
|
+
if (onCancelClickBehaviour === OnCancelClickBehaviour.ADVANCE) {
|
|
148
|
+
onNextStep && onNextStep(step + 1);
|
|
149
|
+
|
|
150
|
+
_this.setState({
|
|
151
|
+
step: step + 1
|
|
152
|
+
}); // Go back to the previous Step
|
|
153
|
+
|
|
154
|
+
} else if (onCancelClickBehaviour === OnCancelClickBehaviour.BACK) {
|
|
155
|
+
onPrevStep && onPrevStep(step - 1);
|
|
156
|
+
|
|
157
|
+
_this.setState({
|
|
158
|
+
step: step - 1
|
|
159
|
+
});
|
|
160
|
+
} else {
|
|
161
|
+
// Default - close the modal
|
|
162
|
+
onClose();
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
onClose();
|
|
166
|
+
}
|
|
167
|
+
}),
|
|
134
168
|
testId: TID.BUTTON_CANCEL
|
|
135
|
-
}, /*#__PURE__*/React.createElement(Trans, {
|
|
169
|
+
}, cancelLabel ? cancelLabel : /*#__PURE__*/React.createElement(Trans, {
|
|
136
170
|
id: "common.cancel"
|
|
137
171
|
})), /*#__PURE__*/React.createElement(Button, {
|
|
138
172
|
testId: TID.BUTTON_NEXT,
|
package/es/index.js
CHANGED
package/es/types.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var OnCancelClickBehaviour;
|
|
2
|
+
|
|
3
|
+
(function (OnCancelClickBehaviour) {
|
|
4
|
+
OnCancelClickBehaviour["DEFAULT"] = "default";
|
|
5
|
+
OnCancelClickBehaviour["ADVANCE"] = "advance";
|
|
6
|
+
OnCancelClickBehaviour["BACK"] = "back";
|
|
7
|
+
})(OnCancelClickBehaviour || (OnCancelClickBehaviour = {}));
|
package/lib/MultistepModal.js
CHANGED
|
@@ -25,6 +25,8 @@ var _intlReact = require("@cloudflare/intl-react");
|
|
|
25
25
|
|
|
26
26
|
var _constants = require("./constants");
|
|
27
27
|
|
|
28
|
+
var _types = require("./types");
|
|
29
|
+
|
|
28
30
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
31
|
|
|
30
32
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
@@ -64,7 +66,12 @@ var getElements = function getElements(steps, step) {
|
|
|
64
66
|
nextOnClick: function nextOnClick() {
|
|
65
67
|
return true;
|
|
66
68
|
},
|
|
67
|
-
progress: undefined
|
|
69
|
+
progress: undefined,
|
|
70
|
+
cancelLabel: undefined,
|
|
71
|
+
cancelOnClick: function cancelOnClick() {
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
onCancelClickBehaviour: _types.OnCancelClickBehaviour.DEFAULT
|
|
68
75
|
};
|
|
69
76
|
}
|
|
70
77
|
|
|
@@ -76,13 +83,16 @@ var getElements = function getElements(steps, step) {
|
|
|
76
83
|
nextOnClick: steps[step].nextOnClick,
|
|
77
84
|
hideBack: steps[step].hideBack,
|
|
78
85
|
hideCancel: steps[step].hideCancel,
|
|
86
|
+
cancelLabel: steps[step].cancelLabel,
|
|
87
|
+
cancelOnClick: steps[step].cancelOnClick,
|
|
79
88
|
progress: steps[step].progressLabel ? steps.map(function (_step, index) {
|
|
80
89
|
return {
|
|
81
90
|
id: index,
|
|
82
91
|
label: _step.progressLabel || '',
|
|
83
92
|
disabled: true
|
|
84
93
|
};
|
|
85
|
-
}) : undefined
|
|
94
|
+
}) : undefined,
|
|
95
|
+
onCancelClickBehaviour: steps[step].onCancelClickBehaviour
|
|
86
96
|
};
|
|
87
97
|
};
|
|
88
98
|
|
|
@@ -152,7 +162,10 @@ var MultistepModal = /*#__PURE__*/function (_React$Component) {
|
|
|
152
162
|
nextOnClick = _getElements.nextOnClick,
|
|
153
163
|
hideBack = _getElements.hideBack,
|
|
154
164
|
hideCancel = _getElements.hideCancel,
|
|
155
|
-
progress = _getElements.progress
|
|
165
|
+
progress = _getElements.progress,
|
|
166
|
+
cancelLabel = _getElements.cancelLabel,
|
|
167
|
+
cancelOnClick = _getElements.cancelOnClick,
|
|
168
|
+
onCancelClickBehaviour = _getElements.onCancelClickBehaviour;
|
|
156
169
|
|
|
157
170
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen ? /*#__PURE__*/_react.default.createElement(_componentTestDummy.TestDummy, {
|
|
158
171
|
id: _constants.TID.MODAL_OPEN
|
|
@@ -190,39 +203,82 @@ var MultistepModal = /*#__PURE__*/function (_React$Component) {
|
|
|
190
203
|
spaced: true
|
|
191
204
|
}, !hideCancel && /*#__PURE__*/_react.default.createElement(_componentButton.Button, {
|
|
192
205
|
type: "default",
|
|
193
|
-
onClick: function
|
|
194
|
-
return
|
|
195
|
-
|
|
206
|
+
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
207
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
208
|
+
while (1) {
|
|
209
|
+
switch (_context.prev = _context.next) {
|
|
210
|
+
case 0:
|
|
211
|
+
if (!cancelOnClick) {
|
|
212
|
+
_context.next = 6;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
_context.next = 3;
|
|
217
|
+
return cancelOnClick();
|
|
218
|
+
|
|
219
|
+
case 3:
|
|
220
|
+
// Advance to the next Step
|
|
221
|
+
if (onCancelClickBehaviour === _types.OnCancelClickBehaviour.ADVANCE) {
|
|
222
|
+
onNextStep && onNextStep(step + 1);
|
|
223
|
+
|
|
224
|
+
_this2.setState({
|
|
225
|
+
step: step + 1
|
|
226
|
+
}); // Go back to the previous Step
|
|
227
|
+
|
|
228
|
+
} else if (onCancelClickBehaviour === _types.OnCancelClickBehaviour.BACK) {
|
|
229
|
+
onPrevStep && onPrevStep(step - 1);
|
|
230
|
+
|
|
231
|
+
_this2.setState({
|
|
232
|
+
step: step - 1
|
|
233
|
+
});
|
|
234
|
+
} else {
|
|
235
|
+
// Default - close the modal
|
|
236
|
+
onClose();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
_context.next = 7;
|
|
240
|
+
break;
|
|
241
|
+
|
|
242
|
+
case 6:
|
|
243
|
+
onClose();
|
|
244
|
+
|
|
245
|
+
case 7:
|
|
246
|
+
case "end":
|
|
247
|
+
return _context.stop();
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}, _callee);
|
|
251
|
+
})),
|
|
196
252
|
testId: _constants.TID.BUTTON_CANCEL
|
|
197
|
-
}, /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
253
|
+
}, cancelLabel ? cancelLabel : /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
198
254
|
id: "common.cancel"
|
|
199
255
|
})), /*#__PURE__*/_react.default.createElement(_componentButton.Button, {
|
|
200
256
|
testId: _constants.TID.BUTTON_NEXT,
|
|
201
257
|
type: "primary",
|
|
202
258
|
disabled: nextDisabled,
|
|
203
259
|
loading: nextLoading,
|
|
204
|
-
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
260
|
+
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
205
261
|
var res;
|
|
206
|
-
return _regeneratorRuntime().wrap(function
|
|
262
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
207
263
|
while (1) {
|
|
208
|
-
switch (
|
|
264
|
+
switch (_context2.prev = _context2.next) {
|
|
209
265
|
case 0:
|
|
210
266
|
onNextStep && onNextStep(step + 1);
|
|
211
267
|
|
|
212
268
|
if (!nextOnClick) {
|
|
213
|
-
|
|
269
|
+
_context2.next = 8;
|
|
214
270
|
break;
|
|
215
271
|
}
|
|
216
272
|
|
|
217
|
-
|
|
273
|
+
_context2.next = 4;
|
|
218
274
|
return nextOnClick();
|
|
219
275
|
|
|
220
276
|
case 4:
|
|
221
|
-
res =
|
|
277
|
+
res = _context2.sent;
|
|
222
278
|
res && _this2.setState({
|
|
223
279
|
step: step + 1
|
|
224
280
|
});
|
|
225
|
-
|
|
281
|
+
_context2.next = 9;
|
|
226
282
|
break;
|
|
227
283
|
|
|
228
284
|
case 8:
|
|
@@ -232,10 +288,10 @@ var MultistepModal = /*#__PURE__*/function (_React$Component) {
|
|
|
232
288
|
|
|
233
289
|
case 9:
|
|
234
290
|
case "end":
|
|
235
|
-
return
|
|
291
|
+
return _context2.stop();
|
|
236
292
|
}
|
|
237
293
|
}
|
|
238
|
-
},
|
|
294
|
+
}, _callee2);
|
|
239
295
|
}))
|
|
240
296
|
}, nextLabel))))));
|
|
241
297
|
}
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "MultistepModal", {
|
|
|
9
9
|
return _MultistepModal.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "OnCancelClickBehaviour", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _types.OnCancelClickBehaviour;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
12
18
|
Object.defineProperty(exports, "TID", {
|
|
13
19
|
enumerable: true,
|
|
14
20
|
get: function get() {
|
|
@@ -20,4 +26,6 @@ var _MultistepModal = _interopRequireDefault(require("./MultistepModal"));
|
|
|
20
26
|
|
|
21
27
|
var _constants = require("./constants");
|
|
22
28
|
|
|
29
|
+
var _types = require("./types");
|
|
30
|
+
|
|
23
31
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/types.js
CHANGED
|
@@ -2,4 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
});
|
|
5
|
+
});
|
|
6
|
+
exports.OnCancelClickBehaviour = void 0;
|
|
7
|
+
var OnCancelClickBehaviour;
|
|
8
|
+
exports.OnCancelClickBehaviour = OnCancelClickBehaviour;
|
|
9
|
+
|
|
10
|
+
(function (OnCancelClickBehaviour) {
|
|
11
|
+
OnCancelClickBehaviour["DEFAULT"] = "default";
|
|
12
|
+
OnCancelClickBehaviour["ADVANCE"] = "advance";
|
|
13
|
+
OnCancelClickBehaviour["BACK"] = "back";
|
|
14
|
+
})(OnCancelClickBehaviour || (exports.OnCancelClickBehaviour = OnCancelClickBehaviour = {}));
|
package/package.json
CHANGED
package/src/MultistepModal.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { createComponent } from '@cloudflare/style-container';
|
|
|
14
14
|
import { Progress } from '@cloudflare/component-progress';
|
|
15
15
|
import { Trans } from '@cloudflare/intl-react';
|
|
16
16
|
import { TID } from './constants';
|
|
17
|
-
import { IStepItem } from './types';
|
|
17
|
+
import { IStepItem, OnCancelClickBehaviour } from './types';
|
|
18
18
|
|
|
19
19
|
type TWidth = 'narrow' | 'wide' | 'extra-wide' | 'super-extra-wide';
|
|
20
20
|
|
|
@@ -41,9 +41,12 @@ interface IElements {
|
|
|
41
41
|
nextDisabled?: boolean;
|
|
42
42
|
nextLoading?: boolean;
|
|
43
43
|
nextOnClick?: () => Promise<boolean> | boolean;
|
|
44
|
+
cancelOnClick?: () => Promise<boolean> | boolean;
|
|
44
45
|
progress?: IProgressStep[];
|
|
45
46
|
hideBack?: boolean;
|
|
46
47
|
hideCancel?: boolean;
|
|
48
|
+
cancelLabel?: JSX.Element | string;
|
|
49
|
+
onCancelClickBehaviour?: OnCancelClickBehaviour;
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
const getElements = (steps: IStepItem[], step: number): IElements => {
|
|
@@ -53,7 +56,10 @@ const getElements = (steps: IStepItem[], step: number): IElements => {
|
|
|
53
56
|
nextLabel: 'Next step',
|
|
54
57
|
nextDisabled: false,
|
|
55
58
|
nextOnClick: () => true,
|
|
56
|
-
progress: undefined
|
|
59
|
+
progress: undefined,
|
|
60
|
+
cancelLabel: undefined,
|
|
61
|
+
cancelOnClick: () => true,
|
|
62
|
+
onCancelClickBehaviour: OnCancelClickBehaviour.DEFAULT
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
65
|
return {
|
|
@@ -64,13 +70,16 @@ const getElements = (steps: IStepItem[], step: number): IElements => {
|
|
|
64
70
|
nextOnClick: steps[step].nextOnClick,
|
|
65
71
|
hideBack: steps[step].hideBack,
|
|
66
72
|
hideCancel: steps[step].hideCancel,
|
|
73
|
+
cancelLabel: steps[step].cancelLabel,
|
|
74
|
+
cancelOnClick: steps[step].cancelOnClick,
|
|
67
75
|
progress: steps[step].progressLabel
|
|
68
76
|
? steps.map((_step, index) => ({
|
|
69
77
|
id: index,
|
|
70
78
|
label: _step.progressLabel || '',
|
|
71
79
|
disabled: true
|
|
72
80
|
}))
|
|
73
|
-
: undefined
|
|
81
|
+
: undefined,
|
|
82
|
+
onCancelClickBehaviour: steps[step].onCancelClickBehaviour
|
|
74
83
|
};
|
|
75
84
|
};
|
|
76
85
|
|
|
@@ -111,8 +120,12 @@ class MultistepModal extends React.Component<IMultistepModalProps> {
|
|
|
111
120
|
nextOnClick,
|
|
112
121
|
hideBack,
|
|
113
122
|
hideCancel,
|
|
114
|
-
progress
|
|
123
|
+
progress,
|
|
124
|
+
cancelLabel,
|
|
125
|
+
cancelOnClick,
|
|
126
|
+
onCancelClickBehaviour
|
|
115
127
|
} = getElements(renderSteps(step), step);
|
|
128
|
+
|
|
116
129
|
return (
|
|
117
130
|
<React.Fragment>
|
|
118
131
|
{isOpen ? (
|
|
@@ -162,10 +175,34 @@ class MultistepModal extends React.Component<IMultistepModalProps> {
|
|
|
162
175
|
{!hideCancel && (
|
|
163
176
|
<Button
|
|
164
177
|
type="default"
|
|
165
|
-
onClick={() =>
|
|
178
|
+
onClick={async () => {
|
|
179
|
+
if (cancelOnClick) {
|
|
180
|
+
await cancelOnClick();
|
|
181
|
+
|
|
182
|
+
// Advance to the next Step
|
|
183
|
+
if (
|
|
184
|
+
onCancelClickBehaviour ===
|
|
185
|
+
OnCancelClickBehaviour.ADVANCE
|
|
186
|
+
) {
|
|
187
|
+
onNextStep && onNextStep(step + 1);
|
|
188
|
+
this.setState({ step: step + 1 });
|
|
189
|
+
// Go back to the previous Step
|
|
190
|
+
} else if (
|
|
191
|
+
onCancelClickBehaviour === OnCancelClickBehaviour.BACK
|
|
192
|
+
) {
|
|
193
|
+
onPrevStep && onPrevStep(step - 1);
|
|
194
|
+
this.setState({ step: step - 1 });
|
|
195
|
+
} else {
|
|
196
|
+
// Default - close the modal
|
|
197
|
+
onClose();
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
onClose();
|
|
201
|
+
}
|
|
202
|
+
}}
|
|
166
203
|
testId={TID.BUTTON_CANCEL}
|
|
167
204
|
>
|
|
168
|
-
<Trans id="common.cancel" />
|
|
205
|
+
{cancelLabel ? cancelLabel : <Trans id="common.cancel" />}
|
|
169
206
|
</Button>
|
|
170
207
|
)}
|
|
171
208
|
<Button
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
export enum OnCancelClickBehaviour {
|
|
2
|
+
DEFAULT = 'default',
|
|
3
|
+
ADVANCE = 'advance',
|
|
4
|
+
BACK = 'back'
|
|
5
|
+
}
|
|
1
6
|
export interface IStepItem {
|
|
2
7
|
content: JSX.Element;
|
|
3
8
|
nextLabel?: string | JSX.Element;
|
|
4
9
|
nextDisabled?: boolean;
|
|
5
10
|
nextLoading?: boolean;
|
|
6
11
|
nextOnClick?: () => Promise<boolean> | boolean;
|
|
12
|
+
cancelOnClick?: () => Promise<boolean> | boolean;
|
|
7
13
|
hideBack?: boolean;
|
|
8
14
|
hideCancel?: boolean;
|
|
9
15
|
progressLabel?: string | JSX.Element | null;
|
|
16
|
+
cancelLabel?: JSX.Element;
|
|
17
|
+
onCancelClickBehaviour?: OnCancelClickBehaviour;
|
|
10
18
|
}
|