devnonla-ui 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -115,7 +115,31 @@ import { DesktopStage, DesktopHeader, MeadowDesktop, DesktopWindow, MeadowShell,
115
115
  </DesktopStage>
116
116
  ```
117
117
 
118
- `MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
118
+ `MeadowShell` is the login/setup backdrop. `DesktopWindow` chrome is inline: traffic lights, `left`, a flex middle (title — double-click to expand), then `right`. A child can fill the same slots with `WindowHeader`. Last collapsed position and size are restored on reopen (`persistKey`, or `false` to disable). Resize handles stay when expanded; dragging an edge leaves expand and keeps the new size. `Menu` is the glass picker (trigger + items + hover action) used by AgentsMenu. Wallpaper defaults to the bundled meadow; pass `src` on `MeadowWallpaper` to swap.
119
+
120
+ # Sidebar
121
+
122
+ Grouped side nav. Pass JSON groups + items; the app owns routing.
123
+
124
+ ```tsx
125
+ import { Sidebar, type SidebarItemType } from "devnonla-ui";
126
+
127
+ const items: SidebarItemType[] = [
128
+ {
129
+ type: "group",
130
+ key: "chat",
131
+ label: "Chat",
132
+ children: [
133
+ { key: "inbox", label: "Inbox", icon: "chat-24" },
134
+ { key: "archive", label: "Archive", icon: "library-24" },
135
+ ],
136
+ },
137
+ ];
138
+
139
+ <Sidebar items={items} selectedKey={active} searchable onSelect={({ key }) => setActive(key)} />
140
+ ```
141
+
142
+ `icon` may be a Fluent name string (JSON-friendly) or a node. Set `href` to render `<a>`; left-click still goes through `onSelect` so a SPA can `navigate`. Cmd/Ctrl-click keeps the native new-tab. Parent sets width; `Sidebar` fills height.
119
143
 
120
144
  # Chat
121
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -88,7 +88,7 @@ function tokenAppearance(color: "default" | "primary" | "danger" | "link", varia
88
88
  }
89
89
  if (color === "link" || variant === "link") return "text-link border-transparent hover:text-link/80";
90
90
  if (variant === "filled") return "bg-muted text-foreground border-transparent hover:bg-muted/80";
91
- if (variant === "text") return "bg-transparent text-foreground border-transparent hover:bg-foreground/6 hover:text-foreground";
91
+ if (variant === "text") return "bg-transparent text-foreground border-transparent hover:bg-ink-hover hover:text-foreground";
92
92
  if (variant === "dashed") return "bg-transparent text-foreground border-dashed border-glass-border hover:bg-glass-bar backdrop-blur-xl";
93
93
  return "nonla-btn-glass text-foreground";
94
94
  }
