@softure-ai/theme-notion 0.2.0 → 0.4.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 (102) hide show
  1. package/CHANGELOG.md +164 -0
  2. package/README.md +196 -16
  3. package/dist/index.d.ts +5 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +5 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/messages/en.d.ts +17 -0
  8. package/dist/messages/en.d.ts.map +1 -1
  9. package/dist/messages/en.js +10 -0
  10. package/dist/messages/en.js.map +1 -1
  11. package/dist/messages/index.d.ts +17 -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/FilterChip.d.ts +24 -0
  18. package/dist/notion/FilterChip.d.ts.map +1 -0
  19. package/dist/notion/FilterChip.js +18 -0
  20. package/dist/notion/FilterChip.js.map +1 -0
  21. package/dist/notion/Sortable.d.ts +47 -0
  22. package/dist/notion/Sortable.d.ts.map +1 -0
  23. package/dist/notion/Sortable.js +158 -0
  24. package/dist/notion/Sortable.js.map +1 -0
  25. package/dist/notion/Stats.d.ts +4 -0
  26. package/dist/notion/Stats.d.ts.map +1 -1
  27. package/dist/notion/Stats.js +10 -3
  28. package/dist/notion/Stats.js.map +1 -1
  29. package/dist/notion/Steps.d.ts +18 -0
  30. package/dist/notion/Steps.d.ts.map +1 -0
  31. package/dist/notion/Steps.js +32 -0
  32. package/dist/notion/Steps.js.map +1 -0
  33. package/dist/page.css +22 -0
  34. package/dist/theme.css +55 -46
  35. package/dist/tokens.d.ts +82 -64
  36. package/dist/tokens.d.ts.map +1 -1
  37. package/dist/tokens.js +22 -19
  38. package/dist/tokens.js.map +1 -1
  39. package/dist/ui/alert.js +1 -1
  40. package/dist/ui/alert.js.map +1 -1
  41. package/dist/ui/badge.d.ts +1 -1
  42. package/dist/ui/badge.d.ts.map +1 -1
  43. package/dist/ui/badge.js +33 -13
  44. package/dist/ui/badge.js.map +1 -1
  45. package/dist/ui/button-group.js +1 -1
  46. package/dist/ui/button-group.js.map +1 -1
  47. package/dist/ui/button.d.ts +1 -1
  48. package/dist/ui/button.js +3 -3
  49. package/dist/ui/button.js.map +1 -1
  50. package/dist/ui/checkbox.js +1 -1
  51. package/dist/ui/checkbox.js.map +1 -1
  52. package/dist/ui/dropdown-menu.js +1 -1
  53. package/dist/ui/empty.js +1 -1
  54. package/dist/ui/empty.js.map +1 -1
  55. package/dist/ui/field.js +2 -2
  56. package/dist/ui/field.js.map +1 -1
  57. package/dist/ui/item.d.ts.map +1 -1
  58. package/dist/ui/item.js +9 -3
  59. package/dist/ui/item.js.map +1 -1
  60. package/dist/ui/progress.d.ts +4 -1
  61. package/dist/ui/progress.d.ts.map +1 -1
  62. package/dist/ui/progress.js +9 -2
  63. package/dist/ui/progress.js.map +1 -1
  64. package/dist/ui/radio-group.d.ts +6 -0
  65. package/dist/ui/radio-group.d.ts.map +1 -0
  66. package/dist/ui/radio-group.js +14 -0
  67. package/dist/ui/radio-group.js.map +1 -0
  68. package/dist/ui/scroll-area.d.ts +3 -1
  69. package/dist/ui/scroll-area.d.ts.map +1 -1
  70. package/dist/ui/scroll-area.js +2 -2
  71. package/dist/ui/scroll-area.js.map +1 -1
  72. package/dist/ui/select.js +2 -2
  73. package/dist/ui/select.js.map +1 -1
  74. package/dist/ui/sidebar.js +4 -4
  75. package/dist/ui/sidebar.js.map +1 -1
  76. package/dist/ui/tabs.js +1 -1
  77. package/dist/ui/tabs.js.map +1 -1
  78. package/package.json +16 -5
  79. package/src/index.ts +17 -0
  80. package/src/messages/en.ts +11 -0
  81. package/src/notion/Code.tsx +39 -0
  82. package/src/notion/FilterChip.tsx +71 -0
  83. package/src/notion/Sortable.tsx +352 -0
  84. package/src/notion/Stats.tsx +23 -3
  85. package/src/notion/Steps.tsx +102 -0
  86. package/src/page.css +22 -0
  87. package/src/tokens.ts +22 -19
  88. package/src/ui/alert.tsx +1 -1
  89. package/src/ui/badge.tsx +35 -13
  90. package/src/ui/button-group.tsx +1 -1
  91. package/src/ui/button.tsx +3 -3
  92. package/src/ui/checkbox.tsx +1 -1
  93. package/src/ui/dropdown-menu.tsx +1 -1
  94. package/src/ui/empty.tsx +1 -1
  95. package/src/ui/field.tsx +2 -2
  96. package/src/ui/item.tsx +18 -7
  97. package/src/ui/progress.tsx +19 -2
  98. package/src/ui/radio-group.tsx +44 -0
  99. package/src/ui/scroll-area.tsx +11 -2
  100. package/src/ui/select.tsx +2 -2
  101. package/src/ui/sidebar.tsx +4 -4
  102. package/src/ui/tabs.tsx +3 -3
