@sableui/react 0.14.0 → 0.15.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/CHANGELOG.md +58 -0
- package/DESIGN.md +3 -1
- package/dist/blocks/index.d.ts +12 -1
- package/dist/blocks/index.js +4 -0
- package/dist/blocks/message-reactions-block.js +87 -0
- package/dist/blocks/message-reactions-block.meta.js +23 -0
- package/dist/components/bubble/bubble.js +105 -5
- package/dist/components/bubble/bubble.meta.js +42 -6
- package/dist/components/bubble/bubble.variants.js +1 -1
- package/dist/components/bubble/index.js +2 -0
- package/dist/components/feedback/feedback.js +8 -1
- package/dist/components/feedback/feedback.meta.js +6 -0
- package/dist/components/like-button/index.js +7 -0
- package/dist/components/like-button/like-button.js +89 -0
- package/dist/components/like-button/like-button.meta.js +132 -0
- package/dist/components/reaction-picker/index.js +13 -0
- package/dist/components/reaction-picker/reaction-picker.js +104 -0
- package/dist/components/reaction-picker/reaction-picker.meta.js +156 -0
- package/dist/components/toast/toast.js +25 -13
- package/dist/components/toast/toast.meta.js +7 -1
- package/dist/file-hashes.json +26 -17
- package/dist/foundations/motion.js +21 -1
- package/dist/icon-sets/reicon.js +11 -1
- package/dist/index.d.ts +295 -62
- package/dist/index.js +3 -1
- package/dist/lib/taxonomy.js +2 -0
- package/dist/motion/Burst.js +79 -0
- package/dist/motion/index.js +2 -0
- package/dist/styles.css +141 -0
- package/llms/blocks/message-reactions-block.md +116 -0
- package/llms/components/bubble.md +17 -7
- package/llms/components/feedback.md +1 -0
- package/llms/components/like-button.md +91 -0
- package/llms/components/reaction-picker.md +115 -0
- package/llms/components/toast.md +2 -1
- package/llms/foundations/motion.md +18 -2
- package/llms/reference/utilities.md +4 -1
- package/llms-full.txt +374 -12
- package/llms.txt +9 -6
- package/package.json +1 -1
- package/registry.json +573 -12
- package/targets/ios.json +18 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/motion/Burst.tsx
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../lib/cn.js";
|
|
6
|
+
import { motionAttribute, useMotionLevel } from "./MotionProvider.js";
|
|
7
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
var DEFAULT_PALETTE = ["pink", "purple", "blue", "orange"];
|
|
9
|
+
function Burst({
|
|
10
|
+
trigger,
|
|
11
|
+
palette = DEFAULT_PALETTE,
|
|
12
|
+
count = 7,
|
|
13
|
+
particle,
|
|
14
|
+
playOnMount = false,
|
|
15
|
+
className,
|
|
16
|
+
motion
|
|
17
|
+
}) {
|
|
18
|
+
const { expressive } = useMotionLevel(motion);
|
|
19
|
+
const [last, setLast] = useState(trigger);
|
|
20
|
+
const [shot, setShot] = useState(playOnMount ? 1 : 0);
|
|
21
|
+
if (!Object.is(trigger, last)) {
|
|
22
|
+
setLast(trigger);
|
|
23
|
+
setShot((n) => n + 1);
|
|
24
|
+
}
|
|
25
|
+
const [done, setDone] = useState(0);
|
|
26
|
+
const landed = useRef({ shot: 0, pieces: 0 });
|
|
27
|
+
if (shot === 0 || shot === done || !expressive || palette.length === 0) return null;
|
|
28
|
+
const places = Math.max(1, Math.round(count));
|
|
29
|
+
const onAnimationEnd = (event) => {
|
|
30
|
+
if (!event.target.classList.contains("sable-burst-dot")) return;
|
|
31
|
+
if (landed.current.shot !== shot) landed.current = { shot, pieces: 0 };
|
|
32
|
+
landed.current.pieces += 1;
|
|
33
|
+
if (landed.current.pieces >= places * 2) setDone(shot);
|
|
34
|
+
};
|
|
35
|
+
const step = 360 / places;
|
|
36
|
+
const scale = particle === void 0 ? 1 : 2.5;
|
|
37
|
+
return /* @__PURE__ */ jsxs(
|
|
38
|
+
"span",
|
|
39
|
+
{
|
|
40
|
+
"aria-hidden": true,
|
|
41
|
+
"data-motion": motionAttribute(motion),
|
|
42
|
+
className: cn("sable-burst [--burst-size:2.25em]", className),
|
|
43
|
+
onAnimationEnd,
|
|
44
|
+
children: [
|
|
45
|
+
particle === void 0 ? /* @__PURE__ */ jsx("span", { className: "sable-burst-ring", "data-palette": palette[0] }) : null,
|
|
46
|
+
Array.from({ length: places }, (_, i) => {
|
|
47
|
+
const angle = i * step - 90;
|
|
48
|
+
return [
|
|
49
|
+
{ angle, reach: 0.95, size: `calc(var(--burst-size) * ${0.14 * scale})`, family: palette[i % palette.length] },
|
|
50
|
+
{
|
|
51
|
+
angle: angle + step / 3,
|
|
52
|
+
reach: 0.75,
|
|
53
|
+
size: `calc(var(--burst-size) * ${0.1 * scale})`,
|
|
54
|
+
family: palette[(i + 1) % palette.length]
|
|
55
|
+
}
|
|
56
|
+
].map((dot, j) => /* @__PURE__ */ jsx(
|
|
57
|
+
"span",
|
|
58
|
+
{
|
|
59
|
+
className: "sable-burst-dot",
|
|
60
|
+
"data-palette": particle === void 0 ? dot.family : void 0,
|
|
61
|
+
"data-particle": particle === void 0 ? void 0 : "",
|
|
62
|
+
style: {
|
|
63
|
+
"--burst-dot-angle": `${dot.angle}deg`,
|
|
64
|
+
"--burst-dot-reach": dot.reach,
|
|
65
|
+
"--burst-dot-size": dot.size
|
|
66
|
+
},
|
|
67
|
+
children: particle
|
|
68
|
+
},
|
|
69
|
+
`${i}-${j}`
|
|
70
|
+
));
|
|
71
|
+
})
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
shot
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
Burst
|
|
79
|
+
};
|
package/dist/motion/index.js
CHANGED
|
@@ -13,12 +13,14 @@ import { useInView } from "./useInView.js";
|
|
|
13
13
|
import { Reveal } from "./Reveal.js";
|
|
14
14
|
import { TextReveal } from "./TextReveal.js";
|
|
15
15
|
import { Presence } from "./Presence.js";
|
|
16
|
+
import { Burst } from "./Burst.js";
|
|
16
17
|
import {
|
|
17
18
|
startViewTransition,
|
|
18
19
|
supportsViewTransitions,
|
|
19
20
|
ViewTransitionName
|
|
20
21
|
} from "./viewTransition.js";
|
|
21
22
|
export {
|
|
23
|
+
Burst,
|
|
22
24
|
MotionProvider,
|
|
23
25
|
MotionScope,
|
|
24
26
|
Presence,
|
package/dist/styles.css
CHANGED
|
@@ -2475,6 +2475,147 @@
|
|
|
2475
2475
|
var(--motion-ease-standard), var(--motion-ease-standard), var(--motion-ease-standard);
|
|
2476
2476
|
}
|
|
2477
2477
|
|
|
2478
|
+
/* Bloom — a small glyph landing in its "on" state: a liked heart, a starred
|
|
2479
|
+
item, a toast's status icon. It grows from nothing past its size and settles
|
|
2480
|
+
back, the amplitude a 16px glyph needs to read as an event. Surfaces never
|
|
2481
|
+
bloom: a dialog that overshot 20% would be a lurch, which is why the overlay
|
|
2482
|
+
recipes travel from 0.96. Size is what sets the amplitude.
|
|
2483
|
+
|
|
2484
|
+
A keyframe animation, so it plays whenever the element MOUNTS: remount the
|
|
2485
|
+
glyph (a changing `key`) to replay it on each "on", and leave it off the
|
|
2486
|
+
resting state so a page that loads with a liked post does not bloom every
|
|
2487
|
+
heart. --motion-bloom-delay holds the glyph at nothing first (a raw delay;
|
|
2488
|
+
the recipe scales it), so a ring or burst can lead. Expressive: "subtle"
|
|
2489
|
+
and reduced motion land the glyph at once. Put it on a wrapper around a
|
|
2490
|
+
glyph that carries motion-press or motion-interactive: an animation holds
|
|
2491
|
+
`scale` while it runs. */
|
|
2492
|
+
@keyframes sable-bloom {
|
|
2493
|
+
0% {
|
|
2494
|
+
scale: 0;
|
|
2495
|
+
}
|
|
2496
|
+
55% {
|
|
2497
|
+
scale: 1.2;
|
|
2498
|
+
}
|
|
2499
|
+
80% {
|
|
2500
|
+
scale: 0.95;
|
|
2501
|
+
}
|
|
2502
|
+
100% {
|
|
2503
|
+
scale: 1;
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
@utility motion-bloom {
|
|
2507
|
+
animation: sable-bloom calc(var(--motion-duration-slower) * var(--motion-expressive, 1))
|
|
2508
|
+
var(--motion-ease-decelerate)
|
|
2509
|
+
calc(var(--motion-bloom-delay, 0ms) * var(--motion-scale, 1) * var(--motion-expressive, 1))
|
|
2510
|
+
backwards;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
/* Burst — the follow-through behind a bloom, drawn by <Burst> (src/motion): a
|
|
2514
|
+
disc that hollows into a ring and shifts colour, then dots thrown outward
|
|
2515
|
+
that shrink as they go. Plain classes, not utilities: the component owns the
|
|
2516
|
+
markup and the per-dot angles. Sized by --burst-size (the ring's diameter,
|
|
2517
|
+
about twice the glyph's). Coloured from the themed palette through
|
|
2518
|
+
`data-palette` scopes, never a step: the ring blooms in currentColor and
|
|
2519
|
+
fades into its scope's dot colour, and each dot carries a family of its
|
|
2520
|
+
own. Every duration is expressive, so under
|
|
2521
|
+
"subtle" or reduced motion it ends on its invisible last frame at once; the
|
|
2522
|
+
component also renders nothing then. */
|
|
2523
|
+
.sable-burst {
|
|
2524
|
+
position: absolute;
|
|
2525
|
+
inset: 0;
|
|
2526
|
+
pointer-events: none;
|
|
2527
|
+
}
|
|
2528
|
+
/* Centred on the glyph by `translate`, which applies before the animated
|
|
2529
|
+
`scale` and `transform`, so each piece grows and travels from the centre.
|
|
2530
|
+
(A grid cell sized itself to the 2x ring and pinned it off-centre.) */
|
|
2531
|
+
.sable-burst > * {
|
|
2532
|
+
position: absolute;
|
|
2533
|
+
left: 50%;
|
|
2534
|
+
top: 50%;
|
|
2535
|
+
translate: -50% -50%;
|
|
2536
|
+
}
|
|
2537
|
+
@keyframes sable-burst-ring {
|
|
2538
|
+
0% {
|
|
2539
|
+
scale: 0.2;
|
|
2540
|
+
border-width: calc(var(--burst-size) / 2);
|
|
2541
|
+
border-color: currentColor;
|
|
2542
|
+
opacity: 1;
|
|
2543
|
+
}
|
|
2544
|
+
45% {
|
|
2545
|
+
scale: 1;
|
|
2546
|
+
border-width: calc(var(--burst-size) / 2);
|
|
2547
|
+
}
|
|
2548
|
+
100% {
|
|
2549
|
+
scale: 1.1;
|
|
2550
|
+
border-width: 0;
|
|
2551
|
+
border-color: var(--palette-dot, currentColor);
|
|
2552
|
+
opacity: 0;
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
.sable-burst-ring {
|
|
2556
|
+
width: var(--burst-size);
|
|
2557
|
+
height: var(--burst-size);
|
|
2558
|
+
border-radius: 9999px;
|
|
2559
|
+
border-style: solid;
|
|
2560
|
+
border-width: 0;
|
|
2561
|
+
opacity: 0;
|
|
2562
|
+
animation: sable-burst-ring calc(var(--motion-duration-slower) * var(--motion-expressive, 1))
|
|
2563
|
+
var(--motion-ease-decelerate) forwards;
|
|
2564
|
+
}
|
|
2565
|
+
@keyframes sable-burst-dot {
|
|
2566
|
+
0% {
|
|
2567
|
+
opacity: 1;
|
|
2568
|
+
transform: rotate(var(--burst-dot-angle)) translateX(calc(var(--burst-size) * 0.4)) scale(1);
|
|
2569
|
+
}
|
|
2570
|
+
100% {
|
|
2571
|
+
opacity: 1;
|
|
2572
|
+
transform: rotate(var(--burst-dot-angle)) translateX(calc(var(--burst-size) * var(--burst-dot-reach)))
|
|
2573
|
+
scale(0);
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
.sable-burst-dot {
|
|
2577
|
+
width: var(--burst-dot-size);
|
|
2578
|
+
height: var(--burst-dot-size);
|
|
2579
|
+
border-radius: 9999px;
|
|
2580
|
+
background-color: var(--palette-dot, currentColor);
|
|
2581
|
+
opacity: 0;
|
|
2582
|
+
/* Thrown as the ring opens, not with it. */
|
|
2583
|
+
animation: sable-burst-dot calc(var(--motion-duration-slower) * 1.3 * var(--motion-expressive, 1))
|
|
2584
|
+
var(--motion-ease-decelerate) calc(var(--motion-duration-fast) * var(--motion-expressive, 1)) forwards;
|
|
2585
|
+
}
|
|
2586
|
+
/* A thrown glyph (Burst's `particle`) instead of a disc: the emoji itself,
|
|
2587
|
+
sized by the same --burst-dot-size, so a reaction sprays copies of what was
|
|
2588
|
+
chosen. Counter-rotated on its way out so it travels upright, and it fades
|
|
2589
|
+
at the end of its flight rather than shrinking to a point. */
|
|
2590
|
+
@keyframes sable-burst-particle {
|
|
2591
|
+
0% {
|
|
2592
|
+
opacity: 1;
|
|
2593
|
+
transform: rotate(var(--burst-dot-angle)) translateX(calc(var(--burst-size) * 0.3))
|
|
2594
|
+
rotate(calc(var(--burst-dot-angle) * -1)) scale(0.4);
|
|
2595
|
+
}
|
|
2596
|
+
60% {
|
|
2597
|
+
opacity: 1;
|
|
2598
|
+
transform: rotate(var(--burst-dot-angle)) translateX(calc(var(--burst-size) * var(--burst-dot-reach) * 0.9))
|
|
2599
|
+
rotate(calc(var(--burst-dot-angle) * -1)) scale(1);
|
|
2600
|
+
}
|
|
2601
|
+
100% {
|
|
2602
|
+
opacity: 0;
|
|
2603
|
+
transform: rotate(var(--burst-dot-angle)) translateX(calc(var(--burst-size) * var(--burst-dot-reach)))
|
|
2604
|
+
rotate(calc(var(--burst-dot-angle) * -1)) scale(0.7);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
.sable-burst-dot[data-particle] {
|
|
2608
|
+
display: grid;
|
|
2609
|
+
place-items: center;
|
|
2610
|
+
width: auto;
|
|
2611
|
+
height: auto;
|
|
2612
|
+
border-radius: 0;
|
|
2613
|
+
background-color: transparent;
|
|
2614
|
+
font-size: var(--burst-dot-size);
|
|
2615
|
+
line-height: 1;
|
|
2616
|
+
animation-name: sable-burst-particle;
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2478
2619
|
/* --------------------------------------------------------------------------
|
|
2479
2620
|
Loader recipes — looping indicators. Durations scale with --motion-scale, so
|
|
2480
2621
|
the policy switch freezes them to a static first frame.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# MessageReactionsBlock
|
|
2
|
+
|
|
3
|
+
A short thread you can react to: right-click or long-press a bubble for a menu with a row of quick reactions above Reply and Copy, or use the add-reaction pill under a message. A new reaction blooms in and sprays copies of its emoji.
|
|
4
|
+
|
|
5
|
+
**Intent:** Reach for this when a conversation excerpt should be reactable — a team thread, a comment card, a support transcript. A read-only excerpt is ChatThreadBlock; a working chat with a composer and history is the ChatPanel page shell.
|
|
6
|
+
|
|
7
|
+
**Block:** Social & messaging · card · designed for 18rem–24rem wide (fills its container up to the max)
|
|
8
|
+
|
|
9
|
+
## Notes
|
|
10
|
+
|
|
11
|
+
- Two ways in, on purpose: the right-click / long-press menu is fast once you know it is there, and the add-reaction pill is how a first-time reader finds reactions at all.
|
|
12
|
+
- The quick row in the menu is MenuReactions (checkbox menu items) and the one in the pill's popover is ReactionPicker (a toolbar), so each is reachable by the keyboard model of the surface it sits in.
|
|
13
|
+
- Only the reader's own reaction celebrates. Counts from other people roll quietly, and the reactions a page loads with never play.
|
|
14
|
+
- The add-reaction pill appears only on messages that already have reactions; a message with none is reacted to from its menu, which keeps quiet rows quiet.
|
|
15
|
+
|
|
16
|
+
## Accessibility
|
|
17
|
+
|
|
18
|
+
- Each bubble is focusable, and its menu opens on right click, long press, Shift+F10 or the Menu key; its reactions are checkbox items reporting whether the reader has used each one.
|
|
19
|
+
- Each reaction pill is a toggle named by its meaning and count ("Party, 3") with `aria-pressed`; the emoji and the burst are hidden from assistive tech.
|
|
20
|
+
- Under reduced motion the reaction appears and the count changes at once; nothing else is lost.
|
|
21
|
+
|
|
22
|
+
## Source
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { Bubble, BubbleReaction, BubbleReactionAdd, BubbleReactions, Card, CardContent, CardFooter, cn, ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, DEFAULT_REACTIONS, MenuReactions, Message } from "@sableui/react"
|
|
26
|
+
|
|
27
|
+
const messages: { id: string; text: string; mine: boolean; reactions: Record<string, number> }[] = [
|
|
28
|
+
{ id: "m1", text: "The new onboarding flow is live on staging 🚀", mine: false, reactions: { "🎉": 2, "👀": 1 } },
|
|
29
|
+
{ id: "m2", text: "Clicked through it twice. The progress bar is so smooth.", mine: true, reactions: {} },
|
|
30
|
+
{ id: "m3", text: "Ship it Friday?", mine: false, reactions: { "👍": 1 } },
|
|
31
|
+
]
|
|
32
|
+
const hint = "Right-click or long-press a message to react."
|
|
33
|
+
// Every emoji that can appear needs a name: it is the pill's accessible label.
|
|
34
|
+
const labels: Record<string, string> = {
|
|
35
|
+
...Object.fromEntries(DEFAULT_REACTIONS.map((r) => [r.emoji, r.label])),
|
|
36
|
+
"👀": "Eyes",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MessageReactionsBlockProps {
|
|
40
|
+
className?: string
|
|
41
|
+
/** false drops the card's surface and border. Keep it framed on a muted page: incoming bubbles are the muted surface too. */
|
|
42
|
+
framed?: boolean
|
|
43
|
+
/** Called when the reader adds or removes a reaction, with the message, the emoji and whether it is now on. */
|
|
44
|
+
onReact?: (messageId: string, emoji: string, on: boolean) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function MessageReactionsBlock({ className, framed = true, onReact }: MessageReactionsBlockProps) {
|
|
48
|
+
// The reader's own reactions, per message. Everyone else's are the counts above.
|
|
49
|
+
const [mine, setMine] = useState<Record<string, string[]>>({ m1: ["🎉"] })
|
|
50
|
+
const toggle = (messageId: string, emoji: string) => {
|
|
51
|
+
const on = !(mine[messageId] ?? []).includes(emoji)
|
|
52
|
+
// Decided again from `prev`, so two toggles in one batch cannot add an emoji twice.
|
|
53
|
+
setMine((prev) => {
|
|
54
|
+
const current = prev[messageId] ?? []
|
|
55
|
+
const next = current.includes(emoji) ? current.filter((e) => e !== emoji) : [...current, emoji]
|
|
56
|
+
return { ...prev, [messageId]: next }
|
|
57
|
+
})
|
|
58
|
+
onReact?.(messageId, emoji, on)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Card variant={framed ? "default" : "flat"} className={cn("w-full max-w-sm", className)}>
|
|
63
|
+
<CardContent className="flex flex-col gap-3">
|
|
64
|
+
{messages.map((m) => {
|
|
65
|
+
const align = m.mine ? "end" : "start"
|
|
66
|
+
const chosen = mine[m.id] ?? []
|
|
67
|
+
// Others' counts, plus the reader's own: a reaction only the reader gave
|
|
68
|
+
// is a pill of its own, ordered after the ones already there.
|
|
69
|
+
const counts: Record<string, number> = { ...m.reactions }
|
|
70
|
+
for (const emoji of chosen) counts[emoji] = (counts[emoji] ?? 0)
|
|
71
|
+
const pills = Object.entries(counts).map(([emoji, others]) => ({
|
|
72
|
+
emoji,
|
|
73
|
+
active: chosen.includes(emoji),
|
|
74
|
+
count: others + (chosen.includes(emoji) ? 1 : 0),
|
|
75
|
+
}))
|
|
76
|
+
return (
|
|
77
|
+
<Message key={m.id} messageId={m.id} align={m.mine ? "end" : undefined}>
|
|
78
|
+
<ContextMenu>
|
|
79
|
+
<ContextMenuTrigger
|
|
80
|
+
// Focusable, so Shift+F10 or the Menu key opens the same menu.
|
|
81
|
+
render={<Bubble tabIndex={0} variant={m.mine ? "primary" : undefined} align={align} />}
|
|
82
|
+
>
|
|
83
|
+
{m.text}
|
|
84
|
+
</ContextMenuTrigger>
|
|
85
|
+
<ContextMenuContent>
|
|
86
|
+
<MenuReactions selected={chosen} onSelect={(emoji) => toggle(m.id, emoji)} />
|
|
87
|
+
<ContextMenuSeparator />
|
|
88
|
+
<ContextMenuItem>Reply</ContextMenuItem>
|
|
89
|
+
<ContextMenuItem>Copy text</ContextMenuItem>
|
|
90
|
+
</ContextMenuContent>
|
|
91
|
+
</ContextMenu>
|
|
92
|
+
{/* Rendered even while empty (it hides itself), so the first reaction still celebrates. */}
|
|
93
|
+
<BubbleReactions align={align}>
|
|
94
|
+
{pills.map((p) => (
|
|
95
|
+
<BubbleReaction
|
|
96
|
+
key={p.emoji}
|
|
97
|
+
emoji={p.emoji}
|
|
98
|
+
label={labels[p.emoji]}
|
|
99
|
+
count={p.count}
|
|
100
|
+
active={p.active}
|
|
101
|
+
onClick={() => toggle(m.id, p.emoji)}
|
|
102
|
+
/>
|
|
103
|
+
))}
|
|
104
|
+
{pills.length > 0 ? (
|
|
105
|
+
<BubbleReactionAdd selected={chosen} onSelect={(emoji) => toggle(m.id, emoji)} />
|
|
106
|
+
) : null}
|
|
107
|
+
</BubbleReactions>
|
|
108
|
+
</Message>
|
|
109
|
+
)
|
|
110
|
+
})}
|
|
111
|
+
</CardContent>
|
|
112
|
+
<CardFooter className="text-caption text-muted-foreground">{hint}</CardFooter>
|
|
113
|
+
</Card>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
```
|
|
@@ -28,14 +28,16 @@ The tinted (or untinted) surface a turn's content sits on. Kept separate from Me
|
|
|
28
28
|
| --- | --- | --- |
|
|
29
29
|
| Bubble | yes | The surface itself. Holds the variant, the side, and the tail. |
|
|
30
30
|
| BubbleReactions | no | The row of reaction pills, just under the bubble at the message column's small gap, so it reads as belonging to that message rather than the next row. |
|
|
31
|
-
| BubbleReaction | no | One reaction pill — emoji, count (hidden at 1), and pressed state. |
|
|
31
|
+
| BubbleReaction | no | One reaction pill — emoji, count (hidden at 1), and pressed state. Celebrates when it becomes the reader's own. |
|
|
32
|
+
| BubbleReactionAdd | no | The add-reaction pill at the end of the row: opens a ReactionPicker above it. |
|
|
32
33
|
|
|
33
34
|
## Subcomponents
|
|
34
35
|
|
|
35
36
|
| Name | Type | Description |
|
|
36
37
|
| --- | --- | --- |
|
|
37
38
|
| BubbleReactions | { align?: "start" \| "end" } & ComponentPropsWithRef<"div"> | Row container for reaction pills. Match `align` to the Bubble so the row hangs off the same edge. |
|
|
38
|
-
| BubbleReaction | { emoji: ReactNode; count?: number; active?: boolean } & ComponentPropsWithRef<"button"> | One reaction pill. A toggle, not a label: `active` drives `aria-pressed` as well as the styling, and `count` is hidden at 1 because the pill already says "one". |
|
|
39
|
+
| BubbleReaction | { emoji: ReactNode; label?: string; count?: number; active?: boolean; motion?: MotionLevel } & ComponentPropsWithRef<"button"> | One reaction pill. A toggle, not a label: `active` drives `aria-pressed` as well as the styling, `label` names it ("Party, 3"), and `count` is hidden at 1 because the pill already says "one". When it turns on — pressed, or newly added already on — the emoji blooms, copies of it burst out and the count rolls; pills the page loads with stay still. |
|
|
40
|
+
| BubbleReactionAdd | { reactions?: Reaction[]; selected?: string[]; onSelect?: (emoji: string) => void; label?: string; motion?: MotionLevel } & ComponentPropsWithRef<"button"> | The add-reaction pill: a smiley that opens a ReactionPicker above it. Choosing an emoji closes the picker and calls `onSelect`; add the emoji to the row and its new pill celebrates on arrival. |
|
|
39
41
|
|
|
40
42
|
## Props
|
|
41
43
|
|
|
@@ -56,16 +58,23 @@ The tinted (or untinted) surface a turn's content sits on. Kept separate from Me
|
|
|
56
58
|
|
|
57
59
|
`muted`, `foreground`, `primary`, `primary-foreground`, `border`, `card`, `card-foreground`, `accent`, `accent-foreground`, `muted-foreground`, `ring`
|
|
58
60
|
|
|
61
|
+
## Motion
|
|
62
|
+
|
|
63
|
+
- **arrival** · Bubble · _no motion_ — A bubble arrives with its Message row, which owns how a new message enters the transcript. A reaction pill that the reader just added arrives with its own celebration (below).
|
|
64
|
+
- **response** · BubbleReaction · `motion-bloom` — Reacting is the reader's choice, so it is answered like a like: the emoji grows from nothing past its size and settles, while copies of it spray outward and fade (Burst with the emoji as its particle, the way chat apps answer a reaction). Plays when a pill turns on and when a pill mounts already on into a row that has rendered — never for the pills a page loads with. Pills inherit Pill's motion-interactive and motion-press.
|
|
65
|
+
- **transition** · BubbleReaction · _custom (outside the recipe layer)_ — The count rolls with NumberTicker as people react. Turning a reaction off is quiet: the tint eases out and the count rolls back, with no burst. Under `subtle` or reduced motion the bloom and the spray are dropped and the tint and count alone answer.
|
|
66
|
+
- **activity** · Bubble · _no motion_ — A bubble is static content; a message still being written is StreamingText or a Marker, not a state of the surface.
|
|
67
|
+
|
|
59
68
|
## Accessibility
|
|
60
69
|
|
|
61
70
|
- The surface is a plain container with no imposed role — a bubble is presentation, and announcing one as a region would put a landmark around every line of a conversation.
|
|
62
|
-
- Reaction pills are real buttons reporting `aria-pressed`, so the reader's own reaction is state rather than colour alone
|
|
71
|
+
- Reaction pills are real buttons reporting `aria-pressed`, so the reader's own reaction is state rather than colour alone. Give each a `label`: it is named "Party, 3", with the emoji and its burst hidden from AT. The add-reaction pill is named "Add reaction" and opens a toolbar picker.
|
|
63
72
|
- `whitespace-pre-wrap` and `break-words` keep pasted logs, long URLs, and hard-wrapped text inside the surface instead of overflowing the conversation.
|
|
64
73
|
- Every variant meets AA against its own surface, including `primary`, which pairs the primary fill with its paired foreground token rather than a hardcoded white.
|
|
65
74
|
|
|
66
75
|
## Related
|
|
67
76
|
|
|
68
|
-
- Components: Message, MessageScroller, Marker, Attachment
|
|
77
|
+
- Components: Message, MessageScroller, Marker, Attachment, ReactionPicker
|
|
69
78
|
|
|
70
79
|
## Examples
|
|
71
80
|
|
|
@@ -96,13 +105,14 @@ import { Avatar, Bubble, CodeBlock, Message } from "@sableui/react"
|
|
|
96
105
|
### With reactions
|
|
97
106
|
|
|
98
107
|
```tsx
|
|
99
|
-
import { Bubble, BubbleReaction, BubbleReactions, Message } from "@sableui/react"
|
|
108
|
+
import { Bubble, BubbleReaction, BubbleReactionAdd, BubbleReactions, Message } from "@sableui/react"
|
|
100
109
|
|
|
101
110
|
<Message messageId="m3">
|
|
102
111
|
<Bubble>Shipped 0.45.0.</Bubble>
|
|
103
112
|
<BubbleReactions>
|
|
104
|
-
<BubbleReaction emoji="🎉" count={3} active onClick={() => toggle("🎉")} />
|
|
105
|
-
<BubbleReaction emoji="👀" count={1} onClick={() => toggle("👀")} />
|
|
113
|
+
<BubbleReaction emoji="🎉" label="Party" count={3} active onClick={() => toggle("🎉")} />
|
|
114
|
+
<BubbleReaction emoji="👀" label="Eyes" count={1} onClick={() => toggle("👀")} />
|
|
115
|
+
<BubbleReactionAdd selected={mine} onSelect={toggle} />
|
|
106
116
|
</BubbleReactions>
|
|
107
117
|
</Message>
|
|
108
118
|
```
|
|
@@ -38,6 +38,7 @@ Use Feedback to collect lightweight sentiment, usefulness, or quality signals fr
|
|
|
38
38
|
|
|
39
39
|
- **arrival** · Popover · `motion-pop` — The form opens from its trigger, so the eye goes from the button it pressed to the field it should type in. Popover owns the recipe.
|
|
40
40
|
- **response** · Rating toggles · `motion-interactive` — The rating row is a choice among a few similar marks. The eased selected fill is what makes the pick read as made, not just hovered.
|
|
41
|
+
- **response** · Chosen rating mark · `motion-bloom` — The mark itself answers the pick: it blooms past its size and settles, so choosing reads as a small decision landing rather than a fill changing. Only the chosen mark, only on choosing — nothing blooms when the form opens or a pick is let go. Expressive: under subtle the fill alone answers.
|
|
41
42
|
- **transition** · Thanks · `motion-tick` — Sending is the one moment the person needs to know their words arrived. The form fades out in place and a check draws itself in over it, then the popover closes. Without it the popover just vanished, which looks the same as the form being dismissed or the message lost.
|
|
42
43
|
- **activity** · Root · _no motion_ — The thanks shows as soon as the form is sent; delivery is the app's background work. A spinner for a one-line report would make a quick, optional gesture feel heavy.
|
|
43
44
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# LikeButton
|
|
2
|
+
|
|
3
|
+
**Status:** stable
|
|
4
|
+
|
|
5
|
+
A pressed-or-not toggle for a like, a star or a save, with its count. Pressing it on fills the glyph, which blooms while a ring and a spray of dots burst from it and the count rolls up; pressing it off is quiet.
|
|
6
|
+
|
|
7
|
+
**Keywords:** like, heart, favorite, favourite, love, star, bookmark, save, upvote, reaction, count, toggle
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Use LikeButton for a personal, reversible endorsement that other people can see the tally of: liking a post, starring a repository, saving a recipe. It is the one place in Sable that celebrates, because the person chose it and it costs nothing to undo.
|
|
12
|
+
|
|
13
|
+
### Best practices
|
|
14
|
+
|
|
15
|
+
- Do: Pass the server's total as `count` and update it when the save lands. The button shows the viewer's own like at once, before the save, and goes back to `count` exactly whenever it changes, so a failed save that leaves `count` alone can also turn `pressed` back off.
|
|
16
|
+
- Do: Match the glyph, family and label to the meaning: `icon="star" tone="yellow" label="Star"` for a star. The label is the accessible name, so it must say what pressing does.
|
|
17
|
+
- Do: Use `format={{ notation: "compact" }}` once counts pass a few thousand, so a feed of buttons keeps one width.
|
|
18
|
+
- Don't: Do not use it for a setting or a view switch (bold, mute, grid or list). Those are tools, not endorsements, and a burst on every press of a formatting control is noise; use Toggle. → use **Toggle**
|
|
19
|
+
- Don't: Do not use it for a rating or a verdict on an answer (helpful, not helpful). That is a question with two sides; use Feedback. → use **Feedback**
|
|
20
|
+
- Don't: Do not press it for the user. A burst is a reply to a person's choice — liking something on their behalf, or on load, turns delight into a notification.
|
|
21
|
+
|
|
22
|
+
## Props
|
|
23
|
+
|
|
24
|
+
| Name | Type | Default | Description |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| count | number | — | The total, rolled when it changes. Pressing adds or removes the viewer's like at once; the button shows `count` exactly again whenever `count` changes. Omit it for a bare glyph (an icon-size button). |
|
|
27
|
+
| pressed | boolean | — | Controlled pressed state. |
|
|
28
|
+
| defaultPressed | boolean | false | Initial pressed state when uncontrolled. |
|
|
29
|
+
| onPressedChange | (pressed: boolean, event) => void | — | Called when the user presses it, with the new state. |
|
|
30
|
+
| icon | string | "heart" | The glyph, by icon name. Its `solid` variant is shown while pressed. |
|
|
31
|
+
| tone | PaletteColor | "red" | The palette family the glyph fills with while pressed, and the burst blooms from. A family, so it follows the theme. |
|
|
32
|
+
| label | string | "Like" | The accessible name, read before the count. |
|
|
33
|
+
| format | Intl.NumberFormatOptions | — | How to write the count, e.g. `{ notation: "compact" }`. |
|
|
34
|
+
| variant | "ghost" \| "outline" \| "secondary" | "ghost" | The Button surface. |
|
|
35
|
+
| size | "xs" \| "sm" \| "md" | "sm" | A Button size; without a count, the matching icon size. |
|
|
36
|
+
| disabled | boolean | false | Disables it. |
|
|
37
|
+
| motion | "full" \| "subtle" \| "off" | "full" | How much motion this component uses: `full` (default) inherits the app's policy, `subtle` keeps feedback and drops the flourish, `off` stills it. It can only turn motion down — it never overrides a reader's reduce-motion setting. The bloom and the burst are the flourish; the fill and the count changing stay. |
|
|
38
|
+
|
|
39
|
+
## Variants
|
|
40
|
+
|
|
41
|
+
- **variant**: ghost, outline, secondary
|
|
42
|
+
- **size**: xs, sm, md
|
|
43
|
+
- **tone**: red, orange, yellow, green, teal, blue, purple, pink
|
|
44
|
+
|
|
45
|
+
## Tokens used
|
|
46
|
+
|
|
47
|
+
`palette-dot`, `accent`, `ring`
|
|
48
|
+
|
|
49
|
+
## Motion
|
|
50
|
+
|
|
51
|
+
- **arrival** · Root · _no motion_ — It arrives with the post or row it belongs to. A page that loads with likes already given must be still: nothing blooms on mount.
|
|
52
|
+
- **response** · Glyph · `motion-bloom` — Pressing it on is the moment. The glyph is 16px, so it needs real amplitude to read as an event: it grows from nothing past its size and settles, after a 90ms beat in which the ring leads. Inherits Button's motion-press for the press itself. Pressing off has no bloom — taking a like back is not a celebration.
|
|
53
|
+
- **transition** · Burst · _custom (outside the recipe layer)_ — The follow-through: <Burst> draws a disc that hollows into a ring and shifts colour, then dots thrown outward in the theme's palette families. Expressive only — under `subtle` or reduced motion it renders nothing and the fill alone answers the press. The count rolls with NumberTicker.
|
|
54
|
+
- **activity** · Root · _no motion_ — There is no in-between state to show: the like is shown at once, before it is saved.
|
|
55
|
+
|
|
56
|
+
## Accessibility
|
|
57
|
+
|
|
58
|
+
- A native <button> through Button, with `aria-pressed`. Enter and Space press it.
|
|
59
|
+
- The accessible name is the label then the count ("Like 1,301"); the burst is aria-hidden and the rolling digits are hidden behind the count's real text.
|
|
60
|
+
- The pressed state is carried by the filled glyph and `aria-pressed`, never by colour alone.
|
|
61
|
+
- Under reduced motion the glyph fills and the count changes at once; the bloom and the burst are dropped.
|
|
62
|
+
|
|
63
|
+
## Related
|
|
64
|
+
|
|
65
|
+
- Components: Toggle, Feedback, NumberTicker, Button
|
|
66
|
+
|
|
67
|
+
## Examples
|
|
68
|
+
|
|
69
|
+
### A post's likes
|
|
70
|
+
|
|
71
|
+
```tsx
|
|
72
|
+
import { LikeButton } from "@sableui/react"
|
|
73
|
+
|
|
74
|
+
<LikeButton count={post.likes} defaultPressed={post.liked} onPressedChange={(on) => api.like(post.id, on)} />
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Star a repository
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { LikeButton } from "@sableui/react"
|
|
81
|
+
|
|
82
|
+
<LikeButton icon="star" tone="yellow" label="Star" variant="outline" count={repo.stars} format={{ notation: "compact" }} />
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Bare glyph
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { LikeButton } from "@sableui/react"
|
|
89
|
+
|
|
90
|
+
<LikeButton label="Save recipe" />
|
|
91
|
+
```
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# ReactionPicker
|
|
2
|
+
|
|
3
|
+
**Status:** stable
|
|
4
|
+
|
|
5
|
+
The quick row of emoji you react to a message with: a toolbar of large emoji toggles that bloom in one after another as it opens and magnify under the pointer, with MenuReactions as the same row inside a right-click menu.
|
|
6
|
+
|
|
7
|
+
**Keywords:** reaction, reactions, emoji, emoji picker, react, tapback, quick reactions, message actions, chat
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Use ReactionPicker wherever a reader chooses a reaction for something: in a Popover from an add-reaction control (BubbleReactionAdd is that, ready-made), or as a hover bar over a message. Use MenuReactions for the same row as the first group of the menu a message opens on right-click or long-press, above Reply and Copy. Both report which emoji the reader has already used, so choosing one again removes it.
|
|
12
|
+
|
|
13
|
+
### Best practices
|
|
14
|
+
|
|
15
|
+
- Do: Keep the quick set short — six to eight. It is the reactions people actually use; a full emoji catalogue belongs behind a trailing "more" control passed as children.
|
|
16
|
+
- Do: Give every reaction a `label`. It is the accessible name and the menu's typeahead, and an emoji's own spoken name differs between platforms.
|
|
17
|
+
- Do: Pass `selected` so the reader's own reactions show pressed, and toggle in `onSelect`: choosing a reaction you already gave takes it back.
|
|
18
|
+
- Do: Offer the right-click menu and a visible add-reaction control together. A context menu is invisible until you know it is there; the pill is how a first-time reader finds reactions.
|
|
19
|
+
- Don't: Do not put a ReactionPicker inside a Menu or ContextMenu. A toolbar is not a menu item, so the menu's arrow keys would skip it; use MenuReactions there. → use **MenuReactions**
|
|
20
|
+
- Don't: Do not use it to rate an answer or collect a verdict. Reactions are social and many-valued; a helpful / not-helpful question is Feedback. → use **Feedback**
|
|
21
|
+
|
|
22
|
+
### Anatomy
|
|
23
|
+
|
|
24
|
+
| Part | Required | Description |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| ReactionPicker | yes | The toolbar: one tab stop, arrow keys move between emoji, each a toggle with `aria-pressed`. |
|
|
27
|
+
| MenuReactions | no | The same row as a group of checkbox menu items, for MenuContent and ContextMenuContent. Choosing one closes the menu. |
|
|
28
|
+
|
|
29
|
+
## Subcomponents
|
|
30
|
+
|
|
31
|
+
| Name | Type | Description |
|
|
32
|
+
| --- | --- | --- |
|
|
33
|
+
| MenuReactions | { reactions?; selected?; onSelect?; motion? } & ComponentProps<typeof Menu.Group> | The quick row as checkbox menu items, for the first group of a MenuContent or ContextMenuContent. Same props as ReactionPicker, without children. |
|
|
34
|
+
|
|
35
|
+
## Props
|
|
36
|
+
|
|
37
|
+
| Name | Type | Default | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| reactions | readonly { emoji: string; label: string }[] | DEFAULT_REACTIONS | The choices, in order. The default is 👍 ❤️ 😂 🎉 😮 😢 🙏. |
|
|
40
|
+
| selected | readonly string[] | [] | The emoji the reader has already reacted with: shown pressed, and choosing one again removes it. |
|
|
41
|
+
| onSelect | (emoji: string) => void | — | Called with the emoji the reader chose. Toggle it in or out of `selected`. |
|
|
42
|
+
| children | ReactNode | — | ReactionPicker only: trailing controls after the emoji, such as a button that opens a full emoji picker. |
|
|
43
|
+
| aria-label | string | "Reactions" | The name of the toolbar or menu group. |
|
|
44
|
+
| motion | "full" \| "subtle" \| "off" | "full" | How much motion this component uses: `full` (default) inherits the app's policy, `subtle` keeps the press and drops the wave of emoji blooming in and the magnify, `off` stills it. It can only turn motion down. |
|
|
45
|
+
|
|
46
|
+
## Tokens used
|
|
47
|
+
|
|
48
|
+
`accent`, `primary`, `ring`
|
|
49
|
+
|
|
50
|
+
## Motion
|
|
51
|
+
|
|
52
|
+
- **arrival** · Glyph · `motion-bloom` — Opening the picker is the reader's own action, so the emoji answer it: each blooms in 24ms after the one before, a short wave from first to last. The surface it sits in (a Popover or a menu) arrives with its own motion-pop. Expressive only — under `subtle` the emoji are simply there.
|
|
53
|
+
- **response** · Glyph · _custom (outside the recipe layer)_ — The emoji under the pointer or the keyboard highlight magnifies to 1.25 on a fast standard ease, so you can see which one a release will choose; each cell also carries motion-interactive and motion-press. The magnify rides an inner layer so it never fights the bloom over `scale`.
|
|
54
|
+
- **transition** · Cell · `motion-interactive` — Pressed and not pressed differ by a tint, eased by motion-interactive. The celebration belongs to the reaction that lands under the message (BubbleReaction), not to the picker that chose it.
|
|
55
|
+
- **activity** · Root · _no motion_ — Choosing is instant; there is no in-between state to show.
|
|
56
|
+
|
|
57
|
+
## Accessibility
|
|
58
|
+
|
|
59
|
+
- ReactionPicker is a Base UI toolbar: one tab stop, Left/Right move between emoji, Home/End jump to the ends.
|
|
60
|
+
- Each emoji is a button named by its `label` and reporting `aria-pressed`, so a screen-reader user hears whether choosing it adds or removes their reaction. The glyph itself is aria-hidden.
|
|
61
|
+
- MenuReactions renders checkbox menu items (`menuitemcheckbox` with `aria-checked`), reached by the menu's arrow keys and typeahead like every other row.
|
|
62
|
+
- Under reduced motion the emoji appear at once and do not magnify; pressed state is carried by `aria-pressed` and a tint, never motion.
|
|
63
|
+
|
|
64
|
+
## Related
|
|
65
|
+
|
|
66
|
+
- Components: Bubble, ContextMenu, Popover, Toolbar, Feedback
|
|
67
|
+
|
|
68
|
+
## Examples
|
|
69
|
+
|
|
70
|
+
### In a popover
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { Button, Icon, Popover, PopoverContent, PopoverTrigger, ReactionPicker } from "@sableui/react"
|
|
74
|
+
|
|
75
|
+
<Popover>
|
|
76
|
+
<PopoverTrigger render={<Button variant="ghost" size="icon-sm" aria-label="Add reaction" />}>
|
|
77
|
+
<Icon name="emoji" />
|
|
78
|
+
</PopoverTrigger>
|
|
79
|
+
<PopoverContent side="top" className="w-auto rounded-full p-1">
|
|
80
|
+
<ReactionPicker selected={mine} onSelect={toggle} />
|
|
81
|
+
</PopoverContent>
|
|
82
|
+
</Popover>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### In a right-click menu
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
import { Bubble, ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, MenuReactions } from "@sableui/react"
|
|
89
|
+
|
|
90
|
+
<ContextMenu>
|
|
91
|
+
<ContextMenuTrigger render={<Bubble />}>See you at 6.</ContextMenuTrigger>
|
|
92
|
+
<ContextMenuContent>
|
|
93
|
+
<MenuReactions selected={mine} onSelect={toggle} />
|
|
94
|
+
<ContextMenuSeparator />
|
|
95
|
+
<ContextMenuItem>Reply</ContextMenuItem>
|
|
96
|
+
<ContextMenuItem>Copy text</ContextMenuItem>
|
|
97
|
+
</ContextMenuContent>
|
|
98
|
+
</ContextMenu>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### A custom set
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { ReactionPicker } from "@sableui/react"
|
|
105
|
+
|
|
106
|
+
<ReactionPicker
|
|
107
|
+
reactions={[
|
|
108
|
+
{ emoji: "✅", label: "Done" },
|
|
109
|
+
{ emoji: "👀", label: "Looking" },
|
|
110
|
+
{ emoji: "🚀", label: "Shipped" },
|
|
111
|
+
]}
|
|
112
|
+
selected={mine}
|
|
113
|
+
onSelect={toggle}
|
|
114
|
+
/>
|
|
115
|
+
```
|