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.
- package/README.md +6 -245
- package/package.json +2 -2
- package/src/app/App.tsx +6 -22
- package/src/app/context.ts +2 -17
- package/src/avatar/AgentAvatar.tsx +17 -6
- package/src/avatar/avatar.css +107 -0
- package/src/button/Button.tsx +4 -4
- package/src/button/ButtonCopy.tsx +1 -1
- package/src/calendar/Calendar.tsx +1 -1
- package/src/card/Card.tsx +2 -5
- package/src/chat/AgentChatbox.tsx +1 -1
- package/src/chat/AgentPanel.tsx +1 -1
- package/src/chat/chatMessageList.tsx +1 -4
- package/src/chat/message-ui/ChatAgentMessage.tsx +6 -4
- package/src/chat/message-ui/ChatError.tsx +1 -1
- package/src/chat/message-ui/ChatInput.tsx +5 -4
- package/src/chat/message-ui/ChatMarkdown.tsx +2 -2
- package/src/chat/message-ui/ChatUserMessage.tsx +3 -3
- package/src/chat/tool-ui/BackgroundTasksBar.tsx +3 -3
- package/src/chat/tool-ui/CallAgentToolUI.tsx +2 -2
- package/src/chat/tool-ui/ChatToolCall.tsx +3 -3
- package/src/chat/tool-ui/ReadSkillToolUI.tsx +2 -2
- package/src/chat/tool-ui/RunJsToolUI.tsx +1 -1
- package/src/chat/tool-ui/ToolUiBadge.tsx +1 -1
- package/src/chat/tool-ui/WebFetchToolUI.tsx +1 -1
- package/src/checkbox/Checkbox.tsx +2 -2
- package/src/codeblock/CodeBlock.tsx +2 -2
- package/src/colorpicker/ColorPicker.tsx +10 -8
- package/src/datepicker/DatePicker.tsx +3 -3
- package/src/desktop/DesktopHeader.tsx +2 -2
- package/src/desktop/DesktopStage.tsx +1 -1
- package/src/desktop/DesktopWindow.tsx +3 -3
- package/src/desktop/MeadowDesktop.tsx +2 -2
- package/src/drawer/Drawer.tsx +6 -2
- package/src/dropdown/menuClasses.ts +1 -1
- package/src/empty/Empty.tsx +1 -1
- package/src/form/variants/FieldRadio.tsx +1 -1
- package/src/form/variants/FieldRepeaterItem.tsx +1 -1
- package/src/index.ts +7 -5
- package/src/input/EditableInput.tsx +3 -2
- package/src/input/Input.tsx +15 -7
- package/src/lib/sizes.ts +6 -6
- package/src/lib/surface.ts +14 -4
- package/src/markdown-editor/MarkdownDiff.tsx +4 -4
- package/src/markdown-editor/MarkdownPreview.tsx +6 -6
- package/src/markdown-editor/MarkdownSource.tsx +1 -1
- package/src/markdown-editor/MarkdownTable.tsx +2 -2
- package/src/markdown-editor/MarkdownViewer.tsx +54 -56
- package/src/markdown-editor/MermaidBlock.tsx +2 -2
- package/src/markdown-editor/ReactCode.tsx +6 -7
- package/src/markdown-editor/ReactCodeFrame.tsx +45 -15
- package/src/markdown-editor/ReactCodeSandbox.tsx +1 -1
- package/src/markdown-editor/markdownScale.ts +149 -0
- package/src/menu/Menu.tsx +1 -1
- package/src/message/message.tsx +18 -8
- package/src/modal/Modal.tsx +13 -7
- package/src/pagination/Pagination.tsx +3 -3
- package/src/popover/Popover.tsx +1 -1
- package/src/scroll/OverlayScroll.tsx +2 -2
- package/src/segmented/Segmented.tsx +1 -1
- package/src/select/Select.tsx +4 -4
- package/src/sidebar/Sidebar.tsx +35 -32
- package/src/skeleton/Skeleton.tsx +4 -4
- package/src/spin/Spin.tsx +14 -2
- package/src/splitter/Splitter.tsx +1 -1
- package/src/styles.css +171 -813
- package/src/table/Table.tsx +12 -12
- package/src/tabs/Tabs.tsx +261 -0
- package/src/tag/Tag.tsx +16 -16
- package/src/theme.ts +53 -232
- package/src/timepicker/TimePicker.tsx +2 -2
- package/src/typography/Typography.tsx +41 -35
package/src/table/Table.tsx
CHANGED
|
@@ -394,7 +394,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
394
394
|
setThumbInset((prev) => (prev === next ? prev : next));
|
|
395
395
|
}, [headSticky, showHeader, size, flexLayout]);
|
|
396
396
|
/** Opaque fill so a sticky header does not show body text, and every header matches. */
|
|
397
|
-
const headBg: CSSProperties = { backgroundColor: "var(--nonla-
|
|
397
|
+
const headBg: CSSProperties = { backgroundColor: "var(--nonla-fill)" };
|
|
398
398
|
|
|
399
399
|
const colStyle = (col: ColumnType<T>, key: string): CSSProperties => {
|
|
400
400
|
const measured = flexLayout?.cols[key];
|
|
@@ -406,7 +406,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
406
406
|
<div className={cn("relative w-full", className)}>
|
|
407
407
|
{titleNode != null ? <div className="mb-3 text-sm font-medium text-foreground">{titleNode}</div> : null}
|
|
408
408
|
|
|
409
|
-
<div className={cn(bordered && "overflow-hidden rounded-xl border border-
|
|
409
|
+
<div className={cn(bordered && "overflow-hidden rounded-xl border border-border-secondary")}>
|
|
410
410
|
<Spin spinning={Boolean(loading)}>
|
|
411
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}>
|
|
412
412
|
<TableBodyScroll y={scroll?.y} x={scroll?.x} scrollRef={scrollBodyRef} insetTop={thumbInset}>
|
|
@@ -421,10 +421,10 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
421
421
|
</colgroup>
|
|
422
422
|
) : null}
|
|
423
423
|
{showHeader ? (
|
|
424
|
-
<thead data-slot="table-header" className={cn("[&_tr]:border-b [&_tr]:border-
|
|
425
|
-
<tr data-slot="table-row" className="border-b border-
|
|
424
|
+
<thead data-slot="table-header" className={cn("[&_tr]:border-b [&_tr]:border-border-secondary", headSticky && "relative z-20")}>
|
|
425
|
+
<tr data-slot="table-row" className="border-b border-border-secondary transition-colors hover:bg-transparent">
|
|
426
426
|
{rowSelection ? (
|
|
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-
|
|
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-border-secondary", bordered && "border-b border-border-secondary")} style={{ ...(selectionColWidth != null ? { width: selectionColWidth } : undefined), ...headBg }}>
|
|
428
428
|
<div className="flex items-center justify-center">
|
|
429
429
|
{rowSelection.type === "radio" ? null : (
|
|
430
430
|
<Checkbox
|
|
@@ -449,7 +449,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
449
449
|
<th
|
|
450
450
|
key={key}
|
|
451
451
|
data-slot="table-head"
|
|
452
|
-
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-border-secondary", flexLayout && flexWeight(col) > 0 ? "min-w-0" : "whitespace-nowrap", alignClass(col.align), bordered && "border-b border-border-secondary", sortable && "cursor-pointer select-none", col.className, headerExtra?.className)}
|
|
453
453
|
style={{
|
|
454
454
|
...colStyle(col, key),
|
|
455
455
|
...headBg,
|
|
@@ -470,7 +470,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
470
470
|
|
|
471
471
|
<tbody data-slot="table-body" className={cn("[&_tr:last-child]:border-0", headSticky && "relative z-0")}>
|
|
472
472
|
{pageData.length === 0 ? (
|
|
473
|
-
<tr data-slot="table-row" className="border-b border-
|
|
473
|
+
<tr data-slot="table-row" className="border-b border-border-secondary">
|
|
474
474
|
<td data-slot="table-cell" colSpan={colCount} className={cn(sz.cell, "text-center align-middle")}>
|
|
475
475
|
{locale?.emptyText ?? <Empty description="No data" className="py-10" />}
|
|
476
476
|
</td>
|
|
@@ -489,7 +489,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
489
489
|
key={key}
|
|
490
490
|
data-slot="table-row"
|
|
491
491
|
data-state={selected ? "selected" : undefined}
|
|
492
|
-
className={cn("border-b border-
|
|
492
|
+
className={cn("border-b border-border-secondary transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted", inSelectionMode && !rowDisabled && "cursor-pointer", rowProps?.className, extraClass)}
|
|
493
493
|
style={rowProps?.style}
|
|
494
494
|
onClick={inSelectionMode ? undefined : rowProps?.onClick}
|
|
495
495
|
onClickCapture={
|
|
@@ -506,7 +506,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
506
506
|
}
|
|
507
507
|
>
|
|
508
508
|
{rowSelection ? (
|
|
509
|
-
<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-border-secondary")} style={selectionColWidth != null ? { width: selectionColWidth } : undefined} onClick={(e) => e.stopPropagation()}>
|
|
510
510
|
<div className="flex items-center justify-center">
|
|
511
511
|
{rowSelection.type === "radio" ? (
|
|
512
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])} />
|
|
@@ -531,7 +531,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
531
531
|
<td
|
|
532
532
|
key={getColumnKey(col, i)}
|
|
533
533
|
data-slot="table-cell"
|
|
534
|
-
className={cn(sz.cell, "align-middle", headSticky && "border-b border-
|
|
534
|
+
className={cn(sz.cell, "align-middle", headSticky && "border-b border-border-secondary", 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)}
|
|
535
535
|
style={colStyle(col, getColumnKey(col, i))}
|
|
536
536
|
title={col.ellipsis && (typeof content === "string" || typeof content === "number") ? String(content) : undefined}
|
|
537
537
|
>
|
|
@@ -546,7 +546,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
546
546
|
</tbody>
|
|
547
547
|
|
|
548
548
|
{footerNode != null ? (
|
|
549
|
-
<tfoot data-slot="table-footer" className="border-t border-
|
|
549
|
+
<tfoot data-slot="table-footer" className="border-t border-border-secondary bg-muted/50 font-medium [&>tr]:last:border-b-0">
|
|
550
550
|
<tr>
|
|
551
551
|
<td colSpan={colCount} className={cn(sz.cell, "align-middle text-muted-foreground")}>
|
|
552
552
|
{footerNode}
|
|
@@ -560,7 +560,7 @@ export function Table<T extends object = Record<string, unknown>>({ columns = []
|
|
|
560
560
|
</Spin>
|
|
561
561
|
|
|
562
562
|
{showPagination ? (
|
|
563
|
-
<div className={cn("flex flex-wrap items-center justify-between gap-3 px-3 py-2", bordered && "border-t border-
|
|
563
|
+
<div className={cn("flex flex-wrap items-center justify-between gap-3 px-3 py-2", bordered && "border-t border-border-secondary", pageConfig.className)}>
|
|
564
564
|
<div className="flex items-center gap-3">
|
|
565
565
|
{pageConfig.showSizeChanger !== false ? (
|
|
566
566
|
<Select
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { type CSSProperties, type KeyboardEvent, type ReactNode, useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { SolarIcon } from "../icon/SolarIcon";
|
|
3
|
+
import { solarIconName } from "../icon/solar";
|
|
4
|
+
import { cn } from "../lib/cn";
|
|
5
|
+
|
|
6
|
+
export type TabsItem = {
|
|
7
|
+
key: string;
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Solar icon name (`settings`), a legacy Fluent Color id (`settings-24`), or a node. */
|
|
12
|
+
icon?: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type TabsProps = {
|
|
16
|
+
items: TabsItem[];
|
|
17
|
+
activeKey?: string;
|
|
18
|
+
defaultActiveKey?: string;
|
|
19
|
+
onChange?: (key: string) => void;
|
|
20
|
+
className?: string;
|
|
21
|
+
style?: CSSProperties;
|
|
22
|
+
"aria-label"?: string;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** Chevron sits in the clear zone. Tabs scroll in past the fade. */
|
|
26
|
+
const FADE = 32;
|
|
27
|
+
const EDGE = 64;
|
|
28
|
+
const TAB_HEIGHT = 40;
|
|
29
|
+
|
|
30
|
+
type Ink = { left: number; width: number };
|
|
31
|
+
type Overflow = { left: boolean; right: boolean };
|
|
32
|
+
|
|
33
|
+
function firstEnabled(items: TabsItem[], preferred?: string) {
|
|
34
|
+
if (preferred && items.some((item) => item.key === preferred)) return preferred;
|
|
35
|
+
return items.find((item) => !item.disabled)?.key ?? items[0]?.key ?? "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function fadeOf(overflow: Overflow): "left" | "right" | "both" | "none" {
|
|
39
|
+
if (overflow.left && overflow.right) return "both";
|
|
40
|
+
if (overflow.left) return "left";
|
|
41
|
+
if (overflow.right) return "right";
|
|
42
|
+
return "none";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function maskImage(fade: ReturnType<typeof fadeOf>) {
|
|
46
|
+
if (fade === "left") return `linear-gradient(to right, transparent ${FADE}px, #000 ${EDGE}px)`;
|
|
47
|
+
if (fade === "right") return `linear-gradient(to left, transparent ${FADE}px, #000 ${EDGE}px)`;
|
|
48
|
+
if (fade === "both") return `linear-gradient(to right, transparent ${FADE}px, #000 ${EDGE}px, #000 calc(100% - ${EDGE}px), transparent calc(100% - ${FADE}px))`;
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function scrollToX(el: HTMLElement, target: number) {
|
|
53
|
+
const max = Math.max(0, el.scrollWidth - el.clientWidth);
|
|
54
|
+
el.scrollLeft = Math.min(max, Math.max(0, target));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function TabIcon({ icon, size }: { icon?: ReactNode; size: number }) {
|
|
58
|
+
if (icon == null || icon === false) return null;
|
|
59
|
+
if (typeof icon === "string") return <SolarIcon name={solarIconName(icon)} size={size} />;
|
|
60
|
+
return <span className="inline-flex shrink-0 items-center justify-center">{icon}</span>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function ScrollButton({ dir, onClick }: { dir: "left" | "right"; onClick: () => void }) {
|
|
64
|
+
return (
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
aria-label={dir === "left" ? "Scroll tabs left" : "Scroll tabs right"}
|
|
68
|
+
className={cn(
|
|
69
|
+
"absolute top-0 z-10 flex h-full w-8 cursor-pointer items-center justify-center border-0 bg-transparent text-tertiary-foreground hover:text-foreground",
|
|
70
|
+
dir === "left" ? "left-0" : "right-0",
|
|
71
|
+
)}
|
|
72
|
+
onClick={onClick}
|
|
73
|
+
>
|
|
74
|
+
<SolarIcon name={dir === "left" ? "alt-arrow-left-linear" : "alt-arrow-right-linear"} size={16} />
|
|
75
|
+
</button>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function Tabs({ items, activeKey, defaultActiveKey, onChange, className, style, "aria-label": ariaLabel = "Tabs" }: TabsProps) {
|
|
80
|
+
const uid = useId();
|
|
81
|
+
|
|
82
|
+
const [inner, setInner] = useState(() => firstEnabled(items, defaultActiveKey));
|
|
83
|
+
const active = firstEnabled(items, activeKey ?? inner);
|
|
84
|
+
const itemsKey = items.map((item) => item.key).join("\0");
|
|
85
|
+
|
|
86
|
+
const scrollerRef = useRef<HTMLDivElement>(null);
|
|
87
|
+
const rowRef = useRef<HTMLDivElement>(null);
|
|
88
|
+
const tabRefs = useRef(new Map<string, HTMLButtonElement>());
|
|
89
|
+
const focusKey = useRef<string | null>(null);
|
|
90
|
+
|
|
91
|
+
const [ink, setInk] = useState<Ink | null>(null);
|
|
92
|
+
const [overflow, setOverflow] = useState<Overflow>({ left: false, right: false });
|
|
93
|
+
|
|
94
|
+
const updateOverflow = useCallback(() => {
|
|
95
|
+
const el = scrollerRef.current;
|
|
96
|
+
if (!el) return;
|
|
97
|
+
const max = el.scrollWidth - el.clientWidth;
|
|
98
|
+
const left = el.scrollLeft > 1;
|
|
99
|
+
const right = max > 1 && el.scrollLeft < max - 1;
|
|
100
|
+
setOverflow((prev) => (prev.left === left && prev.right === right ? prev : { left, right }));
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
const reveal = useCallback(() => {
|
|
104
|
+
const scroller = scrollerRef.current;
|
|
105
|
+
const tab = tabRefs.current.get(active);
|
|
106
|
+
if (!scroller || !tab) return;
|
|
107
|
+
const max = scroller.scrollWidth - scroller.clientWidth;
|
|
108
|
+
if (max <= 1) return;
|
|
109
|
+
const left = tab.offsetLeft;
|
|
110
|
+
const right = left + tab.offsetWidth;
|
|
111
|
+
const viewLeft = scroller.scrollLeft + EDGE;
|
|
112
|
+
const viewRight = scroller.scrollLeft + scroller.clientWidth - EDGE;
|
|
113
|
+
if (left < viewLeft) scrollToX(scroller, left - EDGE);
|
|
114
|
+
else if (right > viewRight) scrollToX(scroller, right - scroller.clientWidth + EDGE);
|
|
115
|
+
updateOverflow();
|
|
116
|
+
}, [active, updateOverflow]);
|
|
117
|
+
|
|
118
|
+
useLayoutEffect(() => {
|
|
119
|
+
const row = rowRef.current;
|
|
120
|
+
const measure = () => {
|
|
121
|
+
const el = tabRefs.current.get(active);
|
|
122
|
+
if (!el) {
|
|
123
|
+
setInk(null);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const next = { left: el.offsetLeft, width: el.offsetWidth };
|
|
127
|
+
setInk((prev) => (prev && prev.left === next.left && prev.width === next.width ? prev : next));
|
|
128
|
+
updateOverflow();
|
|
129
|
+
};
|
|
130
|
+
measure();
|
|
131
|
+
const ro = new ResizeObserver(measure);
|
|
132
|
+
if (row) ro.observe(row);
|
|
133
|
+
if (scrollerRef.current) ro.observe(scrollerRef.current);
|
|
134
|
+
return () => ro.disconnect();
|
|
135
|
+
}, [active, itemsKey, updateOverflow]);
|
|
136
|
+
|
|
137
|
+
useLayoutEffect(() => {
|
|
138
|
+
reveal();
|
|
139
|
+
}, [active, itemsKey, reveal]);
|
|
140
|
+
|
|
141
|
+
useLayoutEffect(() => {
|
|
142
|
+
const key = focusKey.current;
|
|
143
|
+
if (!key || key !== active) return;
|
|
144
|
+
focusKey.current = null;
|
|
145
|
+
tabRefs.current.get(key)?.focus({ preventScroll: true });
|
|
146
|
+
}, [active]);
|
|
147
|
+
|
|
148
|
+
useEffect(() => {
|
|
149
|
+
const el = scrollerRef.current;
|
|
150
|
+
if (!el) return;
|
|
151
|
+
const onWheel = (event: WheelEvent) => {
|
|
152
|
+
if (el.scrollWidth <= el.clientWidth + 1) return;
|
|
153
|
+
if (Math.abs(event.deltaX) >= Math.abs(event.deltaY)) return;
|
|
154
|
+
if (event.deltaY === 0) return;
|
|
155
|
+
const max = el.scrollWidth - el.clientWidth;
|
|
156
|
+
const next = Math.min(max, Math.max(0, el.scrollLeft + event.deltaY));
|
|
157
|
+
if (next === el.scrollLeft) return;
|
|
158
|
+
el.scrollLeft = next;
|
|
159
|
+
updateOverflow();
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
};
|
|
162
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
163
|
+
return () => el.removeEventListener("wheel", onWheel);
|
|
164
|
+
}, [itemsKey, updateOverflow]);
|
|
165
|
+
|
|
166
|
+
function select(key: string, fromKeyboard = false) {
|
|
167
|
+
if (fromKeyboard) focusKey.current = key;
|
|
168
|
+
if (activeKey === undefined) setInner(key);
|
|
169
|
+
if (key !== active) onChange?.(key);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function nudge(dir: -1 | 1) {
|
|
173
|
+
const el = scrollerRef.current;
|
|
174
|
+
if (!el) return;
|
|
175
|
+
const step = dir * Math.max(96, Math.round(el.clientWidth * 0.72));
|
|
176
|
+
scrollToX(el, el.scrollLeft + step);
|
|
177
|
+
updateOverflow();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function onKeyDown(event: KeyboardEvent<HTMLDivElement>) {
|
|
181
|
+
const enabled = items.filter((item) => !item.disabled);
|
|
182
|
+
if (!enabled.length) return;
|
|
183
|
+
const index = enabled.findIndex((item) => item.key === active);
|
|
184
|
+
let next = -1;
|
|
185
|
+
if (event.key === "ArrowRight") next = index < 0 ? 0 : (index + 1) % enabled.length;
|
|
186
|
+
else if (event.key === "ArrowLeft") next = index < 0 ? enabled.length - 1 : (index - 1 + enabled.length) % enabled.length;
|
|
187
|
+
else if (event.key === "Home") next = 0;
|
|
188
|
+
else if (event.key === "End") next = enabled.length - 1;
|
|
189
|
+
else return;
|
|
190
|
+
event.preventDefault();
|
|
191
|
+
const item = enabled[next];
|
|
192
|
+
if (item) select(item.key, true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const fade = fadeOf(overflow);
|
|
196
|
+
const mask = maskImage(fade);
|
|
197
|
+
const panel = items.find((item) => item.key === active);
|
|
198
|
+
const showPanel = items.some((item) => item.children != null);
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<div className={cn("w-full min-w-0", className)} style={style}>
|
|
202
|
+
<div className="relative">
|
|
203
|
+
<div aria-hidden className="pointer-events-none absolute inset-x-0 bottom-0 h-px bg-border" />
|
|
204
|
+
<div
|
|
205
|
+
ref={scrollerRef}
|
|
206
|
+
className="relative overflow-x-auto overflow-y-hidden overscroll-x-contain [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden [&::-webkit-scrollbar]:h-0 [&::-webkit-scrollbar]:w-0"
|
|
207
|
+
style={mask ? { maskImage: mask, WebkitMaskImage: mask } : undefined}
|
|
208
|
+
onScroll={updateOverflow}
|
|
209
|
+
>
|
|
210
|
+
<div ref={rowRef} role="tablist" aria-label={ariaLabel} aria-orientation="horizontal" className="relative flex w-max gap-3" onKeyDown={onKeyDown}>
|
|
211
|
+
{ink ? <span aria-hidden className="pointer-events-none absolute bottom-0 left-0 z-1 h-0.5 rounded-t-xs bg-brand transition-[transform,width] duration-380 ease-[cubic-bezier(0.3,1.25,0.5,1)] motion-reduce:transition-none" style={{ width: ink.width, transform: `translateX(${ink.left}px)` }} /> : null}
|
|
212
|
+
{items.map((item) => {
|
|
213
|
+
const selected = item.key === active;
|
|
214
|
+
return (
|
|
215
|
+
<button
|
|
216
|
+
key={item.key}
|
|
217
|
+
ref={(node) => {
|
|
218
|
+
if (node) tabRefs.current.set(item.key, node);
|
|
219
|
+
else tabRefs.current.delete(item.key);
|
|
220
|
+
}}
|
|
221
|
+
type="button"
|
|
222
|
+
role="tab"
|
|
223
|
+
id={`${uid}-tab-${item.key}`}
|
|
224
|
+
aria-selected={selected}
|
|
225
|
+
aria-controls={showPanel ? `${uid}-panel` : undefined}
|
|
226
|
+
tabIndex={selected ? 0 : -1}
|
|
227
|
+
disabled={item.disabled}
|
|
228
|
+
className={cn(
|
|
229
|
+
"relative z-10 inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap border-0 bg-transparent font-normal text-tertiary-foreground transition-colors select-none",
|
|
230
|
+
"hover:text-foreground focus-visible:ring-brand/55 focus-visible:ring-2 focus-visible:outline-none focus-visible:ring-inset",
|
|
231
|
+
"disabled:cursor-not-allowed disabled:opacity-40",
|
|
232
|
+
selected && "text-foreground",
|
|
233
|
+
)}
|
|
234
|
+
style={{
|
|
235
|
+
height: TAB_HEIGHT,
|
|
236
|
+
paddingLeft: 4,
|
|
237
|
+
paddingRight: 4,
|
|
238
|
+
fontSize: 14,
|
|
239
|
+
}}
|
|
240
|
+
onClick={() => {
|
|
241
|
+
if (!item.disabled) select(item.key);
|
|
242
|
+
}}
|
|
243
|
+
>
|
|
244
|
+
<TabIcon icon={item.icon} size={16} />
|
|
245
|
+
{item.label}
|
|
246
|
+
</button>
|
|
247
|
+
);
|
|
248
|
+
})}
|
|
249
|
+
</div>
|
|
250
|
+
</div>
|
|
251
|
+
{overflow.left ? <ScrollButton dir="left" onClick={() => nudge(-1)} /> : null}
|
|
252
|
+
{overflow.right ? <ScrollButton dir="right" onClick={() => nudge(1)} /> : null}
|
|
253
|
+
</div>
|
|
254
|
+
{showPanel ? (
|
|
255
|
+
<div role="tabpanel" id={`${uid}-panel`} aria-labelledby={`${uid}-tab-${active}`} className="pt-3">
|
|
256
|
+
{panel?.children}
|
|
257
|
+
</div>
|
|
258
|
+
) : null}
|
|
259
|
+
</div>
|
|
260
|
+
);
|
|
261
|
+
}
|
package/src/tag/Tag.tsx
CHANGED
|
@@ -27,23 +27,23 @@ const NAMED_VAR: Record<string, string> = {
|
|
|
27
27
|
warning: "var(--warn)",
|
|
28
28
|
processing: "var(--link)",
|
|
29
29
|
brand: "var(--brand)",
|
|
30
|
-
blue: "
|
|
31
|
-
purple: "
|
|
32
|
-
cyan: "
|
|
33
|
-
green: "
|
|
34
|
-
magenta: "
|
|
35
|
-
pink: "
|
|
36
|
-
orange: "
|
|
37
|
-
gold: "
|
|
38
|
-
red: "
|
|
39
|
-
yellow: "
|
|
40
|
-
volcano: "
|
|
41
|
-
geekblue: "
|
|
42
|
-
lime: "
|
|
30
|
+
blue: "light-dark(#3b7fc4, #7bafe9)",
|
|
31
|
+
purple: "light-dark(#6d5bd0, #9386f2)",
|
|
32
|
+
cyan: "light-dark(#3d6a8c, #81a1c1)",
|
|
33
|
+
green: "light-dark(#2f7d4a, #3fa266)",
|
|
34
|
+
magenta: "light-dark(#9a5f8a, #b48ead)",
|
|
35
|
+
pink: "light-dark(#9a5f8a, #b48ead)",
|
|
36
|
+
orange: "light-dark(#c2613f, #d08770)",
|
|
37
|
+
gold: "light-dark(#a16207, #f1b467)",
|
|
38
|
+
red: "light-dark(#e23b57, #fc6b83)",
|
|
39
|
+
yellow: "light-dark(#a16207, #f1b467)",
|
|
40
|
+
volcano: "light-dark(#e23b57, #fc6b83)",
|
|
41
|
+
geekblue: "light-dark(#3b7fc4, #7bafe9)",
|
|
42
|
+
lime: "light-dark(#3d8f5c, #70b489)",
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const SOFT = "bg-[color-mix(in_oklab,var(--nonla-tag)_12%,transparent)] text-[color-mix(in_oklab,var(--nonla-tag)_72%,black)]";
|
|
46
|
-
const SOLID = "bg-(--nonla-tag) text-[var(--nonla-solid
|
|
46
|
+
const SOLID = "bg-(--nonla-tag) text-[var(--nonla-text-on-solid)]";
|
|
47
47
|
|
|
48
48
|
function resolveVariant(variant: TagProps["variant"]): TagVariant {
|
|
49
49
|
if (variant === "solid") return "solid";
|
|
@@ -79,7 +79,7 @@ export function Tag({
|
|
|
79
79
|
<span
|
|
80
80
|
className={cn(
|
|
81
81
|
"inline-flex h-5.5 max-w-full items-center gap-1.5 rounded-full px-2.5 text-[11px] font-medium tracking-[0.01em]",
|
|
82
|
-
isDefault && (solid ? "bg-foreground/10 text-
|
|
82
|
+
isDefault && (solid ? "bg-foreground/10 text-foreground" : "bg-muted text-muted-foreground"),
|
|
83
83
|
!isDefault && (solid ? SOLID : SOFT),
|
|
84
84
|
className,
|
|
85
85
|
)}
|
|
@@ -87,7 +87,7 @@ export function Tag({
|
|
|
87
87
|
>
|
|
88
88
|
{showDot ? (
|
|
89
89
|
<span
|
|
90
|
-
className={cn("size-1.5 shrink-0 rounded-full", isDefault ? "bg-(--nonla-
|
|
90
|
+
className={cn("size-1.5 shrink-0 rounded-full", isDefault ? "bg-(--nonla-text-secondary)" : "bg-(--nonla-tag)")}
|
|
91
91
|
aria-hidden
|
|
92
92
|
/>
|
|
93
93
|
) : null}
|