UNPKG

@wener/console

Version:
97 lines (96 loc) 4.09 kB
function _define_property(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _object_spread(target) { for(var i = 1; i < arguments.length; i++){ var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === "function") { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function(key) { _define_property(target, key, source[key]); }); } return target; } function _object_without_properties(source, excluded) { if (source == null) return {}; var target = {}, sourceKeys, key, i; if (typeof Reflect !== "undefined" && Reflect.ownKeys) { sourceKeys = Reflect.ownKeys(source); for(i = 0; i < sourceKeys.length; i++){ key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } return target; } target = _object_without_properties_loose(source, excluded); if (Object.getOwnPropertySymbols) { sourceKeys = Object.getOwnPropertySymbols(source); for(i = 0; i < sourceKeys.length; i++){ key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _object_without_properties_loose(source, excluded) { if (source == null) return {}; var target = {}, sourceKeys = Object.getOwnPropertyNames(source), key, i; for(i = 0; i < sourceKeys.length; i++){ key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } return target; } import React from 'react'; import { ResourceStatusSchema } from '@wener/common/resource/schema'; import { getSchemaOptionLabel } from '@wener/common/schema'; import { cn } from '@wener/console'; export var ResourceStatusBadge = function(_0) { var data = _0.data, _0_status = _0.status, status = _0_status === void 0 ? data === null || data === void 0 ? void 0 : data.status : _0_status, _0_reason = _0.reason, reason = _0_reason === void 0 ? data === null || data === void 0 ? void 0 : data.statusReason : _0_reason, _0_state = _0.state, state = _0_state === void 0 ? data === null || data === void 0 ? void 0 : data.state : _0_state, _0_schema = _0.schema, schema = _0_schema === void 0 ? ResourceStatusSchema : _0_schema, className = _0.className, success = _0.success, warning = _0.warning, error = _0.error, props = _object_without_properties(_0, [ "data", "status", "reason", "state", "schema", "className", "success", "warning", "error" ]); if (!status) { return null; } var classNames = ''; if (success === null || success === void 0 ? void 0 : success.includes(status)) { classNames = 'badge-success'; } else if (warning === null || warning === void 0 ? void 0 : warning.includes(status)) { classNames = 'badge-warning'; } else if (error === null || error === void 0 ? void 0 : error.includes(status)) { classNames = 'badge-error'; } var label = getSchemaOptionLabel(schema, status) || status; return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement("div", _object_spread({ className: cn('badge badge-soft', classNames, className) }, props), label)); };