Refine toolbox navigation and local data controls
All checks were successful
Deploy Sokko G / deploy (push) Successful in 20s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 20s
This commit is contained in:
parent
954240adf9
commit
2f2e79d200
27 changed files with 614 additions and 302 deletions
|
|
@ -1,12 +1,25 @@
|
|||
// Rôle : encapsule l'input fichier JSON derrière un bouton d'import réutilisable.
|
||||
import { useRef } from "react";
|
||||
import { Icon } from "./Icon.jsx";
|
||||
import { Tooltip } from "./Tooltip.jsx";
|
||||
|
||||
export function ImportButton({ className, label, title, ariaLabel, icon, onFile, tooltip = "", tooltipPosition = "top", ...props }) {
|
||||
export function ImportButton({ className, label, title, ariaLabel, icon, onFile, onKeyDown, tabIndex = 0, tooltip = "", tooltipPosition = "top", ...props }) {
|
||||
const inputRef = useRef(null);
|
||||
const buttonProps = {
|
||||
...props,
|
||||
role: "button",
|
||||
tabIndex,
|
||||
onKeyDown: (event) => {
|
||||
onKeyDown?.(event);
|
||||
if (event.defaultPrevented || (event.key !== "Enter" && event.key !== " ")) return;
|
||||
event.preventDefault();
|
||||
inputRef.current?.click();
|
||||
}
|
||||
};
|
||||
const children = <>
|
||||
{icon && <Icon name={icon} />}
|
||||
{label}
|
||||
<input type="file" accept="application/json" hidden onChange={async (event) => {
|
||||
<input ref={inputRef} type="file" accept="application/json" hidden onChange={async (event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (file) await onFile(file);
|
||||
event.target.value = "";
|
||||
|
|
@ -14,7 +27,7 @@ export function ImportButton({ className, label, title, ariaLabel, icon, onFile,
|
|||
</>;
|
||||
|
||||
if (tooltip) {
|
||||
return <Tooltip as="label" className={className} content={tooltip} position={tooltipPosition} aria-label={ariaLabel} {...props}>{children}</Tooltip>;
|
||||
return <Tooltip as="label" className={className} content={tooltip} position={tooltipPosition} aria-label={ariaLabel} {...buttonProps}>{children}</Tooltip>;
|
||||
}
|
||||
return <label className={className} aria-label={ariaLabel} title={title} {...props}>{children}</label>;
|
||||
return <label className={className} aria-label={ariaLabel} title={title} {...buttonProps}>{children}</label>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const FOCUSABLE_SELECTOR = [
|
|||
"button:not([disabled])",
|
||||
"input:not([disabled]):not([type='hidden'])",
|
||||
"select:not([disabled])",
|
||||
"summary",
|
||||
"textarea:not([disabled])",
|
||||
"[tabindex]:not([tabindex='-1'])",
|
||||
"[contenteditable='true']"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { Icon } from "./Icon.jsx";
|
|||
import { ImportButton } from "./ImportButton.jsx";
|
||||
import { Tooltip } from "./Tooltip.jsx";
|
||||
|
||||
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, actions, children }) {
|
||||
export function Shell({ route, content, games, drawerGameId = "", drawerVisible = false, compactGameLayout = false, reducedSidebar = false, actions, onOpenAutoBackup, children }) {
|
||||
const gameId = route.split("/")[1] === "games" ? route.split("/")[2] || "" : "";
|
||||
const game = games.find((item) => item.id === gameId);
|
||||
const topbarLabel = route === "/design-system" && import.meta.env.DEV ? "Design system" : route.startsWith("/toolbox") ? content.topbar.toolbox : route.startsWith("/games") ? content.topbar.games : route === "/library" ? content.topbar.library : content.topbar.dashboard;
|
||||
|
|
@ -67,8 +67,8 @@ export function Shell({ route, content, games, drawerGameId = "", drawerVisible
|
|||
<span className="badge">{content.sidebar.badge}</span>
|
||||
<p>{content.sidebar.note}</p>
|
||||
<div className="sidebar-storage-actions" aria-label="Actions globales de stockage">
|
||||
<Tooltip as="button" className="sidebar-action-button nds-icon-button" content={compactSidebar ? "Exporter toutes les toolboxes" : ""} position="right" data-size="sm" data-variant="primary" onClick={actions.exportAllToolboxes} aria-label="Exporter toutes les toolboxes" data-toolbox-tutorial-target="exportAll" title={compactSidebar ? undefined : "Exporter tout"}><Icon name="export" /></Tooltip>
|
||||
<ImportButton className="sidebar-action-button nds-icon-button import-icon-button" data-size="sm" title={compactSidebar ? undefined : "Importer tout"} ariaLabel="Importer toutes les toolboxes" tooltip={compactSidebar ? "Importer toutes les toolboxes" : ""} tooltipPosition="right" onFile={actions.importAllToolboxes} icon="import" />
|
||||
<Tooltip as="button" className="sidebar-action-button sidebar-backup-button nds-button" content={compactSidebar ? content.toolboxes.autoBackup.title : ""} position="right" data-size="sm" data-variant="primary" type="button" onClick={onOpenAutoBackup} aria-label={content.toolboxes.autoBackup.title} title={compactSidebar ? undefined : content.toolboxes.autoBackup.title} data-toolbox-tutorial-target="backup">{compactSidebar && <Icon name="save" />}<span className="sidebar-storage-action-label">{content.toolboxes.autoBackup.sidebarLabel}</span></Tooltip>
|
||||
<ImportButton className="sidebar-action-button nds-icon-button import-icon-button" data-size="sm" ariaLabel="Importer toutes les toolboxes" tooltip="Importer toutes les toolboxes" tooltipPosition="right" onFile={actions.importAllToolboxes} icon="import" />
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Rôle : expose le choix gauche/droite des notifications via un Radio Button Group NDS.
|
||||
import { Icon } from "./Icon.jsx";
|
||||
|
||||
export function ToastPositionSwitch({ position, labels, onChange }) {
|
||||
export function ToastPositionSwitch({ position, labels, onChange, initialFocus = false }) {
|
||||
const normalizedPosition = position === "left" ? "left" : "right";
|
||||
return (
|
||||
<div
|
||||
|
|
@ -18,6 +18,7 @@ export function ToastPositionSwitch({ position, labels, onChange }) {
|
|||
aria-checked={normalizedPosition === "left"}
|
||||
aria-label={labels.left}
|
||||
title={labels.left}
|
||||
data-modal-initial-focus={initialFocus && normalizedPosition === "left" ? "" : undefined}
|
||||
onClick={() => onChange("left")}
|
||||
>
|
||||
<Icon name="toast-left" />
|
||||
|
|
@ -29,6 +30,7 @@ export function ToastPositionSwitch({ position, labels, onChange }) {
|
|||
aria-checked={normalizedPosition === "right"}
|
||||
aria-label={labels.right}
|
||||
title={labels.right}
|
||||
data-modal-initial-focus={initialFocus && normalizedPosition === "right" ? "" : undefined}
|
||||
onClick={() => onChange("right")}
|
||||
>
|
||||
<Icon name="toast-right" />
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
import { useEffect, useId, useState } from "react";
|
||||
import { flushSync } from "react-dom";
|
||||
import { Icon } from "./Icon.jsx";
|
||||
import { ImportButton } from "./ImportButton.jsx";
|
||||
import { Modal } from "./Modal.jsx";
|
||||
import { ToastPositionSwitch } from "./ToastPositionSwitch.jsx";
|
||||
|
||||
export function ConfirmModal({ title, message, confirmLabel = "Confirmer", cancelLabel = "Annuler", danger = false, onClose }) {
|
||||
const titleId = useId();
|
||||
|
|
@ -72,6 +74,66 @@ export function LinkToolboxModal({ toolboxes, selectedId, onClose }) {
|
|||
);
|
||||
}
|
||||
|
||||
export function ToolboxManagementModal({ content, toastPosition, setToastPosition, actions, onClose }) {
|
||||
const titleId = useId();
|
||||
const descriptionId = useId();
|
||||
|
||||
return (
|
||||
<Modal
|
||||
rootClassName="confirm-modal-root toolbox-management-modal-root"
|
||||
dialogClassName="confirm-modal nds-modal toolbox-management-modal themed-scrollbar"
|
||||
labelledBy={titleId}
|
||||
describedBy={descriptionId}
|
||||
onRequestClose={onClose}
|
||||
>
|
||||
<header className="toolbox-management-header">
|
||||
<div>
|
||||
<p className="eyebrow">{content.management.eyebrow}</p>
|
||||
<h2 id={titleId}>{content.management.title}</h2>
|
||||
</div>
|
||||
<button className="nds-icon-button" data-size="sm" type="button" onClick={onClose} aria-label={content.management.close} title={content.management.close}><Icon name="close" /></button>
|
||||
</header>
|
||||
<p id={descriptionId} className="toolbox-management-description">{content.management.description}</p>
|
||||
<section className="toolbox-management-section toolbox-management-preferences" aria-labelledby="toolbox-management-preferences-title">
|
||||
<div>
|
||||
<p className="eyebrow">{content.preferencesLabel}</p>
|
||||
<h3 id="toolbox-management-preferences-title">{content.toastPositionLabel}</h3>
|
||||
</div>
|
||||
<ToastPositionSwitch
|
||||
position={toastPosition}
|
||||
onChange={setToastPosition}
|
||||
initialFocus
|
||||
labels={{
|
||||
title: content.toastPositionLabel,
|
||||
left: content.toastPositionLeft,
|
||||
right: content.toastPositionRight
|
||||
}}
|
||||
/>
|
||||
</section>
|
||||
<section className="toolbox-management-section" aria-labelledby="toolbox-management-data-title">
|
||||
<div>
|
||||
<h3 id="toolbox-management-data-title">{content.management.dataTitle}</h3>
|
||||
<p>{content.management.dataDescription}</p>
|
||||
</div>
|
||||
<div className="toolbox-management-actions nds-toolbar">
|
||||
<button className="nds-button" data-size="sm" type="button" onClick={actions.exportAllToolboxes}><Icon name="export" />{content.exportAll}</button>
|
||||
<ImportButton className="nds-button" data-size="sm" label={content.importAll} icon="import" onFile={actions.importAllToolboxes} />
|
||||
</div>
|
||||
</section>
|
||||
<details className="toolbox-storage-details">
|
||||
<summary>{content.management.storageDetailsTitle}</summary>
|
||||
<div className="toolbox-storage-details-content">
|
||||
<p>{content.storageHelp.text}</p>
|
||||
<ul>{content.storageHelp.items.map((item) => <li key={item}>{item}</li>)}</ul>
|
||||
</div>
|
||||
</details>
|
||||
<footer className="nds-modal-footer toolbox-management-footer">
|
||||
<button className="nds-button" data-size="sm" type="button" onClick={onClose}>{content.management.close}</button>
|
||||
</footer>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export function AutoBackupModal({ backup, content, onClose }) {
|
||||
const folderName = backup.config.directoryHandle?.name || content.noFolder;
|
||||
const lastBackup = backup.config.lastBackup
|
||||
|
|
@ -88,24 +150,17 @@ export function AutoBackupModal({ backup, content, onClose }) {
|
|||
<button className="nds-icon-button" data-size="sm" type="button" disabled={backup.busy} onClick={onClose} aria-label={content.close} title={content.close}><Icon name="close" /></button>
|
||||
</header>
|
||||
<p className="auto-backup-description">{content.description}</p>
|
||||
<div className="auto-backup-compatibility">
|
||||
<strong>{content.compatibleLabel}</strong>
|
||||
<ul>{content.browsers.map((browser) => <li key={browser}>{browser}</li>)}</ul>
|
||||
</div>
|
||||
<div className="auto-backup-permission-guide">
|
||||
<strong>{content.permissionTitle}</strong>
|
||||
<p>{content.permissionDescription}</p>
|
||||
<ol>{content.permissionSteps.map((step) => <li key={step}>{step}</li>)}</ol>
|
||||
</div>
|
||||
{!backup.supported ? <p className="nds-inline-notice" data-variant="warning" role="status">{content.unsupported}</p> : (
|
||||
<>
|
||||
<div className="auto-backup-folder">
|
||||
<div><span className="eyebrow">{content.folderLabel}</span><strong>{folderName}</strong></div>
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={backup.busy} onClick={() => void backup.chooseDirectory()}>{backup.config.directoryHandle ? content.changeFolder : content.chooseFolder}</button>
|
||||
</div>
|
||||
<div className="auto-backup-last">
|
||||
<span className="eyebrow">{content.lastBackup}</span>
|
||||
<strong>{lastBackup}</strong>
|
||||
<section className="auto-backup-settings" aria-label={content.title}>
|
||||
<div className="auto-backup-status-grid">
|
||||
<div className="auto-backup-folder">
|
||||
<div><span className="eyebrow">{content.folderLabel}</span><strong>{folderName}</strong></div>
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={backup.busy} onClick={() => void backup.chooseDirectory()}>{backup.config.directoryHandle ? content.changeFolder : content.chooseFolder}</button>
|
||||
</div>
|
||||
<div className="auto-backup-last">
|
||||
<span className="eyebrow">{content.lastBackup}</span>
|
||||
<strong>{lastBackup}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<label className="auto-backup-toggle">
|
||||
<input className="native-switch-input" type="checkbox" checked={backup.config.enabled} disabled={backup.busy} onChange={(event) => void backup.setEnabled(event.target.checked)} />
|
||||
|
|
@ -118,8 +173,17 @@ export function AutoBackupModal({ backup, content, onClose }) {
|
|||
{backup.config.directoryHandle && (backup.permission === "prompt" || backup.permission === "denied") && <button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={backup.busy} onClick={() => void backup.requestPermission()}>{content.reauthorize}</button>}
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={backup.busy || !backup.config.directoryHandle || backup.permission !== "granted"} onClick={() => void backup.saveNow()}>{content.saveNow}</button>
|
||||
</footer>
|
||||
</>
|
||||
</section>
|
||||
)}
|
||||
<section className="auto-backup-compatibility" aria-labelledby="auto-backup-compatibility-title">
|
||||
<strong id="auto-backup-compatibility-title">{content.compatibleLabel}</strong>
|
||||
<ul>{content.browsers.map((browser) => <li key={browser}>{browser}</li>)}</ul>
|
||||
</section>
|
||||
<section className="auto-backup-permission-guide" aria-labelledby="auto-backup-permission-title">
|
||||
<strong id="auto-backup-permission-title">{content.permissionTitle}</strong>
|
||||
<p>{content.permissionDescription}</p>
|
||||
<ol>{content.permissionSteps.map((step) => <li key={step}>{step}</li>)}</ol>
|
||||
</section>
|
||||
<footer className="nds-modal-footer auto-backup-close-footer">
|
||||
<button className="nds-button" data-size="sm" type="button" disabled={backup.busy} onClick={onClose}>{content.close}</button>
|
||||
</footer>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue