UNPKG

nishant-design-system

Version:
141 lines (140 loc) 6.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DialogHeader = exports.DialogFooter = exports.DialogBody = exports.Dialog = exports.DIALOG_SEMANTIC = void 0; var React = _interopRequireWildcard(require("react")); var _typography = require("../../types/typography"); var _classify = _interopRequireDefault(require("../../utils/classify")); var _Icon = require("../Icon"); var _Modal = require("../Modal"); var _DialogModule = _interopRequireDefault(require("./Dialog.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; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } const DIALOG_SEMANTIC = Object.freeze({ neutral: 'neutral', success: 'success', information: 'information', warning: 'warning', danger: 'danger' }); exports.DIALOG_SEMANTIC = DIALOG_SEMANTIC; const DialogIcon = _ref => { let { semantic, iconName } = _ref; switch (semantic) { case DIALOG_SEMANTIC.neutral: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: iconName ? iconName : 'face-smile', type: "solid" }); case DIALOG_SEMANTIC.success: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: iconName ? iconName : 'circle-check', color: _typography.TEXT_COLORS.success, type: "solid" }); case DIALOG_SEMANTIC.information: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: iconName ? iconName : 'circle-info', color: _typography.TEXT_COLORS.information, type: "solid" }); case DIALOG_SEMANTIC.warning: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: iconName ? iconName : 'circle-exclamation', color: _typography.TEXT_COLORS.warning, type: "solid" }); case DIALOG_SEMANTIC.danger: return /*#__PURE__*/React.createElement(_Icon.Icon, { name: iconName ? iconName : 'shield-exclamation', color: _typography.TEXT_COLORS.danger, type: "solid" }); default: return /*#__PURE__*/React.createElement(_Icon.Icon, { color: _typography.TEXT_COLORS.neutral, name: iconName ? iconName : 'face-smile', type: "solid" }); } }; const DialogHeader = _ref2 => { let { children, className } = _ref2; return /*#__PURE__*/React.createElement(React.Fragment, null, React.Children.count(children) > 0 && /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_DialogModule.default.dialogHeader, className) }, /*#__PURE__*/React.createElement("div", { className: _DialogModule.default.headerContent }, children))); }; exports.DialogHeader = DialogHeader; const DialogBody = _ref3 => { let { children, className } = _ref3; return /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_DialogModule.default.dialogBody, className) }, children); }; exports.DialogBody = DialogBody; const DialogFooter = _ref4 => { let { children, classNames } = _ref4; return /*#__PURE__*/React.createElement(React.Fragment, null, React.Children.count(children) > 0 && /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_DialogModule.default.dialogFooter, classNames?.wrapper) }, /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_DialogModule.default.dialogFooterActions, classNames?.actions) }, children))); }; exports.DialogFooter = DialogFooter; const Dialog = _ref5 => { let { children, isOpen = false, hideBackdrop = false, onClose, tapOutsideToClose = false, iconName = '', semantic = 'neutral', classNames, ...restDialogProps } = _ref5; return /*#__PURE__*/React.createElement(_Modal.Modal, _extends({ isOpen: isOpen, onClose: onClose, hideBackdrop: hideBackdrop, tapOutsideToClose: tapOutsideToClose }, restDialogProps, { classNames: { content: (0, _classify.default)(_DialogModule.default.dialog, classNames?.content), container: (0, _classify.default)(classNames?.container), backdrop: (0, _classify.default)(classNames?.backdrop) } }), /*#__PURE__*/React.createElement("div", { className: _DialogModule.default.topBlock }, /*#__PURE__*/React.createElement("div", { className: (0, _classify.default)(_DialogModule.default.iconContainer, { [_DialogModule.default.neutral]: semantic === DIALOG_SEMANTIC.neutral, [_DialogModule.default.success]: semantic === DIALOG_SEMANTIC.success, [_DialogModule.default.information]: semantic === DIALOG_SEMANTIC.information, [_DialogModule.default.warning]: semantic === DIALOG_SEMANTIC.warning, [_DialogModule.default.danger]: semantic === DIALOG_SEMANTIC.danger }) }, /*#__PURE__*/React.createElement(DialogIcon, { semantic: semantic, iconName: iconName }))), children); }; exports.Dialog = Dialog;