@carbon/ibm-security
Version:
Carbon for Cloud & Cognitive IBM Security UI components
110 lines (108 loc) • 4.4 kB
JavaScript
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 icon.
* @copyright IBM Security 2019 - 2021
*/
import { Checkmark20 } from '@carbon/icons-react';
import classnames from 'classnames';
import { oneOf, string } from 'prop-types';
import React, { Component } from 'react';
import { getComponentNamespace } from '../../globals/namespace';
import Icon from '../Icon';
import Loading from '../Loading';
export var namespace = getComponentNamespace('status-icon');
var defaultSize = 'md';
var SIZE = ['lg', defaultSize, 'sm'];
var STATUS = ['complete', 'error', 'info', 'success', 'unknown', 'warning'];
/**
* Status icon component.
*/
var StatusIcon = /*#__PURE__*/function (_Component) {
function StatusIcon() {
var _this;
_classCallCheck(this, StatusIcon);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, StatusIcon, [].concat(args));
_defineProperty(_this, "state", {
status: _this.props.status
});
return _this;
}
_inherits(StatusIcon, _Component);
return _createClass(StatusIcon, [{
key: "render",
value: function render() {
var _this$props = this.props,
className = _this$props.className,
message = _this$props.message,
size = _this$props.size,
iconDescription = _this$props.iconDescription;
var status = this.state.status;
var statusIcon;
switch (status) {
case STATUS[0]:
statusIcon = /*#__PURE__*/React.createElement(Icon, {
"aria-label": iconDescription && iconDescription.length ? iconDescription : null,
className: "".concat(namespace, "__icon ").concat(namespace, "__icon--success"),
renderIcon: Checkmark20
});
break;
case undefined:
statusIcon = /*#__PURE__*/React.createElement(Loading, {
"aria-label": iconDescription && iconDescription.length ? iconDescription : null,
className: "".concat(namespace, "__icon"),
withOverlay: false
});
break;
default:
statusIcon = /*#__PURE__*/React.createElement("span", {
"aria-label": iconDescription && iconDescription.length ? iconDescription : null,
className: "".concat(namespace, "__icon--color ").concat(namespace, "__icon--color--").concat(status)
});
}
return /*#__PURE__*/React.createElement("div", {
className: classnames(namespace, className, _defineProperty({}, "".concat(namespace, "--").concat(size), size))
}, statusIcon, message && /*#__PURE__*/React.createElement("span", {
className: " ".concat(namespace, "__message")
}, message));
}
}], [{
key: "getDerivedStateFromProps",
value: function getDerivedStateFromProps(_ref, state) {
var status = _ref.status;
return status && state.status !== status ? {
status: status
} : null;
}
}]);
}(Component);
_defineProperty(StatusIcon, "propTypes", {
/** @type {string} Class name. */
className: string,
/** @type {string} icon aria label. */
iconDescription: string,
/** @type {string} Message. */
message: string,
/** @type {string} Size. */
size: oneOf(SIZE),
/** @type {string} Status. */
status: oneOf(STATUS)
});
_defineProperty(StatusIcon, "defaultProps", {
className: null,
message: null,
size: defaultSize,
status: undefined,
iconDescription: null
});
export { StatusIcon as default };
export { SIZE, STATUS };