@spaced-out/ui-design-system
Version:
Sense UI components library
248 lines (247 loc) • 8.43 kB
JavaScript
;
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 _qa = require("../../utils/qa");
var _Button = require("../Button");
var _Icon = require("../Icon");
var _Modal = require("../Modal");
var _DialogModule = _interopRequireDefault(require("./Dialog.module.css"));
var _jsxRuntime = require("react/jsx-runtime");
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 DIALOG_SEMANTIC = exports.DIALOG_SEMANTIC = Object.freeze({
neutral: 'neutral',
success: 'success',
information: 'information',
warning: 'warning',
danger: 'danger'
});
const DialogIcon = _ref => {
let {
semantic,
iconName,
testId
} = _ref;
switch (semantic) {
case DIALOG_SEMANTIC.neutral:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
color: _typography.TEXT_COLORS.neutral,
name: iconName ? iconName : 'face-smile',
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
case DIALOG_SEMANTIC.success:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
name: iconName ? iconName : 'circle-check',
color: _typography.TEXT_COLORS.success,
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
case DIALOG_SEMANTIC.information:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
name: iconName ? iconName : 'circle-info',
color: _typography.TEXT_COLORS.information,
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
case DIALOG_SEMANTIC.warning:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
name: iconName ? iconName : 'circle-exclamation',
color: _typography.TEXT_COLORS.warning,
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
case DIALOG_SEMANTIC.danger:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
name: iconName ? iconName : 'shield-exclamation',
color: _typography.TEXT_COLORS.danger,
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
default:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
color: _typography.TEXT_COLORS.neutral,
name: iconName ? iconName : 'face-smile',
type: "solid",
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'icon'
})
});
}
};
const DialogHeader = _ref2 => {
let {
children,
className,
testId
} = _ref2;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: React.Children.count(children) > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classify.default)(_DialogModule.default.dialogHeader, className),
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'header'
}),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: _DialogModule.default.headerContent,
children: children
})
})
});
};
exports.DialogHeader = DialogHeader;
const DialogBody = _ref3 => {
let {
children,
className,
testId
} = _ref3;
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classify.default)(_DialogModule.default.dialogBody, className),
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'body'
}),
children: children
});
};
exports.DialogBody = DialogBody;
const DialogFooter = _ref4 => {
let {
children,
classNames,
testId
} = _ref4;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
children: React.Children.count(children) > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classify.default)(_DialogModule.default.dialogFooter, classNames?.wrapper),
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'footer'
}),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classify.default)(_DialogModule.default.dialogFooterActions, classNames?.actions),
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'actions'
}),
children: children
})
})
});
};
exports.DialogFooter = DialogFooter;
const Dialog = _ref5 => {
let {
children,
isOpen = false,
hideBackdrop = false,
onClose,
tapOutsideToClose = false,
iconName = '',
semantic = 'neutral',
classNames,
testId,
...restDialogProps
} = _ref5;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Modal.Modal, {
isOpen: isOpen,
onClose: onClose,
hideBackdrop: hideBackdrop,
tapOutsideToClose: tapOutsideToClose,
testId: testId,
...restDialogProps,
classNames: {
content: (0, _classify.default)(_DialogModule.default.dialog, classNames?.content),
container: (0, _classify.default)(classNames?.container),
backdrop: (0, _classify.default)(classNames?.backdrop)
},
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: _DialogModule.default.topBlock,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("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
}),
"data-testid": (0, _qa.generateTestId)({
base: testId,
slot: 'icon-container'
}),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DialogIcon, {
semantic: semantic,
iconName: iconName,
testId: testId
})
})
}), children]
});
};
exports.Dialog = Dialog;
const BasicDialog = _ref6 => {
let {
heading,
body,
confirmText,
abortText,
handleConfirm,
handleAbort,
testId,
...restDialogProps
} = _ref6;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Dialog, {
...restDialogProps,
testId: testId,
children: [!!heading && /*#__PURE__*/(0, _jsxRuntime.jsx)(DialogHeader, {
testId: testId,
children: heading
}), !!body && /*#__PURE__*/(0, _jsxRuntime.jsx)(DialogBody, {
testId: testId,
children: body
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(DialogFooter, {
testId: testId,
children: [!!abortText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
isFluid: true,
type: "tertiary",
onClick: handleAbort,
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'abort-button'
}),
children: abortText
}), !!confirmText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
isFluid: true,
onClick: handleConfirm,
testId: (0, _qa.generateTestId)({
base: testId,
slot: 'confirm-button'
}),
children: confirmText
})]
})]
});
};
exports.BasicDialog = BasicDialog;