mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
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.
This commit is contained in:
@@ -1,33 +1,44 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Minus, Quote, Search, Square, X } from 'lucide-react'
|
||||
import { useId, useState } from 'react'
|
||||
import { Frame, Minus, Quote, Shapes, Spline, Sparkles, Square, Sticker, Type, type LucideIcon } from 'lucide-react'
|
||||
import type { BookElement, BookPageSetup, BookShapeId } from '@trek/shared'
|
||||
import { useStudioStore } from '../../store/studioStore'
|
||||
import { FRAME_SHAPES, HOLED_SHAPES, SHAPE_GROUPS } from './shapes'
|
||||
import { BOOK_GRIDS as GRIDS, bookElementId, bookShapeSize, bookGridElements as gridElements, defaultBookGridBox as defaultGridBox } from '@trek/shared'
|
||||
import { shapeTile } from './shapeOutline'
|
||||
import { StudioLineShelf } from './StudioLineShelf'
|
||||
import { PanelHead } from './StudioPanelHead'
|
||||
import { FEATURED_ICONS, iconComponent, iconLabel, searchIcons } from './iconLibrary'
|
||||
import '../../styles/studio-elements.css'
|
||||
import { PanelHead, Shelf } from './StudioPanelHead'
|
||||
import { StudioTabPanel, StudioTabs } from './StudioTabs'
|
||||
import { StudioStickersPanel } from './StudioStickersPanel'
|
||||
import { StudioIconShelf } from './sidebar/StudioIconShelf'
|
||||
import { FRAME_STYLE_OPTIONS, type FrameStyle } from './studioOptions'
|
||||
import { StudioTextStyles } from './StudioTextStyles'
|
||||
import type { ShelfSource } from './textStylesModel'
|
||||
|
||||
/**
|
||||
* Everything you can add that does not come from the journey: type, shapes,
|
||||
* picture frames, photo grids and the icon set.
|
||||
* lines, picture frames and grids, the icon set and the stickers.
|
||||
*
|
||||
* Four tabs rather than four more entries on the rail. They are all the same
|
||||
* kind of answer to "what do I put on this page", and a rail long enough to
|
||||
* hold them separately stops being faster to hit than a word would be.
|
||||
* One panel with six tabs rather than six entries on the rail. They are all
|
||||
* the same kind of answer to "what do I put on this page", and a rail long
|
||||
* enough to hold them separately stops being faster to hit than a word would
|
||||
* be. The stickers were a rail section of their own until the rebuild; they
|
||||
* are one more kind of thing to add, so they sit here beside the icons.
|
||||
*/
|
||||
|
||||
// The book's own ids, the ones the layouts and the assistant mint (shared/src/book/book-ids.ts).
|
||||
const uid = bookElementId
|
||||
|
||||
/** How many icons the grid draws at a time. Two screens' worth at four across. */
|
||||
const ICON_PAGE = 120
|
||||
type Tab = 'text' | 'shapes' | 'lines' | 'frames' | 'icons' | 'stickers'
|
||||
|
||||
type FrameStyle = 'none' | 'polaroid' | 'white' | 'shadow' | 'film' | 'tape'
|
||||
/** The tabs, three to a row: a word under each icon, so the longest of them keeps its cell. */
|
||||
const TABS: readonly { id: Tab; icon: LucideIcon; labelKey: string }[] = [
|
||||
{ id: 'text', icon: Type, labelKey: 'journey.studio.text' },
|
||||
{ id: 'shapes', icon: Shapes, labelKey: 'journey.studio.shapes' },
|
||||
{ id: 'lines', icon: Spline, labelKey: 'journey.studio.lines' },
|
||||
{ id: 'frames', icon: Frame, labelKey: 'journey.studio.frames' },
|
||||
{ id: 'icons', icon: Sparkles, labelKey: 'journey.studio.icons' },
|
||||
{ id: 'stickers', icon: Sticker, labelKey: 'journey.studio.stickers' },
|
||||
]
|
||||
|
||||
/**
|
||||
* A shape as a tile.
|
||||
@@ -78,103 +89,34 @@ function FrameStyleGlyph({ style }: { style: FrameStyle }) {
|
||||
}}
|
||||
>
|
||||
<span className="st-frame-glyph-photo" style={{ inset: `${pad}px ${pad}px ${bottom}px ${pad}px` }} />
|
||||
{/* Both strips, because both is what gets placed — a preview showing one
|
||||
{/* Both strips, because both is what gets placed: a preview showing one
|
||||
made the second one look like a bug the first time it appeared. */}
|
||||
{style === 'tape' && <><em className="st-frame-glyph-tape" /><em className="st-frame-glyph-tape is-right" /></>}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
function IconCell({ name, onPick }: { name: string; onPick: (name: string) => void }) {
|
||||
const Icon = iconComponent(name)
|
||||
return (
|
||||
<button type="button"
|
||||
className="st-shape-btn is-glyph"
|
||||
onClick={() => onPick(name)}
|
||||
aria-label={name}
|
||||
title={iconLabel(name)}
|
||||
>
|
||||
<Icon strokeWidth={1.7} />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/** A plain text style: size, weight, its sample words and anything else it sets. */
|
||||
type AddText = (size: number, weight: 400 | 500 | 600 | 700, sample: string, extra?: Partial<BookElement>) => void
|
||||
|
||||
/** The type tab: the four plain styles, then the lockups of the Text styles shelf. */
|
||||
function TextTab({ page, source, t, addText }: {
|
||||
page: BookPageSetup
|
||||
source: ShelfSource
|
||||
t: (k: string) => string
|
||||
addText: AddText
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<div className="st-section">
|
||||
<div className="st-section-label">{t('journey.studio.text')}</div>
|
||||
<div className="st-stack">
|
||||
<button type="button" className="st-tile" onClick={() => addText(30, 700, t('journey.studio.sampleHeading'))}>
|
||||
<span style={{ fontSize: 19, fontWeight: 700, letterSpacing: '-0.02em' }}>
|
||||
{t('journey.studio.styleTitle')}
|
||||
</span>
|
||||
</button>
|
||||
<button type="button" className="st-tile" onClick={() => addText(16, 600, t('journey.studio.sampleSubheading'))}>
|
||||
<span style={{ fontSize: 14, fontWeight: 600 }}>{t('journey.studio.styleSubtitle')}</span>
|
||||
</button>
|
||||
<button type="button" className="st-tile" onClick={() => addText(10, 400, t('journey.studio.sampleBody'))}>
|
||||
<span style={{ fontSize: 12.5 }}>{t('journey.studio.styleBody')}</span>
|
||||
</button>
|
||||
<button type="button"
|
||||
className="st-tile"
|
||||
onClick={() => addText(7.5, 600, t('journey.studio.sampleCaption'), { tracking: 0.14, color: '#8a8578' })}
|
||||
>
|
||||
<span style={{ fontSize: 10.5, fontWeight: 600, letterSpacing: '0.14em', textTransform: 'uppercase' }}>
|
||||
{t('journey.studio.styleCaption')}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<StudioTextStyles page={page} source={source} t={t} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function StudioElementsPanel({ page, t, source }: {
|
||||
page: BookPageSetup
|
||||
t: (k: string) => string
|
||||
/** The journal, for the year and the point a lockup is filled with. */
|
||||
source: ShelfSource
|
||||
}) {
|
||||
const [tab, setTab] = useState<'text' | 'shapes' | 'frames' | 'grids' | 'icons'>('text')
|
||||
const [iconQuery, setIconQuery] = useState('')
|
||||
/*
|
||||
* How much of the library is on screen.
|
||||
*
|
||||
* 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 two 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.
|
||||
*/
|
||||
const [iconLimit, setIconLimit] = useState(ICON_PAGE)
|
||||
const iconTail = useRef<HTMLDivElement>(null)
|
||||
/**
|
||||
* What every tab places, and where: centred on the page that is open, across
|
||||
* both pages of a spread or on the one page of a cover.
|
||||
*/
|
||||
function useElementAdders(page: BookPageSetup) {
|
||||
const addElement = useStudioStore(s => s.addElement)
|
||||
const commit = useStudioStore(s => s.commit)
|
||||
const select = useStudioStore(s => s.select)
|
||||
const active = useStudioStore(s => s.activeSpread)
|
||||
const doc = useStudioStore(s => s.doc)
|
||||
const spread = doc?.spreads[active]
|
||||
const single = !!spread && spread.role !== 'inner'
|
||||
const role = useStudioStore(s => s.doc?.spreads[s.activeSpread]?.role)
|
||||
const single = role !== undefined && role !== 'inner'
|
||||
|
||||
const centre = (w: number, h: number) => {
|
||||
const W = single ? page.pageWidth : page.pageWidth * 2
|
||||
return { x: (W - w) / 2, y: (page.pageHeight - h) / 2, w, h }
|
||||
}
|
||||
|
||||
const addText = (size: number, weight: 400 | 500 | 600 | 700, sample: string, extra: Partial<BookElement> = {}) =>
|
||||
const addText: AddText = (size, weight, sample, extra = {}) =>
|
||||
addElement(active, {
|
||||
id: uid('t'), kind: 'text', frame: centre(page.pageWidth * 0.7, size * 0.5 + 8),
|
||||
rotation: 0, opacity: 1, locked: false,
|
||||
@@ -205,7 +147,7 @@ export function StudioElementsPanel({ page, t, source }: {
|
||||
: own ? centre(own.w, own.h)
|
||||
: centre(wide ? side * 1.7 : side, tall ? side * 1.35 : wide ? side * 0.55 : side),
|
||||
rotation: 0, opacity: 1, locked: false,
|
||||
// A rule is a shape too — a hairline box rather than its own element type,
|
||||
// A rule is a shape too: a hairline box rather than its own element type,
|
||||
// so it moves, colours and snaps like everything else on the page.
|
||||
shape: isRule ? 'rect' : shape,
|
||||
fill: opts.outline ? null : '#141414',
|
||||
@@ -218,11 +160,9 @@ export function StudioElementsPanel({ page, t, source }: {
|
||||
}
|
||||
|
||||
/**
|
||||
* An icon, placed as a square.
|
||||
*
|
||||
* Square because that is what it is: unlike a shape, an icon keeps its
|
||||
* proportions inside whatever frame it is given, so a rectangle would only
|
||||
* pad it with air on two sides.
|
||||
* An icon, placed as a square. Unlike a shape, an icon keeps its proportions
|
||||
* inside whatever frame it is given, so a rectangle would only pad it with
|
||||
* air on two sides.
|
||||
*/
|
||||
const addIcon = (name: string) => {
|
||||
const side = Math.min(page.pageWidth, page.pageHeight) * 0.18
|
||||
@@ -247,240 +187,229 @@ export function StudioElementsPanel({ page, t, source }: {
|
||||
} as BookElement)
|
||||
}
|
||||
|
||||
const matchedIcons = useMemo(() => searchIcons(iconQuery), [iconQuery])
|
||||
const shownIcons = useMemo(() => matchedIcons.slice(0, iconLimit), [matchedIcons, iconLimit])
|
||||
/** A block of empty frames, selected as a group so it moves and resizes as one thing straight away. */
|
||||
const addGrid = (grid: (typeof GRIDS)[number]) => {
|
||||
const els = gridElements(grid, defaultGridBox(page, single))
|
||||
commit(d => ({
|
||||
...d,
|
||||
spreads: d.spreads.map((sp, i) => (i !== active ? sp : { ...sp, elements: [...sp.elements, ...els] })),
|
||||
}))
|
||||
select(els.map(e => e.id))
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 tell us when they
|
||||
* meet costs nothing per frame.
|
||||
*/
|
||||
useEffect(() => {
|
||||
const tail = iconTail.current
|
||||
if (!tail) return
|
||||
const io = new IntersectionObserver(entries => {
|
||||
if (entries.some(e => e.isIntersecting)) setIconLimit(n => n + ICON_PAGE)
|
||||
})
|
||||
io.observe(tail)
|
||||
return () => io.disconnect()
|
||||
}, [shownIcons.length, matchedIcons.length])
|
||||
return { active, single, addElement, addText, addShape, addIcon, addFrame, addGrid }
|
||||
}
|
||||
|
||||
type Adders = ReturnType<typeof useElementAdders>
|
||||
|
||||
/** The type tab: the plain styles and the big quotation mark, then the lockups of the Text styles shelf. */
|
||||
function TextTab({ page, source, t, addText }: {
|
||||
page: BookPageSetup
|
||||
source: ShelfSource
|
||||
t: (k: string) => string
|
||||
addText: AddText
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Shelf label={t('journey.studio.text')}>
|
||||
<div className="st-stack">
|
||||
<button type="button" className="st-tile" onClick={() => addText(30, 700, t('journey.studio.sampleHeading'))}>
|
||||
<span style={{ fontSize: 19, fontWeight: 700, letterSpacing: '-0.02em' }}>
|
||||
{t('journey.studio.styleTitle')}
|
||||
</span>
|
||||
</button>
|
||||
<button type="button" className="st-tile" onClick={() => addText(16, 600, t('journey.studio.sampleSubheading'))}>
|
||||
<span style={{ fontSize: 14, fontWeight: 600 }}>{t('journey.studio.styleSubtitle')}</span>
|
||||
</button>
|
||||
<button type="button" className="st-tile" onClick={() => addText(10, 400, t('journey.studio.sampleBody'))}>
|
||||
<span style={{ fontSize: 12.5 }}>{t('journey.studio.styleBody')}</span>
|
||||
</button>
|
||||
<button type="button"
|
||||
className="st-tile"
|
||||
onClick={() => addText(7.5, 600, t('journey.studio.sampleCaption'), { tracking: 0.14, color: '#8a8578' })}
|
||||
>
|
||||
<span style={{ fontSize: 10.5, fontWeight: 600, letterSpacing: '0.14em', textTransform: 'uppercase' }}>
|
||||
{t('journey.studio.styleCaption')}
|
||||
</span>
|
||||
</button>
|
||||
{/* A mark of type rather than a shape: it sets in the face the rest of the page is set in. */}
|
||||
<button type="button"
|
||||
className="st-tile"
|
||||
onClick={() => addText(46, 700, '“', { color: '#c9c2b4', leading: 0.9 })}
|
||||
>
|
||||
<Quote size={16} strokeWidth={1.6} aria-hidden />
|
||||
<span>{t('journey.studio.quoteMark')}</span>
|
||||
</button>
|
||||
</div>
|
||||
</Shelf>
|
||||
|
||||
<StudioTextStyles page={page} source={source} t={t} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** Every shape by its group, the outline-only rectangle first among the basic ones. */
|
||||
function ShapesTab({ addShape, t }: { addShape: Adders['addShape']; t: (k: string) => string }) {
|
||||
return (
|
||||
<>
|
||||
{SHAPE_GROUPS.map(group => (
|
||||
<Shelf key={group.id} label={t(`journey.studio.shapeGroup.${group.id}`)}>
|
||||
<div className="st-shape-grid">
|
||||
{group.id === 'basic' && (
|
||||
<button type="button"
|
||||
className="st-shape-btn"
|
||||
onClick={() => addShape('rect', { outline: true })}
|
||||
title={t('journey.studio.shapeKind.outline')}
|
||||
aria-label={t('journey.studio.shapeKind.outline')}
|
||||
>
|
||||
<Square size={20} strokeWidth={1.1} aria-hidden style={{ opacity: .5 }} />
|
||||
</button>
|
||||
)}
|
||||
{group.shapes.map(shape => (
|
||||
<button type="button"
|
||||
key={shape}
|
||||
className="st-shape-btn is-glyph"
|
||||
onClick={() => addShape(shape)}
|
||||
aria-label={shape}
|
||||
>
|
||||
<ShapeGlyph shape={shape} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Shelf>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
/** Empty frames in their styles and shapes, and the grids that lay several of them out at once. */
|
||||
function FramesTab({ adders, t }: { adders: Adders; t: (k: string) => string }) {
|
||||
return (
|
||||
<>
|
||||
<Shelf label={t('journey.studio.frameStyles')}>
|
||||
<div className="st-shape-grid">
|
||||
{FRAME_STYLE_OPTIONS.map(({ value, labelKey }) => (
|
||||
<button type="button"
|
||||
key={value}
|
||||
className="st-shape-btn is-frame"
|
||||
onClick={() => adders.addFrame(null, value)}
|
||||
title={t(labelKey)}
|
||||
aria-label={t(labelKey)}
|
||||
>
|
||||
<FrameStyleGlyph style={value} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Shelf>
|
||||
|
||||
<Shelf label={t('journey.studio.frameShapes')} hint={t('journey.studio.frameHint')}>
|
||||
<div className="st-shape-grid">
|
||||
{FRAME_SHAPES.map(shape => (
|
||||
<button type="button"
|
||||
key={shape}
|
||||
className="st-shape-btn is-glyph"
|
||||
onClick={() => adders.addFrame(shape === 'rect' ? null : shape)}
|
||||
aria-label={shape}
|
||||
>
|
||||
<ShapeGlyph shape={shape} photo />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Shelf>
|
||||
|
||||
<Shelf label={t('journey.studio.grids')} hint={t('journey.studio.gridHint')}>
|
||||
<div className="st-grid-grid">
|
||||
{GRIDS.map(grid => (
|
||||
<button
|
||||
type="button"
|
||||
key={grid.id}
|
||||
className="st-grid-btn"
|
||||
onClick={() => adders.addGrid(grid)}
|
||||
aria-label={grid.id}
|
||||
title={`${grid.cells.length}`}
|
||||
>
|
||||
{/* The arrangement itself: "hero-two" means nothing until you
|
||||
have seen it, and a diagram is faster to read than a name. */}
|
||||
<span className="st-grid-preview">
|
||||
{grid.cells.map((cell, i) => (
|
||||
<span
|
||||
key={i}
|
||||
style={{
|
||||
left: `${cell.x * 100}%`,
|
||||
top: `${cell.y * 100}%`,
|
||||
width: `${cell.w * 100}%`,
|
||||
height: `${cell.h * 100}%`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</Shelf>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function StudioElementsPanel({ page, t, source }: {
|
||||
page: BookPageSetup
|
||||
t: (k: string) => string
|
||||
/** The journal, for the year and the point a lockup is filled with. */
|
||||
source: ShelfSource
|
||||
}) {
|
||||
const [tab, setTab] = useState<Tab>('text')
|
||||
const tabsId = useId()
|
||||
const adders = useElementAdders(page)
|
||||
|
||||
return (
|
||||
<>
|
||||
<PanelHead label={t('journey.studio.elements')} />
|
||||
|
||||
<div className="st-tabs is-fluid">
|
||||
<button type="button" className={tab === 'text' ? 'is-on' : ''} onClick={() => setTab('text')}>
|
||||
{t('journey.studio.text')}
|
||||
</button>
|
||||
<button type="button" className={tab === 'shapes' ? 'is-on' : ''} onClick={() => setTab('shapes')}>
|
||||
{t('journey.studio.shapes')}
|
||||
</button>
|
||||
<button type="button" className={tab === 'frames' ? 'is-on' : ''} onClick={() => setTab('frames')}>
|
||||
{t('journey.studio.frames')}
|
||||
</button>
|
||||
<button type="button" className={tab === 'grids' ? 'is-on' : ''} onClick={() => setTab('grids')}>
|
||||
{t('journey.studio.grids')}
|
||||
</button>
|
||||
<button type="button" className={tab === 'icons' ? 'is-on' : ''} onClick={() => setTab('icons')}>
|
||||
{t('journey.studio.icons')}
|
||||
</button>
|
||||
</div>
|
||||
<StudioTabs<Tab>
|
||||
idBase={tabsId}
|
||||
label={t('journey.studio.elements')}
|
||||
value={tab}
|
||||
onChange={setTab}
|
||||
columns={3}
|
||||
tabs={TABS.map(x => ({ id: x.id, icon: x.icon, label: t(x.labelKey) }))}
|
||||
/>
|
||||
|
||||
<div className="st-panel-scroll">
|
||||
<StudioTabPanel idBase={tabsId} value={tab} className="st-tab-body">
|
||||
{/*
|
||||
Type first: the plain styles, then the lockups, set titles and marks
|
||||
drawn with the book's own words (StudioTextStyles.tsx).
|
||||
The icons and the stickers carry a search of their own, which sits
|
||||
above their scrolling grid like the Content panel's above its own;
|
||||
the other tabs are short shelves and scroll as they are.
|
||||
*/}
|
||||
{tab === 'text' && <TextTab page={page} source={source} t={t} addText={addText} />}
|
||||
|
||||
{tab === 'shapes' && (
|
||||
<>
|
||||
<div className="st-section">
|
||||
<div className="st-section-label">{t('journey.studio.lines')}</div>
|
||||
<div className="st-shape-grid">
|
||||
<button type="button" className="st-shape-btn" onClick={() => addShape('line')} title={t('journey.studio.shapeKind.line')}>
|
||||
<Minus size={20} strokeWidth={2} />
|
||||
</button>
|
||||
<button type="button"
|
||||
className="st-shape-btn"
|
||||
onClick={() => addShape('rect', { outline: true })}
|
||||
title={t('journey.studio.shapeKind.outline')}
|
||||
>
|
||||
<Square size={20} strokeWidth={1.1} style={{ opacity: .5 }} />
|
||||
</button>
|
||||
<button type="button"
|
||||
className="st-shape-btn"
|
||||
onClick={() => addText(46, 700, '“', { color: '#c9c2b4', leading: 0.9 })}
|
||||
title={t('journey.studio.quoteMark')}
|
||||
>
|
||||
<Quote size={20} strokeWidth={1.6} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<StudioLineShelf page={page} single={single} onAdd={el => addElement(active, el)} t={t} />
|
||||
|
||||
{SHAPE_GROUPS.map(group => (
|
||||
<div className="st-section" key={group.id}>
|
||||
<div className="st-section-label">{t(`journey.studio.shapeGroup.${group.id}`)}</div>
|
||||
<div className="st-shape-grid">
|
||||
{group.shapes.map(shape => (
|
||||
<button type="button"
|
||||
key={shape}
|
||||
className="st-shape-btn is-glyph"
|
||||
onClick={() => addShape(shape)}
|
||||
aria-label={shape}
|
||||
>
|
||||
<ShapeGlyph shape={shape} />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'frames' && (
|
||||
<>
|
||||
<div className="st-section">
|
||||
<div className="st-section-label">{t('journey.studio.frameStyles')}</div>
|
||||
<div className="st-shape-grid">
|
||||
{([
|
||||
['none', 'plainFrame'],
|
||||
['polaroid', 'polaroidFrame'],
|
||||
['white', 'whiteFrame'],
|
||||
['shadow', 'shadowFrame'],
|
||||
['film', 'filmFrame'],
|
||||
['tape', 'tapeFrame'],
|
||||
] as [FrameStyle, string][]).map(([style, key]) => (
|
||||
{tab === 'icons' ? (
|
||||
<StudioIconShelf onPick={adders.addIcon} t={t} />
|
||||
) : tab === 'stickers' ? (
|
||||
<StudioStickersPanel page={page} t={t} />
|
||||
) : (
|
||||
<div className="st-panel-scroll">
|
||||
{tab === 'text' && <TextTab page={page} source={source} t={t} addText={adders.addText} />}
|
||||
{tab === 'shapes' && <ShapesTab addShape={adders.addShape} t={t} />}
|
||||
{tab === 'lines' && (
|
||||
<StudioLineShelf
|
||||
page={page}
|
||||
single={adders.single}
|
||||
onAdd={el => adders.addElement(adders.active, el)}
|
||||
t={t}
|
||||
lead={(
|
||||
<button type="button"
|
||||
key={style}
|
||||
className="st-shape-btn is-frame"
|
||||
onClick={() => addFrame(null, style)}
|
||||
title={t(`journey.studio.${key}`)}
|
||||
aria-label={t(`journey.studio.${key}`)}
|
||||
className="st-shape-btn"
|
||||
onClick={() => adders.addShape('line')}
|
||||
title={t('journey.studio.shapeKind.line')}
|
||||
aria-label={t('journey.studio.shapeKind.line')}
|
||||
>
|
||||
<FrameStyleGlyph style={style} />
|
||||
<Minus size={20} strokeWidth={2} aria-hidden />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="st-section">
|
||||
<div className="st-section-label">{t('journey.studio.frameShapes')}</div>
|
||||
<div className="st-shape-grid">
|
||||
{FRAME_SHAPES.map(shape => (
|
||||
<button type="button"
|
||||
key={shape}
|
||||
className="st-shape-btn is-glyph"
|
||||
onClick={() => addFrame(shape === 'rect' ? null : shape)}
|
||||
aria-label={shape}
|
||||
>
|
||||
<ShapeGlyph shape={shape} photo />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="st-hint" style={{ paddingTop: 8 }}>{t('journey.studio.frameHint')}</p>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{tab === 'grids' && (
|
||||
<div className="st-section">
|
||||
<div className="st-section-label">{t('journey.studio.grids')}</div>
|
||||
<div className="st-grid-grid">
|
||||
{GRIDS.map(grid => (
|
||||
<button
|
||||
type="button"
|
||||
key={grid.id}
|
||||
className="st-grid-btn"
|
||||
onClick={() => {
|
||||
const els = gridElements(grid, defaultGridBox(page, single))
|
||||
commit(d => ({
|
||||
...d,
|
||||
spreads: d.spreads.map((sp, i) =>
|
||||
(i !== active ? sp : { ...sp, elements: [...sp.elements, ...els] })),
|
||||
}))
|
||||
// Selected as a group, so the block can be moved or resized
|
||||
// as one thing straight away rather than cell by cell.
|
||||
select(els.map(e => e.id))
|
||||
}}
|
||||
aria-label={grid.id}
|
||||
title={`${grid.cells.length}`}
|
||||
>
|
||||
{/* The arrangement itself: "hero-two" means nothing until you
|
||||
have seen it, and a diagram is faster to read than a name. */}
|
||||
<span className="st-grid-preview">
|
||||
{grid.cells.map((cell, i) => (
|
||||
<span
|
||||
key={i}
|
||||
style={{
|
||||
left: `${cell.x * 100}%`,
|
||||
top: `${cell.y * 100}%`,
|
||||
width: `${cell.w * 100}%`,
|
||||
height: `${cell.h * 100}%`,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="st-hint" style={{ paddingTop: 8 }}>{t('journey.studio.gridHint')}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{tab === 'icons' && (
|
||||
<div className="st-section">
|
||||
{/*
|
||||
The search sits inside the scroller rather than above the tab
|
||||
strip, unlike the Content panel's: that one filters both of its
|
||||
tabs, this one belongs to a single tab, and hanging it above the
|
||||
strip would make the strip move when you switch away from it.
|
||||
*/}
|
||||
<div className="st-search" style={{ margin: '0 0 10px' }}>
|
||||
<Search size={14} />
|
||||
<input
|
||||
value={iconQuery}
|
||||
onChange={e => { setIconQuery(e.target.value); setIconLimit(ICON_PAGE) }}
|
||||
placeholder={t('journey.studio.searchIcons')}
|
||||
aria-label={t('journey.studio.searchIcons')}
|
||||
spellCheck={false}
|
||||
)}
|
||||
/>
|
||||
{iconQuery && (
|
||||
<button type="button" onClick={() => { setIconQuery(''); setIconLimit(ICON_PAGE) }} aria-label={t('common.clear')}>
|
||||
<X size={13} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{/* The shelf, until somebody searches. */}
|
||||
{!iconQuery && (
|
||||
<>
|
||||
<div className="st-section-label">{t('journey.studio.iconsForTravel')}</div>
|
||||
<div className="st-shape-grid" style={{ marginBottom: 14 }}>
|
||||
{FEATURED_ICONS.map(name => (
|
||||
<IconCell key={name} name={name} onPick={addIcon} />
|
||||
))}
|
||||
</div>
|
||||
<div className="st-section-label">{t('journey.studio.iconsAll')}</div>
|
||||
</>
|
||||
)}
|
||||
<div className="st-shape-grid">
|
||||
{shownIcons.map(name => (
|
||||
<IconCell key={name} name={name} onPick={addIcon} />
|
||||
))}
|
||||
</div>
|
||||
{/* What the observer below watches for. */}
|
||||
{shownIcons.length < matchedIcons.length && <div ref={iconTail} style={{ height: 1 }} />}
|
||||
{!matchedIcons.length && (
|
||||
<p className="st-hint" style={{ paddingTop: 8 }}>{t('journey.studio.noMatches')}</p>
|
||||
)}
|
||||
{tab === 'frames' && <FramesTab adders={adders} t={t} />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</StudioTabPanel>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user