early modal api

typescript
Drake 2 years ago
parent 1878f70dbb
commit 853381b6f7

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -1,5 +1,7 @@
import logger from "./logger";
import modals from "./modals";
export default {
logger
logger,
modals
};

@ -0,0 +1,77 @@
import webpack from "../webpack"
import { React } from "../common"
const { findByProps, findByDisplayName, findByDisplayNameAll } = webpack
const { openModal } = findByProps("openModalLazy")
const Colors = findByProps("button", "colorRed")
const ConfirmModal = findByDisplayName("ConfirmModal")
const Markdown = findByDisplayNameAll("Markdown")[1]
function rawOpenConfirmModal(component, props, insideProps, insideContent) {
if (insideProps === undefined) {
insideProps = {}
}
if (insideContent === undefined) {
insideContent = ""
}
let confirmed;
openModal((e) => {
if (e.transitionState === 3) {
return false //TODO: the fuck does this do?
}
return (
<ConfirmModal
transitionState={e.transitionState}
onClose = {() => confirmed = false}
onCancel = {() => confirmed = false & e.onClose()}
onConfirm = {() => confirmed = true & e.onClose()}
{...props}
>
<component {...insideProps}>{insideContent}</component>
</ConfirmModal>
)
})
while (confirmed === undefined) {
}
return confirmed
}
function openConfirmModal(content, type, opts) {
let buttonColor;
if (!!opts.color) {
buttonColor = opts.color
} else {
switch (type) {
case "danger":
buttonColor = Colors.colorRed
break
case "confirm":
buttonColor = Colors.colorGreen
break
default:
buttonColor = Colors.colorBrandNew
break
}
}
return rawOpenConfirmModal(
Markdown,
{
header: opts.header ?? "Default Modal Header",
confirmText: opts.confirmText ?? "Confirm",
cancelText: opts.cancelText ?? "Cancel",
confirmButtonColor: buttonColor
},
{
editable: false
},
content ?? "Default modal content"
)
}
export default {
rawOpenConfirmModal,
openConfirmModal
}

@ -57,6 +57,9 @@ let webpack = {
findByDisplayName: (prop) => {
return webpack.find((m) => m?.displayName === prop);
},
findByDisplayNameAll: (prop) => {
return webpack.findAll((m) => m?.displayName === prop)
},
findByStrings: (...props) => {
return webpack.find((module) =>
props.every((prop) => module.toString().contains(prop))
@ -68,4 +71,4 @@ let webpack = {
}
};
export default webpack;
export default webpack;
Loading…
Cancel
Save