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
@@ -28,11 +28,12 @@ import type { CSSProperties, ReactNode } from 'react'
28
28
  import { assertRequiredProps } from '../common/validate'
29
29
  import type { FieldHandle } from '../state'
30
30
  import type { MultiField } from '../state/fields'
31
- import type { FilterOption } from './select-filter'
31
+ import type { FilterBase, FilterOption } from './filter-base'
32
32
  import classes from './controls.module.css'
33
33
  import { POPOVER_ROW_HIT_GAP, useFilterRegistration, useFilterSurface } from './filter-context'
34
34
  import { FilterClearButton, FilterPill } from './filter-pill'
35
- import { CheckGlyph, useControlName } from './filter-sheet'
35
+ import { useControlName } from './control-name'
36
+ import { CheckGlyph } from './glyphs'
36
37
  import { PanelRow } from './panel-row'
37
38
  import type { UncontrolledProps } from './uncontrolled'
38
39
 
@@ -40,39 +41,45 @@ import type { UncontrolledProps } from './uncontrolled'
40
41
  * which a facet column stops being a list you scan and starts being one you scroll. */
41
42
  const PANEL_FACET_MAX = 6
42
43
 
43
- export type MultiSelectFilterProps<T extends string> = UncontrolledProps & {
44
- readonly field: FieldHandle<MultiField<T>>
45
- readonly label: string
46
- readonly icon?: ReactNode
47
- /**
48
- * The plural noun in the `3 channels` count.
49
- *
50
- * @default the label, lowercased
51
- */
52
- readonly noun?: string
53
- /**
54
- * Overrides `field.options` at render — a runtime catalogue whose labels carry live data
55
- * (`web · 1.2k`). The VALUES still belong to the field: a multi field is a closed set, so this
56
- * relabels and reorders rows, it does not open new ones. Unlike `SelectFilter` there is no
57
- * string-field shape to make it required.
58
- */
59
- readonly options?: readonly FilterOption[]
60
- /**
61
- * Per-option counts, rendered on the `panel` surface as a mono number plus a bar proportional to
62
- * the LARGEST count in the map — the Foundry facet column (`docs/ASIDE-SPEC.md` §1). A missing
63
- * key is a row with no count and no bar, not a zero.
64
- *
65
- * Ignored on the pill and sheet surfaces, where there is no room for a second data channel: put
66
- * the number in the label there (`options`).
67
- */
68
- readonly counts?: Record<string, number>
69
- /**
70
- * How many facet rows the `panel` surface shows before the rest fold behind a `Show N more` row.
71
- *
72
- * @default 6
73
- */
74
- readonly max?: number
75
- }
44
+ export type MultiSelectFilterProps<T extends string> = UncontrolledProps &
45
+ FilterBase & {
46
+ readonly field: FieldHandle<MultiField<T>>
47
+ readonly label: string
48
+ /**
49
+ * Adds a `Clear` action to the popover. Multi has always shown one.
50
+ *
51
+ * @default true
52
+ */
53
+ readonly clearable?: boolean
54
+ /**
55
+ * The plural noun in the `3 channels` count.
56
+ *
57
+ * @default the label, lowercased
58
+ */
59
+ readonly noun?: string
60
+ /**
61
+ * Overrides `field.options` at render — a runtime catalogue whose labels carry live data
62
+ * (`web · 1.2k`). The VALUES still belong to the field: a multi field is a closed set, so this
63
+ * relabels and reorders rows, it does not open new ones. Unlike `SelectFilter` there is no
64
+ * string-field shape to make it required.
65
+ */
66
+ readonly options?: readonly FilterOption[]
67
+ /**
68
+ * Per-option counts, rendered on the `panel` surface as a mono number plus a bar proportional to
69
+ * the LARGEST count in the map — the Foundry facet column (`docs/ASIDE-SPEC.md` §1). A missing
70
+ * key is a row with no count and no bar, not a zero.
71
+ *
72
+ * Ignored on the pill and sheet surfaces, where there is no room for a second data channel: put
73
+ * the number in the label there (`options`).
74
+ */
75
+ readonly counts?: Record<string, number>
76
+ /**
77
+ * How many facet rows the `panel` surface shows before the rest fold behind a `Show N more` row.
78
+ *
79
+ * @default 6
80
+ */
81
+ readonly max?: number
82
+ }
76
83
 
