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/theme.ts
CHANGED
|
@@ -1,159 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Defaults live in `styles.css` on `:root` / `.nonla-ui`.
|
|
5
|
-
* `--brand-50`…`--brand-800` follow `--nonla-brand` (500 = the knob).
|
|
6
|
-
* Consumers retheme without touching components:
|
|
7
|
-
* 1. CSS: `:root { --nonla-brand: #3b82f6; }`
|
|
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.
|
|
10
|
-
* `<ThemeSwitcher>` also stores `system`, which follows the OS and still paints `light` or `dark`.
|
|
2
|
+
* Paint `light` or `dark` on `<html>`. Dark is the default.
|
|
3
|
+
* The stored choice may be `system`, which follows the OS and still paints one of those two.
|
|
11
4
|
*/
|
|
12
5
|
|
|
13
|
-
export const NONLA_THEME_KEYS = {
|
|
14
|
-
bg: "--nonla-bg",
|
|
15
|
-
fg: "--nonla-fg",
|
|
16
|
-
fgMuted: "--nonla-fg-muted",
|
|
17
|
-
fgTertiary: "--nonla-fg-tertiary",
|
|
18
|
-
fgQuaternary: "--nonla-fg-quaternary",
|
|
19
|
-
brand: "--nonla-brand",
|
|
20
|
-
solidFg: "--nonla-solid-fg",
|
|
21
|
-
danger: "--nonla-danger",
|
|
22
|
-
success: "--nonla-success",
|
|
23
|
-
warn: "--nonla-warn",
|
|
24
|
-
link: "--nonla-link",
|
|
25
|
-
radius: "--nonla-radius",
|
|
26
|
-
height: "--nonla-height",
|
|
27
|
-
heightSm: "--nonla-height-sm",
|
|
28
|
-
heightLg: "--nonla-height-lg",
|
|
29
|
-
ink: "--nonla-ink",
|
|
30
|
-
sidebar: "--nonla-sidebar",
|
|
31
|
-
surface: "--nonla-surface",
|
|
32
|
-
elevated: "--nonla-elevated",
|
|
33
|
-
chip: "--nonla-chip",
|
|
34
|
-
chipHover: "--nonla-chip-hover",
|
|
35
|
-
border: "--nonla-border",
|
|
36
|
-
borderInput: "--nonla-input",
|
|
37
|
-
composer: "--nonla-composer",
|
|
38
|
-
chatBg: "--nonla-chat-bg",
|
|
39
|
-
meadow: "--nonla-meadow",
|
|
40
|
-
glass: "--nonla-glass",
|
|
41
|
-
glassBar: "--nonla-glass-bar",
|
|
42
|
-
glassMenu: "--nonla-glass-menu",
|
|
43
|
-
glassBorder: "--nonla-glass-border",
|
|
44
|
-
glassHighlight: "--nonla-glass-highlight",
|
|
45
|
-
inkHover: "--nonla-ink-hover",
|
|
46
|
-
inkActive: "--nonla-ink-active",
|
|
47
|
-
inkLine: "--nonla-ink-line",
|
|
48
|
-
desktopBarHeight: "--nonla-desktop-bar-height",
|
|
49
|
-
windowHeader: "--nonla-window-header",
|
|
50
|
-
zBase: "--nonla-z-base",
|
|
51
|
-
zDesktop: "--nonla-z-desktop",
|
|
52
|
-
zWindow: "--nonla-z-window",
|
|
53
|
-
zHeader: "--nonla-z-header",
|
|
54
|
-
zPopupBase: "--nonla-z-popup-base",
|
|
55
|
-
blue: "--nonla-blue",
|
|
56
|
-
purple: "--nonla-purple",
|
|
57
|
-
cyan: "--nonla-cyan",
|
|
58
|
-
green: "--nonla-green",
|
|
59
|
-
magenta: "--nonla-magenta",
|
|
60
|
-
pink: "--nonla-pink",
|
|
61
|
-
red: "--nonla-red",
|
|
62
|
-
orange: "--nonla-orange",
|
|
63
|
-
yellow: "--nonla-yellow",
|
|
64
|
-
volcano: "--nonla-volcano",
|
|
65
|
-
geekblue: "--nonla-geekblue",
|
|
66
|
-
lime: "--nonla-lime",
|
|
67
|
-
gold: "--nonla-gold",
|
|
68
|
-
} as const;
|
|
69
|
-
|
|
70
|
-
export type NonlaThemeKnobName = keyof typeof NONLA_THEME_KEYS;
|
|
71
|
-
export type NonlaThemeKnob = (typeof NONLA_THEME_KEYS)[NonlaThemeKnobName];
|
|
72
|
-
|
|
73
|
-
const METRIC_KEYS = new Set<NonlaThemeKnobName>(["radius", "height", "heightSm", "heightLg", "desktopBarHeight", "zBase", "zDesktop", "zWindow", "zHeader", "zPopupBase"]);
|
|
74
|
-
|
|
75
|
-
export type NonlaThemeColorName = Exclude<
|
|
76
|
-
NonlaThemeKnobName,
|
|
77
|
-
"radius" | "height" | "heightSm" | "heightLg" | "desktopBarHeight" | "zBase" | "zDesktop" | "zWindow" | "zHeader" | "zPopupBase"
|
|
78
|
-
>;
|
|
79
|
-
export type NonlaThemeColors = { [K in NonlaThemeColorName]?: string };
|
|
80
|
-
|
|
81
|
-
/** Flat aliases → knob name (`colorBorder` == `colors.border`). */
|
|
82
|
-
const COLOR_ALIASES = {
|
|
83
|
-
colorBorder: "border",
|
|
84
|
-
colorBorderInput: "borderInput",
|
|
85
|
-
/** @deprecated use `borderInput` / `colorBorderInput` */
|
|
86
|
-
input: "borderInput",
|
|
87
|
-
} as const satisfies Record<string, NonlaThemeColorName>;
|
|
88
|
-
|
|
89
|
-
export const NONLA_THEME_KNOBS = Object.values(NONLA_THEME_KEYS);
|
|
90
|
-
|
|
91
|
-
export type NonlaThemeConfig = {
|
|
92
|
-
[K in NonlaThemeKnobName]?: string;
|
|
93
|
-
} & {
|
|
94
|
-
/** Grouped color knobs — same names as the flat keys (`colors.border`, `colors.borderInput`, …). */
|
|
95
|
-
colors?: NonlaThemeColors;
|
|
96
|
-
/** Alias of `colors.border` / `border`. */
|
|
97
|
-
colorBorder?: string;
|
|
98
|
-
/** Alias of `colors.borderInput` / `borderInput`. */
|
|
99
|
-
colorBorderInput?: string;
|
|
100
|
-
/** Extra CSS custom properties (include the leading `--`). */
|
|
101
|
-
vars?: Record<string, string>;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
function entriesOf(theme: NonlaThemeConfig): [string, string][] {
|
|
105
|
-
const map = new Map<string, string>();
|
|
106
|
-
const set = (key: string, value: unknown) => {
|
|
107
|
-
if (typeof value !== "string" || !value) return;
|
|
108
|
-
const knob = (COLOR_ALIASES as Record<string, NonlaThemeKnobName>)[key] ?? (key as NonlaThemeKnobName);
|
|
109
|
-
const prop = NONLA_THEME_KEYS[knob];
|
|
110
|
-
if (prop) map.set(prop, value);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
if (theme.colors) {
|
|
114
|
-
for (const [key, value] of Object.entries(theme.colors)) {
|
|
115
|
-
if (METRIC_KEYS.has(key as NonlaThemeKnobName)) continue;
|
|
116
|
-
set(key, value);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
set("colorBorder", theme.colorBorder);
|
|
120
|
-
set("colorBorderInput", theme.colorBorderInput);
|
|
121
|
-
for (const key of Object.keys(NONLA_THEME_KEYS) as NonlaThemeKnobName[]) {
|
|
122
|
-
set(key, theme[key]);
|
|
123
|
-
}
|
|
124
|
-
if (theme.vars) {
|
|
125
|
-
for (const [prop, value] of Object.entries(theme.vars)) {
|
|
126
|
-
if (value) map.set(prop, value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return [...map.entries()];
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export type NonlaTokenSnapshot = { [K in NonlaThemeKnobName]: string };
|
|
133
|
-
|
|
134
|
-
/** Read computed `--nonla-*` knobs (`getDesignToken`). */
|
|
135
|
-
export function getDesignToken(target?: HTMLElement): NonlaTokenSnapshot {
|
|
136
|
-
const el = target ?? (typeof document === "undefined" ? null : document.documentElement);
|
|
137
|
-
const token = {} as NonlaTokenSnapshot;
|
|
138
|
-
for (const name of Object.keys(NONLA_THEME_KEYS) as NonlaThemeKnobName[]) {
|
|
139
|
-
token[name] = el ? getComputedStyle(el).getPropertyValue(NONLA_THEME_KEYS[name]).trim() : "";
|
|
140
|
-
}
|
|
141
|
-
return token;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Apply knobs on an element (defaults to `:root`). Returns a restore function. */
|
|
145
|
-
export function applyNonlaTheme(theme: NonlaThemeConfig, target: HTMLElement = document.documentElement): () => void {
|
|
146
|
-
const entries = entriesOf(theme);
|
|
147
|
-
const prev = entries.map(([prop]) => [prop, target.style.getPropertyValue(prop)] as const);
|
|
148
|
-
for (const [prop, value] of entries) target.style.setProperty(prop, value);
|
|
149
|
-
return () => {
|
|
150
|
-
for (const [prop, value] of prev) {
|
|
151
|
-
if (value) target.style.setProperty(prop, value);
|
|
152
|
-
else target.style.removeProperty(prop);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
6
|
export type NonlaColorMode = "light" | "dark";
|
|
158
7
|
|
|
159
8
|
/** Stored choice. `system` follows the OS and still applies `light` or `dark` on `<html>`. */
|
|
@@ -162,117 +11,90 @@ export type NonlaColorPreference = NonlaColorMode | "system";
|
|
|
162
11
|
/** `localStorage` key written by `setColorMode` / `setColorPreference`. */
|
|
163
12
|
export const NONLA_COLOR_MODE_KEY = "nonla-color-mode";
|
|
164
13
|
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
let colorMode: NonlaColorMode = "dark";
|
|
170
|
-
let colorPreference: NonlaColorPreference = "dark";
|
|
171
|
-
let colorModeReady = false;
|
|
14
|
+
const listeners = new Set<() => void>();
|
|
15
|
+
let mode: NonlaColorMode = "dark";
|
|
16
|
+
let preference: NonlaColorPreference = "dark";
|
|
17
|
+
let ready = false;
|
|
172
18
|
let schemeQuery: MediaQueryList | null = null;
|
|
173
19
|
|
|
174
|
-
|
|
175
|
-
|
|
20
|
+
function notify() {
|
|
21
|
+
for (const listener of listeners) listener();
|
|
176
22
|
}
|
|
177
23
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function subscribeColorMode(listener: () => void) {
|
|
183
|
-
modeListeners.add(listener);
|
|
184
|
-
return () => {
|
|
185
|
-
modeListeners.delete(listener);
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function subscribeColorPreference(listener: () => void) {
|
|
190
|
-
preferenceListeners.add(listener);
|
|
24
|
+
function subscribe(listener: () => void) {
|
|
25
|
+
listeners.add(listener);
|
|
191
26
|
return () => {
|
|
192
|
-
|
|
27
|
+
listeners.delete(listener);
|
|
193
28
|
};
|
|
194
29
|
}
|
|
195
30
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
31
|
+
export const subscribeColorMode = subscribe;
|
|
32
|
+
export const subscribeColorPreference = subscribe;
|
|
199
33
|
|
|
200
|
-
function
|
|
201
|
-
|
|
34
|
+
export function getColorMode(): NonlaColorMode {
|
|
35
|
+
return mode;
|
|
202
36
|
}
|
|
203
37
|
|
|
204
|
-
function
|
|
205
|
-
return
|
|
38
|
+
export function getColorPreference(): NonlaColorPreference {
|
|
39
|
+
return preference;
|
|
206
40
|
}
|
|
207
41
|
|
|
208
|
-
function
|
|
42
|
+
function readStored(): NonlaColorPreference | null {
|
|
209
43
|
try {
|
|
210
44
|
// Sandboxed iframes throw on the property access itself, before getItem.
|
|
211
45
|
const value = localStorage.getItem(NONLA_COLOR_MODE_KEY);
|
|
212
|
-
return
|
|
46
|
+
return value === "light" || value === "dark" || value === "system" ? value : null;
|
|
213
47
|
} catch {
|
|
214
48
|
return null;
|
|
215
49
|
}
|
|
216
50
|
}
|
|
217
51
|
|
|
218
|
-
function
|
|
219
|
-
|
|
220
|
-
|
|
52
|
+
function writeStored(next: NonlaColorPreference) {
|
|
53
|
+
try {
|
|
54
|
+
localStorage.setItem(NONLA_COLOR_MODE_KEY, next);
|
|
55
|
+
} catch {
|
|
56
|
+
/* private mode or sandboxed iframe */
|
|
57
|
+
}
|
|
221
58
|
}
|
|
222
59
|
|
|
223
|
-
function
|
|
224
|
-
|
|
60
|
+
function systemMode(): NonlaColorMode {
|
|
61
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return "dark";
|
|
62
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
225
63
|
}
|
|
226
64
|
|
|
227
|
-
function
|
|
228
|
-
|
|
229
|
-
const next = systemColorMode();
|
|
230
|
-
if (typeof document === "undefined") {
|
|
231
|
-
colorMode = next;
|
|
232
|
-
notifyColorMode();
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
applyColorMode(next);
|
|
65
|
+
function resolved(next: NonlaColorPreference): NonlaColorMode {
|
|
66
|
+
return next === "system" ? systemMode() : next;
|
|
236
67
|
}
|
|
237
68
|
|
|
238
|
-
function
|
|
69
|
+
function watchSystem() {
|
|
239
70
|
if (typeof window === "undefined" || typeof window.matchMedia !== "function" || schemeQuery) return;
|
|
240
|
-
schemeQuery = window.matchMedia(
|
|
241
|
-
schemeQuery.addEventListener("change",
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
function rememberPreference(next: NonlaColorPreference) {
|
|
245
|
-
try {
|
|
246
|
-
localStorage.setItem(NONLA_COLOR_MODE_KEY, next);
|
|
247
|
-
} catch {
|
|
248
|
-
/* private mode */
|
|
249
|
-
}
|
|
71
|
+
schemeQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
72
|
+
schemeQuery.addEventListener("change", () => {
|
|
73
|
+
if (preference === "system") applyColorMode(systemMode());
|
|
74
|
+
});
|
|
250
75
|
}
|
|
251
76
|
|
|
252
77
|
/** Set `light` or `dark` on `target` (default `<html>`) so portals inherit the palette. */
|
|
253
78
|
export function applyColorMode(next: NonlaColorMode, target: HTMLElement = document.documentElement) {
|
|
254
|
-
|
|
79
|
+
mode = next;
|
|
255
80
|
target.classList.toggle("light", next === "light");
|
|
256
81
|
target.classList.toggle("dark", next === "dark");
|
|
257
82
|
target.style.colorScheme = next;
|
|
258
|
-
|
|
83
|
+
notify();
|
|
259
84
|
}
|
|
260
85
|
|
|
261
86
|
/** Switch the stored choice. `system` follows the OS and still paints `light` or `dark`. */
|
|
262
87
|
export function setColorPreference(next: NonlaColorPreference, target?: HTMLElement) {
|
|
263
|
-
|
|
264
|
-
if (next === "system")
|
|
265
|
-
const resolved = resolvedMode(next);
|
|
88
|
+
preference = next;
|
|
89
|
+
if (next === "system") watchSystem();
|
|
266
90
|
if (typeof document === "undefined") {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
notifyColorPreference();
|
|
91
|
+
mode = resolved(next);
|
|
92
|
+
notify();
|
|
270
93
|
return;
|
|
271
94
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
notifyColorPreference();
|
|
95
|
+
ready = true;
|
|
96
|
+
writeStored(next);
|
|
97
|
+
applyColorMode(resolved(next), target);
|
|
276
98
|
}
|
|
277
99
|
|
|
278
100
|
/** Switch mode and remember it. */
|
|
@@ -282,14 +104,13 @@ export function setColorMode(next: NonlaColorMode, target?: HTMLElement) {
|
|
|
282
104
|
|
|
283
105
|
/** Apply the saved mode once. Falls back to dark. A stored `system` choice follows the OS. */
|
|
284
106
|
export function initColorMode(target?: HTMLElement): NonlaColorMode {
|
|
285
|
-
if (typeof document === "undefined") return
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const fromClass =
|
|
289
|
-
const next =
|
|
290
|
-
|
|
291
|
-
if (next === "system")
|
|
292
|
-
applyColorMode(
|
|
293
|
-
|
|
294
|
-
return colorMode;
|
|
107
|
+
if (typeof document === "undefined" || ready) return mode;
|
|
108
|
+
ready = true;
|
|
109
|
+
const root = document.documentElement;
|
|
110
|
+
const fromClass = root.classList.contains("light") ? "light" : root.classList.contains("dark") ? "dark" : null;
|
|
111
|
+
const next = readStored() ?? fromClass ?? "dark";
|
|
112
|
+
preference = next;
|
|
113
|
+
if (next === "system") watchSystem();
|
|
114
|
+
applyColorMode(resolved(next), target);
|
|
115
|
+
return mode;
|
|
295
116
|
}
|
|
@@ -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-quaternary-foreground outline-none disabled:cursor-not-allowed"
|
|
636
636
|
style={{ fontSize: fieldStyle.fontSize, lineHeight: fieldStyle.lineHeight }}
|
|
637
637
|
/>
|
|
638
638
|
{allowClear && selected && !disabled ? (
|
|
@@ -745,7 +745,7 @@ export const TimePicker = forwardRef<HTMLInputElement, TimePickerProps>(function
|
|
|
745
745
|
</div>
|
|
746
746
|
)}
|
|
747
747
|
</div>
|
|
748
|
-
<PopoverPrimitive.Arrow width={12} height={7} className="fill-
|
|
748
|
+
<PopoverPrimitive.Arrow width={12} height={7} className="fill-card drop-shadow-[0_1px_0_var(--border)]" />
|
|
749
749
|
</PopoverPrimitive.Content>
|
|
750
750
|
</PopoverPrimitive.Portal>
|
|
751
751
|
</PopoverPrimitive.Root>
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type AnchorHTMLAttributes, createElement, type HTMLAttributes, type ReactNode } from "react";
|
|
1
|
+
import { type AnchorHTMLAttributes, type CSSProperties, createElement, type HTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
import { cn } from "../lib/cn";
|
|
3
|
+
import { headingClass, markdownBodyClass, markdownParagraphClass, markdownVariantStyle, pageTitleClass } from "../markdown-editor/markdownScale";
|
|
3
4
|
|
|
4
5
|
export type TypographyType = "secondary" | "success" | "warning" | "danger";
|
|
5
6
|
|
|
6
|
-
export type TitleLevel = 1 | 2 | 3 | 4 | 5;
|
|
7
|
+
export type TitleLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
7
8
|
|
|
8
9
|
type Decorations = {
|
|
9
10
|
type?: TypographyType;
|
|
@@ -17,12 +18,18 @@ type Decorations = {
|
|
|
17
18
|
italic?: boolean;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/** Same ink as MarkdownViewer. Status tones sit on top of that. */
|
|
22
|
+
const INK = {
|
|
23
|
+
title: "var(--nonla-text-main)",
|
|
24
|
+
body: "var(--nonla-text-main)",
|
|
25
|
+
secondary: "var(--nonla-text-tertiary)",
|
|
26
|
+
quiet: "var(--nonla-text-quaternary)",
|
|
27
|
+
success: "var(--nonla-success)",
|
|
28
|
+
warning: "var(--nonla-warn)",
|
|
29
|
+
danger: "var(--nonla-danger)",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
type InkRole = "title" | "body";
|
|
26
33
|
|
|
27
34
|
const TITLE_TAG = {
|
|
28
35
|
1: "h1",
|
|
@@ -30,20 +37,15 @@ const TITLE_TAG = {
|
|
|
30
37
|
3: "h3",
|
|
31
38
|
4: "h4",
|
|
32
39
|
5: "h5",
|
|
40
|
+
6: "h6",
|
|
33
41
|
} as const;
|
|
34
42
|
|
|
35
|
-
/**
|
|
36
|
-
const BODY =
|
|
43
|
+
/** Same scale as MarkdownViewer `docs`. Body size is `--nonla-base-text-size`. Inline code reads `--md-inline-size` (14px). */
|
|
44
|
+
const BODY = markdownBodyClass;
|
|
37
45
|
|
|
38
|
-
const
|
|
39
|
-
1: "text-[38px] leading-[46px] font-bold",
|
|
40
|
-
2: "text-[30px] leading-[38px] font-bold",
|
|
41
|
-
3: "text-[24px] leading-[32px] font-semibold",
|
|
42
|
-
4: "text-[20px] leading-[28px] font-semibold",
|
|
43
|
-
5: "text-[16px] leading-[24px] font-semibold",
|
|
44
|
-
};
|
|
46
|
+
const INLINE_CODE = "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]";
|
|
45
47
|
|
|
46
|
-
const TITLE_SPACE = "nonla-typo
|
|
48
|
+
const TITLE_SPACE = "nonla-typo";
|
|
47
49
|
|
|
48
50
|
function decorationLine(underline?: boolean, deleted?: boolean) {
|
|
49
51
|
if (underline && deleted) return "underline line-through";
|
|
@@ -55,10 +57,10 @@ function decorationLine(underline?: boolean, deleted?: boolean) {
|
|
|
55
57
|
function wrapDecorations(children: ReactNode, props: Decorations) {
|
|
56
58
|
let node = children;
|
|
57
59
|
if (props.mark) {
|
|
58
|
-
node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-
|
|
60
|
+
node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-warn)_40%,transparent)] px-0.5 text-inherit">{node}</mark>;
|
|
59
61
|
}
|
|
60
62
|
if (props.code) {
|
|
61
|
-
node = <code className=
|
|
63
|
+
node = <code className={INLINE_CODE}>{node}</code>;
|
|
62
64
|
}
|
|
63
65
|
if (props.keyboard) {
|
|
64
66
|
node = <kbd className="inline-block rounded-md border border-b-2 border-border bg-muted px-1.5 font-mono text-[0.85em] leading-5">{node}</kbd>;
|
|
@@ -66,16 +68,24 @@ function wrapDecorations(children: ReactNode, props: Decorations) {
|
|
|
66
68
|
return node;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
function
|
|
70
|
-
if (disabled) return
|
|
71
|
-
|
|
71
|
+
function rankColor(role: InkRole, props: Decorations): string | undefined {
|
|
72
|
+
if (props.disabled) return INK.quiet;
|
|
73
|
+
if (props.type === "secondary") return INK.secondary;
|
|
74
|
+
if (props.type === "success") return INK.success;
|
|
75
|
+
if (props.type === "warning") return INK.warning;
|
|
76
|
+
if (props.type === "danger") return INK.danger;
|
|
77
|
+
if (role === "title") return INK.title;
|
|
78
|
+
if (role === "body") return INK.body;
|
|
79
|
+
return undefined;
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"]) {
|
|
82
|
+
function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"], role: InkRole = "body") {
|
|
75
83
|
const line = decorationLine(props.underline, props.delete);
|
|
84
|
+
const color = rankColor(role, props);
|
|
85
|
+
const scale: CSSProperties = { ...markdownVariantStyle("docs"), ...(color ? { color } : null), ...(line ? { textDecorationLine: line } : null), ...style };
|
|
76
86
|
return {
|
|
77
|
-
className: cn(base,
|
|
78
|
-
style:
|
|
87
|
+
className: cn(base, props.disabled && "cursor-not-allowed", props.strong && "font-(--md-strong-weight,600)", props.italic && "italic", props.underline && "underline-offset-[3px]", className),
|
|
88
|
+
style: scale,
|
|
79
89
|
children: wrapDecorations(children, props),
|
|
80
90
|
"aria-disabled": props.disabled || undefined,
|
|
81
91
|
};
|
|
@@ -99,7 +109,7 @@ export type TypographyTextProps = Omit<HTMLAttributes<HTMLSpanElement>, "color">
|
|
|
99
109
|
|
|
100
110
|
export function Text({ className, style, children, ...props }: TypographyTextProps) {
|
|
101
111
|
const { decorations, rest } = splitDecorations(props);
|
|
102
|
-
return <span {...rest} {...decorated(decorations, children,
|
|
112
|
+
return <span {...rest} {...decorated(decorations, children, BODY, className, style, "body")} />;
|
|
103
113
|
}
|
|
104
114
|
|
|
105
115
|
export type TypographyTitleProps = Omit<HTMLAttributes<HTMLHeadingElement>, "color"> & Decorations & {
|
|
@@ -109,14 +119,14 @@ export type TypographyTitleProps = Omit<HTMLAttributes<HTMLHeadingElement>, "col
|
|
|
109
119
|
|
|
110
120
|
export function Title({ level = 1, className, style, children, ...props }: TypographyTitleProps) {
|
|
111
121
|
const { decorations, rest } = splitDecorations(props);
|
|
112
|
-
return createElement(TITLE_TAG[level], { ...rest, ...decorated(decorations, children, cn(TITLE_SPACE,
|
|
122
|
+
return createElement(TITLE_TAG[level], { ...rest, ...decorated(decorations, children, cn(TITLE_SPACE, level === 1 ? pageTitleClass : headingClass(level)), className, style, "title") });
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
export type TypographyParagraphProps = Omit<HTMLAttributes<HTMLParagraphElement>, "color"> & Decorations & { children?: ReactNode };
|
|
116
126
|
|
|
117
127
|
export function Paragraph({ className, style, children, ...props }: TypographyParagraphProps) {
|
|
118
128
|
const { decorations, rest } = splitDecorations(props);
|
|
119
|
-
return <p {...rest} {...decorated(decorations, children,
|
|
129
|
+
return <p {...rest} {...decorated(decorations, children, markdownParagraphClass, className, style, "body")} />;
|
|
120
130
|
}
|
|
121
131
|
|
|
122
132
|
export type TypographyLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "color"> & Decorations & { children?: ReactNode };
|
|
@@ -126,14 +136,10 @@ export function Link({ href, target, rel, className, style, children, onClick, .
|
|
|
126
136
|
const view = decorated(
|
|
127
137
|
decorations,
|
|
128
138
|
children,
|
|
129
|
-
cn(
|
|
130
|
-
"cursor-pointer underline-offset-[3px]",
|
|
131
|
-
BODY,
|
|
132
|
-
decorations.type || decorations.disabled ? undefined : "text-brand hover:text-brand-700",
|
|
133
|
-
decorations.disabled || decorations.underline ? undefined : "hover:underline",
|
|
134
|
-
),
|
|
139
|
+
cn("cursor-pointer underline-offset-[3px]", BODY, decorations.disabled || decorations.underline ? undefined : "hover:underline"),
|
|
135
140
|
className,
|
|
136
141
|
style,
|
|
142
|
+
"body",
|
|
137
143
|
);
|
|
138
144
|
|
|
139
145
|
return (
|