@softure-ai/theme-notion 0.1.1 → 0.3.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/README.md +239 -12
  3. package/dist/index.d.ts +12 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +12 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/messages/en.d.ts +20 -0
  8. package/dist/messages/en.d.ts.map +1 -1
  9. package/dist/messages/en.js +11 -0
  10. package/dist/messages/en.js.map +1 -1
  11. package/dist/messages/index.d.ts +20 -0
  12. package/dist/messages/index.d.ts.map +1 -1
  13. package/dist/notion/Code.d.ts +8 -0
  14. package/dist/notion/Code.d.ts.map +1 -0
  15. package/dist/notion/Code.js +12 -0
  16. package/dist/notion/Code.js.map +1 -0
  17. package/dist/notion/DetailTable.d.ts +15 -0
  18. package/dist/notion/DetailTable.d.ts.map +1 -0
  19. package/dist/notion/DetailTable.js +20 -0
  20. package/dist/notion/DetailTable.js.map +1 -0
  21. package/dist/notion/FilterChip.d.ts +24 -0
  22. package/dist/notion/FilterChip.d.ts.map +1 -0
  23. package/dist/notion/FilterChip.js +18 -0
  24. package/dist/notion/FilterChip.js.map +1 -0
  25. package/dist/notion/FoldRow.d.ts +23 -0
  26. package/dist/notion/FoldRow.d.ts.map +1 -0
  27. package/dist/notion/FoldRow.js +14 -0
  28. package/dist/notion/FoldRow.js.map +1 -0
  29. package/dist/notion/MarkPopover.d.ts +19 -0
  30. package/dist/notion/MarkPopover.d.ts.map +1 -0
  31. package/dist/notion/MarkPopover.js +22 -0
  32. package/dist/notion/MarkPopover.js.map +1 -0
  33. package/dist/notion/PageHeader.d.ts +2 -1
  34. package/dist/notion/PageHeader.d.ts.map +1 -1
  35. package/dist/notion/PageHeader.js +2 -2
  36. package/dist/notion/PageHeader.js.map +1 -1
  37. package/dist/notion/SidePanel.d.ts +13 -0
  38. package/dist/notion/SidePanel.d.ts.map +1 -0
  39. package/dist/notion/SidePanel.js +28 -0
  40. package/dist/notion/SidePanel.js.map +1 -0
  41. package/dist/notion/Sortable.d.ts +36 -0
  42. package/dist/notion/Sortable.d.ts.map +1 -0
  43. package/dist/notion/Sortable.js +83 -0
  44. package/dist/notion/Sortable.js.map +1 -0
  45. package/dist/notion/Stats.d.ts +49 -0
  46. package/dist/notion/Stats.d.ts.map +1 -0
  47. package/dist/notion/Stats.js +38 -0
  48. package/dist/notion/Stats.js.map +1 -0
  49. package/dist/notion/Steps.d.ts +18 -0
  50. package/dist/notion/Steps.d.ts.map +1 -0
  51. package/dist/notion/Steps.js +32 -0
  52. package/dist/notion/Steps.js.map +1 -0
  53. package/dist/notion/TabBar.d.ts +15 -0
  54. package/dist/notion/TabBar.d.ts.map +1 -0
  55. package/dist/notion/TabBar.js +6 -0
  56. package/dist/notion/TabBar.js.map +1 -0
  57. package/dist/notion/tones.d.ts +8 -0
  58. package/dist/notion/tones.d.ts.map +1 -0
  59. package/dist/notion/tones.js +37 -0
  60. package/dist/notion/tones.js.map +1 -0
  61. package/dist/page.css +22 -0
  62. package/dist/theme.css +55 -46
  63. package/dist/tokens.d.ts +82 -64
  64. package/dist/tokens.d.ts.map +1 -1
  65. package/dist/tokens.js +22 -19
  66. package/dist/tokens.js.map +1 -1
  67. package/dist/ui/alert.js +1 -1
  68. package/dist/ui/alert.js.map +1 -1
  69. package/dist/ui/badge.d.ts +1 -1
  70. package/dist/ui/badge.d.ts.map +1 -1
  71. package/dist/ui/badge.js +33 -13
  72. package/dist/ui/badge.js.map +1 -1
  73. package/dist/ui/button-group.js +1 -1
  74. package/dist/ui/button-group.js.map +1 -1
  75. package/dist/ui/button.d.ts +1 -1
  76. package/dist/ui/button.js +3 -3
  77. package/dist/ui/button.js.map +1 -1
  78. package/dist/ui/checkbox.js +1 -1
  79. package/dist/ui/checkbox.js.map +1 -1
  80. package/dist/ui/dropdown-menu.js +1 -1
  81. package/dist/ui/empty.js +1 -1
  82. package/dist/ui/empty.js.map +1 -1
  83. package/dist/ui/field.js +2 -2
  84. package/dist/ui/field.js.map +1 -1
  85. package/dist/ui/item.d.ts.map +1 -1
  86. package/dist/ui/item.js +8 -3
  87. package/dist/ui/item.js.map +1 -1
  88. package/dist/ui/progress.d.ts +4 -1
  89. package/dist/ui/progress.d.ts.map +1 -1
  90. package/dist/ui/progress.js +9 -2
  91. package/dist/ui/progress.js.map +1 -1
  92. package/dist/ui/radio-group.d.ts +6 -0
  93. package/dist/ui/radio-group.d.ts.map +1 -0
  94. package/dist/ui/radio-group.js +14 -0
  95. package/dist/ui/radio-group.js.map +1 -0
  96. package/dist/ui/scroll-area.d.ts +3 -1
  97. package/dist/ui/scroll-area.d.ts.map +1 -1
  98. package/dist/ui/scroll-area.js +2 -2
  99. package/dist/ui/scroll-area.js.map +1 -1
  100. package/dist/ui/select.js +2 -2
  101. package/dist/ui/select.js.map +1 -1
  102. package/dist/ui/sidebar.js +4 -4
  103. package/dist/ui/sidebar.js.map +1 -1
  104. package/dist/ui/tabs.js +1 -1
  105. package/dist/ui/tabs.js.map +1 -1
  106. package/package.json +16 -5
  107. package/src/index.ts +32 -0
  108. package/src/messages/en.ts +12 -0
  109. package/src/notion/Code.tsx +39 -0
  110. package/src/notion/DetailTable.tsx +46 -0
  111. package/src/notion/FilterChip.tsx +71 -0
  112. package/src/notion/FoldRow.tsx +78 -0
  113. package/src/notion/MarkPopover.tsx +84 -0
  114. package/src/notion/PageHeader.tsx +4 -2
  115. package/src/notion/SidePanel.tsx +73 -0
  116. package/src/notion/Sortable.tsx +235 -0
  117. package/src/notion/Stats.tsx +165 -0
  118. package/src/notion/Steps.tsx +102 -0
  119. package/src/notion/TabBar.tsx +47 -0
  120. package/src/notion/tones.ts +45 -0
  121. package/src/page.css +22 -0
  122. package/src/tokens.ts +22 -19
  123. package/src/ui/alert.tsx +1 -1
  124. package/src/ui/badge.tsx +35 -13
  125. package/src/ui/button-group.tsx +1 -1
  126. package/src/ui/button.tsx +3 -3
  127. package/src/ui/checkbox.tsx +1 -1
  128. package/src/ui/dropdown-menu.tsx +1 -1
  129. package/src/ui/empty.tsx +1 -1
  130. package/src/ui/field.tsx +2 -2
  131. package/src/ui/item.tsx +16 -7
  132. package/src/ui/progress.tsx +19 -2
  133. package/src/ui/radio-group.tsx +44 -0
  134. package/src/ui/scroll-area.tsx +11 -2
  135. package/src/ui/select.tsx +2 -2
  136. package/src/ui/sidebar.tsx +4 -4
  137. package/src/ui/tabs.tsx +3 -3