@@ -0,0 +1,352 @@
1
+ "use client";
2
+
3
+ import {
4
+ closestCenter,
5
+ DndContext,
6
+ KeyboardSensor,
7
+ MouseSensor,
8
+ TouchSensor,
9
+ useDndContext,
10
+ useSensor,
11
+ useSensors,
12
+ type Announcements,
13
+ type DragEndEvent,
14
+ type Modifier,
15
+ type UniqueIdentifier,
16
+ } from "@dnd-kit/core";
17
+ import {
18
+ arrayMove,
19
+ SortableContext,
20
+ sortableKeyboardCoordinates,
21
+ useSortable,
22
+ verticalListSortingStrategy,
23
+ } from "@dnd-kit/sortable";
24
+ import { CSS } from "@dnd-kit/utilities";
25
+ import { GripVertical } from "lucide-react";
26
+ import { Slot } from "radix-ui";
27
+ import { createContext, useContext, useId, useCallback, useRef, useState, type ComponentProps, type ReactNode, type Ref } from "react";
28
+
29
+ import { en as messages } from "../messages/en.js";
30
+ import { cn } from "../lib/utils.js";
31
+ import { Button } from "../ui/button.js";
32
+ import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
33
+
34
+ // What a screen reader hears while a row moves. `{item}` is the row's label, `{position}` and `{total}` its place.
35
+ export interface SortableAnnouncements {
36
+ readonly pickedUp: string;
37
+ readonly moved: string;
38
+ readonly dropped: string;
39
+ readonly cancelled: string;
40
+ }
41
+
42
+ export interface SortableMove {
43
+ readonly id: string;
44
+ readonly from: number;
45
+ readonly to: number;
46
+ }
47
+
48
+ // `row`: the whole row is dragged (a phone list); `handle`: only `SortableHandle` starts a drag (a desktop list);
49
+ // `activator`: a press on the app's own `SortableActivator` inside the row lifts it, with the row's hold, while the
50
+ // keyboard still picks up the focused row.
51
+ export type SortableDragBy = "row" | "handle" | "activator";
52
+
53
+ export interface SortableListProps
54
+ extends Omit<ComponentProps<"ul">, "children" | "ref" | "onDragStart" | "onDragEnd"> {
55
+ readonly ref?: Ref<HTMLUListElement | HTMLOListElement>;
56
+ // The list's accessible name.
57
+ readonly label: string;
58
+ // The rows' ids in their current order; the app owns the order.
59
+ readonly items: readonly string[];
60
+ // Called on a drop that changes the order, with the new order and the move.
61
+ readonly onReorder: (next: string[], move: SortableMove) => void;
62
+ readonly dragBy?: SortableDragBy;
63
+ // How long a press holds before the row lifts, in ms; a mouse in `handle` mode starts at once.
64
+ readonly holdDelay?: number;
65
+ // How far the pointer may move during the hold, in px; moving further scrolls instead of lifting.
66
+ readonly tolerance?: number;
67
+ // How to reorder from the keyboard, read when a row (or its handle) gets focus.
68
+ readonly instructions?: string;
69
+ readonly announcements?: Partial<SortableAnnouncements>;
70
+ // A row's name in the announcements; defaults to its id.
71
+ readonly getItemLabel?: (id: string) => string;
72
+ // No row lifts by touch, mouse or keyboard; the rows still render and keep their own handlers.
73
+ readonly disabled?: boolean;
74
+ // The list element: `ol` for a numbered list. Children that are not a `SortableItem` stay in place.
75
+ readonly as?: "ul" | "ol";
76
+ // Called when a row lifts.
77
+ readonly onDragStart?: (id: string) => void;
78
+ // Called on every drop, with the move when the order changed and `null` when it did not.
79
+ readonly onDragEnd?: (id: string, move: SortableMove | null) => void;
80
+ // Called when a drag is cancelled (Escape, or the page lost focus).
81
+ readonly onDragCancel?: (id: string) => void;
82
+ readonly children: ReactNode;
83
+ }
84
+
85
+ const HANDLE_MOUSE_DISTANCE = 4;
86
+
87
+ // The row follows the pointer up and down only.
88
+ const restrictToVerticalAxis: Modifier = ({ transform }) => ({ ...transform, x: 0 });
89
+
90
+ function fillAnnouncement(template: string, values: Readonly<Record<string, string | number>>): string {
91
+ return template.replace(/\{(\w+)\}/g, (match, key: string) => (key in values ? String(values[key]) : match));
92
+ }
93
+
94
+ function assignRef<T>(ref: Ref<T> | undefined, node: T | null) {
95
+ if (typeof ref === "function") ref(node);
96
+ else if (ref) ref.current = node;
97
+ }
98
+
99
+ // A row's group travels in the drag data; dnd-kit types that data loosely, so it is read as unknown.
100
+ function readGroup(data: unknown): string | undefined {
101
+ if (typeof data !== "object" || data === null || !("group" in data)) return undefined;
102
+ return typeof data.group === "string" ? data.group : undefined;
103
+ }
104
+
105
+ type SortableListeners = ReturnType<typeof useSortable>["listeners"];
106
+
107
+ // The keyboard sensor binds `onKeyDown`; the pointer sensors bind the rest.
108
+ function splitListeners(listeners: SortableListeners): { keyboard: SortableListeners; pointer: SortableListeners } {
109
+ const entries = Object.entries(listeners ?? {});
110
+ return {
111
+ keyboard: Object.fromEntries(entries.filter(([name]) => name === "onKeyDown")),
112
+ pointer: Object.fromEntries(entries.filter(([name]) => name !== "onKeyDown")),
113
+ };
114
+ }
115
+
116
+ interface SortableListContextValue {
117
+ readonly dragBy: SortableDragBy;
118
+ readonly isDisabled: boolean;
119
+ }
120
+
121
+ const SortableListContext = createContext<SortableListContextValue>({ dragBy: "row", isDisabled: false });
122
+
123
+ interface SortableItemBinding extends Pick<ReturnType<typeof useSortable>, "attributes" | "listeners" | "setActivatorNodeRef"> {
124
+ readonly dragBy: SortableDragBy;
125
+ readonly isDisabled: boolean;
126
+ }
127
+
128
+ const SortableItemContext = createContext<SortableItemBinding | null>(null);
129
+
130
+ // A list whose rows are reordered by dragging: a long press lifts a row on a touch screen (a swipe before the hold
131
+ // still scrolls, a tap still activates the row), a mouse drags it, the keyboard picks it up with Space or Enter and
132
+ // moves it with the arrows. The order stays with the app: `onReorder` gets the new one. While a row is lifted the
133
+ // list carries `data-sorting`.
134
+ export function SortableList({
135
+ label,
136
+ items,
137
+ onReorder,
138
+ dragBy = "row",
139
+ holdDelay = 500,
140
+ tolerance = 8,
141
+ instructions = messages.sortable.instructions,
142
+ announcements,
143
+ getItemLabel = (id) => id,
144
+ disabled = false,
145
+ as: List = "ul",
146
+ onDragStart,
147
+ onDragEnd,
148
+ onDragCancel,
149
+ ref,
150
+ className,
151
+ children,
152
+ ...props
153
+ }: SortableListProps) {
154
+ const contextId = useId();
155
+ const [isSorting, setIsSorting] = useState(false);
156
+ const hold = { delay: holdDelay, tolerance };
157
+ const sensors = useSensors(
158
+ useSensor(MouseSensor, {
159
+ activationConstraint: dragBy === "handle" ? { distance: HANDLE_MOUSE_DISTANCE } : hold,
160
+ }),
161
+ useSensor(TouchSensor, { activationConstraint: hold }),
162
+ useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
163
+ );
164
+ const copy = { ...messages.sortable, ...announcements };
165
+ const lastOverId = useRef<UniqueIdentifier | null>(null);
166
+ const total = items.length;
167
+
168
+ function announce(template: string, id: UniqueIdentifier, overId?: UniqueIdentifier): string {
169
+ const position = items.indexOf(String(overId ?? id)) + 1;
170
+ return fillAnnouncement(template, { item: getItemLabel(String(id)), position, total });
171
+ }
172
+
173
+ const liveAnnouncements: Announcements = {
174
+ onDragStart: ({ active }) => {
175
+ lastOverId.current = active.id;
176
+ return announce(copy.pickedUp, active.id);
177
+ },
178
+ onDragOver: ({ active, over }) => {
179
+ // The first `over` of a drag is the row's own place: keep the "picked up" announcement.
180
+ if (!over || over.id === lastOverId.current) return undefined;
181
+ lastOverId.current = over.id;
182
+ return announce(copy.moved, active.id, over.id);
183
+ },
184
+ onDragEnd: ({ active, over }) => announce(over ? copy.dropped : copy.cancelled, active.id, over?.id),
185
+ onDragCancel: ({ active }) => announce(copy.cancelled, active.id),
186
+ };
187
+
188
+ // The move a drop makes, or null when it keeps the order (no target, the row's own place, another group).
189
+ function getMove({ active, over }: DragEndEvent): SortableMove | null {
190
+ if (!over || active.id === over.id) return null;
191
+ if (readGroup(active.data.current) !== readGroup(over.data.current)) return null;
192
+ const from = items.indexOf(String(active.id));
193
+ const to = items.indexOf(String(over.id));
194
+ if (from < 0 || to < 0) return null;
195
+ return { id: String(active.id), from, to };
196
+ }
197
+
198
+ function handleDragEnd(event: DragEndEvent) {
199
+ setIsSorting(false);
200
+ const move = getMove(event);
201
+ if (move) onReorder(arrayMove([...items], move.from, move.to), move);
202
+ onDragEnd?.(String(event.active.id), move);
203
+ }
204
+
205
+ return (
206
+ <DndContext
207
+ id={contextId}
208
+ sensors={sensors}
209
+ collisionDetection={closestCenter}
210
+ modifiers={[restrictToVerticalAxis]}
211
+ accessibility={{ announcements: liveAnnouncements, screenReaderInstructions: { draggable: instructions } }}
212
+ onDragStart={({ active }) => {
213
+ setIsSorting(true);
214
+ onDragStart?.(String(active.id));
215
+ }}
216
+ onDragEnd={handleDragEnd}
217
+ onDragCancel={({ active }) => {
218
+ setIsSorting(false);
219
+ onDragCancel?.(String(active.id));
220
+ }}
221
+ >
222
+ <SortableContext items={[...items]} strategy={verticalListSortingStrategy}>
223
+ <SortableListContext.Provider value={{ dragBy, isDisabled: disabled }}>
224
+ <List
225
+ ref={(node: HTMLUListElement | HTMLOListElement | null) => assignRef(ref, node)}
226
+ aria-label={label}
227
+ data-slot="sortable-list"
228
+ data-drag-by={dragBy}
229
+ data-disabled={disabled ? "" : undefined}
230
+ data-sorting={isSorting ? "" : undefined}
231
+ className={cn("flex flex-col", className)}
232
+ {...props}
233
+ >
234
+ {children}
235
+ </List>
236
+ </SortableListContext.Provider>
237
+ </SortableContext>
238
+ </DndContext>
239
+ );
240
+ }
241
+
242
+ export interface SortableItemProps extends ComponentProps<"li"> {
243
+ // The row's id, one of the list's `items`.
244
+ readonly id: string;
245
+ // A lifted row lands only among rows of its own group; rows without one form a group of their own.
246
+ readonly group?: string;
247
+ // This row does not lift; it wins over the list's `disabled`. Other rows may still move past it.
248
+ readonly disabled?: boolean;
249
+ }
250
+
251
+ // The lifted row floats on `accent-strong` with `shadow-menu`, above its siblings; `data-dragging` marks it.
252
+ const SORTABLE_ITEM =
253
+ "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";
254
+
255
+ // The drag props the row element itself carries.
256
+ function getRowBinding(binding: SortableItemBinding) {
257
+ if (binding.isDisabled || binding.dragBy === "handle") return {};
258
+ if (binding.dragBy === "activator") return { ...binding.attributes, ...splitListeners(binding.listeners).keyboard };
259
+ return { ...binding.attributes, ...binding.listeners };
260
+ }
261
+
262
+ // One row of a `SortableList`. In `row` mode the row itself is the drag target and is focusable; in `handle` mode a
263
+ // `SortableHandle` inside it is; in `activator` mode a `SortableActivator` takes the press and the row the keyboard.
264
+ // The drag's own pointer and key handlers win over the same props on the drag target; a key pressed on a control
265
+ // inside the row stays with that control.
266
+ export function SortableItem({ id, group, disabled, className, style, children, ...props }: SortableItemProps) {
267
+ const list = useContext(SortableListContext);
268
+ const { active } = useDndContext();
269
+ const isDisabled = disabled ?? list.isDisabled;
270
+ const isOtherGroup = active !== null && readGroup(active.data.current) !== group;
271
+ const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
272
+ id,
273
+ data: { group },
274
+ attributes: { role: "listitem" },
275
+ disabled: { draggable: isDisabled, droppable: isOtherGroup },
276
+ });
277
+ const binding: SortableItemBinding = { attributes, listeners, setActivatorNodeRef, dragBy: list.dragBy, isDisabled };
278
+ const isRowActivator = list.dragBy !== "handle";
279
+ // The row is the keyboard's activator outside `handle` mode, so a key on a control inside the row stays there.
280
+ const setRowRef = useCallback(
281
+ (node: HTMLLIElement | null) => {
282
+ setNodeRef(node);
283
+ if (isRowActivator) setActivatorNodeRef(node);
284
+ },
285
+ [setNodeRef, setActivatorNodeRef, isRowActivator],
286
+ );
287
+ return (
288
+ <SortableItemContext.Provider value={binding}>
289
+ <li
290
+ ref={setRowRef}
291
+ data-slot="sortable-item"
292
+ data-id={id}
293
+ data-group={group}
294
+ data-disabled={isDisabled ? "" : undefined}
295
+ data-dragging={isDragging ? "" : undefined}
296
+ className={cn(SORTABLE_ITEM, className)}
297
+ style={{ ...style, transform: CSS.Translate.toString(transform), transition }}
298
+ {...props}
299
+ {...getRowBinding(binding)}
300
+ >
301
+ {children}
302
+ </li>
303
+ </SortableItemContext.Provider>
304
+ );
305
+ }
306
+
307
+ function useSortableItemBinding(part: string): SortableItemBinding {
308
+ const binding = useContext(SortableItemContext);
309
+ if (!binding) throw new Error(`${part} failed: it must be rendered inside a SortableItem`);
310
+ return binding;
311
+ }
312
+
313
+ export type SortableActivatorProps = ComponentProps<typeof Slot.Root>;
314
+
315
+ // The app's own element inside a row (a button, a title) that lifts the row on a press, for a list with
316
+ // `dragBy="activator"`; a press elsewhere in the row does nothing. Its own click and keys keep working. In the other
317
+ // modes, or on a disabled row, it renders its child unchanged.
318
+ export function SortableActivator(props: SortableActivatorProps) {
319
+ const binding = useSortableItemBinding("SortableActivator");
320
+ const isBound = binding.dragBy === "activator" && !binding.isDisabled;
321
+ const pointer = isBound ? splitListeners(binding.listeners).pointer : {};
322
+ return <Slot.Root data-slot="sortable-activator" {...props} {...pointer} />;
323
+ }
324
+
325
+ export interface SortableHandleProps extends Omit<ComponentProps<typeof Button>, "children"> {
326
+ // The handle's accessible name.
327
+ readonly label?: string;
328
+ }
329
+
330
+ // A grip button that drags its row, for a list with `dragBy="handle"`.
331
+ // On a disabled row it is a disabled button.
332
+ export function SortableHandle({ label = messages.sortable.handle, className, disabled, ...props }: SortableHandleProps) {
333
+ const { attributes, listeners, setActivatorNodeRef, isDisabled } = useSortableItemBinding("SortableHandle");
334
+ const dragProps = isDisabled ? {} : { ...attributes, ...listeners };
335
+ return (
336
+ <Button
337
+ ref={setActivatorNodeRef}
338
+ type="button"
339
+ variant="ghost"
340
+ size="icon-sm"
341
+ data-slot="sortable-handle"
342
+ className={cn("cursor-grab touch-none text-muted-foreground active:cursor-grabbing", className)}
343
+ disabled={isDisabled || disabled}
344
+ {...props}
345
+ {...dragProps}
346
+ role="button"
347
+ aria-label={label}
348
+ >
349
+ <GripVertical aria-hidden="true" strokeWidth={ICON_STROKE_WIDTH} />
350
+ </Button>
351
+ );
352
+ }
@@ -2,10 +2,11 @@ import { ChevronRight } from "lucide-react";
2
2
  import type { ReactNode } from "react";
