UNPKG

nishant-design-system

Version:
127 lines (125 loc) 5.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InContextAlert = exports.ALERT_SEMANTIC = void 0; var React = _interopRequireWildcard(require("react")); 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(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } const ALERT_SEMANTIC = Object.freeze({ neutral: 'neutral', success: 'success', information: 'information', warning: 'warning', danger: 'danger' }); exports.ALERT_SEMANTIC = ALERT_SEMANTIC; const AlertIcon = _ref => { let { semantic, leftIconName, leftIconType } = _ref; switch (semantic) { case ALERT_SEMANTIC.neutral: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: leftIconName ? leftIconName : 'face-smile', size: "small", type: leftIconType }); case ALERT_SEMANTIC.success: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-check', size: "small", color: _typography.TEXT_COLORS.success, type: leftIconType }); case ALERT_SEMANTIC.information: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-info', size: "small", color: _typography.TEXT_COLORS.information, type: leftIconType }); case ALERT_SEMANTIC.warning: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'circle-exclamation', size: "small", color: _typography.TEXT_COLORS.warning, type: leftIconType }); case ALERT_SEMANTIC.danger: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: leftIconName ? leftIconName : 'shield-exclamation', size: "small", color: _typography.TEXT_COLORS.danger, type: leftIconType }); default: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: leftIconName ? leftIconName : 'face-smile', size: "small", type: leftIconType }); } }; const InContextAlert = /*#__PURE__*/React.forwardRef((props, ref) => { const { classNames, semantic = 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 === ALERT_SEMANTIC.neutral, [_InContextAlertModule.default.success]: semantic === ALERT_SEMANTIC.success, [_InContextAlertModule.default.information]: semantic === ALERT_SEMANTIC.information, [_InContextAlertModule.default.warning]: semantic === ALERT_SEMANTIC.warning, [_InContextAlertModule.default.danger]: semantic === ALERT_SEMANTIC.danger }, classNames?.wrapper), ref: ref }, /*#__PURE__*/React.createElement(AlertIcon, { semantic: semantic, leftIconName: leftIconName, leftIconType: leftIconType }), React.Children.count(children) > 0 && /*#__PURE__*/React.createElement(_Text.SubTitleExtraSmall, { className: (0, _classify.classify)(classNames?.alertText) }, /*#__PURE__*/React.createElement(_Truncate.Truncate, { line: 2 }, 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, name: "close", size: "small", type: "regular", onClick: closeClickHandler, className: _InContextAlertModule.default.closeIcon })))); }); exports.InContextAlert = InContextAlert;