@veracity/vui
Version:
Veracity UI is a React component library crafted for use within Veracity applications and pages. Based on Styled Components and @xstyled.
69 lines (67 loc) • 1.51 kB
JavaScript
import { useVuiContext } from "../core/vuiProvider/context.js";
import { Box } from "../box/box.js";
import { Input } from "../input/input.js";
import { Dialog } from "./dialog.js";
import { jsx } from "react/jsx-runtime";
//#region src/dialog/useDialog.tsx
const useDialog = () => {
const { setPortalSlot } = useVuiContext();
const showConfirm = (title, message) => new Promise((resolve) => setPortalSlot(/* @__PURE__ */ jsx(Dialog, {
body: message,
cancelButton: {
onClick: () => {
resolve(false);
setPortalSlot(null);
},
text: "Cancel"
},
closeButton: false,
isOpen: true,
submitButton: {
onClick: () => {
resolve(true);
setPortalSlot(null);
},
text: "Confirm"
},
title
})));
const showPrompt = (title, value = "") => new Promise((resolve) => {
let inputValue = value;
setPortalSlot(/* @__PURE__ */ jsx(Dialog, {
body: /* @__PURE__ */ jsx(Box, {
px: 3,
py: 2,
children: /* @__PURE__ */ jsx(Input, {
onChange: (e) => inputValue = e.target.value,
value
})
}),
cancelButton: {
onClick: () => {
resolve(false);
setPortalSlot(null);
},
text: "Cancel"
},
closeButton: false,
isOpen: true,
submitButton: {
onClick: () => {
resolve(inputValue);
setPortalSlot(null);
},
text: "Submit"
},
title
}));
});
return {
showConfirm,
showPrompt
};
};
//#endregion
export { useDialog };
globalThis.__vuiVersion__ = "5.3.1"
//# sourceMappingURL=useDialog.js.map