@vvedantb/ui 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ import { InputArea, InputBanners, buildComposerSlashItems } from "@vvedantb/ui";
|
|
|
69
69
|
|
|
70
70
|
| Prop | Default | Notes |
|
|
71
71
|
| --- | --- | --- |
|
|
72
|
-
| `value`, `onChange`, `defaultValue` | uncontrolled, `""` | `onSubmit` clears the draft through `onChange("")` first. Restore it yourself if sending fails. |
|
|
72
|
+
| `value`, `onChange`, `defaultValue` | uncontrolled, `""` | `onSubmit` clears the draft through `onChange("")` first. Restore it yourself if sending fails. A value of `"\n"` shows as an empty editor with the placeholder, and the editor never reports a trailing line holder newline (0.5.4). |
|
|
73
73
|
| `onSubmit(text)` | none | Trimmed text. Not called while `isSending`, or when send is disabled. |
|
|
74
74
|
| `onStop`, `isStreaming`, `isSending`, `isUploading` | off | While streaming, stop shows next to send, and send queues. Sending or uploading shows a spinner and disables send. |
|
|
75
75
|
| `canSubmit` | text, or `fileCount` or `chipCount` above 0 | Overrides when send is enabled. |
|
|
@@ -250,7 +250,7 @@ import {
|
|
|
250
250
|
- `SelectField`: a labelled single select built from `Select`. Children are `SelectItem`s. An empty `value` shows the placeholder. `id` goes to the trigger and the label points at it. `className` merges onto the trigger.
|
|
251
251
|
- Motion: `springTransition`, `springFastTransition` and `fadeUpSpring` presets. `FadePresence` takes optional `variants` (`hidden`, `show`, `exit`); omitted, it keeps its opacity fade. `PanelTransition` wraps children in React `ViewTransition` with `default="none"` and `enter`/`exit` classes (`vt-panel-in`, `vt-panel-out` by default). It needs a React build that exports `ViewTransition`, and the app supplies the `::view-transition-*` CSS.
|
|
252
252
|
|
|
253
|
-
## App shell (0.5.0 to 0.5.
|
|
253
|
+
## App shell (0.5.0 to 0.5.4)
|
|
254
254
|
|
|
255
255
|
A sidebar and main page layout, extracted from existing app markup. It is router-free: pass your own links (with `asChild`), state and media query result. Tooltips need a `TooltipProvider` above the shell.
|
|
256
256
|
|
|
@@ -291,9 +291,9 @@ import {
|
|
|
291
291
|
|
|
292
292
|
- Widths: `AppShell` sets `--app-shell-rail-width` (default `4rem`), `--app-shell-sidebar-width` (rail plus panel, default `20rem`) and `--app-shell-mobile-header-height` (default `calc(3.5rem + env(safe-area-inset-top, 0px))`) as inline style. Change them with `railWidth`, `sidebarWidth` and `mobileHeaderHeight`. The other pieces read these variables. Outside `AppShell`, set the variables yourself or pass a width class with `className`.
|
|
293
293
|
- `AppShell`: `sidebar`, `children`, `panelHidden` (main offsets by the rail width instead of the sidebar width), `skipLinkLabel` (`"Skip to main content"`), `mainId` (`"main-content"`), `className`, `mainClassName`, `contentClassName`.
|
|
294
|
-
- `AppSidebar`: `rail`, `panel` (not rendered while `panelHidden`), `collapsed`, `panelHidden`, `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `id` (default from `useId`), `asideProps` (`data-*` attributes for the `<aside>`), `className`, `mobileTitle`, `mobileHeaderActions` (0.5.2; trailing actions such as icon buttons, in place of the end spacer), `mobileMenuIcon` (`(open) => node`, default a menu icon), `mobileMenuLabel` (`"Open navigation menu"`), `closeLabel` (`"Close navigation"`). Swipe left or Escape closes the drawer. The drawer is `inert` while closed on mobile, and closes when `isDesktop` becomes `true`. Close it on route change in the app.
|
|
294
|
+
- `AppSidebar`: `rail`, `panel` (not rendered while `panelHidden`), `collapsed`, `panelHidden`, `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `id` (default from `useId`), `asideProps` (`data-*` attributes for the `<aside>`), `className`, `mobileTitle`, `mobileHeaderActions` (0.5.2; trailing actions such as icon buttons, in place of the end spacer), `mobileMenuIcon` (`(open) => node`, default a menu icon), `mobileMenuLabel` (`"Open navigation menu"`), `closeLabel` (`"Close navigation"`). Swipe left or Escape closes the drawer. The drawer is `inert` while closed on mobile, and closes when `isDesktop` becomes `true`. Close it on route change in the app. The mobile header is a three-column grid, so the title and trailing actions stay on one row and a long title truncates (0.5.4).
|
|
295
295
|
- `SidebarRail`: `top`, `children` (scroll body), `footer`, `showDivider`, `bodyAsChild` (the single child, for example a tabs list, becomes the body), `className`, `topClassName`, `bodyClassName`, `footerClassName`. Other HTML attributes (`id`, `data-*`, `aria-*`) go to the root `<div>`. The top and footer wrappers render only when their slot is set.
|
|
296
|
-
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `className`. Without `asChild` it is a
|
|
296
|
+
- `RailTile`: `label` (`aria-label` and tooltip), `active`, `tooltip`, `showTooltip` (default `true`), `badge` (inside the tile, after the children; style it with `railBadgeClass`), `asChild`, `className`. Without `asChild` it is a native `<button type="button">` (0.5.3), so icons keep their authored size; other props go to it. With `asChild` the child (for example a router link) gets the tile classes and `aria-current="page"` when active.
|
|
297
297
|
- `RailDivider`, `SidebarIconTooltip` (`label`, `enabled`, `side` `"right"`, `sideOffset` 8).
|
|
298
298
|
- `SidebarPanel`: `title`, `headerTrailing`, `onClose` (adds the close button; pass it on the mobile drawer only), `closeLabel`, `closeButtonClassName`, `collapsed` (`md:hidden`), `className`, `children`.
|
|
299
299
|
- `SidebarAccountMenu`: `name`, `email` (two-line label when set), `stackedLabel` (two-line layout even without `email`, default `false`), `imageUrl` (initials without it), `align` (`"center"`), `side` (`"right"`), `sideOffset` (8), `collisionPadding`, `contentClassName`, `children` (menu items). 0.5.2 adds `badge` (unread dot beside the trigger, in a `relative` wrapper around the menu, so the trigger's dimming and press scale skip it: `true` shows it, `false` fades it out, omitted renders no wrapper and no dot), `triggerProps` (spread onto the trigger `Button` after the defaults; `className` merges last) and `contentProps` (spread onto `DropdownMenuContent`, for example `fitViewport` or `aria-label`; no `className`, use `contentClassName`). `SidebarAccountMenuPlaceholder` is the tile-sized loading box.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one JavaScript entry (primitives, shell pieces, app helpers, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
|
|
6
6
|
"type": "module",
|
package/shell/src/AppSidebar.tsx
CHANGED
|
@@ -96,9 +96,10 @@ export function AppSidebar({
|
|
|
96
96
|
|
|
97
97
|
return (
|
|
98
98
|
<>
|
|
99
|
+
{/* Three columns keep the title centred and stop it overlapping the actions: it truncates instead. */}
|
|
99
100
|
<header
|
|
100
101
|
onKeyDown={closeOnEscape}
|
|
101
|
-
className="fixed inset-x-0 top-0 z-30
|
|
102
|
+
className="fixed inset-x-0 top-0 z-30 grid h-[var(--app-shell-mobile-header-height)] grid-cols-[minmax(max-content,1fr)_minmax(0,auto)_minmax(max-content,1fr)] items-center gap-2 bg-surface px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden"
|
|
102
103
|
>
|
|
103
104
|
<Button
|
|
104
105
|
type="button"
|
|
@@ -108,21 +109,26 @@ export function AppSidebar({
|
|
|
108
109
|
aria-label={mobileMenuLabel}
|
|
109
110
|
aria-expanded={mobileOpen}
|
|
110
111
|
aria-controls={drawerId}
|
|
111
|
-
className={mobileMenuButtonClass}
|
|
112
|
+
className={cn(mobileMenuButtonClass, "justify-self-start")}
|
|
112
113
|
>
|
|
113
114
|
{mobileMenuIcon(mobileOpen)}
|
|
114
115
|
</Button>
|
|
115
116
|
{mobileTitle ? (
|
|
116
|
-
<h1 className="pointer-events-none
|
|
117
|
+
<h1 className="pointer-events-none min-w-0 truncate text-center text-base font-semibold leading-tight tracking-tight text-foreground">
|
|
117
118
|
{mobileTitle}
|
|
118
119
|
</h1>
|
|
119
|
-
) :
|
|
120
|
+
) : (
|
|
121
|
+
<span aria-hidden="true" />
|
|
122
|
+
)}
|
|
120
123
|
{mobileHeaderActions ? (
|
|
121
|
-
<div
|
|
124
|
+
<div
|
|
125
|
+
data-app-sidebar-mobile-actions=""
|
|
126
|
+
className="flex shrink-0 items-center justify-self-end gap-2"
|
|
127
|
+
>
|
|
122
128
|
{mobileHeaderActions}
|
|
123
129
|
</div>
|
|
124
130
|
) : (
|
|
125
|
-
<div className="
|
|
131
|
+
<div className="h-11 w-11 shrink-0 justify-self-end" aria-hidden="true" />
|
|
126
132
|
)}
|
|
127
133
|
</header>
|
|
128
134
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
2
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
|
-
import { Button } from "../../src/ui/button";
|
|
5
4
|
import { cn } from "../../src/utils/cn";
|
|
6
5
|
import { railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
7
6
|
import { SidebarIconTooltip } from "./SidebarIconTooltip";
|
|
@@ -99,7 +98,7 @@ export type RailTileProps = Omit<ComponentPropsWithoutRef<"button">, "children">
|
|
|
99
98
|
children: ReactNode;
|
|
100
99
|
};
|
|
101
100
|
|
|
102
|
-
/** Rail tile with a right-side tooltip. Renders a
|
|
101
|
+
/** Rail tile with a right-side tooltip. Renders a native `<button>`, its child with `asChild`, or a tabs trigger with `tabValue`. */
|
|
103
102
|
export function RailTile({
|
|
104
103
|
label,
|
|
105
104
|
active = false,
|
|
@@ -135,16 +134,15 @@ export function RailTile({
|
|
|
135
134
|
{badge}
|
|
136
135
|
</Slot>
|
|
137
136
|
) : (
|
|
138
|
-
<
|
|
137
|
+
<button
|
|
139
138
|
type="button"
|
|
140
|
-
variant="ghost"
|
|
141
139
|
{...props}
|
|
142
140
|
aria-label={label}
|
|
143
|
-
className={cn(railTileClass, "group
|
|
141
|
+
className={cn(railTileClass, "group", railTileStateClass(active), className)}
|
|
144
142
|
>
|
|
145
143
|
{children}
|
|
146
144
|
{badge}
|
|
147
|
-
</
|
|
145
|
+
</button>
|
|
148
146
|
)}
|
|
149
147
|
</SidebarIconTooltip>
|
|
150
148
|
);
|
|
@@ -30,16 +30,33 @@ const CHIPS_HOST_CLASS = "contents empty:hidden [&>*]:mr-1.5";
|
|
|
30
30
|
|
|
31
31
|
const ZERO_WIDTH_SPACE = "\u200b";
|
|
32
32
|
|
|
33
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* A value of "\n" is an empty draft: Shift+Enter on an empty editor, or a
|
|
35
|
+
* stray line holder that apps stored before 0.5.4. Mirrors `isComposerCompact`.
|
|
36
|
+
*/
|
|
37
|
+
function isEmptyDraft(value: string): boolean {
|
|
38
|
+
return value === "" || value === "\n";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Reads the plain text of the editor. Skips the chips host. Under `pre-wrap` a
|
|
43
|
+
* single trailing "\n" renders no line, so Chromium ends the text with an extra
|
|
44
|
+
* "\n" that only holds the last line open. That holder, or a trailing `<br>`,
|
|
45
|
+
* is dropped once.
|
|
46
|
+
*/
|
|
34
47
|
export function extractEditorText(root: HTMLElement): string {
|
|
35
48
|
let out = "";
|
|
49
|
+
let heldByBr = false;
|
|
36
50
|
const walk = (node: Node, isRoot: boolean) => {
|
|
37
51
|
node.childNodes.forEach((child, index) => {
|
|
38
52
|
if (child instanceof HTMLElement) {
|
|
39
53
|
if (child.hasAttribute(CHIPS_HOST_ATTR)) return;
|
|
40
54
|
if (child.tagName === "BR") {
|
|
41
55
|
// A trailing <br> only holds the line open.
|
|
42
|
-
if (isRoot && index === node.childNodes.length - 1)
|
|
56
|
+
if (isRoot && index === node.childNodes.length - 1) {
|
|
57
|
+
heldByBr = true;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
43
60
|
out += "\n";
|
|
44
61
|
return;
|
|
45
62
|
}
|
|
@@ -57,7 +74,29 @@ export function extractEditorText(root: HTMLElement): string {
|
|
|
57
74
|
});
|
|
58
75
|
};
|
|
59
76
|
walk(root, true);
|
|
60
|
-
return out;
|
|
77
|
+
return !heldByBr && out.endsWith("\n") ? out.slice(0, -1) : out;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The DOM text for a value: a trailing "\n" gets its line holder. */
|
|
81
|
+
function editorTextFor(value: string): string {
|
|
82
|
+
return value.endsWith("\n") ? `${value}\n` : value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Every editor node except the chips host: the anchor, text and line breaks. */
|
|
86
|
+
function textNodes(root: HTMLElement): ChildNode[] {
|
|
87
|
+
return Array.from(root.childNodes).filter(
|
|
88
|
+
(child) => !(child instanceof HTMLElement && child.hasAttribute(CHIPS_HOST_ATTR)),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* True when the DOM shows `shown`. An empty draft must be the bare U+200B
|
|
94
|
+
* anchor: a stray "\n" or `<br>` reads as "" but pushes the placeholder down.
|
|
95
|
+
*/
|
|
96
|
+
function editorShows(root: HTMLElement, shown: string): boolean {
|
|
97
|
+
if (shown !== "") return extractEditorText(root) === shown;
|
|
98
|
+
const [only, ...rest] = textNodes(root);
|
|
99
|
+
return rest.length === 0 && only instanceof Text && only.data === ZERO_WIDTH_SPACE;
|
|
61
100
|
}
|
|
62
101
|
|
|
63
102
|
function chipsHost(root: HTMLElement): HTMLElement | null {
|
|
@@ -96,11 +135,14 @@ function setSelection(
|
|
|
96
135
|
window.getSelection()?.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
97
136
|
}
|
|
98
137
|
|
|
99
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* End of the text: the last text node before its trailing line holder, or the
|
|
140
|
+
* end of the editor after a line break.
|
|
141
|
+
*/
|
|
100
142
|
function textEnd(root: HTMLElement): [Node, number] {
|
|
101
143
|
ensureCaretAnchor(root);
|
|
102
144
|
const last = root.lastChild;
|
|
103
|
-
if (last instanceof Text) return [last, last.length];
|
|
145
|
+
if (last instanceof Text) return [last, last.data.endsWith("\n") ? last.length - 1 : last.length];
|
|
104
146
|
return [root, root.childNodes.length];
|
|
105
147
|
}
|
|
106
148
|
|
|
@@ -276,13 +318,10 @@ export function InputAreaEditor({
|
|
|
276
318
|
useLayoutEffect(() => {
|
|
277
319
|
const root = rootRef.current;
|
|
278
320
|
if (!root || composingRef.current) return;
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
root.appendChild(document.createTextNode(ZERO_WIDTH_SPACE + value));
|
|
321
|
+
const shown = isEmptyDraft(value) ? "" : value;
|
|
322
|
+
if (!editorShows(root, shown)) {
|
|
323
|
+
textNodes(root).forEach((child) => root.removeChild(child));
|
|
324
|
+
root.appendChild(document.createTextNode(ZERO_WIDTH_SPACE + editorTextFor(shown)));
|
|
286
325
|
if (document.activeElement === root) placeCaretAtEnd(root);
|
|
287
326
|
}
|
|
288
327
|
ensureCaretAnchor(root);
|
|
@@ -361,7 +400,7 @@ export function InputAreaEditor({
|
|
|
361
400
|
aria-multiline
|
|
362
401
|
{...ariaProps}
|
|
363
402
|
role="combobox"
|
|
364
|
-
data-empty={value
|
|
403
|
+
data-empty={isEmptyDraft(value) ? "" : undefined}
|
|
365
404
|
data-placeholder={placeholder}
|
|
366
405
|
data-suggestion={suggestion || undefined}
|
|
367
406
|
className={cn(INLINE_EDITOR_CLASS, className)}
|