nishant-design-system
Version:
Sense UI components library
86 lines (83 loc) • 4.12 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Notification = exports.NOTIFICATION_SEMANTIC = void 0;
var React = _interopRequireWildcard(require("react"));
var _typography = require("../../types/typography");
var _classify = require("../../utils/classify");
var _Icon = require("../Icon");
var _Text = require("../Text");
var _NotificationModule = _interopRequireDefault(require("./Notification.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 NOTIFICATION_SEMANTIC = Object.freeze({
success: 'success',
information: 'information',
danger: 'danger'
});
exports.NOTIFICATION_SEMANTIC = NOTIFICATION_SEMANTIC;
// Base Notification will not have any state.
const BaseNotification = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
classNames,
semantic = NOTIFICATION_SEMANTIC.success,
iconLeftName,
iconLeftType = 'regular',
dismissable,
children,
onCloseClick
} = props;
return /*#__PURE__*/React.createElement("div", {
className: (0, _classify.classify)(_NotificationModule.default.baseContainer, {
[_NotificationModule.default.success]: semantic === NOTIFICATION_SEMANTIC.success,
[_NotificationModule.default.information]: semantic === NOTIFICATION_SEMANTIC.information,
[_NotificationModule.default.danger]: semantic === NOTIFICATION_SEMANTIC.danger,
[_NotificationModule.default.dismissable]: dismissable
}, classNames?.wrapper),
ref: ref
}, iconLeftName ? /*#__PURE__*/React.createElement(_Icon.Icon, {
name: iconLeftName,
color: _typography.TEXT_COLORS.inversePrimary,
size: "small",
type: iconLeftType
}) : null, /*#__PURE__*/React.createElement(_Text.SubTitleSmall, {
className: (0, _classify.classify)(classNames?.text),
color: _typography.TEXT_COLORS.inversePrimary
}, children), dismissable && /*#__PURE__*/React.createElement(_Icon.Icon, {
color: _typography.TEXT_COLORS.inversePrimary,
name: "close",
size: "small",
type: "regular",
onClick: onCloseClick,
className: _NotificationModule.default.closeIcon
}));
});
const Notification = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
classNames,
semantic = NOTIFICATION_SEMANTIC.success,
iconLeftName,
iconLeftType,
dismissable,
children,
selfDismiss = false,
onCloseClick
} = 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(BaseNotification, {
classNames: classNames,
iconLeftName: iconLeftName,
iconLeftType: iconLeftType,
semantic: semantic,
dismissable: dismissable,
onCloseClick: closeClickHandler,
ref: ref
}, children));
});
exports.Notification = Notification;