basalt-ui 2.13.3 → 2.15.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 (187) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/MIGRATING.md +42 -12
  3. package/agent/agents/basalt-design-reviewer.md +83 -0
  4. package/agent/rules/basalt-batteries.md +1 -2
  5. package/agent/rules/basalt-charts.md +1 -1
  6. package/agent/rules/basalt-controls.md +3 -3
  7. package/agent/rules/basalt-mantine.md +1 -2
  8. package/agent/rules/basalt-state.md +1 -2
  9. package/agent/rules/basalt-tokens.md +1 -3
  10. package/agent/skills/basalt-design/SKILL.md +26 -8
  11. package/agent/templates/AGENTS-block.md.tpl +7 -0
  12. package/configs/oxlint-plugin.js +39 -2
  13. package/configs/oxlint-plugin.test.ts +48 -0
  14. package/dist/agent/chat/thread-feed-row.d.ts.map +1 -1
  15. package/dist/agent/chat/thread-feed-row.js +2 -2
  16. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  17. package/dist/agent/chat/thread-message.js +2 -2
  18. package/dist/agent/chat/thread-outcome-card.js +2 -2
  19. package/dist/charts/DualPanel.d.ts.map +1 -1
  20. package/dist/charts/DualPanel.js +1 -0
  21. package/dist/charts/compile.d.ts.map +1 -1
  22. package/dist/charts/compile.js +3 -2
  23. package/dist/charts/cursor.d.ts +10 -6
  24. package/dist/charts/cursor.d.ts.map +1 -1
  25. package/dist/charts/cursor.js +20 -13
  26. package/dist/charts/legend.d.ts +7 -6
  27. package/dist/charts/legend.d.ts.map +1 -1
  28. package/dist/charts/legend.js +3 -3
  29. package/dist/charts/panel.d.ts +2 -0
  30. package/dist/charts/panel.d.ts.map +1 -1
  31. package/dist/charts/panel.js +1 -0
  32. package/dist/cli/board-freshness.d.ts +25 -0
  33. package/dist/cli/board-freshness.d.ts.map +1 -0
  34. package/dist/cli/board-freshness.js +88 -0
  35. package/dist/cli/doctor.d.ts +2 -1
  36. package/dist/cli/doctor.d.ts.map +1 -1
  37. package/dist/cli/doctor.js +3 -1
  38. package/dist/cli/help.d.ts.map +1 -1
  39. package/dist/cli/help.js +9 -3
  40. package/dist/cli/index.d.ts +15 -1
  41. package/dist/cli/index.d.ts.map +1 -1
  42. package/dist/cli/index.js +57 -7
  43. package/dist/cli/init.d.ts.map +1 -1
  44. package/dist/cli/init.js +6 -1
  45. package/dist/cli/shot/board.d.ts +5 -0
  46. package/dist/cli/shot/board.d.ts.map +1 -0
  47. package/dist/cli/shot/board.js +96 -0
  48. package/dist/cli/shot/capture.d.ts +59 -0
  49. package/dist/cli/shot/capture.d.ts.map +1 -0
  50. package/dist/cli/shot/capture.js +473 -0
  51. package/dist/cli/shot/index.d.ts +45 -0
  52. package/dist/cli/shot/index.d.ts.map +1 -0
  53. package/dist/cli/shot/index.js +289 -0
  54. package/dist/cli/shot/measure.d.ts +28 -0
  55. package/dist/cli/shot/measure.d.ts.map +1 -0
  56. package/dist/cli/shot/measure.js +176 -0
  57. package/dist/cli/shot/playwright.d.ts +101 -0
  58. package/dist/cli/shot/playwright.d.ts.map +1 -0
  59. package/dist/cli/shot/playwright.js +60 -0
  60. package/dist/cli/shot/serve.d.ts +6 -0
  61. package/dist/cli/shot/serve.d.ts.map +1 -0
  62. package/dist/cli/shot/serve.js +33 -0
  63. package/dist/cli/shot/types.d.ts +97 -0
  64. package/dist/cli/shot/types.d.ts.map +1 -0
  65. package/dist/cli/shot/types.js +17 -0
  66. package/dist/cli/sync.d.ts.map +1 -1
  67. package/dist/cli/sync.js +2 -1
  68. package/dist/commands/notifications/center.d.ts.map +1 -1
  69. package/dist/commands/notifications/center.js +2 -11
  70. package/dist/controls/control-name.d.ts +27 -0
  71. package/dist/controls/control-name.d.ts.map +1 -0
  72. package/dist/controls/control-name.js +11 -0
  73. package/dist/controls/enum-filter.d.ts +3 -6
  74. package/dist/controls/enum-filter.d.ts.map +1 -1
  75. package/dist/controls/enum-filter.js +8 -4
  76. package/dist/controls/filter-base.d.ts +30 -0
  77. package/dist/controls/filter-base.d.ts.map +1 -0
  78. package/dist/controls/filter-base.js +0 -0
  79. package/dist/controls/filter-pill.d.ts +3 -1
  80. package/dist/controls/filter-pill.d.ts.map +1 -1
  81. package/dist/controls/filter-pill.js +2 -0
  82. package/dist/controls/filter-sheet.d.ts +0 -32
  83. package/dist/controls/filter-sheet.d.ts.map +1 -1
  84. package/dist/controls/filter-sheet.js +1 -28
  85. package/dist/controls/glyphs.d.ts +12 -0
  86. package/dist/controls/glyphs.d.ts.map +1 -1
  87. package/dist/controls/glyphs.js +23 -2
  88. package/dist/controls/index.d.ts +2 -1
  89. package/dist/controls/index.d.ts.map +1 -1
  90. package/dist/controls/multi-select-filter.d.ts +8 -3
  91. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  92. package/dist/controls/multi-select-filter.js +27 -10
  93. package/dist/controls/number-filter.d.ts +3 -12
  94. package/dist/controls/number-filter.d.ts.map +1 -1
  95. package/dist/controls/number-filter.js +17 -6
  96. package/dist/controls/panel-row.d.ts +5 -8
  97. package/dist/controls/panel-row.d.ts.map +1 -1
  98. package/dist/controls/panel-row.js +3 -0
  99. package/dist/controls/range-filter.d.ts +14 -14
  100. package/dist/controls/range-filter.d.ts.map +1 -1
  101. package/dist/controls/range-filter.js +18 -41
  102. package/dist/controls/search-filter.d.ts +5 -2
  103. package/dist/controls/search-filter.d.ts.map +1 -1
  104. package/dist/controls/search-filter.js +74 -40
  105. package/dist/controls/select-filter.d.ts +2 -15
  106. package/dist/controls/select-filter.d.ts.map +1 -1
  107. package/dist/controls/sync-button.d.ts +0 -6
  108. package/dist/controls/sync-button.d.ts.map +1 -1
  109. package/dist/controls/sync-button.js +6 -36
  110. package/dist/controls/toggle-filter.d.ts +2 -2
  111. package/dist/controls/toggle-filter.d.ts.map +1 -1
  112. package/dist/controls/toggle-filter.js +3 -2
  113. package/dist/controls/view-tabs.d.ts +3 -4
  114. package/dist/controls/view-tabs.d.ts.map +1 -1
  115. package/dist/controls/view-tabs.js +24 -5
  116. package/dist/format/date.d.ts +43 -10
  117. package/dist/format/date.d.ts.map +1 -1
  118. package/dist/format/date.js +109 -18
  119. package/dist/format/index.d.ts +12 -11
  120. package/dist/format/index.d.ts.map +1 -1
  121. package/dist/format/index.js +11 -2
  122. package/dist/format/measure.d.ts +9 -9
  123. package/dist/format/measure.d.ts.map +1 -1
  124. package/dist/format/measure.js +19 -8
  125. package/dist/format/number.d.ts +35 -27
  126. package/dist/format/number.d.ts.map +1 -1
  127. package/dist/format/number.js +41 -20
  128. package/dist/format/shared.d.ts +38 -7
  129. package/dist/format/shared.d.ts.map +1 -1
  130. package/dist/format/shared.js +61 -13
  131. package/dist/provider/index.d.ts +13 -1
  132. package/dist/provider/index.d.ts.map +1 -1
  133. package/dist/provider/index.js +8 -0
  134. package/dist/surfaces.d.ts +2 -0
  135. package/dist/surfaces.d.ts.map +1 -1
  136. package/dist/surfaces.js +2 -0
  137. package/llms.txt +35 -14
  138. package/package.json +1 -1
  139. package/src/agent/chat/thread-feed-row.tsx +2 -2
  140. package/src/agent/chat/thread-message.tsx +2 -2
  141. package/src/agent/chat/thread-outcome-card.tsx +2 -2
  142. package/src/charts/DualPanel.tsx +1 -0
  143. package/src/charts/compile.ts +3 -2
  144. package/src/charts/cursor.ts +44 -27
  145. package/src/charts/legend.tsx +11 -8
  146. package/src/charts/panel.tsx +3 -0
  147. package/src/cli/board-freshness.ts +132 -0
  148. package/src/cli/doctor.ts +10 -1
  149. package/src/cli/help.ts +14 -2
  150. package/src/cli/index.ts +80 -10
  151. package/src/cli/init.ts +8 -1
  152. package/src/cli/shot/board.ts +154 -0
  153. package/src/cli/shot/capture.ts +650 -0
  154. package/src/cli/shot/index.ts +362 -0
  155. package/src/cli/shot/measure.ts +225 -0
  156. package/src/cli/shot/playwright.ts +152 -0
  157. package/src/cli/shot/serve.ts +35 -0
  158. package/src/cli/shot/types.ts +91 -0
  159. package/src/cli/sync.ts +2 -1
  160. package/src/commands/notifications/center.tsx +2 -14
  161. package/src/controls/control-name.ts +33 -0
  162. package/src/controls/enum-filter.tsx +29 -27
  163. package/src/controls/filter-base.ts +31 -0
  164. package/src/controls/filter-pill.tsx +4 -0
  165. package/src/controls/filter-sheet.tsx +0 -56
  166. package/src/controls/glyphs.tsx +45 -2
  167. package/src/controls/index.ts +2 -1
  168. package/src/controls/multi-select-filter.tsx +67 -43
  169. package/src/controls/number-filter.tsx +47 -47
  170. package/src/controls/panel-row.tsx +7 -8
  171. package/src/controls/range-filter.tsx +54 -78
  172. package/src/controls/search-filter.tsx +107 -54
  173. package/src/controls/select-filter.tsx +2 -18
  174. package/src/controls/sync-button.tsx +7 -40
  175. package/src/controls/toggle-filter.tsx +9 -7
  176. package/src/controls/view-tabs.tsx +41 -21
  177. package/src/format/date.ts +189 -36
  178. package/src/format/index.ts +12 -11
  179. package/src/format/measure.ts +29 -18
  180. package/src/format/number.ts +76 -37
  181. package/src/format/shared.ts +116 -25
  182. package/src/provider/index.tsx +23 -0
  183. package/src/surfaces.ts +5 -0
  184. package/dist/agent/chat/relative-time.d.ts +0 -27
  185. package/dist/agent/chat/relative-time.d.ts.map +0 -1
  186. package/dist/agent/chat/relative-time.js +0 -27
  187. package/src/agent/chat/relative-time.ts +0 -55
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Playwright, resolved from the CONSUMER (it is not a basalt dependency) and typed through the
3
+ * minimal structural surface `shot` uses — the package never imports Playwright at build time.
4
+ * The real `playwright-core` types satisfy this surface, so callers keep their own types.
5
+ */
6
+ import { createRequire } from 'node:module'
7
+ import { join } from 'node:path'
8
+
9
+ import type { Scheme } from './types'
10
+
11
+ export const INSTALL_LINE =
12
+ 'basalt-ui shot needs Playwright: bun add -d playwright && bunx playwright install chromium'
13
+
14
+ const KILL_TIMEOUT_MS = 10_000
15
+
16
+ export type Box = { x: number; y: number; width: number; height: number }
17
+
18
+ export type ShotOptions = {
19
+ path: string
20
+ animations: 'disabled'
21
+ caret: 'hide'
22
+ fullPage?: boolean
23
+ clip?: Box
24
+ }
25
+
26
+ export type PwLocator = {
27
+ first(): PwLocator
28
+ count(): Promise<number>
29
+ hover(options?: { timeout?: number }): Promise<void>
30
+ isVisible(): Promise<boolean>
31
+ boundingBox(): Promise<Box | null>
32
+ scrollIntoViewIfNeeded(): Promise<void>
33
+ waitFor(options: { state: 'visible'; timeout: number }): Promise<void>
34
+ screenshot(options: ShotOptions): Promise<unknown>
35
+ evaluate<R>(fn: (el: Element) => R): Promise<R>
36
+ }
37
+
38
+ export type PwPage = {
39
+ goto(url: string, options: { waitUntil: 'load' | 'networkidle' }): Promise<unknown>
40
+ setDefaultTimeout(ms: number): void
41
+ locator(selector: string): PwLocator
42
+ evaluate<R>(expression: string): Promise<R>
43
+ evaluate<R, A>(fn: (arg: A) => R, arg: A): Promise<R>
44
+ setContent(html: string, options: { waitUntil: 'load' }): Promise<void>
45
+ keyboard: { press(key: string): Promise<void> }
46
+ mouse: { move(x: number, y: number): Promise<void> }
47
+ screenshot(options: ShotOptions): Promise<unknown>
48
+ }
49
+
50
+ export type PwContext = {
51
+ newPage(): Promise<PwPage>
52
+ addInitScript(script: string): Promise<unknown>
53
+ close(): Promise<void>
54
+ }
55
+
56
+ export type ContextOptions = {
57
+ viewport: { width: number; height: number }
58
+ deviceScaleFactor: number
59
+ isMobile: boolean
60
+ hasTouch: boolean
61
+ colorScheme: Scheme
62
+ reducedMotion: 'reduce'
63
+ }
64
+
65
+ export type PwBrowser<C extends PwContext = PwContext> = {
66
+ newContext(options: ContextOptions): Promise<C>
67
+ }
68
+
69
+ type PwServer = { wsEndpoint(): string; kill(): Promise<void> }
70
+ export type Playwright<B extends PwBrowser = PwBrowser> = {
71
+ chromium: {
72
+ launchServer(options: { channel?: string; chromiumSandbox: boolean }): Promise<PwServer>
73
+ connect(wsEndpoint: string): Promise<B>
74
+ }
75
+ }
76
+
77
+ /** Thrown for failures that print one line and exit 1 (no stack). */
78
+ export class ShotError extends Error {}
79
+
80
+ export type PlaywrightResolver = (cwd: string) => Playwright | null
81
+
82
+ export const isPlaywright = (mod: unknown): mod is Playwright => {
83
+ const chromium = (mod as { chromium?: Record<string, unknown> } | null)?.chromium
84
+ return (
85
+ typeof chromium?.['launchServer'] === 'function' && typeof chromium['connect'] === 'function'
86
+ )
87
+ }
88
+
89
+ export const resolvePlaywright: PlaywrightResolver = (cwd) => {
90
+ const require = createRequire(join(cwd, 'package.json'))
91
+ for (const name of ['playwright', 'playwright-core']) {
92
+ try {
93
+ const mod: unknown = require(name)
94
+ if (isPlaywright(mod)) return mod
95
+ } catch {
96
+ // not installed under this name: try the next
97
+ }
98
+ }
99
+ return null
100
+ }
101
+
102
+ const firstLine = (error: unknown): string =>
103
+ (error instanceof Error ? error.message : String(error)).split('\n')[0] ?? ''
104
+
105
+ /** `kill()` bounded by a hang guard: a graceful stop can wedge under Bun. */
106
+ function killBounded(server: PwServer): Promise<unknown> {
107
+ const guard = new Promise((resolve) => setTimeout(resolve, KILL_TIMEOUT_MS).unref())
108
+ return Promise.race([server.kill().catch(() => undefined), guard])
109
+ }
110
+
111
+ export type LaunchOptions = {
112
+ /** Tried in order; `undefined` is the bundled chromium. Default: bundled, then `chrome`. */
113
+ channels?: readonly (string | undefined)[]
114
+ /** Receives this run's kill, so the caller's signal handler can stop it. */
115
+ stops?: (() => unknown)[]
116
+ }
117
+
118
+ /**
119
+ * One Chrome for `fn`, killed afterwards. `launchServer` + `connect` + `kill()` — a graceful
120
+ * `close()` hangs under Bun. Every failed launch keeps its first error line for the final message.
121
+ */
122
+ export async function withBrowser<B extends PwBrowser, T>(
123
+ pw: Playwright<B>,
124
+ fn: (browser: B, channel: string) => Promise<T>,
125
+ { channels = [undefined, 'chrome'], stops }: LaunchOptions = {},
126
+ ): Promise<T> {
127
+ const chromiumSandbox = !process.env['CI']
128
+ const failures: string[] = []
129
+ for (const channel of channels) {
130
+ const label = channel ?? 'bundled chromium'
131
+ let server: PwServer | undefined
132
+ let browser: B
133
+ try {
134
+ server = await pw.chromium.launchServer(
135
+ channel ? { channel, chromiumSandbox } : { chromiumSandbox },
136
+ )
137
+ browser = await pw.chromium.connect(server.wsEndpoint())
138
+ } catch (error) {
139
+ failures.push(` ${label}: ${firstLine(error)}`)
140
+ if (server) await killBounded(server)
141
+ continue
142
+ }
143
+ const live = server
144
+ stops?.push(() => killBounded(live))
145
+ try {
146
+ return await fn(browser, channel ?? 'chromium')
147
+ } finally {
148
+ await killBounded(live)
149
+ }
150
+ }
151
+ throw new ShotError([INSTALL_LINE, ...failures].join('\n'))
152
+ }
@@ -0,0 +1,35 @@
1
+ import { existsSync, statSync } from 'node:fs'
2
+ import { join, normalize, resolve, sep } from 'node:path'
3
+
4
+ import { ShotError } from './playwright'
5
+
6
+ /** Static server for a built SPA dir: real files as-is, extensionless misses fall back to index.html. */
7
+ export function serveDist(distDir: string): { origin: string; stop: () => void } {
8
+ const root = resolve(distDir)
9
+ if (!existsSync(root) || !statSync(root).isDirectory()) {
10
+ throw new ShotError(`--dist ${distDir} is not a directory`)
11
+ }
12
+ const fileFor = (pathname: string): string | null => {
13
+ const file = normalize(join(root, decodeURIComponent(pathname)))
14
+ if (file !== root && !file.startsWith(root + sep)) return null
15
+ if (existsSync(file) && statSync(file).isFile()) return file
16
+ if (/\.[a-z0-9]+$/i.test(pathname)) return null
17
+ const index = join(root, 'index.html')
18
+ return existsSync(index) ? index : null
19
+ }
20
+ const server = Bun.serve({
21
+ port: 0,
22
+ hostname: '127.0.0.1',
23
+ fetch(req) {
24
+ try {
25
+ const file = fileFor(new URL(req.url).pathname)
26
+ return file
27
+ ? new Response(Bun.file(file), { headers: { 'cache-control': 'no-store' } })
28
+ : new Response('not found', { status: 404 })
29
+ } catch {
30
+ return new Response('bad request', { status: 400 })
31
+ }
32
+ },
33
+ })
34
+ return { origin: `http://127.0.0.1:${server.port}`, stop: () => void server.stop(true) }
35
+ }
@@ -0,0 +1,91 @@
1
+ export const SCHEMES = ['light', 'dark'] as const
2
+ export const VIEWPORTS = ['desktop', 'mobile'] as const
3
+ export const STATES = ['rest', 'hover', 'focus', 'tooltip', 'empty', 'loading', 'error'] as const
4
+ /** The states a page opts into with `data-shot-states`; reached through the `shot-state` URL param. */
5
+ export const URL_STATES = ['empty', 'loading', 'error'] as const
6
+
7
+ /** The `name` of a route's full-page shot: not a valid `data-shot` value. */
8
+ export const PAGE_ANCHOR = '_page'
9
+
10
+ export type Scheme = (typeof SCHEMES)[number]
11
+ export type Viewport = (typeof VIEWPORTS)[number]
12
+ export type ShotState = (typeof STATES)[number]
13
+
14
+ export const VIEWPORT_SPECS: Record<Viewport, { width: number; height: number; mobile: boolean }> =
15
+ {
16
+ desktop: { width: 1440, height: 900, mobile: false },
17
+ mobile: { width: 390, height: 844, mobile: true },
18
+ }
19
+
20
+ export type Sides = { top: number; right: number; bottom: number; left: number }
21
+
22
+ export type ContrastFailure = {
23
+ text: string
24
+ ratio: number
25
+ fg: string
26
+ bg: string
27
+ fontSize: number
28
+ }
29
+
30
+ /** What the in-page measurer returns for one anchor. */
31
+ export type Measurement = {
32
+ box: { width: number; height: number }
33
+ padding: Sides
34
+ gap: { row: number; column: number }
35
+ radius: number
36
+ borderWidth: number
37
+ fontSizes: number[]
38
+ nested: { path: string; radius: number; padding: Sides }[]
39
+ emptyRatio: number
40
+ /** `min` is null when the anchor holds no text. */
41
+ contrast: {
42
+ min: number | null
43
+ failures: ContrastFailure[]
44
+ /** Set when some text sat on no opaque ancestor background and white was assumed. */
45
+ backdrop?: 'assumed-white'
46
+ }
47
+ }
48
+
49
+ export type AnchorMetrics = Measurement & {
50
+ route: string
51
+ name: string
52
+ scheme: Scheme
53
+ viewport: Viewport
54
+ /** The anchor's contact sheet (`png/…__sheet.png`): every state × scheme × viewport on one image. Absent when it could not be written. */
55
+ sheet?: string
56
+ }
57
+
58
+ export type ShotRecord = {
59
+ route: string
60
+ name: string
61
+ scheme: Scheme
62
+ viewport: Viewport
63
+ state: ShotState
64
+ file: string | null
65
+ status: 'ok' | 'not-declared' | 'skipped' | 'error'
66
+ note?: string
67
+ }
68
+
69
+ /** The theme's resolved steps (px) for one scheme × viewport; a missing custom property is omitted. */
70
+ export type Scale = {
71
+ scheme: Scheme
72
+ viewport: Viewport
73
+ spacing: Record<string, number>
74
+ radius: Record<string, number>
75
+ fontSizes: Record<string, number>
76
+ }
77
+
78
+ export type ShotMetrics = {
79
+ version: 1
80
+ generatedAt: string
81
+ base: string
82
+ routes: string[]
83
+ viewports: Viewport[]
84
+ schemes: Scheme[]
85
+ states: ShotState[]
86
+ scale: Scale[]
87
+ /** Why `scale` is empty or partial; absent when it was read. */
88
+ scaleError?: string
89
+ anchors: AnchorMetrics[]
90
+ shots: ShotRecord[]
91
+ }
package/src/cli/sync.ts CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  readManifest,
28
28
  readSource,
