UNPKG

@spaced-out/ui-design-system

Version:
160 lines (159 loc) 6.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DialogHeader = exports.DialogFooter = exports.DialogBody = exports.Dialog = exports.DIALOG_SEMANTIC = exports.BasicDialog = void 0; var React = _interopRequireWildcard(require("react")); var _typography = require("../../types/typography"); var _classify = _interopRequireDefault(require("../../utils/classify")); var _Button = require("../Button"); var _Icon = require("../Icon"); var _Modal = require("../Modal"); var _DialogModule = _interopRequireDefault(require("./Dialog.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); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const DIALOG_SEMANTIC = exports.DIALOG_SEMANTIC = Object.freeze({ neutral: 'neutral', success: 'success', information: 'information', warning: 'warning', danger: 'danger' }); 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; const BasicDialog = _ref6 => { let { heading, body, confirmText, abortText, handleConfirm, handleAbort, ...restDialogProps } = _ref6; return /*#__PURE__*/React.createElement(Dialog, restDialogProps, !!heading && /*#__PURE__*/React.createElement(DialogHeader, null, heading), !!body && /*#__PURE__*/React.createElement(DialogBody, null, body), /*#__PURE__*/React.createElement(DialogFooter, null, !!abortText && /*#__PURE__*/React.createElement(_Button.Button, { isFluid: true, type: "tertiary", onClick: handleAbort }, abortText), !!confirmText && /*#__PURE__*/React.createElement(_Button.Button, { isFluid: true, onClick: handleConfirm }, confirmText))); }; exports.BasicDialog = BasicDialog;