devnonla-ui 0.12.0 → 0.13.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
@@ -2,6 +2,8 @@
2
2
 
3
3
  React controls for Nonla Agents.
4
4
 
5
+ Docs: https://devnonla.github.io/devnonla-ui/
6
+
5
7
  ```bash
6
8
  bun add devnonla-ui
7
9
  ```
@@ -10,256 +12,15 @@ Peer deps: `react` / `react-dom` >= 19, `react-hook-form`. Consumer should use T
10
12
 
11
13
  ```tsx
12
14
  import "devnonla-ui/styles.css";
13
- import { App, Button, EFormItemType, SchemaForm, Modal, message, type TFormItemProps } from "devnonla-ui";
14
- import { useForm } from "react-hook-form";
15
-
16
- message.success("Saved");
17
- Modal.confirm({ title: "Delete?", onOk: async () => {} });
15
+ import { App, Button } from "devnonla-ui";
18
16
 
19
- const items: TFormItemProps[] = [
20
- {
21
- type: EFormItemType.Input,
22
- name: "name",
23
- label: "Name",
24
- rules: { required: "Name is required" },
25
- options: { placeholder: "Your name" },
26
- },
27
- ];
28
-
29
- function Example() {
30
- const form = useForm({ defaultValues: { name: "" } });
17
+ export function Root() {
31
18
  return (
32
19
  <App>
33
- <form onSubmit={form.handleSubmit(console.log)}>
34
- <SchemaForm form={form} items={items} />
35
- <Button type="primary" htmlType="submit">
36
- Save
37
- </Button>
38
- </form>
20
+ <Button type="primary">Save</Button>
39
21
  </App>
40
22
  );
41
23
  }
42
24
  ```
43
25
 
44
- `SchemaForm` is JSON-schema driven (ZoForm-style) on `react-hook-form`. The BE can return `TFormItemProps[]`; FE hydrates `rules.pattern` strings to `RegExp`. Pass `fetcher` for `select_remote` fields. Layout-only labeled fields use `Form` / `Form.Item`.
45
-
46
- # Sizes
47
-
48
- Only **3 canonical sizes**: `small` | `default` | `large`.
49
-
50
- Edit [`src/lib/sizes.ts`](src/lib/sizes.ts) — `CONTROL_SIZES`.
51
-
52
- Aliases: `xs` → small, `middle` / `medium` → default.
53
-
54
- # Theme (colors)
55
-
56
- All color lives in **`--nonla-*` knobs** (`src/styles.css`). Components never hardcode palette hex.
57
-
58
- Dark is the default (`:root` and `.dark`). `.light` is the daylight palette. `<App>` calls `initColorMode()` once and restores `localStorage` key `nonla-color-mode`, falling back to dark. Switch with `setColorMode("light" | "dark")` or `<ThemeToggle>`. `setColorPreference("light" | "dark" | "system")` and `<ThemeSwitcher>` also store `system`, which follows the OS and still paints `light` or `dark`. To start in daylight before paint, put `class="light"` on `<html>`.
59
-
60
- **Other apps** — import the CSS, then override knobs. Do not fork Button/Tag/….
61
-
62
- ```css
63
- @import "tailwindcss";
64
- @import "devnonla-ui/styles.css";
65
-
66
- :root {
67
- --nonla-brand: #3b82f6;
68
- --nonla-bg: #0b0f19;
69
- }
70
- ```
71
-
72
- `--brand-50` … `--brand-800` follow `--nonla-brand` (500 = the knob). Tints mix into the surface; `brand-700` stays with the ink. Text **on** the brand fill (Button primary, Tag solid, Checkbox) is `--nonla-solid-fg` / `colors.solidFg` — default `#181818` on the neutral `#f0f0f0` fill.
73
-
74
- Or at runtime:
75
-
76
- ```tsx
77
- <App
78
- theme={{
79
- colors: { brand: "#3b82f6", bg: "#0b0f19", border: "#666666", borderInput: "#8a8a8a" },
80
- }}
81
- >
82
- …
83
- </App>
84
- ```
85
-
86
- Flat knobs still work (`brand`, `colorBorder`, `colorBorderInput`, …). `applyNonlaTheme({ brand: "#3b82f6" })` does the same on `:root`.
87
-
88
- Core knobs: `--nonla-bg`, `--nonla-fg`, `--nonla-brand`, `--nonla-solid-fg`, `--nonla-danger`, `--nonla-success`, `--nonla-warn`, `--nonla-link`, `--nonla-radius` (small = −2px, large = +2px), `--nonla-height` / `--nonla-height-sm` / `--nonla-height-lg`, plus surfaces (`--nonla-surface`, `--nonla-chip`, …) and preset accents (`--nonla-blue`, `--nonla-purple`, …).
89
-
90
- Those map into shadcn-standard tokens (`--background`, `--destructive`, …) plus Nonla aliases (`--brand`, `--success`, …).
91
-
92
- - You: only touch `--nonla-*` (CSS or `theme` / `applyNonlaTheme`).
93
- - Shadcn consumers: can still override `--background` / `--primary` / etc.
94
- - Nonla CTA = `--brand` (from `--nonla-brand`). Label on that fill = `--nonla-solid-fg`. `--primary` = ink (emphasis), not the brand button.
95
-
96
- `<App>` is the ConfigProvider: `theme`, `componentSize`, `getPopupContainer`. Overlay portals (Select, Dropdown, DatePicker, Modal, Drawer, …) read `getPopupContainer`. `message.*` and `Modal.confirm` render into holders under `App`. `useToken()` / `getDesignToken()` read the live seed knobs.
97
-
98
- ```tsx
99
- <App componentSize="large" getPopupContainer={() => document.getElementById("app")!}>
100
- …
101
- </App>
102
- ```
103
-
104
- # Card
105
-
106
- Titled settings surface. `Card.Item` is a label row; `align="center"` for a short row, `split` so a field fills the trailing half. `Card.Footer` sits under the rows. `caption` is the note under the frame.
107
-
108
- ```tsx
109
- import { Card, Switch } from "devnonla-ui";
110
-
111
- <Card title="General" caption="Applies to this workspace.">
112
- <Card.Item label="Notifications" align="center">
113
- <Switch />
114
- </Card.Item>
115
- <Card.Footer>Saved</Card.Footer>
116
- </Card>
117
- ```
118
-
119
- # Desktop
120
-
121
- Meadow wallpaper, window chrome, header bar, and desktop icons live in this package so other Nonla apps share the same shell.
122
-
123
- ```tsx
124
- import { DesktopStage, DesktopHeader, MeadowDesktop, DesktopWindow, MeadowShell, Menu, SolarIcon } from "devnonla-ui";
125
-
126
- <DesktopStage>
127
- <MeadowDesktop>{icons}</MeadowDesktop>
128
- <DesktopHeader left={nav} right={apps} />
129
- <DesktopWindow title="Tools" left={nav} right={actions} expanded={false} onClose={close} onToggleExpand={toggle}>
130
- {children}
131
- </DesktopWindow>
132
- </DesktopStage>
133
- ```
134
-
135
- `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`. The window zooms open; `origin` is the element it zooms from, and `closeRef` receives a close function to call instead of unmounting so it can shrink back. 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.
136
-
137
- # Sidebar
138
-
139
- Grouped side nav. Pass JSON groups + items; the app owns routing.
140
-
141
- ```tsx
142
- import { Sidebar, type SidebarItemType } from "devnonla-ui";
143
-
144
- const items: SidebarItemType[] = [
145
- {
146
- type: "group",
147
- key: "chat",
148
- label: "Chat",
149
- children: [
150
- { key: "inbox", label: "Inbox", icon: "chat-24" },
151
- { key: "archive", label: "Archive", icon: "library-24" },
152
- ],
153
- },
154
- ];
155
-
156
- <Sidebar items={items} selectedKey={active} searchable onSelect={({ key }) => setActive(key)} />
157
- ```
158
-
159
- `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.
160
-
161
- # Chat
162
-
163
- `AgentPanel` is the full chat surface: welcome, messages, thinking, tool calls, markdown, composer. Attach an SSE endpoint and send. The panel POSTs `{ messages }` (plus optional `extraBody`).
164
-
165
- `AgentChatbox` is the same UI when the **app** owns the request: `send` POSTs only the new user text; `resume` reattaches a live stream on mount; `onStop` runs after the client abort.
166
-
167
- ```tsx
168
- import { AgentChatbox, AgentPanel } from "devnonla-ui";
169
-
170
- <AgentPanel
171
- endpoint="/api/agents/abc/assistant/stream"
172
- title="Nova"
173
- toolbar={<ModelPicker />}
174
- toolUis={[{ name: "get_calendar_events", component: CalendarToolUI }]}
175
- toolHooks={[
176
- { name: "web_fetch", onCall: (e) => console.log("fetch", e.input), onResult: (e) => console.log("done", e.output) },
177
- ]}
178
- />
179
-
180
- <AgentChatbox
181
- send={({ text, signal }) => fetch("/api/chat", { method: "POST", body: JSON.stringify({ text }), signal })}
182
- resume={({ signal }) => fetch("/api/chat/stream", { signal })}
183
- onStop={() => fetch("/api/chat/stop", { method: "POST" })}
184
- />
185
- ```
186
-
187
- `endpoint` can also be a function that returns a `Response` (tests, mocks). Pass any node to `toolbar` for the composer (model picker, tools, …). Extra tool cards go in `toolUis` and win over builtins on the same `toolName`. `toolHooks` fire `onCall` / `onResult` for matching tools (omit `name` to hear every tool).
188
-
189
- Stream events:
190
-
191
- `text-delta` | `thinking-delta` | `tool-call` | `tool-result` | `done` | `error`
192
-
193
- Primitives (`ChatWelcome`, `ChatUserMessage`, `ChatAgentMessage`, `ChatThinking`, `ChatToolCall`, `ChatInput`, `ChatError`, `ChatMarkdown`) stay exported for custom layouts.
194
-
195
- # Markdown
196
-
197
- `MarkdownViewer` renders markdown for reading: headings, lists, tables, code, and mermaid. Agent replies use the same view.
198
-
199
- `MarkdownEditor` edits markdown in preview, source, or diff. Pass `original` to enable the diff view. `diffLayout` is side by side by default. `readOnly` locks the editor and hides the mode switcher.
200
-
201
- ```tsx
202
- import { MarkdownEditor, MarkdownViewer } from "devnonla-ui";
203
-
204
- <MarkdownViewer value={article} />
205
- <MarkdownEditor value={text} original={previous} onChange={setText} />
206
- ```
207
-
208
- ## Live React in markdown
209
-
210
- A `live-react` fence exports a default component and renders it above its source. It is off unless you opt in.
211
-
212
- - **Markdown from users or agents:** pass `sandboxSrc`. The fence runs in an iframe with `sandbox="allow-scripts"` and no `allow-same-origin`, so it cannot reach the page's cookies, storage, or DOM. `sandboxSrc` is a page you host on its own origin that calls `mountReactCodeRunner`; its `modules` are the only imports markdown gets.
213
- - **Markdown you wrote:** pass `trustedModules`. The fence runs in your page with full access. Never use it for content someone else can write.
214
-
215
- ```tsx
216
- // sandbox page
217
- import * as ui from "devnonla-ui";
218
- import { mountReactCodeRunner } from "devnonla-ui";
219
-
220
- mountReactCodeRunner(document.getElementById("root")!, { "devnonla-ui": ui });
221
-
222
- // app
223
- <MarkdownViewer value={article} sandboxSrc="https://sandbox.example.com/runner.html" />
224
- ```
225
-
226
- Outside markdown, use the pieces directly. `ReactCodeSandbox` takes `code` and `src` and renders the same framed result with a Code tab. `ReactCode` is the in-page version for source you wrote. `ReactCodeFrame` is the header and tab box, if you want to wrap your own result.
227
-
228
- ```tsx
229
- <ReactCodeSandbox code={source} src="https://sandbox.example.com/runner.html" />
230
- ```
231
-
232
- Serve the runner page with `Content-Security-Policy: connect-src 'none'` and `Access-Control-Allow-Origin: *` on its assets, since a sandboxed frame loads them cross-origin.
233
-
234
- # Typography
235
-
236
- `Text`, `Title`, `Paragraph`, and `Link` share one decoration set: `type` (`secondary` | `success` | `warning` | `danger`), `disabled`, `mark`, `code`, `keyboard`, `underline`, `delete`, `strong`, and `italic`. `Title` `level` is 1–5. `Typography` groups the same pieces.
237
-
238
- ```tsx
239
- import { Link, Paragraph, Text, Title } from "devnonla-ui";
240
-
241
- <Title level={2}>Agents</Title>
242
- <Paragraph>Run them on your machine.</Paragraph>
243
- <Text type="secondary">Updated today</Text>
244
- <Link href="https://nonlaagents.com">nonlaagents.com</Link>
245
- ```
246
-
247
- # Logo
248
-
249
- `Logo` is the mark and the wordmark “Nonla Agents”. The wordmark is K2D regular, drawn as SVG outlines. `variant` is `icon`, `text`, or `full` (default). `size` is the icon height in px (default 32). `color` recolors the mark and the wordmark; the eyes and the smile stay.
250
-
251
- ```tsx
252
- import { Logo } from "devnonla-ui";
253
-
254
- <Logo />
255
- <Logo variant="icon" size={24} />
256
- <Logo color="#181818" />
257
- ```
258
-
259
- # Icons
260
-
261
- `SolarIcon` renders vendored Solar icons (`@iconify-json/solar`) as inline SVG, so they follow `currentColor`. Default style is `linear`. A legacy Fluent Color id such as `settings-24` still resolves to the Solar equivalent.
262
-
263
- ```tsx
264
- <SolarIcon name="settings-linear" size={16} />
265
- ```
26
+ Install, theme, and each control are in the [docs](https://devnonla.github.io/devnonla-ui/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devnonla-ui",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "description": "NonlaUI — React controls for Nonla Agents",
6
6
  "author": "devlangla <devlangla0x01@gmail.com>",
@@ -9,7 +9,7 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/devnonla/devnonla-ui.git"
11
11
  },
12
- "homepage": "https://github.com/devnonla/devnonla-ui",
12
+ "homepage": "https://devnonla.github.io/devnonla-ui/",
13
13
  "bugs": {
14
14
  "url": "https://github.com/devnonla/devnonla-ui/issues"
15
15
  },
package/src/app/App.tsx CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2
- import { type ReactNode, useLayoutEffect, useMemo, useState } from "react";
2
+ import { type ReactNode, useMemo } from "react";
3
3
  import { type ControlSize, ControlSizeContext, normalizeSize } from "../lib/sizes";
4
4
  import { MessageHolder, message } from "../message/message";
5
5
  import { ConfirmHolder, Modal } from "../modal/Modal";
6
- import { applyNonlaTheme, initColorMode, type NonlaThemeConfig } from "../theme";
6
+ import { initColorMode } from "../theme";
7
7
  import { AppContext, type NonlaAppConfig, useAppConfig, usePopupContainer, useToken } from "./context";
8
8
 
9
9
  export type { NonlaAppConfig };
@@ -14,30 +14,14 @@ export type AppProps = {
14
14
  getPopupContainer?: () => HTMLElement;
15
15
  /** Default control size (`componentSize`). Per-control `size` still wins. */
16
16
  componentSize?: ControlSize;
17
- /** Override `--nonla-*` knobs on `:root` (portals inherit). Prefer CSS in the host when possible. */
18
- theme?: NonlaThemeConfig;
19
17
  };
20
18
 
21
19
  /** Root host for NonlaUI — ConfigProvider + message/modal holders. Mount once near app root. */
22
- export function App({ children, getPopupContainer, componentSize, theme }: AppProps) {
20
+ export function App({ children, getPopupContainer, componentSize }: AppProps) {
23
21
  // Before children paint, so a sandbox iframe can open on the saved mode instead of flashing the default.
24
22
  initColorMode();
25
- const [themeRev, setThemeRev] = useState(0);
26
23
  const size = componentSize ? normalizeSize(componentSize) : undefined;
27
- const value = useMemo<NonlaAppConfig>(
28
- () => ({ getPopupContainer, componentSize: size, themeRev }),
29
- [getPopupContainer, size, themeRev],
30
- );
31
-
32
- useLayoutEffect(() => {
33
- if (!theme) return;
34
- const restore = applyNonlaTheme(theme);
35
- setThemeRev((n) => n + 1);
36
- return () => {
37
- restore();
38
- setThemeRev((n) => n + 1);
39
- };
40
- }, [theme]);
24
+ const value = useMemo<NonlaAppConfig>(() => ({ getPopupContainer, componentSize: size }), [getPopupContainer, size]);
41
25
 
42
26
  return (
43
27
  <AppContext.Provider value={value}>
@@ -5,11 +5,9 @@ import { getColorMode, getDesignToken, type NonlaTokenSnapshot, subscribeColorMo
5
5
  export type NonlaAppConfig = {
6
6
  getPopupContainer?: () => HTMLElement;
7
7
  componentSize?: CanonicalSize;
8
- /** Bumps when `<App theme>` applies knobs — `useToken` re-reads CSS. */
9
- themeRev: number;
10
8
  };
11
9
 
12
- export const AppContext = createContext<NonlaAppConfig>({ themeRev: 0 });
10
+ export const AppContext = createContext<NonlaAppConfig>({});
13
11
 
14
12
  export function useAppConfig() {
15
13
  return useContext(AppContext);
@@ -21,14 +19,12 @@ export function usePopupContainer(override?: () => HTMLElement) {
21
19
  return () => (override ?? getPopupContainer)?.() ?? document.body;
22
20
  }
23
21
 
24
- /** Computed seed knobs under the current App theme (`useToken`). */
22
+ /** Computed `--nonla-*` knobs (`useToken`). Re-reads when the color mode changes. */
25
23
  export function useToken(): { token: NonlaTokenSnapshot } {
26
- const { themeRev } = useAppConfig();
27
24
  const mode = useSyncExternalStore(subscribeColorMode, getColorMode, () => "dark" as const);
28
25
  const token = useMemo(() => {
29
- void themeRev;
30
26
  void mode;
31
27
  return getDesignToken();
32
- }, [themeRev, mode]);
28
+ }, [mode]);
33
29
  return { token };
34
30
  }
@@ -7,6 +7,9 @@ export type AgentAvatarMotion = "still" | "idle";
7
7
  /** Fixed facing. The head turns that way and the eyes follow. */
8
8
  export type AgentAvatarLook = "forward" | "left" | "right" | "up" | "down" | "up-left" | "up-right" | "down-left" | "down-right";
9
9
 
10
+ /** Pupil color. Omitted picks black, or white when the face is dark. */
11
+ export type AgentAvatarEyeColor = "black" | "white";
12
+
10
13
  export const AGENT_AVATAR_PARTS = {
11
14
  shape: ["circle", "square", "triangle", "diamond", "hex", "gem", "pill", "arch", "cloud", "blob", "drop", "shield"],
12
15
  color: ["#6E56F0", "#1C1C1C", "#F0B429", "#3DCFC0", "#F47820", "#3B82F6", "#F2549B", "#A56B3C"],
@@ -14,10 +17,11 @@ export const AGENT_AVATAR_PARTS = {
14
17
 
15
18
  type Part<K extends keyof typeof AGENT_AVATAR_PARTS> = (typeof AGENT_AVATAR_PARTS)[K][number];
16
19
 
17
- /** A character is one shape plus the two eyes. */
20
+ /** A character is one shape, a color, and two eyes. */
18
21
  export type AgentAvatarConfig = {
19
22
  shape: Part<"shape">;
20
23
  color: string;
24
+ eyeColor?: AgentAvatarEyeColor;
21
25
  };
22
26
 
23
27
  export type AgentAvatarProps = {
@@ -51,6 +55,7 @@ function resolveConfig(config?: Partial<AgentAvatarConfig>): AgentAvatarConfig {
51
55
  return {
52
56
  shape: config?.shape ?? DEFAULT_CONFIG.shape,
53
57
  color: config?.color ?? DEFAULT_CONFIG.color,
58
+ eyeColor: config?.eyeColor,
54
59
  };
55
60
  }
56
61
 
@@ -71,6 +76,12 @@ function eyeInk(color: string) {
71
76
  return luma < 0.28 ? EYE_ON_DARK : EYE;
72
77
  }
73
78
 
79
+ function eyeFill(color: string, eyeColor?: AgentAvatarEyeColor) {
80
+ if (eyeColor === "white") return EYE_ON_DARK;
81
+ if (eyeColor === "black") return EYE;
82
+ return eyeInk(color);
83
+ }
84
+
74
85
  /** Head shift, then how much further the eyes travel, in viewBox units. */
75
86
  const LOOK: Record<AgentAvatarLook, { head: [number, number]; eyes: [number, number] }> = {
76
87
  forward: { head: [0, 0], eyes: [0, 0] },
@@ -112,21 +123,21 @@ function Eyes({ cx, cy, w = 5.2, h = 12 }: { cx: number; cy: number; w?: number;
112
123
  );
113
124
  }
114
125
 
115
- function Shape({ shape, color }: AgentAvatarConfig) {
126
+ function Shape({ shape, color, eyeColor }: AgentAvatarConfig) {
116
127
  const paint = useContext(PaintContext);
117
128
  const shadow = useContext(ShadowContext);
118
129
  const soft = { fill: paint, stroke: paint, strokeLinejoin: "round" as const };
119
- const face = (mark: ReactNode, eyes: ReactNode, shiftY = 0) => (
130
+ const face = (mark: ReactNode, pupils: ReactNode, shiftY = 0) => (
120
131
  <g transform={shiftY ? `translate(0 ${shiftY})` : undefined}>
121
132
  <g filter={shadow}>{mark}</g>
122
- {eyes}
133
+ {pupils}
123
134
  </g>
124
135
  );
125
136
  const body: Record<AgentAvatarConfig["shape"], ReactNode> = {
126
137
  circle: face(<circle cx="32" cy="32" r="22" fill={paint} />, <Eyes cx={32} cy={30} />),
127
138
  square: face(<rect x="9" y="9" width="46" height="46" rx="16" fill={paint} />, <Eyes cx={32} cy={30} />),
128
139
  triangle: face(<path d="M32 16 L50 50 H14 Z" strokeWidth="14" {...soft} />, <Eyes cx={32} cy={38} />, -1),
129
- diamond: face(<path d="M32 10 L54 32 L32 54 L10 32 Z" strokeWidth="16" {...soft} />, <Eyes cx={32} cy={30} />),
140
+ diamond: face(<path d="M32 14 L50 32 L32 50 L14 32 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
130
141
  hex: face(<path d="M32 12 L49 22 L49 42 L32 52 L15 42 L15 22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
131
142
  gem: face(<path d="M22 12 H42 L52 22 V42 L42 52 H22 L12 42 V22 Z" strokeWidth="8" {...soft} />, <Eyes cx={32} cy={30} />),
132
143
  pill: face(<rect x="6" y="18" width="52" height="28" rx="14" fill={paint} />, <Eyes cx={32} cy={30} />),
@@ -152,7 +163,7 @@ function Shape({ shape, color }: AgentAvatarConfig) {
152
163
  -6,
153
164
  ),
154
165
  };
155
- return <InkContext.Provider value={eyeInk(color)}>{body[shape]}</InkContext.Provider>;
166
+ return <InkContext.Provider value={eyeFill(color, eyeColor)}>{body[shape]}</InkContext.Provider>;
156
167
  }
157
168
 
158
169
  export function AgentAvatar({ config, size = 64, motion = "still", look = "forward", className, label = "Agent" }: AgentAvatarProps) {
package/src/card/Card.tsx CHANGED
@@ -1,9 +1,6 @@
1
1
  import type { HTMLAttributes, ReactNode } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
 
4
- /** Hairline used by the dashboard card ring and row rules (`--nonla-hairline`). */
5
- const HAIRLINE = "var(--nonla-hairline)";
6
-
7
4
  export type CardProps = HTMLAttributes<HTMLElement> & {
8
5
  /** Section label above the surface. */
9
6
  title?: ReactNode;
@@ -29,7 +26,7 @@ function CardRoot({ title, caption, className, children, ...rest }: CardProps) {
29
26
  return (
30
27
  <section className={cn("flex flex-col gap-[9px]", className)} {...rest}>
31
28
  {title != null && title !== "" ? <div className="px-2 text-sm leading-4 text-foreground">{title}</div> : null}
32
- <div className="flex flex-col self-stretch rounded-xl bg-card" style={{ boxShadow: `0 0 0 1px ${HAIRLINE}` }}>
29
+ <div className="flex flex-col self-stretch rounded-xl bg-card" style={{ boxShadow: "var(--nonla-card-shadow)" }}>
33
30
  {children}
34
31
  </div>
35
32
  {caption != null && caption !== "" ? <div className="px-3 text-xs leading-4 text-tertiary-foreground">{caption}</div> : null}
@@ -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-transparent", 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-200 mx-auto min-w-0 w-full ${messages.length === 0 ? "flex flex-1 flex-col pb-16" : "pt-4 pb-20"}`}>
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" : "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} />
@@ -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-transparent", 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-200 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" : "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} />
@@ -5,7 +5,6 @@ import type { AgentMessage } from "./common/types";
5
5
  import { formatToolName } from "./common/utils";
