aws-northstar
Version:
NorthStar Design System
87 lines (83 loc) • 4.07 kB
JavaScript
;
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const CheckCircleOutlineOutlined_1 = __importDefault(require("@material-ui/icons/CheckCircleOutlineOutlined"));
const InfoOutlined_1 = __importDefault(require("@material-ui/icons/InfoOutlined"));
const CancelOutlined_1 = __importDefault(require("@material-ui/icons/CancelOutlined"));
const ReportProblemOutlined_1 = __importDefault(require("@material-ui/icons/ReportProblemOutlined"));
const styles_1 = require("@material-ui/core/styles");
const clsx_1 = __importDefault(require("clsx"));
const Box_1 = __importDefault(require("../../layouts/Box"));
const Text_1 = __importDefault(require("../Text"));
const icons = {
positive: CheckCircleOutlineOutlined_1.default,
negative: CancelOutlined_1.default,
warning: ReportProblemOutlined_1.default,
};
const getIconByStatusType = (statusType, title) => {
var _a;
const IconComponent = (_a = icons[statusType]) !== null && _a !== void 0 ? _a : InfoOutlined_1.default;
return react_1.default.createElement(IconComponent, { fontSize: "small", titleAccess: title });
};
const useStyles = (0, styles_1.makeStyles)((theme) => ({
root: {
display: 'flex',
'& span': {
marginLeft: '2px',
},
},
positive: {
color: theme.palette.success.dark,
},
negative: {
color: theme.palette.warning.dark,
},
info: {
color: theme.palette.info.dark,
},
}));
/**
* A status indicator is a small component that communicates the state of a resource (either in its entirety,
* or a particular facet of a resource) in a compact form that is easily embedded in a card, table, list or header view.
*/
const StatusIndicator = (_a) => {
var { statusType, children } = _a, props = __rest(_a, ["statusType", "children"]);
const styles = useStyles({});
const variantMap = {
positive: styles.positive,
negative: styles.negative,
warning: styles.negative,
info: styles.info,
};
const className = (0, clsx_1.default)(styles.root, variantMap[statusType]);
return (react_1.default.createElement(Box_1.default, { className: className, "data-testid": props['data-testid'] },
getIconByStatusType(statusType, children === null || children === void 0 ? void 0 : children.toString()),
react_1.default.createElement(Text_1.default, null, children)));
};
exports.default = StatusIndicator;