|
1 | 1 | async function prompt(
|
2 |
| - heading, |
3 |
| - body, |
4 |
| - buttons = ["Cancel", "Ok"], |
5 |
| - options = { title: heading, size: { width: 360, height: 280 } } |
| 2 | + heading, |
| 3 | + body, |
| 4 | + buttons = ['Cancel', 'Ok'], |
| 5 | + options = { title: heading, size: { width: 360, height: 280 } } |
6 | 6 | ) {
|
7 |
| - const [dlgEl, formEl, headingEl, dividerEl, bodyEl, footerEl] = [ |
8 |
| - "dialog", |
9 |
| - "form", |
10 |
| - "sp-heading", |
11 |
| - "sp-divider", |
12 |
| - "sp-body", |
13 |
| - "footer", |
14 |
| - ].map((tag) => document.createElement(tag)) |
15 |
| - ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => { |
16 |
| - el.style.margin = "6px" |
17 |
| - el.style.width = "calc(100% - 12px)" |
18 |
| - }) |
| 7 | + const [dlgEl, formEl, headingEl, dividerEl, bodyEl, footerEl] = [ |
| 8 | + 'dialog', |
| 9 | + 'form', |
| 10 | + 'sp-heading', |
| 11 | + 'sp-divider', |
| 12 | + 'sp-body', |
| 13 | + 'footer', |
| 14 | + ].map((tag) => document.createElement(tag)) |
| 15 | + ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => { |
| 16 | + el.style.margin = '6px' |
| 17 | + el.style.width = 'calc(100% - 12px)' |
| 18 | + }) |
19 | 19 |
|
20 |
| - formEl.setAttribute("method", "dialog") |
21 |
| - formEl.addEventListener("submit", () => dlgEl.close()) |
| 20 | + formEl.setAttribute('method', 'dialog') |
| 21 | + formEl.addEventListener('submit', () => dlgEl.close()) |
22 | 22 |
|
23 |
| - footerEl.style.marginTop = "26px" |
| 23 | + footerEl.style.marginTop = '26px' |
24 | 24 |
|
25 |
| - dividerEl.setAttribute("size", "large") |
| 25 | + dividerEl.setAttribute('size', 'large') |
26 | 26 |
|
27 |
| - headingEl.textContent = heading |
| 27 | + headingEl.textContent = heading |
28 | 28 |
|
29 |
| - bodyEl.textContent = body |
| 29 | + bodyEl.textContent = body |
30 | 30 |
|
31 |
| - buttons.forEach((btnText, idx) => { |
32 |
| - const btnEl = document.createElement("sp-button") |
33 |
| - btnEl.setAttribute( |
34 |
| - "variant", |
35 |
| - idx === buttons.length - 1 ? btnText.variant || "cta" : "secondary" |
| 31 | + buttons.forEach((btnText, idx) => { |
| 32 | + const btnEl = document.createElement('sp-button') |
| 33 | + btnEl.setAttribute( |
| 34 | + 'variant', |
| 35 | + idx === buttons.length - 1 ? btnText.variant || 'cta' : 'secondary' |
| 36 | + ) |
| 37 | + if (idx === buttons.length - 1) |
| 38 | + btnEl.setAttribute('autofocus', 'autofocus') |
| 39 | + if (idx < buttons.length - 1) btnEl.setAttribute('quiet') |
| 40 | + btnEl.textContent = btnText.text || btnText |
| 41 | + btnEl.style.marginLeft = '12px' |
| 42 | + btnEl.addEventListener('click', () => |
| 43 | + dlgEl.close(btnText.text || btnText) |
| 44 | + ) |
| 45 | + footerEl.appendChild(btnEl) |
| 46 | + }) |
| 47 | + ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => |
| 48 | + formEl.appendChild(el) |
36 | 49 | )
|
37 |
| - if (idx === buttons.length - 1) btnEl.setAttribute("autofocus", "autofocus") |
38 |
| - if (idx < buttons.length - 1) btnEl.setAttribute("quiet") |
39 |
| - btnEl.textContent = btnText.text || btnText |
40 |
| - btnEl.style.marginLeft = "12px" |
41 |
| - btnEl.addEventListener("click", () => dlgEl.close(btnText.text || btnText)) |
42 |
| - footerEl.appendChild(btnEl) |
43 |
| - }) |
44 |
| - ;[headingEl, dividerEl, bodyEl, footerEl].forEach((el) => |
45 |
| - formEl.appendChild(el) |
46 |
| - ) |
47 |
| - dlgEl.appendChild(formEl) |
48 |
| - document.body.appendChild(dlgEl) |
| 50 | + dlgEl.appendChild(formEl) |
| 51 | + document.body.appendChild(dlgEl) |
49 | 52 |
|
50 |
| - return dlgEl.uxpShowModal(options) |
| 53 | + return dlgEl.uxpShowModal(options) |
51 | 54 | }
|
52 | 55 |
|
53 | 56 | // const r1 = await prompt(
|
|
0 commit comments