(message, inputs, help)
| 32 | * @returns {Promise<Strings>} |
| 33 | */ |
| 34 | export default function multiPrompt(message, inputs, help) { |
| 35 | return new Promise((resolve, reject) => { |
| 36 | const $title = tag("div", { |
| 37 | className: "title", |
| 38 | child: tag("span", { |
| 39 | textContent: message, |
| 40 | }), |
| 41 | style: { |
| 42 | justifyContent: "space-between", |
| 43 | }, |
| 44 | }); |
| 45 | const $body = tag("div", { |
| 46 | className: "message scroll", |
| 47 | style: { |
| 48 | fontSize: "1rem", |
| 49 | }, |
| 50 | }); |
| 51 | const okBtn = tag("button", { |
| 52 | type: "submit", |
| 53 | textContent: strings.ok, |
| 54 | onclick: function (e) { |
| 55 | e.preventDefault(); |
| 56 | e.stopPropagation(); |
| 57 | const inputAr = [...$body.getAll("input")]; |
| 58 | |
| 59 | for (let $input of inputAr) { |
| 60 | if ($input.isRequired && !$input.value) { |
| 61 | $errorMessage.textContent = strings.required.capitalize(); |
| 62 | const $sibling = $input.nextElementSibling; |
| 63 | const $parent = $input.parentElement; |
| 64 | if ($sibling) $parent.insertBefore($errorMessage, $sibling); |
| 65 | else $parent.append($errorMessage); |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | hide(); |
| 70 | resolve(getValue()); |
| 71 | }, |
| 72 | }); |
| 73 | const cancelBtn = tag("button", { |
| 74 | textContent: strings.cancel, |
| 75 | type: "button", |
| 76 | onclick: function () { |
| 77 | reject(); |
| 78 | hide(); |
| 79 | }, |
| 80 | }); |
| 81 | const $errorMessage = ( |
| 82 | <span className="error-msg" style={{ display: "block" }} /> |
| 83 | ); |
| 84 | const $mask = <span className="mask" />; |
| 85 | const $promptDiv = tag("form", { |
| 86 | action: "#", |
| 87 | className: "prompt multi", |
| 88 | onsubmit: (e) => { |
| 89 | e.preventDefault(); |
| 90 | if (!okBtn.disabled) { |
| 91 | resolve(getValue()); |
no test coverage detected