@carbon/ibm-security
Version:
Carbon for Cloud & Cognitive IBM Security UI components
97 lines (96 loc) • 4.28 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
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";
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 Status indicator.
* @copyright IBM Security 2019 - 2021
*/
import { Restart20 } from '@carbon/icons-react';
import deprecate from 'carbon-components-react/es/prop-types/deprecate';
import classnames from 'classnames';
import { array, element, func, oneOfType, number, shape, string } from 'prop-types';
import React, { Component } from 'react';
import Button from '../Button';
import { getComponentNamespace } from '../../globals/namespace';
export var namespace = getComponentNamespace('status-indicator');
var StatusIndicator = /*#__PURE__*/function (_Component) {
function StatusIndicator() {
var _this;
_classCallCheck(this, StatusIndicator);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, StatusIndicator, [].concat(args));
_defineProperty(_this, "state", {
retry: _this.props.retry
});
return _this;
}
_inherits(StatusIndicator, _Component);
return _createClass(StatusIndicator, [{
key: "render",
value: function render() {
var _this$props = this.props,
title = _this$props.title,
className = _this$props.className,
currentIndex = _this$props.currentIndex,
children = _this$props.children;
return /*#__PURE__*/React.createElement("div", {
className: classnames(namespace, className)
}, title && /*#__PURE__*/React.createElement("h1", {
className: "".concat(namespace, "__title")
}, title), /*#__PURE__*/React.createElement("ul", _extends({
className: "".concat(namespace, "__list")
}, currentIndex), children, this.state.retry && /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Button, {
className: "".concat(namespace, "__button--retry"),
kind: "ghost",
onClick: this.state.retry.action,
onKeyPress: this.state.retry.action,
renderIcon: Restart20
}, this.state.retry.label))));
}
}], [{
key: "getDerivedStateFromProps",
value: function getDerivedStateFromProps(nextProps, prevState) {
if (prevState.retry !== nextProps.retry) {
return {
retry: nextProps.retry
};
}
return null;
}
}]);
}(Component);
_defineProperty(StatusIndicator, "propTypes", {
/** @type {Array} The array of child elements of the application. */
children: oneOfType([array, element]),
/** @type {string} Extra classes to add. */
className: string,
/** @type {number} The index of the current step. */
currentIndex: number,
/** @type {Record<object, any>} An object list of retry button props. */
retry: shape({
/** @type {func} An action to be re-run in the event of failure. */
action: func,
/** @type {string} The label to be displayed for the retry button. */
label: string,
/** @type {string} The description for the retry button. */
description: deprecate(string, "\nThe prop `retry.description` for StatusIndicator has been deprecated. Please provide a valid `retry.label` instead.")
}),
/** @type {string} A title for the component. */
title: string
});
_defineProperty(StatusIndicator, "defaultProps", {
title: null,
className: '',
currentIndex: 0,
children: null,
retry: null
});
export default StatusIndicator;