basalt-ui 2.8.1 → 2.9.1
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.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +33 -0
- package/MIGRATING.md +81 -27
- package/README.md +7 -8
- package/agent/rules/basalt-controls.md +1 -1
- package/agent/rules/basalt-state.md +1 -1
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/templates/AGENTS-block.md.tpl +2 -2
- package/configs/oxlint-plugin.js +25 -68
- package/configs/oxlint-plugin.test.ts +19 -27
- package/configs/oxlint.json +4 -0
- package/dist/charts/BandStrip.d.ts +1 -1
- package/dist/charts/BandStrip.d.ts.map +1 -1
- package/dist/charts/BandStrip.js +1 -10
- package/dist/charts/MirroredBars.d.ts.map +1 -1
- package/dist/charts/MirroredBars.js +2 -9
- package/dist/charts/band-fold.d.ts +15 -0
- package/dist/charts/band-fold.d.ts.map +1 -0
- package/dist/charts/band-fold.js +19 -0
- package/dist/charts/index.d.ts +1 -0
- package/dist/charts/index.d.ts.map +1 -1
- package/dist/charts/index.js +3 -1
- package/dist/cli/audit-allows.d.ts.map +1 -1
- package/dist/cli/audit-allows.js +1 -1
- package/dist/cli/check-theme.d.ts.map +1 -1
- package/dist/cli/check-theme.js +4 -1
- package/dist/cli/config.d.ts +14 -4
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +7 -2
- package/dist/cli/doctor-upgrade.d.ts +9 -0
- package/dist/cli/doctor-upgrade.d.ts.map +1 -1
- package/dist/cli/doctor-upgrade.js +14 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +10 -12
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -3
- package/dist/cli/index.d.ts +3 -2
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +4 -2
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +6 -0
- package/dist/cli/install-root.d.ts +10 -0
- package/dist/cli/install-root.d.ts.map +1 -0
- package/dist/cli/install-root.js +32 -0
- package/dist/cli/router-wiring.d.ts +4 -2
- package/dist/cli/router-wiring.d.ts.map +1 -1
- package/dist/cli/router-wiring.js +2 -0
- package/dist/cli/sync.d.ts +0 -2
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +19 -15
- package/dist/cli/tokens-css.d.ts.map +1 -1
- package/dist/cli/tokens-css.js +1 -6
- package/dist/common/errors.d.ts +1 -6
- package/dist/common/errors.d.ts.map +1 -1
- package/dist/common/errors.js +0 -7
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +1 -9
- package/dist/common/props.d.ts +2 -2
- package/dist/common/vx-family.d.ts +1 -1
- package/dist/content/toc-click-pin.d.ts +45 -0
- package/dist/content/toc-click-pin.d.ts.map +1 -0
- package/dist/content/toc-click-pin.js +111 -0
- package/dist/content/toc-spy.d.ts +25 -0
- package/dist/content/toc-spy.d.ts.map +1 -0
- package/dist/content/toc-spy.js +43 -0
- package/dist/content/toc.d.ts +1 -4
- package/dist/content/toc.d.ts.map +1 -1
- package/dist/content/toc.js +38 -49
- package/dist/controls/number-filter.d.ts.map +1 -1
- package/dist/controls/number-filter.js +1 -1
- package/dist/dashboard/index.d.ts +1 -1
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +1 -3
- package/dist/dashboard/section.d.ts +10 -2
- package/dist/dashboard/section.d.ts.map +1 -1
- package/dist/dashboard/section.js +20 -3
- package/dist/dashboard/stat-card.d.ts +2 -8
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +1 -1
- package/dist/guard/index.d.ts +13 -9
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +74 -37
- package/dist/guard/types.d.ts +8 -7
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/guard/vx-names.d.ts +1 -1
- package/dist/guard/vx-names.d.ts.map +1 -1
- package/dist/guard/vx-names.js +1 -33
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.d.ts +1 -11
- package/dist/router-tanstack/search-store.d.ts.map +1 -1
- package/dist/router-tanstack/search-store.js +1 -2
- package/dist/shell/index.d.ts +1 -0
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +3 -0
- package/dist/shell/nav-types.d.ts +1 -1
- package/dist/shell/page-bar.d.ts +6 -0
- package/dist/shell/page-bar.d.ts.map +1 -1
- package/dist/shell/page-bar.js +12 -2
- package/dist/state/fields.d.ts +1 -1
- package/dist/state/fields.d.ts.map +1 -1
- package/dist/state/fields.js +3 -1
- package/dist/surfaces.d.ts +1 -1
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +5 -11
- package/dist/table/data-table.d.ts +2 -2
- package/dist/tokens/core.d.ts +0 -10
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +6 -44
- package/llms.txt +24 -8
- package/package.json +8 -5
- package/src/charts/BandStrip.tsx +4 -16
- package/src/charts/MirroredBars.tsx +2 -11
- package/src/charts/band-fold.ts +26 -0
- package/src/charts/index.ts +1 -0
- package/src/cli/audit-allows.ts +1 -3
- package/src/cli/check-theme.ts +7 -1
- package/src/cli/config.ts +21 -5
- package/src/cli/doctor-upgrade.ts +23 -1
- package/src/cli/doctor.ts +10 -17
- package/src/cli/help.ts +1 -4
- package/src/cli/index.ts +9 -6
- package/src/cli/init.ts +7 -0
- package/src/cli/install-root.ts +40 -0
- package/src/cli/router-wiring.ts +6 -2
- package/src/cli/sync.ts +28 -17
- package/src/cli/tokens-css.ts +0 -5
- package/src/common/errors.ts +1 -18
- package/src/common/index.ts +1 -8
- package/src/common/props.ts +2 -2
- package/src/common/vx-family.ts +1 -1
- package/src/content/toc-click-pin.ts +156 -0
- package/src/content/toc-spy.ts +61 -0
- package/src/content/toc.tsx +47 -95
- package/src/controls/form-layout.tsx +1 -1
- package/src/controls/number-filter.tsx +6 -1
- package/src/dashboard/index.ts +1 -6
- package/src/dashboard/section.tsx +39 -8
- package/src/dashboard/stat-card.tsx +4 -11
- package/src/guard/index.ts +114 -89
- package/src/guard/types.ts +8 -7
- package/src/guard/vx-names.ts +1 -33
- package/src/index.ts +1 -2
- package/src/router-tanstack/search-store.ts +2 -14
- package/src/shell/index.tsx +2 -0
- package/src/shell/nav-types.ts +1 -1
- package/src/shell/page-bar.tsx +21 -2
- package/src/state/fields.ts +7 -2
- package/src/surfaces.ts +5 -11
- package/src/table/data-table.tsx +2 -2
- package/src/tokens/core.ts +6 -67
- package/dist/tokens.css +0 -331
package/src/content/toc.tsx
CHANGED
|
@@ -17,10 +17,7 @@
|
|
|
17
17
|
* a viewport-rooted observer measures the wrong band. `null` means the document scrolls, which is
|
|
18
18
|
* the shell-less case and behaves exactly as before.
|
|
19
19
|
*
|
|
20
|
-
* The active
|
|
21
|
-
* link set that navigates within one page, rather than `"page"`/`"true"`) — both a genuine a11y fix
|
|
22
|
-
* (previously `activeId` drove `classes.active` alone, so a screen reader had no signal at all) and
|
|
23
|
-
* the one DOM-observable hook for `activeId` that does not depend on a CSS Modules class hash.
|
|
20
|
+
* The active item carries `aria-current="location"` (WAI-ARIA APG: a link set within one page).
|
|
24
21
|
*
|
|
25
22
|
* @example
|
|
26
23
|
* import { TableOfContents, headingSlug } from 'basalt-ui/content'
|
|
@@ -32,10 +29,12 @@
|
|
|
32
29
|
* <TableOfContents containerRef={articleRef} />
|
|
33
30
|
*/
|
|
34
31
|
import type { MouseEvent, RefObject } from 'react'
|
|
35
|
-
import { useEffect, useRef, useState } from 'react'
|
|
32
|
+
import { useCallback, useEffect, useReducer, useRef, useState } from 'react'
|
|
36
33
|
import { useReducedMotion } from '@mantine/hooks'
|
|
37
34
|
import { scrollParentOf } from '../common/scroll-parent'
|
|
38
35
|
import classes from './toc.module.css'
|
|
36
|
+
import { useClickPin } from './toc-click-pin'
|
|
37
|
+
import { OBSERVER_ROOT_MARGIN, pickActive, scrollMetrics } from './toc-spy'
|
|
39
38
|
|
|
40
39
|
export type TocItem = {
|
|
41
40
|
readonly id: string
|
|
@@ -59,12 +58,6 @@ export type TableOfContentsProps = {
|
|
|
59
58
|
const DEFAULT_LEVELS: readonly [number, number] = [2, 3]
|
|
60
59
|
const DEFAULT_TITLE = 'On this page'
|
|
61
60
|
|
|
62
|
-
/**
|
|
63
|
-
* Ceiling on how long a clicked item holds the rail: released on `scrollend` where supported, so
|
|
64
|
-
* this only covers browsers without it — and a smooth scroll that never settles.
|
|
65
|
-
*/
|
|
66
|
-
const CLICK_PIN_MAX_MS = 1000
|
|
67
|
-
|
|
68
61
|
/** Heading text without the hover-anchor `#` glyph the markdown/MDX heading renderers append. */
|
|
69
62
|
function headingLabel(node: HTMLElement): string {
|
|
70
63
|
const clone = node.cloneNode(true) as HTMLElement
|
|
@@ -93,18 +86,19 @@ export function TableOfContents({
|
|
|
93
86
|
const [collected, setCollected] = useState<TocItem[]>([])
|
|
94
87
|
const [activeId, setActiveId] = useState<string | null>(null)
|
|
95
88
|
const reduceMotion = useReducedMotion()
|
|
96
|
-
// Set while a clicked item owns the rail; `resolve` stands down until it's released.
|
|
97
|
-
const pinnedRef = useRef<string | null>(null)
|
|
98
|
-
const releasePinRef = useRef<(() => void) | null>(null)
|
|
99
89
|
// The rail's own node — the probe `scrollParentOf` walks from when there is no `containerRef`.
|
|
100
90
|
const navRef = useRef<HTMLElement | null>(null)
|
|
101
|
-
// The resolved
|
|
102
|
-
|
|
91
|
+
// The spy's working set, resolved once per effect run: headings, scroller, and the band's members.
|
|
92
|
+
const elementsRef = useRef<HTMLElement[]>([])
|
|
103
93
|
const portRef = useRef<HTMLElement | null>(null)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
const intersectingRef = useRef<Set<string>>(new Set())
|
|
95
|
+
// Bumped when a click hands the rail back, so the rail re-resolves.
|
|
96
|
+
const [idleTick, bumpIdle] = useReducer((n: number) => n + 1, 0)
|
|
97
|
+
const pin = useClickPin(bumpIdle)
|
|
98
|
+
const scrollerOf = useCallback(
|
|
99
|
+
() => scrollParentOf(containerRef?.current ?? navRef.current),
|
|
100
|
+
[containerRef],
|
|
101
|
+
)
|
|
108
102
|
|
|
109
103
|
// Auto-collection: re-scan on mount + on any childList mutation under the container.
|
|
110
104
|
useEffect(() => {
|
|
@@ -122,51 +116,35 @@ export function TableOfContents({
|
|
|
122
116
|
|
|
123
117
|
const resolvedItems = items ?? collected
|
|
124
118
|
|
|
119
|
+
// The spy's answer for the reader's current position — or the clicked entry, while the click owns it.
|
|
120
|
+
const resolve = useCallback(() => {
|
|
121
|
+
if (pin.activeId !== null) {
|
|
122
|
+
setActiveId(pin.activeId)
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
const id = pickActive(
|
|
126
|
+
elementsRef.current,
|
|
127
|
+
intersectingRef.current,
|
|
128
|
+
scrollMetrics(portRef.current),
|
|
129
|
+
)
|
|
130
|
+
if (id !== undefined) setActiveId(id)
|
|
131
|
+
}, [pin])
|
|
132
|
+
|
|
125
133
|
// Scroll-spy: one IntersectionObserver over every collected heading.
|
|
126
134
|
useEffect(() => {
|
|
135
|
+
pin.prune(resolvedItems.map((item) => item.id))
|
|
127
136
|
if (resolvedItems.length === 0) return
|
|
128
137
|
const elements = resolvedItems
|
|
129
138
|
.map((item) => document.getElementById(item.id))
|
|
130
139
|
.filter((el): el is HTMLElement => el !== null)
|
|
131
140
|
if (elements.length === 0) return
|
|
132
141
|
|
|
133
|
-
const port =
|
|
134
|
-
portRef.current = port
|
|
142
|
+
const port = scrollerOf()
|
|
135
143
|
const scroller: Window | HTMLElement = port ?? window
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// A clicked item is the reader SAYING where they are; everything below only infers it. Stand
|
|
141
|
-
// down until the scroll they asked for has settled.
|
|
142
|
-
if (pinnedRef.current !== null) return
|
|
143
|
-
|
|
144
|
-
// Bottom edge: the last sections are usually shorter than the observer's 70% dead zone, so
|
|
145
|
-
// their headings can NEVER reach the activation band — the rail would stall on whichever
|
|
146
|
-
// section last made it in. Once the page bottoms out, the final item is the honest answer.
|
|
147
|
-
const box = port ?? document.documentElement
|
|
148
|
-
const seen = port ? port.clientHeight + port.scrollTop : window.innerHeight + window.scrollY
|
|
149
|
-
if (seen >= box.scrollHeight - 2) {
|
|
150
|
-
const last = elements[elements.length - 1]
|
|
151
|
-
if (last) setActiveId(last.id)
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (intersecting.size > 0) {
|
|
156
|
-
const topmost = elements.find((el) => intersecting.has(el.id))
|
|
157
|
-
if (topmost) setActiveId(topmost.id)
|
|
158
|
-
return
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Nothing intersecting — the last heading already scrolled past, or (above the first one,
|
|
162
|
-
// i.e. at the very top of the article) the first heading, so the rail always marks where the
|
|
163
|
-
// reader actually is instead of showing nothing until the first heading reaches the band.
|
|
164
|
-
// "Past" is measured against the SCROLLER's top edge, which for the window case is 0.
|
|
165
|
-
const originTop = port ? port.getBoundingClientRect().top : 0
|
|
166
|
-
const passed = elements.filter((el) => el.getBoundingClientRect().top < originTop)
|
|
167
|
-
const current = passed[passed.length - 1] ?? elements[0]
|
|
168
|
-
if (current) setActiveId(current.id)
|
|
169
|
-
}
|
|
144
|
+
const intersecting = intersectingRef.current
|
|
145
|
+
intersecting.clear()
|
|
146
|
+
elementsRef.current = elements
|
|
147
|
+
portRef.current = port
|
|
170
148
|
|
|
171
149
|
const observer = new IntersectionObserver(
|
|
172
150
|
(entries) => {
|
|
@@ -178,54 +156,34 @@ export function TableOfContents({
|
|
|
178
156
|
},
|
|
179
157
|
// `root: null` IS the viewport — the shell-less case, unchanged. Inside a shell the root has
|
|
180
158
|
// to be the scrollport or the `-70%` dead zone is measured against a box nothing scrolls.
|
|
181
|
-
{ root: port, rootMargin:
|
|
159
|
+
{ root: port, rootMargin: OBSERVER_ROOT_MARGIN },
|
|
182
160
|
)
|
|
183
161
|
|
|
184
162
|
for (const el of elements) observer.observe(el)
|
|
185
|
-
// The observer only fires when an intersection CHANGES; the bottom edge
|
|
186
|
-
//
|
|
187
|
-
// for React, so this stays free on every frame that doesn't move the rail.
|
|
163
|
+
// The observer only fires when an intersection CHANGES; the bottom edge resolves on scroll
|
|
164
|
+
// position alone, so it needs a scroll signal too. Re-setting the same id is a no-op for React.
|
|
188
165
|
scroller.addEventListener('scroll', resolve, { passive: true })
|
|
189
166
|
return () => {
|
|
190
167
|
observer.disconnect()
|
|
191
168
|
scroller.removeEventListener('scroll', resolve)
|
|
192
|
-
|
|
169
|
+
elementsRef.current = []
|
|
193
170
|
}
|
|
194
|
-
}, [resolvedItems,
|
|
171
|
+
}, [resolvedItems, scrollerOf, pin, resolve])
|
|
195
172
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
* the heading can reach the activation band, so the bottom pin would answer with the LAST item
|
|
202
|
-
* instead of the one that was asked for.
|
|
203
|
-
*/
|
|
204
|
-
const pinActive = (id: string) => {
|
|
205
|
-
releasePinRef.current?.()
|
|
206
|
-
setActiveId(id)
|
|
207
|
-
pinnedRef.current = id
|
|
173
|
+
// A click handed the rail back: answer for where the reader is, next frame.
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
const frame = requestAnimationFrame(resolve)
|
|
176
|
+
return () => cancelAnimationFrame(frame)
|
|
177
|
+
}, [idleTick, resolve])
|
|
208
178
|
|
|
209
|
-
|
|
210
|
-
// inside `AppShell.Main`, which would leave the rail pinned for the full `CLICK_PIN_MAX_MS`.
|
|
211
|
-
const scroller: Window | HTMLElement = portRef.current ?? window
|
|
212
|
-
let timer: ReturnType<typeof setTimeout> | null = null
|
|
213
|
-
const release = () => {
|
|
214
|
-
pinnedRef.current = null
|
|
215
|
-
if (timer !== null) clearTimeout(timer)
|
|
216
|
-
scroller.removeEventListener('scrollend', release)
|
|
217
|
-
releasePinRef.current = null
|
|
218
|
-
}
|
|
219
|
-
timer = setTimeout(release, CLICK_PIN_MAX_MS)
|
|
220
|
-
scroller.addEventListener('scrollend', release, { once: true })
|
|
221
|
-
releasePinRef.current = release
|
|
222
|
-
}
|
|
179
|
+
if (resolvedItems.length === 0) return null
|
|
223
180
|
|
|
224
181
|
const handleClick = (id: string) => (event: MouseEvent<HTMLAnchorElement>) => {
|
|
225
182
|
event.preventDefault()
|
|
226
183
|
const el = document.getElementById(id)
|
|
227
184
|
if (el) {
|
|
228
|
-
|
|
185
|
+
setActiveId(id)
|
|
186
|
+
pin.click(id, event.currentTarget, scrollerOf())
|
|
229
187
|
el.scrollIntoView({ behavior: reduceMotion ? 'auto' : 'smooth' })
|
|
230
188
|
history.replaceState(null, '', `#${id}`)
|
|
231
189
|
}
|
|
@@ -249,12 +207,6 @@ export function TableOfContents({
|
|
|
249
207
|
]
|
|
250
208
|
.filter(Boolean)
|
|
251
209
|
.join(' ')}
|
|
252
|
-
// `classes.active` alone used to be the ONLY signal of which item the spy picked —
|
|
253
|
-
// both a real a11y gap (nothing here told assistive tech which section is current)
|
|
254
|
-
// and, incidentally, the reason a consumer/test could not observe `activeId` without
|
|
255
|
-
// reading CSS. `location` (not `page`/`true`) is the value WAI-ARIA's Authoring
|
|
256
|
-
// Practices call out BY NAME for exactly this widget: a set of links navigating
|
|
257
|
-
// within a single page, as opposed to a set of links to different pages.
|
|
258
210
|
aria-current={activeId === item.id ? 'location' : undefined}
|
|
259
211
|
onClick={handleClick(item.id)}
|
|
260
212
|
>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* ./controls — the form layout primitives: `FormSection`, `FormRow`, `FormGroup`, `FormActions`.
|
|
3
3
|
* Mantine-coupled. They need no `@mantine/form` (layout only), which is why they live here and not
|
|
4
4
|
* in `./forms`, whose barrel value-imports it: importing a row from there made a consumer install a
|
|
5
|
-
* peer it never used.
|
|
5
|
+
* peer it never used.
|
|
6
6
|
*
|
|
7
7
|
* The gap they close (audit B #5 / §4): `./forms` shipped no layout at all, so the only row
|
|
8
8
|
* primitive in the package was `SettingsRow` over in `./dashboard` — which is the SETTINGS-page
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
* <NumberFilter field={lines.field.minDuration} label="Min duration" step={30} />
|
|
54
54
|
*
|
|
55
55
|
* @example
|
|
56
|
+
* // Naming the unset state: labels are keyed by value, at definition, like every option label.
|
|
57
|
+
* // store = createSearchStore({ … }).labels({ minDuration: { 0: 'Any' } }) → the pill reads "Any"
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
56
60
|
* // "No filter" is the fallback, not a row: `clearable` writes it back, and the pill reads the
|
|
57
61
|
* // filter's name while no preset is picked.
|
|
58
62
|
* // difficulty: field.number({ fallback: 0, min: 0, max: 5, int: true })
|
|
@@ -276,7 +280,8 @@ function NumberStepper({
|
|
|
276
280
|
|
|
277
281
|
return (
|
|
278
282
|
<FilterPill
|
|
279
|
-
|
|
283
|
+
// A value `.labels()` names (`{ 0: 'Any' }`) reads as that name — the unset state's wording.
|
|
284
|
+
label={field.options.find((option) => option.value === String(value))?.label ?? String(value)}
|
|
280
285
|
numeric
|
|
281
286
|
active={!isDefault}
|
|
282
287
|
{...(icon !== undefined && { icon })}
|
package/src/dashboard/index.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
export { WidgetHeader } from './widget-header'
|
|
2
2
|
export { DeltaBadge } from './delta-badge'
|
|
3
3
|
export { Section } from './section'
|
|
4
|
-
export {
|
|
5
|
-
StatCard,
|
|
6
|
-
type StatCardBreakdownRow,
|
|
7
|
-
type StatCardSparklineSize,
|
|
8
|
-
type StatCardTone,
|
|
9
|
-
} from './stat-card'
|
|
4
|
+
export { StatCard, type StatCardBreakdownRow, type StatCardSparklineSize } from './stat-card'
|
|
10
5
|
export { StatGroup } from './stat-group'
|
|
11
6
|
export { EmptyState } from './empty-state'
|
|
12
7
|
export { SettingsSection, SettingsRow, DangerZone } from './settings-section'
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
* separate slot rather than the first child: a section a reader folded away should still state its
|
|
23
23
|
* headline figures, or folding it costs them the numbers they were watching.
|
|
24
24
|
*
|
|
25
|
-
* `id` turns the root into a scroll anchor
|
|
26
|
-
*
|
|
27
|
-
* hidden under
|
|
25
|
+
* `id` turns the root into a scroll anchor. Inside `BasaltShell` both bars sit outside the
|
|
26
|
+
* scrollport, so the offset is the clearance token alone; without a shell it adds `PageBar`'s
|
|
27
|
+
* measured height (`--basalt-page-bar-h`) so the heading isn't hidden under the sticky bar.
|
|
28
28
|
*
|
|
29
29
|
* @example
|
|
30
30
|
* import { Section, StatCard } from 'basalt-ui'
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* <UsageChart />
|
|
46
46
|
* </Section>
|
|
47
47
|
*/
|
|
48
|
-
import { useId } from 'react'
|
|
48
|
+
import { useEffect, useId } from 'react'
|
|
49
49
|
import type { ReactNode } from 'react'
|
|
50
50
|
import { cx } from '../common/props'
|
|
51
51
|
import type { BasaltProps, SlotStylesProps } from '../common/props'
|
|
@@ -58,6 +58,7 @@ import { useFilterSurface } from '../controls/filter-context'
|
|
|
58
58
|
import { QueryState } from './query-state'
|
|
59
59
|
import type { QueryEmptyCopy, QueryStateLike } from './query-state'
|
|
60
60
|
import { usePersistedOrLocal } from '../state/persisted-or-local'
|
|
61
|
+
import { PAGE_BAR_HEIGHT_VAR, useInPageBarShell } from '../shell'
|
|
61
62
|
import { WidgetHeader } from './widget-header'
|
|
62
63
|
import type { WidgetHeaderProps } from './widget-header'
|
|
63
64
|
import classes from './section.module.css'
|
|
@@ -107,6 +108,12 @@ export type SectionProps = Omit<WidgetHeaderProps, 'tier' | 'classNames' | 'acti
|
|
|
107
108
|
/** Persists the fold state at `basalt:section:<persistKey>`. Omit for a local, unpersisted fold
|
|
108
109
|
* (`useState`). */
|
|
109
110
|
persistKey?: string
|
|
111
|
+
/** Controlled fold state (Mantine naming). Given one, the section follows it — a click only
|
|
112
|
+
* calls `onOpenChange`, and the value is mirrored into the local/persisted fold so dropping
|
|
113
|
+
* `open` keeps what the reader last saw. Omit for the uncontrolled, optionally persisted fold. */
|
|
114
|
+
open?: boolean
|
|
115
|
+
/** Called with the next fold state on every toggle, controlled or not. */
|
|
116
|
+
onOpenChange?: (open: boolean) => void
|
|
110
117
|
/** The fold state a section opens on, respected only while no persisted value exists — a section
|
|
111
118
|
* a reader has closed stays closed. `false` is what a long secondary block wants. @default true */
|
|
112
119
|
defaultOpen?: boolean
|
|
@@ -114,7 +121,9 @@ export type SectionProps = Omit<WidgetHeaderProps, 'tier' | 'classNames' | 'acti
|
|
|
114
121
|
* still states its headline figures, which is what makes collapsing it a real option. Keep it to
|
|
115
122
|
* one row — the body is what `children` is for. */
|
|
116
123
|
summary?: ReactNode
|
|
117
|
-
/** Turns the root into a scroll anchor (`id` + `scroll-margin-top`
|
|
124
|
+
/** Turns the root into a scroll anchor (`id` + `scroll-margin-top`). Inside `BasaltShell` the
|
|
125
|
+
* offset is the clearance token; without a shell it also clears `PageBar`, which assumes the
|
|
126
|
+
* document is the scrollport. */
|
|
118
127
|
id?: string
|
|
119
128
|
children: ReactNode
|
|
120
129
|
}
|
|
@@ -154,6 +163,14 @@ function ChevronToggle({
|
|
|
154
163
|
)
|
|
155
164
|
}
|
|
156
165
|
|
|
166
|
+
const ANCHOR_CLEARANCE = 'var(--vx-space-sticky-header-clearance)'
|
|
167
|
+
|
|
168
|
+
/** The `scroll-margin-top` of an anchored Section; the bar term only exists without a shell. */
|
|
169
|
+
function anchorOffset(inShell: boolean): string {
|
|
170
|
+
if (inShell) return ANCHOR_CLEARANCE
|
|
171
|
+
return `calc(var(${PAGE_BAR_HEIGHT_VAR}, 0px) + ${ANCHOR_CLEARANCE})`
|
|
172
|
+
}
|
|
173
|
+
|
|
157
174
|
export function Section({
|
|
158
175
|
actions,
|
|
159
176
|
query,
|
|
@@ -162,6 +179,8 @@ export function Section({
|
|
|
162
179
|
collapsible = false,
|
|
163
180
|
persistKey,
|
|
164
181
|
defaultOpen = true,
|
|
182
|
+
open: openProp,
|
|
183
|
+
onOpenChange,
|
|
165
184
|
summary,
|
|
166
185
|
id,
|
|
167
186
|
children,
|
|
@@ -186,11 +205,20 @@ export function Section({
|
|
|
186
205
|
[persistKey, collapsible, title],
|
|
187
206
|
)
|
|
188
207
|
|
|
189
|
-
const [
|
|
208
|
+
const [stateOpen, setStateOpen] = usePersistedOrLocal({
|
|
190
209
|
scope: 'section',
|
|
191
210
|
persistKey,
|
|
192
211
|
initial: defaultOpen,
|
|
193
212
|
})
|
|
213
|
+
const open = openProp ?? stateOpen
|
|
214
|
+
// Dropping `open` falls back to what the reader last SAW, not to a stale persisted value.
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
if (openProp !== undefined && openProp !== stateOpen) setStateOpen(openProp)
|
|
217
|
+
}, [openProp, stateOpen, setStateOpen])
|
|
218
|
+
const setOpen = (next: boolean) => {
|
|
219
|
+
if (openProp === undefined) setStateOpen(next)
|
|
220
|
+
onOpenChange?.(next)
|
|
221
|
+
}
|
|
194
222
|
const bodyId = useId()
|
|
195
223
|
// The aside decides, not the call site (law C1): a Section on the PageAside panel surface, or on
|
|
196
224
|
// its mobile sheet projection, renders the quiet `group` tier automatically — a Section never
|
|
@@ -206,8 +234,11 @@ export function Section({
|
|
|
206
234
|
// row 2's band are shell regions rendered outside it — counting either would land every `#anchor`
|
|
207
235
|
// that far below its own heading. What is left is breathing room, which is exactly what
|
|
208
236
|
// `--vx-space-sticky-header-clearance` means (tokens/palette.ts, `deriveSpacing`).
|
|
209
|
-
|
|
210
|
-
|
|
237
|
+
//
|
|
238
|
+
// The one exception is a tree with NO shell: `PageBar` is then a sticky bar in the document flow,
|
|
239
|
+
// the document is the scrollport, and its published height is exactly what an anchor must clear.
|
|
240
|
+
const inShell = useInPageBarShell()
|
|
241
|
+
const anchorStyle = id === undefined ? undefined : { scrollMarginTop: anchorOffset(inShell) }
|
|
211
242
|
const rootStyle =
|
|
212
243
|
anchorStyle === undefined && style === undefined ? undefined : { ...anchorStyle, ...style }
|
|
213
244
|
|
|
@@ -111,13 +111,6 @@ import type { QueryStateLike } from './query-state'
|
|
|
111
111
|
import { assertQueryStateLike } from '../common/query-state-like'
|
|
112
112
|
import classes from './stat-card.module.css'
|
|
113
113
|
|
|
114
|
-
/**
|
|
115
|
-
* A threshold verdict on the card's value. `undefined` is never tinted — see the module docblock.
|
|
116
|
-
* Alias of the common `Tone` vocabulary (audit A13) — byte-identical, kept as its own name so a
|
|
117
|
-
* consumer's existing `StatCardTone` reference never breaks.
|
|
118
|
-
*/
|
|
119
|
-
export type StatCardTone = Tone
|
|
120
|
-
|
|
121
114
|
/**
|
|
122
115
|
* The four boxes `StatCard` paints, and the whole styling seam it offers (`common/props.ts`).
|
|
123
116
|
* `value` is not its own slot: the hero number is painted by `WidgetHeader`'s internal metrics row,
|
|
@@ -136,7 +129,7 @@ export type StatCardSlot = 'root' | 'header' | 'body' | 'sparkline'
|
|
|
136
129
|
export type StatCardBreakdownRow = {
|
|
137
130
|
readonly label: string
|
|
138
131
|
readonly value: string
|
|
139
|
-
readonly tone?:
|
|
132
|
+
readonly tone?: Tone
|
|
140
133
|
}
|
|
141
134
|
|
|
142
135
|
/**
|
|
@@ -225,7 +218,7 @@ function sparklineState(
|
|
|
225
218
|
* that it cannot be mistaken for the card's own edge. */
|
|
226
219
|
const TONE_RAIL_WIDTH = 3
|
|
227
220
|
|
|
228
|
-
const TONE_LABEL: Record<
|
|
221
|
+
const TONE_LABEL: Record<Tone, string> = {
|
|
229
222
|
good: 'Within the good threshold',
|
|
230
223
|
warn: 'Past the warning threshold',
|
|
231
224
|
bad: 'Past the severe threshold',
|
|
@@ -310,7 +303,7 @@ export type StatCardProps = BasaltProps &
|
|
|
310
303
|
* assistive tech. Omitting it is NOT `'good'`: omitted covers a reading that is fine AND one that
|
|
311
304
|
* is absent, and stays untinted so a card with nothing measured can never render green. Pass
|
|
312
305
|
* `'good'` only to assert a measured value that has earned the verdict. */
|
|
313
|
-
tone?:
|
|
306
|
+
tone?: Tone
|
|
314
307
|
}
|
|
315
308
|
|
|
316
309
|
export function StatCard({
|
|
@@ -449,7 +442,7 @@ export function StatCard({
|
|
|
449
442
|
insetBlock: 0,
|
|
450
443
|
insetInlineStart: 0,
|
|
451
444
|
width: TONE_RAIL_WIDTH,
|
|
452
|
-
// `
|
|
445
|
+
// `Tone`'s members are `VX.status` keys by construction, so the rail reads the
|
|
453
446
|
// per-scheme `--vx-status-*` solid directly — never a hex, so it re-resolves in both
|
|
454
447
|
// schemes and under a consumer's `derive` retune. Contrast against
|
|
455
448
|
// `--vx-surface-panel` is measured in `theme/contrast.test.ts`.
|