mirror of
https://github.com/simonw/datasette.git
synced 2026-09-27 04:14:25 +02:00
Screenshots for reusable modal dialogs docs, plus just shots (#2958)
docs/shots.yml defines documentation screenshots for shot-scraper "Just shots" runs them.
This commit is contained in:
parent
8e17729ff3
commit
cec5e6b2ef
9 changed files with 157 additions and 41 deletions
38
docs/shots/modal-example.js
Normal file
38
docs/shots/modal-example.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
document.addEventListener("datasette_init", () => {
|
||||
const openButton = document.createElement("button");
|
||||
openButton.type = "button";
|
||||
openButton.textContent = "Open example dialog";
|
||||
// Indicate that this button opens a dialog:
|
||||
openButton.setAttribute("aria-haspopup", "dialog");
|
||||
// Identify which dialog it controls:
|
||||
openButton.setAttribute("aria-controls", "my-plugin-dialog");
|
||||
|
||||
const modal = DatasetteModal.create();
|
||||
const dialog = modal.dialog;
|
||||
dialog.id = "my-plugin-dialog";
|
||||
// Tell screenreaders the dialog is labelled by #my-plugin-dialog-title
|
||||
dialog.setAttribute("aria-labelledby", "my-plugin-dialog-title");
|
||||
dialog.innerHTML = `
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title" id="my-plugin-dialog-title">
|
||||
Example dialog
|
||||
</h2>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
This dialog uses Datasette's shared styles and keyboard behavior.
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="modal-btn modal-btn-ghost">Close</button>
|
||||
</div>`;
|
||||
|
||||
const closeButton = dialog.querySelector("button");
|
||||
closeButton.addEventListener("click", () => {
|
||||
modal.requestClose("cancel");
|
||||
});
|
||||
openButton.addEventListener("click", () => {
|
||||
modal.show({ returnFocusTo: openButton, initialFocus: closeButton });
|
||||
});
|
||||
|
||||
document.body.append(modal);
|
||||
document.querySelector("section.content").append(openButton);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue