@behavioral-agentic-design-system/core 0.28.0 → 0.29.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 +2 -2
- package/scripts/a11y-lint.cjs +78 -9
- package/scripts/build-tokens.cjs +273 -15
- package/scripts/wcag-audit.cjs +37 -7
- package/src/api/layers/file.ts +1 -0
- package/src/app/font-ready.tsx +6 -5
- package/src/app/layout.tsx +54 -3
- package/src/app/preview/components/page.tsx +5532 -3044
- package/src/app/preview/layout.tsx +4 -1
- package/src/app/preview/showcase-filter.tsx +66 -0
- package/src/app/preview/tab-replay.tsx +63 -0
- package/src/app/shell.tsx +74 -18
- package/src/components/customize/save-bar.tsx +19 -6
- package/src/components/docs-tab.tsx +36 -24
- package/src/components/layers-tab.tsx +37 -5
- package/src/components/ui/alert.tsx +12 -0
- package/src/components/ui/badge.tsx +19 -0
- package/src/components/ui/chat-marker.tsx +120 -0
- package/src/components/ui/checkbox.tsx +9 -1
- package/src/components/ui/close-button.tsx +71 -0
- package/src/components/ui/combobox.tsx +62 -3
- package/src/components/ui/container.tsx +65 -0
- package/src/components/ui/date-field.tsx +368 -0
- package/src/components/ui/drawer.tsx +334 -0
- package/src/components/ui/file-button.tsx +145 -0
- package/src/components/ui/floating-indicator.tsx +217 -0
- package/src/components/ui/format-byte.tsx +113 -0
- package/src/components/ui/index.ts +21 -0
- package/src/components/ui/input.tsx +38 -3
- package/src/components/ui/keyboard-shortcut.tsx +146 -0
- package/src/components/ui/loading-dots.tsx +99 -0
- package/src/components/ui/month-picker.tsx +296 -0
- package/src/components/ui/multi-select.tsx +15 -13
- package/src/components/ui/nav-link.tsx +200 -0
- package/src/components/ui/navigation-rail.tsx +256 -0
- package/src/components/ui/notification.tsx +20 -0
- package/src/components/ui/password-input.tsx +34 -1
- package/src/components/ui/progress.tsx +15 -1
- package/src/components/ui/prose.tsx +62 -0
- package/src/components/ui/result.tsx +151 -0
- package/src/components/ui/rolling-number.tsx +1 -0
- package/src/components/ui/simple-grid.tsx +110 -0
- package/src/components/ui/skeleton.tsx +52 -3
- package/src/components/ui/squircle.tsx +274 -0
- package/src/components/ui/stack.tsx +105 -0
- package/src/components/ui/status-badge.tsx +93 -0
- package/src/components/ui/tabs.tsx +34 -7
- package/src/components/ui/tag.tsx +46 -5
- package/src/components/ui/theme-icon.tsx +138 -0
- package/src/components/ui/timeline.tsx +27 -10
- package/src/components/ui/tooltip.tsx +12 -1
- package/src/components/ui/tree-select.tsx +386 -0
- package/src/components/ui/year-picker.tsx +307 -0
- package/src/data/docs-index.ts +10 -0
- package/src/hooks/use-global-primary-color.ts +57 -6
- package/src/stories/Alert.stories.tsx +31 -1
- package/src/stories/Badge.stories.tsx +63 -6
- package/src/stories/ChatMarker.stories.tsx +59 -0
- package/src/stories/Checkbox.stories.tsx +5 -0
- package/src/stories/CloseButton.stories.tsx +65 -0
- package/src/stories/Combobox.stories.tsx +74 -3
- package/src/stories/Container.stories.tsx +134 -0
- package/src/stories/DateField.stories.tsx +114 -0
- package/src/stories/Drawer.stories.tsx +211 -0
- package/src/stories/FileButton.stories.tsx +117 -0
- package/src/stories/FloatingIndicator.stories.tsx +343 -0
- package/src/stories/FormatByte.stories.tsx +142 -0
- package/src/stories/Input.stories.tsx +91 -0
- package/src/stories/KeyboardShortcut.stories.tsx +87 -0
- package/src/stories/LoadingDots.stories.tsx +73 -0
- package/src/stories/MonthPicker.stories.tsx +99 -0
- package/src/stories/MultiSelect.stories.tsx +3 -1
- package/src/stories/NavLink.stories.tsx +213 -0
- package/src/stories/NavigationRail.stories.tsx +413 -0
- package/src/stories/Notification.stories.tsx +53 -0
- package/src/stories/PasswordInput.stories.tsx +21 -0
- package/src/stories/Progress.stories.tsx +38 -0
- package/src/stories/Prose.stories.tsx +232 -0
- package/src/stories/Result.stories.tsx +145 -0
- package/src/stories/RollingNumber.stories.tsx +1 -1
- package/src/stories/SimpleGrid.stories.tsx +130 -0
- package/src/stories/Skeleton.stories.tsx +62 -1
- package/src/stories/Squircle.stories.tsx +127 -0
- package/src/stories/Stack.stories.tsx +139 -0
- package/src/stories/StatusBadge.stories.tsx +125 -0
- package/src/stories/Tabs.stories.tsx +56 -1
- package/src/stories/Tag.stories.tsx +31 -0
- package/src/stories/ThemeIcon.stories.tsx +97 -0
- package/src/stories/Timeline.stories.tsx +69 -0
- package/src/stories/Tooltip.stories.tsx +18 -0
- package/src/stories/TreeSelect.stories.tsx +222 -0
- package/src/stories/YearPicker.stories.tsx +100 -0
- package/src/styles.css +289 -15
- package/src/tokens.json +96 -1
- package/LICENSE +0 -21
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { Button } from "./button";
|
|
6
|
+
|
|
7
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
export interface FileButtonProps
|
|
10
|
+
extends Omit<
|
|
11
|
+
React.ComponentProps<"button">,
|
|
12
|
+
"children" | "onClick" | "onChange"
|
|
13
|
+
> {
|
|
14
|
+
/** Called with the selected File[] (or null on cancel / empty selection). */
|
|
15
|
+
onChange?: (files: File[] | null) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Accept string passed to <input type="file">. e.g. "image/*", ".pdf,.docx".
|
|
18
|
+
* Omit to accept all file types.
|
|
19
|
+
*/
|
|
20
|
+
accept?: string;
|
|
21
|
+
/** Allow multiple file selection. Default false. */
|
|
22
|
+
multiple?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Visible label / trigger children. Defaults to "Upload file" so the button
|
|
25
|
+
* always has an accessible name. Icon-only usage MUST pass aria-label.
|
|
26
|
+
*/
|
|
27
|
+
children?: React.ReactNode;
|
|
28
|
+
/**
|
|
29
|
+
* Forward ref to the hidden input, for programmatic reset via
|
|
30
|
+
* `inputRef.current.value = ""` (the component already resets after every
|
|
31
|
+
* selection so the same file can be re-picked).
|
|
32
|
+
*/
|
|
33
|
+
inputRef?: React.RefObject<HTMLInputElement | null>;
|
|
34
|
+
/** Button size (forwarded to Button). Default "default". */
|
|
35
|
+
size?: "sm" | "default" | "lg" | "xl" | "2xl" | "icon";
|
|
36
|
+
/** Button variant (forwarded to Button). Default "outline". */
|
|
37
|
+
variant?:
|
|
38
|
+
| "default"
|
|
39
|
+
| "destructive"
|
|
40
|
+
| "outline"
|
|
41
|
+
| "secondary"
|
|
42
|
+
| "ghost"
|
|
43
|
+
| "link";
|
|
44
|
+
/** Disabled forwarded to both the button and the hidden input. */
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ─── FileButton ───────────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Click-to-browse file picker trigger. Renders as a BADS Button that
|
|
52
|
+
* programmatically clicks a visually-hidden <input type="file">.
|
|
53
|
+
*
|
|
54
|
+
* Distinct from FileUpload (drag-and-drop dropzone with file list, reject
|
|
55
|
+
* state, and size validation) — FileButton is the pure button affordance:
|
|
56
|
+
* profile photo change, "Import CSV", document attachment in a composer.
|
|
57
|
+
*
|
|
58
|
+
* Does NOT upload anything. The consumer's onChange handler owns any network
|
|
59
|
+
* call and its own consent/retention obligations.
|
|
60
|
+
*
|
|
61
|
+
* Motion: none of its own — hover/focus/active transitions inherit from
|
|
62
|
+
* Button's existing token-driven contract (transition-colors + focus ring).
|
|
63
|
+
*/
|
|
64
|
+
function FileButton({
|
|
65
|
+
onChange,
|
|
66
|
+
accept,
|
|
67
|
+
multiple = false,
|
|
68
|
+
children = "Upload file",
|
|
69
|
+
inputRef,
|
|
70
|
+
size = "default",
|
|
71
|
+
variant = "outline",
|
|
72
|
+
disabled,
|
|
73
|
+
...props
|
|
74
|
+
}: FileButtonProps) {
|
|
75
|
+
const internalRef = React.useRef<HTMLInputElement | null>(null);
|
|
76
|
+
|
|
77
|
+
// One callback ref feeds both the internal ref (used for .click()) and the
|
|
78
|
+
// consumer's optional inputRef (used for programmatic reset).
|
|
79
|
+
const setInputRef = React.useCallback(
|
|
80
|
+
(node: HTMLInputElement | null) => {
|
|
81
|
+
internalRef.current = node;
|
|
82
|
+
if (inputRef) inputRef.current = node;
|
|
83
|
+
},
|
|
84
|
+
[inputRef]
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
88
|
+
const list = e.target.files;
|
|
89
|
+
onChange?.(list && list.length > 0 ? Array.from(list) : null);
|
|
90
|
+
// Reset so selecting the same file again re-fires change.
|
|
91
|
+
e.target.value = "";
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// Native `cancel` event (Chrome 113+/Safari 16.4+/Firefox 91+): user opened
|
|
95
|
+
// the picker and dismissed it. Attached natively — React's typed props don't
|
|
96
|
+
// include onCancel on <input>. Older browsers just never fire this —
|
|
97
|
+
// degraded (no null callback), not broken.
|
|
98
|
+
const onChangeRef = React.useRef(onChange);
|
|
99
|
+
React.useLayoutEffect(() => {
|
|
100
|
+
onChangeRef.current = onChange;
|
|
101
|
+
});
|
|
102
|
+
React.useEffect(() => {
|
|
103
|
+
const node = internalRef.current;
|
|
104
|
+
if (!node) return;
|
|
105
|
+
const handleCancel = () => onChangeRef.current?.(null);
|
|
106
|
+
node.addEventListener("cancel", handleCancel);
|
|
107
|
+
return () => node.removeEventListener("cancel", handleCancel);
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<>
|
|
112
|
+
<Button
|
|
113
|
+
type="button"
|
|
114
|
+
data-slot="file-button"
|
|
115
|
+
variant={variant}
|
|
116
|
+
size={size}
|
|
117
|
+
disabled={disabled}
|
|
118
|
+
onClick={() => internalRef.current?.click()}
|
|
119
|
+
{...props}
|
|
120
|
+
>
|
|
121
|
+
{children}
|
|
122
|
+
</Button>
|
|
123
|
+
{/*
|
|
124
|
+
Hidden picker input. aria-hidden + tabIndex=-1: the Button is the single
|
|
125
|
+
interactive/announced stop — the input exists only to reach the OS
|
|
126
|
+
dialog. sr-only keeps it out of layout without display:none (which
|
|
127
|
+
would break .click() in some browsers).
|
|
128
|
+
*/}
|
|
129
|
+
<input
|
|
130
|
+
ref={setInputRef}
|
|
131
|
+
type="file"
|
|
132
|
+
data-slot="file-button-input"
|
|
133
|
+
accept={accept}
|
|
134
|
+
multiple={multiple}
|
|
135
|
+
disabled={disabled}
|
|
136
|
+
aria-hidden="true"
|
|
137
|
+
tabIndex={-1}
|
|
138
|
+
className="sr-only"
|
|
139
|
+
onChange={handleChange}
|
|
140
|
+
/>
|
|
141
|
+
</>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { FileButton };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { cn } from "../../lib/utils"
|
|
5
|
+
|
|
6
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
interface FloatingIndicatorProps {
|
|
9
|
+
/**
|
|
10
|
+
* The currently active element to track. Typically a ref.current for a nav
|
|
11
|
+
* item or tab trigger. When null, the indicator fades out.
|
|
12
|
+
*
|
|
13
|
+
* The element must be a descendant of `parent`.
|
|
14
|
+
*/
|
|
15
|
+
target: Element | null
|
|
16
|
+
/**
|
|
17
|
+
* The container element that wraps all nav items.
|
|
18
|
+
*
|
|
19
|
+
* **This element must have `position: relative` applied** so the indicator's
|
|
20
|
+
* `position: absolute` resolves against it. Without it the indicator will
|
|
21
|
+
* position against the nearest positioned ancestor, which is almost always wrong.
|
|
22
|
+
*/
|
|
23
|
+
parent: Element | null
|
|
24
|
+
/** Applied to the indicator div */
|
|
25
|
+
className?: string
|
|
26
|
+
/**
|
|
27
|
+
* CSS duration string, defaults to `var(--duration-base)`.
|
|
28
|
+
* Pass a CSS duration (`"150ms"`, `"var(--duration-fast)"`) to override per-instance.
|
|
29
|
+
* Prefer token vars over literal values so token changes propagate automatically.
|
|
30
|
+
*/
|
|
31
|
+
transitionDuration?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface IndicatorRect {
|
|
35
|
+
left: number
|
|
36
|
+
top: number
|
|
37
|
+
width: number
|
|
38
|
+
height: number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ─── Component ────────────────────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Animated highlight that slides between nav/tab items as selection changes.
|
|
45
|
+
*
|
|
46
|
+
* Renders an `aria-hidden` absolutely-positioned div that measures the active
|
|
47
|
+
* item's bounding rect relative to the parent container and smoothly translates
|
|
48
|
+
* to follow it. Motion uses token-driven `var(--duration-base)` + `var(--ease-out)`.
|
|
49
|
+
*
|
|
50
|
+
* **Usage requirements:**
|
|
51
|
+
* - The `parent` container must have `position: relative` (or any non-static position).
|
|
52
|
+
* - `target` must be a descendant of `parent`.
|
|
53
|
+
* - The indicator is purely decorative — all active-state ARIA (`aria-selected`,
|
|
54
|
+
* `aria-current`, `data-state="active"`) belongs on the nav items themselves.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* const containerRef = useRef<HTMLDivElement>(null)
|
|
59
|
+
* const [target, setTarget] = useState<HTMLElement | null>(null)
|
|
60
|
+
* const itemRefs = useRef<(HTMLButtonElement | null)[]>([])
|
|
61
|
+
*
|
|
62
|
+
* useEffect(() => {
|
|
63
|
+
* setTarget(itemRefs.current[activeIndex])
|
|
64
|
+
* }, [activeIndex])
|
|
65
|
+
*
|
|
66
|
+
* <div ref={containerRef} className="relative inline-flex bg-muted p-1 rounded-lg">
|
|
67
|
+
* <FloatingIndicator target={target} parent={containerRef.current} />
|
|
68
|
+
* {items.map((item, i) => (
|
|
69
|
+
* <button key={item} ref={el => { itemRefs.current[i] = el }} onClick={() => setActiveIndex(i)}>
|
|
70
|
+
* {item}
|
|
71
|
+
* </button>
|
|
72
|
+
* ))}
|
|
73
|
+
* </div>
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
function FloatingIndicator({
|
|
77
|
+
target,
|
|
78
|
+
parent,
|
|
79
|
+
className,
|
|
80
|
+
transitionDuration = "var(--duration-base)",
|
|
81
|
+
}: FloatingIndicatorProps) {
|
|
82
|
+
const [rect, setRect] = React.useState<IndicatorRect | null>(null)
|
|
83
|
+
// Track whether we've ever had a rect — used to skip the initial transition
|
|
84
|
+
// so the indicator appears in place on first render rather than flying in
|
|
85
|
+
// from the top-left corner.
|
|
86
|
+
const [hasInitialized, setHasInitialized] = React.useState(false)
|
|
87
|
+
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (!target || !parent) {
|
|
90
|
+
setRect(null)
|
|
91
|
+
setHasInitialized(false)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const measure = () => {
|
|
96
|
+
const parentRect = parent.getBoundingClientRect()
|
|
97
|
+
const targetRect = target.getBoundingClientRect()
|
|
98
|
+
setRect({
|
|
99
|
+
left: targetRect.left - parentRect.left + parent.scrollLeft,
|
|
100
|
+
top: targetRect.top - parentRect.top + parent.scrollTop,
|
|
101
|
+
width: targetRect.width,
|
|
102
|
+
height: targetRect.height,
|
|
103
|
+
})
|
|
104
|
+
setHasInitialized(true)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
measure()
|
|
108
|
+
|
|
109
|
+
// Resolve the correct window from the target's own document — required for
|
|
110
|
+
// cross-window safety (preview iframes, Radix portals). The bare `window`
|
|
111
|
+
// global is the wrong reference inside an iframe (component-build-spec §2).
|
|
112
|
+
const win =
|
|
113
|
+
(target as HTMLElement).ownerDocument?.defaultView ?? window
|
|
114
|
+
|
|
115
|
+
const ro = new win.ResizeObserver(measure)
|
|
116
|
+
ro.observe(parent)
|
|
117
|
+
ro.observe(target)
|
|
118
|
+
|
|
119
|
+
return () => ro.disconnect()
|
|
120
|
+
}, [target, parent])
|
|
121
|
+
|
|
122
|
+
const isVisible = !!rect
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
aria-hidden="true"
|
|
127
|
+
data-slot="floating-indicator"
|
|
128
|
+
className={cn(
|
|
129
|
+
"pointer-events-none absolute rounded-md bg-background shadow-sm",
|
|
130
|
+
// Explicit property list — never transition-all (animates focus-ring
|
|
131
|
+
// box-shadow, layout props, and every other property, including ones
|
|
132
|
+
// that should be instant). See CLAUDE.md § microanimation rule.
|
|
133
|
+
"transition-[left,top,width,height]",
|
|
134
|
+
!isVisible && "opacity-0",
|
|
135
|
+
className
|
|
136
|
+
)}
|
|
137
|
+
style={{
|
|
138
|
+
left: rect?.left ?? 0,
|
|
139
|
+
top: rect?.top ?? 0,
|
|
140
|
+
width: rect?.width ?? 0,
|
|
141
|
+
height: rect?.height ?? 0,
|
|
142
|
+
// Token-driven duration — var() resolves at runtime from styles.css.
|
|
143
|
+
// Using "var(--duration-base)" not a literal "200ms" so token changes
|
|
144
|
+
// in tokens.json → pnpm build:tokens → propagate here automatically.
|
|
145
|
+
transitionDuration: hasInitialized ? transitionDuration : "0ms",
|
|
146
|
+
transitionTimingFunction: "var(--ease-out)",
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ─── Hook ─────────────────────────────────────────────────────────────────────
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Convenience hook that manages the target element state for a `FloatingIndicator`.
|
|
156
|
+
*
|
|
157
|
+
* Returns two complementary setters:
|
|
158
|
+
* - `setTarget` — call imperatively on item click / keyboard navigation
|
|
159
|
+
* - `targetRef` — a React callback ref; conditionally pass to the active item's `ref`
|
|
160
|
+
* so the indicator auto-positions when the active item mounts
|
|
161
|
+
*
|
|
162
|
+
* The `target` state value is ready to pass directly to `<FloatingIndicator target={...} />`.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* const containerRef = useRef<HTMLDivElement>(null)
|
|
167
|
+
* const [activeIndex, setActiveIndex] = useState(0)
|
|
168
|
+
* const { setTarget, targetRef, target } = useFloatingIndicator(containerRef)
|
|
169
|
+
*
|
|
170
|
+
* <div ref={containerRef} className="relative inline-flex bg-muted p-1 rounded-lg">
|
|
171
|
+
* <FloatingIndicator target={target} parent={containerRef.current} />
|
|
172
|
+
* {items.map((item, i) => (
|
|
173
|
+
* <button
|
|
174
|
+
* key={item.value}
|
|
175
|
+
* ref={activeIndex === i ? targetRef : null}
|
|
176
|
+
* onClick={() => { setActiveIndex(i); setTarget(buttonEl) }}
|
|
177
|
+
* >
|
|
178
|
+
* {item.label}
|
|
179
|
+
* </button>
|
|
180
|
+
* ))}
|
|
181
|
+
* </div>
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
function useFloatingIndicator(
|
|
185
|
+
containerRef: React.RefObject<HTMLElement | null>
|
|
186
|
+
) {
|
|
187
|
+
const [target, setTargetState] = React.useState<HTMLElement | null>(null)
|
|
188
|
+
|
|
189
|
+
/** Imperatively set the active target element. Call on click or keyboard navigation. */
|
|
190
|
+
const setTarget = React.useCallback((el: HTMLElement | null) => {
|
|
191
|
+
setTargetState(el)
|
|
192
|
+
}, [])
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Callback ref — pass as `ref` to the currently active item.
|
|
196
|
+
* When the active item mounts (or the ref is conditionally applied to a
|
|
197
|
+
* different item), the indicator auto-snaps to that element.
|
|
198
|
+
* Fires on mount only — for active-index changes on stable DOM, use `setTarget`.
|
|
199
|
+
*/
|
|
200
|
+
const targetRef = React.useCallback((el: HTMLElement | null) => {
|
|
201
|
+
if (el !== null) setTargetState(el)
|
|
202
|
+
}, [])
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
/** The current target element — pass to `<FloatingIndicator target={...} />` */
|
|
206
|
+
target,
|
|
207
|
+
/** Imperative setter — call on click/keyboard */
|
|
208
|
+
setTarget,
|
|
209
|
+
/** Callback ref — conditionally pass to the active item's `ref` prop */
|
|
210
|
+
targetRef,
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ─── Exports ──────────────────────────────────────────────────────────────────
|
|
215
|
+
|
|
216
|
+
export { FloatingIndicator, useFloatingIndicator }
|
|
217
|
+
export type { FloatingIndicatorProps }
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Explicit default locale. FormatByte never reads the runtime locale
|
|
7
|
+
* (navigator.language): an implicit locale formats differently on the
|
|
8
|
+
* server and the client, which is the classic hydration-mismatch bug.
|
|
9
|
+
* Consumers localizing for real pass `locale` from their own i18n layer.
|
|
10
|
+
* Same contract as FormatNumber.
|
|
11
|
+
*/
|
|
12
|
+
const FORMAT_BYTE_DEFAULT_LOCALE = "en-US"
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* SI (base-1000) byte scale, matching Mantine's `formatBytes` and Chakra's
|
|
16
|
+
* byte format utilities — and what OS file managers (Finder, Nautilus)
|
|
17
|
+
* report. NOT the IEC base-1024 scale (KiB/MiB): a 1,048,576-byte file
|
|
18
|
+
* reads "1.0 MB" here, not "1.0 MiB".
|
|
19
|
+
*/
|
|
20
|
+
const BYTE_SCALE = [
|
|
21
|
+
{ threshold: 1_000_000_000_000, suffix: "TB" },
|
|
22
|
+
{ threshold: 1_000_000_000, suffix: "GB" },
|
|
23
|
+
{ threshold: 1_000_000, suffix: "MB" },
|
|
24
|
+
{ threshold: 1_000, suffix: "KB" },
|
|
25
|
+
] as const
|
|
26
|
+
|
|
27
|
+
export interface FormatByteProps
|
|
28
|
+
extends Omit<React.ComponentProps<"span">, "children"> {
|
|
29
|
+
/** The byte count to format (integer or float; negatives allowed). */
|
|
30
|
+
value: number
|
|
31
|
+
/**
|
|
32
|
+
* Decimal places on scaled values (KB and up). Defaults to `1`
|
|
33
|
+
* ("1.5 MB"). Byte-scale values (< 1000) always render as integers
|
|
34
|
+
* ("500 B") — fractional bytes aren't a thing users read.
|
|
35
|
+
*/
|
|
36
|
+
precision?: number
|
|
37
|
+
/**
|
|
38
|
+
* BCP 47 locale tag for the numeric part. Defaults to "en-US"
|
|
39
|
+
* (explicit, SSR-safe) — pass your i18n layer's locale to localize.
|
|
40
|
+
*/
|
|
41
|
+
locale?: string
|
|
42
|
+
/**
|
|
43
|
+
* `font-variant-numeric: tabular-nums` so digits occupy equal widths.
|
|
44
|
+
* Defaults to `true`, same as FormatNumber: file sizes overwhelmingly
|
|
45
|
+
* land in table columns and meta rows where alignment matters, and
|
|
46
|
+
* tabular figures sidestep the Hyperlegible Sans proportional-figure
|
|
47
|
+
* kerning collision. Pass `tabular={false}` for proportional figures.
|
|
48
|
+
*/
|
|
49
|
+
tabular?: boolean
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Locale-aware byte-value display primitive. Converts a raw byte count to
|
|
54
|
+
* the appropriate SI scale (B / KB / MB / GB / TB) and formats the number
|
|
55
|
+
* via `Intl.NumberFormat`. Display-only: for editable file-size inputs use
|
|
56
|
+
* NumberInput.
|
|
57
|
+
*
|
|
58
|
+
* Distinct from FormatNumber, which passes `Intl.NumberFormatOptions`
|
|
59
|
+
* straight through — `style="unit" unit="byte"` formats the raw numeric
|
|
60
|
+
* ("1,536,000 byte") and never picks the KB/MB/GB scale. FormatByte owns
|
|
61
|
+
* that scale conversion.
|
|
62
|
+
*
|
|
63
|
+
* Scaled output rounds, so the exact byte count rides the native `title`
|
|
64
|
+
* attribute ("1,536,000 bytes") for hover/long-press recovery — the same
|
|
65
|
+
* recoverability pattern FormatNumber uses for compact notation. A
|
|
66
|
+
* consumer-supplied `title` wins. Hook-free (no "use client"), so it works
|
|
67
|
+
* as a Server Component and formats identically on both sides.
|
|
68
|
+
*/
|
|
69
|
+
function FormatByte({
|
|
70
|
+
value,
|
|
71
|
+
precision = 1,
|
|
72
|
+
locale = FORMAT_BYTE_DEFAULT_LOCALE,
|
|
73
|
+
tabular = true,
|
|
74
|
+
className,
|
|
75
|
+
title,
|
|
76
|
+
...props
|
|
77
|
+
}: FormatByteProps) {
|
|
78
|
+
const abs = Math.abs(value)
|
|
79
|
+
const scale = BYTE_SCALE.find((s) => abs >= s.threshold)
|
|
80
|
+
|
|
81
|
+
let formatted: string
|
|
82
|
+
let fullValue: string | undefined
|
|
83
|
+
|
|
84
|
+
if (scale) {
|
|
85
|
+
const number = new Intl.NumberFormat(locale, {
|
|
86
|
+
minimumFractionDigits: precision,
|
|
87
|
+
maximumFractionDigits: precision,
|
|
88
|
+
}).format(value / scale.threshold)
|
|
89
|
+
formatted = `${number} ${scale.suffix}`
|
|
90
|
+
// Scaled output rounds — keep the exact count recoverable on title.
|
|
91
|
+
fullValue = `${new Intl.NumberFormat(locale, {
|
|
92
|
+
maximumFractionDigits: 0,
|
|
93
|
+
}).format(value)} bytes`
|
|
94
|
+
} else {
|
|
95
|
+
const number = new Intl.NumberFormat(locale, {
|
|
96
|
+
maximumFractionDigits: 0,
|
|
97
|
+
}).format(value)
|
|
98
|
+
formatted = `${number} B`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<span
|
|
103
|
+
data-slot="format-byte"
|
|
104
|
+
className={cn(tabular && "tabular-nums", className)}
|
|
105
|
+
title={title ?? fullValue}
|
|
106
|
+
{...props}
|
|
107
|
+
>
|
|
108
|
+
{formatted}
|
|
109
|
+
</span>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export { FormatByte, FORMAT_BYTE_DEFAULT_LOCALE }
|
|
@@ -32,9 +32,11 @@ export * from "./hover-card";
|
|
|
32
32
|
export * from "./input";
|
|
33
33
|
export * from "./input-group";
|
|
34
34
|
export * from "./kbd";
|
|
35
|
+
export * from "./keyboard-shortcut";
|
|
35
36
|
export * from "./label";
|
|
36
37
|
export * from "./link";
|
|
37
38
|
export * from "./menubar";
|
|
39
|
+
export * from "./month-picker";
|
|
38
40
|
export * from "./motion-toggle";
|
|
39
41
|
export * from "./navigation-menu";
|
|
40
42
|
export * from "./notification";
|
|
@@ -71,6 +73,7 @@ export * from "./toggle-group";
|
|
|
71
73
|
export * from "./toolbar";
|
|
72
74
|
export * from "./tooltip";
|
|
73
75
|
export * from "./tree-view";
|
|
76
|
+
export * from "./tree-select";
|
|
74
77
|
export * from "./editable";
|
|
75
78
|
export * from "./qr-code";
|
|
76
79
|
export * from "./highlight";
|
|
@@ -100,6 +103,7 @@ export * from "./burger";
|
|
|
100
103
|
export * from "./action-bar";
|
|
101
104
|
export * from "./checkbox-card";
|
|
102
105
|
export * from "./watermark";
|
|
106
|
+
export * from "./loading-dots";
|
|
103
107
|
export * from "./loading-overlay";
|
|
104
108
|
export * from "./float-label";
|
|
105
109
|
export * from "./tour";
|
|
@@ -117,8 +121,25 @@ export * from "./signature-pad";
|
|
|
117
121
|
export * from "./floating-action-button";
|
|
118
122
|
export * from "./clipboard";
|
|
119
123
|
export * from "./chat-bubble";
|
|
124
|
+
export * from "./chat-marker";
|
|
120
125
|
export * from "./data-table";
|
|
121
126
|
export * from "./focus-trap";
|
|
122
127
|
export * from "./mark";
|
|
123
128
|
export * from "./rolling-number";
|
|
124
129
|
export * from "./ai-badge";
|
|
130
|
+
export * from "./prose";
|
|
131
|
+
export * from "./result";
|
|
132
|
+
export * from "./navigation-rail";
|
|
133
|
+
export * from "./squircle";
|
|
134
|
+
export * from "./drawer";
|
|
135
|
+
export * from "./floating-indicator";
|
|
136
|
+
export * from "./nav-link";
|
|
137
|
+
export * from "./year-picker";
|
|
138
|
+
export * from "./format-byte";
|
|
139
|
+
export * from "./file-button";
|
|
140
|
+
export * from "./theme-icon";
|
|
141
|
+
export * from "./date-field";
|
|
142
|
+
export * from "./stack";
|
|
143
|
+
export * from "./container";
|
|
144
|
+
export * from "./simple-grid";
|
|
145
|
+
export * from "./close-button";
|
|
@@ -27,6 +27,13 @@ type InputProps = Omit<React.ComponentProps<"input">, "size"> &
|
|
|
27
27
|
/** When true, shows a dismiss (×) button on the right when the input has a value.
|
|
28
28
|
* Calls onChange with an empty string on click. Only meaningful for controlled inputs. */
|
|
29
29
|
clearable?: boolean
|
|
30
|
+
/** Content rendered inside the field boundary, left of the text caret (icon, "$", …).
|
|
31
|
+
* Pointer-events are disabled on the slot; add `pointer-events-auto` to interactive
|
|
32
|
+
* children. Purely decorative content should carry `aria-hidden="true"`. */
|
|
33
|
+
leftSection?: React.ReactNode
|
|
34
|
+
/** Content rendered inside the field boundary, right of the text caret (icon, unit, …).
|
|
35
|
+
* Same pointer-events / aria-hidden guidance as `leftSection`. */
|
|
36
|
+
rightSection?: React.ReactNode
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
function Input({
|
|
@@ -34,19 +41,28 @@ function Input({
|
|
|
34
41
|
type,
|
|
35
42
|
size,
|
|
36
43
|
clearable,
|
|
44
|
+
leftSection,
|
|
45
|
+
rightSection,
|
|
37
46
|
value,
|
|
38
47
|
onChange,
|
|
39
48
|
disabled,
|
|
40
49
|
...props
|
|
41
50
|
}: InputProps) {
|
|
42
51
|
const showClear = clearable && !disabled && value !== undefined && value !== ""
|
|
52
|
+
const hasWrapper = Boolean(clearable || leftSection || rightSection)
|
|
43
53
|
|
|
44
54
|
const inputEl = (
|
|
45
55
|
<input
|
|
46
56
|
type={type}
|
|
47
57
|
data-slot="input"
|
|
48
58
|
data-size={size ?? "default"}
|
|
49
|
-
className={cn(
|
|
59
|
+
className={cn(
|
|
60
|
+
inputVariants({ size, className }),
|
|
61
|
+
clearable && "pr-8",
|
|
62
|
+
leftSection && "pl-9",
|
|
63
|
+
rightSection && "pr-9",
|
|
64
|
+
clearable && rightSection && "pr-14"
|
|
65
|
+
)}
|
|
50
66
|
value={value}
|
|
51
67
|
onChange={onChange}
|
|
52
68
|
disabled={disabled}
|
|
@@ -54,18 +70,37 @@ function Input({
|
|
|
54
70
|
/>
|
|
55
71
|
)
|
|
56
72
|
|
|
57
|
-
if (!
|
|
73
|
+
if (!hasWrapper) {
|
|
58
74
|
return inputEl
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
return (
|
|
62
78
|
<div className="relative">
|
|
79
|
+
{leftSection && (
|
|
80
|
+
<div
|
|
81
|
+
data-slot="input-left-section"
|
|
82
|
+
className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 text-muted-foreground"
|
|
83
|
+
>
|
|
84
|
+
{leftSection}
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
63
87
|
{inputEl}
|
|
88
|
+
{rightSection && (
|
|
89
|
+
<div
|
|
90
|
+
data-slot="input-right-section"
|
|
91
|
+
className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3 text-muted-foreground"
|
|
92
|
+
>
|
|
93
|
+
{rightSection}
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
64
96
|
{showClear && (
|
|
65
97
|
<button
|
|
66
98
|
type="button"
|
|
67
99
|
aria-label="Clear input"
|
|
68
|
-
className=
|
|
100
|
+
className={cn(
|
|
101
|
+
"absolute top-1/2 -translate-y-1/2 inline-flex items-center justify-center size-6 rounded text-muted-foreground hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
|
|
102
|
+
rightSection ? "right-8" : "right-1.5"
|
|
103
|
+
)}
|
|
69
104
|
style={{
|
|
70
105
|
transitionDuration: "var(--duration-fast)",
|
|
71
106
|
transitionTimingFunction: "var(--ease-out)",
|