Add chance simulator toolbox and refine checklist interactions
All checks were successful
Deploy Sokko G / deploy (push) Successful in 17s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 17s
This commit is contained in:
parent
35fe877d58
commit
6b85e58765
25 changed files with 1518 additions and 18 deletions
|
|
@ -1,5 +1,5 @@
|
|||
// Rôle : rend les sections et items de checklist avec édition inline et quantités.
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Icon } from "../../../components/Icon.jsx";
|
||||
import { useInlineEdit } from "../../../hooks/useInlineEdit.js";
|
||||
import {
|
||||
|
|
@ -119,6 +119,7 @@ export function ChecklistSection({ section, context, data, reorder, onRenameSect
|
|||
onDeleteItem={onDeleteItem}
|
||||
editing={editingItemId === item.id}
|
||||
onToggleEditing={() => setEditingItemId(editingItemId === item.id ? "" : item.id)}
|
||||
onCloseEditing={() => setEditingItemId("")}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
|
|
@ -127,7 +128,8 @@ export function ChecklistSection({ section, context, data, reorder, onRenameSect
|
|||
);
|
||||
}
|
||||
|
||||
function ChecklistItem({ item, section, context, reorder, items, save, onUpdateItem, onMoveItemToCategory, onDeleteItem, editing, onToggleEditing }) {
|
||||
function ChecklistItem({ item, section, context, reorder, items, save, onUpdateItem, onMoveItemToCategory, onDeleteItem, editing, onToggleEditing, onCloseEditing }) {
|
||||
const itemRef = useRef(null);
|
||||
const done = context.clampQty(item.qtyCurrent, item.qtyTarget) >= item.qtyTarget;
|
||||
const textContent = context.moduleText?.checklist || {};
|
||||
const className = [
|
||||
|
|
@ -149,6 +151,15 @@ function ChecklistItem({ item, section, context, reorder, items, save, onUpdateI
|
|||
onCommit: (title) => onMoveItemToCategory(item.id, title)
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!editing) return undefined;
|
||||
function handleOutsidePointerDown(event) {
|
||||
if (!itemRef.current?.contains(event.target)) onCloseEditing();
|
||||
}
|
||||
document.addEventListener("pointerdown", handleOutsidePointerDown);
|
||||
return () => document.removeEventListener("pointerdown", handleOutsidePointerDown);
|
||||
}, [editing, onCloseEditing]);
|
||||
|
||||
function updateItem(updater) {
|
||||
save(items.map((entry) => entry.id === item.id ? updater(entry) : entry));
|
||||
}
|
||||
|
|
@ -161,7 +172,7 @@ function ChecklistItem({ item, section, context, reorder, items, save, onUpdateI
|
|||
}
|
||||
|
||||
return (
|
||||
<li className={className} {...reorder.getItemProps({ itemId: item.id, groupId: section.id })}>
|
||||
<li ref={itemRef} className={className} {...reorder.getItemProps({ itemId: item.id, groupId: section.id })}>
|
||||
<div className={`checklist-item-main ${editing ? "is-editing" : ""}`}>
|
||||
<button
|
||||
className="checklist-drag-handle nds-icon-button"
|
||||
|
|
@ -225,7 +236,7 @@ function ChecklistItem({ item, section, context, reorder, items, save, onUpdateI
|
|||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button type="button" className="checklist-edit-button nds-icon-button" data-size="sm" onClick={onToggleEditing} aria-label={`${textContent.editTitle || "Modifier"} ${item.label}`} title={textContent.editTitle || "Modifier"}>
|
||||
<button type="button" className="checklist-edit-button nds-icon-button" data-size="sm" onClick={onToggleEditing} aria-pressed={editing} aria-label={`${textContent.editTitle || "Modifier"} ${item.label}`} title={textContent.editTitle || "Modifier"}>
|
||||
<Icon name="edit" />
|
||||
</button>
|
||||
<button className="checklist-delete-button nds-icon-button" data-size="sm" data-variant="danger" onClick={() => onDeleteItem(item.id)} aria-label={`${textContent.deleteTitle || "Supprimer"} ${item.label}`} title={textContent.deleteTitle || "Supprimer"}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue