@cloudflare/component-multistep-modal 4.0.38 → 5.0.0
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 +15 -0
- package/dist/index.d.ts +1 -0
- package/dist/types.d.ts +8 -0
- package/es/MultistepModal.js +46 -5
- package/es/index.js +1 -0
- package/es/types.js +7 -1
- package/lib/MultistepModal.js +99 -16
- package/lib/index.js +8 -0
- package/lib/types.js +10 -1
- package/package.json +4 -4
- package/src/MultistepModal.tsx +48 -6
- package/src/index.ts +1 -0
- package/src/types.ts +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
## 4.0.39
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [8d9c4128ea]
|
|
14
|
+
- @cloudflare/component-button@8.5.10
|
|
15
|
+
- @cloudflare/component-modal@8.0.34
|
|
16
|
+
- @cloudflare/component-progress@9.0.39
|
|
17
|
+
|
|
3
18
|
## 4.0.38
|
|
4
19
|
|
|
5
20
|
### 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,40 @@ 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
|
+
if (nextOnClick) {
|
|
151
|
+
var res = yield nextOnClick();
|
|
152
|
+
res && _this.setState({
|
|
153
|
+
step: step + 1
|
|
154
|
+
});
|
|
155
|
+
} else {
|
|
156
|
+
_this.setState({
|
|
157
|
+
step: step + 1
|
|
158
|
+
});
|
|
159
|
+
} // Go back to the previous Step
|
|
160
|
+
|
|
161
|
+
} else if (onCancelClickBehaviour === OnCancelClickBehaviour.BACK) {
|
|
162
|
+
onPrevStep && onPrevStep(step - 1);
|
|
163
|
+
|
|
164
|
+
_this.setState({
|
|
165
|
+
step: step - 1
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
// Default - close the modal
|
|
169
|
+
onClose();
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
onClose();
|
|
173
|
+
}
|
|
174
|
+
}),
|
|
134
175
|
testId: TID.BUTTON_CANCEL
|
|
135
|
-
}, /*#__PURE__*/React.createElement(Trans, {
|
|
176
|
+
}, cancelLabel ? cancelLabel : /*#__PURE__*/React.createElement(Trans, {
|
|
136
177
|
id: "common.cancel"
|
|
137
178
|
})), /*#__PURE__*/React.createElement(Button, {
|
|
138
179
|
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,109 @@ 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
|
-
|
|
195
|
-
|
|
206
|
+
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
207
|
+
var res;
|
|
208
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
209
|
+
while (1) {
|
|
210
|
+
switch (_context.prev = _context.next) {
|
|
211
|
+
case 0:
|
|
212
|
+
if (!cancelOnClick) {
|
|
213
|
+
_context.next = 18;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
_context.next = 3;
|
|
218
|
+
return cancelOnClick();
|
|
219
|
+
|
|
220
|
+
case 3:
|
|
221
|
+
if (!(onCancelClickBehaviour === _types.OnCancelClickBehaviour.ADVANCE)) {
|
|
222
|
+
_context.next = 15;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
onNextStep && onNextStep(step + 1);
|
|
227
|
+
|
|
228
|
+
if (!nextOnClick) {
|
|
229
|
+
_context.next = 12;
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
_context.next = 8;
|
|
234
|
+
return nextOnClick();
|
|
235
|
+
|
|
236
|
+
case 8:
|
|
237
|
+
res = _context.sent;
|
|
238
|
+
res && _this2.setState({
|
|
239
|
+
step: step + 1
|
|
240
|
+
});
|
|
241
|
+
_context.next = 13;
|
|
242
|
+
break;
|
|
243
|
+
|
|
244
|
+
case 12:
|
|
245
|
+
_this2.setState({
|
|
246
|
+
step: step + 1
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
case 13:
|
|
250
|
+
_context.next = 16;
|
|
251
|
+
break;
|
|
252
|
+
|
|
253
|
+
case 15:
|
|
254
|
+
if (onCancelClickBehaviour === _types.OnCancelClickBehaviour.BACK) {
|
|
255
|
+
onPrevStep && onPrevStep(step - 1);
|
|
256
|
+
|
|
257
|
+
_this2.setState({
|
|
258
|
+
step: step - 1
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
// Default - close the modal
|
|
262
|
+
onClose();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
case 16:
|
|
266
|
+
_context.next = 19;
|
|
267
|
+
break;
|
|
268
|
+
|
|
269
|
+
case 18:
|
|
270
|
+
onClose();
|
|
271
|
+
|
|
272
|
+
case 19:
|
|
273
|
+
case "end":
|
|
274
|
+
return _context.stop();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}, _callee);
|
|
278
|
+
})),
|
|
196
279
|
testId: _constants.TID.BUTTON_CANCEL
|
|
197
|
-
}, /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
280
|
+
}, cancelLabel ? cancelLabel : /*#__PURE__*/_react.default.createElement(_intlReact.Trans, {
|
|
198
281
|
id: "common.cancel"
|
|
199
282
|
})), /*#__PURE__*/_react.default.createElement(_componentButton.Button, {
|
|
200
283
|
testId: _constants.TID.BUTTON_NEXT,
|
|
201
284
|
type: "primary",
|
|
202
285
|
disabled: nextDisabled,
|
|
203
286
|
loading: nextLoading,
|
|
204
|
-
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
287
|
+
onClick: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
205
288
|
var res;
|
|
206
|
-
return _regeneratorRuntime().wrap(function
|
|
289
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
207
290
|
while (1) {
|
|
208
|
-
switch (
|
|
291
|
+
switch (_context2.prev = _context2.next) {
|
|
209
292
|
case 0:
|
|
210
293
|
onNextStep && onNextStep(step + 1);
|
|
211
294
|
|
|
212
295
|
if (!nextOnClick) {
|
|
213
|
-
|
|
296
|
+
_context2.next = 8;
|
|
214
297
|
break;
|
|
215
298
|
}
|
|
216
299
|
|
|
217
|
-
|
|
300
|
+
_context2.next = 4;
|
|
218
301
|
return nextOnClick();
|
|
219
302
|
|
|
220
303
|
case 4:
|
|
221
|
-
res =
|
|
304
|
+
res = _context2.sent;
|
|
222
305
|
res && _this2.setState({
|
|
223
306
|
step: step + 1
|
|
224
307
|
});
|
|
225
|
-
|
|
308
|
+
_context2.next = 9;
|
|
226
309
|
break;
|
|
227
310
|
|
|
228
311
|
case 8:
|
|
@@ -232,10 +315,10 @@ var MultistepModal = /*#__PURE__*/function (_React$Component) {
|
|
|
232
315
|
|
|
233
316
|
case 9:
|
|
234
317
|
case "end":
|
|
235
|
-
return
|
|
318
|
+
return _context2.stop();
|
|
236
319
|
}
|
|
237
320
|
}
|
|
238
|
-
},
|
|
321
|
+
}, _callee2);
|
|
239
322
|
}))
|
|
240
323
|
}, nextLabel))))));
|
|
241
324
|
}
|
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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/component-multistep-modal",
|
|
3
3
|
"description": "Multistep modal with a progress bar",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"author": "Vojtech Miksu <vojtech@cloudflare.com>",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@cloudflare/component-box": "^4.0.6",
|
|
17
|
-
"@cloudflare/component-button": "^8.5.
|
|
18
|
-
"@cloudflare/component-modal": "^8.0.
|
|
19
|
-
"@cloudflare/component-progress": "^9.0.
|
|
17
|
+
"@cloudflare/component-button": "^8.5.10",
|
|
18
|
+
"@cloudflare/component-modal": "^8.0.34",
|
|
19
|
+
"@cloudflare/component-progress": "^9.0.39",
|
|
20
20
|
"@cloudflare/component-test-dummy": "^4.0.6",
|
|
21
21
|
"@cloudflare/intl-react": "^1.9.80",
|
|
22
22
|
"prop-types": "^15.6.0"
|
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,39 @@ 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
|
+
if (nextOnClick) {
|
|
189
|
+
const res = await nextOnClick();
|
|
190
|
+
res && this.setState({ step: step + 1 });
|
|
191
|
+
} else {
|
|
192
|
+
this.setState({ step: step + 1 });
|
|
193
|
+
}
|
|
194
|
+
// Go back to the previous Step
|
|
195
|
+
} else if (
|
|
196
|
+
onCancelClickBehaviour === OnCancelClickBehaviour.BACK
|
|
197
|
+
) {
|
|
198
|
+
onPrevStep && onPrevStep(step - 1);
|
|
199
|
+
this.setState({ step: step - 1 });
|
|
200
|
+
} else {
|
|
201
|
+
// Default - close the modal
|
|
202
|
+
onClose();
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
onClose();
|
|
206
|
+
}
|
|
207
|
+
}}
|
|
166
208
|
testId={TID.BUTTON_CANCEL}
|
|
167
209
|
>
|
|
168
|
-
<Trans id="common.cancel" />
|
|
210
|
+
{cancelLabel ? cancelLabel : <Trans id="common.cancel" />}
|
|
169
211
|
</Button>
|
|
170
212
|
)}
|
|
171
213
|
<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
|
}
|