6
6
  import { ChatAgentMessage } from "./message-ui/ChatAgentMessage";
7
7
  import { ChatError } from "./message-ui/ChatError";
8
- import { ChatMarkdown } from "./message-ui/ChatMarkdown";
9
8
  import { ChatThinking } from "./message-ui/ChatThinking";
10
9
  import { ChatUserMessage } from "./message-ui/ChatUserMessage";
11
10
  import { BackgroundTaskToolUI } from "./tool-ui/BackgroundTaskToolUI";
@@ -78,9 +77,7 @@ export function MessageRow({ msg, generating, toolUis }: { msg: AgentMessage; ge
78
77
  const thinking = msg.meta?.thinking;
79
78
  const thinkingDuration = msg.meta?.thinkingDuration;
80
79
  return (
81
- <ChatAgentMessage thinking={thinking} thinkingDuration={thinkingDuration ?? 0} thinkingStreaming={thinking != null && thinkingDuration == null}>
82
- {msg.content ? <ChatMarkdown content={msg.content} streaming={!!msg.streaming} /> : null}
83
- </ChatAgentMessage>
80
+ <ChatAgentMessage content={msg.content} streaming={!!msg.streaming} thinking={thinking} thinkingDuration={thinkingDuration ?? 0} thinkingStreaming={thinking != null && thinkingDuration == null} />
84
81
  );
85
82
  }
86
83
 
@@ -1,11 +1,13 @@
1
1
  import type { ReactNode } from "react";
2
2
  import { cn } from "../../lib/cn";
3
+ import { ChatMarkdown } from "./ChatMarkdown";
3
4
  import { ChatThinking } from "./ChatThinking";
4
5
 
5
6
  export type ChatAgentMessageProps = {
6
- /** Plain text fallback when `children` is omitted. */
7
+ /** Markdown body. Rendered with `MarkdownViewer` `variant="chat"`. */
7
8
  content?: string;
8
- /** Prefer passing rendered markdown / rich content as children. */
9
+ streaming?: boolean;
10
+ /** Extra row content. Replaces `content` when set. */
9
11
  children?: ReactNode;
10
12
  thinking?: string;
11
13
  thinkingDuration?: number;
@@ -13,8 +15,8 @@ export type ChatAgentMessageProps = {
13
15
  className?: string;
14
16
  };
15
17
 
16
- export function ChatAgentMessage({ content, children, thinking, thinkingDuration, thinkingStreaming, className }: ChatAgentMessageProps) {
17
- const body = children ?? (content ? <p className="m-0 whitespace-pre-wrap wrap-break-word text-(length:--chat-body-size) leading-(--chat-body-leading) text-(--nonla-ink)">{content}</p> : null);
18
+ export function ChatAgentMessage({ content, streaming = false, children, thinking, thinkingDuration, thinkingStreaming, className }: ChatAgentMessageProps) {
19
+ const body = children ?? (content ? <ChatMarkdown content={content} streaming={streaming} /> : null);
18
20
 
19
21
  return (
20
22
  <div className={cn("nonla-chat-agent mt-1", className)}>
@@ -5,7 +5,7 @@ export type ChatMarkdownProps = {
5
5
  streaming?: boolean;
6
6
  };
7
7
 
8
- /** Agent markdown. Uses MarkdownViewer as-is, with no extra prose styles. */
8
+ /** Agent markdown. `MarkdownViewer` on the `chat` scale. */
9
9
  export function ChatMarkdown({ content, streaming = false }: ChatMarkdownProps) {
10
- return <MarkdownViewer value={content} streaming={streaming} />;
10
+ return <MarkdownViewer value={content} streaming={streaming} variant="chat" />;
11
11
  }
@@ -138,7 +138,7 @@ export function CallAgentToolUI({ msg, assistantLabel = "Assistant", assistantCo
138
138
  <div className="flex flex-col gap-3 px-3 py-3">
139
139
  {composing || hasRequest ? (
140
140
  <AgentTurn name={assistantLabel} align="end">
141
- <div className="rounded-2xl rounded-tr-sm border border-solid border-(--nonla-input) bg-well-strong px-3 py-2 text-left">
141
+ <div className="nonla-chat-user rounded-2xl rounded-tr-sm border border-solid border-(--nonla-input) bg-well-strong px-3 py-2 text-left">
142
142
  {composing ? <TypingDots /> : <p className="m-0 text-[14px] leading-[1.55] whitespace-pre-wrap text-foreground">{requestMessage}</p>}
143
143
  </div>
144
144
  </AgentTurn>
@@ -45,7 +45,7 @@ export function CodeBlock({ code, language, title, lineNumbers = false, wordWrap
45
45
  return (
46
46
  <CodeBlockContext.Provider value={{ code }}>
47
47
  <div className={cn("nonla-codeblock relative flex min-w-0 w-full flex-col overflow-clip rounded-xl border border-border bg-card text-sm text-foreground", className)} data-language={language} {...props}>
48
- <div className="flex h-8 items-center justify-between gap-2 pl-3 pr-1 text-xs text-muted-foreground">
48
+ <div className="nonla-codeblock-header flex h-8 items-center justify-between gap-2 pl-3 pr-1 text-xs text-muted-foreground">
49
49
  <div className="flex min-w-0 items-center gap-2">
50
50
  {label ? <span className="truncate font-medium">{label}</span> : null}
51
51
  </div>
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ export type InputRef = HTMLInputElement;
15
15
 
16
16
  export type { AlertProps, AlertType } from "./alert/Alert";
17
17
  export { Alert } from "./alert/Alert";
18
- export type { AgentAvatarConfig, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
18
+ export type { AgentAvatarConfig, AgentAvatarEyeColor, AgentAvatarLook, AgentAvatarMotion, AgentAvatarProps } from "./avatar/AgentAvatar";
19
19
  export { AGENT_AVATAR_PARTS, AgentAvatar } from "./avatar/AgentAvatar";
20
20
  export type { CalendarProps } from "./calendar/Calendar";
21
21
  export { Calendar } from "./calendar/Calendar";
@@ -163,7 +163,7 @@ export type { LogoProps, LogoVariant } from "./logo/Logo";
163
163
  export { Logo } from "./logo/Logo";
164
164
  export type { MarkdownDiffLayout, MarkdownEditorMode, MarkdownEditorProps } from "./markdown-editor/MarkdownEditor";
165
165
  export { MarkdownEditor } from "./markdown-editor/MarkdownEditor";
166
- export type { MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
166
+ export type { MarkdownVariant, MarkdownViewerProps } from "./markdown-editor/MarkdownViewer";
167
167
  export { MarkdownViewer } from "./markdown-editor/MarkdownViewer";
168
168
  export type { MermaidBlockProps } from "./markdown-editor/MermaidBlock";
169
169
  export { MermaidBlock } from "./markdown-editor/MermaidBlock";
@@ -213,10 +213,12 @@ export type {
213
213
  TableRowSelection,
214
214
  } from "./table/Table";
215
215
  export { Table } from "./table/Table";
216
+ export type { TabsItem, TabsProps } from "./tabs/Tabs";
217
+ export { Tabs } from "./tabs/Tabs";
216
218
  export type { TagProps, TagVariant } from "./tag/Tag";
217
219
  export { Tag } from "./tag/Tag";
218
- export type { NonlaColorMode, NonlaColorPreference, NonlaThemeColorName, NonlaThemeColors, NonlaThemeConfig, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
219
- export { applyNonlaTheme, getColorMode, getColorPreference, getDesignToken, initColorMode, NONLA_COLOR_MODE_KEY, NONLA_THEME_KEYS, NONLA_THEME_KNOBS, setColorMode, setColorPreference } from "./theme";
220
+ export type { NonlaColorMode, NonlaColorPreference, NonlaThemeKnob, NonlaThemeKnobName, NonlaTokenSnapshot } from "./theme";
221
+ export { getColorMode, getColorPreference, getDesignToken, initColorMode, NONLA_COLOR_MODE_KEY, NONLA_THEME_KEYS, NONLA_THEME_KNOBS, setColorMode, setColorPreference } from "./theme";
220
222
  export type { ThemeSwitcherProps } from "./theme-switcher/ThemeSwitcher";
221
223
  export { ThemeSwitcher, useColorPreference } from "./theme-switcher/ThemeSwitcher";
222
224
  export type { ThemeToggleProps } from "./theme-toggle/ThemeToggle";
@@ -2,7 +2,7 @@ import { type MouseEvent, useLayoutEffect, useRef } from "react";
2
2
  import { cn } from "../lib/cn";
3
3
  import { OverlayScroll } from "../scroll/OverlayScroll";
4
4
  import { type MarkdownDoc, readInlineEdit, writeInlineEdit } from "./blocks";
5
- import { BlockBody, headingClass, ListItem, spaceBefore } from "./MarkdownViewer";
5
+ import { BlockBody, headingClass, ListItem, markdownVariantStyle, spaceBefore } from "./MarkdownViewer";
6
6
 
7
7
  function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur, onEnter }: { value: string; mono?: boolean; className?: string; caret?: "start" | "end"; onChange: (value: string) => void; onBlur: () => void; onEnter?: (before: string, after: string) => void }) {
8
8
  const ref = useRef<HTMLTextAreaElement>(null);
@@ -57,7 +57,7 @@ function BlockEditor({ value, mono, className, caret = "end", onChange, onBlur,
57
57
  });
58
58
  }}
59
59
  className={cn(
60
- "block w-full resize-none overflow-hidden border-0 bg-transparent p-0 text-[14px] leading-[22px] text-foreground shadow-none outline-none ring-0 placeholder:text-placeholder focus:outline-none focus:ring-0",
60
+ "block w-full resize-none overflow-hidden border-0 bg-transparent p-0 text-(length:--md-body-size,16px) leading-(--md-body-leading,24px) text-(--md-ink) shadow-none outline-none ring-0 placeholder:text-placeholder focus:outline-none focus:ring-0",
61
61
  mono && "font-mono text-[13px] leading-5",
62
62
  className,
63
63
  )}
@@ -88,7 +88,7 @@ export type MarkdownPreviewProps = {
88
88
  export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Write markdown…", onStartEdit, onEditMouseDown, onChangeBody, onBlurBlock, onEnterList, caret = "end", onAppend }: MarkdownPreviewProps) {
89
89
  return (
90
90
  <OverlayScroll className="h-full bg-card">
91
- <div className="mx-auto flex w-full max-w-3xl flex-col px-8 py-6">
91
+ <div className="mx-auto flex w-full max-w-3xl flex-col px-8 py-6" style={markdownVariantStyle("docs")}>
92
92
  {doc.blocks.map((block, index) => {
93
93
  const editing = editingIndex === index;
94
94
  const locked = block.kind === "mermaid" || readOnly;
@@ -29,13 +29,13 @@ export function MarkdownTable({ children }: { children: ReactNode }) {
29
29
  }, []);
30
30
 
31
31
  return (
32
- <div className="relative my-4 max-w-full overflow-hidden rounded-xl border border-border bg-card group">
32
+ <div className="relative my-(--md-table-my,16px) max-w-full overflow-hidden rounded-xl border border-border bg-card group">
33
33
  <ButtonCopy getText={getText} label="Copy as Markdown" className="absolute top-1 right-1 z-10 opacity-0 group-hover:opacity-100" />
34
34
 
35
35
  <div className="overflow-x-auto">
36
36
  <table
37
37
  ref={tableRef}
38
- className="w-max min-w-full border-separate border-spacing-0 text-[14px] [&_th]:max-w-[360px] [&_td]:max-w-[360px] [&_th]:whitespace-normal [&_td]:whitespace-normal [&_th]:wrap-normal [&_td]:wrap-normal [&_th]:bg-(--nonla-table-head) [&_th]:text-foreground [&_th]:font-semibold [&_th]:px-2.5 [&_th]:py-1.5 [&_th]:text-left [&_th]:align-top [&_th]:border-r [&_th]:border-b [&_th]:border-border [&_th:last-child]:border-r-0 [&_td]:px-2.5 [&_td]:py-1.5 [&_td]:align-top [&_td]:text-foreground [&_td]:bg-card [&_td]:border-r [&_td]:border-b [&_td]:border-border [&_td:last-child]:border-r-0 [&_tbody_tr:last-child_td]:border-b-0"
38
+ className="w-max min-w-full border-separate border-spacing-0 text-(length:--md-table-size,15px) [&_th]:max-w-[360px] [&_td]:max-w-[360px] [&_th]:whitespace-normal [&_td]:whitespace-normal [&_th]:wrap-normal [&_td]:wrap-normal [&_th]:bg-(--nonla-table-head) [&_th]:font-semibold [&_th]:px-2.5 [&_th]:py-1.5 [&_th]:text-left [&_th]:align-top [&_th]:border-r [&_th]:border-b [&_th]:border-border [&_th:last-child]:border-r-0 [&_td]:px-2.5 [&_td]:py-1.5 [&_td]:align-top [&_td]:bg-card [&_td]:border-r [&_td]:border-b [&_td]:border-border [&_td:last-child]:border-r-0 [&_tbody_tr:last-child_td]:border-b-0"
39
39
  >
40
40
  {children}
41
41
  </table>