Files
TREK/client/src/components/Studio/sidebar/StudioIconShelf.tsx
T
Maurice bdf5767a5f feat(studio): rebuild both side panels around one head, one row and one order
The rail lists its sections in the order a book is made: Pages, Content,
Layouts, Elements and Travel, then Theme and Layers set apart below a rule.
Stickers are a tab of Elements beside the icons instead of a rail section of
their own, and Elements has six tabs (text, shapes, lines, frames with the
grids, icons, stickers). The quotation mark moved to the text styles, the
outline rectangle to the basic shapes and the plain rule to the lines. The rail
and every tab row are tab lists the arrow keys walk through, and a long name
wraps instead of being cut. The icon and sticker searches say in the field how
many match, which the sticker library's own head used to.

Every panel on both sides opens on the same head, and every labelled control
uses one row that moves the control under its label when the two do not fit,
so no label sits in a fixed column any more. Number fields, chips, sliders,
tab labels, theme names and travel cards wrap the same way, a country beside
a stop wraps under itself, and an upload cell holds its words to two lines
with the whole label in its tooltip. The heads, shelves and groups are real
headings, so a screen reader can walk the panels by them.

The inspector shows every kind in one order: what the element is and says,
its position and size, its look, its effects, then Arrange. Align and the
stacking buttons are one Arrange group with a button that opens the page in
Layers; its rows sit under their labels, each in two sets that move to a
second line whole. Rarely used groups start folded and open on an element
that already uses them (a turned element, a map held at a zoom, a summary set
in another face), and every group mounts afresh for the next selection. A
sticker's duplicate angle and opacity are gone in favour of the shared
position group, which now has the turn buttons for every kind. With several
elements selected it keeps their angle, opacity and turn, and the mirror when
all of them are stickers, and leaves the frame's numbers to one element. A
photo's fill page and fill spread sit under its crop. With nothing selected
the inspector shows the page background, the book's theme with the way to the
Theme panel, and the page numbers.

Seventeen translation keys nothing has used since before the rebuild (the old
inspector title, the empty spread note, the summary and country list names,
the roads buttons and others) are gone from every language. The broad key
template the old panels used had counted them as reached; the format names,
the empty photo grid messages and the map source hints are now named where the
key check can read them.

Also fixed on the way: the travel stops list shared its class with the
gradient stops and was laid out as sixteen pixel handles; the alignment
buttons were named in raw English; the map's print resolution note joined its
two halves with a dash.
2026-10-24 03:08:27 +00:00

99 lines
3.4 KiB
TypeScript

import { useEffect, useMemo, useRef, useState } from 'react';
import { FEATURED_ICONS, iconComponent, iconLabel, searchIcons } from '../iconLibrary';
import { Shelf } from '../StudioPanelHead';
import { StudioSearch } from '../StudioSearch';
/**
* The icon library, as the Icons tab of the Elements panel: a shelf of icons
* for travel, then all fourteen hundred, and a search over their names.
*
* Fourteen hundred icons is fourteen hundred React components, each a
* forwardRef around several SVG nodes, and rendering them all costs about a
* second of blocked main thread on the first click of the tab, for a grid
* whose first rows are all anybody sees. So it grows as it is scrolled, and a
* search resets it: the results of a search are short, and starting them
* part-drawn would be wrong.
*/
/** How many icons the grid draws at a time. Two screens' worth at three across. */
const ICON_PAGE = 120;
function IconCell({ name, onPick }: { name: string; onPick: (name: string) => void }) {
const Icon = iconComponent(name);
const label = iconLabel(name);
return (
<button
type="button"
className="st-shape-btn is-glyph"
onClick={() => onPick(name)}
aria-label={name}
title={label}
>
<Icon strokeWidth={1.7} />
</button>
);
}
export function StudioIconShelf({ onPick, t }: { onPick: (name: string) => void; t: (k: string) => string }) {
const [query, setQuery] = useState('');
const [limit, setLimit] = useState(ICON_PAGE);
const tail = useRef<HTMLDivElement>(null);
const matched = useMemo(() => searchIcons(query), [query]);
const shown = useMemo(() => matched.slice(0, limit), [matched, limit]);
/*
* Grow the grid when its foot comes into view. An observer rather than a
* scroll handler: the panel is the scroller, the foot is the thing that
* matters, and asking the browser to say when they meet costs nothing.
*/
useEffect(() => {
const foot = tail.current;
if (!foot) return;
const io = new IntersectionObserver((entries) => {
if (entries.some((e) => e.isIntersecting)) setLimit((n) => n + ICON_PAGE);
});
io.observe(foot);
return () => io.disconnect();
}, [shown.length, matched.length]);
const search = (value: string) => {
setQuery(value);
setLimit(ICON_PAGE);
};
return (
<>
<StudioSearch
value={query}
onChange={search}
label={t('journey.studio.searchIcons')}
clearLabel={t('common.clear')}
count={matched.length}
/>
<div className="st-panel-scroll">
{/* The shelf, until somebody searches. */}
{!query && (
<Shelf label={t('journey.studio.iconsForTravel')}>
<div className="st-shape-grid">
{FEATURED_ICONS.map((name) => (
<IconCell key={name} name={name} onPick={onPick} />
))}
</div>
</Shelf>
)}
<Shelf label={query ? undefined : t('journey.studio.iconsAll')}>
<div className="st-shape-grid">
{shown.map((name) => (
<IconCell key={name} name={name} onPick={onPick} />
))}
</div>
{/* What the observer above watches for. */}
{shown.length < matched.length && <div ref={tail} className="st-shelf-tail" />}
{!matched.length && <p className="st-hint">{t('journey.studio.noMatches')}</p>}
</Shelf>
</div>
</>
);
}