@behavioral-agentic-design-system/core 0.26.0 → 0.27.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/package.json +1 -1
- package/scripts/build-tokens.cjs +8 -0
- package/src/app/preview/components/page.tsx +236 -1
- package/src/components/ui/floating-action-button.tsx +179 -0
- package/src/components/ui/index.ts +1 -0
- package/src/components/ui/meter.tsx +4 -4
- package/src/components/ui/transfer-list.tsx +48 -13
- package/src/components/ui/typing-indicator.tsx +96 -0
- package/src/components/ui/word-rotate.tsx +82 -0
- package/src/data/docs-index.ts +1 -0
- package/src/stories/Affix.stories.tsx +1 -1
- package/src/stories/Anchor.stories.tsx +4 -4
- package/src/stories/FloatingActionButton.stories.tsx +215 -0
- package/src/stories/Meter.stories.tsx +7 -0
- package/src/stories/TransferList.stories.tsx +21 -0
- package/src/stories/TypingIndicator.stories.tsx +139 -0
- package/src/stories/WordRotate.stories.tsx +101 -0
- package/src/styles.css +8 -0
- package/src/tokens.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behavioral-agentic-design-system/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "BADS core — tokens, shadcn/ui components, and the BADS template shell (app routes, customize tab, theme hooks). Forks consume this and re-export, keeping client repos to ~30 lines of glue.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matthew Stephens <work@matthewstephens.com> (https://github.com/matthewlarn)",
|
package/scripts/build-tokens.cjs
CHANGED
|
@@ -729,6 +729,14 @@ html, body {
|
|
|
729
729
|
[data-slot="marquee-track"] { animation-play-state: paused; }
|
|
730
730
|
}
|
|
731
731
|
|
|
732
|
+
/* TypingIndicator — three-dot is-typing animation. Dots bob on a staggered
|
|
733
|
+
delay applied via inline style per dot (pattern b keyframe + pattern c
|
|
734
|
+
animationDelay). Reduced-motion base layer forces duration to 0.01ms. */
|
|
735
|
+
@keyframes typing-dot {
|
|
736
|
+
0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
|
|
737
|
+
30% { transform: translateY(-4px); opacity: 1; }
|
|
738
|
+
}
|
|
739
|
+
|
|
732
740
|
::view-transition-new(root) {
|
|
733
741
|
animation: theme-reveal 0.4s ease-in-out forwards;
|
|
734
742
|
}
|
|
@@ -201,7 +201,10 @@ import {
|
|
|
201
201
|
HoverCardDescription,
|
|
202
202
|
HoverCardTrigger,
|
|
203
203
|
} from "@behavioral-agentic-design-system/core/components/ui/hover-card";
|
|
204
|
-
import { Sparkles, Info, CircleAlert, CalendarIcon, BuildingIcon, CheckIcon, CreditCardIcon, ClipboardCheckIcon, TrophyIcon, UserCheckIcon, XIcon, ZapIcon, StarIcon, ShieldCheckIcon, InboxIcon, WifiOffIcon, ClipboardListIcon, PlusIcon, HomeIcon, SearchIcon, LibraryIcon, PaletteIcon, UserIcon, BellIcon, BookOpenIcon, DownloadIcon, TriangleAlertIcon, CheckCircle2Icon, GitPullRequestIcon, MessageSquareIcon } from "lucide-react";
|
|
204
|
+
import { Sparkles, Info, CircleAlert, CalendarIcon, BuildingIcon, CheckIcon, CreditCardIcon, ClipboardCheckIcon, TrophyIcon, UserCheckIcon, XIcon, ZapIcon, StarIcon, ShieldCheckIcon, InboxIcon, WifiOffIcon, ClipboardListIcon, PlusIcon, HomeIcon, SearchIcon, LibraryIcon, PaletteIcon, UserIcon, BellIcon, BookOpenIcon, DownloadIcon, TriangleAlertIcon, CheckCircle2Icon, GitPullRequestIcon, MessageSquareIcon, PencilIcon } from "lucide-react";
|
|
205
|
+
import { FloatingActionButton } from "@behavioral-agentic-design-system/core/components/ui/floating-action-button";
|
|
206
|
+
import { TypingIndicator } from "@behavioral-agentic-design-system/core/components/ui/typing-indicator";
|
|
207
|
+
import { WordRotate } from "@behavioral-agentic-design-system/core/components/ui/word-rotate";
|
|
205
208
|
import {
|
|
206
209
|
BottomNavigation,
|
|
207
210
|
BottomNavigationItem,
|
|
@@ -5245,6 +5248,15 @@ export default function ComponentsPreview() {
|
|
|
5245
5248
|
<Section title="Signature Pad">
|
|
5246
5249
|
<SignaturePadShowcase />
|
|
5247
5250
|
</Section>
|
|
5251
|
+
<Section title="Floating Action Button">
|
|
5252
|
+
<FloatingActionButtonShowcase />
|
|
5253
|
+
</Section>
|
|
5254
|
+
<Section title="Typing Indicator">
|
|
5255
|
+
<TypingIndicatorShowcase />
|
|
5256
|
+
</Section>
|
|
5257
|
+
<Section title="WordRotate">
|
|
5258
|
+
<WordRotateShowcase />
|
|
5259
|
+
</Section>
|
|
5248
5260
|
</div>
|
|
5249
5261
|
</div>
|
|
5250
5262
|
);
|
|
@@ -7960,3 +7972,226 @@ function TimerShowcase() {
|
|
|
7960
7972
|
</div>
|
|
7961
7973
|
);
|
|
7962
7974
|
}
|
|
7975
|
+
|
|
7976
|
+
function FloatingActionButtonShowcase() {
|
|
7977
|
+
/**
|
|
7978
|
+
* FABs are `position: fixed`, so each demo lives inside a frame with
|
|
7979
|
+
* `position: relative; overflow: hidden` PLUS `transform: translateZ(0)`.
|
|
7980
|
+
* The transform makes the frame the containing block for fixed descendants
|
|
7981
|
+
* (relative alone does NOT contain `fixed`), and overflow-hidden keeps the
|
|
7982
|
+
* pinned button from escaping the showcase section onto the page viewport.
|
|
7983
|
+
*/
|
|
7984
|
+
const Frame = ({
|
|
7985
|
+
caption,
|
|
7986
|
+
children,
|
|
7987
|
+
tall,
|
|
7988
|
+
}: {
|
|
7989
|
+
caption: React.ReactNode;
|
|
7990
|
+
children: React.ReactNode;
|
|
7991
|
+
tall?: boolean;
|
|
7992
|
+
}) => (
|
|
7993
|
+
<div className="space-y-2">
|
|
7994
|
+
<p className="text-xs font-medium text-muted-foreground">{caption}</p>
|
|
7995
|
+
<div
|
|
7996
|
+
// lint-disable: card-bypass — needs [transform:translateZ(0)] to confine position:fixed FAB children; Card doesn't expose that CSS prop
|
|
7997
|
+
className={`relative ${tall ? "h-52" : "h-40"} overflow-hidden rounded-lg border bg-card [transform:translateZ(0)]`}
|
|
7998
|
+
>
|
|
7999
|
+
<div className="p-4">
|
|
8000
|
+
<p className="text-sm text-muted-foreground">
|
|
8001
|
+
The frame stands in for the viewport.
|
|
8002
|
+
</p>
|
|
8003
|
+
</div>
|
|
8004
|
+
{children}
|
|
8005
|
+
</div>
|
|
8006
|
+
</div>
|
|
8007
|
+
);
|
|
8008
|
+
|
|
8009
|
+
return (
|
|
8010
|
+
<div className="space-y-6">
|
|
8011
|
+
<p className="text-sm text-muted-foreground">
|
|
8012
|
+
Fixed-position circular button for the ONE primary action of a surface
|
|
8013
|
+
— the single-action counterpart to SpeedDial. Wraps Button (focus
|
|
8014
|
+
ring, loading, disabled inherited); md is the 56px thumb-target
|
|
8015
|
+
convention; icon-only form requires{" "}
|
|
8016
|
+
<code className="font-mono">aria-label</code>. Entrance zoom/fade and
|
|
8017
|
+
the shadow lift ride the motion tokens and collapse under
|
|
8018
|
+
reduced-motion.
|
|
8019
|
+
</p>
|
|
8020
|
+
<div className="grid gap-6 lg:grid-cols-2">
|
|
8021
|
+
<Frame caption="Default — primary, bottom-right, md (56px)">
|
|
8022
|
+
<FloatingActionButton
|
|
8023
|
+
icon={<PlusIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8024
|
+
aria-label="Create new"
|
|
8025
|
+
/>
|
|
8026
|
+
</Frame>
|
|
8027
|
+
<Frame caption="Extended — visible label is the accessible name">
|
|
8028
|
+
<FloatingActionButton
|
|
8029
|
+
icon={<PencilIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8030
|
+
label="New review"
|
|
8031
|
+
/>
|
|
8032
|
+
</Frame>
|
|
8033
|
+
<Frame caption="Secondary variant — support chat, bottom-left">
|
|
8034
|
+
<FloatingActionButton
|
|
8035
|
+
variant="secondary"
|
|
8036
|
+
corner="bottom-left"
|
|
8037
|
+
icon={<MessageSquareIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8038
|
+
aria-label="Open support chat"
|
|
8039
|
+
/>
|
|
8040
|
+
</Frame>
|
|
8041
|
+
<Frame
|
|
8042
|
+
tall
|
|
8043
|
+
caption="Sizes — sm 40px (below the 44px floor: dense secondary chrome only), md 56px, lg 64px"
|
|
8044
|
+
>
|
|
8045
|
+
<FloatingActionButton
|
|
8046
|
+
size="sm"
|
|
8047
|
+
variant="secondary"
|
|
8048
|
+
corner="top-left"
|
|
8049
|
+
icon={<PlusIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8050
|
+
aria-label="Add token (compact)"
|
|
8051
|
+
/>
|
|
8052
|
+
<FloatingActionButton
|
|
8053
|
+
size="md"
|
|
8054
|
+
corner="bottom-left"
|
|
8055
|
+
icon={<PlusIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8056
|
+
aria-label="Create new"
|
|
8057
|
+
/>
|
|
8058
|
+
<FloatingActionButton
|
|
8059
|
+
size="lg"
|
|
8060
|
+
icon={<PlusIcon strokeWidth={1.5} aria-hidden="true" />}
|
|
8061
|
+
aria-label="Create new (large)"
|
|
8062
|
+
/>
|
|
8063
|
+
</Frame>
|
|
8064
|
+
</div>
|
|
8065
|
+
</div>
|
|
8066
|
+
);
|
|
8067
|
+
}
|
|
8068
|
+
|
|
8069
|
+
function TypingIndicatorShowcase() {
|
|
8070
|
+
const [phase, setPhase] = React.useState<"idle" | "typing" | "done">("idle")
|
|
8071
|
+
const [response, setResponse] = React.useState("")
|
|
8072
|
+
|
|
8073
|
+
const handleSend = () => {
|
|
8074
|
+
setPhase("typing")
|
|
8075
|
+
setResponse("")
|
|
8076
|
+
setTimeout(() => {
|
|
8077
|
+
setPhase("done")
|
|
8078
|
+
setResponse("Here are three options for animated numbers: RollingNumber (odometer), Timer (countdown), and FormatNumber (static locale). Pick based on whether the value changes live.")
|
|
8079
|
+
}, 2600)
|
|
8080
|
+
}
|
|
8081
|
+
|
|
8082
|
+
return (
|
|
8083
|
+
<div className="flex flex-col gap-6 w-full">
|
|
8084
|
+
{/* Sizes */}
|
|
8085
|
+
<div className="flex flex-col gap-2">
|
|
8086
|
+
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide">Sizes</p>
|
|
8087
|
+
<div className="flex items-center gap-4">
|
|
8088
|
+
<div className="flex flex-col items-start gap-1">
|
|
8089
|
+
<TypingIndicator size="sm" />
|
|
8090
|
+
<span className="text-xs text-muted-foreground">sm</span>
|
|
8091
|
+
</div>
|
|
8092
|
+
<div className="flex flex-col items-start gap-1">
|
|
8093
|
+
<TypingIndicator size="default" />
|
|
8094
|
+
<span className="text-xs text-muted-foreground">default</span>
|
|
8095
|
+
</div>
|
|
8096
|
+
<div className="flex flex-col items-start gap-1">
|
|
8097
|
+
<TypingIndicator size="lg" />
|
|
8098
|
+
<span className="text-xs text-muted-foreground">lg</span>
|
|
8099
|
+
</div>
|
|
8100
|
+
</div>
|
|
8101
|
+
</div>
|
|
8102
|
+
|
|
8103
|
+
{/* Realistic chat UI */}
|
|
8104
|
+
<div className="flex flex-col gap-2">
|
|
8105
|
+
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide">Realistic use</p>
|
|
8106
|
+
<div className="rounded-lg border bg-card p-4 max-w-sm flex flex-col gap-3">
|
|
8107
|
+
{/* User message */}
|
|
8108
|
+
<div className="flex justify-end">
|
|
8109
|
+
<div className="max-w-[70%] rounded-2xl rounded-tr-sm bg-primary px-3 py-2 text-sm text-primary-foreground">
|
|
8110
|
+
Which component for animated numbers?
|
|
8111
|
+
</div>
|
|
8112
|
+
</div>
|
|
8113
|
+
|
|
8114
|
+
{/* Assistant area */}
|
|
8115
|
+
<div className="flex items-end gap-2 min-h-[36px]">
|
|
8116
|
+
<Avatar size="sm" className="shrink-0">
|
|
8117
|
+
<AvatarFallback>B</AvatarFallback>
|
|
8118
|
+
</Avatar>
|
|
8119
|
+
<div>
|
|
8120
|
+
{phase === "idle" && (
|
|
8121
|
+
<p className="text-sm text-muted-foreground">Click "Ask BADS" to see the typing indicator.</p>
|
|
8122
|
+
)}
|
|
8123
|
+
{phase === "typing" && (
|
|
8124
|
+
<TypingIndicator label="BADS assistant is typing" />
|
|
8125
|
+
)}
|
|
8126
|
+
{phase === "done" && (
|
|
8127
|
+
<div className="rounded-2xl rounded-tl-sm bg-muted px-3 py-2 text-sm">
|
|
8128
|
+
{response}
|
|
8129
|
+
</div>
|
|
8130
|
+
)}
|
|
8131
|
+
</div>
|
|
8132
|
+
</div>
|
|
8133
|
+
|
|
8134
|
+
<Button
|
|
8135
|
+
size="xl"
|
|
8136
|
+
onClick={handleSend}
|
|
8137
|
+
disabled={phase === "typing"}
|
|
8138
|
+
className="w-full"
|
|
8139
|
+
>
|
|
8140
|
+
{phase === "typing" ? "Waiting…" : "Ask BADS"}
|
|
8141
|
+
</Button>
|
|
8142
|
+
</div>
|
|
8143
|
+
</div>
|
|
8144
|
+
</div>
|
|
8145
|
+
)
|
|
8146
|
+
}
|
|
8147
|
+
|
|
8148
|
+
function WordRotateShowcase() {
|
|
8149
|
+
return (
|
|
8150
|
+
<div className="space-y-6">
|
|
8151
|
+
<p className="text-sm text-muted-foreground">
|
|
8152
|
+
Cycles an array of words in place with a slide-fade exit/entrance. Zero
|
|
8153
|
+
dependencies — pure CSS transitions keyed to{" "}
|
|
8154
|
+
<code className="text-xs">var(--duration-base)</code>. Announced via{" "}
|
|
8155
|
+
<code className="text-xs">aria-live="polite"</code> on each swap.
|
|
8156
|
+
Reduced-motion safe via the base layer.
|
|
8157
|
+
</p>
|
|
8158
|
+
<div className="space-y-8">
|
|
8159
|
+
<div className="space-y-2">
|
|
8160
|
+
<p className="text-xs font-medium text-muted-foreground">Default — 2 s interval in a heading</p>
|
|
8161
|
+
<p className="text-2xl font-semibold text-foreground">
|
|
8162
|
+
Design systems that are{" "}
|
|
8163
|
+
<WordRotate words={["accessible", "beautiful", "consistent"]} />
|
|
8164
|
+
</p>
|
|
8165
|
+
</div>
|
|
8166
|
+
<div className="space-y-2">
|
|
8167
|
+
<p className="text-xs font-medium text-muted-foreground">Branded colour — status rotation, 1 s interval</p>
|
|
8168
|
+
<p className="text-2xl font-semibold text-foreground">
|
|
8169
|
+
Status:{" "}
|
|
8170
|
+
<WordRotate
|
|
8171
|
+
words={["building", "testing", "shipping"]}
|
|
8172
|
+
interval={1000}
|
|
8173
|
+
className="text-primary"
|
|
8174
|
+
/>
|
|
8175
|
+
</p>
|
|
8176
|
+
</div>
|
|
8177
|
+
<div className="space-y-2">
|
|
8178
|
+
<p className="text-xs font-medium text-muted-foreground">Realistic use — marketing hero, 3 s interval</p>
|
|
8179
|
+
<div className="flex max-w-sm flex-col gap-4 rounded-lg border border-border bg-card p-6">
|
|
8180
|
+
<h2 className="text-2xl font-bold text-card-foreground">
|
|
8181
|
+
Ship{" "}
|
|
8182
|
+
<WordRotate
|
|
8183
|
+
words={["faster", "smarter", "cleaner"]}
|
|
8184
|
+
interval={3000}
|
|
8185
|
+
className="text-primary"
|
|
8186
|
+
/>
|
|
8187
|
+
{" "}with every client.
|
|
8188
|
+
</h2>
|
|
8189
|
+
<p className="text-sm text-muted-foreground">
|
|
8190
|
+
Jordan Reeves · design.bads.com · 88 registry components.
|
|
8191
|
+
</p>
|
|
8192
|
+
</div>
|
|
8193
|
+
</div>
|
|
8194
|
+
</div>
|
|
8195
|
+
</div>
|
|
8196
|
+
);
|
|
8197
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../../lib/utils";
|
|
7
|
+
import { Button } from "./button";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* FloatingActionButton — fixed-position circular button that triggers a
|
|
11
|
+
* single primary action, pinned to a viewport corner. The single-action
|
|
12
|
+
* counterpart to SpeedDial (which opens a submenu of 2–5 quick actions).
|
|
13
|
+
* Cross-library Tier 1 pattern: MUI `Fab` + Ant Design `FloatButton`.
|
|
14
|
+
*
|
|
15
|
+
* Wraps the Button primitive, so focus ring, loading (spinner + aria-busy +
|
|
16
|
+
* disabled), and disabled affordances are inherited — this file only owns
|
|
17
|
+
* positioning, shape, size contract, and entrance motion.
|
|
18
|
+
*
|
|
19
|
+
* Accessible name is REQUIRED: either a visible `label` (extended/pill form)
|
|
20
|
+
* or `aria-label` when icon-only. A dev-mode warning fires when both are
|
|
21
|
+
* missing.
|
|
22
|
+
*
|
|
23
|
+
* Motion:
|
|
24
|
+
* - entrance: tw-animate-css `animate-in fade-in-0 zoom-in-75` (existing
|
|
25
|
+
* keyframe utility — spec §4 pattern (a), same family Dialog/Tooltip use)
|
|
26
|
+
* - hover/active: shadow elevation shift on `transition-shadow` with inline
|
|
27
|
+
* token vars (spec §4 pattern (c)); bg hover comes from Button's own
|
|
28
|
+
* `transition-colors` variant classes
|
|
29
|
+
* - reduced motion: base-layer prefers-reduced-motion kill-switch, no
|
|
30
|
+
* per-component guard needed
|
|
31
|
+
*
|
|
32
|
+
* Exit motion on unmount is deliberately out of scope — the element is
|
|
33
|
+
* removed before an exit keyframe could play; animated dismissal needs
|
|
34
|
+
* presence management (a future follow-up, same limitation as Ant
|
|
35
|
+
* FloatButton).
|
|
36
|
+
*/
|
|
37
|
+
const fabVariants = cva(
|
|
38
|
+
// fixed + z-50 floats above page content; rounded-full is the FAB shape
|
|
39
|
+
// contract; shadow ladder (lg → xl on hover → md on active) is the lift
|
|
40
|
+
// affordance — never hover:scale (BADS-SLOP-3 anti-default). The explicit
|
|
41
|
+
// property list replaces Button's `transition-colors` (same tailwind-merge
|
|
42
|
+
// group) so bg hover AND elevation both animate — never `transition-all`.
|
|
43
|
+
"fixed z-50 rounded-full shadow-lg transition-[background-color,color,box-shadow] hover:shadow-xl active:shadow-md animate-in fade-in-0 zoom-in-75",
|
|
44
|
+
{
|
|
45
|
+
variants: {
|
|
46
|
+
size: {
|
|
47
|
+
// sm is 40px — BELOW the 44px SC 2.5.5 floor. Dense/desktop-secondary
|
|
48
|
+
// chrome only; never a primary CTA (registry antiPatterns).
|
|
49
|
+
sm: "min-h-10 min-w-10 [&_svg:not([class*='size-'])]:size-5",
|
|
50
|
+
// md 56px is the thumb-target convention both source systems default to.
|
|
51
|
+
md: "min-h-14 min-w-14 [&_svg:not([class*='size-'])]:size-6",
|
|
52
|
+
lg: "min-h-16 min-w-16 [&_svg:not([class*='size-'])]:size-6",
|
|
53
|
+
},
|
|
54
|
+
corner: {
|
|
55
|
+
"bottom-right": "bottom-6 right-6",
|
|
56
|
+
"bottom-left": "bottom-6 left-6",
|
|
57
|
+
"top-right": "top-6 right-6",
|
|
58
|
+
"top-left": "top-6 left-6",
|
|
59
|
+
},
|
|
60
|
+
// extended = visible label → pill form. Explicit h-* + px-* override
|
|
61
|
+
// Button's size classes via tailwind-merge; round form zeroes padding so
|
|
62
|
+
// min-h/min-w keep the button square.
|
|
63
|
+
extended: {
|
|
64
|
+
false: "px-0 py-0",
|
|
65
|
+
true: "gap-2 text-sm font-medium",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
compoundVariants: [
|
|
69
|
+
{ extended: false, size: "sm", class: "h-10 w-10" },
|
|
70
|
+
{ extended: false, size: "md", class: "h-14 w-14" },
|
|
71
|
+
{ extended: false, size: "lg", class: "h-16 w-16" },
|
|
72
|
+
{ extended: true, size: "sm", class: "h-10 px-4" },
|
|
73
|
+
{ extended: true, size: "md", class: "h-14 px-5" },
|
|
74
|
+
{ extended: true, size: "lg", class: "h-16 px-6" },
|
|
75
|
+
],
|
|
76
|
+
defaultVariants: {
|
|
77
|
+
size: "md",
|
|
78
|
+
corner: "bottom-right",
|
|
79
|
+
extended: false,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
interface FloatingActionButtonProps
|
|
85
|
+
extends Omit<React.ComponentProps<"button">, "children">,
|
|
86
|
+
Omit<VariantProps<typeof fabVariants>, "extended"> {
|
|
87
|
+
/** Required — the icon rendered inside. Lucide at strokeWidth 1.5 by convention. */
|
|
88
|
+
icon: React.ReactNode;
|
|
89
|
+
/** Visible label beside the icon — switches to the extended (pill) FAB form. */
|
|
90
|
+
label?: string;
|
|
91
|
+
/** Maps to Button variants: primary → default, secondary → secondary. */
|
|
92
|
+
variant?: "primary" | "secondary";
|
|
93
|
+
/** Spinner replaces the icon; aria-busy + disabled via Button. Dimensions stay stable. */
|
|
94
|
+
loading?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Render via Radix Slot (e.g. a Next.js Link). The composed icon + label
|
|
97
|
+
* are injected as the child's children; if the child already has its own
|
|
98
|
+
* children, those win (compose the icon yourself in that case). Button's
|
|
99
|
+
* asChild contract applies: `loading` is a no-op with asChild.
|
|
100
|
+
*/
|
|
101
|
+
asChild?: boolean;
|
|
102
|
+
children?: React.ReactNode;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function FloatingActionButton({
|
|
106
|
+
icon,
|
|
107
|
+
label,
|
|
108
|
+
size = "md",
|
|
109
|
+
corner = "bottom-right",
|
|
110
|
+
variant = "primary",
|
|
111
|
+
loading = false,
|
|
112
|
+
asChild = false,
|
|
113
|
+
className,
|
|
114
|
+
style,
|
|
115
|
+
children,
|
|
116
|
+
...props
|
|
117
|
+
}: FloatingActionButtonProps) {
|
|
118
|
+
if (process.env.NODE_ENV !== "production") {
|
|
119
|
+
if (
|
|
120
|
+
!label &&
|
|
121
|
+
!props["aria-label"] &&
|
|
122
|
+
!props["aria-labelledby"] &&
|
|
123
|
+
!asChild
|
|
124
|
+
) {
|
|
125
|
+
console.warn(
|
|
126
|
+
"FloatingActionButton: icon-only FABs need an accessible name — pass `aria-label` (or a visible `label`)."
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const content = (
|
|
132
|
+
<>
|
|
133
|
+
{/* Button renders its own aria-hidden spinner when loading; hide the
|
|
134
|
+
icon then so the round form stays a single centered glyph. */}
|
|
135
|
+
{loading && !asChild ? null : icon}
|
|
136
|
+
{label ? <span>{label}</span> : null}
|
|
137
|
+
</>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
let inner: React.ReactNode = content;
|
|
141
|
+
if (asChild && React.isValidElement(children)) {
|
|
142
|
+
const child = children as React.ReactElement<{
|
|
143
|
+
children?: React.ReactNode;
|
|
144
|
+
}>;
|
|
145
|
+
// Slot needs exactly one child; inject the composed icon/label into it
|
|
146
|
+
// unless the consumer already hand-composed the child's content.
|
|
147
|
+
inner =
|
|
148
|
+
child.props.children != null
|
|
149
|
+
? child
|
|
150
|
+
: React.cloneElement(child, undefined, content);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<Button
|
|
155
|
+
asChild={asChild}
|
|
156
|
+
variant={variant === "secondary" ? "secondary" : "default"}
|
|
157
|
+
loading={loading}
|
|
158
|
+
data-slot="floating-action-button"
|
|
159
|
+
data-state="visible"
|
|
160
|
+
className={cn(fabVariants({ size, corner, extended: Boolean(label) }), className)}
|
|
161
|
+
// Elevation lift timing rides the motion tokens (spec §4 pattern (c));
|
|
162
|
+
// CSS vars resolve at runtime against :root, so tokens.json changes
|
|
163
|
+
// propagate without a rebuild of this file. Consumer style merges on
|
|
164
|
+
// top (but the motion tokens are listed first so an explicit consumer
|
|
165
|
+
// override still wins).
|
|
166
|
+
style={{
|
|
167
|
+
transitionDuration: "var(--duration-fast)",
|
|
168
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
169
|
+
...style,
|
|
170
|
+
}}
|
|
171
|
+
{...props}
|
|
172
|
+
>
|
|
173
|
+
{inner}
|
|
174
|
+
</Button>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { FloatingActionButton, fabVariants };
|
|
179
|
+
export type { FloatingActionButtonProps };
|
|
@@ -118,9 +118,9 @@ function Meter({
|
|
|
118
118
|
: null)}
|
|
119
119
|
className={cn(
|
|
120
120
|
meterVariants({ variant, size }),
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
disabled &&
|
|
121
|
+
// Always dim the track when disabled — label text stays at full
|
|
122
|
+
// opacity so it meets WCAG AAA contrast regardless of state.
|
|
123
|
+
disabled && "opacity-50",
|
|
124
124
|
className
|
|
125
125
|
)}
|
|
126
126
|
{...props}
|
|
@@ -152,7 +152,7 @@ function Meter({
|
|
|
152
152
|
return (
|
|
153
153
|
<div
|
|
154
154
|
data-slot="meter-wrapper"
|
|
155
|
-
className=
|
|
155
|
+
className="flex w-full flex-col gap-2"
|
|
156
156
|
>
|
|
157
157
|
<div className="flex items-center justify-between gap-3">
|
|
158
158
|
{showLabel ? (
|
|
@@ -50,12 +50,39 @@ interface PanelProps {
|
|
|
50
50
|
|
|
51
51
|
function Panel({ label, items, checked, onToggle, searchable }: PanelProps) {
|
|
52
52
|
const [filter, setFilter] = React.useState("")
|
|
53
|
+
const [activeIdx, setActiveIdx] = React.useState(-1)
|
|
53
54
|
const listboxId = React.useId()
|
|
54
55
|
|
|
55
56
|
const visible = filter
|
|
56
57
|
? items.filter((it) => it.toLowerCase().includes(filter.toLowerCase()))
|
|
57
58
|
: items
|
|
58
59
|
|
|
60
|
+
// Reset active index when visible list changes (filter or items update)
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setActiveIdx(-1)
|
|
63
|
+
}, [filter, items])
|
|
64
|
+
|
|
65
|
+
function handleKeyDown(e: React.KeyboardEvent<HTMLUListElement>) {
|
|
66
|
+
if (visible.length === 0) return
|
|
67
|
+
if (e.key === "ArrowDown") {
|
|
68
|
+
e.preventDefault()
|
|
69
|
+
setActiveIdx((prev) => (prev + 1) % visible.length)
|
|
70
|
+
} else if (e.key === "ArrowUp") {
|
|
71
|
+
e.preventDefault()
|
|
72
|
+
setActiveIdx((prev) => (prev <= 0 ? visible.length - 1 : prev - 1))
|
|
73
|
+
} else if (e.key === " " || e.key === "Enter") {
|
|
74
|
+
e.preventDefault()
|
|
75
|
+
if (activeIdx >= 0 && activeIdx < visible.length) {
|
|
76
|
+
onToggle(visible[activeIdx])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const activeItemId =
|
|
82
|
+
activeIdx >= 0 && activeIdx < visible.length
|
|
83
|
+
? `${listboxId}-opt-${activeIdx}`
|
|
84
|
+
: undefined
|
|
85
|
+
|
|
59
86
|
return (
|
|
60
87
|
<div className="w-56 min-h-48 max-h-72 rounded-md border border-border bg-background overflow-hidden flex flex-col">
|
|
61
88
|
{/* Panel header */}
|
|
@@ -78,41 +105,49 @@ function Panel({ label, items, checked, onToggle, searchable }: PanelProps) {
|
|
|
78
105
|
</div>
|
|
79
106
|
)}
|
|
80
107
|
|
|
81
|
-
{/* Item list
|
|
108
|
+
{/* Item list — container is the sole focusable target; items use
|
|
109
|
+
aria-activedescendant so screen readers track the active option
|
|
110
|
+
without each item needing its own tabIndex (nested-interactive). */}
|
|
82
111
|
<ul
|
|
83
112
|
id={listboxId}
|
|
84
113
|
role="listbox"
|
|
85
114
|
aria-multiselectable="true"
|
|
86
115
|
aria-label={label}
|
|
87
|
-
|
|
116
|
+
aria-activedescendant={activeItemId}
|
|
117
|
+
tabIndex={0}
|
|
118
|
+
onKeyDown={handleKeyDown}
|
|
119
|
+
className="overflow-y-auto flex-1 py-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
|
|
88
120
|
>
|
|
89
121
|
{visible.length === 0 ? (
|
|
90
|
-
<li
|
|
122
|
+
<li
|
|
123
|
+
role="option"
|
|
124
|
+
aria-disabled="true"
|
|
125
|
+
aria-selected="false"
|
|
126
|
+
className="px-3 py-2 text-sm text-muted-foreground select-none"
|
|
127
|
+
>
|
|
91
128
|
No items
|
|
92
129
|
</li>
|
|
93
130
|
) : (
|
|
94
|
-
visible.map((item) => {
|
|
131
|
+
visible.map((item, idx) => {
|
|
95
132
|
const isChecked = checked.has(item)
|
|
133
|
+
const isActive = idx === activeIdx
|
|
96
134
|
return (
|
|
97
135
|
<li
|
|
98
136
|
key={item}
|
|
137
|
+
id={`${listboxId}-opt-${idx}`}
|
|
99
138
|
role="option"
|
|
100
139
|
aria-selected={isChecked}
|
|
101
|
-
onClick={() =>
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
e.preventDefault()
|
|
105
|
-
onToggle(item)
|
|
106
|
-
}
|
|
140
|
+
onClick={() => {
|
|
141
|
+
setActiveIdx(idx)
|
|
142
|
+
onToggle(item)
|
|
107
143
|
}}
|
|
108
|
-
tabIndex={0}
|
|
109
144
|
className={cn(
|
|
110
145
|
"flex items-center gap-2 px-2 py-1.5 cursor-pointer select-none text-sm",
|
|
111
146
|
"transition-colors",
|
|
112
|
-
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
|
|
113
147
|
isChecked
|
|
114
148
|
? "bg-accent text-accent-foreground"
|
|
115
|
-
: "hover:bg-muted"
|
|
149
|
+
: "hover:bg-muted",
|
|
150
|
+
isActive && "ring-1 ring-ring ring-inset"
|
|
116
151
|
)}
|
|
117
152
|
style={{
|
|
118
153
|
transitionDuration: "var(--duration-fast)",
|