@vitavision/ui 0.14.0 → 0.14.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitavision/ui",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "The vitavision instrument design system: Tailwind v4 tokens, theme, and React primitives.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -0,0 +1,74 @@
1
+ /*
2
+ * The keyboard shortcuts of a screen, listed for its help: the `?` dialog of a review tool, a
3
+ * shortcuts section in a side panel.
4
+ */
5
+
6
+ import { Fragment, useId, type ComponentProps } from "react";
7
+
8
+ import { cn } from "./cn";
9
+ import { Kbd } from "./Kbd";
10
+
11
+ /** One command and the keys that run it. */
12
+ export interface Shortcut {
13
+ /**
14
+ * The keys, as the keyboard labels them: each entry is one key or chord (`J`, `⇧ click`,
15
+ * `⌘K`), and several distinct entries are alternatives (`["J", "↓"]` reads "J or ↓").
16
+ */
17
+ keys: readonly string[];
18
+ /** What it does, as a short phrase ("Next tile"), unique within its group. */
19
+ description: string;
20
+ }
21
+
22
+ /** A titled group of shortcuts ("Navigation", "Flags"). */
23
+ export interface ShortcutGroup {
24
+ /** The group's heading, unique within the list. */
25
+ title: string;
26
+ /** Its shortcuts, in the order they should read. */
27
+ shortcuts: readonly Shortcut[];
28
+ }
29
+
30
+ /** Props of `ShortcutList`. */
31
+ export type ShortcutListProps = Omit<ComponentProps<"div">, "children"> & {
32
+ /** The groups, in the order they should read. Empty groups are left out. */
33
+ groups: readonly ShortcutGroup[];
34
+ };
35
+
36
+ /**
37
+ * The keyboard shortcuts of a screen as titled groups: each row a command's keys, as `Kbd`
38
+ * caps, beside what it does. Groups flow into two columns where there is room.
39
+ *
40
+ * It only lists: binding the keys is the app's. Put it in a `Dialog` for a `?` help, or in a
41
+ * panel. Each group is a `<section>` labelled by its heading, and its rows are a description
42
+ * list, so a screen reader announces "J or ↓, Next tile".
43
+ */
44
+ export function ShortcutList({ groups, className, ...rest }: ShortcutListProps) {
45
+ const baseId = useId();
46
+ return (
47
+ <div {...rest} className={cn("grid gap-x-8 gap-y-4 sm:grid-cols-2", className)}>
48
+ {groups.map((group, g) =>
49
+ group.shortcuts.length === 0 ? null : (
50
+ <section key={group.title} aria-labelledby={`${baseId}-${g}`} className="min-w-0">
51
+ <h3 id={`${baseId}-${g}`} className="mb-1.5 text-[11px] font-semibold tracking-wider text-fg-muted uppercase">
52
+ {group.title}
53
+ </h3>
54
+ <dl className="grid grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-1 text-sm">
55
+ {group.shortcuts.map((shortcut) => (
56
+ <Fragment key={shortcut.description}>
57
+ <dt className="flex flex-wrap items-center gap-1 text-xs text-fg-muted">
58
+ {shortcut.keys.map((key, k) => (
59
+ <Fragment key={key}>
60
+ {k > 0 && <span>or</span>}
61
+ <Kbd>{key}</Kbd>
62
+ </Fragment>
63
+ ))}
64
+ </dt>
65
+ <dd className="text-fg">{shortcut.description}</dd>
66
+ </Fragment>
67
+ ))}
68
+ </dl>
69
+ </section>
70
+ ),
71
+ )}
72
+ </div>
73
+ );
74
+ }
@@ -44,6 +44,7 @@ export { Popover, PopoverClose, type PopoverProps } from "./Popover";
44
44
  export { PoseInput, type PoseInputProps, type PoseValue, type Quaternion, type RotationView, type Vec3 } from "./PoseInput";
45
45
  export { SegmentedControl } from "./SegmentedControl";
46
46
  export { Select, type SelectOption } from "./Select";
47
+ export { ShortcutList, type Shortcut, type ShortcutGroup, type ShortcutListProps } from "./ShortcutList";
47
48
  export { Slider } from "./Slider";
48
49
  export { Table, type Column, type TableWindowing } from "./Table";
49
50
  export { sortRows, type SortDirection, type TableSort } from "./tableSort";