@carbon/ibm-security
Version:
Carbon for Cloud & Cognitive IBM Security UI components
87 lines • 4 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _WizardStep;
import _regeneratorRuntime from "@babel/runtime/regenerator";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/**
* @file WizardStep.
* @copyright IBM Security 2019, 2021
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
var WizardStep = /*#__PURE__*/function (_Component) {
function WizardStep() {
_classCallCheck(this, WizardStep);
return _callSuper(this, WizardStep, arguments);
}
_inherits(WizardStep, _Component);
return _createClass(WizardStep, [{
key: "render",
value: function render() {
var _this$props = this.props,
title = _this$props.title,
renderMain = _this$props.renderMain,
next = _this$props.next,
validate = _this$props.validate;
return null && {
title: title,
renderMain: renderMain,
next: next,
validate: validate
};
}
}]);
}(Component);
_WizardStep = WizardStep;
_defineProperty(WizardStep, "getPropsFromElement", function (stepElem) {
if (! /*#__PURE__*/React.isValidElement(stepElem) && stepElem.type !== _WizardStep) {
return null;
}
return stepElem.props;
});
WizardStep.propTypes = {
/** @type {function(state: Object): Promise} this is called after each step. You can do async work here or save your changes
* depending on whether you are using a sequential wizard or not. */
next: PropTypes.func,
/** @type {function(state: Object, setState: function(changes: Object)): boolean} render function for the contents of the step.
* use setState to shallow merge the state with the changes object supplied to setState (just like in react) */
renderMain: PropTypes.func,
/** @type {string} The title of the step. */
title: PropTypes.string.isRequired,
/** @type {function(state: Object): boolean} Pure and synchronous predicate function to validate the wizard's state against the current step, occuring after every state change (for example, every user keystroke). This should not be used as a hook to trigger any side effects, nor allow the return value to depend on anything else other than the argument. When it returns `true`, parts of the wizard (buttons, navigation, etc.) become active. */
validate: PropTypes.func
};
WizardStep.defaultProps = {
// eslint-disable-next-line no-unused-vars, react/display-name
renderMain: function renderMain(state, setState) {
return /*#__PURE__*/React.createElement("div", null);
},
// eslint-disable-next-line no-unused-vars
validate: function validate(state) {
return true;
},
next: function () {
var _next = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(state) {
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
return _context.abrupt("return", state);
case 1:
case "end":
return _context.stop();
}
}, _callee);
}));
function next(_x) {
return _next.apply(this, arguments);
}
return next;
}()
};
export default WizardStep;