3
3
 
4
4
  import { Badge } from "../ui/badge.js";
5
+ import { Progress } from "../ui/progress.js";
5
6
  import { cn } from "../lib/utils.js";
6
7
 
7
8
  import { ICON_STROKE_WIDTH } from "./icon-stroke.js";
8
- import { TONE_COLORS, TONE_TEXT, type Tone } from "./tones.js";
9
+ import { TONE_COLORS, TONE_FILL, TONE_TEXT, type Tone } from "./tones.js";
9
10
 
10
11
  export interface StatsFoldProps {
11
12
  /** The section's heading. */
@@ -50,6 +51,10 @@ export interface StatCard {
50
51
  readonly hint?: string;
51
52
  readonly tone?: Tone;
52
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;
53
58
  }
54
59
 
55
60
  export interface StatCardsProps {
@@ -62,13 +67,19 @@ export interface StatCardsProps {
62
67
  readonly isOneRow?: boolean;
63
68
  }
64
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
+
65
75
  function getStatCardsLayout(isFullWidth: boolean, isOneRow: boolean): "row" | "full" | "grid" {
66
76
  if (isOneRow) return "row";
67
77
  return isFullWidth ? "full" : "grid";
68
78
  }
69
79
 
70
80
  // Summary figures as a row of cards wrapping on a narrow screen: the label, the figure in its tone's colour (never
71
- // broken, tabular numbers), an optional note under it and an optional short figure on its right as a tag.
81
+ // broken, tabular numbers), an optional bar under it, an optional note and an optional short figure on its right as a
82
+ // tag.
72
83
  export function StatCards({ label, cards, isFullWidth = false, isOneRow = false }: StatCardsProps) {
73
84
  return (
74
85
  <ul
@@ -91,11 +102,20 @@ export function StatCards({ label, cards, isFullWidth = false, isOneRow = false
91
102
  data-stat={card.key}
92
103
  className="flex min-w-0 items-start justify-between gap-2 rounded-lg bg-card p-3 text-card-foreground shadow-card"
93
104
  >
94
- <div className="min-w-0">
105
+ <div className={cn("min-w-0", card.progress !== undefined && "flex-1")}>
95
106
  <div className="text-section-label text-muted-foreground">{card.label}</div>
96
107
  <div data-tone={tone} className={cn("mt-1 text-heading-3 whitespace-nowrap tabular-nums", TONE_TEXT[tone])}>
97
108
  {card.value}
98
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
+ )}
99
119
  {card.hint === undefined ? null : <div className="mt-1 text-small text-muted-foreground">{card.hint}</div>}
100
120
  </div>
101
121
  {card.aside === undefined ? null : (
@@ -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
+ }
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
+ }
package/src/tokens.ts CHANGED
@@ -14,67 +14,69 @@ export const NOTION_THEME = defineTheme({
14
14
  "card-foreground": { light: "#37352f", dark: "#d4d4d4" },
15
15
  popover: { light: "#ffffff", dark: "#252525" },
16
16
  "popover-foreground": { light: "#37352f", dark: "#d4d4d4" },
17
- primary: { light: "#2383e2", dark: "#2383e2" },
17
+ primary: { light: "#0171cf", dark: "#0171cf" },
18
18
  "primary-foreground": { light: "#ffffff", dark: "#ffffff" },
19
- "primary-hover": { light: "#0077d4", dark: "#0077d4" },
19
+ "primary-hover": { light: "#0066b8", dark: "#0066b8" },
20
+ link: { light: "#0171cf", dark: "#409cfd" },
20
21
  secondary: { light: "#f1f1ef", dark: "#2f2f2f" },
21
22
  "secondary-foreground": { light: "#37352f", dark: "#d4d4d4" },
23
+ "code-foreground": { light: "#c33c39", dark: "#f86a66" },
22
24
  muted: { light: "#f7f7f5", dark: "#202020" },
23
- "muted-foreground": { light: "#787774", dark: "#9b9b9b" },
25
+ "muted-foreground": { light: "#656461", dark: "#a5a5a5" },
24
26
  accent: { light: "rgba(55, 53, 47, 0.08)", dark: "rgba(255, 255, 255, 0.055)" },
25
27
  "accent-foreground": { light: "#37352f", dark: "#d4d4d4" },
26
28
  "accent-strong": { light: "rgba(55, 53, 47, 0.16)", dark: "rgba(255, 255, 255, 0.1)" },
27
- destructive: { light: "#eb5757", dark: "#eb5757" },
29
+ destructive: { light: "#c63339", dark: "#fd6866" },
28
30
  "destructive-foreground": { light: "#ffffff", dark: "#ffffff" },
29
31
  border: { light: "#e9e9e7", dark: "#2f2f2f" },
30
- input: { light: "rgba(15, 15, 15, 0.1)", dark: "rgba(255, 255, 255, 0.075)" },
32
+ input: { light: "rgba(15, 15, 15, 0.46)", dark: "rgba(255, 255, 255, 0.36)" },
31
33
  field: { light: "rgba(242, 241, 238, 0.6)", dark: "rgba(255, 255, 255, 0.055)" },
32
- "control-off": { light: "rgba(135, 131, 120, 0.3)", dark: "rgba(202, 196, 183, 0.15)" },
33
- ring: { light: "rgba(35, 131, 226, 0.57)", dark: "rgba(35, 131, 226, 0.57)" },
34
+ "control-off": { light: "rgba(135, 131, 120, 0.95)", dark: "rgba(202, 196, 183, 0.5)" },
35
+ ring: { light: "rgba(1, 113, 207, 0.8)", dark: "rgba(64, 156, 253, 0.65)" },
34
36
  sidebar: { light: "#f7f7f5", dark: "#202020" },
35
37
  "sidebar-foreground": { light: "#5f5e5b", dark: "#9b9b9b" },
36
- "sidebar-primary": { light: "#2383e2", dark: "#2383e2" },
38
+ "sidebar-primary": { light: "#0171cf", dark: "#0171cf" },
37
39
  "sidebar-primary-foreground": { light: "#ffffff", dark: "#ffffff" },
38
40
  "sidebar-accent": { light: "rgba(55, 53, 47, 0.08)", dark: "rgba(255, 255, 255, 0.055)" },
39
41
  "sidebar-accent-foreground": { light: "#37352f", dark: "#d4d4d4" },
40
42
  "sidebar-border": { light: "#ededeb", dark: "#2a2a2a" },
41
- "sidebar-ring": { light: "rgba(35, 131, 226, 0.57)", dark: "rgba(35, 131, 226, 0.57)" },
43
+ "sidebar-ring": { light: "rgba(1, 113, 207, 0.8)", dark: "rgba(64, 156, 253, 0.65)" },
42
44
  tooltip: { light: "#0f0f0f", dark: "#373737" },
43
45
  "tooltip-foreground": { light: "rgba(255, 255, 255, 0.9)", dark: "rgba(255, 255, 255, 0.9)" },
44
46
  overlay: { light: "rgba(15, 15, 15, 0.6)", dark: "rgba(0, 0, 0, 0.6)" },
45
- gray: { light: "#787774", dark: "#9b9b9b" },
47
+ gray: { light: "#656461", dark: "#a5a5a5" },
46
48
  "gray-bg": { light: "#f1f1ef", dark: "#2f2f2f" },
47
49
  "gray-tag": { light: "#e3e2e0", dark: "#5a5a5a" },
48
50
  "gray-tag-foreground": { light: "#32302c", dark: "rgba(255, 255, 255, 0.81)" },
49
- brown: { light: "#9f6b53", dark: "#ba856f" },
51
+ brown: { light: "#98644d", dark: "#ba856f" },
50
52
  "brown-bg": { light: "#f4eeee", dark: "#4a3228" },
51
53
  "brown-tag": { light: "#eee0da", dark: "#603b2c" },
52
54
  "brown-tag-foreground": { light: "#442a1e", dark: "rgba(255, 255, 255, 0.81)" },
53
- orange: { light: "#d9730d", dark: "#c77d48" },
55
+ orange: { light: "#af5a02", dark: "#c77d48" },
54
56
  "orange-bg": { light: "#fbecdd", dark: "#5c3b23" },
55
57
  "orange-tag": { light: "#fadec9", dark: "#854c1d" },
56
58
  "orange-tag-foreground": { light: "#49290e", dark: "rgba(255, 255, 255, 0.81)" },
57
- yellow: { light: "#cb912f", dark: "#ca984d" },
59
+ yellow: { light: "#986702", dark: "#ca984d" },
58
60
  "yellow-bg": { light: "#fbf3db", dark: "#564328" },
59
- "yellow-tag": { light: "#fdecc8", dark: "#89632a" },
61
+ "yellow-tag": { light: "#fdecc8", dark: "#825c23" },
60
62
  "yellow-tag-foreground": { light: "#402c1b", dark: "rgba(255, 255, 255, 0.81)" },
61
- green: { light: "#448361", dark: "#529e72" },
63
+ green: { light: "#3e7d5c", dark: "#529e72" },
62
64
  "green-bg": { light: "#edf3ec", dark: "#243d30" },
63
65
  "green-tag": { light: "#dbeddb", dark: "#2b593f" },
64
66
  "green-tag-foreground": { light: "#1c3829", dark: "rgba(255, 255, 255, 0.81)" },
65
- blue: { light: "#337ea9", dark: "#379ad3" },
67
+ blue: { light: "#2b77a2", dark: "#379ad3" },
66
68
  "blue-bg": { light: "#e7f3f8", dark: "#143a4e" },
67
69
  "blue-tag": { light: "#d3e5ef", dark: "#28456c" },
68
70
  "blue-tag-foreground": { light: "#183347", dark: "rgba(255, 255, 255, 0.81)" },
69
- purple: { light: "#9065b0", dark: "#9d68d3" },
71
+ purple: { light: "#8a5faa", dark: "#a974e0" },
70
72
  "purple-bg": { light: "#f6f3f9", dark: "#3c2d49" },
71
73
  "purple-tag": { light: "#e8deee", dark: "#492f64" },
72
74
  "purple-tag-foreground": { light: "#412454", dark: "rgba(255, 255, 255, 0.81)" },
73
- pink: { light: "#c14c8a", dark: "#d15796" },
75
+ pink: { light: "#ba4684", dark: "#dc61a0" },
74
76
  "pink-bg": { light: "#faf1f5", dark: "#4e2c3c" },
75
77
  "pink-tag": { light: "#f5e0e9", dark: "#69314c" },
76
78
  "pink-tag-foreground": { light: "#4c2337", dark: "rgba(255, 255, 255, 0.81)" },
77
- red: { light: "#d44c47", dark: "#df5452" },
79
+ red: { light: "#c8413d", dark: "#ea5e5b" },
78
80
  "red-bg": { light: "#fdebec", dark: "#522e2a" },
79
81
  "red-tag": { light: "#ffe2dd", dark: "#6e3630" },
80
82
  "red-tag-foreground": { light: "#5d1715", dark: "rgba(255, 255, 255, 0.81)" },
@@ -131,6 +133,7 @@ export const NOTION_THEME = defineTheme({
131
133
  "content-width-wide": "1152px",
132
134
  "control-height": "28px",
133
135
  "row-height": "34px",
136
+ "touch-target": "44px",
134
137
  },
135
138
  // The design system allows only its own colours, so no raw Tailwind colour utility exists.
136
139
  clearDefaultPalette: true,
package/src/ui/alert.tsx CHANGED
@@ -9,7 +9,7 @@ const alertVariants = cva(
9
9
  variant: {
10
10
  default: "bg-card text-card-foreground",
11
11
  destructive:
12
- "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current",
12
+ "bg-card text-destructive *:data-[slot=alert-description]:text-destructive [&>svg]:text-current",
13
13
  gray: "border-transparent bg-gray-bg text-foreground [&>svg]:text-gray *:data-[slot=alert-description]:text-foreground",
14
14
  brown: "border-transparent bg-brown-bg text-foreground [&>svg]:text-brown *:data-[slot=alert-description]:text-foreground",
15
15
  orange: "border-transparent bg-orange-bg text-foreground [&>svg]:text-orange *:data-[slot=alert-description]:text-foreground",