Add responsive game filters and hybrid toolbox drawer
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
1ee460b94f
commit
00e73f0062
32 changed files with 1202 additions and 241 deletions
17
website/src/features/games/ActiveFilterBadges.jsx
Normal file
17
website/src/features/games/ActiveFilterBadges.jsx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Rôle : affiche les critères actifs et permet de les retirer individuellement.
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
|
||||
export function ActiveFilterBadges({ items, label = "Filtres actifs" }) {
|
||||
if (!items.length) return null;
|
||||
|
||||
return (
|
||||
<div className="nds-active-filters" role="group" aria-label={label}>
|
||||
{items.map((item) => (
|
||||
<button className="nds-badge nds-active-filter" data-variant="neutral" type="button" key={item.id} aria-label={`Retirer le filtre ${item.label}`} onClick={item.onRemove}>
|
||||
<span>{item.label}</span>
|
||||
<Icon name="close" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
49
website/src/features/games/GameFilterDropdown.jsx
Normal file
49
website/src/features/games/GameFilterDropdown.jsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Rôle : fournit le menu déroulant partagé des barres de filtres avancées.
|
||||
import { useId } from "react";
|
||||
import { CompactDropdown } from "../../components/CompactDropdown.jsx";
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
|
||||
export function GameFilterDropdown({
|
||||
label,
|
||||
triggerLabel = label,
|
||||
count = 0,
|
||||
icon = "checklist",
|
||||
align = "start",
|
||||
columns,
|
||||
className = "",
|
||||
menuClassName = "",
|
||||
children
|
||||
}) {
|
||||
const dropdownId = useId();
|
||||
const triggerId = `${dropdownId}-trigger`;
|
||||
const menuId = `${dropdownId}-menu`;
|
||||
|
||||
return (
|
||||
<CompactDropdown
|
||||
className={`nds-filter-dropdown ${align === "end" ? "is-aligned-end" : ""} ${className}`.trim()}
|
||||
menuClassName={`nds-filter-menu nds-popover ${menuClassName}`.trim()}
|
||||
menuProps={{ id: menuId, role: "dialog", "aria-labelledby": triggerId, "data-columns": columns }}
|
||||
label={label}
|
||||
renderTrigger={({ open, toggle, triggerRef }) => (
|
||||
<button
|
||||
ref={triggerRef}
|
||||
id={triggerId}
|
||||
className={`nds-filter-menu-trigger nds-select-trigger ${open ? "active" : ""}`}
|
||||
data-size="sm"
|
||||
type="button"
|
||||
aria-controls={menuId}
|
||||
aria-expanded={open}
|
||||
aria-haspopup="dialog"
|
||||
aria-label={count > 0 ? `${label}, ${count} sélectionné${count > 1 ? "s" : ""}` : label}
|
||||
onClick={toggle}
|
||||
>
|
||||
<Icon name={icon} />
|
||||
<span>{triggerLabel}</span>
|
||||
{count > 0 && <strong className="nds-filter-count" aria-hidden="true">{count}</strong>}
|
||||
</button>
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</CompactDropdown>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,5 +1,30 @@
|
|||
// Rôle : fournit le panneau de filtres générique des pages de données de jeu.
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
import { Tooltip } from "../../components/Tooltip.jsx";
|
||||
import { ActiveFilterBadges } from "./ActiveFilterBadges.jsx";
|
||||
import { GameFilterDropdown } from "./GameFilterDropdown.jsx";
|
||||
|
||||
function FilterLogic({ matchLabel, logicLabels, value, onChange }) {
|
||||
return (
|
||||
<div className="filter-logic nds-filter-logic">
|
||||
<span>{matchLabel}</span>
|
||||
<div className="filter-logic-group nds-radio-button-group" data-size="xs" role="radiogroup" aria-label={matchLabel}>
|
||||
{["and", "or"].map((logic) => (
|
||||
<button
|
||||
key={logic}
|
||||
className={value === logic ? "active" : ""}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={value === logic}
|
||||
onClick={() => onChange(logic)}
|
||||
>
|
||||
{logicLabels[logic]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function GameFiltersPanel({
|
||||
title,
|
||||
|
|
@ -14,6 +39,7 @@ export function GameFiltersPanel({
|
|||
getOptionLabel = (option) => option,
|
||||
getOptionClassName = () => "",
|
||||
renderOptionMedia,
|
||||
variant = "vertical",
|
||||
onChange
|
||||
}) {
|
||||
const selected = new Set(filters[selectedKey] || []);
|
||||
|
|
@ -21,8 +47,114 @@ export function GameFiltersPanel({
|
|||
onChange(updater(filters));
|
||||
}
|
||||
|
||||
function toggleOption(optionId) {
|
||||
update((state) => {
|
||||
const values = new Set(state[selectedKey] || []);
|
||||
if (values.has(optionId)) values.delete(optionId);
|
||||
else values.add(optionId);
|
||||
return { ...state, [selectedKey]: [...values] };
|
||||
});
|
||||
}
|
||||
|
||||
function reset() {
|
||||
onChange({ name: "", [selectedKey]: [], logic: "and" });
|
||||
}
|
||||
|
||||
const activeBadges = [
|
||||
...(filters.name.trim() ? [{ id: "name", label: `${nameLabel} : ${filters.name.trim()}`, onRemove: () => update((state) => ({ ...state, name: "" })) }] : []),
|
||||
...options.filter((option) => selected.has(getOptionId(option))).map((option) => {
|
||||
const optionId = getOptionId(option);
|
||||
return {
|
||||
id: `${selectedKey}-${optionId}`,
|
||||
label: `${title} : ${getOptionLabel(option)}`,
|
||||
onRemove: () => toggleOption(optionId)
|
||||
};
|
||||
})
|
||||
];
|
||||
|
||||
if (variant === "horizontal-compact") {
|
||||
return (
|
||||
<div className="filter-panel nds-filter-panel" data-variant={variant}>
|
||||
<label className="nds-filter-search">
|
||||
<span className="sr-only">{nameLabel}</span>
|
||||
<input className="nds-input" data-size="sm" type="search" value={filters.name} placeholder="Rechercher..." onChange={(event) => update((state) => ({ ...state, name: event.target.value }))} />
|
||||
</label>
|
||||
<div className="nds-filter-group">
|
||||
<span className="nds-filter-group-label">{title}</span>
|
||||
<div className="nds-filter-direct-options" role="group" aria-label={title}>
|
||||
{options.map((option) => {
|
||||
const optionId = getOptionId(option);
|
||||
const optionLabel = getOptionLabel(option);
|
||||
const active = selected.has(optionId);
|
||||
return (
|
||||
<Tooltip
|
||||
as="button"
|
||||
className={`nds-filter-option ${getOptionClassName(option)} ${active ? "active" : ""}`.trim()}
|
||||
content={optionLabel}
|
||||
key={optionId}
|
||||
type="button"
|
||||
aria-label={optionLabel}
|
||||
aria-pressed={active}
|
||||
onClick={() => toggleOption(optionId)}
|
||||
>
|
||||
{renderOptionMedia?.(option)}
|
||||
<span className="nds-filter-option-label">{optionLabel}</span>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<div className="nds-filter-group">
|
||||
<FilterLogic matchLabel={matchLabel} logicLabels={logicLabels} value={filters.logic} onChange={(logic) => update((state) => ({ ...state, logic }))} />
|
||||
</div>
|
||||
<button className="filter-reset-button nds-icon-button nds-filter-reset" data-size="xs" type="button" onClick={reset} aria-label={resetLabel} title={resetLabel}>
|
||||
<Icon name="rubber" />
|
||||
</button>
|
||||
<ActiveFilterBadges items={activeBadges} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (variant === "horizontal-menu") {
|
||||
return (
|
||||
<div className="filter-panel nds-filter-panel" data-variant={variant}>
|
||||
<label className="nds-filter-search">
|
||||
<span className="sr-only">{nameLabel}</span>
|
||||
<input className="nds-input" data-size="sm" type="search" value={filters.name} placeholder="Rechercher..." onChange={(event) => update((state) => ({ ...state, name: event.target.value }))} />
|
||||
</label>
|
||||
<div className="nds-filter-group">
|
||||
<GameFilterDropdown label={title} count={selected.size}>
|
||||
{() => (
|
||||
<fieldset className="nds-filter-menu-fieldset">
|
||||
<legend className="sr-only">{title}</legend>
|
||||
<FilterLogic matchLabel={matchLabel} logicLabels={logicLabels} value={filters.logic} onChange={(logic) => update((state) => ({ ...state, logic }))} />
|
||||
<div className="nds-filter-menu-options">
|
||||
{options.map((option) => {
|
||||
const optionId = getOptionId(option);
|
||||
const optionLabel = getOptionLabel(option);
|
||||
return (
|
||||
<label className={`filter-chip nds-chip nds-filter-menu-option ${getOptionClassName(option)} ${selected.has(optionId) ? "active" : ""}`} key={optionId}>
|
||||
<input className="nds-checkbox" data-size="sm" type="checkbox" checked={selected.has(optionId)} onChange={() => toggleOption(optionId)} />
|
||||
{renderOptionMedia?.(option)}
|
||||
<span>{optionLabel}</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</fieldset>
|
||||
)}
|
||||
</GameFilterDropdown>
|
||||
</div>
|
||||
<button className="filter-reset-button nds-icon-button nds-filter-reset" data-size="xs" type="button" onClick={reset} aria-label={resetLabel} title={resetLabel}>
|
||||
<Icon name="rubber" />
|
||||
</button>
|
||||
<ActiveFilterBadges items={activeBadges} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="filter-panel nds-filter-panel">
|
||||
<div className="filter-panel nds-filter-panel" data-variant="vertical">
|
||||
<div className="filter-panel-head">
|
||||
<div>
|
||||
<p className="eyebrow">Filtres</p>
|
||||
|
|
@ -31,7 +163,8 @@ export function GameFiltersPanel({
|
|||
<button
|
||||
className="filter-reset-button nds-icon-button"
|
||||
data-size="xs"
|
||||
onClick={() => onChange({ name: "", [selectedKey]: [], logic: "and" })}
|
||||
type="button"
|
||||
onClick={reset}
|
||||
aria-label={resetLabel}
|
||||
title={resetLabel}
|
||||
>
|
||||
|
|
@ -42,23 +175,7 @@ export function GameFiltersPanel({
|
|||
<span>{nameLabel}</span>
|
||||
<input className="nds-input" data-size="sm" type="search" value={filters.name} placeholder="Rechercher..." onChange={(event) => update((state) => ({ ...state, name: event.target.value }))} />
|
||||
</label>
|
||||
<div className="filter-logic">
|
||||
<span>{matchLabel}</span>
|
||||
<div className="filter-logic-group nds-radio-button-group" data-size="xs" role="radiogroup" aria-label={matchLabel}>
|
||||
{["and", "or"].map((logic) => (
|
||||
<button
|
||||
key={logic}
|
||||
className={filters.logic === logic ? "active" : ""}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={filters.logic === logic}
|
||||
onClick={() => update((state) => ({ ...state, logic }))}
|
||||
>
|
||||
{logicLabels[logic]}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<FilterLogic matchLabel={matchLabel} logicLabels={logicLabels} value={filters.logic} onChange={(logic) => update((state) => ({ ...state, logic }))} />
|
||||
<div className="filter-options legacy-scrollbar">
|
||||
{options.map((option) => {
|
||||
const optionId = getOptionId(option);
|
||||
|
|
@ -69,12 +186,7 @@ export function GameFiltersPanel({
|
|||
data-size="sm"
|
||||
type="checkbox"
|
||||
checked={selected.has(optionId)}
|
||||
onChange={(event) => update((state) => {
|
||||
const values = new Set(state[selectedKey] || []);
|
||||
if (event.target.checked) values.add(optionId);
|
||||
else values.delete(optionId);
|
||||
return { ...state, [selectedKey]: [...values] };
|
||||
})}
|
||||
onChange={() => toggleOption(optionId)}
|
||||
/>
|
||||
{renderOptionMedia?.(option)}
|
||||
<span>{getOptionLabel(option)}</span>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// Rôle : expose les catégories repliables et les seuils Aniimo dans un défilement commun.
|
||||
import { useState } from "react";
|
||||
// Rôle : expose les filtres Aniimo dans une barre horizontale à menus avancés.
|
||||
import { Icon } from "../../../components/Icon.jsx";
|
||||
import { ActiveFilterBadges } from "../ActiveFilterBadges.jsx";
|
||||
import { GameFilterDropdown } from "../GameFilterDropdown.jsx";
|
||||
import { aniimoAsset, createAniimoFilters } from "./utils.js";
|
||||
|
||||
function LogicChoice({ label, value, onChange, content }) {
|
||||
return (
|
||||
<div className="filter-logic">
|
||||
<div className="filter-logic nds-filter-logic">
|
||||
<span>{content.match}</span>
|
||||
<div className="filter-logic-group nds-radio-button-group" data-size="xs" role="group" aria-label={label}>
|
||||
{["and", "or"].map((logic) => <button key={logic} type="button" className={value === logic ? "active" : ""} aria-pressed={value === logic} onClick={() => onChange(logic)}>{content[logic]}</button>)}
|
||||
|
|
@ -25,77 +26,100 @@ function LevelOperatorIcon({ exact = false }) {
|
|||
}
|
||||
|
||||
export function AniimoFilters({ filters, onChange, options, t, content }) {
|
||||
const [collapsed, setCollapsed] = useState({});
|
||||
const abilityOptions = [...options.abilities].sort((a, b) => Number(!options.elements.includes(a)) - Number(!options.elements.includes(b)));
|
||||
const elementAbilities = options.abilities.filter((option) => options.elements.includes(option));
|
||||
const actionAbilities = options.abilities.filter((option) => !options.elements.includes(option));
|
||||
function toggle(key, option, checked) {
|
||||
onChange({ ...filters, [key]: checked ? [...filters[key], option] : filters[key].filter((value) => value !== option) });
|
||||
}
|
||||
function updateAbility(option, minimum) {
|
||||
const abilities = { ...filters.abilities };
|
||||
if (minimum > 0) abilities[option] = minimum;
|
||||
else delete abilities[option];
|
||||
onChange({ ...filters, abilities });
|
||||
}
|
||||
const activeBadges = [
|
||||
...(filters.name.trim() ? [{ id: "name", label: `${content.name} : ${filters.name.trim()}`, onRemove: () => onChange({ ...filters, name: "" }) }] : []),
|
||||
...(filters.prismanaOnly ? [{ id: "prismana", label: content.prismana, onRemove: () => onChange({ ...filters, prismanaOnly: false }) }] : []),
|
||||
...filters.roles.map((option) => ({ id: `role-${option}`, label: `${content.roles} : ${t(option)}`, onRemove: () => toggle("roles", option, false) })),
|
||||
...filters.elements.map((option) => ({ id: `element-${option}`, label: `${content.elements} : ${t(option)}`, onRemove: () => toggle("elements", option, false) })),
|
||||
...Object.entries(filters.abilities).map(([option, level]) => ({ id: `ability-${option}`, label: `${t(option)} ${filters.abilityExact ? "=" : "≥"} ${level}`, onRemove: () => updateAbility(option, 0) }))
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="filter-panel nds-filter-panel aniimo-filters">
|
||||
<div className="filter-panel-head">
|
||||
<div><p className="eyebrow">{content.filters}</p><h2>{content.title}</h2></div>
|
||||
<button className="filter-reset-button nds-icon-button" data-size="xs" type="button" title={content.reset} aria-label={content.reset} onClick={() => onChange({ ...createAniimoFilters(), grouped: filters.grouped })}><Icon name="rubber" /></button>
|
||||
</div>
|
||||
<label className="field compact">
|
||||
<span>{content.name}</span>
|
||||
<div className="filter-panel nds-filter-panel aniimo-filters" data-variant="horizontal-menu">
|
||||
<label className="nds-filter-search">
|
||||
<span className="sr-only">{content.name}</span>
|
||||
<input className="nds-input" data-size="sm" type="search" placeholder={content.searchPlaceholder} value={filters.name} onChange={(event) => onChange({ ...filters, name: event.target.value })} />
|
||||
</label>
|
||||
<label className={`filter-chip nds-chip ${filters.prismanaOnly ? "active" : ""}`} data-size="sm">
|
||||
<input className="nds-checkbox" data-size="sm" type="checkbox" checked={filters.prismanaOnly} onChange={(event) => onChange({ ...filters, prismanaOnly: event.target.checked })} />
|
||||
<img src="/static/icons/prismana.svg" alt="" width="16" height="16" />
|
||||
<span>{content.prismanaOnly}</span>
|
||||
</label>
|
||||
<div className="aniimo-filter-sections filter-options legacy-scrollbar" role="region" aria-label={content.filters} tabIndex="0">
|
||||
{["roles", "elements", "abilities"].map((key) => (
|
||||
<div key={key} className="aniimo-filter-section-surface">
|
||||
<fieldset className="aniimo-filter-section">
|
||||
<legend><button type="button" className="aniimo-filter-toggle nds-button" data-size="sm" data-variant="ghost" aria-expanded={!collapsed[key]} aria-controls={`aniimo-filter-${key}`} onClick={() => setCollapsed((current) => ({ ...current, [key]: !current[key] }))}>
|
||||
<span>{content[key]}</span>
|
||||
<span className="aniimo-selected-count" aria-hidden="true">{(key === "abilities" ? Object.keys(filters.abilities).length : filters[key].length) || ""}</span>
|
||||
<Icon name={collapsed[key] ? "chevron-down" : "chevron-up"} />
|
||||
</button></legend>
|
||||
<div id={`aniimo-filter-${key}`} hidden={collapsed[key]}>
|
||||
{key === "elements" && <LogicChoice label={content[key]} content={content} value={filters.elementsLogic} onChange={(logic) => onChange({ ...filters, elementsLogic: logic })} />}
|
||||
{key === "abilities" && <div className="filter-logic">
|
||||
<span>{content.levelMode}</span>
|
||||
<div className="filter-logic-group nds-radio-button-group" data-size="xs" role="group" aria-label={content.levelMode}>
|
||||
<button type="button" className={!filters.abilityExact ? "active" : ""} aria-label={content.minimum} title={content.minimum} aria-pressed={!filters.abilityExact} onClick={() => onChange({ ...filters, abilityExact: false })}><LevelOperatorIcon /></button>
|
||||
<button type="button" className={filters.abilityExact ? "active" : ""} aria-label={content.exactLevel} title={content.exactLevel} aria-pressed={filters.abilityExact} onClick={() => onChange({ ...filters, abilityExact: true })}><LevelOperatorIcon exact /></button>
|
||||
</div>
|
||||
</div>}
|
||||
<div className={`aniimo-filter-options ${key === "abilities" ? "aniimo-ability-options" : "aniimo-chip-options"}`} role="region" aria-label={content[key]}>
|
||||
{(key === "abilities" ? abilityOptions : options[key]).map((option) => {
|
||||
const isAbility = key === "abilities";
|
||||
const rangeId = `aniimo-minimum-${option}`;
|
||||
if (isAbility) {
|
||||
const level = filters.abilities[option] || 0;
|
||||
return <div key={option} className="aniimo-ability-filter" data-ability-group={options.elements.includes(option) ? "elements" : "other"} data-active={level > 0 || undefined}>
|
||||
<label htmlFor={rangeId}><img src={aniimoAsset(option)} alt="" width="18" height="18" /><span>{t(option)}</span></label>
|
||||
<input id={rangeId} className="nds-range" data-size="sm" type="range" min="0" max="4" step="1" value={level} aria-label={`${t(option)} — ${filters.abilityExact ? content.exactLevel : content.minimum}`} aria-valuetext={level ? `${filters.abilityExact ? content.exactLevel : content.minimum} ${level}` : content.abilityDisabled} onChange={(event) => {
|
||||
const abilities = { ...filters.abilities };
|
||||
const minimum = Number(event.target.value);
|
||||
if (minimum > 0) abilities[option] = minimum;
|
||||
else delete abilities[option];
|
||||
onChange({ ...filters, abilities });
|
||||
}} />
|
||||
<span className="aniimo-minimum-value" aria-hidden="true">{level}</span>
|
||||
</div>;
|
||||
}
|
||||
const selected = filters[key].includes(option);
|
||||
return (
|
||||
<label key={option} className={`filter-chip nds-chip ${selected ? "active" : ""}`} data-size="sm">
|
||||
<input className="nds-checkbox" data-size="sm" type="checkbox" checked={selected} onChange={(event) => toggle(key, option, event.target.checked)} />
|
||||
<img src={aniimoAsset(option)} alt="" width="16" height="16" />
|
||||
<span>{t(option)}</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
<div className="nds-filter-group nds-filter-advanced-options">
|
||||
<button className={`aniimo-prismana-filter nds-filter-option ${filters.prismanaOnly ? "active" : ""}`} type="button" aria-label={content.prismanaOnly} aria-pressed={filters.prismanaOnly} onClick={() => onChange({ ...filters, prismanaOnly: !filters.prismanaOnly })}>
|
||||
<img src="/static/icons/prismana.svg" alt="" width="16" height="16" />
|
||||
<span className="nds-filter-option-label">{content.prismana}</span>
|
||||
</button>
|
||||
<GameFilterDropdown label={content.roles} count={filters.roles.length} icon="shield" columns={2}>
|
||||
{() => <FilterCheckboxOptions filterKey="roles" label={content.roles} values={options.roles} selected={filters.roles} t={t} onToggle={toggle} />}
|
||||
</GameFilterDropdown>
|
||||
<GameFilterDropdown label={content.elements} count={filters.elements.length} icon="fire" columns={2}>
|
||||
{() => (
|
||||
<fieldset className="nds-filter-menu-fieldset">
|
||||
<legend className="sr-only">{content.elements}</legend>
|
||||
<LogicChoice label={content.elements} content={content} value={filters.elementsLogic} onChange={(logic) => onChange({ ...filters, elementsLogic: logic })} />
|
||||
<FilterCheckboxOptions filterKey="elements" label={content.elements} values={options.elements} selected={filters.elements} t={t} onToggle={toggle} />
|
||||
</fieldset>
|
||||
)}
|
||||
</GameFilterDropdown>
|
||||
<GameFilterDropdown className="aniimo-abilities-dropdown" label={content.abilities} triggerLabel="Compétences" count={Object.keys(filters.abilities).length} icon="home" align="end" menuClassName="aniimo-abilities-menu">
|
||||
{() => (
|
||||
<fieldset className="nds-filter-menu-fieldset">
|
||||
<legend className="sr-only">{content.abilities}</legend>
|
||||
<div className="filter-logic nds-filter-logic">
|
||||
<span>{content.levelMode}</span>
|
||||
<div className="filter-logic-group nds-radio-button-group" data-size="xs" role="group" aria-label={content.levelMode}>
|
||||
<button type="button" className={!filters.abilityExact ? "active" : ""} aria-label={content.minimum} title={content.minimum} aria-pressed={!filters.abilityExact} onClick={() => onChange({ ...filters, abilityExact: false })}><LevelOperatorIcon /></button>
|
||||
<button type="button" className={filters.abilityExact ? "active" : ""} aria-label={content.exactLevel} title={content.exactLevel} aria-pressed={filters.abilityExact} onClick={() => onChange({ ...filters, abilityExact: true })}><LevelOperatorIcon exact /></button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="aniimo-filter-options aniimo-ability-options" role="region" aria-label={content.abilities}>
|
||||
<AbilityFilterColumn label={content.elements} group="elements" options={elementAbilities} filters={filters} t={t} content={content} onChange={updateAbility} />
|
||||
<AbilityFilterColumn label={content.abilityActions} group="actions" options={actionAbilities} filters={filters} t={t} content={content} onChange={updateAbility} />
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
))}
|
||||
)}
|
||||
</GameFilterDropdown>
|
||||
</div>
|
||||
<button className="filter-reset-button nds-icon-button nds-filter-reset" data-size="xs" type="button" title={content.reset} aria-label={content.reset} onClick={() => onChange({ ...createAniimoFilters(), grouped: filters.grouped })}><Icon name="rubber" /></button>
|
||||
<ActiveFilterBadges items={activeBadges} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function FilterCheckboxOptions({ filterKey, label, values, selected, t, onToggle }) {
|
||||
return (
|
||||
<div className="nds-filter-menu-options aniimo-filter-options aniimo-chip-options" role="region" aria-label={label}>
|
||||
{values.map((option) => (
|
||||
<label key={option} className={`filter-chip nds-chip nds-filter-menu-option ${selected.includes(option) ? "active" : ""}`} data-size="sm">
|
||||
<input className="nds-checkbox" data-size="sm" type="checkbox" checked={selected.includes(option)} onChange={(event) => onToggle(filterKey, option, event.target.checked)} />
|
||||
<img src={aniimoAsset(option)} alt="" width="16" height="16" />
|
||||
<span>{t(option)}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AbilityFilterColumn({ label, group, options, filters, t, content, onChange }) {
|
||||
return (
|
||||
<div className="aniimo-ability-column" role="group" aria-label={label}>
|
||||
<div className="aniimo-ability-list">
|
||||
{options.map((option) => {
|
||||
const rangeId = `aniimo-minimum-${option}`;
|
||||
const level = filters.abilities[option] || 0;
|
||||
return <div key={option} className="aniimo-ability-filter" data-ability-group={group} data-active={level > 0 || undefined}>
|
||||
<label htmlFor={rangeId}><img src={aniimoAsset(option)} alt="" width="18" height="18" /><span>{t(option)}</span></label>
|
||||
<input id={rangeId} className="nds-range" data-size="sm" type="range" min="0" max="4" step="1" value={level} aria-label={`${t(option)} — ${filters.abilityExact ? content.exactLevel : content.minimum}`} aria-valuetext={level ? `${filters.abilityExact ? content.exactLevel : content.minimum} ${level}` : content.abilityDisabled} onChange={(event) => onChange(option, Number(event.target.value))} />
|
||||
<span className="aniimo-minimum-value" aria-hidden="true">{level}</span>
|
||||
</div>;
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export function Diablo4Filters({ options, filters, setFilters }) {
|
|||
getOptionLabel={getCategoryLabel}
|
||||
getOptionClassName={(option) => `diablo4-filter-chip tone-${option.tone || "default"}`}
|
||||
renderOptionMedia={(option) => <span className="diablo4-category-icon" aria-hidden="true" style={getCategoryIconStyle(option)} />}
|
||||
variant="horizontal-menu"
|
||||
onChange={(nextFilters) => setFilters((state) => ({ ...state, diablo4: nextFilters }))}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export function MhwildsFilters({ category, filterKey, options, filters, setFilte
|
|||
options={options}
|
||||
getOptionLabel={(option) => t(option, { capitalize: true })}
|
||||
renderOptionMedia={(option) => <img src={assetPath(option)} alt="" />}
|
||||
variant="horizontal-compact"
|
||||
onChange={(nextFilters) => setFilters((state) => ({ ...state, [category]: nextFilters }))}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import { ToastPositionSwitch } from "../../components/ToastPositionSwitch.jsx";
|
|||
import { useGroupedReorder } from "../../hooks/useGroupedReorder.js";
|
||||
import { useInlineEdit } from "../../hooks/useInlineEdit.js";
|
||||
import { compressImage } from "../../utils/imageCompression.js";
|
||||
import { getSetting as dbGetSetting, setSetting as dbSetSetting } from "../../utils/indexedDbStorage.js";
|
||||
import { getGameCardCover, ToolboxCard, ToolboxGameIcon, ToolboxIconPicker } from "./ToolboxCard.jsx";
|
||||
import { AddToolControls, ToolboxModules } from "./modules/index.jsx";
|
||||
import {
|
||||
|
|
@ -37,7 +36,11 @@ import {
|
|||
uid
|
||||
} from "./storage/toolboxStorage.js";
|
||||
|
||||
const DRAWER_WIDTH_SETTING = "drawerWidth";
|
||||
const DRAWER_INITIAL_WIDTH = 700;
|
||||
|
||||
function getDrawerMaxWidth() {
|
||||
return Math.max(DRAWER_INITIAL_WIDTH, Math.floor(window.innerWidth * 0.94));
|
||||
}
|
||||
|
||||
function addModuleToOrder(moduleOrder, modules, moduleId) {
|
||||
const order = normalizeModuleOrder(moduleOrder, modules);
|
||||
|
|
@ -347,19 +350,16 @@ export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, act
|
|||
const guideChecklist = checklist.available && checklist.guideId.split("/")[0] === gameId ? checklist : undefined;
|
||||
const selectedId = links[gameId] || "";
|
||||
const toolbox = toolboxes.find((item) => item.id === selectedId);
|
||||
const [width, setWidth] = useState("");
|
||||
const [width, setWidth] = useState(DRAWER_INITIAL_WIDTH);
|
||||
const panelRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
dbGetSetting(DRAWER_WIDTH_SETTING, "")
|
||||
.then((storedWidth) => {
|
||||
if (cancelled) return;
|
||||
const value = Number(storedWidth);
|
||||
if (Number.isFinite(value) && value > 0) setWidth(Math.min(Math.max(value, 360), Math.floor(window.innerWidth * 0.94)));
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => { cancelled = true; };
|
||||
const clampToViewport = () => {
|
||||
if (window.innerWidth < DRAWER_INITIAL_WIDTH) return;
|
||||
setWidth((currentWidth) => Math.min(currentWidth, getDrawerMaxWidth()));
|
||||
};
|
||||
window.addEventListener("resize", clampToViewport);
|
||||
return () => window.removeEventListener("resize", clampToViewport);
|
||||
}, []);
|
||||
|
||||
function startResize(event) {
|
||||
|
|
@ -368,13 +368,11 @@ export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, act
|
|||
event.preventDefault();
|
||||
const startX = event.clientX;
|
||||
const startWidth = panel.getBoundingClientRect().width;
|
||||
const minWidth = 360;
|
||||
const maxWidth = Math.floor(window.innerWidth * 0.94);
|
||||
const maxWidth = getDrawerMaxWidth();
|
||||
document.body.classList.add("is-resizing-drawer");
|
||||
const onMove = (moveEvent) => {
|
||||
const nextWidth = Math.min(Math.max(startWidth + startX - moveEvent.clientX, minWidth), maxWidth);
|
||||
const nextWidth = Math.min(Math.max(startWidth + startX - moveEvent.clientX, DRAWER_INITIAL_WIDTH), maxWidth);
|
||||
setWidth(nextWidth);
|
||||
dbSetSetting(DRAWER_WIDTH_SETTING, Math.round(nextWidth)).catch(() => {});
|
||||
};
|
||||
const stop = () => {
|
||||
document.body.classList.remove("is-resizing-drawer");
|
||||
|
|
@ -388,10 +386,9 @@ export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, act
|
|||
}
|
||||
|
||||
return (
|
||||
<aside className="drawer" id="toolbox-drawer" aria-hidden="false" style={width ? { "--drawer-panel-width": `${width}px` } : undefined}>
|
||||
<div className="drawer-backdrop" onClick={() => actions.setDrawerGameId("")} />
|
||||
<aside className="drawer" id="toolbox-drawer" aria-hidden="false" style={{ "--drawer-panel-width": `${width}px` }}>
|
||||
<span className="drawer-resize-handle nds-drawer-resize-handle" aria-hidden="true" onPointerDown={startResize} />
|
||||
<section className="drawer-panel nds-drawer-panel legacy-scrollbar" ref={panelRef} style={width ? { width } : undefined}>
|
||||
<section className="drawer-panel nds-drawer-panel legacy-scrollbar" ref={panelRef}>
|
||||
<div className="drawer-content">
|
||||
<header>
|
||||
<div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue