Add ARCHITECTURE.md (layers, flows, folder map, glossary), CONTRIBUTING.md (setup and step-by-step recipes) and a README in each main folder, with an index of docs/. Convert the 511 JavaScript headers from "// Rôle :" lines to JSDoc @file blocks, define a three-level header template in website/AGENTS.md and check the header in tests/file-headers.test.mjs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
123 lines
4.5 KiB
JavaScript
123 lines
4.5 KiB
JavaScript
/**
|
|
* @file Rend les contrôles modal et quick-add d'ajout d'outils toolbox.
|
|
*/
|
|
|
|
import { useState } from "react";
|
|
import { CompactDropdown } from "../../../components/CompactDropdown.jsx";
|
|
import { Icon } from "../../../components/Icon.jsx";
|
|
import { Modal } from "../../../components/Modal.jsx";
|
|
import { Tooltip } from "../../../components/Tooltip.jsx";
|
|
import { LIBRARY_CATEGORY_DEFINITIONS, TOOLBOX_MODULES } from "../toolboxModuleRegistry.js";
|
|
|
|
export function AddToolControls({ categories, descriptions, onAdd }) {
|
|
const [open, setOpen] = useState(false);
|
|
const modules = Object.entries(TOOLBOX_MODULES);
|
|
const moduleCategories = LIBRARY_CATEGORY_DEFINITIONS.map((category) => ({
|
|
...category,
|
|
title: categories[category.key]
|
|
}));
|
|
|
|
function addTool(type) {
|
|
onAdd(type);
|
|
setOpen(false);
|
|
}
|
|
|
|
function renderToolCard(type) {
|
|
const module = TOOLBOX_MODULES[type];
|
|
return (
|
|
<button key={type} className="tool-add-card" type="button" data-modal-initial-focus={type === moduleCategories[0]?.types[0] ? "" : undefined} onClick={() => addTool(type)}>
|
|
<span className="module-icon" aria-hidden="true">
|
|
<span className={`module-icon-svg module-icon-${module.icon}`} />
|
|
</span>
|
|
<strong>{module.label}</strong>
|
|
<span>{descriptions[type]}</span>
|
|
</button>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className="tool-add-controls"
|
|
aria-label="Ajouter un outil"
|
|
>
|
|
<button
|
|
className="tool-add-modal-button nds-button"
|
|
data-size="sm"
|
|
data-variant="primary"
|
|
data-edge="left"
|
|
data-border="joined"
|
|
type="button"
|
|
onClick={() => setOpen(true)}
|
|
data-toolbox-tutorial-target="addTool"
|
|
>
|
|
Ajouter un outil
|
|
</button>
|
|
<CompactDropdown
|
|
className="tool-add-quick-dropdown"
|
|
menuClassName="tool-quick-add"
|
|
label="Ajout rapide"
|
|
renderTrigger={({ open: quickOpen, toggle }) => (
|
|
<Tooltip
|
|
as="button"
|
|
className={`tool-add-quick-toggle nds-icon-button ${quickOpen ? "active" : ""}`}
|
|
content={quickOpen ? "Masquer l'ajout rapide" : "Afficher l'ajout rapide"}
|
|
data-size="sm"
|
|
data-variant="primary"
|
|
data-edge="right"
|
|
data-border="joined"
|
|
type="button"
|
|
onClick={toggle}
|
|
aria-label={quickOpen ? "Masquer l'ajout rapide" : "Afficher l'ajout rapide"}
|
|
aria-expanded={quickOpen}
|
|
>
|
|
<Icon name="dropdown" />
|
|
</Tooltip>
|
|
)}
|
|
>
|
|
{({ close }) => (
|
|
<>
|
|
{modules.map(([type, module]) => (
|
|
<Tooltip
|
|
as="button"
|
|
key={type}
|
|
className="tool-quick-add-button nds-icon-button"
|
|
content={module.label}
|
|
data-size="sm"
|
|
type="button"
|
|
onClick={() => {
|
|
onAdd(type);
|
|
close();
|
|
}}
|
|
aria-label={`Ajouter ${module.label}`}
|
|
>
|
|
<span className="module-icon" aria-hidden="true">
|
|
<span className={`module-icon-svg module-icon-${module.icon}`} />
|
|
</span>
|
|
</Tooltip>
|
|
))}
|
|
</>
|
|
)}
|
|
</CompactDropdown>
|
|
</div>
|
|
{open && (
|
|
<Modal rootClassName="tool-add-modal-root" dialogClassName="confirm-modal nds-modal tool-add-modal" labelledBy="tool-add-modal-title" onRequestClose={() => setOpen(false)}>
|
|
<header>
|
|
<h2 id="tool-add-modal-title">Ajouter un outil</h2>
|
|
<button className="drawer-close-button nds-icon-button" data-size="sm" type="button" onClick={() => setOpen(false)} aria-label="Fermer" title="Fermer">
|
|
<Icon name="close" />
|
|
</button>
|
|
</header>
|
|
<div className="tool-add-category-list">
|
|
{moduleCategories.map((category) => (
|
|
<section className="tool-add-category-section" key={category.key} aria-labelledby={`tool-add-category-${category.key}`}>
|
|
<h3 id={`tool-add-category-${category.key}`}><span>{category.title}</span></h3>
|
|
<div className="tool-add-grid">{category.types.map(renderToolCard)}</div>
|
|
</section>
|
|
))}
|
|
</div>
|
|
</Modal>
|
|
)}
|
|
</>
|
|
);
|
|
}
|