examples/09-Wizard.ps1
|
# 09 - Wizard: several steps in one page; the last one closes the window with kHost.close(result), and # Show-NativeWebView returns that result as an object. if (-not (Get-Command Show-NativeWebView -ErrorAction Ignore)) { Import-Module NativeWebView -ErrorAction Stop } $Html = @' <!doctype html> <html><head><style> body { font-family: Verdana, 'Segoe UI', Arial, sans-serif; font-size: 13px; color: #454545; padding: 24px; background: #F9F9F9; } h2 { color: #154363; font-size: 18px; } .step { display: none; } .step.on { display: block; } label { display: block; margin: 10px 0 4px; } input, select { width: 100%; padding: 6px; box-sizing: border-box; border: 1px solid #CCCCCC; font: inherit; } button { margin-top: 18px; padding: 8px 18px; background: #095495; color: white; border: 0; border-radius: 4px; font: inherit; } button:hover { background: #154363; } .dots { color: #CCCCCC; } .dots b { color: #095495; } </style></head> <body> <div class="dots" id="dots"></div> <div class="step on"><h2>1. Site</h2><label>Title <input id="title" value="Sales team"></label></div> <div class="step"><h2>2. Template</h2><label>Template <select id="template"><option>Team site</option><option>Communication site</option></select></label></div> <div class="step"><h2>3. Owners</h2><label>Owner <input id="owner" value="ada@contoso.com"></label></div> <button id="ok">Next</button> <script> var steps = document.querySelectorAll(".step"), at = 0; function show() { steps.forEach(function (s, i) { s.classList.toggle("on", i === at); }); document.getElementById("ok").textContent = at === steps.length - 1 ? "Create" : "Next"; document.getElementById("dots").innerHTML = Array.prototype.map.call(steps, function (s, i) { return i === at ? "<b>●</b>" : "●"; }).join(" "); } document.getElementById("ok").onclick = function () { if (at < steps.length - 1) { at++; show(); return; } kHost.close({ title: document.getElementById("title").value, template: document.getElementById("template").value, owners: [document.getElementById("owner").value] }); }; show(); </script> </body></html> '@ $Site = Show-NativeWebView -Html $Html -Title "New site" -Width 440 -Height 360 -NoResize if ($null -eq $Site) { Write-Host "Cancelled." } else { Write-Host ("Create '" + $Site.title + "' (" + $Site.template + ") owned by " + ($Site.owners -join ", ")) } |