mirror of
https://github.com/Shu-Ying/noname-shuying.git
synced 2026-11-23 21:50:01 +08:00
fixed # 更改休息处和商店的样式
This commit is contained in:
+25
-20
@@ -2,12 +2,34 @@ import { ui } from "../../../../noname.js";
|
||||
import { mountMenu } from "./navigation.js";
|
||||
import { createRelicIcon } from "./relic-icon.js";
|
||||
|
||||
export const chooseButtons = (title, choices, description = "", options = {}) => new Promise(resolve => {
|
||||
export const chooseFlow = (title, render, { back } = {}) => new Promise(resolve => {
|
||||
const previousFocus = document.activeElement;
|
||||
const overlay = ui.create.div(".mengsan-overlay-shuying.mengsan-flow-overlay-shuying", ui.window);
|
||||
overlay.setAttribute("role", "dialog");
|
||||
overlay.setAttribute("aria-modal", "true");
|
||||
overlay.setAttribute("aria-label", title);
|
||||
const finish = id => {
|
||||
if (overlay.dataset.resolved) return;
|
||||
overlay.dataset.resolved = "true";
|
||||
overlay.remove();
|
||||
if (previousFocus?.isConnected) previousFocus.focus();
|
||||
resolve(id);
|
||||
};
|
||||
const initialFocus = render(overlay, finish);
|
||||
overlay.addEventListener("keydown", event => {
|
||||
if (event.key === "Escape" && back) {
|
||||
event.preventDefault(); finish(back); return;
|
||||
}
|
||||
if (event.key !== "Tab") return;
|
||||
const focusable = [...overlay.querySelectorAll("button:not(:disabled)")];
|
||||
const first = focusable[0], last = focusable[focusable.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
||||
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
||||
});
|
||||
initialFocus?.focus();
|
||||
});
|
||||
|
||||
export const chooseButtons = (title, choices, description = "", options = {}) => chooseFlow(title, (overlay, finish) => {
|
||||
const panel = ui.create.div(".mengsan-panel-shuying.mengsan-flow-panel-shuying", overlay);
|
||||
const eyebrow = document.createElement("p");
|
||||
eyebrow.className = "mengsan-flow-eyebrow-shuying";
|
||||
@@ -22,13 +44,6 @@ export const chooseButtons = (title, choices, description = "", options = {}) =>
|
||||
summary.textContent = description;
|
||||
}
|
||||
const buttons = ui.create.div(".mengsan-choice-list-shuying", panel);
|
||||
const finish = id => {
|
||||
if (overlay.dataset.resolved) return;
|
||||
overlay.dataset.resolved = "true";
|
||||
overlay.remove();
|
||||
if (previousFocus?.isConnected) previousFocus.focus();
|
||||
resolve(id);
|
||||
};
|
||||
choices.forEach(choice => {
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
@@ -51,15 +66,5 @@ export const chooseButtons = (title, choices, description = "", options = {}) =>
|
||||
buttons.appendChild(button);
|
||||
});
|
||||
if (options.menu !== false) mountMenu(overlay);
|
||||
overlay.addEventListener("keydown", event => {
|
||||
if (event.key === "Escape" && options.back) {
|
||||
event.preventDefault(); finish(options.back); return;
|
||||
}
|
||||
if (event.key !== "Tab") return;
|
||||
const focusable = [...overlay.querySelectorAll("button:not(:disabled)")];
|
||||
const first = focusable[0], last = focusable[focusable.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); }
|
||||
else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); }
|
||||
});
|
||||
buttons.querySelector("button:not(:disabled)")?.focus();
|
||||
});
|
||||
return buttons.querySelector("button:not(:disabled)");
|
||||
}, options);
|
||||
|
||||
Reference in New Issue
Block a user