basalt-ui 2.13.2 → 2.14.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 (143) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/MIGRATING.md +40 -12
  3. package/dist/agent/chat/thread-feed-row.d.ts.map +1 -1
  4. package/dist/agent/chat/thread-feed-row.js +2 -2
  5. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  6. package/dist/agent/chat/thread-message.js +2 -2
  7. package/dist/agent/chat/thread-outcome-card.js +2 -2
  8. package/dist/charts/DualPanel.d.ts.map +1 -1
  9. package/dist/charts/DualPanel.js +1 -0
  10. package/dist/charts/compile.d.ts.map +1 -1
  11. package/dist/charts/compile.js +3 -2
  12. package/dist/charts/cursor.d.ts +10 -6
  13. package/dist/charts/cursor.d.ts.map +1 -1
  14. package/dist/charts/cursor.js +20 -13
  15. package/dist/charts/legend.d.ts +5 -4
  16. package/dist/charts/legend.d.ts.map +1 -1
  17. package/dist/charts/legend.js +3 -3
  18. package/dist/charts/panel.d.ts +2 -0
  19. package/dist/charts/panel.d.ts.map +1 -1
  20. package/dist/charts/panel.js +1 -0
  21. package/dist/commands/notifications/center.d.ts.map +1 -1
  22. package/dist/commands/notifications/center.js +2 -11
  23. package/dist/controls/control-name.d.ts +27 -0
  24. package/dist/controls/control-name.d.ts.map +1 -0
  25. package/dist/controls/control-name.js +11 -0
  26. package/dist/controls/enum-filter.d.ts +3 -6
  27. package/dist/controls/enum-filter.d.ts.map +1 -1
  28. package/dist/controls/enum-filter.js +8 -4
  29. package/dist/controls/filter-base.d.ts +30 -0
  30. package/dist/controls/filter-base.d.ts.map +1 -0
  31. package/dist/controls/filter-base.js +0 -0
  32. package/dist/controls/filter-pill.d.ts +3 -1
  33. package/dist/controls/filter-pill.d.ts.map +1 -1
  34. package/dist/controls/filter-pill.js +2 -0
  35. package/dist/controls/filter-sheet.d.ts +0 -32
  36. package/dist/controls/filter-sheet.d.ts.map +1 -1
  37. package/dist/controls/filter-sheet.js +1 -28
  38. package/dist/controls/glyphs.d.ts +12 -0
  39. package/dist/controls/glyphs.d.ts.map +1 -1
  40. package/dist/controls/glyphs.js +23 -2
  41. package/dist/controls/index.d.ts +2 -1
  42. package/dist/controls/index.d.ts.map +1 -1
  43. package/dist/controls/multi-select-filter.d.ts +8 -3
  44. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  45. package/dist/controls/multi-select-filter.js +27 -10
  46. package/dist/controls/number-filter.d.ts +3 -12
  47. package/dist/controls/number-filter.d.ts.map +1 -1
  48. package/dist/controls/number-filter.js +17 -6
  49. package/dist/controls/panel-row.d.ts +5 -8
  50. package/dist/controls/panel-row.d.ts.map +1 -1
  51. package/dist/controls/panel-row.js +3 -0
  52. package/dist/controls/range-filter.d.ts +14 -14
  53. package/dist/controls/range-filter.d.ts.map +1 -1
  54. package/dist/controls/range-filter.js +18 -41
  55. package/dist/controls/search-filter.d.ts +5 -2
  56. package/dist/controls/search-filter.d.ts.map +1 -1
  57. package/dist/controls/search-filter.js +74 -40
  58. package/dist/controls/select-filter.d.ts +2 -15
  59. package/dist/controls/select-filter.d.ts.map +1 -1
  60. package/dist/controls/sync-button.d.ts +0 -6
  61. package/dist/controls/sync-button.d.ts.map +1 -1
  62. package/dist/controls/sync-button.js +6 -36
  63. package/dist/controls/toggle-filter.d.ts +2 -2
  64. package/dist/controls/toggle-filter.d.ts.map +1 -1
  65. package/dist/controls/toggle-filter.js +3 -2
  66. package/dist/controls/view-tabs.d.ts +3 -4
  67. package/dist/controls/view-tabs.d.ts.map +1 -1
  68. package/dist/controls/view-tabs.js +24 -5
  69. package/dist/format/date.d.ts +43 -10
  70. package/dist/format/date.d.ts.map +1 -1
  71. package/dist/format/date.js +109 -18
  72. package/dist/format/index.d.ts +12 -11
  73. package/dist/format/index.d.ts.map +1 -1
  74. package/dist/format/index.js +11 -2
  75. package/dist/format/measure.d.ts +9 -9
  76. package/dist/format/measure.d.ts.map +1 -1
  77. package/dist/format/measure.js +19 -8
  78. package/dist/format/number.d.ts +35 -27
  79. package/dist/format/number.d.ts.map +1 -1
  80. package/dist/format/number.js +41 -20
  81. package/dist/format/shared.d.ts +38 -7
  82. package/dist/format/shared.d.ts.map +1 -1
  83. package/dist/format/shared.js +61 -13
  84. package/dist/provider/create-router.d.ts +9 -4
  85. package/dist/provider/create-router.d.ts.map +1 -1
  86. package/dist/provider/create-router.js +1 -19
  87. package/dist/provider/error-fallback.module.css +4 -15
  88. package/dist/provider/error-fallback.module.css.d.ts +0 -1
  89. package/dist/provider/fallback.module.css +37 -0
  90. package/dist/provider/fallback.module.css.d.ts +11 -0
  91. package/dist/provider/index.d.ts +13 -1
  92. package/dist/provider/index.d.ts.map +1 -1
  93. package/dist/provider/index.js +10 -1
  94. package/dist/provider/route-defaults.d.ts +10 -0
  95. package/dist/provider/route-defaults.d.ts.map +1 -0
  96. package/dist/provider/route-defaults.js +25 -0
  97. package/dist/provider/route-defaults.module.css +39 -0
  98. package/dist/provider/route-defaults.module.css.d.ts +10 -0
  99. package/llms.txt +35 -14
  100. package/package.json +1 -1
  101. package/src/agent/chat/thread-feed-row.tsx +2 -2
  102. package/src/agent/chat/thread-message.tsx +2 -2
  103. package/src/agent/chat/thread-outcome-card.tsx +2 -2
  104. package/src/charts/DualPanel.tsx +1 -0
  105. package/src/charts/compile.ts +3 -2
  106. package/src/charts/cursor.ts +44 -27
  107. package/src/charts/legend.tsx +9 -6
  108. package/src/charts/panel.tsx +3 -0
  109. package/src/commands/notifications/center.tsx +2 -14
  110. package/src/controls/control-name.ts +33 -0
  111. package/src/controls/enum-filter.tsx +29 -27
  112. package/src/controls/filter-base.ts +31 -0
  113. package/src/controls/filter-pill.tsx +4 -0
  114. package/src/controls/filter-sheet.tsx +0 -56
  115. package/src/controls/glyphs.tsx +45 -2
  116. package/src/controls/index.ts +2 -1
  117. package/src/controls/multi-select-filter.tsx +67 -43
  118. package/src/controls/number-filter.tsx +47 -47
  119. package/src/controls/panel-row.tsx +7 -8
  120. package/src/controls/range-filter.tsx +54 -78
  121. package/src/controls/search-filter.tsx +107 -54
  122. package/src/controls/select-filter.tsx +2 -18
  123. package/src/controls/sync-button.tsx +7 -40
  124. package/src/controls/toggle-filter.tsx +9 -7
  125. package/src/controls/view-tabs.tsx +41 -21
  126. package/src/format/date.ts +189 -36
  127. package/src/format/index.ts +12 -11
  128. package/src/format/measure.ts +29 -18
  129. package/src/format/number.ts +76 -37
  130. package/src/format/shared.ts +116 -25
  131. package/src/provider/create-router.tsx +2 -36
  132. package/src/provider/error-fallback.module.css +4 -15
  133. package/src/provider/error-fallback.module.css.d.ts +0 -1
  134. package/src/provider/fallback.module.css +37 -0
  135. package/src/provider/fallback.module.css.d.ts +11 -0
  136. package/src/provider/index.tsx +25 -1
  137. package/src/provider/route-defaults.module.css +39 -0
  138. package/src/provider/route-defaults.module.css.d.ts +10 -0
  139. package/src/provider/route-defaults.tsx +39 -0
  140. package/dist/agent/chat/relative-time.d.ts +0 -27
  141. package/dist/agent/chat/relative-time.d.ts.map +0 -1
  142. package/dist/agent/chat/relative-time.js +0 -27
  143. package/src/agent/chat/relative-time.ts +0 -55
@@ -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'
@@ -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
  }}