@@ -0,0 +1,235 @@
1
+ "use client";
2
+
3
+ import {
4
+ closestCenter,
5
+ DndContext,
6
+ KeyboardSensor,
7
+ MouseSensor,
8
+ TouchSensor,
9
+ useSensor,
10
+ useSensors,
11
+ type Announcements,
12
+ type DragEndEvent,
13
+ type Modifier,
14
+ type UniqueIdentifier,
15
+ } from "@dnd-kit/core";
16
+ import {
17
+ arrayMove,
18
+ SortableContext,
19
+ sortableKeyboardCoordinates,
20
+ useSortable,
21
+ verticalListSortingStrategy,
22
+ } from "@dnd-kit/sortable";
23
+ import { CSS } from "@dnd-kit/utilities";
24
+ import { GripVertical } from "lucide-react";
25
+ import { createContext, useContext, useId, useRef, type ComponentProps, type ReactNode } from "react";
26
+
27
+ import { en as messages } from "../messages/en.js";
28
+ import { cn } from "../lib/utils.js";
29
+ import { Button } from "../ui/button.js";
30
+ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
31
+
32
+ // What a screen reader hears while a row moves. `{item}` is the row's label, `{position}` and `{total}` its place.
33
+ export interface SortableAnnouncements {
34
+ readonly pickedUp: string;
35
+ readonly moved: string;
36
+ readonly dropped: string;
37
+ readonly cancelled: string;
38
+ }
39
+
40
+ export interface SortableMove {
41
+ readonly id: string;
42
+ readonly from: number;
43
+ readonly to: number;
44
+ }
45
+
46
+ // `row`: the whole row is dragged (a phone list); `handle`: only `SortableHandle` starts a drag (a desktop list).
47
+ export type SortableDragBy = "row" | "handle";
48
+
49
+ export interface SortableListProps extends Omit<ComponentProps<"ul">, "children"> {
50
+ // The list's accessible name.
51
+ readonly label: string;
52
+ // The rows' ids in their current order; the app owns the order.
53
+ readonly items: readonly string[];
54
+ // Called on a drop that changes the order, with the new order and the move.
55
+ readonly onReorder: (next: string[], move: SortableMove) => void;
56
+ readonly dragBy?: SortableDragBy;
57
+ // How long a press holds before the row lifts, in ms; a mouse in `handle` mode starts at once.
58
+ readonly holdDelay?: number;
59
+ // How far the pointer may move during the hold, in px; moving further scrolls instead of lifting.
60
+ readonly tolerance?: number;
61
+ // How to reorder from the keyboard, read when a row (or its handle) gets focus.
62
+ readonly instructions?: string;
63
+ readonly announcements?: Partial<SortableAnnouncements>;
64
+ // A row's name in the announcements; defaults to its id.
65
+ readonly getItemLabel?: (id: string) => string;
66
+ readonly children: ReactNode;
67
+ }
68
+
69
+ const HANDLE_MOUSE_DISTANCE = 4;
70
+
71
+ // The row follows the pointer up and down only.
72
+ const restrictToVerticalAxis: Modifier = ({ transform }) => ({ ...transform, x: 0 });
73
+
74
+ function fillAnnouncement(template: string, values: Readonly<Record<string, string | number>>): string {
75
+ return template.replace(/\{(\w+)\}/g, (match, key: string) => (key in values ? String(values[key]) : match));
76
+ }
77
+
78
+ interface SortableItemContextValue {
79
+ readonly dragBy: SortableDragBy;
80
+ }
81
+
82
+ const SortableListContext = createContext<SortableItemContextValue>({ dragBy: "row" });
83
+
84
+ type SortableHandleBinding = Pick<ReturnType<typeof useSortable>, "attributes" | "listeners" | "setActivatorNodeRef">;
85
+
86
+ const SortableHandleContext = createContext<SortableHandleBinding | null>(null);
87
+
88
+ // A list whose rows are reordered by dragging: a long press lifts a row on a touch screen (a swipe before the hold
89
+ // still scrolls, a tap still activates the row), a mouse drags it, the keyboard picks it up with Space or Enter and
90
+ // moves it with the arrows. The order stays with the app: `onReorder` gets the new one.
91
+ export function SortableList({
92
+ label,
93
+ items,
94
+ onReorder,
95
+ dragBy = "row",
96
+ holdDelay = 500,
97
+ tolerance = 8,
98
+ instructions = messages.sortable.instructions,
99
+ announcements,
100
+ getItemLabel = (id) => id,
101
+ className,
102
+ children,
103
+ ...props
104
+ }: SortableListProps) {
105
+ const contextId = useId();
106
+ const hold = { delay: holdDelay, tolerance };
107
+ const sensors = useSensors(
108
+ useSensor(MouseSensor, {
109
+ activationConstraint: dragBy === "handle" ? { distance: HANDLE_MOUSE_DISTANCE } : hold,
110
+ }),
111
+ useSensor(TouchSensor, { activationConstraint: hold }),
112
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
113
+ );
114
+ const copy = { ...messages.sortable, ...announcements };
115
+ const lastOverId = useRef<UniqueIdentifier | null>(null);
116
+ const total = items.length;
117
+
118
+ function announce(template: string, id: UniqueIdentifier, overId?: UniqueIdentifier): string {
119
+ const position = items.indexOf(String(overId ?? id)) + 1;
120
+ return fillAnnouncement(template, { item: getItemLabel(String(id)), position, total });
121
+ }
122
+
123
+ const liveAnnouncements: Announcements = {
124
+ onDragStart: ({ active }) => {
125
+ lastOverId.current = active.id;
126
+ return announce(copy.pickedUp, active.id);
127
+ },
128
+ onDragOver: ({ active, over }) => {
129
+ // The first `over` of a drag is the row's own place: keep the "picked up" announcement.
130
+ if (!over || over.id === lastOverId.current) return undefined;
131
+ lastOverId.current = over.id;
132
+ return announce(copy.moved, active.id, over.id);
133
+ },
134
+ onDragEnd: ({ active, over }) => announce(over ? copy.dropped : copy.cancelled, active.id, over?.id),
135
+ onDragCancel: ({ active }) => announce(copy.cancelled, active.id),
136
+ };
137
+
138
+ function handleDragEnd({ active, over }: DragEndEvent) {
139
+ if (!over || active.id === over.id) return;
140
+ const from = items.indexOf(String(active.id));
141
+ const to = items.indexOf(String(over.id));
142
+ if (from < 0 || to < 0) return;
143
+ onReorder(arrayMove([...items], from, to), { id: String(active.id), from, to });
144
+ }
145
+
146
+ return (
147
+ <DndContext
148
+ id={contextId}
149
+ sensors={sensors}
150
+ collisionDetection={closestCenter}
151
+ modifiers={[restrictToVerticalAxis]}
152
+ accessibility={{ announcements: liveAnnouncements, screenReaderInstructions: { draggable: instructions } }}
153
+ onDragEnd={handleDragEnd}
154
+ >
155
+ <SortableContext items={[...items]} strategy={verticalListSortingStrategy}>
156
+ <SortableListContext.Provider value={{ dragBy }}>
157
+ <ul
158
+ aria-label={label}
159
+ data-slot="sortable-list"
160
+ data-drag-by={dragBy}
161
+ className={cn("flex flex-col", className)}
162
+ {...props}
163
+ >
164
+ {children}
165
+ </ul>
166
+ </SortableListContext.Provider>
167
+ </SortableContext>
168
+ </DndContext>
169
+ );
170
+ }
171
+
172
+ export interface SortableItemProps extends ComponentProps<"li"> {
173
+ // The row's id, one of the list's `items`.
174
+ readonly id: string;
175
+ }
176
+
177
+ // The lifted row floats on `accent-strong` with `shadow-menu`, above its siblings; `data-dragging` marks it.
178
+ const SORTABLE_ITEM =
179
+ "rounded-md bg-background outline-none touch-manipulation select-none [-webkit-touch-callout:none] focus-visible:ring-2 focus-visible:ring-ring data-[dragging]:relative data-[dragging]:z-10 data-[dragging]:bg-accent-strong data-[dragging]:shadow-menu";
180
+
181
+ // One row of a `SortableList`. In `row` mode the row itself is the drag target and is focusable; in `handle` mode a
182
+ // `SortableHandle` inside it is. The drag's own pointer and key handlers win over the same props on the drag target.
183
+ export function SortableItem({ id, className, style, children, ...props }: SortableItemProps) {
184
+ const { dragBy } = useContext(SortableListContext);
185
+ const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
186
+ id,
187
+ attributes: { role: "listitem" },
188
+ });
189
+ const rowBinding = dragBy === "row" ? { ...attributes, ...listeners } : {};
190
+ return (
191
+ <SortableHandleContext.Provider value={{ attributes, listeners, setActivatorNodeRef }}>
192
+ <li
193
+ ref={setNodeRef}
194
+ data-slot="sortable-item"
195
+ data-id={id}
196
+ data-dragging={isDragging ? "" : undefined}
197
+ className={cn(SORTABLE_ITEM, className)}
198
+ style={{ ...style, transform: CSS.Translate.toString(transform), transition }}
199
+ {...props}
200
+ {...rowBinding}
201
+ >
202
+ {children}
203
+ </li>
204
+ </SortableHandleContext.Provider>
205
+ );
206
+ }
207
+
208
+ export interface SortableHandleProps extends Omit<ComponentProps<typeof Button>, "children"> {
209
+ // The handle's accessible name.
210
+ readonly label?: string;
211
+ }
212
+
213
+ // A grip button that drags its row, for a list with `dragBy="handle"`.
214
+ export function SortableHandle({ label = messages.sortable.handle, className, ...props }: SortableHandleProps) {
215
+ const binding = useContext(SortableHandleContext);
216
+ if (!binding) throw new Error("SortableHandle failed: it must be rendered inside a SortableItem");
217
+ const { attributes, listeners, setActivatorNodeRef } = binding;
218
+ return (
219
+ <Button
220
+ ref={setActivatorNodeRef}
221
+ type="button"
222
+ variant="ghost"
223
+ size="icon-sm"
224
+ data-slot="sortable-handle"
225
+ className={cn("cursor-grab touch-none text-muted-foreground active:cursor-grabbing", className)}
226
+ {...props}
227
+ {...attributes}
228
+ {...listeners}
229
+ role="button"
230
+ aria-label={label}
231
+ >
232
+ <GripVertical aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
233
+ </Button>
234
+ );
235
+ }
@@ -0,0 +1,165 @@
1
+ import { ChevronRight } from "lucide-react";
2
+ import type { ReactNode } from "react";
3
+
4
+ import { Badge } from "../ui/badge.js";
5
+ import { Progress } from "../ui/progress.js";
6
+ import { cn } from "../lib/utils.js";
7
+
8
+ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
9
+ import { TONE_COLORS, TONE_FILL, TONE_TEXT, type Tone } from "./tones.js";
10
+
11
+ export interface StatsFoldProps {
12
+ /** The section's heading. */
13
+ readonly title: string;
14
+ readonly children: ReactNode;
15
+ readonly className?: string;
16
+ }
17
+
18
+ // A screen's summary figures folded under a heading, closed by default: the design system's collapsible (a ghost row
19
+ // with a chevron that turns when open, the content indented under it), on native `<details>` so it needs no client.
20
+ export function StatsFold({ title, children, className }: StatsFoldProps) {
21
+ return (
22
+ <details data-slot="stats-fold" className={cn("group/stats-fold", className)}>
23
+ <summary
24
+ data-slot="stats-fold-summary"
25
+ className="flex h-row-height cursor-pointer list-none items-center gap-1 rounded-md px-1 text-foreground transition-colors duration-120 hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none [&::-webkit-details-marker]:hidden"
26
+ >
27
+ <ChevronRight
28
+ aria-hidden="true"
29
+ strokeWidth={ICON_STROKE_WIDTH}
30
+ className="size-4 shrink-0 text-muted-foreground transition-transform duration-150 group-open/stats-fold:rotate-90"
31
+ />
32
+ <h2 className="text-ui-medium">{title}</h2>
33
+ </summary>
34
+ <div data-slot="stats-fold-content" className="flex flex-col gap-3 pt-2 pb-1 pl-6">
35
+ {children}
36
+ </div>
37
+ </details>
38
+ );
39
+ }
40
+
41
+ export interface StatCardAside {
42
+ readonly text: string;
43
+ readonly tone?: Tone;
44
+ }
45
+
46
+ export interface StatCard {
47
+ /** Unique within the row; kept as `data-stat`. */
48
+ readonly key: string;
49
+ readonly label: string;
50
+ readonly value: string;
51
+ readonly hint?: string;
52
+ readonly tone?: Tone;
53
+ readonly aside?: StatCardAside;
54
+ /** A bar under the figure, 0–100 (clamped); in the card's `tone` when it has one, primary otherwise. */
55
+ readonly progress?: number;
56
+ /** The bar's accessible name; defaults to `label`. */
57
+ readonly progressLabel?: string;
58
+ }
59
+
60
+ export interface StatCardsProps {
61
+ /** The list's accessible name. */
62
+ readonly label: string;
63
+ readonly cards: readonly StatCard[];
64
+ /** The cards stretch across the column (min 14rem) instead of the narrow grid (min 10rem). */
65
+ readonly isFullWidth?: boolean;
66
+ /** Every card in one row from `sm` up, wrapping only on a phone. */
67
+ readonly isOneRow?: boolean;
68
+ }
69
+
70
+ function clampProgress(progress: number): number {
71
+ if (!Number.isFinite(progress)) return 0;
72
+ return Math.min(100, Math.max(0, progress));
73
+ }
74
+
75
+ function getStatCardsLayout(isFullWidth: boolean, isOneRow: boolean): "row" | "full" | "grid" {
76
+ if (isOneRow) return "row";
77
+ return isFullWidth ? "full" : "grid";
78
+ }
79
+
80
+ // Summary figures as a row of cards wrapping on a narrow screen: the label, the figure in its tone's colour (never
81
+ // broken, tabular numbers), an optional bar under it, an optional note and an optional short figure on its right as a
82
+ // tag.
83
+ export function StatCards({ label, cards, isFullWidth = false, isOneRow = false }: StatCardsProps) {
84
+ return (
85
+ <ul
86
+ aria-label={label}
87
+ data-slot="stat-cards"
88
+ data-layout={getStatCardsLayout(isFullWidth, isOneRow)}
89
+ className={cn(
90
+ "grid gap-2",
91
+ isFullWidth
92
+ ? "grid-cols-[repeat(auto-fit,minmax(min(14rem,100%),1fr))]"
93
+ : "grid-cols-[repeat(auto-fill,minmax(min(10rem,100%),1fr))]",
94
+ isOneRow && "sm:auto-cols-fr sm:grid-flow-col sm:grid-cols-none",
95
+ )}
96
+ >
97
+ {cards.map((card) => {
98
+ const tone = card.tone ?? "default";
99
+ return (
100
+ <li
101
+ key={card.key}
102
+ data-stat={card.key}
103
+ className="flex min-w-0 items-start justify-between gap-2 rounded-lg bg-card p-3 text-card-foreground shadow-card"
104
+ >
105
+ <div className={cn("min-w-0", card.progress !== undefined && "flex-1")}>
106
+ <div className="text-section-label text-muted-foreground">{card.label}</div>
107
+ <div data-tone={tone} className={cn("mt-1 text-heading-3 whitespace-nowrap tabular-nums", TONE_TEXT[tone])}>
108
+ {card.value}
109
+ </div>
110
+ {card.progress === undefined ? null : (
111
+ <Progress
112
+ value={clampProgress(card.progress)}
113
+ aria-label={card.progressLabel ?? card.label}
114
+ data-slot="stat-card-progress"
115
+ className="mt-2"
116
+ indicatorClassName={card.tone === undefined ? undefined : TONE_FILL[card.tone]}
117
+ />
118
+ )}
119
+ {card.hint === undefined ? null : <div className="mt-1 text-small text-muted-foreground">{card.hint}</div>}
120
+ </div>
121
+ {card.aside === undefined ? null : (
122
+ <Badge
123
+ variant="tag"
124
+ color={TONE_COLORS[card.aside.tone ?? "default"] ?? "default"}
125
+ data-slot="stat-card-aside"
126
+ data-tone={card.aside.tone ?? "default"}
127
+ className="text-small"
128
+ >
129
+ {card.aside.text}
130
+ </Badge>
131
+ )}
132
+ </li>
133
+ );
134
+ })}
135
+ </ul>
136
+ );
137
+ }
138
+
139
+ export interface StatPill {
140
+ readonly key: string;
141
+ readonly label: string;
142
+ readonly value: string;
143
+ readonly tone?: Tone;
144
+ }
145
+
146
+ export interface StatPillsProps {
147
+ /** The list's accessible name. */
148
+ readonly label: string;
149
+ readonly pills: readonly StatPill[];
150
+ }
151
+
152
+ // Small counts as "label **value**" tags in one row, wrapping only on a phone, each in its tone's colour.
153
+ export function StatPills({ label, pills }: StatPillsProps) {
154
+ return (
155
+ <ul aria-label={label} data-slot="stat-pills" className="flex flex-wrap gap-1.5 sm:flex-nowrap sm:overflow-x-auto">
156
+ {pills.map((pill) => (
157
+ <li key={pill.key} data-stat={pill.key} data-tone={pill.tone ?? "default"}>
158
+ <Badge variant="tag" color={TONE_COLORS[pill.tone ?? "default"] ?? "default"}>
159
+ {pill.label} <strong className="font-medium tabular-nums">{pill.value}</strong>
160
+ </Badge>
161
+ </li>
162
+ ))}
163
+ </ul>
164
+ );
165
+ }
@@ -0,0 +1,102 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ import { en as messages } from "../messages/en.js";
4
+ import { cn } from "../lib/utils.js";
5
+
6
+ export type StepState = "done" | "current" | "todo" | "failed";
7
+
8
+ export interface StepItem {
9
+ // Kept on the step as `data-step`.
10
+ readonly key: string;
11
+ readonly title: string;
12
+ readonly note?: ReactNode;
13
+ // Defaults to `todo`.
14
+ readonly state?: StepState;
15
+ // Drawn at the step's end, e.g. a tag naming the service the step uses.
16
+ readonly aside?: ReactNode;
17
+ }
18
+
19
+ // `row`: a wrapping grid of cards; `list`: a compact vertical list.
20
+ export type StepsLayout = "row" | "list";
21
+
22
+ export interface StepsProps {
23
+ // The list's accessible name.
24
+ readonly label: string;
25
+ readonly steps: readonly StepItem[];
26
+ readonly layout?: StepsLayout;
27
+ // Each state's word for assistive technology, from the app's message layer.
28
+ readonly stateLabels?: Partial<Readonly<Record<StepState, string>>>;
29
+ }
30
+
31
+ // Literal class names per state, so Tailwind generates each one (the theme's `@source` covers this folder).
32
+ const STEP_NUMBER_STATE: Readonly<Record<StepState, string>> = {
33
+ done: "bg-green-tag text-green-tag-foreground",
34
+ current: "bg-primary text-primary-foreground",
35
+ todo: "bg-muted text-muted-foreground",
36
+ failed: "bg-red-tag text-red-tag-foreground",
37
+ };
38
+
39
+ const STEPS_LIST: Readonly<Record<StepsLayout, string>> = {
40
+ row: "grid grid-cols-[repeat(auto-fill,minmax(min(12rem,100%),1fr))] gap-2",
41
+ list: "flex flex-col",
42
+ };
43
+
44
+ const STEP_ITEM: Readonly<Record<StepsLayout, string>> = {
45
+ row: "flex min-w-0 items-start gap-2 rounded-lg bg-card p-3 text-card-foreground shadow-card data-[state=current]:bg-blue-bg",
46
+ list: "flex min-w-0 items-start gap-2 rounded-md px-2 py-1.5 transition-colors duration-120 hover:bg-accent",
47
+ };
48
+
49
+ const STEP_NUMBER_SHAPE: Readonly<Record<StepsLayout, string>> = {
50
+ row: "rounded-full",
51
+ list: "rounded-sm",
52
+ };
53
+
54
+ // An ordered process: each step's number in a badge coloured by its state, its title, an optional note under it and
55
+ // an optional aside at its end. The state is also a word for assistive technology, so it never reads by colour alone.
56
+ export function Steps({ label, steps, layout = "row", stateLabels }: StepsProps) {
57
+ const words = { ...messages.steps, ...stateLabels };
58
+ return (
59
+ <ol aria-label={label} data-slot="steps" data-layout={layout} className={STEPS_LIST[layout]}>
60
+ {steps.map((step, index) => {
61
+ const state = step.state ?? "todo";
62
+ return (
63
+ <li
64
+ key={step.key}
65
+ data-step={step.key}
66
+ data-state={state}
67
+ aria-current={state === "current" ? "step" : undefined}
68
+ className={STEP_ITEM[layout]}
69
+ >
70
+ <span
71
+ aria-hidden="true"
72
+ data-slot="step-number"
73
+ className={cn(
74
+ "mt-px flex size-5 shrink-0 items-center justify-center text-small font-medium tabular-nums",
75
+ STEP_NUMBER_SHAPE[layout],
76
+ STEP_NUMBER_STATE[state],
77
+ )}
78
+ >
79
+ {index + 1}
80
+ </span>
81
+ <div className="min-w-0 flex-1">
82
+ <div className="text-sm font-medium">
83
+ {step.title}
84
+ <span className="sr-only">, {words[state]}</span>
85
+ </div>
86
+ {step.note === undefined ? null : (
87
+ <div data-slot="step-note" className="mt-0.5 text-small text-muted-foreground">
88
+ {step.note}
89
+ </div>
90
+ )}
91
+ </div>
92
+ {step.aside === undefined ? null : (
93
+ <div data-slot="step-aside" className="shrink-0">
94
+ {step.aside}
95
+ </div>
96
+ )}
97
+ </li>
98
+ );
99
+ })}
100
+ </ol>
101
+ );
102
+ }
@@ -0,0 +1,47 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export interface TabBarItem<Key extends string> {
4
+ // Kept on the link as `data-tab`.
5
+ readonly key: Key;
6
+ readonly label: string;
7
+ readonly href: string;
8
+ // Drawn before the label; the caller hides it from assistive technology.
9
+ readonly icon?: ReactNode;
10
+ // Drawn after the label, 0 included.
11
+ readonly count?: number;
12
+ }
13
+
14
+ export interface TabBarProps<Key extends string> {
15
+ // The nav's accessible name.
16
+ readonly label: string;
17
+ readonly tabs: readonly TabBarItem<Key>[];
18
+ readonly current: Key;
19
+ }
20
+
21
+ // A screen's tabs as line tabs where each tab is a link, so the shown tab lives in the address and survives a reload.
22
+ export function TabBar<Key extends string>({ label, tabs, current }: TabBarProps<Key>) {
23
+ return (
24
+ <nav aria-label={label} data-slot="tab-bar" className="overflow-x-auto border-b border-border">
25
+ <ul className="flex gap-1 pb-1">
26
+ {tabs.map((tab) => (
27
+ <li key={tab.key}>
28
+ <a
29
+ href={tab.href}
30
+ className="relative inline-flex h-control-height items-center gap-1.5 rounded-md px-2 text-ui-medium whitespace-nowrap text-muted-foreground transition-colors duration-120 after:absolute after:inset-x-0 after:-bottom-1 after:h-0.5 after:bg-foreground after:opacity-0 hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none aria-[current=page]:text-foreground aria-[current=page]:after:opacity-100 [&_svg]:size-4 [&_svg]:shrink-0"
31
+ data-tab={tab.key}
32
+ aria-current={tab.key === current ? "page" : undefined}
33
+ >
34
+ {tab.icon}
35
+ {tab.label}
36
+ {tab.count === undefined ? null : (
37
+ <span data-slot="tab-bar-count" className="rounded-xs bg-accent px-1 text-small text-muted-foreground tabular-nums">
38
+ {tab.count}
39
+ </span>
40
+ )}
41
+ </a>
42
+ </li>
43
+ ))}
44
+ </ul>
45
+ </nav>
46
+ );
47
+ }
@@ -0,0 +1,45 @@
1
+ import type { PaletteColor } from "./palette.js";
2
+
3
+ // A figure's colour by what it means: done, to do, owed or failing, out of play, or neutral. Each app keeps its own
4
+ // table of which meaning takes which tone ("booked" → success); the theme owns the colours and the class names.
5
+ export const TONES = ["default", "success", "warning", "danger", "muted"] as const;
6
+
7
+ export type Tone = (typeof TONES)[number];
8
+
9
+ // A tone's palette colour; `default` has none and reads in the text colour.
10
+ export const TONE_COLORS: Readonly<Record<Tone, PaletteColor | null>> = {
11
+ default: null,
12
+ success: "green",
13
+ warning: "orange",
14
+ danger: "red",
15
+ muted: "gray",
16
+ };
17
+
18
+ // Literal class names per tone, so Tailwind generates each one (the theme's `@source` covers this folder).
19
+
20
+ // A figure written in its tone's colour.
21
+ export const TONE_TEXT: Readonly<Record<Tone, string>> = {
22
+ default: "text-foreground",
23
+ success: "text-green",
24
+ warning: "text-orange",
25
+ danger: "text-red",
26
+ muted: "text-gray",
27
+ };
28
+
29
+ // A drawn share (a bar segment) in its tone's colour; the default is a quiet gray.
30
+ export const TONE_FILL: Readonly<Record<Tone, string>> = {
31
+ default: "bg-gray",
32
+ success: "bg-green",
33
+ warning: "bg-orange",
34
+ danger: "bg-red",
35
+ muted: "bg-gray",
36
+ };
37
+
38
+ // A box's leading edge in its tone's colour; the default is a quiet gray.
39
+ export const TONE_EDGE: Readonly<Record<Tone, string>> = {
40
+ default: "border-l-gray",
41
+ success: "border-l-green",
42
+ warning: "border-l-orange",
43
+ danger: "border-l-red",
44
+ muted: "border-l-gray",
45
+ };
package/src/page.css ADDED
@@ -0,0 +1,22 @@
1
+ /*
2
+ * The Notion page base: the rules of the design system's base layer that the kit's `base.css` leaves to the theme.
3
+ * Text outside the components takes the panel size (14 px, `text-sm`), selected text the blue tag colour, and the page
4
+ * greyscale font smoothing on macOS. In `@layer base`, so every component and utility overrides it.
5
+ *
6
+ * Import it after `theme.css` and the kit's `base.css`, through the app's Tailwind (it reads the type scale with
7
+ * `--theme()`).
8
+ */
9
+ @layer base {
10
+ html {
11
+ -webkit-font-smoothing: antialiased;
12
+ }
13
+
14
+ body {
15
+ font-size: --theme(--text-sm);
16
+ line-height: --theme(--text-sm--line-height);
17
+ }
18
+
19
+ ::selection {
20
+ background: var(--blue-tag);
21
+ }
22
+ }