Add custom toolbox card covers
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
25889a23ba
commit
06de3a3a6e
13 changed files with 7480 additions and 38 deletions
|
|
@ -2,11 +2,13 @@
|
|||
/* eslint-disable react-refresh/only-export-components -- expose aussi les helpers publics de rendu des cartes toolbox. */
|
||||
import { CompactDropdown } from "../../components/CompactDropdown.jsx";
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
import { ToolboxCoverEditor } from "./ToolboxCoverEditor.jsx";
|
||||
import {
|
||||
DEFAULT_TOOLBOX_ICON,
|
||||
normalizeToolboxIcon,
|
||||
TOOLBOX_ICONS
|
||||
} from "./storage/toolboxStorage.js";
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
export function getGameCardCover(game) {
|
||||
return game?.images?.cardCover || game?.image || "";
|
||||
|
|
@ -22,7 +24,9 @@ export function formatDate(value) {
|
|||
|
||||
export function ToolboxCard({ toolbox, game, actions, reorder }) {
|
||||
const gameCoverImage = getGameCardCover(game);
|
||||
const coverImage = gameCoverImage || toolbox.icon || DEFAULT_TOOLBOX_ICON;
|
||||
const customCoverImage = !gameCoverImage && toolbox.customCover ? toolbox.customCover : "";
|
||||
const coverImage = gameCoverImage || customCoverImage || toolbox.icon || DEFAULT_TOOLBOX_ICON;
|
||||
const hasRectCover = Boolean(gameCoverImage || customCoverImage);
|
||||
const className = [
|
||||
"card",
|
||||
"nds-card",
|
||||
|
|
@ -46,13 +50,13 @@ export function ToolboxCard({ toolbox, game, actions, reorder }) {
|
|||
<Icon name="drag" />
|
||||
</button>
|
||||
<a
|
||||
className={`card-cover nds-card-cover toolbox-card-cover-link ${gameCoverImage ? "toolbox-card-cover" : "toolbox-icon-cover"}`}
|
||||
className={`card-cover nds-card-cover toolbox-card-cover-link ${hasRectCover ? "toolbox-card-cover" : "toolbox-icon-cover"}`}
|
||||
href={`#/toolbox/${toolbox.id}`}
|
||||
aria-label={`Ouvrir ${toolbox.name}`}
|
||||
title={`Ouvrir ${toolbox.name}`}
|
||||
style={{ "--game-cover": getGameCardBackground(game), background: gameCoverImage ? "" : "var(--gradient-nebula)" }}
|
||||
style={{ "--game-cover": getGameCardBackground(game), background: hasRectCover ? "" : "var(--gradient-nebula)" }}
|
||||
>
|
||||
<img src={coverImage} alt={game ? game.title : `Icône de ${toolbox.name}`} loading="lazy" />
|
||||
<img src={coverImage} alt={game ? game.title : customCoverImage ? `Image de ${toolbox.name}` : `Icône de ${toolbox.name}`} loading="lazy" />
|
||||
</a>
|
||||
<div className="card-body nds-card-body">
|
||||
<p className="eyebrow">{game ? game.title : "Toolbox libre"}</p>
|
||||
|
|
@ -76,49 +80,97 @@ export function ToolboxCard({ toolbox, game, actions, reorder }) {
|
|||
|
||||
export function ToolboxIconPicker({ toolbox, onChange, tutorialTarget = "" }) {
|
||||
const icon = normalizeToolboxIcon(toolbox.icon);
|
||||
const triggerImage = toolbox.customCover || icon;
|
||||
const fileInputRef = useRef(null);
|
||||
const [coverEditor, setCoverEditor] = useState(null);
|
||||
|
||||
function closeCoverEditor() {
|
||||
setCoverEditor(null);
|
||||
if (fileInputRef.current) fileInputRef.current.value = "";
|
||||
}
|
||||
|
||||
return (
|
||||
<CompactDropdown
|
||||
className="toolbox-icon-picker"
|
||||
menuClassName="toolbox-icon-picker-menu"
|
||||
label="Icônes de toolbox"
|
||||
renderTrigger={({ open, toggle }) => (
|
||||
<button
|
||||
className={`toolbox-icon-picker-button nds-large-icon-picker-trigger ${open ? "active" : ""}`}
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label="Changer l'icône de la toolbox"
|
||||
aria-expanded={open}
|
||||
aria-pressed={open}
|
||||
data-toolbox-tutorial-target={tutorialTarget || undefined}
|
||||
title="Changer l'icône"
|
||||
>
|
||||
<img src={icon} alt="" aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
>
|
||||
{({ close }) => (
|
||||
<>
|
||||
{TOOLBOX_ICONS.map((path) => (
|
||||
<>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/*"
|
||||
hidden
|
||||
onChange={(event) => {
|
||||
const file = event.target.files?.[0];
|
||||
if (!file?.type?.startsWith("image/")) return;
|
||||
setCoverEditor({ file });
|
||||
}}
|
||||
/>
|
||||
<CompactDropdown
|
||||
className="toolbox-icon-picker"
|
||||
menuClassName="toolbox-icon-picker-menu"
|
||||
label="Icônes de toolbox"
|
||||
renderTrigger={({ open, toggle }) => (
|
||||
<button
|
||||
className={`toolbox-icon-picker-button nds-large-icon-picker-trigger ${toolbox.customCover ? "has-custom-cover" : ""} ${open ? "active" : ""}`}
|
||||
type="button"
|
||||
onClick={toggle}
|
||||
aria-label="Changer l'image de la toolbox"
|
||||
aria-expanded={open}
|
||||
aria-pressed={open}
|
||||
data-toolbox-tutorial-target={tutorialTarget || undefined}
|
||||
title="Changer l'image"
|
||||
>
|
||||
<img src={triggerImage} alt="" aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
>
|
||||
{({ close }) => (
|
||||
<>
|
||||
{TOOLBOX_ICONS.map((path) => (
|
||||
<button
|
||||
key={path}
|
||||
className={`nds-icon-button ${!toolbox.customCover && path === icon ? "active" : ""}`}
|
||||
data-size="md"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onChange(path, "");
|
||||
close();
|
||||
}}
|
||||
aria-label={`Utiliser l'icône ${path.split("/").pop().replace(".png", "")}`}
|
||||
aria-pressed={!toolbox.customCover && path === icon}
|
||||
title={path.split("/").pop().replace(".png", "")}
|
||||
>
|
||||
<img src={path} alt="" aria-hidden="true" loading="lazy" />
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
key={path}
|
||||
className={`nds-icon-button ${path === icon ? "active" : ""}`}
|
||||
data-size="md"
|
||||
className={`toolbox-cover-menu-action nds-button ${toolbox.customCover ? "active" : ""}`}
|
||||
data-size="sm"
|
||||
data-variant="secondary"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onChange(path);
|
||||
fileInputRef.current?.click();
|
||||
close();
|
||||
}}
|
||||
aria-label={`Utiliser l'icône ${path.split("/").pop().replace(".png", "")}`}
|
||||
aria-pressed={path === icon}
|
||||
title={path.split("/").pop().replace(".png", "")}
|
||||
aria-label={toolbox.customCover ? "Remplacer l'image de card" : "Ajouter une image de card"}
|
||||
aria-pressed={Boolean(toolbox.customCover)}
|
||||
title={toolbox.customCover ? "Remplacer l'image de card" : "Ajouter une image de card"}
|
||||
>
|
||||
<img src={path} alt="" aria-hidden="true" loading="lazy" />
|
||||
<Icon name="picture" />
|
||||
<span>Image personnalisée</span>
|
||||
</button>
|
||||
))}
|
||||
</>
|
||||
</>
|
||||
)}
|
||||
</CompactDropdown>
|
||||
{coverEditor && (
|
||||
<ToolboxCoverEditor
|
||||
file={coverEditor.file}
|
||||
existingCover={coverEditor.existingCover || toolbox.customCover || ""}
|
||||
onClose={closeCoverEditor}
|
||||
onSave={(customCover) => {
|
||||
onChange(icon, customCover);
|
||||
closeCoverEditor();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</CompactDropdown>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue