Rotating words: {Next|Now} in titles and text cycles through its choices
Migration 084: site defaults for the motion (slide, flip, fade, type, mirror), direction and seconds per word in Site settings, and a hero's and a block's own. The hero's headline, section and band titles, headings, paragraphs, callouts and quotes rotate; menus, tab titles, search text and emails show the first word; less motion shows it still. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ab8dcdd608
commit
a10ff6d75f
30 changed files with 411 additions and 37 deletions
|
|
@ -55,6 +55,7 @@ import { headingAnchors } from '../lib/contents.ts'
|
|||
import { SITE_NAME } from '../lib/site.ts'
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
import { useReadingMode } from '../lib/readingMode.ts'
|
||||
import { WordMotion, Words } from './RotatingWords.tsx'
|
||||
|
||||
const BODY = 'var(--color-muted)'
|
||||
|
||||
|
|
@ -96,14 +97,15 @@ export default function ContentBlocks({
|
|||
return (
|
||||
<div className={`space-y-6 ${className}`}>
|
||||
{blocks.map((block, index) => (
|
||||
<WordMotion key={block.id ?? index} settings={block.words}>
|
||||
<Block
|
||||
key={block.id ?? index}
|
||||
block={block}
|
||||
accent={accent}
|
||||
anchor={idAt.get(index)}
|
||||
level={levels[index]}
|
||||
presentHref={presentHrefs[index]}
|
||||
/>
|
||||
</WordMotion>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
|
|
@ -191,14 +193,14 @@ function Block({
|
|||
case 'heading':
|
||||
return (
|
||||
<h3 id={anchor} className="text-2xl font-bold" style={{ color: accentText(accent) }}>
|
||||
{text}
|
||||
<Words text={text} />
|
||||
</h3>
|
||||
)
|
||||
|
||||
case 'subheading':
|
||||
return (
|
||||
<h4 id={anchor} className="text-lg font-normal" style={{ color: accentText(accent) }}>
|
||||
{text}
|
||||
<Words text={text} />
|
||||
</h4>
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
The little formatting a content block's text may carry, typed in
|
||||
the admin as plain characters:
|
||||
|
||||
**bold** *italic* [link text](url)
|
||||
**bold** *italic* [link text](url) {Next|Now} (rotating words)
|
||||
a line break keeps its place
|
||||
a blank line starts a new paragraph
|
||||
|
||||
|
|
@ -21,8 +21,9 @@
|
|||
import { Fragment, type CSSProperties, type ReactNode } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { accentText } from '../lib/color.ts'
|
||||
import { RotatingWords } from './RotatingWords.tsx'
|
||||
|
||||
const TOKEN = /\*\*(.+?)\*\*|\*(.+?)\*|\[([^\]]+)\]\(([^)\s]+)\)/g
|
||||
const TOKEN = /\*\*(.+?)\*\*|\*(.+?)\*|\[([^\]]+)\]\(([^)\s]+)\)|\{([^{}|\n]+(?:\|[^{}|\n]+)+)\}/g
|
||||
const SAFE_URL = /^(\/(?!\/)|#|https?:\/\/|mailto:|tel:)/i
|
||||
|
||||
/** External if it has a scheme or starts with //; otherwise it's
|
||||
|
|
@ -83,9 +84,10 @@ function line(text: string, accent: string, key: string): ReactNode[] {
|
|||
for (const match of text.matchAll(TOKEN)) {
|
||||
const at = match.index ?? 0
|
||||
if (at > last) out.push(text.slice(last, at))
|
||||
const [whole, bold, italic, label, url] = match
|
||||
const [whole, bold, italic, label, url, words] = match
|
||||
const k = `${key}-${n++}`
|
||||
if (bold != null) out.push(<strong key={k} className="font-semibold">{bold}</strong>)
|
||||
if (words != null) out.push(<RotatingWords key={k} words={words.split('|').map((word) => word.trim())} />)
|
||||
else if (bold != null) out.push(<strong key={k} className="font-semibold">{bold}</strong>)
|
||||
else if (italic != null) out.push(<em key={k}>{italic}</em>)
|
||||
else if (label != null && SAFE_URL.test(url)) {
|
||||
out.push(
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ import { documentTitle } from "../lib/site.ts";
|
|||
import { accentText, ACCENTS, BRAND } from '../lib/color.ts'
|
||||
import { SectionNav, useActiveSection } from "./admin/SectionNav.tsx";
|
||||
import "./PageShell.css";
|
||||
import { Words } from "./RotatingWords.tsx"
|
||||
import { firstWords } from "../lib/words.ts";
|
||||
|
||||
|
||||
export type ShellSection = {
|
||||
|
|
@ -97,7 +99,7 @@ export function Section({ section }: { section: ShellSection }) {
|
|||
<div className="flex flex-wrap items-end justify-between gap-4">
|
||||
<div>
|
||||
<h2 className="text-3xl md:text-4xl font-bold" style={{ color: accentText(accent) }}>
|
||||
{title}
|
||||
<Words text={title} />
|
||||
</h2>
|
||||
{blurb && <p className="mt-2 text-muted max-w-xl">{blurb}</p>}
|
||||
</div>
|
||||
|
|
@ -188,7 +190,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
return () => ro.disconnect();
|
||||
}, [sideNav]);
|
||||
const navSections = sideNav
|
||||
? sections.filter((s) => !s.unlisted).map((s) => ({ id: s.id, label: s.title, accent: s.accent }))
|
||||
? sections.filter((s) => !s.unlisted).map((s) => ({ id: s.id, label: firstWords(s.title), accent: s.accent }))
|
||||
: [];
|
||||
const active = useActiveSection(navSections);
|
||||
const activeAccent = sections.find((s) => s.id === active)?.accent;
|
||||
|
|
@ -279,7 +281,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
// comes from the server (pageMeta.js), which also sets the page's
|
||||
// description and preview for search and link sharing.
|
||||
useEffect(() => {
|
||||
if (typeof title === "string") document.title = documentTitle(title);
|
||||
if (typeof title === "string") document.title = documentTitle(firstWords(title));
|
||||
}, [title]);
|
||||
|
||||
// The thin solid banner between sections, the page's full width
|
||||
|
|
@ -299,7 +301,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
<div className="pt-24 pb-12 px-6">
|
||||
<div className="max-w-6xl mx-auto">
|
||||
<h1 className="text-4xl sm:text-5xl md:text-6xl font-bold [overflow-wrap:anywhere] hyphens-auto" style={{ color: accentText(BRAND) }}>
|
||||
{title}
|
||||
{typeof title === "string" ? <Words text={title} /> : title}
|
||||
</h1>
|
||||
{intro && <p className="mt-3 text-lg text-muted max-w-2xl">{intro}</p>}
|
||||
</div>
|
||||
|
|
|
|||
94
src/components/RotatingWords.css
Normal file
94
src/components/RotatingWords.css
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/* Rotating words (RotatingWords.tsx): every word in one grid cell,
|
||||
so the space is the longest word's; the current one 'in', the one
|
||||
it replaced 'out', the rest 'idle' (hidden). */
|
||||
|
||||
.rotating-words {
|
||||
display: inline-block;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.rotating-words-stack {
|
||||
display: inline-grid;
|
||||
/* Room for descenders, and clipped so a sliding word comes in from
|
||||
behind the line, not over the one above. */
|
||||
padding-bottom: 0.08em;
|
||||
overflow: hidden;
|
||||
perspective: 600px;
|
||||
}
|
||||
|
||||
.rotating-word {
|
||||
grid-area: 1 / 1;
|
||||
white-space: nowrap;
|
||||
transition:
|
||||
transform 0.55s cubic-bezier(0.2, 0.7, 0.2, 1),
|
||||
opacity 0.55s ease;
|
||||
backface-visibility: hidden;
|
||||
}
|
||||
|
||||
.rotating-word[data-state="idle"] {
|
||||
opacity: 0;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
/* slide */
|
||||
.rotating-words[data-motion="slide"][data-direction="top"] .rotating-word[data-state="idle"] {
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
.rotating-words[data-motion="slide"][data-direction="top"] .rotating-word[data-state="out"] {
|
||||
transform: translateY(100%);
|
||||
opacity: 0;
|
||||
}
|
||||
.rotating-words[data-motion="slide"][data-direction="bottom"] .rotating-word[data-state="idle"] {
|
||||
transform: translateY(100%);
|
||||
}
|
||||
.rotating-words[data-motion="slide"][data-direction="bottom"] .rotating-word[data-state="out"] {
|
||||
transform: translateY(-100%);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* flip: like a card turning over on its horizontal edge */
|
||||
.rotating-words[data-motion="flip"][data-direction="top"] .rotating-word[data-state="idle"] {
|
||||
transform: rotateX(90deg);
|
||||
}
|
||||
.rotating-words[data-motion="flip"][data-direction="top"] .rotating-word[data-state="out"] {
|
||||
transform: rotateX(-90deg);
|
||||
opacity: 0;
|
||||
}
|
||||
.rotating-words[data-motion="flip"][data-direction="bottom"] .rotating-word[data-state="idle"] {
|
||||
transform: rotateX(-90deg);
|
||||
}
|
||||
.rotating-words[data-motion="flip"][data-direction="bottom"] .rotating-word[data-state="out"] {
|
||||
transform: rotateX(90deg);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* mirror: turning on its upright, the new word coming round from behind */
|
||||
.rotating-words[data-motion="mirror"] .rotating-word[data-state="idle"] {
|
||||
transform: rotateY(-180deg);
|
||||
}
|
||||
.rotating-words[data-motion="mirror"] .rotating-word[data-state="out"] {
|
||||
transform: rotateY(180deg);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* fade, and type (the letters appear; the old word fades) */
|
||||
.rotating-words[data-motion="fade"] .rotating-word[data-state="out"],
|
||||
.rotating-words[data-motion="type"] .rotating-word[data-state="out"] {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.rotating-words-caret {
|
||||
display: inline-block;
|
||||
width: 0.08em;
|
||||
height: 0.9em;
|
||||
margin-left: 0.04em;
|
||||
vertical-align: -0.08em;
|
||||
background: currentColor;
|
||||
animation: rotating-words-blink 1s steps(1) infinite;
|
||||
}
|
||||
|
||||
@keyframes rotating-words-blink {
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
117
src/components/RotatingWords.tsx
Normal file
117
src/components/RotatingWords.tsx
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
ROTATING WORDS
|
||||
|
||||
A word that cycles through choices in place, typed into any title
|
||||
or text as {Next|Now|Rising}: the hero's headline, a section's
|
||||
title, a heading or a paragraph (InlineText.tsx parses the braces).
|
||||
|
||||
How it moves comes from the nearest WordMotion (the hero's or a
|
||||
block's own settings) over the site's defaults (Site settings →
|
||||
Animated words, window.__SITE__.words):
|
||||
|
||||
motion slide, flip, fade, type or mirror
|
||||
direction where a sliding or flipping word comes from: top
|
||||
or bottom
|
||||
seconds how long each word shows
|
||||
|
||||
The space it takes is the longest word's, every word stacked in
|
||||
one grid cell, so the line never jumps. With less motion (the
|
||||
system's setting, or reading mode) it's the first word, still;
|
||||
screen readers always get the first word, not a changing one.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react'
|
||||
|
||||
import { prefersLessMotion } from '../lib/motion.ts'
|
||||
import { WORD_DEFAULTS, type WordSettings } from '../lib/site.ts'
|
||||
import { WORD_GROUP } from '../lib/words.ts'
|
||||
import './RotatingWords.css'
|
||||
|
||||
/* Settings for the words inside: a hero's or a block's (blank keeps
|
||||
what's around it). */
|
||||
const WordContext = createContext<WordSettings>(WORD_DEFAULTS)
|
||||
|
||||
/* Blank (null) keeps what's around it. */
|
||||
type WordOverrides = { motion?: WordSettings['motion'] | null; direction?: WordSettings['direction'] | null; seconds?: number | null }
|
||||
|
||||
export function WordMotion({ settings, children }: { settings?: WordOverrides | null; children: ReactNode }) {
|
||||
const around = useContext(WordContext)
|
||||
const value = {
|
||||
motion: settings?.motion || around.motion,
|
||||
direction: settings?.direction || around.direction,
|
||||
seconds: settings?.seconds || around.seconds,
|
||||
}
|
||||
return <WordContext.Provider value={value}>{children}</WordContext.Provider>
|
||||
}
|
||||
|
||||
/** A text with its groups as rotating words, the rest as it is. */
|
||||
export function Words({ text }: { text?: string | null }) {
|
||||
const parts: ReactNode[] = []
|
||||
const source = text ?? ''
|
||||
let last = 0
|
||||
let n = 0
|
||||
for (const match of source.matchAll(WORD_GROUP)) {
|
||||
const at = match.index ?? 0
|
||||
if (at > last) parts.push(source.slice(last, at))
|
||||
parts.push(<RotatingWords key={n++} words={match[1].split('|').map((word) => word.trim())} />)
|
||||
last = at + match[0].length
|
||||
}
|
||||
if (last < source.length) parts.push(source.slice(last))
|
||||
return <>{parts}</>
|
||||
}
|
||||
|
||||
const TYPE_STEP_MS = 70
|
||||
|
||||
export function RotatingWords({ words }: { words: string[] }) {
|
||||
const { motion, direction, seconds } = useContext(WordContext)
|
||||
const [index, setIndex] = useState(0)
|
||||
const [still, setStill] = useState(true)
|
||||
// For 'type': how many letters of the current word show.
|
||||
const [typed, setTyped] = useState(words[0]?.length ?? 0)
|
||||
|
||||
useEffect(() => {
|
||||
if (prefersLessMotion() || words.length < 2) return undefined
|
||||
setStill(false)
|
||||
const timer = window.setInterval(() => setIndex((i) => (i + 1) % words.length), Math.max(1, seconds) * 1000)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [words.length, seconds])
|
||||
|
||||
// Typing: the word appears a letter at a time.
|
||||
useEffect(() => {
|
||||
if (still || motion !== 'type') return undefined
|
||||
setTyped(0)
|
||||
const word = words[index] ?? ''
|
||||
let shown = 0
|
||||
const timer = window.setInterval(() => {
|
||||
shown += 1
|
||||
setTyped(shown)
|
||||
if (shown >= word.length) window.clearInterval(timer)
|
||||
}, TYPE_STEP_MS)
|
||||
return () => window.clearInterval(timer)
|
||||
}, [index, motion, still, words])
|
||||
|
||||
if (still) return <>{words[0]}</>
|
||||
|
||||
return (
|
||||
<span className="rotating-words" data-motion={motion} data-direction={direction}>
|
||||
<span className="sr-only">{words[0]}</span>
|
||||
<span className="rotating-words-stack" aria-hidden="true">
|
||||
{words.map((word, i) => {
|
||||
const state = i === index ? 'in' : i === (index + words.length - 1) % words.length ? 'out' : 'idle'
|
||||
return (
|
||||
<span key={i} className="rotating-word" data-state={state}>
|
||||
{motion === 'type' && i === index ? (
|
||||
<>
|
||||
{word.slice(0, typed)}
|
||||
<span className="rotating-words-caret" />
|
||||
</>
|
||||
) : (
|
||||
word
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
})}
|
||||
</span>
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
|
@ -346,6 +346,45 @@ export const HREF_HELP = {
|
|||
video: "The video's page, eg. https://www.youtube.com/watch?v=…, or a video file",
|
||||
};
|
||||
|
||||
/* Rotating words (084): text typed as {Next|Now|Rising} cycles
|
||||
through its choices. These pick how, for a block or a hero; Site
|
||||
settings → Animated words holds the defaults. */
|
||||
export const WORD_MOTIONS = [
|
||||
["slide", "Slide"],
|
||||
["flip", "Flip, like a card"],
|
||||
["fade", "Fade"],
|
||||
["type", "Type, letter by letter"],
|
||||
["mirror", "Mirror, turning round"],
|
||||
];
|
||||
export const WORD_DIRECTIONS = [
|
||||
["bottom", "From the bottom"],
|
||||
["top", "From the top"],
|
||||
];
|
||||
export const WORD_HELP = "Type choices in braces to rotate them, eg. {Next|Now|Rising} Generation of {Unity|New Thought}.";
|
||||
|
||||
/* The three fields, under `prefix` (eg. "hero."), shown `when`. */
|
||||
export const wordFields = (prefix: string, label: string, when?: any) => [
|
||||
{
|
||||
path: `${prefix}word_motion`,
|
||||
label: label ? `${label}rotating words` : "Rotating words",
|
||||
widget: "select",
|
||||
options: WORD_MOTIONS,
|
||||
blankLabel: "Default: the site's (Site settings → Animated words)",
|
||||
help: WORD_HELP,
|
||||
when,
|
||||
},
|
||||
{
|
||||
path: `${prefix}word_direction`,
|
||||
label: label ? `${label}words come in` : "Words come in",
|
||||
widget: "select",
|
||||
options: WORD_DIRECTIONS,
|
||||
blankLabel: "Default: the site's",
|
||||
help: "For Slide and Flip",
|
||||
when,
|
||||
},
|
||||
{ path: `${prefix}word_seconds`, label: label ? `${label}seconds per word` : "Seconds per word", widget: "number", help: "1 to 20. Default: the site's", when },
|
||||
];
|
||||
|
||||
export const blocksChild = {
|
||||
key: "content_blocks",
|
||||
label: "Content blocks",
|
||||
|
|
@ -441,6 +480,7 @@ export const blocksChild = {
|
|||
help: "Shows the team's members as tiles, its leads first. People added as items show after it.",
|
||||
when: { path: "type", value: "people" },
|
||||
},
|
||||
...wordFields("", "", { path: "type", value: ["heading", "subheading", "paragraph", "callout", "quote"] }),
|
||||
],
|
||||
children: [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
every page offers them all. The Community blog's settings show on
|
||||
the Community page only (its id), for now. */
|
||||
|
||||
import { FEATURED_KINDS, featuredCardsChild, blocksChild } from "./shared.ts";
|
||||
import { FEATURED_KINDS, featuredCardsChild, blocksChild, wordFields } from "./shared.ts";
|
||||
import { mediaUrl } from "../media.ts";
|
||||
import { PATH_ICONS } from "../../data/pathIcons.ts";
|
||||
|
||||
|
|
@ -146,6 +146,7 @@ const BAND_FIELDS = [
|
|||
help: "For the Featured event feature. A pinned event that's over falls back to the countdown's",
|
||||
when: IS("hero"),
|
||||
},
|
||||
...wordFields("hero.", "Hero: ", IS("hero")),
|
||||
{
|
||||
path: "countdown.event_id",
|
||||
label: "Count down to",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import siteConfiguration from "../../../site.json";
|
||||
import { mediaUrl } from "../media.ts";
|
||||
import { THEME_DEFAULTS } from "../../../server/src/themeDefaults.js";
|
||||
import { WORD_DIRECTIONS, WORD_HELP, WORD_MOTIONS } from "./shared.ts";
|
||||
|
||||
/* ── Site settings (035_site_settings.sql) ───────────────────────
|
||||
Overrides for site.json, superadmins only: every blank falls back
|
||||
|
|
@ -158,6 +159,15 @@ export const siteSettings = {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Animated words",
|
||||
note: WORD_HELP + " Works in the hero's headline, section titles, headings and paragraphs. These are the defaults; a hero or a block can set its own. Visitors who ask for less motion see the first word, still.",
|
||||
fields: [
|
||||
{ path: "word_motion", label: "Motion", widget: "select", options: WORD_MOTIONS, blankLabel: "Default: Slide" },
|
||||
{ path: "word_direction", label: "Words come in", widget: "select", options: WORD_DIRECTIONS, blankLabel: "Default: from the bottom", help: "For Slide and Flip" },
|
||||
{ path: "word_seconds", label: "Seconds per word", widget: "number", help: "1 to 20. Default: 3" },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Notices",
|
||||
fields: [
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { useCallback } from 'react'
|
|||
|
||||
import { useSitePageHeadings } from './useSitePages.ts'
|
||||
import { UNLISTED_PRESETS } from '../pages/sections/Bands.tsx'
|
||||
import { firstWords } from '../lib/words.ts'
|
||||
|
||||
export type NavSection = { label: string; hash: string }
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ export function useNavSections(): (path: string) => NavSection[] {
|
|||
(path: string) =>
|
||||
(sitePages?.[path] ?? [])
|
||||
.filter((section) => !UNLISTED_PRESETS.includes(section.preset ?? ''))
|
||||
.map((section) => ({ label: section.title, hash: `#${section.anchor}` })),
|
||||
.map((section) => ({ label: firstWords(section.title), hash: `#${section.anchor}` })),
|
||||
[sitePages],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
import { readableOn } from './color.ts'
|
||||
import { PLATFORMS } from './platforms.ts'
|
||||
import { firstWords } from '../lib/words.ts'
|
||||
|
||||
export type NewsletterItem = {
|
||||
title: string
|
||||
|
|
@ -186,7 +187,8 @@ const imageTag = (src: string, alt: string) =>
|
|||
`<img src="${escape(src)}" width="552" alt="${escape(alt)}" style="display:block;margin:0 auto;width:100%;max-width:552px;height:auto;border:0;">`
|
||||
|
||||
function blockHtml(block: NewsletterPart, n: Newsletter): string {
|
||||
const text = block.text?.trim() ?? ''
|
||||
// An email can't animate: rotating words ({Next|Now}) are their first.
|
||||
const text = firstWords(block.text).trim()
|
||||
const href = block.href ? safeHref(block.href, n) : null
|
||||
const items = block.items ?? []
|
||||
const align = alignOf(block)
|
||||
|
|
@ -412,7 +414,7 @@ export function newsletterHtml(n: Newsletter): string {
|
|||
}
|
||||
|
||||
function blockText(block: NewsletterPart, n: Newsletter): string[] {
|
||||
const text = block.text?.trim() ?? ''
|
||||
const text = firstWords(block.text).trim()
|
||||
const items = block.items ?? []
|
||||
const link = (url: string) => safeHref(url, n) ?? url
|
||||
switch (block.type) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ export type Hero = {
|
|||
video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null
|
||||
/** With the 'event' feature: the pinned event, else the page's countdown's. */
|
||||
event: HeroEvent | null
|
||||
/** Its rotating words' own motion (084), else the site's. */
|
||||
words?: { motion?: any; direction?: any; seconds?: number | null } | null
|
||||
}
|
||||
|
||||
export type SectionStat = {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@
|
|||
|
||||
import siteConfiguration from '../../site.json'
|
||||
|
||||
type SiteText = { title?: string; requestFiles?: boolean }
|
||||
/** How rotating words move (RotatingWords.tsx, 084). */
|
||||
export type WordSettings = { motion: 'slide' | 'flip' | 'fade' | 'type' | 'mirror'; direction: 'top' | 'bottom'; seconds: number }
|
||||
|
||||
type SiteText = { title?: string; requestFiles?: boolean; words?: Partial<WordSettings> | null }
|
||||
|
||||
/* What the server wrote into the page, if it did. */
|
||||
const fromServer: SiteText =
|
||||
|
|
@ -33,6 +36,14 @@ export const SITE_NAME: string = fromServer.title || siteConfiguration.title
|
|||
|
||||
export const SITE_ORIGIN: string = siteConfiguration.url
|
||||
|
||||
/** Rotating words' defaults: Site settings → Animated words, else
|
||||
* sliding up from the bottom, three seconds a word. */
|
||||
export const WORD_DEFAULTS: WordSettings = {
|
||||
motion: fromServer.words?.motion || 'slide',
|
||||
direction: fromServer.words?.direction || 'bottom',
|
||||
seconds: fromServer.words?.seconds || 3,
|
||||
}
|
||||
|
||||
/** Whether the Request form takes files (Google Drive is set up on
|
||||
* the server). Unknown (the Vite dev server) offers them, and the
|
||||
* server says so if it can't. */
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import type { EventSeries } from './eventSeries.ts'
|
|||
export type ContentBlock = {
|
||||
id?: number | string
|
||||
slot?: 'card' | 'body'
|
||||
/** Its rotating words' own motion (084), else the site's. */
|
||||
words?: { motion?: any; direction?: any; seconds?: number | null } | null
|
||||
type:
|
||||
| 'heading'
|
||||
| 'subheading'
|
||||
|
|
|
|||
10
src/lib/words.ts
Normal file
10
src/lib/words.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/* Rotating words as plain text (src/components/RotatingWords.tsx
|
||||
draws them moving): a group typed as {Next|Now|Rising}. */
|
||||
|
||||
/** {A|B} groups in a text. */
|
||||
export const WORD_GROUP = /\{([^{}|\n]+(?:\|[^{}|\n]+)+)\}/g
|
||||
|
||||
/** The text as plain words, each group its first choice: for menus,
|
||||
* tab titles, emails and anywhere that can't move. */
|
||||
export const firstWords = (text?: string | null): string =>
|
||||
(text ?? '').replace(WORD_GROUP, (_, group: string) => group.split('|')[0].trim())
|
||||
|
|
@ -44,6 +44,7 @@ import CommunityBlog from './sections/CommunityBlog.tsx'
|
|||
import HistoryTimeline from './sections/history/HistoryTimeline.tsx'
|
||||
import { DirectoryTabs, DIRECTORY_PREVIEW } from './sections/PeopleDirectory.tsx'
|
||||
import { DataRequestSection, FeedbackSection, GivingSection, QrSection, RequestSection } from './sections/FormSections.tsx'
|
||||
import { Words } from '../components/RotatingWords.tsx'
|
||||
|
||||
/* Year the program starts: decades ending before it get the
|
||||
pre-program look on the timeline. */
|
||||
|
|
@ -235,7 +236,9 @@ function PlainBand({ section }: { section: SitePageSection }) {
|
|||
return (
|
||||
<section id={section.anchor} className="py-24">
|
||||
<div className="mx-auto mb-12 max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{section.title}</h2>
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">
|
||||
<Words text={section.title} />
|
||||
</h2>
|
||||
{section.blurb && <p className="mt-3 max-w-xl text-lg text-muted">{section.blurb}</p>}
|
||||
</div>
|
||||
<SectionBody
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
import EventCalendar from '../EventCalendar.tsx'
|
||||
import RequestLink from '../../../components/RequestLink.tsx'
|
||||
import { Words } from '../../../components/RotatingWords.tsx'
|
||||
|
||||
type CalendarBandProps = { id: string; title: string; blurb?: string | null }
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ export default function CalendarBand({ id, title, blurb }: CalendarBandProps) {
|
|||
<div className="mx-auto mb-10 flex max-w-6xl flex-wrap items-end justify-between gap-4 px-6">
|
||||
<div>
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">
|
||||
{title}
|
||||
<Words text={title} />
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-xl text-lg text-muted">{blurb}</p>}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
import FeaturedCards from '../../../components/FeaturedCards.tsx'
|
||||
import type { FeaturedCard, FeaturedColumns } from '../../../lib/sectionTypes.ts'
|
||||
import { Words } from '../../../components/RotatingWords.tsx'
|
||||
|
||||
type FeaturedBandProps = {
|
||||
id: string
|
||||
|
|
@ -22,7 +23,7 @@ export default function FeaturedBand({ id, title, blurb, cards, columns }: Featu
|
|||
return (
|
||||
<section id={id} className="py-24">
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{title}</h2>
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl"><Words text={title} /></h2>
|
||||
{blurb && <p className="mt-4 max-w-2xl text-lg text-muted">{blurb}</p>}
|
||||
<div className="mt-12">
|
||||
<FeaturedCards cards={cards} columns={columns ?? undefined} />
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import { MONTH_LABELS, type TimelineItem } from '../../../lib/timeline.ts'
|
|||
import { accentText, BRAND } from '../../../lib/color.ts'
|
||||
import { scrollBehavior } from '../../../lib/motion.ts';
|
||||
import { useReadingMode } from '../../../lib/readingMode.ts'
|
||||
import { Words } from '../../../components/RotatingWords.tsx'
|
||||
|
||||
const DRAG_SLOP = 6
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ export default function FeaturedTimelineRail({ id, title, blurb }: RailProps) {
|
|||
if (reading) {
|
||||
return (
|
||||
<section id={id}>
|
||||
<h2>{title}</h2>
|
||||
<h2><Words text={title} /></h2>
|
||||
{blurb && <p>{blurb}</p>}
|
||||
{error ? (
|
||||
<p>Couldn’t load the timeline. {error}</p>
|
||||
|
|
@ -104,7 +105,7 @@ export default function FeaturedTimelineRail({ id, title, blurb }: RailProps) {
|
|||
<div className="mx-auto flex max-w-6xl flex-wrap items-end gap-6 px-6">
|
||||
<div>
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">
|
||||
{title}
|
||||
<Words text={title} />
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-xl text-lg text-muted">{blurb}</p>}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@ import { useReadingMode } from '../../../lib/readingMode.ts'
|
|||
import { eventHref } from '../../../lib/hrefs.ts'
|
||||
import { seriesLabel } from '../../../lib/eventSeries.ts'
|
||||
import type { Hero, HeroBackdrop, HeroEvent, HeroFeature, HeroSlide } from '../../../lib/sectionTypes.ts'
|
||||
import { WordMotion, Words as RotatingText } from '../../../components/RotatingWords.tsx'
|
||||
import { firstWords } from '../../../lib/words.ts'
|
||||
|
||||
const DEEP = '#001011'
|
||||
|
||||
|
|
@ -187,7 +189,9 @@ function Words({ hero, feature }: { hero: Hero; feature: HeroFeature }) {
|
|||
} [overflow-wrap:anywhere]`}
|
||||
style={{ animationDelay: '60ms' }}
|
||||
>
|
||||
{hero.headline}
|
||||
<WordMotion settings={hero.words}>
|
||||
<RotatingText text={hero.headline} />
|
||||
</WordMotion>
|
||||
</h1>
|
||||
|
||||
{hero.subhead && (
|
||||
|
|
@ -226,7 +230,7 @@ function ReadingHero({ hero, feature, slides, video }: ReadingHeroProps) {
|
|||
return (
|
||||
<>
|
||||
{feature === 'none' && hero.eyebrow && <p>{hero.eyebrow}</p>}
|
||||
<h1>{hero.headline}</h1>
|
||||
<h1>{firstWords(hero.headline)}</h1>
|
||||
{hero.subhead && <p>{hero.subhead}</p>}
|
||||
{[hero.primary, hero.secondary].map(
|
||||
(button) =>
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import HomeLink, { isExternal } from './HomeLink.tsx'
|
|||
import type { SectionPath } from '../../../lib/sectionTypes.ts'
|
||||
import { ACCENTS, accentText, readableOn } from '../../../lib/color.ts'
|
||||
import { useReadingMode } from '../../../lib/readingMode.ts'
|
||||
import { Words } from '../../../components/RotatingWords.tsx'
|
||||
import { firstWords } from '../../../lib/words.ts'
|
||||
|
||||
type PathfinderProps = {
|
||||
id: string
|
||||
|
|
@ -80,7 +82,7 @@ export default function Pathfinder({ id, title, blurb, paths }: PathfinderProps)
|
|||
if (reading) {
|
||||
return (
|
||||
<section id={id}>
|
||||
<h2>{title}</h2>
|
||||
<h2><Words text={title} /></h2>
|
||||
{blurb && <p>{blurb}</p>}
|
||||
{paths.map((option, index) => (
|
||||
<div key={`${option.label}-${index}`}>
|
||||
|
|
@ -131,14 +133,14 @@ export default function Pathfinder({ id, title, blurb, paths }: PathfinderProps)
|
|||
return (
|
||||
<section id={id} className="py-24">
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{title}</h2>
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl"><Words text={title} /></h2>
|
||||
{blurb && <p className="mt-4 max-w-2xl text-lg text-muted">{blurb}</p>}
|
||||
|
||||
<div className="mt-12 overflow-hidden shadow-md">
|
||||
<div className="-mr-[4px] -mb-[4px]">
|
||||
<div
|
||||
role="tablist"
|
||||
aria-label={title}
|
||||
aria-label={firstWords(title)}
|
||||
aria-orientation="horizontal"
|
||||
className="grid sm:grid-cols-2 lg:grid-cols-[repeat(var(--paths),minmax(0,1fr))]"
|
||||
style={{ '--paths': Math.min(paths.length, 5) } as CSSProperties}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import { useEffect, useRef, useState } from 'react'
|
|||
import type { SectionStat } from '../../../lib/sectionTypes.ts'
|
||||
import { prefersLessMotion } from '../../../lib/motion.ts'
|
||||
import { useReadingMode } from '../../../lib/readingMode.ts'
|
||||
import { Words } from '../../../components/RotatingWords.tsx'
|
||||
|
||||
const COUNT_MS = 1400
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ export default function StatsBand({ id, title, blurb, stats }: StatsBandProps) {
|
|||
if (useReadingMode()) {
|
||||
return (
|
||||
<section id={id}>
|
||||
<h2>{title}</h2>
|
||||
<h2><Words text={title} /></h2>
|
||||
{blurb && <p>{blurb}</p>}
|
||||
<ul>
|
||||
{stats.map((stat, index) => (
|
||||
|
|
@ -74,7 +75,7 @@ export default function StatsBand({ id, title, blurb, stats }: StatsBandProps) {
|
|||
>
|
||||
<div className="relative mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-3xl font-bold text-white md:text-4xl">
|
||||
{title}
|
||||
<Words text={title} />
|
||||
</h2>
|
||||
{blurb && <p className="mt-3 max-w-2xl text-white/70">{blurb}</p>}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue