devnonla-ui 0.8.0 → 0.9.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 +31 -4
- package/package.json +3 -3
- package/src/app/App.tsx +5 -1
- package/src/app/context.ts +5 -3
- package/src/button/Button.tsx +2 -2
- package/src/button/ButtonCopy.tsx +2 -2
- package/src/card/Card.tsx +81 -0
- package/src/chat/AgentChatbox.tsx +1 -1
- package/src/chat/AgentPanel.tsx +1 -1
- package/src/chat/message-ui/ChatError.tsx +2 -2
- package/src/chat/message-ui/ChatInput.tsx +5 -5
- package/src/chat/message-ui/ChatMarkdown.tsx +8 -7
- package/src/chat/message-ui/ChatThinking.tsx +3 -3
- package/src/chat/message-ui/ChatUserMessage.tsx +3 -3
- package/src/chat/message-ui/MermaidBlock.tsx +68 -39
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +3 -3
- package/src/chat/tool-ui/CallAgentToolUI.tsx +3 -3
- package/src/chat/tool-ui/ChatToolCall.tsx +4 -4
- package/src/chat/tool-ui/GetCurrentTimeToolUI.tsx +2 -2
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +2 -2
- package/src/chat/tool-ui/RunJsToolUI.tsx +2 -2
- package/src/chat/tool-ui/ToolUiTrailing.tsx +3 -3
- package/src/chat/tool-ui/WebFetchToolUI.tsx +2 -2
- package/src/checkbox/Checkbox.tsx +17 -4
- package/src/codeblock/CodeBlock.tsx +2 -2
- package/src/datepicker/DatePicker.tsx +3 -3
- package/src/desktop/DesktopHeader.tsx +1 -1
- package/src/desktop/DesktopIcon.tsx +2 -2
- package/src/desktop/DesktopWindow.tsx +51 -29
- package/src/empty/Empty.tsx +8 -5
- package/src/form/FormItem.tsx +1 -1
- package/src/form-layout/FormLayout.tsx +1 -1
- package/src/icon/SolarIcon.tsx +39 -0
- package/src/icon/solar.ts +172 -0
- package/src/index.ts +24 -12
- package/src/input/EditableInput.tsx +3 -3
- package/src/input/Input.tsx +3 -3
- package/src/lib/sizes.ts +9 -6
- package/src/lib/surface.ts +1 -1
- package/src/markdown-editor/MarkdownDiff.tsx +211 -0
- package/src/markdown-editor/MarkdownEditor.tsx +294 -0
- package/src/markdown-editor/MarkdownPreview.tsx +326 -0
- package/src/markdown-editor/MarkdownSource.tsx +72 -0
- package/src/markdown-editor/blocks.ts +329 -0
- package/src/markdown-editor/diff.ts +296 -0
- package/src/menu/Menu.tsx +3 -3
- package/src/pagination/Pagination.tsx +8 -7
- package/src/segmented/Segmented.tsx +2 -2
- package/src/select/Select.tsx +192 -63
- package/src/sidebar/Sidebar.tsx +9 -8
- package/src/spin/Spin.tsx +17 -11
- package/src/styles.css +265 -110
- package/src/switch/Switch.tsx +17 -3
- package/src/table/Table.tsx +61 -26
- package/src/theme-toggle/ThemeToggle.tsx +33 -0
- package/src/theme.ts +72 -0
- package/src/timepicker/TimePicker.tsx +1 -1
- package/src/icon/FluentIcon.tsx +0 -28
- package/src/icon/fluent.ts +0 -75
package/src/table/Table.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import { cn } from "../lib/cn";
|
|
|
5
5
|
import { type CanonicalSize, type ControlSize, useControlSize } from "../lib/sizes";
|
|
6
6
|
import { Pagination, type PaginationProps } from "../pagination/Pagination";
|
|
7
7
|
import { OverlayScroll } from "../scroll/OverlayScroll";
|
|
8
|
+
import { Select } from "../select/Select";
|
|
8
9
|
import { Spin } from "../spin/Spin";
|
|
9
10
|
|
|
10
11
|
export type SortOrder = "ascend" | "descend" | null;
|
|
@@ -76,7 +77,9 @@ export type TableProps<T extends object = Record<string, unknown>> = {
|
|
|
76
77
|
/** `false` disables; object enables (client-side slice when `total` omitted). */
|
|
77
78
|
pagination?: false | TablePaginationConfig;
|
|
78
79
|
className?: string;
|
|
80
|
+
/** Row padding. Type size stays the same; `small` is tight, `large` is roomy. */
|
|
79
81
|
size?: ControlSize;
|
|
82
|
+
/** Card frame around the table. On by default. */
|
|
80
83
|
bordered?: boolean;
|
|
81
84
|
scroll?: { x?: number | string; y?: number | string };
|
|
82
85
|
onRow?: (
|
|
@@ -177,28 +180,40 @@ function TableBodyScroll({ x, y, scrollRef, insetTop = 0, children }: { x?: numb
|
|
|
177
180
|
function sizeClasses(s: CanonicalSize) {
|
|
178
181
|
if (s === "small") {
|
|
179
182
|
return {
|
|
180
|
-
head: "h-
|
|
181
|
-
cell: "px-2 py-1
|
|
182
|
-
check: "w-
|
|
183
|
+
head: "h-8 px-2 text-base",
|
|
184
|
+
cell: "px-2 py-1 text-base",
|
|
185
|
+
check: "w-8 px-2",
|
|
183
186
|
};
|
|
184
187
|
}
|
|
185
188
|
if (s === "large") {
|
|
186
189
|
return {
|
|
187
|
-
head: "h-12 px-
|
|
188
|
-
cell: "px-
|
|
189
|
-
check: "w-12 px-
|
|
190
|
+
head: "h-12 px-4 text-base",
|
|
191
|
+
cell: "px-4 py-3 text-base",
|
|
192
|
+
check: "w-12 px-4",
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
|
-
// default — text-base is 14px (`--text-sm` in this theme is 13px)
|
|
193
195
|
return {
|
|
194
|
-
head: "h-10 px-
|
|
195
|
-
cell: "
|
|
196
|
-
check: "w-10 px-
|
|
196
|
+
head: "h-10 px-3 text-base",
|
|
197
|
+
cell: "px-3 py-2 text-base",
|
|
198
|
+
check: "w-10 px-3",
|
|
197
199
|
};
|
|
198
200
|
}
|
|
199
201
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
+
function defaultShowTotal(total: number, [from, to]: [number, number]) {
|
|
203
|
+
if (total === 0) return "0";
|
|
204
|
+
return `${from}–${to} of ${total}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function pageSizeSelectOptions(pageSize: number, pageSizeOptions?: Array<number | string>) {
|
|
208
|
+
const raw = pageSizeOptions?.length ? pageSizeOptions.map(Number) : [10, 20, 50, 100];
|
|
209
|
+
const sizes = [...new Set(raw.filter((n) => Number.isFinite(n) && n > 0))];
|
|
210
|
+
const list = sizes.includes(pageSize) ? sizes : [pageSize, ...sizes];
|
|
211
|
+
return list.map((n) => ({ value: n, label: `${n} / page` }));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function Table<T extends object = Record<string, unknown>>({ columns = [], dataSource = [], rowKey, loading, pagination, className, size, bordered = true, scroll, onRow, locale, showHeader = true, title, footer, rowSelection, rowClassName, onChange }: TableProps<T>) {
|
|
215
|
+
const resolvedSize = useControlSize(size);
|
|
216
|
+
const sz = sizeClasses(resolvedSize);
|
|
202
217
|
|
|
203
218
|
const selectionControlled = rowSelection?.selectedRowKeys !== undefined;
|
|
204
219
|
const [innerSelected, setInnerSelected] = useState<Key[]>(() => rowSelection?.defaultSelectedRowKeys ?? []);
|
|
@@ -391,8 +406,9 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
391
406
|
<div className={cn("relative w-full", className)}>
|
|
392
407
|
{titleNode != null ? <div className="mb-3 text-sm font-medium text-foreground">{titleNode}</div> : null}
|
|
393
408
|
|
|
409
|
+
<div className={cn(bordered && "overflow-hidden rounded-xl border border-hairline")}>
|
|
394
410
|
<Spin spinning={Boolean(loading)}>
|
|
395
|
-
<div ref={containerRef} data-slot="table-container" className={cn("relative w-full", flexLayout ? "overflow-x-hidden" : "overflow-x-auto"
|
|
411
|
+
<div ref={containerRef} data-slot="table-container" className={cn("relative w-full", flexLayout ? "overflow-x-hidden" : "overflow-x-auto")} style={scroll?.x != null ? { overflowX: "auto" } : undefined}>
|
|
396
412
|
<TableBodyScroll y={scroll?.y} x={scroll?.x} scrollRef={scrollBodyRef} insetTop={thumbInset}>
|
|
397
413
|
<table data-slot="table" className={cn("caption-bottom text-base", headSticky ? "border-separate border-spacing-0" : "border-collapse", flexLayout ? "w-full table-fixed" : wantsFlex ? "w-max" : "w-full")}>
|
|
398
414
|
{flexLayout ? (
|
|
@@ -405,10 +421,10 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
405
421
|
</colgroup>
|
|
406
422
|
) : null}
|
|
407
423
|
{showHeader ? (
|
|
408
|
-
<thead data-slot="table-header" className={cn("[&_tr]:border-b [&_tr]:border-
|
|
409
|
-
<tr data-slot="table-row" className="border-b border-
|
|
424
|
+
<thead data-slot="table-header" className={cn("[&_tr]:border-b [&_tr]:border-hairline", headSticky && "relative z-20")}>
|
|
425
|
+
<tr data-slot="table-row" className="border-b border-hairline transition-colors hover:bg-transparent">
|
|
410
426
|
{rowSelection ? (
|
|
411
|
-
<th data-slot="table-head" className={cn(sz.head, sz.check, "align-middle font-medium text-foreground", headSticky && "sticky top-0 z-10 border-b border-
|
|
427
|
+
<th data-slot="table-head" className={cn(sz.head, sz.check, "align-middle font-medium text-foreground", headSticky && "sticky top-0 z-10 border-b border-hairline", bordered && "border-b border-hairline")} style={{ ...(selectionColWidth != null ? { width: selectionColWidth } : undefined), ...headBg }}>
|
|
412
428
|
<div className="flex items-center justify-center">
|
|
413
429
|
{rowSelection.type === "radio" ? null : (
|
|
414
430
|
<Checkbox
|
|
@@ -433,7 +449,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
433
449
|
<th
|
|
434
450
|
key={key}
|
|
435
451
|
data-slot="table-head"
|
|
436
|
-
className={cn(sz.head, "align-middle font-medium text-foreground", headSticky && "sticky top-0 z-10 border-b border-
|
|
452
|
+
className={cn(sz.head, "align-middle font-medium text-foreground", headSticky && "sticky top-0 z-10 border-b border-hairline", flexLayout && flexWeight(col) > 0 ? "min-w-0" : "whitespace-nowrap", alignClass(col.align), bordered && "border-b border-hairline", sortable && "cursor-pointer select-none", col.className, headerExtra?.className)}
|
|
437
453
|
style={{
|
|
438
454
|
...colStyle(col, key),
|
|
439
455
|
...headBg,
|
|
@@ -454,7 +470,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
454
470
|
|
|
455
471
|
<tbody data-slot="table-body" className={cn("[&_tr:last-child]:border-0", headSticky && "relative z-0")}>
|
|
456
472
|
{pageData.length === 0 ? (
|
|
457
|
-
<tr data-slot="table-row" className="border-b border-
|
|
473
|
+
<tr data-slot="table-row" className="border-b border-hairline">
|
|
458
474
|
<td data-slot="table-cell" colSpan={colCount} className={cn(sz.cell, "text-center align-middle")}>
|
|
459
475
|
{locale?.emptyText ?? <Empty description="No data" className="py-10" />}
|
|
460
476
|
</td>
|
|
@@ -473,7 +489,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
473
489
|
key={key}
|
|
474
490
|
data-slot="table-row"
|
|
475
491
|
data-state={selected ? "selected" : undefined}
|
|
476
|
-
className={cn("border-b border-
|
|
492
|
+
className={cn("border-b border-hairline transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", inSelectionMode && !rowDisabled && "cursor-pointer", rowProps?.className, extraClass)}
|
|
477
493
|
style={rowProps?.style}
|
|
478
494
|
onClick={inSelectionMode ? undefined : rowProps?.onClick}
|
|
479
495
|
onClickCapture={
|
|
@@ -490,7 +506,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
490
506
|
}
|
|
491
507
|
>
|
|
492
508
|
{rowSelection ? (
|
|
493
|
-
<td data-row-select data-slot="table-cell" className={cn(sz.cell, sz.check, "align-middle", headSticky && "border-b border-
|
|
509
|
+
<td data-row-select data-slot="table-cell" className={cn(sz.cell, sz.check, "align-middle", headSticky && "border-b border-hairline")} style={selectionColWidth != null ? { width: selectionColWidth } : undefined} onClick={(e) => e.stopPropagation()}>
|
|
494
510
|
<div className="flex items-center justify-center">
|
|
495
511
|
{rowSelection.type === "radio" ? (
|
|
496
512
|
<input type="radio" name="nonla-table-row-select" checked={selected} disabled={rowSelection.getCheckboxProps?.(record)?.disabled} aria-label="Select row" className="size-3.5 accent-foreground" onChange={() => emitSelection([key])} />
|
|
@@ -515,7 +531,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
515
531
|
<td
|
|
516
532
|
key={getColumnKey(col, i)}
|
|
517
533
|
data-slot="table-cell"
|
|
518
|
-
className={cn(sz.cell, "align-middle", headSticky && "border-b border-
|
|
534
|
+
className={cn(sz.cell, "align-middle", headSticky && "border-b border-hairline", alignClass(col.align), flexLayout && flexWeight(col) > 0 ? (col.ellipsis ? "max-w-0 truncate" : "min-w-0 whitespace-normal wrap-break-word") : col.ellipsis ? "max-w-0 truncate" : "whitespace-nowrap", col.className)}
|
|
519
535
|
style={colStyle(col, getColumnKey(col, i))}
|
|
520
536
|
title={col.ellipsis && (typeof content === "string" || typeof content === "number") ? String(content) : undefined}
|
|
521
537
|
>
|
|
@@ -530,7 +546,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
530
546
|
</tbody>
|
|
531
547
|
|
|
532
548
|
{footerNode != null ? (
|
|
533
|
-
<tfoot data-slot="table-footer" className="border-t border-
|
|
549
|
+
<tfoot data-slot="table-footer" className="border-t border-hairline bg-muted/50 font-medium [&>tr]:last:border-b-0">
|
|
534
550
|
<tr>
|
|
535
551
|
<td colSpan={colCount} className={cn(sz.cell, "align-middle text-muted-foreground")}>
|
|
536
552
|
{footerNode}
|
|
@@ -544,21 +560,40 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
544
560
|
</Spin>
|
|
545
561
|
|
|
546
562
|
{showPagination ? (
|
|
547
|
-
<div className={cn("
|
|
563
|
+
<div className={cn("flex flex-wrap items-center justify-between gap-3 px-3 py-2", bordered && "border-t border-hairline", pageConfig.className)}>
|
|
564
|
+
<div className="flex items-center gap-3">
|
|
565
|
+
{pageConfig.showSizeChanger !== false ? (
|
|
566
|
+
<Select
|
|
567
|
+
size="small"
|
|
568
|
+
value={pageSize}
|
|
569
|
+
className="w-[8.5rem]"
|
|
570
|
+
options={pageSizeSelectOptions(pageSize, pageConfig.pageSizeOptions)}
|
|
571
|
+
onChange={(value) => {
|
|
572
|
+
const nextSize = Number(value);
|
|
573
|
+
if (!Number.isFinite(nextSize) || nextSize <= 0) return;
|
|
574
|
+
const nextPage = Math.min(current, Math.max(1, Math.ceil(total / nextSize)));
|
|
575
|
+
pageConfig.onShowSizeChange?.(current, nextSize);
|
|
576
|
+
handlePageChange(nextPage, nextSize);
|
|
577
|
+
}}
|
|
578
|
+
/>
|
|
579
|
+
) : null}
|
|
580
|
+
{pageConfig.showTotal !== false ? <span className="text-xs text-muted-foreground">{(pageConfig.showTotal ?? defaultShowTotal)(total, [total === 0 ? 0 : (current - 1) * pageSize + 1, Math.min(current * pageSize, total)])}</span> : null}
|
|
581
|
+
</div>
|
|
548
582
|
<Pagination
|
|
549
583
|
{...pageConfig}
|
|
550
584
|
className={undefined}
|
|
551
585
|
hideOnSinglePage={false}
|
|
552
|
-
align={pageConfig.align ?? "end"}
|
|
553
586
|
current={current}
|
|
554
587
|
pageSize={pageSize}
|
|
555
588
|
total={total}
|
|
556
|
-
size=
|
|
557
|
-
|
|
589
|
+
size="small"
|
|
590
|
+
showTotal={false}
|
|
591
|
+
showSizeChanger={false}
|
|
558
592
|
onChange={handlePageChange}
|
|
559
593
|
/>
|
|
560
594
|
</div>
|
|
561
595
|
) : null}
|
|
596
|
+
</div>
|
|
562
597
|
</div>
|
|
563
598
|
);
|
|
564
599
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useLayoutEffect, useSyncExternalStore } from "react";
|
|
2
|
+
import { Segmented } from "../segmented/Segmented";
|
|
3
|
+
import { getColorMode, initColorMode, type NonlaColorMode, setColorMode, subscribeColorMode } from "../theme";
|
|
4
|
+
|
|
5
|
+
export function useColorMode(): NonlaColorMode {
|
|
6
|
+
return useSyncExternalStore(subscribeColorMode, getColorMode, () => "dark");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ThemeToggleProps = {
|
|
10
|
+
className?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Light and Dark, both always visible. Remembers the choice. */
|
|
14
|
+
export function ThemeToggle({ className }: ThemeToggleProps) {
|
|
15
|
+
const mode = useColorMode();
|
|
16
|
+
|
|
17
|
+
useLayoutEffect(() => {
|
|
18
|
+
initColorMode();
|
|
19
|
+
}, []);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Segmented
|
|
23
|
+
size="small"
|
|
24
|
+
className={className}
|
|
25
|
+
value={mode}
|
|
26
|
+
onChange={setColorMode}
|
|
27
|
+
options={[
|
|
28
|
+
{ value: "light", label: "Light" },
|
|
29
|
+
{ value: "dark", label: "Dark" },
|
|
30
|
+
]}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
33
|
+
}
|
package/src/theme.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Consumers retheme without touching components:
|
|
7
7
|
* 1. CSS: `:root { --nonla-brand: #3b82f6; }`
|
|
8
8
|
* 2. JS: `<App theme={{ colors: { brand: "#3b82f6" } }} />` or `applyNonlaTheme({ brand: "#3b82f6" })`
|
|
9
|
+
* Color mode is `light` | `dark` on `<html>` (`setColorMode`, `<ThemeToggle>`). Dark is the default.
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
export const NONLA_THEME_KEYS = {
|
|
@@ -25,6 +26,7 @@ export const NONLA_THEME_KEYS = {
|
|
|
25
26
|
heightSm: "--nonla-height-sm",
|
|
26
27
|
heightLg: "--nonla-height-lg",
|
|
27
28
|
ink: "--nonla-ink",
|
|
29
|
+
sidebar: "--nonla-sidebar",
|
|
28
30
|
surface: "--nonla-surface",
|
|
29
31
|
elevated: "--nonla-elevated",
|
|
30
32
|
chip: "--nonla-chip",
|
|
@@ -43,6 +45,7 @@ export const NONLA_THEME_KEYS = {
|
|
|
43
45
|
inkActive: "--nonla-ink-active",
|
|
44
46
|
inkLine: "--nonla-ink-line",
|
|
45
47
|
desktopBarHeight: "--nonla-desktop-bar-height",
|
|
48
|
+
windowHeader: "--nonla-window-header",
|
|
46
49
|
zBase: "--nonla-z-base",
|
|
47
50
|
zDesktop: "--nonla-z-desktop",
|
|
48
51
|
zWindow: "--nonla-z-window",
|
|
@@ -149,3 +152,72 @@ export function applyNonlaTheme(theme: NonlaThemeConfig, target: HTMLElement = d
|
|
|
149
152
|
}
|
|
150
153
|
};
|
|
151
154
|
}
|
|
155
|
+
|
|
156
|
+
export type NonlaColorMode = "light" | "dark";
|
|
157
|
+
|
|
158
|
+
/** `localStorage` key written by `setColorMode`. */
|
|
159
|
+
export const NONLA_COLOR_MODE_KEY = "nonla-color-mode";
|
|
160
|
+
|
|
161
|
+
const modeListeners = new Set<() => void>();
|
|
162
|
+
let colorMode: NonlaColorMode = "dark";
|
|
163
|
+
let colorModeReady = false;
|
|
164
|
+
|
|
165
|
+
export function getColorMode(): NonlaColorMode {
|
|
166
|
+
return colorMode;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function subscribeColorMode(listener: () => void) {
|
|
170
|
+
modeListeners.add(listener);
|
|
171
|
+
return () => {
|
|
172
|
+
modeListeners.delete(listener);
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function notifyColorMode() {
|
|
177
|
+
for (const listener of modeListeners) listener();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function readStoredColorMode(): NonlaColorMode | null {
|
|
181
|
+
if (typeof localStorage === "undefined") return null;
|
|
182
|
+
try {
|
|
183
|
+
const value = localStorage.getItem(NONLA_COLOR_MODE_KEY);
|
|
184
|
+
return value === "light" || value === "dark" ? value : null;
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** Set `light` or `dark` on `target` (default `<html>`) so portals inherit the palette. */
|
|
191
|
+
export function applyColorMode(next: NonlaColorMode, target: HTMLElement = document.documentElement) {
|
|
192
|
+
colorMode = next;
|
|
193
|
+
target.classList.toggle("light", next === "light");
|
|
194
|
+
target.classList.toggle("dark", next === "dark");
|
|
195
|
+
target.style.colorScheme = next;
|
|
196
|
+
notifyColorMode();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Switch mode and remember it. */
|
|
200
|
+
export function setColorMode(next: NonlaColorMode, target?: HTMLElement) {
|
|
201
|
+
if (typeof document === "undefined") {
|
|
202
|
+
colorMode = next;
|
|
203
|
+
notifyColorMode();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
applyColorMode(next, target);
|
|
207
|
+
colorModeReady = true;
|
|
208
|
+
try {
|
|
209
|
+
localStorage.setItem(NONLA_COLOR_MODE_KEY, next);
|
|
210
|
+
} catch {
|
|
211
|
+
/* private mode */
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Apply the saved mode once. Falls back to dark. */
|
|
216
|
+
export function initColorMode(target?: HTMLElement): NonlaColorMode {
|
|
217
|
+
if (typeof document === "undefined") return colorMode;
|
|
218
|
+
if (colorModeReady) return colorMode;
|
|
219
|
+
colorModeReady = true;
|
|
220
|
+
const fromClass = document.documentElement.classList.contains("light") ? "light" : document.documentElement.classList.contains("dark") ? "dark" : null;
|
|
221
|
+
applyColorMode(readStoredColorMode() ?? fromClass ?? "dark", target);
|
|
222
|
+
return colorMode;
|
|
223
|
+
}
|
|
@@ -632,7 +632,7 @@ export const TimePicker = forwardRef<HTMLInputElement, TimePickerProps>(function
|
|
|
632
632
|
onKeyDown={handleKeyDown}
|
|
633
633
|
onKeyUp={(e) => syncPartFromCaret(e.currentTarget)}
|
|
634
634
|
onClick={(e) => syncPartFromCaret(e.currentTarget)}
|
|
635
|
-
className="min-w-0 flex-1 border-0 bg-transparent p-0 text-foreground placeholder:text-
|
|
635
|
+
className="min-w-0 flex-1 border-0 bg-transparent p-0 text-foreground placeholder:text-placeholder outline-none disabled:cursor-not-allowed"
|
|
636
636
|
style={{ fontSize: fieldStyle.fontSize, lineHeight: fieldStyle.lineHeight }}
|
|
637
637
|
/>
|
|
638
638
|
{allowClear && selected && !disabled ? (
|
package/src/icon/FluentIcon.tsx
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { cn } from "../lib/cn";
|
|
3
|
-
import { ensureFluentIcons, getFluentImgSrc } from "./fluent";
|
|
4
|
-
|
|
5
|
-
export function FluentIcon({ name, size = 16, className }: { name: string; size?: number; className?: string }) {
|
|
6
|
-
const [src, setSrc] = useState<string | null>(() => getFluentImgSrc(name));
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
const cached = getFluentImgSrc(name);
|
|
10
|
-
if (cached) {
|
|
11
|
-
setSrc(cached);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
let cancelled = false;
|
|
15
|
-
void ensureFluentIcons().then(() => {
|
|
16
|
-
if (!cancelled) setSrc(getFluentImgSrc(name));
|
|
17
|
-
});
|
|
18
|
-
return () => {
|
|
19
|
-
cancelled = true;
|
|
20
|
-
};
|
|
21
|
-
}, [name]);
|
|
22
|
-
|
|
23
|
-
if (!src) {
|
|
24
|
-
return <span aria-hidden className={cn("inline-block shrink-0", className)} style={{ width: size, height: size }} />;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return <img src={src} alt="" width={size} height={size} draggable={false} className={cn("shrink-0 select-none pointer-events-none", className)} />;
|
|
28
|
-
}
|
package/src/icon/fluent.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export const ICON_PREFIX = "fluent-color";
|
|
2
|
-
export const DEFAULT_ICON_NAME = "bot-24";
|
|
3
|
-
export const DEFAULT_TOOL_ICON = `${ICON_PREFIX}:${DEFAULT_ICON_NAME}`;
|
|
4
|
-
|
|
5
|
-
const SIZE_SUFFIX = /-24$/;
|
|
6
|
-
|
|
7
|
-
type IconifyIcon = { body: string; width?: number; height?: number };
|
|
8
|
-
type IconifyPack = {
|
|
9
|
-
icons?: Record<string, IconifyIcon>;
|
|
10
|
-
width?: number;
|
|
11
|
-
height?: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
let memoryNames: string[] | null = null;
|
|
15
|
-
const svgByName = new Map<string, string>();
|
|
16
|
-
const imgSrcByName = new Map<string, string>();
|
|
17
|
-
let inflight: Promise<string[]> | null = null;
|
|
18
|
-
|
|
19
|
-
function hydrate(pack: IconifyPack): string[] {
|
|
20
|
-
const defaultW = pack.width ?? 24;
|
|
21
|
-
const defaultH = pack.height ?? 24;
|
|
22
|
-
const names: string[] = [];
|
|
23
|
-
for (const [name, icon] of Object.entries(pack.icons ?? {})) {
|
|
24
|
-
if (!SIZE_SUFFIX.test(name) || !icon?.body) continue;
|
|
25
|
-
const w = icon.width ?? defaultW;
|
|
26
|
-
const h = icon.height ?? defaultH;
|
|
27
|
-
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 ${w} ${h}">${icon.body}</svg>`;
|
|
28
|
-
svgByName.set(name, svg);
|
|
29
|
-
names.push(name);
|
|
30
|
-
}
|
|
31
|
-
memoryNames = names;
|
|
32
|
-
return names;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Loads the vendored Fluent Color pack (code-split). No network. */
|
|
36
|
-
export function ensureFluentIcons(): Promise<string[]> {
|
|
37
|
-
if (memoryNames) return Promise.resolve(memoryNames);
|
|
38
|
-
if (inflight) return inflight;
|
|
39
|
-
inflight = import("@iconify-json/fluent-color/icons.json")
|
|
40
|
-
.then((mod) => hydrate((mod.default ?? mod) as IconifyPack))
|
|
41
|
-
.finally(() => {
|
|
42
|
-
inflight = null;
|
|
43
|
-
});
|
|
44
|
-
return inflight;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function getIconNames(): string[] {
|
|
48
|
-
return memoryNames ?? [];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function getFluentImgSrc(name: string): string | null {
|
|
52
|
-
const hit = imgSrcByName.get(name);
|
|
53
|
-
if (hit) return hit;
|
|
54
|
-
const svg = svgByName.get(name);
|
|
55
|
-
if (!svg) return null;
|
|
56
|
-
const src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
57
|
-
imgSrcByName.set(name, src);
|
|
58
|
-
return src;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function isSvgIcon(value?: string | null): boolean {
|
|
62
|
-
return !!value && value.trimStart().startsWith("<svg");
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function isFluentIcon(value?: string | null): boolean {
|
|
66
|
-
return !!value && value.startsWith(`${ICON_PREFIX}:`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function fluentIconName(value: string): string {
|
|
70
|
-
return value.slice(ICON_PREFIX.length + 1);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function fluentIconRef(name: string): string {
|
|
74
|
-
return `${ICON_PREFIX}:${name}`;
|
|
75
|
-
}
|