@sincpro/web-ui 2.15.0 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/media/Carousel.d.ts +34 -0
- package/dist/components/media/Carousel.js +148 -0
- package/dist/components/media/OnScroll.d.ts +27 -0
- package/dist/components/media/OnScroll.js +18 -0
- package/dist/components/media/Ribbon.d.ts +39 -0
- package/dist/components/media/Ribbon.js +74 -0
- package/dist/components/media/Rise.d.ts +31 -0
- package/dist/components/media/Rise.js +27 -0
- package/dist/components/media/Stories.d.ts +71 -0
- package/dist/components/media/Stories.js +174 -0
- package/dist/components/media/index.d.ts +5 -0
- package/dist/components/media/index.js +9 -0
- package/dist/components/media/motion.d.ts +7 -0
- package/dist/components/media/motion.js +17 -0
- package/dist/components/navigation/PortalNav.d.ts +49 -0
- package/dist/components/navigation/PortalNav.js +40 -0
- package/dist/components/navigation/index.d.ts +1 -0
- package/dist/components/navigation/index.js +3 -0
- package/dist/components/preview/FilePreview.d.ts +5 -3
- package/dist/components/preview/FilePreview.js +39 -3
- package/dist/components/preview/index.d.ts +1 -1
- package/dist/components/preview/index.js +1 -1
- package/dist/components/preview/previewKind.d.ts +12 -2
- package/dist/components/preview/previewKind.js +44 -2
- package/dist/components/shell/Notifications.d.ts +64 -0
- package/dist/components/shell/Notifications.js +84 -0
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +3 -0
- package/dist/foundations/copy.es.js +35 -0
- package/dist/foundations/uiCopy.d.ts +58 -0
- package/dist/foundations/uiCopy.js +42 -1
- package/dist/primitives/choice/CheckField.d.ts +26 -0
- package/dist/primitives/choice/CheckField.js +45 -0
- package/dist/primitives/choice/index.d.ts +1 -0
- package/dist/primitives/choice/index.js +2 -0
- package/dist/tokens.css +182 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -364,7 +364,13 @@ The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`
|
|
|
364
364
|
`frame`, `frame.banner`, `frame.bar`, `frame.sidebar`, `frame.main`, `banner`, `banner.action`,
|
|
365
365
|
`inbox`, `inbox.item` (with `data-unread`), `kbd`, `plans`, `plan` (with `data-highlight`, `data-current`), `plan.highlight`, `plan.price`,
|
|
366
366
|
`plan.features`, `plan.action`, `qr`, `price`, `price.before`, `range-slider`, `rating`, `gallery`,
|
|
367
|
-
`gallery.main`, `gallery.strip`, `lightbox`, `
|
|
367
|
+
`gallery.main`, `gallery.strip`, `lightbox`, `carousel`, `carousel.track`, `carousel.slide`,
|
|
368
|
+
`carousel.dots`, `rise.line`, `appear`, `draw-on-scroll` (with `data-axis`), `enter-on-scroll`,
|
|
369
|
+
`ribbon` (with `data-moving`, `data-paused`, `data-direction`), `ribbon.viewport`, `ribbon.list`,
|
|
370
|
+
`ribbon.copy`, `story-ring` (with `data-seen`), `story-bar`, `story-viewer`, `story-viewer.progress`,
|
|
371
|
+
`story-viewer.media`, `notification-bell`, `notification-panel`, `notification-panel.group`,
|
|
372
|
+
`notification-panel.item` (with `data-unread`), `portal-nav`, `portal-nav.person`, `portal-nav.toggle`,
|
|
373
|
+
`portal-nav.sections`, `check-field`, `file-preview.video`, `file-preview.audio`, `file-preview.office` (with `data-kind`), `sidebar`, `sidebar.brand`,
|
|
368
374
|
`sidebar.user`, `sidebar.search`, `sidebar.nav`, `sidebar.account`, `navigation`,
|
|
369
375
|
`navigation.item`, `dirty.blocked`, `dirty.bar`, `field`, `field.label`, `form.section`,
|
|
370
376
|
`form.index`, `dock`, `dock.pill`, `dock.bare`, `pager`, `pagination`, `smart`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
|
|
@@ -395,6 +401,35 @@ computed), `Rating` (an average with its figure, or the opinion asked), `Gallery
|
|
|
395
401
|
full-size `Lightbox`), `Inbox` (the bell in `TopBar systray`, or `InboxList` as a page), and
|
|
396
402
|
`Banner` — a notice about the whole application, in `AppFrame banner`.
|
|
397
403
|
|
|
404
|
+
For a public site and a member portal (server-rendered, as in Next.js): `Carousel` (a hero that
|
|
405
|
+
turns, a news strip — scroll-snap, `slidesPerView` by width, autoplay that stops on hover, focus
|
|
406
|
+
and «reduce motion»), the stories (`StoryBar` of `StoryRing`s and the full-screen `StoryViewer`),
|
|
407
|
+
`NotificationBell` with a `NotificationPanel` in any header, `PortalNav` (a portal's menu with
|
|
408
|
+
real links, folded into one button on a phone), and `CheckField` — a yes/no row that lines up in
|
|
409
|
+
`FormSection columns` and is the «settings» row. `FilePreview` plays video and audio with the
|
|
410
|
+
browser's own players and shows Word, Excel and PowerPoint as an «abrir o descargar» card.
|
|
411
|
+
|
|
412
|
+
A site's landing has its own motion — and only a site's page uses it (the register is explained
|
|
413
|
+
under «A SITE'S PAGE» in `tokens.css`): `Rise` (a headline that rises line by line, inside the
|
|
414
|
+
application's own `<h1>`), `Appear step` (what follows it, on the same clock), `DrawOnScroll`
|
|
415
|
+
(a rule or a line drawn by the scroll itself) and `EnterOnScroll` (a section that enters), all
|
|
416
|
+
CSS with no JavaScript; and `Ribbon` (items that pass in a loop, as many copies as the width
|
|
417
|
+
needs, with a pause button). The same motion is open as utilities for an element of the site's
|
|
418
|
+
own — `rise-line`, `appear-in` (with `--motion-step`), `draw-on-scroll-x`, `draw-on-scroll-y`,
|
|
419
|
+
`enter-on-scroll`. Every one is the final state in the HTML, moves only under
|
|
420
|
+
`prefers-reduced-motion: no-preference`, and the scroll-driven ones are simply drawn where the
|
|
421
|
+
browser lacks `animation-timeline`; under reduced motion the ribbon is a row to scroll.
|
|
422
|
+
|
|
423
|
+
```tsx
|
|
424
|
+
<h1 className="font-serif text-6xl">
|
|
425
|
+
<Rise lines={["¿Tu auditor está", "habilitado para ejercer?"]} />
|
|
426
|
+
</h1>
|
|
427
|
+
<Appear step={2} as="p">Verifica en el registro del colegio…</Appear>
|
|
428
|
+
<Ribbon label="Galería del colegio" speed="slow">
|
|
429
|
+
{albums.map((album) => <AlbumCover key={album.id} album={album} />)}
|
|
430
|
+
</Ribbon>
|
|
431
|
+
```
|
|
432
|
+
|
|
398
433
|
#### A form that explains itself: the «settings» style
|
|
399
434
|
|
|
400
435
|
The default form is the dense sheet of an ERP — label | control, two columns, help behind a
|
|
@@ -13,6 +13,7 @@ export * from "./gantt/index.js";
|
|
|
13
13
|
export * from "./guide/index.js";
|
|
14
14
|
export * from "./lines/index.js";
|
|
15
15
|
export * from "./listing/index.js";
|
|
16
|
+
export * from "./media/index.js";
|
|
16
17
|
export * from "./navigation/index.js";
|
|
17
18
|
export * from "./plans/index.js";
|
|
18
19
|
export * from "./preview/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from "./gantt/index.js";
|
|
|
14
14
|
export * from "./guide/index.js";
|
|
15
15
|
export * from "./lines/index.js";
|
|
16
16
|
export * from "./listing/index.js";
|
|
17
|
+
export * from "./media/index.js";
|
|
17
18
|
export * from "./navigation/index.js";
|
|
18
19
|
export * from "./plans/index.js";
|
|
19
20
|
export * from "./preview/index.js";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
type PerView = 1 | 2 | 3 | 4;
|
|
3
|
+
export type CarouselPerView = PerView | Partial<Record<"base" | "sm" | "md" | "lg", PerView>>;
|
|
4
|
+
export type CarouselProps = {
|
|
5
|
+
/** Each child is a slide: a hero's picture, a news card, a product. */
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** What the carousel is, said: «Noticias», «Destacados». */
|
|
8
|
+
label: string;
|
|
9
|
+
/** How many slides are seen at once, by width: `{ base: 1, md: 2, lg: 3 }`. One by default. */
|
|
10
|
+
slidesPerView?: CarouselPerView;
|
|
11
|
+
/** Past the last comes the first (arrows and autoplay). */
|
|
12
|
+
loop?: boolean;
|
|
13
|
+
/** Turns by itself every so many milliseconds. Stops on hover and on focus, has a pause
|
|
14
|
+
* button, and never runs when the person asked for less motion. */
|
|
15
|
+
autoplay?: number;
|
|
16
|
+
/** The dots under it. On by default when there is more than one position. */
|
|
17
|
+
dots?: boolean;
|
|
18
|
+
/** Which slide starts the view, when the application holds it. */
|
|
19
|
+
index?: number;
|
|
20
|
+
onIndexChange?: (next: number) => void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Slides of any content that the person moves — the arrows, the dots, a finger or the
|
|
24
|
+
* mouse dragging, the keyboard — and that may turn by themselves.
|
|
25
|
+
*
|
|
26
|
+
* Context: built on CSS scroll-snap, so a finger swipes with the browser's own physics and
|
|
27
|
+
* the server renders every slide (a search engine reads them; nothing waits for JS). Where
|
|
28
|
+
* the person is, is written for a screen reader («2 de 5» on each slide), never only a dot.
|
|
29
|
+
* Autoplay is a courtesy that yields: a hover, a focus inside, the pause button or the
|
|
30
|
+
* system's «reduce motion» stop it, and while it runs the region is not live — a reader is
|
|
31
|
+
* not interrupted every five seconds.
|
|
32
|
+
*/
|
|
33
|
+
export declare function Carousel({ children, label, slidesPerView, loop, autoplay, dots, index: indexProp, onIndexChange, }: CarouselProps): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useReducedMotion } from "./motion.js";
|
|
4
|
+
import { fillCopy, useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { IconButton } from "../../primitives/button/Button.js";
|
|
6
|
+
import { ChevronLeft, ChevronRight, Pause, Play } from "lucide-react";
|
|
7
|
+
import { Children, useCallback, useEffect, useRef, useState, } from "react";
|
|
8
|
+
/* Written whole so Tailwind sees every class: one table per breakpoint. */
|
|
9
|
+
const BASIS = {
|
|
10
|
+
base: { 1: "basis-full", 2: "basis-1/2", 3: "basis-1/3", 4: "basis-1/4" },
|
|
11
|
+
sm: { 1: "sm:basis-full", 2: "sm:basis-1/2", 3: "sm:basis-1/3", 4: "sm:basis-1/4" },
|
|
12
|
+
md: { 1: "md:basis-full", 2: "md:basis-1/2", 3: "md:basis-1/3", 4: "md:basis-1/4" },
|
|
13
|
+
lg: { 1: "lg:basis-full", 2: "lg:basis-1/2", 3: "lg:basis-1/3", 4: "lg:basis-1/4" },
|
|
14
|
+
};
|
|
15
|
+
/** The class of a slide's width for each breakpoint asked. */
|
|
16
|
+
function slideBasis(perView = 1) {
|
|
17
|
+
const asked = typeof perView === "number" ? { base: perView } : perView;
|
|
18
|
+
return Object.keys(BASIS)
|
|
19
|
+
.flatMap((at) => (asked[at] === undefined ? [] : [BASIS[at][asked[at]]]))
|
|
20
|
+
.join(" ");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Slides of any content that the person moves — the arrows, the dots, a finger or the
|
|
24
|
+
* mouse dragging, the keyboard — and that may turn by themselves.
|
|
25
|
+
*
|
|
26
|
+
* Context: built on CSS scroll-snap, so a finger swipes with the browser's own physics and
|
|
27
|
+
* the server renders every slide (a search engine reads them; nothing waits for JS). Where
|
|
28
|
+
* the person is, is written for a screen reader («2 de 5» on each slide), never only a dot.
|
|
29
|
+
* Autoplay is a courtesy that yields: a hover, a focus inside, the pause button or the
|
|
30
|
+
* system's «reduce motion» stop it, and while it runs the region is not live — a reader is
|
|
31
|
+
* not interrupted every five seconds.
|
|
32
|
+
*/
|
|
33
|
+
export function Carousel({ children, label, slidesPerView = 1, loop = false, autoplay, dots = true, index: indexProp, onIndexChange, }) {
|
|
34
|
+
const copy = useUiCopy();
|
|
35
|
+
const reduced = useReducedMotion();
|
|
36
|
+
const slides = Children.toArray(children);
|
|
37
|
+
const total = slides.length;
|
|
38
|
+
const track = useRef(null);
|
|
39
|
+
const drag = useRef(null);
|
|
40
|
+
const [current, setCurrent] = useState(indexProp ?? 0);
|
|
41
|
+
const [perView, setPerView] = useState(1);
|
|
42
|
+
const [stopped, setStopped] = useState(false);
|
|
43
|
+
const [held, setHeld] = useState(false);
|
|
44
|
+
const last = Math.max(0, total - perView);
|
|
45
|
+
const slideAt = (at) => track.current?.children[at];
|
|
46
|
+
const go = useCallback((next) => {
|
|
47
|
+
const scroller = track.current;
|
|
48
|
+
if (scroller === null)
|
|
49
|
+
return;
|
|
50
|
+
const max = Math.max(0, scroller.children.length - perView);
|
|
51
|
+
const at = loop
|
|
52
|
+
? next > max
|
|
53
|
+
? 0
|
|
54
|
+
: next < 0
|
|
55
|
+
? max
|
|
56
|
+
: next
|
|
57
|
+
: Math.min(max, Math.max(0, next));
|
|
58
|
+
const slide = scroller.children[at];
|
|
59
|
+
if (slide === undefined)
|
|
60
|
+
return;
|
|
61
|
+
scroller.scrollTo({ left: slide.offsetLeft, behavior: reduced ? "auto" : "smooth" });
|
|
62
|
+
}, [loop, perView, reduced]);
|
|
63
|
+
/* Where it is comes from the scroll — whatever moved it: a finger, a wheel, a button. */
|
|
64
|
+
const measure = () => {
|
|
65
|
+
const scroller = track.current;
|
|
66
|
+
const first = slideAt(0);
|
|
67
|
+
if (scroller === null || first === undefined || first.offsetWidth === 0)
|
|
68
|
+
return;
|
|
69
|
+
const step = first.offsetWidth;
|
|
70
|
+
setPerView(Math.max(1, Math.round(scroller.clientWidth / step)));
|
|
71
|
+
const at = Math.round(scroller.scrollLeft / step);
|
|
72
|
+
setCurrent((was) => {
|
|
73
|
+
if (was !== at)
|
|
74
|
+
onIndexChange?.(at);
|
|
75
|
+
return at;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const scroller = track.current;
|
|
80
|
+
if (scroller === null)
|
|
81
|
+
return;
|
|
82
|
+
measure();
|
|
83
|
+
const observer = new ResizeObserver(measure);
|
|
84
|
+
observer.observe(scroller);
|
|
85
|
+
return () => observer.disconnect();
|
|
86
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- measured on mount and resize
|
|
87
|
+
}, []);
|
|
88
|
+
/* A controlled index moves the view, without the smooth scroll on the first paint. */
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (indexProp !== undefined && indexProp !== current)
|
|
91
|
+
go(indexProp);
|
|
92
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- only when the application moves it
|
|
93
|
+
}, [indexProp]);
|
|
94
|
+
const playing = autoplay !== undefined && total > 1 && !reduced && !stopped;
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
if (!playing || held)
|
|
97
|
+
return;
|
|
98
|
+
const timer = window.setInterval(() => {
|
|
99
|
+
go(current >= last ? 0 : current + 1);
|
|
100
|
+
}, autoplay);
|
|
101
|
+
return () => window.clearInterval(timer);
|
|
102
|
+
}, [playing, held, autoplay, current, last, go]);
|
|
103
|
+
const keys = (event) => {
|
|
104
|
+
const step = { ArrowRight: 1, ArrowLeft: -1 }[event.key];
|
|
105
|
+
if (step !== undefined)
|
|
106
|
+
go(current + step);
|
|
107
|
+
else if (event.key === "Home")
|
|
108
|
+
go(0);
|
|
109
|
+
else if (event.key === "End")
|
|
110
|
+
go(last);
|
|
111
|
+
else
|
|
112
|
+
return;
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
};
|
|
115
|
+
/* A finger already swipes the snap; the mouse drags it by hand and lets it snap at the end. */
|
|
116
|
+
const down = (event) => {
|
|
117
|
+
if (event.pointerType !== "mouse" || track.current === null)
|
|
118
|
+
return;
|
|
119
|
+
drag.current = { x: event.clientX, left: track.current.scrollLeft };
|
|
120
|
+
track.current.dataset.dragging = "";
|
|
121
|
+
};
|
|
122
|
+
const move = (event) => {
|
|
123
|
+
if (drag.current === null || track.current === null)
|
|
124
|
+
return;
|
|
125
|
+
track.current.scrollLeft = drag.current.left - (event.clientX - drag.current.x);
|
|
126
|
+
};
|
|
127
|
+
const up = () => {
|
|
128
|
+
const scroller = track.current;
|
|
129
|
+
if (drag.current === null || scroller === null)
|
|
130
|
+
return;
|
|
131
|
+
drag.current = null;
|
|
132
|
+
delete scroller.dataset.dragging;
|
|
133
|
+
const first = slideAt(0);
|
|
134
|
+
if (first !== undefined)
|
|
135
|
+
go(Math.round(scroller.scrollLeft / first.offsetWidth));
|
|
136
|
+
};
|
|
137
|
+
const atStart = !loop && current <= 0;
|
|
138
|
+
const atEnd = !loop && current >= last;
|
|
139
|
+
const positions = last + 1;
|
|
140
|
+
const basis = slideBasis(slidesPerView);
|
|
141
|
+
return (_jsxs("section", { "data-ui": "carousel", "aria-roledescription": copy.carousel.roledescription, "aria-label": label, onKeyDown: keys, onPointerEnter: () => setHeld(true), onPointerLeave: () => setHeld(false), onFocus: () => setHeld(true), onBlur: (event) => {
|
|
142
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
143
|
+
setHeld(false);
|
|
144
|
+
}, className: "group/carousel relative flex min-w-0 flex-col gap-3", children: [_jsxs("div", { className: "relative min-w-0", children: [_jsx("div", { ref: track, "data-ui": "carousel.track",
|
|
145
|
+
/* A scroll box a keyboard can reach (axe: scrollable-region-focusable); its arrows
|
|
146
|
+
move the slides through the section's handler. */
|
|
147
|
+
tabIndex: 0, "aria-live": playing && !held ? "off" : "polite", onScroll: measure, onPointerDown: down, onPointerMove: move, onPointerUp: up, onPointerCancel: up, className: "scroll-quiet -mx-2 flex snap-x rounded-control focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary snap-mandatory data-dragging:cursor-grabbing data-dragging:snap-none data-dragging:select-none", children: slides.map((slide, at) => (_jsx("div", { "data-ui": "carousel.slide", role: "group", "aria-roledescription": copy.carousel.slide, "aria-label": fillCopy(copy.carousel.position, { index: at + 1, total }), className: `min-w-0 shrink-0 snap-start px-2 ${basis}`, children: slide }, at))) }), positions < 2 ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: "absolute top-1/2 left-1 -translate-y-1/2 rounded-pill bg-surface/90 shadow-raised", children: _jsx(IconButton, { icon: ChevronLeft, label: copy.carousel.previous, size: "md", disabled: atStart, onClick: () => go(current - 1) }) }), _jsx("span", { className: "absolute top-1/2 right-1 -translate-y-1/2 rounded-pill bg-surface/90 shadow-raised", children: _jsx(IconButton, { icon: ChevronRight, label: copy.carousel.next, size: "md", disabled: atEnd, onClick: () => go(current + 1) }) })] }))] }), positions < 2 || (!dots && autoplay === undefined) ? null : (_jsxs("div", { className: "flex items-center justify-center gap-2", children: [autoplay === undefined || reduced ? null : (_jsx(IconButton, { icon: stopped ? Play : Pause, label: stopped ? copy.carousel.play : copy.carousel.pause, size: "sm", onClick: () => setStopped((was) => !was) })), !dots ? null : (_jsx("div", { "data-ui": "carousel.dots", className: "flex items-center gap-1", children: Array.from({ length: positions }, (_, at) => (_jsx("button", { type: "button", "aria-label": fillCopy(copy.carousel.goTo, { index: at + 1 }), "aria-current": at === current ? "true" : undefined, onClick: () => go(at), className: "hit-target flex size-4 items-center justify-center rounded-pill focus-visible:outline-2 focus-visible:outline-primary", children: _jsx("span", { "aria-hidden": true, className: `h-2 rounded-pill transition-all duration-(--duration-quick) ${at === current ? "w-4 bg-primary" : "w-2 bg-line-strong"}` }) }, at))) }))] }))] }));
|
|
148
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type DrawOnScrollProps = {
|
|
3
|
+
/** The rule or line drawn: a `Divider`, a bar of the brand's colour, a timeline's line. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** `x` draws from the start edge (a rule under a word), `y` from the top (a timeline). */
|
|
6
|
+
axis?: "x" | "y";
|
|
7
|
+
/** The element it is. `div` by default; `span` inside a line of text. */
|
|
8
|
+
as?: "div" | "span";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A rule or a line drawn by the scroll itself as it comes into view.
|
|
12
|
+
*
|
|
13
|
+
* Context: it scales its own box, so it wraps the line and nothing else — a line that sits
|
|
14
|
+
* absolutely (a timeline's spine) takes the utility on itself instead:
|
|
15
|
+
* `className="draw-on-scroll-y"`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function DrawOnScroll({ children, axis, as: Element, }: DrawOnScrollProps): import("react").JSX.Element;
|
|
18
|
+
export type EnterOnScrollProps = {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
/** The element it is. `div` by default; `li` for an item of a list. */
|
|
21
|
+
as?: "div" | "li" | "section" | "article";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A row of a site's page that enters as it scrolls into view. For a landing's sections —
|
|
25
|
+
* never for a list a person works in, where a row that is not there yet is a row not read.
|
|
26
|
+
*/
|
|
27
|
+
export declare function EnterOnScroll({ children, as: Element }: EnterOnScrollProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A rule or a line drawn by the scroll itself as it comes into view.
|
|
4
|
+
*
|
|
5
|
+
* Context: it scales its own box, so it wraps the line and nothing else — a line that sits
|
|
6
|
+
* absolutely (a timeline's spine) takes the utility on itself instead:
|
|
7
|
+
* `className="draw-on-scroll-y"`.
|
|
8
|
+
*/
|
|
9
|
+
export function DrawOnScroll({ children, axis = "x", as: Element = "div", }) {
|
|
10
|
+
return (_jsx(Element, { "data-ui": "draw-on-scroll", "data-axis": axis, className: axis === "x" ? "draw-on-scroll-x" : "draw-on-scroll-y", children: children }));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A row of a site's page that enters as it scrolls into view. For a landing's sections —
|
|
14
|
+
* never for a list a person works in, where a row that is not there yet is a row not read.
|
|
15
|
+
*/
|
|
16
|
+
export function EnterOnScroll({ children, as: Element = "div" }) {
|
|
17
|
+
return (_jsx(Element, { "data-ui": "enter-on-scroll", className: "enter-on-scroll", children: children }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
declare const SPEED: {
|
|
3
|
+
readonly slow: 24;
|
|
4
|
+
readonly normal: 40;
|
|
5
|
+
readonly fast: 64;
|
|
6
|
+
};
|
|
7
|
+
declare const GAP: {
|
|
8
|
+
readonly sm: "gap-2 pe-2";
|
|
9
|
+
readonly md: "gap-4 pe-4";
|
|
10
|
+
readonly lg: "gap-6 pe-6";
|
|
11
|
+
};
|
|
12
|
+
export type RibbonProps = {
|
|
13
|
+
/** Each child is an item that passes: a cover, a logo, a testimony. */
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
/** What the ribbon is, said: «Galería del colegio», «Confían en nosotros». */
|
|
16
|
+
label: string;
|
|
17
|
+
/** How fast it passes, by distance: slow, normal (default) or fast. */
|
|
18
|
+
speed?: keyof typeof SPEED;
|
|
19
|
+
/** Where it goes: to the left (default) or to the right — two rows that cross. */
|
|
20
|
+
direction?: "left" | "right";
|
|
21
|
+
/** The space between the items. */
|
|
22
|
+
gap?: keyof typeof GAP;
|
|
23
|
+
/** The edges fade instead of cutting. On by default. */
|
|
24
|
+
fade?: boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Items that pass by themselves in a loop: a site's covers, its partners' logos.
|
|
28
|
+
*
|
|
29
|
+
* Context: the list is written once for everyone and repeated only to fill the loop — as
|
|
30
|
+
* many copies as the width needs, measured, so a short list on a wide screen never leaves a
|
|
31
|
+
* hole. The copies are `aria-hidden` and `inert`: a reader hears the list once, Tab stops on
|
|
32
|
+
* each link once. It stops under the pointer, with the focus inside, and with its pause
|
|
33
|
+
* button — a finger has no hover, and something that moves by itself for more than five
|
|
34
|
+
* seconds must be stoppable (WCAG 2.2.2). Under reduced motion, and on the server, it is a
|
|
35
|
+
* row that scrolls by hand: the server cannot know, so it sends the row, and the browser
|
|
36
|
+
* starts it once it has measured.
|
|
37
|
+
*/
|
|
38
|
+
export declare function Ribbon({ children, label, speed, direction, gap, fade, }: RibbonProps): import("react").JSX.Element;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useReducedMotion } from "./motion.js";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { IconButton } from "../../primitives/button/Button.js";
|
|
6
|
+
import { Pause, Play } from "lucide-react";
|
|
7
|
+
import { Children, useLayoutEffect, useRef, useState, } from "react";
|
|
8
|
+
/* Pixels per second. By distance and not by a duration for the whole loop: a ribbon of four
|
|
9
|
+
covers and one of twenty logos then pass at the same pace, the one the eye can follow. */
|
|
10
|
+
const SPEED = { slow: 24, normal: 40, fast: 64 };
|
|
11
|
+
/* The gap is written twice on purpose: between the items, and once more after the last
|
|
12
|
+
(`pe-*`). Every copy is then exactly one period wide, and the track can move one copy and
|
|
13
|
+
start again without a jump — a single row with `gap` lands half a gap off on each turn. */
|
|
14
|
+
const GAP = {
|
|
15
|
+
sm: "gap-2 pe-2",
|
|
16
|
+
md: "gap-4 pe-4",
|
|
17
|
+
lg: "gap-6 pe-6",
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Items that pass by themselves in a loop: a site's covers, its partners' logos.
|
|
21
|
+
*
|
|
22
|
+
* Context: the list is written once for everyone and repeated only to fill the loop — as
|
|
23
|
+
* many copies as the width needs, measured, so a short list on a wide screen never leaves a
|
|
24
|
+
* hole. The copies are `aria-hidden` and `inert`: a reader hears the list once, Tab stops on
|
|
25
|
+
* each link once. It stops under the pointer, with the focus inside, and with its pause
|
|
26
|
+
* button — a finger has no hover, and something that moves by itself for more than five
|
|
27
|
+
* seconds must be stoppable (WCAG 2.2.2). Under reduced motion, and on the server, it is a
|
|
28
|
+
* row that scrolls by hand: the server cannot know, so it sends the row, and the browser
|
|
29
|
+
* starts it once it has measured.
|
|
30
|
+
*/
|
|
31
|
+
export function Ribbon({ children, label, speed = "normal", direction = "left", gap = "md", fade = true, }) {
|
|
32
|
+
const copy = useUiCopy();
|
|
33
|
+
const reduced = useReducedMotion();
|
|
34
|
+
const items = Children.toArray(children);
|
|
35
|
+
const viewport = useRef(null);
|
|
36
|
+
const first = useRef(null);
|
|
37
|
+
const [loop, setLoop] = useState(null);
|
|
38
|
+
const [paused, setPaused] = useState(false);
|
|
39
|
+
const moving = !reduced && loop !== null && items.length > 1;
|
|
40
|
+
/* Measured before paint, again when the width changes (a rotated phone, loaded images). */
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
if (reduced)
|
|
43
|
+
return;
|
|
44
|
+
const view = viewport.current;
|
|
45
|
+
const list = first.current;
|
|
46
|
+
if (view === null || list === null)
|
|
47
|
+
return;
|
|
48
|
+
const measure = () => {
|
|
49
|
+
const period = list.offsetWidth;
|
|
50
|
+
if (period === 0)
|
|
51
|
+
return;
|
|
52
|
+
const copies = Math.max(2, Math.ceil(view.clientWidth / period) + 1);
|
|
53
|
+
const seconds = period / SPEED[speed];
|
|
54
|
+
setLoop((was) => was?.copies === copies && was.seconds === seconds ? was : { copies, seconds });
|
|
55
|
+
};
|
|
56
|
+
measure();
|
|
57
|
+
const observer = new ResizeObserver(measure);
|
|
58
|
+
observer.observe(view);
|
|
59
|
+
observer.observe(list);
|
|
60
|
+
return () => observer.disconnect();
|
|
61
|
+
}, [reduced, speed]);
|
|
62
|
+
const list = (repeat) => (_jsx("ul", { ref: repeat === 0 ? first : undefined, "data-ui": repeat === 0 ? "ribbon.list" : "ribbon.copy", "aria-hidden": repeat === 0 ? undefined : true, inert: repeat !== 0, className: `flex shrink-0 items-stretch ${GAP[gap]}`, children: items.map((item, at) => (_jsx("li", { className: "flex shrink-0 snap-start", children: item }, at))) }, repeat));
|
|
63
|
+
return (_jsxs("section", { "data-ui": "ribbon", "aria-label": label, "data-moving": moving ? "" : undefined, "data-paused": moving && paused ? "" : undefined, "data-direction": direction, className: "relative min-w-0", style: moving && loop !== null
|
|
64
|
+
? {
|
|
65
|
+
"--ribbon-copies": loop.copies,
|
|
66
|
+
"--ribbon-duration": `${loop.seconds}s`,
|
|
67
|
+
}
|
|
68
|
+
: undefined, children: [_jsx("div", { ref: viewport, "data-ui": "ribbon.viewport",
|
|
69
|
+
/* Still, it is a row to scroll — reachable by keyboard (axe:
|
|
70
|
+
scrollable-region-focusable); moving, the pause button is the stop. */
|
|
71
|
+
tabIndex: moving ? undefined : 0, className: `rounded-control focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${moving ? "overflow-clip" : "snap-x overflow-x-auto overscroll-x-contain"} ${fade && moving ? "ribbon-fade" : ""}`, children: _jsxs("div", { className: "ribbon-track", children: [list(0), moving && loop !== null
|
|
72
|
+
? Array.from({ length: loop.copies - 1 }, (_, at) => list(at + 1))
|
|
73
|
+
: null] }) }), !moving ? null : (_jsx("span", { className: "absolute end-3 top-1/2 -translate-y-1/2 rounded-pill bg-surface/90 shadow-raised", children: _jsx(IconButton, { icon: paused ? Play : Pause, label: paused ? copy.ribbon.play : copy.ribbon.pause, size: "sm", onClick: () => setPaused((was) => !was) }) }))] }));
|
|
74
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type RiseProps = {
|
|
3
|
+
/** The headline, one entry per line: each rises in turn. Where it breaks is the
|
|
4
|
+
* application's decision — a line that does not fit still wraps inside its own mask. */
|
|
5
|
+
lines: readonly ReactNode[];
|
|
6
|
+
/** The step of the first line, when something enters before it. 0 by default. */
|
|
7
|
+
start?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A headline that rises line by line from behind its own lower edge — the one moment a
|
|
11
|
+
* site's landing opens with.
|
|
12
|
+
*
|
|
13
|
+
* Context: it draws only the lines, so it goes inside the application's own heading, with
|
|
14
|
+
* the heading's own look: `<h1 className="…"><Rise lines={[…]} /></h1>`. A space is written
|
|
15
|
+
* between the lines: each line is a block, and without it a reader announces «estáhabilitado».
|
|
16
|
+
* Under reduced motion the lines are simply there.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Rise({ lines, start }: RiseProps): import("react").JSX.Element[];
|
|
19
|
+
export type AppearProps = {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
/** Its place in the page's entrance, on the same clock as `Rise`'s lines: after a
|
|
22
|
+
* two-line headline, what follows is step 2, then 3. */
|
|
23
|
+
step?: number;
|
|
24
|
+
/** The element it is. `div` by default. */
|
|
25
|
+
as?: "div" | "span" | "li" | "p";
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* What follows a headline, appearing in its step: the lead, the search box, the call to
|
|
29
|
+
* action.
|
|
30
|
+
*/
|
|
31
|
+
export declare function Appear({ children, step, as: Element }: AppearProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/* No "use client": an entrance is CSS (`rise-line`, `appear-in` in tokens.css). The server
|
|
3
|
+
sends the final state and the browser plays the entrance on its own first paint — there is
|
|
4
|
+
nothing to hydrate and nothing that can differ between the two sides. */
|
|
5
|
+
/** The place of a piece in its page's entrance: 0, 1, 2… on one clock (`--duration-step`). */
|
|
6
|
+
function stepStyle(step) {
|
|
7
|
+
return { "--motion-step": step };
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A headline that rises line by line from behind its own lower edge — the one moment a
|
|
11
|
+
* site's landing opens with.
|
|
12
|
+
*
|
|
13
|
+
* Context: it draws only the lines, so it goes inside the application's own heading, with
|
|
14
|
+
* the heading's own look: `<h1 className="…"><Rise lines={[…]} /></h1>`. A space is written
|
|
15
|
+
* between the lines: each line is a block, and without it a reader announces «estáhabilitado».
|
|
16
|
+
* Under reduced motion the lines are simply there.
|
|
17
|
+
*/
|
|
18
|
+
export function Rise({ lines, start = 0 }) {
|
|
19
|
+
return lines.map((line, at) => (_jsxs("span", { "data-ui": "rise.line", className: "rise-line", style: stepStyle(start + at), children: [_jsx("span", { children: line }), at < lines.length - 1 ? " " : null] }, at)));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* What follows a headline, appearing in its step: the lead, the search box, the call to
|
|
23
|
+
* action.
|
|
24
|
+
*/
|
|
25
|
+
export function Appear({ children, step = 0, as: Element = "div" }) {
|
|
26
|
+
return (_jsx(Element, { "data-ui": "appear", className: "appear-in", style: stepStyle(step), children: children }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type StoryItem = {
|
|
2
|
+
id: string;
|
|
3
|
+
/** An image, or a video played by the browser's own `<video>`. */
|
|
4
|
+
src: string;
|
|
5
|
+
type?: "image" | "video";
|
|
6
|
+
/** What it shows, said. Not optional: a story without words is a hole for a reader. */
|
|
7
|
+
alt: string;
|
|
8
|
+
/** How long an image stays, in milliseconds (5 s by default). A video lasts what it lasts. */
|
|
9
|
+
duration?: number;
|
|
10
|
+
caption?: string;
|
|
11
|
+
/** «Ver la nota», «Inscribirme»: a real link, so it works without JS and opens in place. */
|
|
12
|
+
action?: {
|
|
13
|
+
label: string;
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
when?: Date | string;
|
|
17
|
+
};
|
|
18
|
+
export type StoryPerson = {
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
avatar?: string;
|
|
22
|
+
items: readonly StoryItem[];
|
|
23
|
+
/** Everything already seen: the ring goes quiet. */
|
|
24
|
+
seen?: boolean;
|
|
25
|
+
};
|
|
26
|
+
export type StoryRingProps = {
|
|
27
|
+
name: string;
|
|
28
|
+
avatar?: string;
|
|
29
|
+
/** Seen: a hairline instead of the coloured ring. */
|
|
30
|
+
seen?: boolean;
|
|
31
|
+
onPress?: () => void;
|
|
32
|
+
/** The name under the ring. On by default. */
|
|
33
|
+
showName?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* A person's avatar with the ring that says there is something new.
|
|
37
|
+
*
|
|
38
|
+
* Context: unseen is not only a colour — the ring is thicker and the word is in the
|
|
39
|
+
* button's name («Ana, nuevo»), so it reads the same without colour vision.
|
|
40
|
+
*/
|
|
41
|
+
export declare function StoryRing({ name, avatar, seen, onPress, showName, }: StoryRingProps): import("react").JSX.Element;
|
|
42
|
+
export type StoryBarProps = {
|
|
43
|
+
people: readonly StoryPerson[];
|
|
44
|
+
/** Pressing a ring: the application opens the viewer at that person. */
|
|
45
|
+
onOpen: (personIndex: number) => void;
|
|
46
|
+
};
|
|
47
|
+
/** The row of rings, scrolling sideways — the top of a portal's home. */
|
|
48
|
+
export declare function StoryBar({ people, onOpen }: StoryBarProps): import("react").JSX.Element;
|
|
49
|
+
export type StoryViewerProps = {
|
|
50
|
+
people: readonly StoryPerson[];
|
|
51
|
+
open: boolean;
|
|
52
|
+
/** Whose stories are shown. */
|
|
53
|
+
personIndex: number;
|
|
54
|
+
onPersonChange: (next: number) => void;
|
|
55
|
+
onClose: () => void;
|
|
56
|
+
/** Each item, the moment it is shown: the application marks it seen. */
|
|
57
|
+
onSeen?: (personId: string, itemId: string) => void;
|
|
58
|
+
/** The clock the times are read against; now by default (a test passes a fixed one). */
|
|
59
|
+
now?: Date;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* One person's stories at full screen, then the next person's.
|
|
63
|
+
*
|
|
64
|
+
* Context: the gestures of the apps people already know — a tap on the left half goes back,
|
|
65
|
+
* on the right goes on, holding pauses, a swipe down closes — and each one has a key and a
|
|
66
|
+
* button too: the arrows, Space, Escape, the ✕ and the pause button, so it is not a
|
|
67
|
+
* touchscreen-only toy. The progress is a segment per item; the time runs only while the
|
|
68
|
+
* item is really there (a video's own clock, an image's timer), and stops while paused or
|
|
69
|
+
* while the tab is hidden.
|
|
70
|
+
*/
|
|
71
|
+
export declare function StoryViewer({ people, open, personIndex, onPersonChange, onClose, onSeen, now, }: StoryViewerProps): import("react").JSX.Element;
|