@@ -90,7 +90,7 @@ export function AgentChatbox({
90
90
  return (
91
91
  <div className={cn("nonla-agent-chatbox relative flex h-full min-h-0 flex-col overflow-hidden bg-chat", className)}>
92
92
  <OverlayScroll visibility={scrollbar} scrollRef={scrollRef} onScroll={onScroll} className="flex-1 min-h-0 min-w-0" innerClassName={messages.length === 0 ? "flex flex-col" : undefined}>
93
- <div data-chat-scroll-content className={`max-w-190 mx-auto min-w-0 w-full ${messages.length === 0 ? "flex flex-1 flex-col pb-24" : "pt-4 pb-28"}`}>
93
+ <div data-chat-scroll-content className={`max-w-200 mx-auto min-w-0 w-full ${messages.length === 0 ? "flex flex-1 flex-col pb-16" : "pt-4 pb-20"}`}>
94
94
  {messages.length === 0 ? (
95
95
  (emptyState ?? (
96
96
  <ChatWelcome name={welcomeName} description={description} avatar={avatar} starters={starters} onStarter={sendMessage} disabled={generating} />
@@ -103,7 +103,7 @@ export function AgentChatbox({
103
103
 
104
104
  <div className="relative shrink-0">
105
105
  {accessory}
106
- <div className="mx-auto w-full max-w-190">
106
+ <div className="mx-auto w-full max-w-200">
107
107
  <ChatInput generating={generating} placeholder={placeholder} onSend={sendMessage} onCancel={cancel} toolbar={toolbar} enableTypeToFocus />
108
108
  </div>
109
109
  </div>
@@ -97,7 +97,7 @@ export function AgentPanel({
97
97
  return (
98
98
  <div className={cn("nonla-agent-panel relative flex h-full min-h-0 flex-col overflow-hidden bg-chat", className)}>
99
99
  <OverlayScroll visibility={scrollbar} scrollRef={scrollRef} onScroll={onScroll} className="flex-1 min-h-0 min-w-0" innerClassName={messages.length === 0 ? "flex flex-col" : undefined}>
100
- <div data-chat-scroll-content className={`max-w-190 mx-auto min-w-0 w-full ${messages.length === 0 ? "flex flex-1 flex-col pb-24" : "pt-4 pb-28"}`}>
100
+ <div data-chat-scroll-content className={`max-w-200 mx-auto min-w-0 w-full ${messages.length === 0 ? "flex flex-1 flex-col pb-24" : "pt-4 pb-28"}`}>
101
101
  {messages.length === 0 ? (
102
102
  (emptyState ?? (
103
103
  <ChatWelcome name={welcomeName} description={description} avatar={avatar} starters={starters} onStarter={sendMessage} disabled={generating} />
@@ -110,7 +110,7 @@ export function AgentPanel({
110
110
 
111
111
  <div className="relative shrink-0">
112
112
  {accessory}
113
- <div className="mx-auto w-full max-w-190">
113
+ <div className="mx-auto w-full max-w-200">
114
114
  <ChatInput generating={generating} placeholder={placeholder} onSend={sendMessage} onCancel={cancel} onClear={handleNewChat} toolbar={toolbar} focusSignal={String(epoch)} enableTypeToFocus />
115
115
  </div>
116
116
  </div>
@@ -23,10 +23,15 @@ export type ChatInputProps = {
23
23
 
24
24
  function resize(el: HTMLTextAreaElement | null, maxRows = 10) {
25
25
  if (!el) return;
26
- el.style.height = "auto";
27
- const line = Number.parseFloat(getComputedStyle(el).lineHeight) || 22;
28
- const max = line * maxRows + 8;
29
- el.style.height = `${Math.min(el.scrollHeight, max)}px`;
26
+ // Collapse first — `height: auto` can keep a stretched/flex height so scrollHeight
27
+ // stays inflated until a later text change remeasures.
28
+ el.style.height = "0px";
29
+ const styles = getComputedStyle(el);
30
+ const line = Number.parseFloat(styles.lineHeight) || 22;
31
+ const padY = (Number.parseFloat(styles.paddingTop) || 0) + (Number.parseFloat(styles.paddingBottom) || 0);
32
+ const min = line + padY;
33
+ const max = line * maxRows + padY;
34
+ el.style.height = `${Math.min(Math.max(el.scrollHeight, min), max)}px`;
30
35
  }
31
36
 
32
37
  function isEditableTarget(el: EventTarget | null): boolean {
@@ -46,6 +51,16 @@ export function ChatInput({ generating = false, placeholder = "Message…", disa
46
51
  resize(textareaRef.current);
47
52
  }, [text]);
48
53
 
54
+ // Remeasure when the composer width settles (first paint / panel resize).
55
+ useEffect(() => {
56
+ const el = textareaRef.current;
57
+ const parent = el?.parentElement;
58
+ if (!el || !parent) return;
59
+ const ro = new ResizeObserver(() => resize(el));
60
+ ro.observe(parent);
61
+ return () => ro.disconnect();
62
+ }, []);
63
+
49
64
  useEffect(() => {
50
65
  const onSignal = focusSignal !== undefined;
51
66
  if (!autoFocus && !onSignal) return;
@@ -28,7 +28,7 @@ export function ChatToolCall({ toolName = "Tool", label, toolInput, toolOutput,
28
28
  const [open, setOpen] = useState(defaultOpen);
29
29
  const displayLabel = label ?? formatToolName(toolName);
30
30
 
31
- const identityIcon = icon ?? <FluentIcon name="board-24" size={13} className="shrink-0" />;
31
+ const identityIcon = icon ?? <FluentIcon name="code-block-24" size={13} className="shrink-0" />;
32
32
 
33
33
  const header = (
34
34
  <>
@@ -606,7 +606,7 @@ export function ColorPicker({
606
606
  <button
607
607
  type="button"
608
608
  aria-label="Clear"
609
- className="inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted-foreground hover:bg-foreground/6 hover:text-foreground"
609
+ className="inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-md text-muted-foreground hover:bg-ink-hover hover:text-foreground"
610
610
  onClick={() => clear()}
611
611
  >
612
612
  <ClearIcon />
@@ -269,7 +269,7 @@ const DatePickerRoot = forwardRef<HTMLButtonElement, DatePickerProps>(function D
269
269
  role="button"
270
270
  tabIndex={-1}
271
271
  aria-label="Clear"
272
- className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-foreground/6 hover:text-foreground group-hover/datepicker:opacity-100"
272
+ className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-ink-hover hover:text-foreground group-hover/datepicker:opacity-100"
273
273
  onClick={clear}
274
274
  onPointerDown={(e) => e.preventDefault()}
275
275
  >
@@ -408,7 +408,7 @@ const RangePicker = forwardRef<HTMLButtonElement, RangePickerProps>(function Ran
408
408
  role="button"
409
409
  tabIndex={-1}
410
410
  aria-label="Clear"
411
- className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-foreground/6 hover:text-foreground group-hover/datepicker:opacity-100"
411
+ className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-ink-hover hover:text-foreground group-hover/datepicker:opacity-100"
412
412
  onClick={clear}
413
413
  onPointerDown={(e) => e.preventDefault()}
414
414
  >
@@ -139,6 +139,69 @@ function offsetFromRect(view: Size, rect: Rect): Point {
139
139
  };
140
140
  }
141
141
 
142
+ type Geometry = Point & Size;
143
+
144
+ const GEOMETRY_PREFIX = "nonla-desktop-window:";
145
+ const geometryMemory = new Map<string, Geometry>();
146
+
147
+ function isGeometry(value: unknown): value is Geometry {
148
+ if (!value || typeof value !== "object") return false;
149
+ const { x, y, w, h } = value as Record<string, unknown>;
150
+ return [x, y, w, h].every((n) => typeof n === "number" && Number.isFinite(n));
151
+ }
152
+
153
+ function geometryStorageKey(persistKey: string) {
154
+ return `${GEOMETRY_PREFIX}${persistKey}`;
155
+ }
156
+
157
+ function readGeometry(persistKey: string | false): Geometry | null {
158
+ if (!persistKey) return null;
159
+ const cached = geometryMemory.get(persistKey);
160
+ if (cached) return cached;
161
+ try {
162
+ const raw = localStorage.getItem(geometryStorageKey(persistKey));
163
+ if (!raw) return null;
164
+ const parsed: unknown = JSON.parse(raw);
165
+ if (!isGeometry(parsed)) return null;
166
+ geometryMemory.set(persistKey, parsed);
167
+ return parsed;
168
+ } catch {
169
+ return null;
170
+ }
171
+ }
172
+
173
+ function writeGeometry(persistKey: string | false, geometry: Geometry) {
174
+ if (!persistKey) return;
175
+ geometryMemory.set(persistKey, geometry);
176
+ try {
177
+ localStorage.setItem(geometryStorageKey(persistKey), JSON.stringify(geometry));
178
+ } catch {
179
+ /* private mode / quota */
180
+ }
181
+ }
182
+
183
+ function initialView(): Size {
184
+ return { w: window.innerWidth, h: Math.max(0, window.innerHeight - 42) };
185
+ }
186
+
187
+ function restoreGeometry(persistKey: string | false, view: Size): { offset: Point; size: Size | null } {
188
+ const stored = readGeometry(persistKey);
189
+ if (!stored) return { offset: { x: 0, y: 0 }, size: null };
190
+ const size = clampSize(view, stored);
191
+ return { offset: clampOffset(view, size, stored), size };
192
+ }
193
+
194
+ function persistGeometry(persistKey: string | false, view: Size, offset: Point, size: Size | null) {
195
+ const compact = windowSize(view, size);
196
+ const clamped = clampOffset(view, compact, offset);
197
+ writeGeometry(persistKey, {
198
+ x: Math.round(clamped.x),
199
+ y: Math.round(clamped.y),
200
+ w: Math.round(compact.w),
201
+ h: Math.round(compact.h),
202
+ });
203
+ }
204
+
142
205
  function lockResizeCursor(cursor: string | null) {
143
206
  document.body.style.cursor = cursor ?? "";
144
207
  document.body.style.userSelect = cursor ? "none" : "";
@@ -227,6 +290,8 @@ export type DesktopWindowProps = {
227
290
  /** Overlay auto-hide scrollbar on the body. Pass `false` when children manage their own scroll (split panes, AgentPanel). */
228
291
  scroll?: boolean;
229
292
  scrollbar?: OverlayScrollVisibility;
293
+ /** Last collapsed position and size. Default `"default"`. Pass a unique key per window, or `false` to disable. */
294
+ persistKey?: string | false;
230
295
  children: ReactNode;
231
296
  };
232
297
 
@@ -239,6 +304,7 @@ export function DesktopWindow({
239
304
  onToggleExpand,
240
305
  scroll = true,
241
306
  scrollbar = "hover",
307
+ persistKey = "default",
242
308
  children,
243
309
  }: DesktopWindowProps) {
244
310
  const overlayRef = useRef<HTMLDivElement>(null);
@@ -260,15 +326,12 @@ export function DesktopWindow({
260
326
  orig: Rect;
261
327
  } | null>(null);
262
328
  const [phase, setPhase] = useState<Phase>("open");
263
- const [offset, setOffset] = useState({ x: 0, y: 0 });
264
- const [size, setSize] = useState<Size | null>(null);
329
+ const [view, setView] = useState<Size>(initialView);
330
+ const [offset, setOffset] = useState(() => restoreGeometry(persistKey, initialView()).offset);
331
+ const [size, setSize] = useState<Size | null>(() => restoreGeometry(persistKey, initialView()).size);
265
332
  const [dragging, setDragging] = useState(false);
266
333
  const [resizing, setResizing] = useState(false);
267
334
  const sizeRef = useRef<Size | null>(null);
268
- const [view, setView] = useState<Size>(() => ({
269
- w: window.innerWidth,
270
- h: Math.max(0, window.innerHeight - 42),
271
- }));
272
335
  const [leftSlot, setLeftSlot] = useState<HTMLDivElement | null>(null);
273
336
  const [rightSlot, setRightSlot] = useState<HTMLDivElement | null>(null);
274
337
  const headerChrome = useMemo(() => ({ left: leftSlot, right: rightSlot }), [leftSlot, rightSlot]);
@@ -339,6 +402,17 @@ export function DesktopWindow({
339
402
  return () => observer.disconnect();
340
403
  }, []);
341
404
 
405
+ useEffect(() => {
406
+ if (dragging || resizing) return;
407
+ persistGeometry(persistKey, view, offset, size);
408
+ }, [dragging, resizing, offset, size, view, persistKey]);
409
+
410
+ useEffect(() => {
411
+ return () => {
412
+ persistGeometry(persistKey, viewRef.current, offsetRef.current, sizeRef.current);
413
+ };
414
+ }, [persistKey]);
415
+
342
416
  useEffect(() => {
343
417
  const onKey = (e: KeyboardEvent) => {
344
418
  if (e.key !== "Escape" || e.defaultPrevented || isEditableTarget(e.target) || hasOpenDialog()) return;
@@ -423,16 +497,31 @@ export function DesktopWindow({
423
497
  };
424
498
 
425
499
  const startResize = (edge: Edge, e: ReactPointerEvent<HTMLElement>) => {
426
- if (e.button !== 0 || expanded || phase === "leaving") return;
500
+ if (e.button !== 0 || phase === "leaving") return;
427
501
  e.stopPropagation();
428
502
  e.preventDefault();
429
503
 
504
+ const nextView = viewRef.current;
505
+ const orig = expandedRef.current
506
+ ? { x: 0, y: 0, w: nextView.w, h: nextView.h }
507
+ : collapsedRect(nextView, offsetRef.current, sizeRef.current);
508
+
509
+ if (expandedRef.current) {
510
+ const nextSize = { w: orig.w, h: orig.h };
511
+ const nextOffset = offsetFromRect(nextView, orig);
512
+ sizeRef.current = nextSize;
513
+ offsetRef.current = nextOffset;
514
+ setSize(nextSize);
515
+ setOffset(nextOffset);
516
+ onToggleExpand();
517
+ }
518
+
430
519
  resizeRef.current = {
431
520
  pointerId: e.pointerId,
432
521
  edge,
433
522
  startX: e.clientX,
434
523
  startY: e.clientY,
435
- orig: collapsedRect(viewRef.current, offsetRef.current, sizeRef.current),
524
+ orig,
436
525
  };
437
526
  setResizing(true);
438
527
  lockResizeCursor(HANDLES.find((handle) => handle.edge === edge)?.cursor ?? "nwse-resize");
@@ -530,7 +619,7 @@ export function DesktopWindow({
530
619
  </div>
531
620
  </div>
532
621
 
533
- {!expanded && !leaving
622
+ {!leaving
534
623
  ? HANDLES.map((handle) => (
535
624
  <div key={handle.edge} aria-hidden onPointerDown={(e) => startResize(handle.edge, e)} className={cn("absolute z-10 touch-none", handle.className)} />
536
625
  ))
@@ -59,7 +59,7 @@ function MenuItems({
59
59
  if (item.children?.length) {
60
60
  return (
61
61
  <ContextMenuPrimitive.Sub key={key}>
62
- <ContextMenuPrimitive.SubTrigger disabled={item.disabled} className={cn(menuItemClass, "data-[state=open]:bg-foreground/8", item.danger && "text-destructive", item.className)} style={item.style}>
62
+ <ContextMenuPrimitive.SubTrigger disabled={item.disabled} className={cn(menuItemClass, "data-[state=open]:bg-ink-active", item.danger && "text-destructive", item.className)} style={item.style}>
63
63
  {item.icon ? <span className={menuIconClass}>{item.icon}</span> : null}
64
64
  <span className="min-w-0 flex-1">{item.label}</span>
65
65
  <ChevronRight />
@@ -76,7 +76,7 @@ function MenuItems({ items, onClick, portal }: { items: (MenuItemType | null | u
76
76
  if (item.children?.length) {
77
77
  return (
78
78
  <DropdownMenu.Sub key={key}>
79
- <DropdownMenu.SubTrigger disabled={item.disabled} className={cn(menuItemClass, "data-[state=open]:bg-foreground/8", item.danger && "text-destructive", item.className)} style={item.style}>
79
+ <DropdownMenu.SubTrigger disabled={item.disabled} className={cn(menuItemClass, "data-[state=open]:bg-ink-active", item.danger && "text-destructive", item.className)} style={item.style}>
80
80
  {item.icon ? <span className={menuIconClass}>{item.icon}</span> : null}
81
81
  <span className="min-w-0 flex-1">{item.label}</span>
82
82
  <ChevronRight />
package/src/index.ts CHANGED
@@ -174,6 +174,8 @@ export type { SelectOptionConfig, SelectProps, SelectValue } from "./select/Sele
174
174
  export { Select, SelectOption } from "./select/Select";
175
175
  export type { ShimmerProps } from "./shimmer/Shimmer";
176
176
  export { Shimmer } from "./shimmer/Shimmer";
177
+ export type { SidebarItemType, SidebarProps, SidebarSelectInfo } from "./sidebar/Sidebar";
178
+ export { Sidebar } from "./sidebar/Sidebar";
177
179
  export type { SkeletonProps } from "./skeleton/Skeleton";
178
180
  export { Skeleton } from "./skeleton/Skeleton";
179
181
  export type { SpinProps, SpinVariant } from "./spin/Spin";
@@ -299,7 +299,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
299
299
  tabIndex={-1}
300
300
  aria-label="Increase"
301
301
  disabled={atMax}
302
- className={cn("flex flex-1 items-center justify-center text-muted-foreground", "hover:bg-foreground/5 hover:text-foreground active:bg-foreground/8", "disabled:opacity-30 disabled:pointer-events-none", "border-b border-border/60")}
302
+ className={cn("flex flex-1 items-center justify-center text-muted-foreground", "hover:bg-ink-hover hover:text-foreground active:bg-ink-active", "disabled:opacity-30 disabled:pointer-events-none", "border-b border-border/60")}
303
303
  onMouseDown={(e) => e.preventDefault()}
304
304
  onClick={() => stepBy(1)}
305
305
  >
@@ -310,7 +310,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
310
310
  tabIndex={-1}
311
311
  aria-label="Decrease"
312
312
  disabled={atMin}
313
- className={cn("flex flex-1 items-center justify-center text-muted-foreground", "hover:bg-foreground/5 hover:text-foreground active:bg-foreground/8", "disabled:opacity-30 disabled:pointer-events-none")}
313
+ className={cn("flex flex-1 items-center justify-center text-muted-foreground", "hover:bg-ink-hover hover:text-foreground active:bg-ink-active", "disabled:opacity-30 disabled:pointer-events-none")}
314
314
  onMouseDown={(e) => e.preventDefault()}
315
315
  onClick={() => stepBy(-1)}
316
316
  >
package/src/menu/Menu.tsx CHANGED
@@ -65,7 +65,7 @@ export type MenuItemProps = {
65
65
 
66
66
  export function MenuItem({ icon, label, extra, selected, action, onClick, className }: MenuItemProps) {
67
67
  return (
68
- <div className={cn("group relative flex min-h-8 items-center rounded-md", selected ? "bg-ink-active" : "hover:bg-foreground/5", className)}>
68
+ <div className={cn("group relative flex min-h-8 items-center rounded-md", selected ? "bg-ink-active" : "hover:bg-ink-hover", className)}>
69
69
  <button
70
70
  type="button"
71
71
  aria-current={selected ? "true" : undefined}
@@ -114,7 +114,7 @@ function ItemBtn({
114
114
  className={cn(
115
115
  "group inline-flex min-w-0 cursor-pointer items-center justify-center px-1.5 tabular-nums select-none",
116
116
  "transition-colors disabled:cursor-not-allowed disabled:opacity-40",
117
- active ? "bg-brand font-medium text-(--nonla-solid-fg)" : "text-muted-foreground hover:bg-foreground/5 hover:text-foreground",
117
+ active ? "bg-brand font-medium text-(--nonla-solid-fg)" : "text-muted-foreground hover:bg-ink-hover hover:text-foreground",
118
118
  className,
119
119
  )}
120
120
  style={{
@@ -245,7 +245,7 @@ function GoButton({
245
245
  "inline-flex cursor-pointer items-center justify-center px-2 text-foreground",
246
246
  controlFieldSurface,
247
247
  controlFieldTransition,
248
- "hover:bg-foreground/5 disabled:cursor-not-allowed disabled:opacity-45",
248
+ "hover:bg-ink-hover disabled:cursor-not-allowed disabled:opacity-45",
249
249
  )}
250
250
  style={{
251
251
  height: controlHeightVar(size),
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from "react";
1
+ import { type ReactNode, useLayoutEffect, useRef, useState } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
  import { type ControlSize, controlHeightVar, controlRadiusVar, getSizeTokens, useControlSize } from "../lib/sizes";
4
4
 
@@ -20,6 +20,8 @@ function norm<V extends string | number>(opt: SegmentedOption<V>): { label: Reac
20
20
  return opt;
21
21
  }
22
22
 
23
+ type Thumb = { left: number; top: number; width: number; height: number };
24
+
23
25
  export function Segmented<V extends string | number = string | number>({ options, value, defaultValue, onChange, size, block, disabled, className }: SegmentedProps<V>) {
24
26
  const items = options.map((o) => norm(o));
25
27
  const current = value ?? defaultValue ?? items[0]?.value;
@@ -28,26 +30,73 @@ export function Segmented<V extends string | number = string | number>({ options
28
30
  const itemPadX = Math.max(tok.paddingInline - 4, 6);
29
31
  const radius = controlRadiusVar(resolvedSize);
30
32
 
33
+ const rootRef = useRef<HTMLDivElement>(null);
34
+ const itemRefs = useRef(new Map<string, HTMLButtonElement>());
35
+ const [thumb, setThumb] = useState<Thumb | null>(null);
36
+
37
+ const itemsKey = items.map((i) => String(i.value)).join("");
38
+
39
+ useLayoutEffect(() => {
40
+ const root = rootRef.current;
41
+ if (!root) return;
42
+
43
+ const measure = () => {
44
+ const el = itemRefs.current.get(String(current));
45
+ if (!el) {
46
+ setThumb(null);
47
+ return;
48
+ }
49
+ setThumb({ left: el.offsetLeft, top: el.offsetTop, width: el.offsetWidth, height: el.offsetHeight });
50
+ };
51
+
52
+ measure();
53
+ const ro = new ResizeObserver(measure);
54
+ ro.observe(root);
55
+ return () => ro.disconnect();
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ }, [current, resolvedSize, block, itemsKey]);
58
+
31
59
  return (
32
60
  <div
33
- className={cn("inline-flex w-fit max-w-full shrink-0 items-center gap-0.5 rounded-lg bg-brand-50 p-0.5", block && "flex w-full", className)}
61
+ ref={rootRef}
62
+ className={cn(
63
+ "relative inline-flex w-fit max-w-full shrink-0 items-center gap-0.5 rounded-lg border border-solid border-glass-border bg-glass-bar p-0.5 shadow-[inset_0_1px_0_var(--glass-highlight)] backdrop-blur-xl",
64
+ block && "flex w-full",
65
+ className,
66
+ )}
34
67
  role="tablist"
35
68
  style={{ borderRadius: radius }}
36
69
  data-size={resolvedSize}
37
70
  >
71
+ {thumb ? (
72
+ <span
73
+ aria-hidden
74
+ className="nonla-segmented-thumb pointer-events-none absolute border border-solid border-glass-border bg-glass shadow-[inset_0_1px_0_var(--glass-highlight),0_1px_3px_color-mix(in_srgb,black_10%,transparent)]"
75
+ style={{
76
+ width: thumb.width,
77
+ height: thumb.height,
78
+ transform: `translate(${thumb.left}px, ${thumb.top}px)`,
79
+ borderRadius: `max(4px, calc(${radius} - 2px))`,
80
+ }}
81
+ />
82
+ ) : null}
38
83
  {items.map((item) => {
39
84
  const active = item.value === current;
40
85
  return (
41
86
  <button
42
87
  key={String(item.value)}
88
+ ref={(el) => {
89
+ if (el) itemRefs.current.set(String(item.value), el);
90
+ else itemRefs.current.delete(String(item.value));
91
+ }}
43
92
  type="button"
44
93
  role="tab"
45
94
  aria-selected={active}
46
95
  disabled={disabled || item.disabled}
47
96
  className={cn(
48
- "inline-flex cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 transition-colors focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45",
97
+ "relative z-10 inline-flex cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border border-solid border-transparent transition-colors focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45",
49
98
  block ? "min-w-0 flex-1" : "shrink-0",
50
- active ? "bg-brand-200 text-foreground" : "bg-transparent text-foreground hover:bg-brand-100",
99
+ active ? "text-foreground" : "bg-transparent text-foreground hover:bg-ink-hover",
51
100
  )}
52
101
  style={{
53
102
  height: `max(22px, calc(${controlHeightVar(resolvedSize)} - 4px))`,
@@ -12,6 +12,7 @@ import {
12
12
  useState,
13
13
  } from "react";
14
14
  import { usePopupContainer } from "../app/context";
15
+ import { menuItemClass } from "../dropdown/menuClasses";
15
16
  import { cn } from "../lib/cn";
16
17
  import { type ControlSize, controlFieldFocusBorder, controlFieldStyle, controlFieldSurface, controlFieldTransition, controlStatusClass, useControlSize } from "../lib/sizes";
17
18
  import { glassOverlayClass } from "../lib/surface";
@@ -233,7 +234,7 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select
233
234
  role="button"
234
235
  tabIndex={-1}
235
236
  aria-label="Clear"
236
- className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-foreground/6 hover:text-foreground group-hover/select:opacity-100"
237
+ className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-ink-hover hover:text-foreground group-hover/select:opacity-100"
237
238
  onPointerDown={(e) => e.preventDefault()}
238
239
  onClick={(e) => {
239
240
  e.preventDefault();
@@ -293,11 +294,12 @@ export const Select = forwardRef<HTMLButtonElement, SelectProps>(function Select
293
294
  tabIndex={-1}
294
295
  aria-selected={opt.value === selected}
295
296
  data-active={i === active ? "true" : undefined}
297
+ data-highlighted={!opt.disabled && i === active && opt.value !== selected ? "" : undefined}
296
298
  className={cn(
297
- "relative flex cursor-pointer select-none items-center rounded-md border border-solid border-transparent px-2.5 py-1.5 text-sm outline-none",
299
+ menuItemClass,
300
+ "cursor-pointer",
298
301
  opt.disabled && "pointer-events-none opacity-40",
299
302
  !opt.disabled && opt.value === selected && "nonla-glass-chip-on text-foreground",
300
- !opt.disabled && i === active && opt.value !== selected && "nonla-glass-chip",
301
303
  )}
302
304
  onMouseEnter={() => setActive(i)}
303
305
  onMouseDown={(e) => e.preventDefault()}
@@ -0,0 +1,198 @@
1
+ import { type MouseEvent, type ReactNode, useMemo, useState } from "react";
2
+ import { FluentIcon } from "../icon/FluentIcon";
3
+ import { SearchInput } from "../input/SearchInput";
4
+ import { cn } from "../lib/cn";
5
+ import { OverlayScroll } from "../scroll/OverlayScroll";
6
+
7
+ export type SidebarItemType = {
8
+ key?: string;
9
+ label?: ReactNode;
10
+ /** Fluent icon name, or a node. */
11
+ icon?: ReactNode;
12
+ disabled?: boolean;
13
+ type?: "item" | "group" | "divider";
14
+ children?: SidebarItemType[];
15
+ href?: string;
16
+ extra?: ReactNode;
17
+ className?: string;
18
+ };
19
+
20
+ export type SidebarSelectInfo = {
21
+ key: string;
22
+ item: SidebarItemType;
23
+ };
24
+
25
+ export type SidebarProps = {
26
+ items?: SidebarItemType[];
27
+ selectedKey?: string;
28
+ defaultSelectedKey?: string;
29
+ onSelect?: (info: SidebarSelectInfo) => void;
30
+ searchable?: boolean;
31
+ searchPlaceholder?: string;
32
+ header?: ReactNode;
33
+ footer?: ReactNode;
34
+ emptyText?: ReactNode;
35
+ className?: string;
36
+ "aria-label"?: string;
37
+ };
38
+
39
+ function itemKey(item: SidebarItemType, i: number) {
40
+ return item.key ?? (item.type === "divider" ? `divider-${i}` : isGroup(item) ? `group-${i}` : `item-${i}`);
41
+ }
42
+
43
+ function isGroup(item: SidebarItemType) {
44
+ return item.type === "group" || (item.type !== "item" && item.type !== "divider" && Boolean(item.children?.length));
45
+ }
46
+
47
+ function labelText(label: ReactNode) {
48
+ if (typeof label === "string" || typeof label === "number") return String(label);
49
+ return "";
50
+ }
51
+
52
+ function matchesQuery(item: SidebarItemType, q: string) {
53
+ if (!q) return true;
54
+ return labelText(item.label).toLowerCase().includes(q);
55
+ }
56
+
57
+ function filterItems(items: SidebarItemType[], q: string): SidebarItemType[] {
58
+ if (!q) return items;
59
+ const out: SidebarItemType[] = [];
60
+ for (const item of items) {
61
+ if (item.type === "divider") {
62
+ if (out.length && out[out.length - 1]?.type !== "divider") out.push(item);
63
+ continue;
64
+ }
65
+ if (isGroup(item)) {
66
+ const children = filterItems(item.children ?? [], q);
67
+ if (children.length || matchesQuery(item, q)) out.push({ ...item, children });
68
+ continue;
69
+ }
70
+ if (matchesQuery(item, q)) out.push(item);
71
+ }
72
+ while (out[out.length - 1]?.type === "divider") out.pop();
73
+ return out;
74
+ }
75
+
76
+ function ItemIcon({ icon }: { icon?: ReactNode }) {
77
+ if (icon == null || icon === false) return null;
78
+ if (typeof icon === "string") return <FluentIcon name={icon} size={16} />;
79
+ return <span className="inline-flex size-4 shrink-0 items-center justify-center [&_img]:size-4 [&_svg]:size-4">{icon}</span>;
80
+ }
81
+
82
+ function SidebarList({
83
+ items,
84
+ selected,
85
+ onSelect,
86
+ }: {
87
+ items: SidebarItemType[];
88
+ selected?: string;
89
+ onSelect?: SidebarProps["onSelect"];
90
+ }) {
91
+ return (
92
+ <>
93
+ {items.map((item, i) => {
94
+ const key = itemKey(item, i);
95
+ if (item.type === "divider") {
96
+ return <div key={key} className="mx-2 my-1 h-px bg-ink-line" />;
97
+ }
98
+ if (isGroup(item)) {
99
+ return (
100
+ <div key={key} className="mb-4">
101
+ {item.label != null && item.label !== "" ? (
102
+ <div className={cn("px-2 pb-1.5 pt-2 text-[11px] font-medium uppercase tracking-wider text-quaternary-foreground", item.className)}>
103
+ {item.label}
104
+ </div>
105
+ ) : null}
106
+ <div className="flex flex-col gap-0.5">
107
+ <SidebarList items={item.children ?? []} selected={selected} onSelect={onSelect} />
108
+ </div>
109
+ </div>
110
+ );
111
+ }
112
+
113
+ const active = selected != null && key === selected;
114
+ const className = cn(
115
+ "flex w-full items-center gap-2 rounded-md border-0 px-2 py-1.5 text-left text-sm no-underline",
116
+ item.disabled ? "pointer-events-none cursor-not-allowed opacity-40" : "cursor-pointer",
117
+ active ? "bg-ink-active font-medium text-foreground" : "bg-transparent text-foreground/80 hover:bg-ink-hover hover:text-foreground",
118
+ item.className,
119
+ );
120
+
121
+ const body = (
122
+ <>
123
+ <ItemIcon icon={item.icon} />
124
+ <span className="min-w-0 flex-1 truncate">{item.label}</span>
125
+ {item.extra != null ? <span className="shrink-0 text-xs tabular-nums text-muted-foreground">{item.extra}</span> : null}
126
+ </>
127
+ );
128
+
129
+ const activate = (e: MouseEvent<HTMLElement>) => {
130
+ if (item.disabled) {
131
+ e.preventDefault();
132
+ return;
133
+ }
134
+ if (item.href && (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0)) return;
135
+ if (item.href && onSelect) e.preventDefault();
136
+ onSelect?.({ key, item });
137
+ };
138
+
139
+ if (item.href) {
140
+ return (
141
+ <a key={key} href={item.href} aria-current={active ? "page" : undefined} aria-disabled={item.disabled || undefined} className={className} onClick={activate}>
142
+ {body}
143
+ </a>
144
+ );
145
+ }
146
+
147
+ return (
148
+ <button key={key} type="button" aria-current={active ? "true" : undefined} disabled={item.disabled} className={className} onClick={activate}>
149
+ {body}
150
+ </button>
151
+ );
152
+ })}
153
+ </>
154
+ );
155
+ }
156
+
157
+ /** Grouped side nav — pass JSON groups + items. Router stays in the app (`onSelect` / `href`). */
158
+ export function Sidebar({
159
+ items = [],
160
+ selectedKey,
161
+ defaultSelectedKey,
162
+ onSelect,
163
+ searchable = false,
164
+ searchPlaceholder = "Search…",
165
+ header,
166
+ footer,
167
+ emptyText = "No matches.",
168
+ className,
169
+ "aria-label": ariaLabel = "Sidebar",
170
+ }: SidebarProps) {
171
+ const [query, setQuery] = useState("");
172
+ const [uncontrolled, setUncontrolled] = useState(defaultSelectedKey);
173
+ const selected = selectedKey ?? uncontrolled;
174
+
175
+ const visible = useMemo(() => filterItems(items, query.trim().toLowerCase()), [items, query]);
176
+
177
+ const handleSelect = (info: SidebarSelectInfo) => {
178
+ if (selectedKey === undefined) setUncontrolled(info.key);
179
+ onSelect?.(info);
180
+ };
181
+
182
+ return (
183
+ <div className={cn("flex h-full min-h-0 flex-col", className)}>
184
+ {header}
185
+ {searchable ? (
186
+ <div className={cn("shrink-0 px-3 pb-2", header ? "pt-1" : "pt-3")}>
187
+ <SearchInput size="small" wait={0} placeholder={searchPlaceholder} onChange={setQuery} />
188
+ </div>
189
+ ) : null}
190
+ <OverlayScroll className="min-h-0 flex-1" innerClassName={cn("px-2 pb-6", !searchable && !header && "pt-2")}>
191
+ <nav aria-label={ariaLabel}>
192
+ {visible.length === 0 ? <p className="px-2 py-4 text-sm text-muted-foreground">{emptyText}</p> : <SidebarList items={visible} selected={selected} onSelect={handleSelect} />}
193
+ </nav>
194
+ </OverlayScroll>
195
+ {footer}
196
+ </div>
197
+ );
198
+ }
@@ -290,9 +290,12 @@ function SplitterRoot({
290
290
  >
291
291
  <span
292
292
  className={cn(
293
- "pointer-events-none absolute rounded-full transition-colors",
294
- isVertical ? "inset-x-0 top-1/2 h-0.5 -translate-y-1/2" : "inset-y-0 left-1/2 w-0.5 -translate-x-1/2",
293
+ "pointer-events-none absolute rounded-full transition-all",
294
+ isVertical
295
+ ? "inset-x-0 top-1/2 h-px -translate-y-1/2 group-hover:h-[3px] group-focus-visible:h-[3px]"
296
+ : "inset-y-0 left-1/2 w-px -translate-x-1/2 group-hover:w-[3px] group-focus-visible:w-[3px]",
295
297
  dragging ? "bg-brand" : "bg-border group-hover:bg-brand group-focus-visible:bg-brand",
298
+ dragging && (isVertical ? "h-[3px]" : "w-[3px]"),
296
299
  )}
297
300
  />
298
301
  {draggerIcon ? (
@@ -304,16 +307,7 @@ function SplitterRoot({
304
307
  >
305
308
  {draggerIcon}
306
309
  </span>
307
- ) : (
308
- <span
309
- className={cn(
310
- "pointer-events-none absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-sm bg-card shadow-button-outline transition-opacity",
311
- "opacity-0 group-hover:opacity-100 group-focus-visible:opacity-100",
312
- dragging && "opacity-100",
313
- isVertical ? "h-1 w-8" : "h-8 w-1",
314
- )}
315
- />
316
- )}
310
+ ) : null}
317
311
  </div>
318
312
  </div>
319
313
  ) : null}
package/src/styles.css CHANGED
@@ -650,13 +650,17 @@
650
650
  }
651
651
 
652
652
  /* Nested glass chip — hover is frost only; selected tints with brand */
653
- .nonla-glass-chip,
654
- .nonla-menu-item[data-highlighted] {
653
+ .nonla-glass-chip {
655
654
  background: var(--glass-bar);
656
655
  border-color: var(--glass-border);
657
656
  -webkit-backdrop-filter: blur(24px);
658
657
  backdrop-filter: blur(24px);
659
658
  }
659
+ /* Menu item hover — pure ink tint; panel's warm frost shows through, no milky gray */
660
+ .nonla-menu-item[data-highlighted] {
661
+ background: var(--ink-hover);
662
+ border-color: var(--glass-border);
663
+ }
660
664
  .nonla-glass-chip-on {
661
665
  background: var(--glass-bar);
662
666
  border-color: color-mix(in oklab, var(--brand) 38%, var(--glass-border));
@@ -664,6 +668,16 @@
664
668
  -webkit-backdrop-filter: blur(24px);
665
669
  backdrop-filter: blur(24px);
666
670
  }
671
+ /* Segmented sliding thumb — glass pill glides between items */
672
+ .nonla-segmented-thumb {
673
+ top: 0;
674
+ left: 0;
675
+ transition:
676
+ transform 380ms cubic-bezier(0.3, 1.25, 0.5, 1),
677
+ width 380ms cubic-bezier(0.3, 1.25, 0.5, 1),
678
+ height 380ms cubic-bezier(0.3, 1.25, 0.5, 1);
679
+ }
680
+
667
681
  @media (prefers-reduced-motion: reduce) {
668
682
  .nonla-btn-glass {
669
683
  transition: box-shadow var(--nonla-dur-fast) var(--nonla-ease-out);
@@ -671,6 +685,9 @@
671
685
  .nonla-btn-glass:active:not(:disabled):not([aria-disabled]) {
672
686
  transform: none;
673
687
  }
688
+ .nonla-segmented-thumb {
689
+ transition: none;
690
+ }
674
691
  }
675
692
 
676
693
  .nonla-overlay {
package/src/tag/Tag.tsx CHANGED
@@ -97,7 +97,7 @@ export function Tag({
97
97
  {closable ? (
98
98
  <button
99
99
  type="button"
100
- className="-mr-0.5 inline-flex size-3.5 shrink-0 items-center justify-center rounded-full text-current/55 transition-colors hover:bg-foreground/8 hover:text-current"
100
+ className="-mr-0.5 inline-flex size-3.5 shrink-0 items-center justify-center rounded-full text-current/55 transition-colors hover:bg-ink-hover hover:text-current"
101
101
  aria-label="Remove"
102
102
  onClick={onClose}
103
103
  >
@@ -245,7 +245,7 @@ function StepperButton({
245
245
  aria-label={label}
246
246
  className={cn(
247
247
  "flex h-10 items-center justify-center rounded-md text-muted-foreground transition-colors",
248
- "hover:bg-foreground/5 hover:text-foreground active:bg-foreground/8",
248
+ "hover:bg-ink-hover hover:text-foreground active:bg-ink-active",
249
249
  )}
250
250
  style={{ width: size }}
251
251
  onPointerDown={onPointerDown}
@@ -298,7 +298,7 @@ function PickGrid({
298
298
  tabIndex={-1}
299
299
  className={cn(
300
300
  "flex h-11 items-center justify-center rounded-md tabular-nums text-[13.5px] font-normal transition-colors",
301
- selected ? "bg-foreground/8 text-foreground" : "text-foreground hover:bg-foreground/5",
301
+ selected ? "bg-ink-active text-foreground" : "text-foreground hover:bg-ink-hover",
302
302
  )}
303
303
  onClick={() => onSelect(opt.value)}
304
304
  >
@@ -372,7 +372,7 @@ function StepperBoard({
372
372
  className={cn(
373
373
  "flex cursor-pointer items-center justify-center rounded-md font-semibold leading-none tracking-tight transition-colors",
374
374
  col.wide ? "text-[23px]" : "tabular-nums",
375
- col.active ? "bg-foreground/6 text-foreground" : "text-foreground hover:bg-foreground/5",
375
+ col.active ? "bg-ink-hover text-foreground" : "text-foreground hover:bg-ink-hover",
376
376
  )}
377
377
  style={{ width: size, height: size, fontSize: col.wide ? undefined : fontSize }}
378
378
  onClick={col.onPick}
@@ -640,7 +640,7 @@ export const TimePicker = forwardRef<HTMLInputElement, TimePickerProps>(function
640
640
  type="button"
641
641
  tabIndex={-1}
642
642
  aria-label="Clear"
643
- className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-foreground/6 hover:text-foreground group-hover/timepicker:opacity-100 group-focus-within/timepicker:opacity-100"
643
+ className="inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground opacity-0 transition-opacity hover:bg-ink-hover hover:text-foreground group-hover/timepicker:opacity-100 group-focus-within/timepicker:opacity-100"
644
644
  onMouseDown={(e) => e.preventDefault()}
645
645
  onClick={clear}
646
646
  >
@@ -682,7 +682,7 @@ export const TimePicker = forwardRef<HTMLInputElement, TimePickerProps>(function
682
682
  type="button"
683
683
  tabIndex={-1}
684
684
  aria-label="Back"
685
- className="absolute top-2 left-1.5 z-10 flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-foreground/5 hover:text-foreground"
685
+ className="absolute top-2 left-1.5 z-10 flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-ink-hover hover:text-foreground"
686
686
  onClick={() => setPicking(null)}
687
687
  >
688
688
  <Chevron dir="left" />