Files
TREK/client/src/components/Studio/StudioShapePaint.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

140 lines
4.5 KiB
TypeScript

import {
shapePaint,
withShapePaint,
withThemeLinks,
type BookElement,
type BookShapeElement,
type BookTheme,
} from '@trek/shared';
import { shapeOutlineInUse } from './inspector/inspectorModel';
import { usePaintChannel } from './paint/usePaintChannel';
import { Choice, Line, NumField, Section } from './StudioControls';
import { STROKE_STYLE_OPTIONS } from './studioOptions';
import { StudioPaintPicker } from './StudioPaintPicker';
import type { StudioT } from './StudioSidebar';
import { Swatches } from './StudioSwatches';
import { StudioThemeLink } from './theme/StudioThemeLink';
/** The outline a shape is given when its fill goes and it has none, so it never turns invisible. */
const OUTLINE = '#141414';
type SetShape = (patch: Partial<BookShapeElement>) => void;
/**
* A shape's fill, as a paint: none, one colour, a gradient or a pattern.
*
* The fill goes to every selected shape at once, the way the rest of the
* inspector's properties do. Taking the fill away from a shape with no
* outline gives it one, as the old fill switch did: a shape with neither is
* a shape nobody can see or find again.
*/
export function StudioShapeFill({
el,
spreadIndex,
selection,
theme,
set,
t,
}: {
el: BookShapeElement;
spreadIndex: number;
selection: readonly string[];
/** The book's theme, for the theme colours under the paint; none without one. */
theme?: BookTheme;
/** The inspector's write, for linking the fill to the theme. */
set: SetShape;
t: StudioT;
}) {
const channel = usePaintChannel((paint) => (doc) => ({
...doc,
spreads: doc.spreads.map((sp, i) =>
i !== spreadIndex
? sp
: {
...sp,
elements: sp.elements.map((e): BookElement => {
if (e.kind !== 'shape' || !selection.includes(e.id)) return e;
// A paint picked by hand stops the fill following the theme.
const painted = withThemeLinks(withShapePaint(e, paint), { paint }, doc.theme);
return paint === null && !e.stroke
? { ...painted, stroke: OUTLINE, strokeWidth: e.strokeWidth || 0.5 }
: painted;
}),
}
),
}));
return (
<Section label={t('journey.studio.fill')}>
<StudioPaintPicker value={shapePaint(el)} channel={channel} t={t} noneLabel={t('journey.studio.paint.none')} />
<StudioThemeLink
theme={theme}
token={el.token}
t={t}
onLink={(token, fill) => set({ fill, token, paint: undefined })}
onUnlink={() => set({ token: undefined })}
/>
</Section>
);
}
/**
* A shape's outline: its colour, the stroke it is drawn in and how wide.
*
* Folded until the shape has one, since most shapes are a fill and nothing
* else. Every way of asking for an outline brings one: a colour, a width or a
* dash on a shape that had none draws it rather than doing nothing.
*/
export function StudioShapeOutline({
el,
theme,
set,
t,
}: {
el: BookShapeElement;
theme?: BookTheme;
set: SetShape;
t: StudioT;
}) {
const width = el.strokeWidth || 0.5;
return (
<Section label={t('journey.studio.stroke')} defaultOpen={shapeOutlineInUse(el)}>
<Swatches value={el.stroke ?? OUTLINE} onPick={(stroke) => set({ stroke, strokeWidth: width })} />
<StudioThemeLink
theme={theme}
token={el.strokeToken}
t={t}
onLink={(strokeToken, stroke) => set({ stroke, strokeToken, strokeWidth: width })}
onUnlink={() => set({ strokeToken: undefined })}
/>
<div className="st-section-gap">
<Line label={t('journey.studio.strokeStyle')}>
<Choice
value={el.strokeStyle}
ariaLabel={t('journey.studio.strokeStyle')}
options={STROKE_STYLE_OPTIONS.map((o) => ({ value: o.value, label: t(o.labelKey) }))}
onPick={(strokeStyle) =>
set({
strokeStyle,
// A stroke style with no stroke is invisible, so asking for dashes turns the outline on.
...(el.stroke ? {} : { stroke: el.fill ?? OUTLINE, strokeWidth: width }),
})
}
/>
</Line>
</div>
<div className="st-section-gap">
<NumField
label={t('journey.studio.strokeWidth')}
value={el.strokeWidth}
min={0}
max={20}
step={0.1}
unit="mm"
onChange={(v) => set({ strokeWidth: v, ...(v > 0 && !el.stroke ? { stroke: OUTLINE } : {}) })}
/>
</div>
</Section>
);
}