devnonla-ui 0.12.0 → 0.14.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.
Files changed (72) hide show
  1. package/README.md +6 -245
  2. package/package.json +2 -2
  3. package/src/app/App.tsx +6 -22
  4. package/src/app/context.ts +2 -17
  5. package/src/avatar/AgentAvatar.tsx +17 -6
  6. package/src/avatar/avatar.css +107 -0
  7. package/src/button/Button.tsx +4 -4
  8. package/src/button/ButtonCopy.tsx +1 -1
  9. package/src/calendar/Calendar.tsx +1 -1
  10. package/src/card/Card.tsx +2 -5
  11. package/src/chat/AgentChatbox.tsx +1 -1
  12. package/src/chat/AgentPanel.tsx +1 -1
  13. package/src/chat/chatMessageList.tsx +1 -4
  14. package/src/chat/message-ui/ChatAgentMessage.tsx +6 -4
  15. package/src/chat/message-ui/ChatError.tsx +1 -1
  16. package/src/chat/message-ui/ChatInput.tsx +5 -4
  17. package/src/chat/message-ui/ChatMarkdown.tsx +2 -2
  18. package/src/chat/message-ui/ChatUserMessage.tsx +3 -3
  19. package/src/chat/tool-ui/BackgroundTasksBar.tsx +3 -3
  20. package/src/chat/tool-ui/CallAgentToolUI.tsx +2 -2
  21. package/src/chat/tool-ui/ChatToolCall.tsx +3 -3
  22. package/src/chat/tool-ui/ReadSkillToolUI.tsx +2 -2
  23. package/src/chat/tool-ui/RunJsToolUI.tsx +1 -1
  24. package/src/chat/tool-ui/ToolUiBadge.tsx +1 -1
  25. package/src/chat/tool-ui/WebFetchToolUI.tsx +1 -1
  26. package/src/checkbox/Checkbox.tsx +2 -2
  27. package/src/codeblock/CodeBlock.tsx +2 -2
  28. package/src/colorpicker/ColorPicker.tsx +10 -8
  29. package/src/datepicker/DatePicker.tsx +3 -3
  30. package/src/desktop/DesktopHeader.tsx +2 -2
  31. package/src/desktop/DesktopStage.tsx +1 -1
  32. package/src/desktop/DesktopWindow.tsx +3 -3
  33. package/src/desktop/MeadowDesktop.tsx +2 -2
  34. package/src/drawer/Drawer.tsx +6 -2
  35. package/src/dropdown/menuClasses.ts +1 -1
  36. package/src/empty/Empty.tsx +1 -1
  37. package/src/form/variants/FieldRadio.tsx +1 -1
  38. package/src/form/variants/FieldRepeaterItem.tsx +1 -1
  39. package/src/index.ts +7 -5
  40. package/src/input/EditableInput.tsx +3 -2
  41. package/src/input/Input.tsx +15 -7
  42. package/src/lib/sizes.ts +6 -6
  43. package/src/lib/surface.ts +14 -4
  44. package/src/markdown-editor/MarkdownDiff.tsx +4 -4
  45. package/src/markdown-editor/MarkdownPreview.tsx +6 -6
  46. package/src/markdown-editor/MarkdownSource.tsx +1 -1
  47. package/src/markdown-editor/MarkdownTable.tsx +2 -2
  48. package/src/markdown-editor/MarkdownViewer.tsx +54 -56
  49. package/src/markdown-editor/MermaidBlock.tsx +2 -2
  50. package/src/markdown-editor/ReactCode.tsx +6 -7
  51. package/src/markdown-editor/ReactCodeFrame.tsx +45 -15
  52. package/src/markdown-editor/ReactCodeSandbox.tsx +1 -1
  53. package/src/markdown-editor/markdownScale.ts +149 -0
  54. package/src/menu/Menu.tsx +1 -1
  55. package/src/message/message.tsx +18 -8
  56. package/src/modal/Modal.tsx +13 -7
  57. package/src/pagination/Pagination.tsx +3 -3
  58. package/src/popover/Popover.tsx +1 -1
  59. package/src/scroll/OverlayScroll.tsx +2 -2
  60. package/src/segmented/Segmented.tsx +1 -1
  61. package/src/select/Select.tsx +4 -4
  62. package/src/sidebar/Sidebar.tsx +35 -32
  63. package/src/skeleton/Skeleton.tsx +4 -4
  64. package/src/spin/Spin.tsx +14 -2
  65. package/src/splitter/Splitter.tsx +1 -1
  66. package/src/styles.css +171 -813
  67. package/src/table/Table.tsx +12 -12
  68. package/src/tabs/Tabs.tsx +261 -0
  69. package/src/tag/Tag.tsx +16 -16
  70. package/src/theme.ts +53 -232
  71. package/src/timepicker/TimePicker.tsx +2 -2
  72. package/src/typography/Typography.tsx +41 -35
@@ -15,11 +15,11 @@ export type InputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "size" | "p
15
15
  onPressEnter?: (e: KeyboardEvent<HTMLInputElement>) => void;
16
16
  };
17
17
 
18
- const fieldBase = cn("w-full", controlFieldSurface, "placeholder:text-placeholder focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45", controlFieldFocusBorder);
18
+ const fieldBase = cn("w-full", controlFieldSurface, "placeholder:text-quaternary-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-45", controlFieldFocusBorder);
19
19
 
20
20
  function variantClass(variant: InputProps["variant"]) {
21
21
  if (variant === "borderless") return "border-transparent bg-transparent hover:bg-transparent shadow-none focus:border-transparent focus:bg-transparent focus-within:bg-transparent";
22
- if (variant === "filled") return "border-transparent bg-muted focus:border-transparent focus:bg-[var(--control-bg-hover)]";
22
+ if (variant === "filled") return "border-transparent bg-muted focus:border-transparent focus:bg-muted-strong";
23
23
  return "";
24
24
  }
25
25
 
@@ -162,12 +162,15 @@ function roundTo(n: number, precision?: number) {
162
162
 
163
163
  function HandlerChevron({ dir, size }: { dir: "up" | "down"; size: number }) {
164
164
  return (
165
- <svg width={size} height={size} viewBox="0 0 10 10" fill="none" aria-hidden className="opacity-70">
165
+ <svg width={size} height={size} viewBox="0 0 10 10" fill="none" aria-hidden>
166
166
  {dir === "up" ? <path d="M2.5 6.25L5 3.75L7.5 6.25" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" /> : <path d="M2.5 3.75L5 6.25L7.5 3.75" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" />}
167
167
  </svg>
168
168
  );
169
169
  }
170
170
 
171
+ /** Stepper reveal and press. Same ease-out and duration as the field focus. */
172
+ const handlerEase = "duration-[var(--nonla-dur-fast,150ms)] ease-[var(--nonla-ease-out,cubic-bezier(0.16,1,0.3,1))] motion-reduce:transition-none";
173
+
171
174
  const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function InputNumber({ value, defaultValue, onChange, min, max, step = 1, controls = true, precision, parser, formatter, disabled, size, status, className, style, placeholder, onBlur, onFocus, onKeyDown, ...rest }, ref) {
172
175
  const controlled = value !== undefined;
173
176
  const [inner, setInner] = useState<number | null>(defaultValue ?? null);
@@ -275,7 +278,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
275
278
  }}
276
279
  onKeyDown={handleKeyDown}
277
280
  className={cn(
278
- "min-w-0 flex-1 border-0 bg-transparent text-foreground placeholder:text-placeholder outline-none",
281
+ "min-w-0 flex-1 border-0 bg-transparent text-foreground placeholder:text-quaternary-foreground outline-none",
279
282
  "disabled:cursor-not-allowed",
280
283
  // Kill native number chrome if type ever switches
281
284
  "[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
@@ -291,7 +294,12 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
291
294
 
292
295
  {controls && !disabled ? (
293
296
  <div
294
- className={cn("absolute top-0 right-0 bottom-0 flex flex-col overflow-hidden border-l border-border/80", "opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100")}
297
+ className={cn(
298
+ "pointer-events-none absolute top-0 right-0 bottom-0 flex flex-col overflow-hidden border-l border-input opacity-0",
299
+ "transition-opacity",
300
+ handlerEase,
301
+ "group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100",
302
+ )}
295
303
  style={{ width: handlerW, borderTopRightRadius: `calc(${controlRadiusVar(size)} - 1px)`, borderBottomRightRadius: `calc(${controlRadiusVar(size)} - 1px)` }}
296
304
  >
297
305
  <button
@@ -299,7 +307,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
299
307
  tabIndex={-1}
300
308
  aria-label="Increase"
301
309
  disabled={atMax}
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")}
310
+ className={cn("flex flex-1 items-center justify-center border-b border-input text-tertiary-foreground", "transition-colors", handlerEase, "hover:bg-ink-hover hover:text-foreground active:bg-ink-active active:duration-75", "disabled:pointer-events-none disabled:opacity-30")}
303
311
  onMouseDown={(e) => e.preventDefault()}
304
312
  onClick={() => stepBy(1)}
305
313
  >
@@ -310,7 +318,7 @@ const InputNumber = forwardRef<HTMLInputElement, InputNumberProps>(function Inpu
310
318
  tabIndex={-1}
311
319
  aria-label="Decrease"
312
320
  disabled={atMin}
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")}
321
+ className={cn("flex flex-1 items-center justify-center text-tertiary-foreground", "transition-colors", handlerEase, "hover:bg-ink-hover hover:text-foreground active:bg-ink-active active:duration-75", "disabled:pointer-events-none disabled:opacity-30")}
314
322
  onMouseDown={(e) => e.preventDefault()}
315
323
  onClick={() => stepBy(-1)}
316
324
  >
package/src/lib/sizes.ts CHANGED
@@ -83,10 +83,10 @@ export function controlRadiusVar(size: ControlSize | undefined): string {
83
83
  return "var(--nonla-radius)";
84
84
  }
85
85
 
86
- /** Soft status border — keep the same color on focus so brand focus does not override. */
86
+ /** Soft status border — keep the same color on focus so the ink focus stroke does not override. */
87
87
  export function controlStatusClass(status?: "error" | "warning"): string {
88
- if (status === "error") return "border-[color-mix(in_oklab,var(--destructive)_55%,transparent)] focus:border-destructive focus-within:border-destructive data-[state=open]:border-destructive";
89
- if (status === "warning") return "border-[color-mix(in_oklab,var(--warn)_55%,transparent)] focus:border-warn focus-within:border-warn data-[state=open]:border-warn";
88
+ if (status === "error") return "border-[color-mix(in_oklab,var(--destructive)_55%,transparent)] focus:border-destructive! focus-within:border-destructive! data-[state=open]:border-destructive!";
89
+ if (status === "warning") return "border-[color-mix(in_oklab,var(--warn)_55%,transparent)] focus:border-warn! focus-within:border-warn! data-[state=open]:border-warn!";
90
90
  return "";
91
91
  }
92
92
 
@@ -100,11 +100,11 @@ export const controlFieldTransition = "transition-[background-color,border-color
100
100
  export const controlFieldSurface = "border border-solid border-input bg-transparent text-foreground";
101
101
 
102
102
  /**
103
- * Focus fill is Cursor `--bg-tertiary` (ink at 8%).
104
- * Keyboard focus / open menu also strengthens the stroke to `--border-primary` (ink at 20%).
103
+ * Focus fill is the sidebar step. Focus stroke is `--nonla-input-focus`.
104
+ * Each theme sets those names to a concrete color. Any focus and an open menu use the stroke.
105
105
  */
106
106
  export const controlFieldFocusBorder =
107
- "focus:bg-input-fill focus-within:bg-input-fill data-[state=open]:bg-input-fill aria-expanded:bg-input-fill focus-visible:border-input-focus has-[:focus-visible]:border-input-focus data-[state=open]:border-input-focus aria-expanded:border-input-focus";
107
+ "focus:bg-sidebar focus-within:bg-sidebar data-[state=open]:bg-sidebar aria-expanded:bg-sidebar focus:border-input-focus focus-within:border-input-focus focus-visible:border-input-focus has-[:focus-visible]:border-input-focus data-[state=open]:border-input-focus aria-expanded:border-input-focus";
108
108
 
109
109
  /** Shared field chrome (Input / Select / DatePicker). */
110
110
  export function controlFieldStyle(size: ControlSize | undefined): CSSProperties {
@@ -1,9 +1,19 @@
1
1
  /** Solid panel — window, modal, popover, menu, drawer, toast. */
2
- export const glassSurfaceClass = "nonla-glass";
2
+ export const glassSurfaceClass =
3
+ "nonla-glass border border-solid border-border bg-card text-foreground shadow-(--nonla-shadow)";
3
4
 
4
5
  /** Floating overlay chrome (Popover / Dropdown / Select / pickers / Tooltip). */
5
- export const glassOverlayClass =
6
- "nonla-popup-layer z-[var(--nonla-z-popup,1050)] rounded-xl nonla-glass outline-none nonla-popper";
6
+ export const glassOverlayClass = [
7
+ glassSurfaceClass,
8
+ "nonla-popup-layer nonla-popper z-[var(--nonla-z-popup,1050)] rounded-xl outline-none will-change-[transform,opacity]",
9
+ "[transform-origin:var(--radix-popover-content-transform-origin,var(--radix-dropdown-menu-content-transform-origin,var(--radix-select-content-transform-origin,var(--radix-tooltip-content-transform-origin,center))))]",
10
+ "data-[state=open]:data-[side=top]:animate-[nonla-pop-in-top_var(--nonla-dur-fast)_var(--nonla-ease-out)]",
11
+ "data-[state=open]:data-[side=bottom]:animate-[nonla-pop-in-bottom_var(--nonla-dur-fast)_var(--nonla-ease-out)]",
12
+ "data-[state=open]:data-[side=left]:animate-[nonla-pop-in-left_var(--nonla-dur-fast)_var(--nonla-ease-out)]",
13
+ "data-[state=open]:data-[side=right]:animate-[nonla-pop-in-right_var(--nonla-dur-fast)_var(--nonla-ease-out)]",
14
+ "data-[state=open]:not-data-[side]:animate-[nonla-pop-in-bottom_var(--nonla-dur-fast)_var(--nonla-ease-out)]",
15
+ "data-[state=closed]:animate-[nonla-pop-out_100ms_var(--nonla-ease-in)]",
16
+ ].join(" ");
7
17
 
8
18
  /** Meadow menus — same panel as overlays. */
9
- export const meadowSurfaceClass = "rounded-xl nonla-glass";
19
+ export const meadowSurfaceClass = `rounded-xl ${glassSurfaceClass}`;
@@ -8,7 +8,7 @@ export type MarkdownDiffLayout = "inline" | "side-by-side";
8
8
  function rowBg(kind: DiffLine["kind"]): string {
9
9
  if (kind === "insert") return "bg-[color-mix(in_oklab,var(--success)_16%,var(--card))]";
10
10
  if (kind === "delete") return "bg-[color-mix(in_oklab,var(--destructive)_14%,var(--card))]";
11
- if (kind === "empty") return "bg-secondary/45";
11
+ if (kind === "empty") return "bg-muted/45";
12
12
  return "bg-card";
13
13
  }
14
14
 
@@ -65,7 +65,7 @@ function LineBody({ line }: { line: DiffLine }) {
65
65
 
66
66
  function FoldButton({ count, onClick, span }: { count: number; onClick: () => void; span?: boolean }) {
67
67
  return (
68
- <button type="button" className={cn("flex w-full items-center justify-center border-y border-border bg-secondary/70 py-0.5 text-xs text-link hover:bg-secondary", span && "col-span-2")} onClick={onClick}>
68
+ <button type="button" className={cn("flex w-full items-center justify-center border-y border-border bg-muted/70 py-0.5 text-xs text-link hover:bg-muted", span && "col-span-2")} onClick={onClick}>
69
69
  Show {count} unchanged {count === 1 ? "line" : "lines"}
70
70
  </button>
71
71
  );
@@ -166,8 +166,8 @@ function SplitDiff({ model, open, toggle, originalLabel, modifiedLabel }: { mode
166
166
  segment += 1;
167
167
  chunks.push(
168
168
  <div key={`seg-${id}`} className="flex w-full items-start">
169
- <div className="nonla-scroll-hover w-1/2 min-w-0 overflow-x-auto">{left}</div>
170
- <div className="nonla-scroll-hover w-1/2 min-w-0 overflow-x-auto border-l border-border">{right}</div>
169
+ <div className="w-1/2 min-w-0 overflow-x-auto [scrollbar-color:transparent_transparent] hover:[scrollbar-color:var(--nonla-scrollbar-thumb)_transparent] [&::-webkit-scrollbar-thumb]:bg-transparent hover:[&::-webkit-scrollbar-thumb]:bg-(--nonla-scrollbar-thumb) hover:[&::-webkit-scrollbar-thumb:hover]:bg-(--nonla-scrollbar-thumb-hover)">{left}</div>
170
+ <div className="w-1/2 min-w-0 overflow-x-auto border-l border-border [scrollbar-color:transparent_transparent] hover:[scrollbar-color:var(--nonla-scrollbar-thumb)_transparent] [&::-webkit-scrollbar-thumb]:bg-transparent hover:[&::-webkit-scrollbar-thumb]:bg-(--nonla-scrollbar-thumb) hover:[&::-webkit-scrollbar-thumb:hover]:bg-(--nonla-scrollbar-thumb-hover)">{right}</div>
171
171
  </div>,
172
172
  );
173
173
  left = [];
@@ -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,8 +57,8 @@ 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",
61
- mono && "font-mono text-[13px] leading-5",
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-foreground shadow-none outline-none ring-0 placeholder:text-quaternary-foreground focus:outline-none focus:ring-0",
61
+ mono && "font-mono text-(length:--md-code-size,14px) leading-(--md-code-leading,22px)",
62
62
  className,
63
63
  )}
64
64
  aria-label="Edit markdown"
@@ -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;
@@ -142,9 +142,9 @@ export function MarkdownPreview({ doc, editingIndex, readOnly, placeholder = "Wr
142
142
  );
143
143
  })}
144
144
  {readOnly ? (
145
- doc.blocks.length === 0 ? <p className="m-0 text-sm text-placeholder">{placeholder}</p> : null
145
+ doc.blocks.length === 0 ? <p className="m-0 text-sm text-quaternary-foreground">{placeholder}</p> : null
146
146
  ) : (
147
- <button type="button" className="mt-3 min-h-16 text-left text-sm text-placeholder" onClick={onAppend} aria-label="Add paragraph">
147
+ <button type="button" className="mt-3 min-h-16 text-left text-sm text-quaternary-foreground" onClick={onAppend} aria-label="Add paragraph">
148
148
  {doc.blocks.length === 0 ? placeholder : ""}
149
149
  </button>
150
150
  )}
@@ -63,7 +63,7 @@ export function MarkdownSource({ value, onChange, readOnly, placeholder = "Write
63
63
  setCursor(pos);
64
64
  });
65
65
  }}
66
- className="relative z-10 block w-full resize-none overflow-hidden bg-transparent py-2 pr-4 font-mono text-[13px] leading-5 text-foreground outline-none placeholder:text-placeholder"
66
+ className="relative z-10 block w-full resize-none overflow-hidden bg-transparent py-2 pr-4 font-mono text-[13px] leading-5 text-foreground outline-none placeholder:text-quaternary-foreground"
67
67
  style={{ height: Math.max(lines.length, 1) * LINE + PAD * 2 }}
68
68
  />
69
69
  </div>
@@ -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-muted [&_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>
@@ -7,29 +7,39 @@ import { cn } from "../lib/cn";
7
7
  import { type InlineEdit, type MarkdownBlock, parseMarkdownDoc, readFence, readInlineEdit } from "./blocks";
8
8
  import { MarkdownTable } from "./MarkdownTable";
9
9
  import { MermaidBlock } from "./MermaidBlock";
10
+ import { headingClass, type MarkdownVariant, markdownVariantStyle } from "./markdownScale";
10
11
  import { ReactCode } from "./ReactCode";
11
12
  import { ReactCodeSandbox } from "./ReactCodeSandbox";
12
13
 
14
+ export type { MarkdownVariant };
15
+ export { headingClass, markdownVariantStyle };
16
+
17
+ /** Task checks use the body ink, so a checked box sits with the text instead of the brand fill. */
18
+ const taskCheckClass =
19
+ "data-[state=checked]:border-foreground! data-[state=checked]:bg-foreground! data-[state=checked]:text-background! data-[state=indeterminate]:border-foreground! data-[state=indeterminate]:bg-foreground! data-[state=indeterminate]:text-background!";
20
+
13
21
  const documentClass = cn(
14
- "min-w-0 wrap-anywhere text-[14px] leading-[22px] text-foreground",
15
- "[&_h1]:my-0 [&_h1]:text-[32px] [&_h1]:leading-tight [&_h1]:font-bold [&_h1]:tracking-tight",
16
- "[&_h2]:my-0 [&_h2]:text-[24px] [&_h2]:leading-tight [&_h2]:font-bold [&_h2]:tracking-tight",
17
- "[&_h3]:my-0 [&_h3]:text-[20px] [&_h3]:leading-snug [&_h3]:font-semibold",
18
- "[&_h4]:my-0 [&_h4]:text-[18px] [&_h4]:leading-snug [&_h4]:font-semibold",
19
- "[&_h5]:my-0 [&_h5]:text-[16px] [&_h5]:leading-snug [&_h5]:font-semibold",
20
- "[&_h6]:my-0 [&_h6]:text-[14px] [&_h6]:leading-snug [&_h6]:font-semibold",
21
- "[&_p]:my-0",
22
- "[&_ul]:my-1 [&_ul]:list-disc [&_ul]:pl-6",
23
- "[&_ol]:my-1 [&_ol]:list-decimal [&_ol]:pl-6",
22
+ "min-w-0 wrap-anywhere text-(length:--md-body-size,16px) leading-(--md-body-leading,24px) text-foreground",
23
+ "[&_:is(h1,h2,h3,h4,h5,h6)]:text-foreground",
24
+ "[&_:is(h1,h2)]:mt-(--md-h2-mt,24px) [&_h1]:mb-(--md-h1-mb,12px) [&_h2]:mb-(--md-h2-mb,1px) [&_:is(h1,h2)]:pt-(--md-h2-py,3px) [&_:is(h1,h2)]:pb-(--md-h2-py,3px) [&_:is(h1,h2)]:text-(length:--md-h2-size,30px) [&_:is(h1,h2)]:leading-(--md-h2-leading,40px) [&_:is(h1,h2)]:font-(--md-h2-weight,700) [&_:is(h1,h2)]:tracking-normal",
25
+ "[&_h3]:mt-(--md-h3-mt,22px) [&_h3]:mb-(--md-h3-mb,1px) [&_h3]:text-(length:--md-h3-size,24px) [&_h3]:leading-(--md-h3-leading,32px) [&_h3]:font-(--md-h3-weight,700)",
26
+ "[&_h4]:mt-(--md-h4-mt,16px) [&_h4]:mb-(--md-h4-mb,1px) [&_h4]:text-(length:--md-h4-size,20px) [&_h4]:leading-(--md-h4-leading,26px) [&_h4]:font-(--md-h4-weight,700)",
27
+ "[&_h5]:mt-(--md-h5-mt,0px) [&_h5]:mb-(--md-h5-mb,0px) [&_h5]:text-(length:--md-h5-size,16px) [&_h5]:leading-(--md-h5-leading,1.375) [&_h5]:font-(--md-h5-weight,700)",
28
+ "[&_h6]:mt-(--md-h6-mt,0px) [&_h6]:mb-(--md-h6-mb,0px) [&_h6]:text-(length:--md-h6-size,14px) [&_h6]:leading-(--md-h6-leading,1.375) [&_h6]:font-(--md-h6-weight,700)",
29
+ "[&_p]:my-(--md-p-my,1px) [&_p]:py-(--md-p-py,4px) [&_p]:leading-(--md-p-leading,1.5)",
30
+ "[&_ul]:my-(--md-list-my,8px) [&_ul]:list-disc [&_ul]:pl-(--md-ul-pl,4px)",
31
+ "[&_ol]:my-(--md-list-my,8px) [&_ol]:list-decimal [&_ol]:pl-(--md-ol-pl,4px)",
32
+ "[&_li>ul]:mt-1 [&_li>ol]:mt-1 [&_li>ol]:pl-(--md-nest,1.25rem)",
33
+ "[&_th_ul]:my-0 [&_td_ul]:my-0 [&_th_ol]:my-0 [&_td_ol]:my-0 [&_th_li]:mt-0 [&_td_li]:mt-0 [&_th_li>ul]:mt-0.5 [&_td_li>ul]:mt-0.5 [&_th_li>ol]:mt-0.5 [&_td_li>ol]:mt-0.5 [&_th_li>p]:my-0 [&_td_li>p]:my-0",
24
34
  "[&_ul.contains-task-list]:list-none",
25
- "[&_li]:my-0.5",
35
+ "[&_li]:mt-(--md-li-mt,4px) [&_li]:leading-[1.5]",
26
36
  "[&_li.task-list-item]:relative",
27
37
  "[&_li.task-list-item>.nonla-md-task-check]:absolute [&_li.task-list-item>.nonla-md-task-check]:top-1 [&_li.task-list-item>.nonla-md-task-check]:-left-5",
28
- "[&_blockquote]:my-1 [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground",
38
+ "[&_blockquote]:my-(--md-quote-my,4px) [&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-3 [&_blockquote]:text-muted-foreground",
29
39
  "[&_a]:text-link [&_a]:underline-offset-[3px] hover:[&_a]:underline",
30
- "[&_hr]:my-2 [&_hr]:border-border",
31
- "[&_strong]:font-semibold",
32
- "[&_img]:my-1 [&_img]:max-w-full [&_img]:rounded-lg",
40
+ "[&_hr]:my-(--md-rule-my,8px) [&_hr]:border-border",
41
+ "[&_strong]:font-(--md-strong-weight,600)",
42
+ "[&_img]:my-(--md-img-my,4px) [&_img]:max-w-full [&_img]:rounded-lg",
33
43
  );
34
44
 
35
45
  const previewComponents: Components = {
@@ -39,10 +49,10 @@ const previewComponents: Components = {
39
49
  const codeText = String(children).replace(/\n$/, "");
40
50
  const isBlock = codeText.includes("\n") || !!match;
41
51
  if (!isBlock) {
42
- return <code className="rounded-sm bg-secondary px-1 py-0.5 font-mono text-[0.9em] shadow-button-outline">{children}</code>;
52
+ return <code className="nonla-inline-code rounded-sm bg-muted px-[0.35em] py-[0.12em] align-baseline font-mono text-(length:--md-inline-size,14px) leading-none whitespace-nowrap [box-decoration-break:clone] [-webkit-box-decoration-break:clone]">{children}</code>;
43
53
  }
44
54
  if (lang.toLowerCase() === "mermaid") return <MermaidView code={codeText} />;
45
- return <CodeBlock code={codeText} language={lang || undefined} className="my-2" />;
55
+ return <CodeBlock code={codeText} language={lang || undefined} className="my-(--md-code-my,8px)" />;
46
56
  },
47
57
  table({ children }) {
48
58
  return <MarkdownTable>{children}</MarkdownTable>;
@@ -57,8 +67,8 @@ const previewComponents: Components = {
57
67
  input({ type, checked }) {
58
68
  if (type !== "checkbox") return <input type={type} checked={checked} readOnly />;
59
69
  return (
60
- <span className="nonla-md-task-check pointer-events-none inline-flex h-[22px] items-center">
61
- <Checkbox checked={Boolean(checked)} tabIndex={-1} />
70
+ <span className="nonla-md-task-check pointer-events-none inline-flex h-(--md-body-leading,24px) items-center">
71
+ <Checkbox checked={Boolean(checked)} tabIndex={-1} className={taskCheckClass} />
62
72
  </span>
63
73
  );
64
74
  },
@@ -71,15 +81,6 @@ function MermaidView({ code }: { code: string }) {
71
81
  return <MermaidBlock className="my-0">{code}</MermaidBlock>;
72
82
  }
73
83
 
74
- export function headingClass(level: number): string {
75
- if (level === 1) return "text-[32px] font-bold leading-tight tracking-tight";
76
- if (level === 2) return "text-[24px] font-bold leading-tight tracking-tight";
77
- if (level === 3) return "text-[20px] font-semibold leading-snug";
78
- if (level === 4) return "text-[18px] font-semibold leading-snug";
79
- if (level === 5) return "text-[16px] font-semibold leading-snug";
80
- return "text-[14px] font-semibold leading-snug";
81
- }
82
-
83
84
  type MdNode = {
84
85
  type: string;
85
86
  value?: string;
@@ -136,20 +137,23 @@ function RichText({ source }: { source: string }) {
136
137
  export function ListItem({ view, children }: { view: Extract<InlineEdit, { kind: "list" }>; children: ReactNode }) {
137
138
  const level = Math.floor(view.indent.length / 2);
138
139
  const ordinal = Number(/^(\d+)/.exec(view.marker)?.[1] ?? "1");
140
+ const marker = "w-6 shrink-0 pt-0.5 text-(length:--md-body-size,16px) leading-(--md-p-leading,1.5)";
139
141
  return (
140
- <div className="flex items-start gap-1.5" style={level > 0 ? { marginLeft: `${level * 1.25}rem` } : undefined}>
142
+ <div className="flex items-start gap-1.5 pl-(--md-item-pl,4px)" style={level > 0 ? { marginLeft: `calc(${level} * var(--md-nest, 1.25rem))` } : undefined}>
141
143
  {view.task ? (
142
- <span className="pointer-events-none inline-flex h-[22px] w-5 shrink-0 items-center justify-center">
143
- <Checkbox checked={view.checked} tabIndex={-1} />
144
+ <span className={cn(marker, "pointer-events-none inline-flex justify-center")}>
145
+ <span className="mt-[calc((1lh-1rem)/2)] inline-flex">
146
+ <Checkbox checked={view.checked} tabIndex={-1} className={taskCheckClass} />
147
+ </span>
144
148
  </span>
145
149
  ) : view.ordered ? (
146
- <span className="w-6 shrink-0 text-right text-[14px] leading-[22px] tabular-nums">{ordinal}.</span>
150
+ <span className={cn(marker, "text-right tabular-nums")}>{ordinal}.</span>
147
151
  ) : (
148
- <span className="flex h-[22px] w-5 shrink-0 items-center justify-center" aria-hidden>
149
- <span className="size-1.5 rounded-full bg-current" />
152
+ <span className={cn(marker, "flex justify-center")} aria-hidden>
153
+ <span className="mt-[calc((1lh-0.375rem)/2)] size-1.5 rounded-full bg-current" />
150
154
  </span>
151
155
  )}
152
- <div className="min-w-0 flex-1">{children}</div>
156
+ <div className="min-w-0 flex-1 [&_p]:my-0! [&_p]:py-0.5!">{children}</div>
153
157
  </div>
154
158
  );
155
159
  }
@@ -158,22 +162,14 @@ function isListBlock(block: MarkdownBlock): boolean {
158
162
  return block.kind === "text" && readInlineEdit(block.body).kind === "list";
159
163
  }
160
164
 
161
- function headingGap(level: number): string {
162
- if (level <= 2) return "mt-6";
163
- if (level === 3) return "mt-5";
164
- if (level === 4) return "mt-4";
165
- return "mt-3";
166
- }
167
-
168
- export function spaceBefore(block: MarkdownBlock, prev?: MarkdownBlock): string {
165
+ export function spaceBefore(block: MarkdownBlock, prev?: MarkdownBlock, variant: MarkdownVariant = "docs"): string {
166
+ const chat = variant === "chat";
169
167
  if (!prev) return "";
170
- if (isListBlock(block) && isListBlock(prev)) return "mt-0.5";
171
- if (block.kind === "text") {
172
- const view = readInlineEdit(block.body);
173
- if (view.kind === "heading") return headingGap(view.level);
174
- }
175
- if (prev.kind === "text" && readInlineEdit(prev.body).kind === "heading") return "mt-2";
176
- return "mt-3";
168
+ if (isListBlock(block) && isListBlock(prev)) return chat ? "mt-px" : "mt-0.5";
169
+ if (prev.kind === "text" && readInlineEdit(prev.body).kind === "heading") return "[&_p]:mt-0! [&_p]:pt-0.5!";
170
+ if (isListBlock(block) && prev.kind === "text") return chat ? "mt-0.5" : "mt-1";
171
+ if (block.kind === "text" && prev.kind === "text") return "";
172
+ return chat ? "mt-2" : "mt-3";
177
173
  }
178
174
 
179
175
  function fenceClosed(body: string): boolean {
@@ -235,26 +231,28 @@ export type MarkdownViewerProps = {
235
231
  * Only for markdown you wrote. `react` is provided. Other imports must be listed here.
236
232
  */
237
233
  trustedModules?: Record<string, unknown>;
238
- /** Header on `live-react` results (`Sandbox` or `Live`). `false` shows the result inline. Default `true`. */
234
+ /** Frame around `live-react` results. `false` shows the result inline. Default `true`. */
239
235
  showHeader?: boolean;
240
- /** Code tab in the header of `live-react` results. Needs `showHeader`. Default `true`. */
236
+ /** Switch that opens the source of a `live-react` preview. Needs `showHeader`. Default `true`. */
241
237
  showCode?: boolean;
238
+ /** `docs` is the article scale. `chat` tightens size and spacing for a thread. Default `docs`. */
239
+ variant?: MarkdownVariant;
242
240
  };
243
241
 
244
242
  /** Read-only markdown. Same blocks as the editor preview, without editing. */
245
- export function MarkdownViewer({ value = "", streaming = false, sandboxSrc, trustedModules, showHeader = true, showCode = true, placeholder, className }: MarkdownViewerProps) {
243
+ export function MarkdownViewer({ value = "", streaming = false, sandboxSrc, trustedModules, showHeader = true, showCode = true, placeholder, className, variant = "docs" }: MarkdownViewerProps) {
246
244
  const doc = useMemo(() => parseMarkdownDoc(value), [value]);
247
245
  if (doc.blocks.length === 0) {
248
- return placeholder ? <p className={cn("m-0 text-sm text-placeholder", className)}>{placeholder}</p> : null;
246
+ return placeholder ? <p className={cn("m-0 text-sm text-quaternary-foreground", className)}>{placeholder}</p> : null;
249
247
  }
250
248
  return (
251
- <div className={cn("nonla-markdown-viewer flex min-w-0 flex-col text-foreground", className)}>
249
+ <div data-variant={variant} className={cn("nonla-markdown-viewer flex min-w-0 flex-col text-foreground", variant === "chat" && "[&>[data-md-block]:first-child_:is(h1,h2,h3,h4,h5,h6)]:mt-0", className)} style={markdownVariantStyle(variant)}>
252
250
  {doc.blocks.map((block, index) => (
253
251
  <div
254
252
  // biome-ignore lint/suspicious/noArrayIndexKey: block position is the document identity
255
253
  key={`${index}:${block.kind}`}
256
254
  data-md-block={block.kind}
257
- className={cn("outline-none", spaceBefore(block, doc.blocks[index - 1]))}
255
+ className={cn("outline-none", spaceBefore(block, doc.blocks[index - 1], variant))}
258
256
  >
259
257
  <BlockBody block={block} streaming={streaming} trustedModules={trustedModules} sandboxSrc={sandboxSrc} showHeader={showHeader} showCode={showCode} />
260
258
  </div>
@@ -176,7 +176,7 @@ export function MermaidBlock({ children, className }: MermaidBlockProps) {
176
176
 
177
177
  if (error) {
178
178
  return (
179
- <div className={cn("my-3 rounded-lg bg-accent border border-destructive/30 p-4 text-xs text-destructive", className)}>
179
+ <div className={cn("my-3 rounded-lg bg-brand/14 border border-destructive/30 p-4 text-xs text-destructive", className)}>
180
180
  <p className="font-medium mb-1">Mermaid render error</p>
181
181
  <pre className="whitespace-pre-wrap text-[11px] opacity-70">{error}</pre>
182
182
  </div>
@@ -189,7 +189,7 @@ export function MermaidBlock({ children, className }: MermaidBlockProps) {
189
189
 
190
190
  return (
191
191
  <>
192
- <div className={cn("my-3 last:mb-0 group relative rounded-xl border border-border overflow-hidden bg-card", className)}>
192
+ <div className={cn("my-3 last:mb-0 group relative overflow-hidden rounded-xl bg-card", className)}>
193
193
  <div className="absolute top-2 right-2 z-10 flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
194
194
  <Button size="small" icon={<SolarIcon name="maximize-linear" size={12} />} title="Fullscreen" aria-label="Fullscreen" onClick={openFullscreen} />
195
195
  </div>
@@ -1,5 +1,4 @@
1
1
  import { Component, type ReactNode, useMemo } from "react";
2
- import { SolarIcon } from "../icon/SolarIcon";
3
2
  import { ReactCodeFrame } from "./ReactCodeFrame";
4
3
  import { compileReactCode, type LiveComponent } from "./reactCompile";
5
4
 
@@ -8,13 +7,13 @@ export type ReactCodeProps = {
8
7
  code: string;
9
8
  /** Modules `import` can resolve. `react` is always available. */
10
9
  trustedModules: Record<string, unknown>;
11
- /** Header above the result. Default `true`. */
10
+ /** Bordered frame around the preview. `false` shows the result inline. Default `true`. */
12
11
  showHeader?: boolean;
13
- /** Code tab in the header. Needs `showHeader`. Default `true`. */
12
+ /** Switch that opens the source. Needs `showHeader`. Default `true`. */
14
13
  showCode?: boolean;
15
- /** Header text. Default `Live`. */
14
+ /** Label above the preview. Omit for no label bar. */
16
15
  title?: ReactNode;
17
- /** Header icon. `null` hides it. */
16
+ /** Icon before the title. */
18
17
  icon?: ReactNode;
19
18
  /** Classes for the outer box. */
20
19
  className?: string;
@@ -58,11 +57,11 @@ class RenderBoundary extends Component<{ children: ReactNode }, { error: string
58
57
  *
59
58
  * Only for source you wrote. Markdown from users or agents must use `ReactCodeSandbox`.
60
59
  */
61
- export function ReactCode({ code, trustedModules, showHeader = true, showCode = true, title = "Live", icon, className }: ReactCodeProps) {
60
+ export function ReactCode({ code, trustedModules, showHeader = true, showCode = true, title, icon, className }: ReactCodeProps) {
62
61
  return (
63
62
  <ReactCodeFrame
64
63
  title={title}
65
- icon={icon === undefined ? <SolarIcon name="play-circle-linear" size={16} className="text-warn" /> : icon}
64
+ icon={icon}
66
65
  showHeader={showHeader}
67
66
  code={showCode ? code : undefined}
68
67
  className={className}
@@ -1,7 +1,9 @@
1
1
  import { type ReactNode, useState } from "react";
2
2
  import { CodeBlock } from "../codeblock/CodeBlock";
3
+ import { SolarIcon } from "../icon/SolarIcon";
3
4
  import { cn } from "../lib/cn";
4
5
  import { Segmented } from "../segmented/Segmented";
6
+ import { Tooltip } from "../tooltip/Tooltip";
5
7
 
6
8
  type Tab = "preview" | "code";
7
9
 
@@ -11,36 +13,64 @@ const TABS = [
11
13
  ] satisfies { label: string; value: Tab }[];
12
14
 
13
15
  export type ReactCodeFrameProps = {
14
- /** Header text, such as `Sandbox`. */
15
- title: ReactNode;
16
- /** Icon before the title. `null` hides it. */
16
+ /** Label above the preview. Omit for no label bar. */
17
+ title?: ReactNode;
18
+ /** Icon before the title. */
17
19
  icon?: ReactNode;
18
- /** `false` drops the header and the border, so the result sits inline with the text around it. */
20
+ /** `false` drops the frame, so the result sits inline with the text around it. */
19
21
  showHeader?: boolean;
20
- /** Source for the Code tab. Omit to show the result only. The tab lives in the header, so no header means no tab. */
22
+ /** Source for the Code view. Omit to show the result only. The switch lives in the frame, so no frame means no code. */
21
23
  code?: string;
22
24
  className?: string;
23
25
  /** The rendered result. */
24
26
  children: ReactNode;
25
27
  };
26
28
 
27
- /** Header, result, and an optional Code tab around a rendered `live-react` block. */
29
+ /** Preview, and a way to open the source. A title bar keeps that switch beside the label. */
28
30
  export function ReactCodeFrame({ title, icon, showHeader = true, code, className, children }: ReactCodeFrameProps) {
29
31
  const [tab, setTab] = useState<Tab>("preview");
32
+ const [open, setOpen] = useState(false);
30
33
  if (!showHeader) return <div className={cn("mb-2 w-full min-w-0", className)}>{children}</div>;
31
34
  const hasCode = code !== undefined;
35
+ const hasLabel = (title != null && title !== false) || icon != null;
36
+ const showingCode = hasLabel ? tab === "code" : open;
37
+ const codeLabel = open ? "Hide code" : "Show code";
32
38
  return (
33
39
  <div className={cn("mb-2 flex w-full min-w-0 flex-col overflow-clip rounded-xl border border-border text-foreground", className)}>
34
- <div className="flex h-10 items-center justify-between gap-2 border-b border-border pr-2 pl-3 text-xs font-medium">
35
- <div className="flex min-w-0 items-center gap-2">
36
- {icon}
37
- <span className="truncate">{title}</span>
40
+ {hasLabel ? (
41
+ <div className="flex h-10 items-center justify-between gap-2 border-b border-border pr-2 pl-3 text-xs font-medium">
42
+ <div className="flex min-w-0 items-center gap-2">
43
+ {icon}
44
+ {title != null && title !== false ? <span className="truncate">{title}</span> : null}
45
+ </div>
46
+ {hasCode ? <Segmented<Tab> size="small" options={TABS} value={tab} onChange={setTab} /> : null}
38
47
  </div>
39
- {hasCode ? <Segmented<Tab> size="small" options={TABS} value={tab} onChange={setTab} /> : null}
40
- </div>
41
- {/* Stays mounted on the Code tab, so an iframe keeps its state. */}
42
- <div className={cn("min-w-0 px-3 py-3", hasCode && tab === "code" && "hidden")}>{children}</div>
43
- {hasCode && tab === "code" ? <CodeBlock code={code} language="tsx" className="my-0 rounded-none border-0" /> : null}
48
+ ) : null}
49
+ {/* Stays mounted when the Code tab replaces it, so an iframe keeps its state. The code button keeps this and opens the source under it. */}
50
+ <div className={cn("min-w-0 px-6 py-8", hasLabel && showingCode && "hidden")}>{children}</div>
51
+ {hasCode && !hasLabel ? (
52
+ <div className="flex h-10 items-center justify-end border-t border-border pr-1.5">
53
+ <Tooltip title={codeLabel}>
54
+ <button
55
+ type="button"
56
+ aria-expanded={open}
57
+ aria-label={codeLabel}
58
+ className={cn(
59
+ "inline-flex size-7 cursor-pointer items-center justify-center rounded-md transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand/55",
60
+ open ? "bg-muted text-foreground" : "text-muted-foreground",
61
+ )}
62
+ onClick={() => setOpen((value) => !value)}
63
+ >
64
+ <SolarIcon name="code-square-linear" size={16} />
65
+ </button>
66
+ </Tooltip>
67
+ </div>
68
+ ) : null}
69
+ {hasCode && showingCode ? (
70
+ <div className={cn(!hasLabel && "border-t border-border")}>
71
+ <CodeBlock code={code} language="tsx" className="my-0 rounded-none border-0" />
72
+ </div>
73
+ ) : null}
44
74
  </div>
45
75
  );
46
76
  }
@@ -30,7 +30,7 @@ export type ReactCodeSandboxProps = {
30
30
  src: string;
31
31
  /** Header above the result. Default `true`. */
32
32
  showHeader?: boolean;
33
- /** Code tab in the header. Needs `showHeader`. Default `true`. */
33
+ /** Preview / Code switch in the header. Needs `showHeader`. Default `true`. */
34
34
  showCode?: boolean;
35
35
  /** Header text. Default `Sandbox`. */
36
36
  title?: ReactNode;