@jengaui/alert-dialog
Version:
Jenga UI Alert Dialog component in React
17 lines (12 loc) • 2.53 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var portal = require('@jengaui/portal');
var dialog = require('@jengaui/dialog');
var react = require('react');
var button = require('@jengaui/button');
var buttonGroup = require('@jengaui/button-group');
var content = require('@jengaui/content');
var utils = require('@react-aria/utils');
var jsxRuntime = require('react/jsx-runtime');
var N={label:"Ok",type:"primary"},Z={label:"Cancel"};function v(u,g){let{onClose:t}=dialog.useDialogContext(),{danger:m,actions:l,title:c,styles:p,noActions:D,content:i,...d}=u,{confirm:e,secondary:r,cancel:n}=l??{};return e=e!==!1?{...N,...typeof e=="object"?e:null}:void 0,n=n?{...Z,...typeof n=="object"?n:null}:void 0,jsxRuntime.jsxs(dialog.Dialog,{ref:g,role:"alertdialog",isDismissable:!1,...d,children:[c?jsxRuntime.jsx(content.Header,{children:jsxRuntime.jsx(content.Title,{children:c})}):null,i?jsxRuntime.jsx(content.Content,{children:typeof i=="string"?jsxRuntime.jsx(content.Paragraph,{children:i}):i}):null,D?null:jsxRuntime.jsx(content.Footer,{children:jsxRuntime.jsxs(buttonGroup.ButtonGroup,{align:"end",children:[jsxRuntime.jsx(button.Button,{autoFocus:!0,theme:m?"danger":void 0,...e,onPress:a=>{var o;return utils.chain((o=e==null?void 0:e.onPress)==null?void 0:o.call(e,a),t==null?void 0:t("confirm"))}}),r&&jsxRuntime.jsx(button.Button,{...r,onPress:a=>{var o;return utils.chain((o=r==null?void 0:r.onPress)==null?void 0:o.call(r,a),t==null?void 0:t("secondary"))}}),n&&jsxRuntime.jsx(button.Button,{...n,onPress:a=>{var o;return utils.chain((o=n==null?void 0:n.onPress)==null?void 0:o.call(n,a),t==null?void 0:t("cancel"))}})]})})]})}var B=react.forwardRef(v);var R="AlertDialogZone";function oo(u){let{openedDialog:g}=u;if(g===null)return jsxRuntime.jsx(portal.Portal,{},R);let{type:t,isDismissable:m=!0,actions:l,onDismiss:c,content:p,...D}=g.props,{resolve:i,reject:d,isVisible:e,dialogType:r}=g.meta,n=(()=>{let a=(o,y)=>{if(typeof o>"u")return;if(typeof o=="boolean")return o?{onPress:()=>i(y)}:!1;let P=o.onPress;return {...o,onPress:O=>{P==null||P(O),i(y);}}};return typeof l>"u"?{}:{confirm:a(l.confirm,"confirm"),secondary:a(l.secondary,"secondary"),cancel:a(l.cancel,"cancel")}})();return jsxRuntime.jsx(portal.Portal,{children:jsxRuntime.jsx(dialog.DialogContainer,{isOpen:e,isDismissable:m,type:t,onDismiss:c,children:jsxRuntime.jsx(B,{noActions:r==="form",actions:n,isHidden:!e,content:typeof p=="function"?p({resolve:i,reject:d}):p,...D})})},R)}
exports.AlertDialogZone = oo;