29
29
  reconcileRoots,
30
+ ruleRootsFor,
30
31
  relativePosix,
31
32
  renderContext,
32
33
  reportPrune,
@@ -143,7 +144,7 @@ export function sync(opts: SyncOptions = {}, invocationCwd: string = process.cwd
143
144
 
144
145
  // Before renderContext, which reads `basalt.roots` for the roots-derived template variables.
145
146
  const rootsState = reconcileRoots(cwd, { write: opts.check !== true })
146
- const ctx = renderContext(cwd)
147
+ const ctx = renderContext(cwd, ruleRootsFor(rootsState))
147
148
  const manifest = readManifest(cwd)
148
149
  const placement = resolvePlacement(cwd)
149
150
  const { skip: seedSkip, skipped } = routerSeedPlan(cwd, placement.appRel)
@@ -29,24 +29,12 @@ import {
29
29
  } from '@mantine/core'
30
30
  import type { BasaltProps } from '../../common/props'
31
31
  import { cx } from '../../common/props'
32
+ import { relativeTime } from '../../format'
32
33
  import { VX } from '../../tokens'
33
34
  import { resolveAction } from './define-notifications'
34
35
  import { useNotificationHistory } from './store'
35
36
  import type { NotificationHistoryItem, NotificationIntent } from './store'
36
37
 
37
- // ── Relative time ─────────────────────────────────────────────────────────────
38
-
39
- function relativeTime(createdAt: number): string {
40
- const seconds = Math.floor((Date.now() - createdAt) / 1000)
41
- if (seconds < 60) return 'just now'
42
- const minutes = Math.floor(seconds / 60)
43
- if (minutes < 60) return `${minutes}m ago`
44
- const hours = Math.floor(minutes / 60)
45
- if (hours < 24) return `${hours}h ago`
46
- const days = Math.floor(hours / 24)
47
- return `${days}d ago`
48
- }
49
-
50
38
  // ── Intent → Mantine color (drives the action Button's own `light`-variant tint) ──────────────
51
39
 
52
40
  const INTENT_COLOR: Record<NotificationIntent, string> = {
@@ -136,7 +124,7 @@ function NotificationItem({
136
124
  </Text>
137
125
  <Group gap="xs" align="center" mt={2} wrap="nowrap">
138
126
  <Text ff="monospace" c="var(--vx-faint)" style={{ fontSize: VX.text.micro }}>
139
- {relativeTime(item.createdAt)}
127
+ {relativeTime(item.createdAt, { style: 'short' })}
140
128
  </Text>
141
129
  {resolved !== undefined && (
142
130
  <Button variant="light" color={color} size="compact-xs" onClick={handleAction}>
@@ -0,0 +1,33 @@
1
+ import { useId } from 'react'
2
+
3
+ /**
4
+ * Names a control that has no VISIBLE Mantine `label`, and does it differently per surface — which
5
+ * is the whole reason this is one helper instead of an `aria-label` sprinkled per call site.
6
+ *
7
+ * In the SHEET and the PANEL the visible `PanelRow` heading is right there, so the control points
8
+ * at it (`aria-labelledby`) and the heading stops being decoration. In the PILL surface there is no
9
+ * visible name to point at — the pill text is the VALUE (`EUR`, `30d`, `3 channels`) — so the
10
+ * control carries the filter's own name instead. Either way the announced name is what is being
11
+ * filtered, not what it currently holds.
12
+ *
13
+ * The id is generated by the CONTROL, not by `PanelRow`, because the control renders its own
14
+ * `PanelRow`: an id published downward through context could never reach the sibling that needs it.
15
+ *
16
+ * @example
17
+ * const { labelId, nameProps } = useControlName(label, inSheet || inPanel)
18
+ * <Radio.Group {...nameProps} …/>
19
+ * // and, in the sheet/panel branch: <PanelRow label={label} labelId={labelId}>…</PanelRow>
20
+ */
21
+ export function useControlName(
22
+ label: string,
23
+ named: boolean,
24
+ ): {
25
+ labelId: string
26
+ nameProps: { 'aria-labelledby': string } | { 'aria-label': string }
27
+ } {
28
+ const labelId = useId()
29
+ return {
30
+ labelId,
31
+ nameProps: named ? { 'aria-labelledby': labelId } : { 'aria-label': label },
32
+ }
33
+ }
@@ -32,10 +32,10 @@ import type { BasaltProps } from '../common/props'
32
32
  import type { FieldOption } from '../state/fields'
33
33
  import classes from './controls.module.css'
34
34
  import { POPOVER_ROW_HIT_GAP, useFilterRegistration, useFilterSurface } from './filter-context'
35
+ import type { FilterBase, FilterOption } from './filter-base'
35
36
  import { FilterClearButton, FilterPill } from './filter-pill'
36
- import { useControlName } from './filter-sheet'
37
+ import { useControlName } from './control-name'
37
38
  import { PanelChoice, PanelRow } from './panel-row'
38
- import type { FilterOption } from './select-filter'
39
39
 
40
40
  /**
41
41
  * The slice of a `FieldHandle` this body actually binds to, generic over the VALUE rather than over
@@ -53,34 +53,33 @@ export type ChoiceHandle<T extends string> = {
53
53
  clear(): void
54
54
  }
55
55
 
56
- export type EnumFilterProps<T extends string> = BasaltProps & {
57
- readonly field: ChoiceHandle<T>
58
- readonly label: string
59
- readonly icon?: ReactNode
60
- /** Adds a `Clear` action that clears the field — the same `field.clear()` `Reset all` calls. */
61
- readonly clearable?: boolean
62
- /**
63
- * Overrides `field.options` at render — a runtime catalogue whose labels carry live data, or the
64
- * only row source a `StringField` has. `| undefined` explicitly: an internal component is spread
65
- * into, and `exactOptionalPropertyTypes` rejects a possibly-undefined member on a bare optional.
66
- */
67
- readonly options?: readonly FilterOption[] | undefined
68
- /** Pill text for a value no rendered option matches, ahead of `label` — the name `.labels()` gave
69
- * an unset state that is deliberately not a row (`NumberFilter`'s preset form). */
70
- readonly unmatchedLabel?: string | undefined
71
- /**
72
- * Mono pill label — forwarded to `FilterPill.numeric`. Set by `NumberFilter`, whose values ARE
73
- * numbers (`1` / `2` / `7`), and by nothing else: the same law `[data-numeric]` applies to a
74
- * numeric SegmentedControl label. A word-valued filter never sets it.
75
- */
76
- readonly numeric?: boolean | undefined
77
- }
56
+ export type EnumFilterProps<T extends string> = BasaltProps &
57
+ FilterBase & {
58
+ readonly field: ChoiceHandle<T>
59
+ readonly label: string
60
+ /**
61
+ * Overrides `field.options` at render — a runtime catalogue whose labels carry live data, or the
62
+ * only row source a `StringField` has. `| undefined` explicitly: an internal component is spread
63
+ * into, and `exactOptionalPropertyTypes` rejects a possibly-undefined member on a bare optional.
64
+ */
65
+ readonly options?: readonly FilterOption[] | undefined
66
+ /** Pill text for a value no rendered option matches, ahead of `label` — the name `.labels()` gave
67
+ * an unset state that is deliberately not a row (`NumberFilter`'s preset form). */
68
+ readonly unmatchedLabel?: string | undefined
69
+ /**
70
+ * Mono pill label — forwarded to `FilterPill.numeric`. Set by `NumberFilter`, whose values ARE
71
+ * numbers (`1` / `2` / `7`), and by nothing else: the same law `[data-numeric]` applies to a
72
+ * numeric SegmentedControl label. A word-valued filter never sets it.
73
+ */
74
+ readonly numeric?: boolean | undefined
75
+ }
78
76
 
79
77
  export function EnumFilter<T extends string>({
80
78
  field,
81
79
  label,
82
80
  icon,
83
81
  clearable,
82
+ disabled,
84
83
  numeric,
85
84
  options: optionsProp,
86
85
  unmatchedLabel,
@@ -90,9 +89,10 @@ export function EnumFilter<T extends string>({
90
89
  const [value, setValue] = field.use()
91
90
  const surface = useFilterSurface()
92
91
  const isDefault = field.isDefault(value)
93
- useFilterRegistration(!isDefault, () => {
92
+ const clearFilter = (): void => {
94
93
  field.clear()
95
- })
94
+ }
95
+ useFilterRegistration(!isDefault, clearFilter)
96
96
 
97
97
  // The prop wins whole, never merged: a catalogue that has dropped a value must be able to drop
98
98
  // its row, which a merge with `field.options` would silently put back.
@@ -123,6 +123,7 @@ export function EnumFilter<T extends string>({
123
123
  value={value}
124
124
  options={options}
125
125
  {...(numeric === true && { numeric: true })}
126
+ {...(disabled === true && { disabled: true })}
126
127
  onChange={(next) => {
127
128
  // Rendered from `options` — the cast restores what the codec already guarantees.
128
129
  setValue(next as T)
@@ -161,7 +162,7 @@ export function EnumFilter<T extends string>({
161
162
  />
162
163
  ))}
163
164
  </Stack>
164
- {clearable === true && !isDefault && <FilterClearButton onClear={() => field.clear()} />}
165
+ {clearable === true && !isDefault && <FilterClearButton onClear={clearFilter} />}
165
166
  </Radio.Group>
166
167
  )
167
168
 
@@ -170,6 +171,7 @@ export function EnumFilter<T extends string>({
170
171
  label={selected?.label ?? unmatchedLabel ?? label}
171
172
  active={!isDefault}
172
173
  {...(numeric === true && { numeric: true })}
174
+ {...(disabled === true && { disabled: true })}
173
175
  {...(icon !== undefined && { icon })}
174
176
  {...(className !== undefined && { className })}
175
177
  {...(style !== undefined && { style })}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The prop and option shapes every filter shares (`docs/CONTROLS-SPEC.md` §3). INTERNAL — the
3
+ * filters re-state their own props from these, so a new member lands on the whole family at once.
4
+ */
5
+ import type { ReactNode } from 'react'
6
+
7
+ /**
8
+ * What every filter takes besides its `field`. A filter picks the members that mean something to it
9
+ * (`Omit<FilterBase, 'clearable'>` for a toggle) and tightens `label` to required where no sensible
10
+ * default exists — a store field declares no name of its own, only its VALUES' labels.
11
+ */
12
+ export type FilterBase = {
13
+ /** The popover/sheet heading and the accessible name — never the pill text, which reads the VALUE. */
14
+ readonly label?: string
15
+ /** Leading pill icon. */
16
+ readonly icon?: ReactNode
17
+ /** Adds a `Clear` action that clears the field — the same `field.clear()` `Reset all` calls. */
18
+ readonly clearable?: boolean
19
+ /** Renders the control inert: a pill that will not open, a row that will not edit. */
20
+ readonly disabled?: boolean
21
+ }
22
+
23
+ /**
24
+ * One row of any option list. `disabled` renders the row and refuses the selection — a live
25
+ * catalogue cannot leave an archived value out, because rows already pointing at it still label it.
26
+ */
27
+ export type FilterOption<V extends string | number = string> = {
28
+ readonly value: V
29
+ readonly label: string
30
+ readonly disabled?: boolean
31
+ }
@@ -41,6 +41,8 @@ export type FilterPillProps = BasaltProps & {
41
41
  * where `aria-expanded` (which Mantine's `Popover.Target` supplies) is the correct state.
42
42
  */
43
43
  readonly pressed?: boolean
44
+ /** Inert: the pill cannot be pressed, so its popover never opens. */
45
+ readonly disabled?: boolean
44
46
  /** Set by `FilterSet` on its own fold/sheet pills; a filter never passes either of these. */
45
47
  readonly hideGlyph?: boolean
46
48
  /** `data-shown` — the CSS hook that reveals the `+N` fold pill once folding is needed. */
@@ -56,6 +58,7 @@ export function FilterPill({
56
58
  onClick,
57
59
  ariaLabel,
58
60
  pressed,
61
+ disabled,
59
62
  className,
60
63
  style,
61
64
  hideGlyph,
@@ -79,6 +82,7 @@ export function FilterPill({
79
82
  {...(ariaLabel !== undefined && { 'aria-label': ariaLabel })}
80
83
  {...(pressed !== undefined && children === undefined && { 'aria-pressed': pressed })}
81
84
  {...(shown === true && { 'data-shown': true })}
85
+ {...(disabled === true && { disabled: true })}
82
86
  {...(icon !== undefined && {
83
87
  // `IconSlot` owns the 16px box and the optical centring; `.pillIcon` adds only the pill's
84
88
  // muted-then-ink colour law. A consumer's glyph can no longer set this row's height.
@@ -18,7 +18,6 @@
18
18
  * hand would own a second, unregistered filter home (C1).
19
19
  */
20
20
  import { Button, Drawer } from '@mantine/core'
21
- import { useId } from 'react'
22
21
  import type { ReactNode } from 'react'
23
22
  import type { BasaltProps } from '../common/props'
24
23
  import classes from './controls.module.css'
@@ -78,58 +77,3 @@ export function FilterSheet({
78
77
  </Drawer>
79
78
  )
80
79
  }
81
-
82
- /**
83
- * The selected-row mark — 16px, drawn at the row's trailing edge (`docs/CONTROLS-SPEC.md` §2.1).
84
- * Exported from the MODULE, not from `./index.ts`: the panel surface's facet list draws the same
85
- * mark at the same edge, and two hand-drawn checks would drift.
86
- */
87
- export function CheckGlyph(): ReactNode {
88
- return (
89
- <svg
90
- width={16}
91
- height={16}
92
- viewBox="0 0 24 24"
93
- fill="none"
94
- stroke="currentColor"
95
- strokeWidth={2.25}
96
- strokeLinecap="round"
97
- strokeLinejoin="round"
98
- aria-hidden
99
- >
100
- <path d="M5 12.5l5 5l9 -11" />
101
- </svg>
102
- )
103
- }
104
-
105
- /**
106
- * Names a control that has no VISIBLE Mantine `label`, and does it differently per surface — which
107
- * is the whole reason this is one helper instead of an `aria-label` sprinkled per call site.
108
- *
109
- * In the SHEET and the PANEL the visible `PanelRow` heading is right there, so the control points
110
- * at it (`aria-labelledby`) and the heading stops being decoration. In the PILL surface there is no
111
- * visible name to point at — the pill text is the VALUE (`EUR`, `30d`, `3 channels`) — so the
112
- * control carries the filter's own name instead. Either way the announced name is what is being
113
- * filtered, not what it currently holds.
114
- *
115
- * The id is generated by the CONTROL, not by `PanelRow`, because the control renders its own
116
- * `PanelRow`: an id published downward through context could never reach the sibling that needs it.
117
- *
118
- * @example
119
- * const { labelId, nameProps } = useControlName(label, inSheet || inPanel)
120
- * <Radio.Group {...nameProps} …/>
121
- * // and, in the sheet/panel branch: <PanelRow label={label} labelId={labelId}>…</PanelRow>
122
- */
123
- export function useControlName(
124
- label: string,
125
- named: boolean,
126
- ): {
127
- labelId: string
128
- nameProps: { 'aria-labelledby': string } | { 'aria-label': string }
129
- } {
130
- const labelId = useId()
131
- return {
132
- labelId,
133
- nameProps: named ? { 'aria-labelledby': labelId } : { 'aria-label': label },
134
- }
135
- }
@@ -17,7 +17,17 @@ import type { ReactNode } from 'react'
17
17
  const ICON_SIZE = 16
18
18
  const AFFORDANCE_SIZE = 14
19
19
 
20
- function Stroke({ size = ICON_SIZE, children }: { size?: number; children: ReactNode }): ReactNode {
20
+ function Stroke({
21
+ size = ICON_SIZE,
22
+ strokeWidth = 1.75,
23
+ className,
24
+ children,
25
+ }: {
26
+ size?: number
27
+ strokeWidth?: number
28
+ className?: string | undefined
29
+ children: ReactNode
30
+ }): ReactNode {
21
31
  return (
22
32
  <svg
23
33
  width={size}
@@ -25,7 +35,8 @@ function Stroke({ size = ICON_SIZE, children }: { size?: number; children: React
25
35
  viewBox="0 0 24 24"
26
36
  fill="none"
27
37
  stroke="currentColor"
28
- strokeWidth={1.75}
38
+ strokeWidth={strokeWidth}
39
+ {...(className !== undefined && { className })}
29
40
  strokeLinecap="round"
30
41
  strokeLinejoin="round"
31
42
  aria-hidden
@@ -69,3 +80,35 @@ export function UpDownGlyph(): ReactNode {
69
80
  </Stroke>
70
81
  )
71
82
  }
83
+
84
+ /**
85
+ * The selected-row mark — 16px, drawn at the row's trailing edge (`docs/CONTROLS-SPEC.md` §2.1).
86
+ * Shared by the facet list and any other row that marks a selection at its trailing edge, so two
87
+ * hand-drawn checks cannot drift.
88
+ */
89
+ export function CheckGlyph(): ReactNode {
90
+ return (
91
+ <Stroke strokeWidth={2.25}>
92
+ <path d="M5 12.5l5 5l9 -11" />
93
+ </Stroke>
94
+ )
95
+ }
96
+
97
+ /** `SearchFilter`'s leading icon. */
98
+ export function SearchGlyph(): ReactNode {
99
+ return (
100
+ <Stroke strokeWidth={2}>
101
+ <circle cx="11" cy="11" r="7" />
102
+ <path d="M21 21l-4.35 -4.35" />
103
+ </Stroke>
104
+ )
105
+ }
106
+
107
+ /** `SyncButton`'s icon; the caller owns the spin class, which lives in its own stylesheet. */
108
+ export function RefreshGlyph({ className }: { className?: string | undefined }): ReactNode {
109
+ return (
110
+ <Stroke strokeWidth={2} className={className}>
111
+ <path d="M20 11a8 8 0 1 0-2.34 5.66M20 5v6h-6" />
112
+ </Stroke>
113
+ )
114
+ }
@@ -10,11 +10,12 @@ export { SyncButton } from './sync-button'
10
10
  // `FilterPill`, `FilterSheet` and the `EnumFilter` body are deliberately NOT here: reaching for
11
11
  // them is hand-rolling a filter (`basalt/hand-rolled-filter`).
12
12
  export { FilterSet } from './filter-set'
13
- export { RangeFilter } from './range-filter'
13
+ export { RangeFilter, type RangeCustomPickerProps } from './range-filter'
14
14
  export { SelectFilter } from './select-filter'
15
15
  export { MultiSelectFilter } from './multi-select-filter'
16
16
  export { NumberFilter } from './number-filter'
17
17
  export { SearchFilter } from './search-filter'
18
18
  export { ToggleFilter } from './toggle-filter'
19
19
  export { ViewTabs } from './view-tabs'
20
+ export type { FilterOption } from './filter-base'
20
21
  export { FormRow, FormGroup } from './form-layout'