UNPKG

@spaced-out/ui-design-system

Version:
127 lines (126 loc) 5.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InContextAlert = void 0; var React = _interopRequireWildcard(require("react")); var _common = require("../../types/common"); var _typography = require("../../types/typography"); var _classify = require("../../utils/classify"); var _Icon = require("../Icon"); var _Link = require("../Link"); var _Text = require("../Text"); var _Truncate = require("../Truncate"); var _InContextAlertModule = _interopRequireDefault(require("./InContextAlert.module.css")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const AlertIcon = _ref => { let { semantic, leftIconName, leftIconType, iconClassName } = _ref; switch (semantic) { case _common.ALERT_SEMANTIC.neutral: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: leftIconName ? leftIconName : 'face-smile', size: "small", type: leftIconType, className: iconClassName }); case _common.ALERT_SEMANTIC.success: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-check', size: "small", color: _typography.TEXT_COLORS.success, type: leftIconType, className: iconClassName }); case _common.ALERT_SEMANTIC.information: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-info', size: "small", color: _typography.TEXT_COLORS.information, type: leftIconType, className: iconClassName }); case _common.ALERT_SEMANTIC.warning: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-exclamation', size: "small", color: _typography.TEXT_COLORS.warning, type: leftIconType, className: iconClassName }); case _common.ALERT_SEMANTIC.danger: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'shield-exclamation', size: "small", color: _typography.TEXT_COLORS.danger, type: leftIconType, className: iconClassName }); default: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: leftIconName ? leftIconName : 'face-smile', size: "small", type: leftIconType, className: iconClassName }); } }; const InContextAlert = exports.InContextAlert = /*#__PURE__*/React.forwardRef((props, ref) => { const { classNames, semantic = _common.ALERT_SEMANTIC.neutral, dismissable, children, selfDismiss = false, leftIconName = '', onCloseClick, actionText = '', onAction, leftIconType } = props; const [dismissed, setDismissed] = React.useState(false); const closeClickHandler = e => { onCloseClick && onCloseClick(e); selfDismiss && setDismissed(true); }; return /*#__PURE__*/React.createElement(React.Fragment, null, !dismissed && /*#__PURE__*/React.createElement("div", { className: (0, _classify.classify)(_InContextAlertModule.default.alertContainer, { [_InContextAlertModule.default.neutral]: semantic === _common.ALERT_SEMANTIC.neutral, [_InContextAlertModule.default.success]: semantic === _common.ALERT_SEMANTIC.success, [_InContextAlertModule.default.information]: semantic === _common.ALERT_SEMANTIC.information, [_InContextAlertModule.default.warning]: semantic === _common.ALERT_SEMANTIC.warning, [_InContextAlertModule.default.danger]: semantic === _common.ALERT_SEMANTIC.danger }, classNames?.wrapper), ref: ref }, /*#__PURE__*/React.createElement(AlertIcon, { semantic: semantic, leftIconName: leftIconName, leftIconType: leftIconType, iconClassName: classNames?.icon }), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement(_Text.SubTitleExtraSmall, { className: (0, _classify.classify)(classNames?.alertText) }, /*#__PURE__*/React.createElement(_Truncate.Truncate, { line: 2, wordBreak: "initial" }, children)), !!(actionText || dismissable) && /*#__PURE__*/React.createElement("div", { className: (0, _classify.classify)(_InContextAlertModule.default.actionContainer, classNames?.actionContainer) }, !!actionText && /*#__PURE__*/React.createElement(_Link.Link, { onClick: onAction, color: "primary" }, actionText), !!dismissable && /*#__PURE__*/React.createElement(_Icon.ClickableIcon, { color: _typography.TEXT_COLORS.primary, ariaLabel: "close", name: "close", size: "small", type: "regular", onClick: closeClickHandler, className: _InContextAlertModule.default.closeIcon })))); });