diff --git a/tracker/tracker-assist/src/Confirm.ts b/tracker/tracker-assist/src/Confirm.ts new file mode 100644 index 000000000..a7da63abd --- /dev/null +++ b/tracker/tracker-assist/src/Confirm.ts @@ -0,0 +1,91 @@ + +const declineIcon = ``; + +export default class Confirm { + private wrapper: HTMLDivElement; + + constructor(text: string, styles?: Object) { + const wrapper = document.createElement('div'); + const popup = document.createElement('div'); + const p = document.createElement('p'); + p.innerText = text; + const buttons = document.createElement('div'); + const answerBtn = document.createElement('button'); + answerBtn.innerHTML = declineIcon.replace('fill="#ef5261"', 'fill="green"'); + const declineBtn = document.createElement('button'); + declineBtn.innerHTML = declineIcon; + buttons.appendChild(answerBtn); + buttons.appendChild(declineBtn); + popup.appendChild(p); + popup.appendChild(buttons); + + const btnStyles = { + borderRadius: "50%", + width: "20px", + height: "20px", + background: "transparent", + padding: 0, + margin: 0, + border: 0, + cursor: "pointer", + } + Object.assign(answerBtn.style, btnStyles); + Object.assign(declineBtn.style, btnStyles); + Object.assign(buttons.style, { + display: "flex", + alignItems: "center", + justifyContent: "space-evenly", + }); + + Object.assign(popup.style, { + position: "relative", + pointerEvents: "auto", + margin: "4em auto", + width: "90%", + maxWidth: "400px", + padding: "25px 30px", + background: "black", + opacity: ".75", + color: "white", + textAlign: "center", + borderRadius: ".25em .25em .4em .4em", + boxShadow: "0 0 20px rgb(0 0 0 / 20%)", + }, styles); + + Object.assign(wrapper.style, { + position: "fixed", + left: 0, + top: 0, + height: "100%", + width: "100%", + pointerEvents: "none", + zIndex: 2147483647 - 1, + }) + + wrapper.appendChild(popup); + this.wrapper = wrapper; + + answerBtn.onclick = () => { + this.remove(); + this.callback(true); + } + declineBtn.onclick = () => { + this.remove(); + this.callback(false); + } + } + + mount() { + document.body.appendChild(this.wrapper); + } + + private callback: (result: boolean) => void = ()=>{}; + onAnswer(callback: (result: boolean) => void) { + this.callback = callback; + } + + remove() { + if (!this.wrapper.parentElement) { return; } + document.body.removeChild(this.wrapper); + } +}