77
84
  export function MultiSelectFilter<T extends string>(props: MultiSelectFilterProps<T>): ReactNode {
78
85
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
@@ -80,13 +87,26 @@ export function MultiSelectFilter<T extends string>(props: MultiSelectFilterProp
80
87
  assertRequiredProps('MultiSelectFilter', props, ['field'], {
81
88
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
82
89
  })
83
- const { field, label, icon, noun, counts, max, options: optionsProp, className, style } = props
90
+ const {
91
+ field,
92
+ label,
93
+ icon,
94
+ noun,
95
+ counts,
96
+ max,
97
+ clearable = true,
98
+ disabled,
99
+ options: optionsProp,
100
+ className,
101
+ style,
102
+ } = props
84
103
  const [value, setValue] = field.use()
85
104
  const surface = useFilterSurface()
86
105
  const isDefault = field.isDefault(value)
87
- useFilterRegistration(!isDefault, () => {
106
+ const clearFilter = (): void => {
88
107
  field.clear()
89
- })
108
+ }
109
+ useFilterRegistration(!isDefault, clearFilter)
90
110
 
91
111
  // The prop wins whole, never merged — same rule as `EnumFilter`: a catalogue that dropped a row
92
112
  // must be able to drop it, and `All channels` is counted against the rows actually shown.
@@ -122,6 +142,7 @@ export function MultiSelectFilter<T extends string>(props: MultiSelectFilterProp
122
142
  options={options}
123
143
  selected={value}
124
144
  max={max ?? PANEL_FACET_MAX}
145
+ {...(disabled === true && { disabled: true })}
125
146
  onToggle={toggle}
126
147
  {...(counts !== undefined && { counts })}
127
148
  />
@@ -150,11 +171,11 @@ export function MultiSelectFilter<T extends string>(props: MultiSelectFilterProp
150
171
  key={option.value}
151
172
  value={option.value}
152
173
  label={option.label}
153
- {...(option.disabled === true && { disabled: true })}
174
+ {...((option.disabled === true || disabled === true) && { disabled: true })}
154
175
  />
155
176
  ))}
156
177
  </Stack>
157
- {!isDefault && <FilterClearButton onClear={() => field.clear()} />}
178
+ {clearable && !isDefault && disabled !== true && <FilterClearButton onClear={clearFilter} />}
158
179
  </Checkbox.Group>
159
180
  )
160
181
 
@@ -162,6 +183,7 @@ export function MultiSelectFilter<T extends string>(props: MultiSelectFilterProp
162
183
  <FilterPill
163
184
  label={carriesInformation ? `${value.length} ${noun ?? label.toLowerCase()}` : label}
164
185
  active={!isDefault}
186
+ {...(disabled === true && { disabled: true })}
165
187
  {...(icon !== undefined && { icon })}
166
188
  {...(className !== undefined && { className })}
167
189
  {...(style !== undefined && { style })}
@@ -179,6 +201,7 @@ type FacetListProps = {
179
201
  /** Rows shown before the rest fold behind `Show N more`. */
180
202
  readonly max: number
181
203
  readonly onToggle: (value: string) => void
204
+ readonly disabled?: boolean
182
205
  }
183
206
 
184
207
  /**
@@ -197,6 +220,7 @@ function FacetList({
197
220
  counts,
198
221
  max,
199
222
  onToggle,
223
+ disabled,
200
224
  }: FacetListProps): ReactNode {
201
225
  const [expanded, setExpanded] = useState(false)
202
226
  const shown = expanded ? options : options.slice(0, max)
@@ -208,7 +232,7 @@ function FacetList({
208
232
  return (
209
233
  // A real `<fieldset>` named by the row's own label — the native element carries the grouping
210
234
  // semantics, and the heading is already visible.
211
- <fieldset className={classes.facetList} aria-labelledby={labelId}>
235
+ <fieldset className={classes.facetList} aria-labelledby={labelId} disabled={disabled}>
212
236
  {shown.map((option) => {
213
237
  const isSelected = selected.includes(option.value)
214
238
  const count = counts?.[option.value]
@@ -217,7 +241,7 @@ function FacetList({
217
241
  key={option.value}
218
242
  className={classes.facetOption}
219
243
  {...(isSelected && { 'data-selected': true })}
220
- {...(option.disabled === true && { 'data-disabled': true })}
244
+ {...((option.disabled === true || disabled === true) && { 'data-disabled': true })}
221
245
  >
222
246
  {/* theme-allow raw-form-control — the input is NEVER PAINTED. Visually hidden
223
247
  (`.facetInput`), it exists only to carry the row's semantics; the surface the reader
@@ -227,7 +251,7 @@ function FacetList({
227
251
  type="checkbox"
228
252
  value={option.value}
229
253
  checked={isSelected}
230
- disabled={option.disabled === true}
254
+ disabled={option.disabled === true || disabled === true}
231
255
  aria-label={option.label}
232
256
  onChange={() => {
233
257
  onToggle(option.value)
@@ -74,38 +74,29 @@ import classes from './controls.module.css'
74
74
  import { EnumFilter } from './enum-filter'
75
75
  import type { ChoiceHandle } from './enum-filter'
76
76
  import { useFilterRegistration, useFilterSurface } from './filter-context'
77
+ import type { FilterBase, FilterOption } from './filter-base'
77
78
  import { FilterClearButton, FilterPill } from './filter-pill'
78
- import { useControlName } from './filter-sheet'
79
+ import { useControlName } from './control-name'
79
80
  import { PanelRow } from './panel-row'
80
81
  import type { UncontrolledProps } from './uncontrolled'
81
82
 
82
- /** One row of a numeric preset set. Narrower than `FilterOption` — a preset is never `disabled`:
83
- * the set is declared at the call site, so a row that should not be offered is left out. */
84
- export type NumberFilterOption = {
85
- readonly value: number
86
- readonly label: string
87
- }
88
-
89
- export type NumberFilterProps = UncontrolledProps & {
90
- readonly field: FieldHandle<NumberField>
91
- /** The popover/sheet heading and the accessible name — never the pill text, which reads the
92
- * VALUE (see `EnumFilter`'s doc for why a pill may only print what is selected). */
93
- readonly label: string
94
- readonly icon?: ReactNode
95
- /** Present → the radio-list form. Absent → the stepper form. */
96
- readonly options?: readonly NumberFilterOption[]
97
- /**
98
- * The stepper's increment, overriding the field's own. Ignored in the `options` form, which has
99
- * no stepper.
100
- *
101
- * @default `field.step` — the field's declared grain, which is `1` for an `int: true` field that
102
- * declared none. Absent on both, the input keeps Mantine's own default of 1.
103
- */
104
- readonly step?: number
105
- /** Adds a `Clear` action that clears the field — the same `field.clear()` `Reset all` calls.
106
- * Parity with `SelectFilter`/`EnumFilter`, in both forms. */
107
- readonly clearable?: boolean
108
- }
83
+ export type NumberFilterProps = UncontrolledProps &
84
+ FilterBase & {
85
+ readonly field: FieldHandle<NumberField>
86
+ /** The popover/sheet heading and the accessible name — never the pill text, which reads the
87
+ * VALUE (see `EnumFilter`'s doc for why a pill may only print what is selected). */
88
+ readonly label: string
89
+ /** Present → the radio-list form. Absent → the stepper form. */
90
+ readonly options?: readonly FilterOption<number>[]
91
+ /**
92
+ * The stepper's increment, overriding the field's own. Ignored in the `options` form, which has
93
+ * no stepper.
94
+ *
95
+ * @default `field.step` — the field's declared grain, which is `1` for an `int: true` field that
96
+ * declared none. Absent on both, the input keeps Mantine's own default of 1.
97
+ */
98
+ readonly step?: number
99
+ }
109
100
 
110
101
  export function NumberFilter(props: NumberFilterProps): ReactNode {
111
102
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
@@ -113,7 +104,7 @@ export function NumberFilter(props: NumberFilterProps): ReactNode {
113
104
  assertRequiredProps('NumberFilter', props, ['field'], {
114
105
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
115
106
  })
116
- const { field, label, icon, options, step, clearable, className, style } = props
107
+ const { field, label, icon, options, step, clearable, disabled, className, style } = props
117
108
  // Two BRANCHES, two components, and never a conditional hook: the radio form's state lives in
118
109
  // `EnumFilter` and the stepper's in `NumberStepper`, so which one mounts is decided once by a prop
119
110
  // that does not change across a mount's life.
@@ -124,6 +115,7 @@ export function NumberFilter(props: NumberFilterProps): ReactNode {
124
115
  label={label}
125
116
  options={options}
126
117
  {...(clearable === true && { clearable: true })}
118
+ {...(disabled === true && { disabled: true })}
127
119
  {...(icon !== undefined && { icon })}
128
120
  {...(className !== undefined && { className })}
129
121
  {...(style !== undefined && { style })}
@@ -138,6 +130,7 @@ export function NumberFilter(props: NumberFilterProps): ReactNode {
138
130
  field={field}
139
131
  label={label}
140
132
  {...(clearable === true && { clearable: true })}
133
+ {...(disabled === true && { disabled: true })}
141
134
  {...(icon !== undefined && { icon })}
142
135
  {...(grain !== undefined && { step: grain })}
143
136
  {...(className !== undefined && { className })}
@@ -166,17 +159,20 @@ function NumberChoice({
166
159
  icon,
167
160
  options,
168
161
  clearable,
162
+ disabled,
169
163
  className,
170
164
  style,
171
- }: BasaltProps & {
172
- readonly field: FieldHandle<NumberField>
173
- readonly label: string
174
- readonly icon?: ReactNode
175
- readonly options: readonly NumberFilterOption[]
176
- readonly clearable?: boolean
177
- }): ReactNode {
165
+ }: BasaltProps &
166
+ FilterBase & {
167
+ readonly field: FieldHandle<NumberField>
168
+ readonly label: string
169
+ readonly options: readonly FilterOption<number>[]
170
+ }): ReactNode {
178
171
  const [value, setValue] = field.use()
179
- const rows = options.map((option) => ({ value: String(option.value), label: option.label }))
172
+ const rows: readonly FilterOption[] = options.map((option) => ({
173
+ ...option,
174
+ value: String(option.value),
175
+ }))
180
176
  // The same `.labels()` naming the stepper pill reads: a value it names (`{ 0: 'Any' }`) prints
181
177
  // that name though it is not a row, so "no filter" needs no literal `Any` option.
182
178
  const named = field.options.find((option) => option.value === String(value))?.label
@@ -207,6 +203,7 @@ function NumberChoice({
207
203
  options={rows}
208
204
  {...(named !== undefined && { unmatchedLabel: named })}
209
205
  {...(clearable === true && { clearable: true })}
206
+ {...(disabled === true && { disabled: true })}
210
207
  {...(icon !== undefined && { icon })}
211
208
  {...(className !== undefined && { className })}
212
209
  {...(style !== undefined && { style })}
@@ -221,22 +218,23 @@ function NumberStepper({
221
218
  icon,
222
219
  step,
223
220
  clearable,
221
+ disabled,
224
222
  className,
225
223
  style,
226
- }: BasaltProps & {
227
- readonly field: FieldHandle<NumberField>
228
- readonly label: string
229
- readonly icon?: ReactNode
230
- readonly step?: number
231
- readonly clearable?: boolean
232
- }): ReactNode {
224
+ }: BasaltProps &
225
+ FilterBase & {
226
+ readonly field: FieldHandle<NumberField>
227
+ readonly label: string
228
+ readonly step?: number
229
+ }): ReactNode {
233
230
  const [value, setValue] = field.use()
234
231
  const surface = useFilterSurface()
235
232
  const inSheet = surface === 'sheet'
236
233
  const isDefault = field.isDefault(value)
237
- useFilterRegistration(!isDefault, () => {
234
+ const clearFilter = (): void => {
238
235
  field.clear()
239
- })
236
+ }
237
+ useFilterRegistration(!isDefault, clearFilter)
240
238
  const inPanel = surface === 'panel'
241
239
  const { labelId, nameProps } = useControlName(label, inSheet || inPanel)
242
240
  const draft = useCommittedNumber(value, setValue, { min: field.min, max: field.max })
@@ -245,6 +243,7 @@ function NumberStepper({
245
243
  <NumberInput
246
244
  {...nameProps}
247
245
  size="ctl"
246
+ {...(disabled === true && { disabled: true })}
248
247
  // The FIELD's bounds, straight off the handle — so the stepper stops at the limit and a typed
249
248
  // value cannot exceed it, instead of being silently corrected one commit later. The codec's
250
249
  // clamp stays the backstop for everything that does not come through this box.
@@ -289,6 +288,7 @@ function NumberStepper({
289
288
  label={field.options.find((option) => option.value === String(value))?.label ?? String(value)}
290
289
  numeric
291
290
  active={!isDefault}
291
+ {...(disabled === true && { disabled: true })}
292
292
  {...(icon !== undefined && { icon })}
293
293
  {...(className !== undefined && { className })}
294
294
  {...(style !== undefined && { style })}
@@ -297,7 +297,7 @@ function NumberStepper({
297
297
  {input}
298
298
  {/* Same placement as `EnumFilter`'s: popover only — the sheet and panel rows reset through
299
299
  the `FilterSet` registration above. The draft follows the clear via its effect. */}
300
- {clearable === true && !isDefault && <FilterClearButton onClear={() => field.clear()} />}
300
+ {clearable === true && !isDefault && <FilterClearButton onClear={clearFilter} />}
301
301
  </div>
302
302
  </FilterPill>
303
303
  )
@@ -29,6 +29,7 @@ import { cx } from '../common/props'
29
29
  import type { BasaltProps } from '../common/props'
30
30
  import { CtlSlot } from '../theme'
31
31
  import { InfoGlyph } from '../dashboard/widget-header'
32
+ import type { FilterOption } from './filter-base'
32
33
  import classes from './panel-row.module.css'
33
34
 
34
35
  /**
@@ -122,18 +123,13 @@ export function PanelRow({
122
123
  )
123
124
  }
124
125
 
125
- /** One option as both surfaces render it — `disabled` is the `SegmentedControl` half. */
126
- export type PanelChoiceOption = {
127
- readonly value: string
128
- readonly label: string
129
- readonly disabled?: boolean
130
- }
131
-
132
126
  export type PanelChoiceProps = {
133
127
  /** The control's accessible name, as `useControlName` resolved it for this surface. */
134
128
  readonly nameProps: { 'aria-labelledby': string } | { 'aria-label': string }
135
129
  readonly value: string
136
- readonly options: readonly PanelChoiceOption[]
130
+ readonly options: readonly FilterOption[]
131
+ /** The whole control is inert. */
132
+ readonly disabled?: boolean
137
133
  /** Numeric labels (`7d` / `30d`) get the mono treatment `segmented-control.module.css` owns. */
138
134
  readonly numeric?: boolean
139
135
  readonly onChange: (next: string) => void
@@ -355,6 +351,7 @@ export function PanelChoice({
355
351
  value,
356
352
  options,
357
353
  numeric,
354
+ disabled,
358
355
  onChange,
359
356
  }: PanelChoiceProps): ReactNode {
360
357
  const data = options.map((option) => ({
@@ -373,6 +370,7 @@ export function PanelChoice({
373
370
  fullWidth
374
371
  value={value}
375
372
  data={data}
373
+ {...(disabled === true && { disabled: true })}
376
374
  {...(numeric === true && { 'data-numeric': true })}
377
375
  onChange={onChange}
378
376
  />
@@ -384,6 +382,7 @@ export function PanelChoice({
384
382
  value={value}
385
383
  allowDeselect={false}
386
384
  data={data}
385
+ {...(disabled === true && { disabled: true })}
387
386
  onChange={(next) => {
388
387
  if (next !== null) onChange(next)
389
388
  }}
@@ -26,6 +26,10 @@
26
26
  * import { DateRangePicker } from 'basalt-ui/controls-dates'
27
27
  * // range: field.range({ presets: ['7d', '30d', '90d', 'ytd'], fallback: '30d', custom: true })
28
28
  * <RangeFilter field={analytics.field.range} customPicker={DateRangePicker} />
29
+ *
30
+ * @example
31
+ * // range: field.range({ presets: ['7d', '30d'], fallback: '30d' }) — no `custom`, no picker
32
+ * <RangeFilter field={analytics.field.range} />
29
33
  */
30
34
  import { SegmentedControl, Select, Stack } from '@mantine/core'
31
35
  import { useEffect, useRef, useState } from 'react'
@@ -35,9 +39,10 @@ import type { FieldHandle } from '../state'
35
39
  import type { RangeField, RangeValue } from '../state/fields'
36
40
  import classes from './controls.module.css'
37
41
  import { useFilterRegistration, useFilterSurface } from './filter-context'
42
+ import type { FilterBase } from './filter-base'
38
43
  import { FilterPill } from './filter-pill'
39
44
  import { CalendarGlyph } from './glyphs'
40
- import { useControlName } from './filter-sheet'
45
+ import { useControlName } from './control-name'
41
46
  import { PanelRow } from './panel-row'
42
47
  import type { UncontrolledProps } from './uncontrolled'
43
48
 
@@ -49,28 +54,6 @@ const CUSTOM_ROW_LABEL = 'Custom range…'
49
54
  /** `7d`, `30d`, `24h`, `90` — a label the mono numeric treatment is for. */
50
55
  const NUMERIC_LABEL = /^\d/
51
56
 
52
- /** Once per label — a filter renders on every navigation, and the wiring is fixed at definition. */
53
- const noPickerWarned = new Set<string>()
54
-
55
- /**
56
- * Dev-only: the field declares `custom: true` and no picker was injected, so the custom window is
57
- * unreachable — the popover shows presets only and the sheet's `Custom range…` row never renders.
58
- * A warning rather than a type error: `custom: true` with presets only is a legal (and tested)
59
- * configuration, and the picker is INJECTED precisely because `@mantine/dates` may be absent, so
60
- * the type cannot tell "deliberately preset-only" from "forgot the import".
61
- */
62
- function warnCustomWithoutPicker(label: string, unreachable: boolean): void {
63
- if (!unreachable || process.env.NODE_ENV === 'production' || noPickerWarned.has(label)) return
64
- noPickerWarned.add(label)
65
- // oxlint-disable-next-line no-console -- a dev-time wiring warning has no other channel
66
- console.warn(
67
- `[basalt-ui] RangeFilter('${label}'): the field declares \`custom: true\` but no ` +
68
- '`customPicker` was injected, so the custom window cannot be reached. Pass ' +
69
- '`customPicker={DateRangePicker}` (`basalt-ui/controls-dates`), or drop `custom: true` from ' +
70
- 'the field. (dev only)',
71
- )
72
- }
73
-
74
57
  /**
75
58
  * The contract a custom-range picker satisfies — `basalt-ui/controls-dates`' `DateRangePicker`, or a
76
59
  * consumer's own. Dates are ISO (`YYYY-MM-DD`), the same shape `field.range` stores and
@@ -82,53 +65,48 @@ export type RangeCustomPickerProps = {
82
65
  }
83
66
 
84
67
  /** Everything about the props that does not depend on the field's `custom` flag. */
85
- type RangeFilterBase<P extends string, C extends boolean> = UncontrolledProps & {
86
- /**
87
- * A range handle from either store factory. Generic over the field's `custom` flag so a
88
- * `field.range({ ... })` WITHOUT `custom` (whose handle is `RangeField<P, false>`, and whose
89
- * values therefore never include `'custom'`) binds with no cast — pinning `C` to its default
90
- * `boolean` here made the setter contravariantly incompatible and forced one at every call site.
91
- */
92
- readonly field: FieldHandle<RangeField<P, C>>
93
- /** Leading pill icon. Defaults to a calendar glyph — a range filter reads as a date control, so
94
- * the glyph is part of the control's identity, not a per-call-site decision. */
95
- readonly icon?: ReactNode
96
- /** Sheet-form heading. The pill's own label is the VALUE, which is what a bar reads. @default 'Range' */
97
- readonly label?: string
98
- }
68
+ type RangeFilterCommon<P extends string, C extends boolean> = UncontrolledProps &
69
+ Omit<FilterBase, 'clearable' | 'label'> & {
70
+ /** Sheet-form heading. The pill's own label is the VALUE, which is what a bar reads. @default 'Range' */
71
+ readonly label?: string
72
+ /**
73
+ * A range handle from either store factory. Generic over the field's `custom` flag so a
74
+ * `field.range({ ... })` WITHOUT `custom` (whose handle is `RangeField<P, false>`, and whose
75
+ * values therefore never include `'custom'`) binds with no cast — pinning `C` to its default
76
+ * `boolean` here made the setter contravariantly incompatible and forced one at every call site.
77
+ */
78
+ readonly field: FieldHandle<RangeField<P, C>>
79
+ }
99
80
 
100
- export type RangeFilterProps<P extends string, C extends boolean = boolean> = RangeFilterBase<
81
+ /**
82
+ * `customPicker` is REQUIRED exactly when the field is `custom: true` and FORBIDDEN otherwise, so
83
+ * the unreachable-affordance state (a custom window nobody can pick) is a type error instead of a
84
+ * dev warning. A widened handle (`C = boolean`) cannot say which, so it must supply the picker.
85
+ */
86
+ export type RangeFilterProps<P extends string, C extends boolean = boolean> = RangeFilterCommon<
101
87
  P,
102
88
  C
103
- > & {
104
- /**
105
- * Rendered when the field declares `custom: true`. Omitted → presets only, which stays LEGAL
106
- * (a range that only ever shows presets is a real configuration) but warns once in dev when the
107
- * field allows a custom window: the affordance is then unreachable, and nothing else says so.
108
- */
109
- readonly customPicker?: ComponentType<RangeCustomPickerProps>
110
- }
89
+ > &
90
+ ([C] extends [false]
91
+ ? { readonly customPicker?: never }
92
+ : { readonly customPicker: ComponentType<RangeCustomPickerProps> })
111
93
 
112
94
  export function RangeFilter<P extends string, C extends boolean = boolean>(
113
95
  props: RangeFilterProps<P, C>,
96
+ ): ReactNode
97
+ // The implementation signature is the widest arm, picker optional; the overload above is the only
98
+ // one a caller sees.
99
+ export function RangeFilter<P extends string>(
100
+ props: Omit<RangeFilterProps<P, boolean>, 'customPicker'> & {
101
+ readonly customPicker?: ComponentType<RangeCustomPickerProps> | undefined
102
+ },
114
103
  ): ReactNode {
115
104
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
116
105
  // (evaluating 'field.use')`, caught by `RootBoundary`.
117
106
  assertRequiredProps('RangeFilter', props, ['field'], {
118
107
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
119
108
  })
120
- const {
121
- field,
122
- icon,
123
- customPicker,
124
- label = 'Range',
125
- className,
126
- style,
127
- // One cast, at the one boundary a generic `C` cannot be read through: `C` only ever describes
128
- // the FIELD's custom flag, and the body handles both.
129
- } = props as unknown as RangeFilterBase<P, boolean> & {
130
- readonly customPicker?: ComponentType<RangeCustomPickerProps>
131
- }
109
+ const { field, icon, disabled, customPicker: Picker, label = 'Range', className, style } = props
132
110
  const [value, setValue] = field.use()
133
111
  const surface = useFilterSurface()
134
112
  const isDefault = field.isDefault(value)
@@ -142,8 +120,6 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
142
120
  const numeric = presets.length > 0 && presets.every((option) => NUMERIC_LABEL.test(option.label))
143
121
  const inSheet = surface === 'sheet'
144
122
  const inPanel = surface === 'panel'
145
- const Picker = customPicker
146
- warnCustomWithoutPicker(label, allowsCustom && Picker === undefined)
147
123
  // The track is a `radiogroup`; without this it announces unnamed, and the pill it hangs off reads
148
124
  // the VALUE (`30d`), not the filter.
149
125
  const { labelId, nameProps } = useControlName(label, inSheet || inPanel)
@@ -163,7 +139,18 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
163
139
  seenPreset.current = value.preset
164
140
  setCustomOpen(value.preset === 'custom')
165
141
  }, [value.preset])
166
- const showPicker = allowsCustom && Picker !== undefined
142
+ const picker =
143
+ allowsCustom && Picker !== undefined ? (
144
+ <Picker
145
+ value={{ from: value.from, to: value.to }}
146
+ onChange={({ from, to }) => {
147
+ // The injected picker cannot be disabled through its props, so a disabled filter drops
148
+ // what it reports instead.
149
+ if (disabled === true) return
150
+ setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
151
+ }}
152
+ />
153
+ ) : null
167
154
 
168
155
  // The sheet form is the panel form (`docs/CONTROLS-SPEC.md` §3: "sheet = panel rows inside a
169
156
  // Drawer") — one `Select` holding the presets plus a `Custom range…` row, which reveals the same
@@ -181,13 +168,14 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
181
168
  <Select
182
169
  {...nameProps}
183
170
  allowDeselect={false}
171
+ {...(disabled === true && { disabled: true })}
184
172
  // `customOpen` is what the row reads while the picker is open but no window has been
185
173
  // picked yet — selecting `Custom range…` reveals the calendar, it does not write a
186
174
  // half-built `{ preset: 'custom' }` the codec would have to guess at.
187
175
  value={customOpen ? 'custom' : value.preset}
188
176
  data={[
189
177
  ...presets.map((option) => ({ value: option.value, label: option.label })),
190
- ...(showPicker ? [{ value: 'custom', label: CUSTOM_ROW_LABEL }] : []),
178
+ ...(picker !== null ? [{ value: 'custom', label: CUSTOM_ROW_LABEL }] : []),
191
179
  ]}
192
180
  onChange={(next) => {
193
181
  if (next === null) return
@@ -201,14 +189,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
201
189
  setValue({ preset: next } as RangeValue<P | 'custom'>)
202
190
  }}
203
191
  />
204
- {showPicker && customOpen && (
205
- <Picker
206
- value={{ from: value.from, to: value.to }}
207
- onChange={({ from, to }) => {
208
- setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
209
- }}
210
- />
211
- )}
192
+ {customOpen && picker}
212
193
  </PanelRow>
213
194
  )
214
195
  }
@@ -218,6 +199,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
218
199
  <SegmentedControl
219
200
  {...nameProps}
220
201
  size="ctl"
202
+ {...(disabled === true && { disabled: true })}
221
203
  orientation={presets.length >= VERTICAL_FROM ? 'vertical' : 'horizontal'}
222
204
  value={value.preset}
223
205
  data={presets.map((option) => ({ value: option.value, label: option.label }))}
@@ -228,14 +210,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
228
210
  setValue({ preset: next } as RangeValue<P | 'custom'>)
229
211
  }}
230
212
  />
231
- {showPicker && (
232
- <Picker
233
- value={{ from: value.from, to: value.to }}
234
- onChange={({ from, to }) => {
235
- setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
236
- }}
237
- />
238
- )}
213
+ {picker}
239
214
  </Stack>
240
215
  )
241
216
 
@@ -244,6 +219,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
244
219
  label={rangeLabel(value, options)}
245
220
  active={!isDefault}
246
221
  numeric={numeric && value.preset !== 'custom'}
222
+ {...(disabled === true && { disabled: true })}
247
223
  icon={icon ?? <CalendarGlyph />}
248
224
  {...(className !== undefined && { className })}
249
225
  {...(style !== undefined && { style })}