@oaiz/app-kit 0.1.4233 → 0.1.4246
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -137,6 +137,9 @@ The package holds no font files. The theme's `font-sans` is the device's system
|
|
|
137
137
|
accordion uses `font-inter`, which names the Inter typeface first; install and load Inter yourself
|
|
138
138
|
if you want it, otherwise the browser falls back to the system fonts.
|
|
139
139
|
|
|
140
|
+
To give `Heading` and `AppShell` titles a different family, set `--role-heading-font` in your
|
|
141
|
+
app theme's `:root`. Headings use `font-sans` by default, and body text keeps its own font.
|
|
142
|
+
|
|
140
143
|
## Source and provenance
|
|
141
144
|
|
|
142
145
|
The source is in the `app-kit/` folder of [oaiz-io/oaiz-sdk](https://github.com/oaiz-io/oaiz-sdk).
|
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useId,
|
|
3
|
+
useRef,
|
|
4
|
+
useState,
|
|
5
|
+
type CSSProperties,
|
|
6
|
+
type MouseEvent,
|
|
7
|
+
type ReactNode,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import { Menu, Search } from 'lucide-react';
|
|
3
10
|
|
|
4
11
|
import { useTheme, type ThemeChoice } from '../hooks/use-theme';
|
|
@@ -231,18 +238,37 @@ function NavList({
|
|
|
231
238
|
);
|
|
232
239
|
}
|
|
233
240
|
|
|
234
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* With `iconOnPhone`, a phone shows the search icon alone, so a narrow header keeps room for its
|
|
243
|
+
* title. `compact` is an icon-only button with a full touch target, for a header beside bottom tabs.
|
|
244
|
+
*/
|
|
235
245
|
function SearchButton({
|
|
236
246
|
onSearch,
|
|
237
247
|
iconOnPhone = false,
|
|
248
|
+
compact = false,
|
|
238
249
|
label,
|
|
239
250
|
className,
|
|
240
251
|
}: {
|
|
241
|
-
onSearch: () => void;
|
|
252
|
+
onSearch: (event: MouseEvent<HTMLButtonElement>) => void;
|
|
242
253
|
iconOnPhone?: boolean;
|
|
254
|
+
compact?: boolean;
|
|
243
255
|
label: string;
|
|
244
256
|
className?: string;
|
|
245
257
|
}) {
|
|
258
|
+
if (compact) {
|
|
259
|
+
return (
|
|
260
|
+
<Button
|
|
261
|
+
variant="ghost"
|
|
262
|
+
size={null}
|
|
263
|
+
type="button"
|
|
264
|
+
aria-label={label}
|
|
265
|
+
onClick={onSearch}
|
|
266
|
+
className={cn('size-[var(--touch-target-min)] shrink-0', className)}
|
|
267
|
+
>
|
|
268
|
+
<Search aria-hidden="true" />
|
|
269
|
+
</Button>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
246
272
|
return (
|
|
247
273
|
<Button variant="plain" size={null}
|
|
248
274
|
type="button"
|
|
@@ -358,6 +384,8 @@ export function AppShell({
|
|
|
358
384
|
const contentId = mainId ?? generatedMainId;
|
|
359
385
|
const mainRef = useRef<HTMLElement>(null);
|
|
360
386
|
const menuRef = useRef<HTMLButtonElement>(null);
|
|
387
|
+
// The header search beside bottom tabs, while it has the palette open; the palette has no trigger.
|
|
388
|
+
const searchOpenerRef = useRef<HTMLButtonElement | null>(null);
|
|
361
389
|
const [navOpen, setNavOpen] = useState(false);
|
|
362
390
|
const [paletteOpen, setPaletteOpen] = useState(false);
|
|
363
391
|
const theme = useTheme();
|
|
@@ -365,10 +393,16 @@ export function AppShell({
|
|
|
365
393
|
const hasSidebar = navItems.length > 1;
|
|
366
394
|
const tabs = phoneNav === 'tabs' && hasSidebar && navItems.length <= 5;
|
|
367
395
|
const search = commands ? () => setPaletteOpen(true) : onSearch;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
396
|
+
const phoneSearch = tabs && search;
|
|
397
|
+
useHotkey(
|
|
398
|
+
'k',
|
|
399
|
+
() => {
|
|
400
|
+
// Reopening can happen before the previous close autofocus runs.
|
|
401
|
+
if (!paletteOpen) searchOpenerRef.current = null;
|
|
402
|
+
setPaletteOpen((open) => !open);
|
|
403
|
+
},
|
|
404
|
+
{ mod: true, enabled: commands !== undefined },
|
|
405
|
+
);
|
|
372
406
|
|
|
373
407
|
return (
|
|
374
408
|
<div
|
|
@@ -392,6 +426,16 @@ export function AppShell({
|
|
|
392
426
|
onOpenChange={setPaletteOpen}
|
|
393
427
|
groups={[...commands, navCommands(nav, messages.goTo)]}
|
|
394
428
|
onSearchChange={onCommandSearch}
|
|
429
|
+
onCloseAutoFocus={(event) => {
|
|
430
|
+
const opener = searchOpenerRef.current;
|
|
431
|
+
searchOpenerRef.current = null;
|
|
432
|
+
// Preserve focus set by the command.
|
|
433
|
+
const active = document.activeElement;
|
|
434
|
+
if (active !== null && active !== document.body) return;
|
|
435
|
+
if (!opener || opener.getClientRects().length === 0) return;
|
|
436
|
+
event.preventDefault();
|
|
437
|
+
opener.focus();
|
|
438
|
+
}}
|
|
395
439
|
/>
|
|
396
440
|
)}
|
|
397
441
|
{hasSidebar && (
|
|
@@ -460,6 +504,7 @@ export function AppShell({
|
|
|
460
504
|
<header
|
|
461
505
|
className={cn(
|
|
462
506
|
'flex h-11 shrink-0 items-center gap-inline border-b',
|
|
507
|
+
phoneSearch && 'max-half:h-auto max-half:py-1',
|
|
463
508
|
width === 'narrow'
|
|
464
509
|
? 'px-[max(var(--spacing-page),calc((100%-48rem)/2))]'
|
|
465
510
|
: 'px-page',
|
|
@@ -525,6 +570,17 @@ export function AppShell({
|
|
|
525
570
|
className="w-40"
|
|
526
571
|
/>
|
|
527
572
|
)}
|
|
573
|
+
{phoneSearch && (
|
|
574
|
+
<SearchButton
|
|
575
|
+
compact
|
|
576
|
+
onSearch={(event) => {
|
|
577
|
+
if (commands) searchOpenerRef.current = event.currentTarget;
|
|
578
|
+
phoneSearch();
|
|
579
|
+
}}
|
|
580
|
+
label={messages.search}
|
|
581
|
+
className="half:hidden"
|
|
582
|
+
/>
|
|
583
|
+
)}
|
|
528
584
|
{actions && (
|
|
529
585
|
<div className="flex items-center gap-inline">{actions}</div>
|
|
530
586
|
)}
|
|
@@ -52,6 +52,8 @@ export type CommandPaletteProps = {
|
|
|
52
52
|
context?: ReactNode;
|
|
53
53
|
/** Reports the search text, so the caller can read matching records from OAIZ. */
|
|
54
54
|
onSearchChange?: (search: string) => void;
|
|
55
|
+
/** Runs as the palette closes; prevent its default and focus the control that opened it. */
|
|
56
|
+
onCloseAutoFocus?: (event: Event) => void;
|
|
55
57
|
labels?: Partial<{
|
|
56
58
|
title: string;
|
|
57
59
|
description: string;
|
|
@@ -149,6 +151,7 @@ export function CommandPalette({
|
|
|
149
151
|
empty = 'No results.',
|
|
150
152
|
context,
|
|
151
153
|
onSearchChange,
|
|
154
|
+
onCloseAutoFocus,
|
|
152
155
|
labels,
|
|
153
156
|
}: CommandPaletteProps) {
|
|
154
157
|
const [pages, setPages] = useState<CommandPaletteItem[]>([]);
|
|
@@ -206,6 +209,7 @@ export function CommandPalette({
|
|
|
206
209
|
<DialogContent
|
|
207
210
|
showCloseButton={false}
|
|
208
211
|
overlayClassName="bg-black/20"
|
|
212
|
+
onCloseAutoFocus={onCloseAutoFocus}
|
|
209
213
|
className={cn(
|
|
210
214
|
// A phone docks it at the top, so the keyboard opens below the results.
|
|
211
215
|
'top-[15%] translate-y-0 gap-0 overflow-hidden p-0 max-mobile:top-0',
|
|
@@ -27,7 +27,7 @@ const badgeVariants = cva(
|
|
|
27
27
|
'success-subtle':
|
|
28
28
|
'border-transparent bg-badge-success text-badge-success-foreground font-medium',
|
|
29
29
|
'warning-subtle':
|
|
30
|
-
'border-transparent bg-
|
|
30
|
+
'border-transparent bg-warning-bg-subtle text-warning-text font-medium',
|
|
31
31
|
'destructive-subtle':
|
|
32
32
|
'border-transparent bg-destructive-bg-subtle text-destructive-text font-medium',
|
|
33
33
|
neutral:
|
|
@@ -25,7 +25,7 @@ const LEVEL_DEFAULT_TAG: Record<HeadingLevel, HeadingTag> = {
|
|
|
25
25
|
6: 'h6',
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const headingVariants = cva('font-
|
|
28
|
+
const headingVariants = cva('font-heading text-foreground', {
|
|
29
29
|
variants: {
|
|
30
30
|
size: {
|
|
31
31
|
'5xl': 'text-4xl tracking-tight half:text-5xl',
|
|
@@ -77,6 +77,17 @@
|
|
|
77
77
|
--radius-4xl: initial;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/* Heading's family. An app theme sets --role-heading-font; without it, headings
|
|
81
|
+
use --font-sans. `inline` resolves the role where the heading sits, so a
|
|
82
|
+
scoped override applies; `static` keeps --font-heading readable on :root. */
|
|
83
|
+
:root {
|
|
84
|
+
--role-heading-font: initial;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@theme static inline {
|
|
88
|
+
--font-heading: var(--role-heading-font, var(--font-sans));
|
|
89
|
+
}
|
|
90
|
+
|
|
80
91
|
/* ============================================================================
|
|
81
92
|
PRIMITIVE COLOR SCALE
|
|
82
93
|
|