basalt-ui 1.1.1 → 1.3.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.
- package/AGENTS.md +2 -2
- package/CHANGELOG.md +46 -0
- package/README.md +64 -8
- package/agent/rules/basalt-app.md +126 -0
- package/agent/rules/basalt-content.md +3 -1
- package/agent/rules/basalt-tokens.md +14 -5
- package/agent/skills/basalt-app/SKILL.md +28 -7
- package/dist/agent/part-list.d.ts.map +1 -1
- package/dist/agent/part-list.js +17 -7
- package/dist/agent/stick-to-bottom.js +2 -2
- package/dist/agent-chat/thread-detail-panel.d.ts.map +1 -1
- package/dist/agent-chat/thread-detail-panel.js +37 -33
- package/dist/agent-chat/thread-message.d.ts.map +1 -1
- package/dist/agent-chat/thread-message.js +8 -5
- package/dist/agent-chat/thread-outcome-card.js +3 -3
- package/dist/agent-chat/thread-workspace.js +1 -1
- package/dist/charts/primitives/ChartLegend.js +2 -0
- package/dist/charts/primitives/ChartTooltip.js +2 -1
- package/dist/cli/index.d.ts +29 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +80 -9
- package/dist/connectivity/connectivity-indicator.d.ts.map +1 -1
- package/dist/connectivity/connectivity-indicator.js +3 -3
- package/dist/content/article-card.module.css +7 -5
- package/dist/content/article-layout.module.css +16 -12
- package/dist/content/callout.module.css +4 -4
- package/dist/content/code-block.module.css +8 -7
- package/dist/content/guide.module.css +3 -3
- package/dist/content/mermaid.module.css +2 -2
- package/dist/content/prose.module.css +59 -29
- package/dist/content/reading-progress.module.css +2 -0
- package/dist/content/toc.module.css +6 -3
- package/dist/dashboard/delta-badge.d.ts.map +1 -1
- package/dist/dashboard/delta-badge.js +10 -2
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +3 -16
- package/dist/dashboard/settings-section.js +2 -2
- package/dist/dashboard/settings-section.module.css +2 -2
- package/dist/dashboard/stat-card.js +2 -1
- package/dist/data/virtual-list.d.ts.map +1 -1
- package/dist/data/virtual-list.js +12 -2
- package/dist/forms/FormErrorSummary.js +2 -2
- package/dist/guard/index.d.ts +20 -4
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +266 -38
- package/dist/guard/types.d.ts +24 -3
- package/dist/guard/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/provider/index.d.ts +30 -1
- package/dist/provider/index.d.ts.map +1 -1
- package/dist/provider/index.js +32 -7
- package/dist/provider/lab-theme.d.ts +39 -0
- package/dist/provider/lab-theme.d.ts.map +1 -0
- package/dist/provider/lab-theme.js +52 -0
- package/dist/shell/app-header.module.css +2 -2
- package/dist/shell/app-mobile-nav.module.css +1 -1
- package/dist/shell/app-sidebar-account.d.ts.map +1 -1
- package/dist/shell/app-sidebar-account.js +4 -2
- package/dist/shell/app-sidebar.d.ts.map +1 -1
- package/dist/shell/app-sidebar.js +4 -2
- package/dist/shell/app-sidebar.module.css +36 -26
- package/dist/shell/index.d.ts.map +1 -1
- package/dist/shell/index.js +11 -4
- package/dist/shell/sidebar-search.module.css +16 -4
- package/dist/styles.css +22 -11
- package/dist/surfaces.d.ts +21 -11
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +10 -3
- package/dist/theme/controls.module.css +1 -1
- package/dist/theme/floating.module.css +1 -1
- package/dist/theme/index.d.ts +116 -11
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +703 -566
- package/dist/theme/nav-link.module.css +1 -1
- package/dist/theme/use-basalt-spacing.d.ts +3 -0
- package/dist/theme/use-basalt-spacing.d.ts.map +1 -0
- package/dist/theme/use-basalt-spacing.js +8 -0
- package/dist/theme-lab/derive-controls.d.ts +13 -0
- package/dist/theme-lab/derive-controls.d.ts.map +1 -0
- package/dist/theme-lab/derive-controls.js +137 -0
- package/dist/theme-lab/derive-state.d.ts +55 -0
- package/dist/theme-lab/derive-state.d.ts.map +1 -0
- package/dist/theme-lab/derive-state.js +81 -0
- package/dist/theme-lab/index.d.ts +12 -2
- package/dist/theme-lab/index.d.ts.map +1 -1
- package/dist/theme-lab/index.js +13 -62
- package/dist/theme-toggle/index.d.ts.map +1 -1
- package/dist/theme-toggle/index.js +3 -2
- package/dist/tokens/derive.d.ts +89 -0
- package/dist/tokens/derive.d.ts.map +1 -0
- package/dist/tokens/derive.js +250 -0
- package/dist/tokens/hct.d.ts +34 -0
- package/dist/tokens/hct.d.ts.map +1 -0
- package/dist/tokens/hct.js +159 -0
- package/dist/tokens/index.d.ts +143 -7
- package/dist/tokens/index.d.ts.map +1 -1
- package/dist/tokens/index.js +322 -48
- package/dist/tokens/palette.d.ts +984 -167
- package/dist/tokens/palette.d.ts.map +1 -1
- package/dist/tokens/palette.js +617 -119
- package/dist/tokens.css +248 -0
- package/dist/vite-color-mix.d.ts +30 -0
- package/dist/vite-color-mix.d.ts.map +1 -0
- package/dist/vite-color-mix.js +80 -0
- package/dist/vite.d.ts +82 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +312 -0
- package/llms.txt +14 -4
- package/package.json +41 -10
- package/src/agent/part-list.tsx +13 -7
- package/src/agent/stick-to-bottom.tsx +2 -2
- package/src/agent-chat/thread-detail-panel.tsx +13 -10
- package/src/agent-chat/thread-message.tsx +8 -5
- package/src/agent-chat/thread-outcome-card.tsx +2 -2
- package/src/agent-chat/thread-workspace.tsx +2 -2
- package/src/charts/primitives/ChartLegend.tsx +2 -2
- package/src/charts/primitives/ChartTooltip.tsx +2 -2
- package/src/cli/check-theme.test.ts +18 -0
- package/src/cli/index.ts +129 -6
- package/src/cli/tokens-css.test.ts +90 -0
- package/src/connectivity/connectivity-indicator.tsx +8 -2
- package/src/content/article-card.module.css +7 -5
- package/src/content/article-layout.module.css +16 -12
- package/src/content/callout.module.css +4 -4
- package/src/content/code-block.module.css +8 -7
- package/src/content/guide.module.css +3 -3
- package/src/content/mermaid.module.css +2 -2
- package/src/content/prose.module.css +59 -29
- package/src/content/prose.module.css.test.ts +55 -0
- package/src/content/reading-progress.module.css +2 -0
- package/src/content/toc.module.css +6 -3
- package/src/dashboard/delta-badge.tsx +10 -4
- package/src/dashboard/empty-state.tsx +3 -16
- package/src/dashboard/settings-section.module.css +2 -2
- package/src/dashboard/settings-section.tsx +2 -2
- package/src/dashboard/stat-card.tsx +2 -2
- package/src/data/virtual-list.tsx +12 -2
- package/src/forms/FormErrorSummary.tsx +1 -1
- package/src/guard/check-source.test.ts +483 -15
- package/src/guard/index.ts +426 -47
- package/src/guard/types.ts +24 -2
- package/src/index.ts +1 -0
- package/src/provider/index.test.tsx +100 -0
- package/src/provider/index.tsx +79 -7
- package/src/provider/lab-theme.test.ts +147 -0
- package/src/provider/lab-theme.ts +166 -0
- package/src/shell/app-header.module.css +2 -2
- package/src/shell/app-mobile-nav.module.css +1 -1
- package/src/shell/app-sidebar-account.tsx +9 -2
- package/src/shell/app-sidebar.module.css +36 -26
- package/src/shell/app-sidebar.tsx +12 -2
- package/src/shell/index.tsx +14 -3
- package/src/shell/sidebar-search.module.css +16 -4
- package/src/styles.css +22 -11
- package/src/surfaces.ts +24 -10
- package/src/theme/contrast.test.ts +19 -3
- package/src/theme/controls.module.css +1 -1
- package/src/theme/density-option.test.ts +96 -0
- package/src/theme/density-relations.test.ts +428 -0
- package/src/theme/derive-theme.test.ts +101 -0
- package/src/theme/floating.module.css +1 -1
- package/src/theme/fonts-option.test.ts +69 -0
- package/src/theme/index.ts +930 -563
- package/src/theme/nav-link.module.css +1 -1
- package/src/theme/radius-option.test.ts +86 -0
- package/src/theme/radius.test.ts +132 -0
- package/src/theme/spacing.test.ts +432 -0
- package/src/theme/use-basalt-spacing.test.tsx +51 -0
- package/src/theme/use-basalt-spacing.ts +38 -0
- package/src/theme-lab/derive-controls.test.ts +94 -0
- package/src/theme-lab/derive-controls.tsx +227 -0
- package/src/theme-lab/derive-state.test.ts +71 -0
- package/src/theme-lab/derive-state.ts +163 -0
- package/src/theme-lab/index.tsx +29 -68
- package/src/theme-lab/theme-lab.test.ts +4 -18
- package/src/theme-toggle/index.tsx +9 -4
- package/src/tokens/build-fonts-css.test.ts +51 -0
- package/src/tokens/build-radius-css.test.ts +25 -0
- package/src/tokens/density.test.ts +274 -0
- package/src/tokens/derive-radius.test.ts +62 -0
- package/src/tokens/derive.test.ts +30 -0
- package/src/tokens/derive.ts +481 -0
- package/src/tokens/hct.ts +231 -0
- package/src/tokens/index.ts +534 -48
- package/src/tokens/palette.test.ts +114 -0
- package/src/tokens/palette.ts +1118 -180
- package/src/vite-color-mix.test.ts +46 -0
- package/src/vite-color-mix.ts +137 -0
- package/src/vite.test.ts +192 -0
- package/src/vite.ts +502 -1
package/src/guard/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Guard types — Mantine-free, dependency-free (zero imports beyond TS types).
|
|
3
3
|
*
|
|
4
|
-
* GuardKind is the closed set of
|
|
4
|
+
* GuardKind is the closed set of 19 violation kinds the theme guard can emit.
|
|
5
5
|
* Finding is the structured result per violation, replacing the old `Violation` shape.
|
|
6
6
|
* GuardConfig is the per-run configuration that drives checkSource.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/** The
|
|
9
|
+
/** The 19 theme-guard violation kinds. */
|
|
10
10
|
export type GuardKind =
|
|
11
11
|
| 'raw-hex'
|
|
12
12
|
| 'raw-color-fn'
|
|
@@ -26,6 +26,7 @@ export type GuardKind =
|
|
|
26
26
|
| 'chart-missing-aria-label'
|
|
27
27
|
| 'raw-form-control'
|
|
28
28
|
| 'sub-16-input-font'
|
|
29
|
+
| 'raw-font-family'
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* A structured finding — the chosen testable surface (§C.4). Replaces the old `Violation` type.
|
|
@@ -114,4 +115,25 @@ export type GuardConfig = {
|
|
|
114
115
|
* Default 'theme-allow'. Pure-comment lines (// * /\*) are always skipped.
|
|
115
116
|
*/
|
|
116
117
|
readonly allowComment: string
|
|
118
|
+
/**
|
|
119
|
+
* Per-rule, per-path exemptions — complements whole-file `exempt` (BasaltConfig, which skips
|
|
120
|
+
* ALL rules for a file) and code-level `appliesTo` (hardcoded per-kind path scoping, e.g.
|
|
121
|
+
* raw-visx-axis → chart files only). This is the config-driven counterpart: a consumer can say
|
|
122
|
+
* "kind K does not apply under path P" without exempting the whole file or forking the rule.
|
|
123
|
+
*
|
|
124
|
+
* Each value is a list of path-segment patterns matched against a finding's `relPath`. A pattern
|
|
125
|
+
* matches when `relPath.split('/')` includes it as a WHOLE segment — `'agent'` matches
|
|
126
|
+
* `src/agent/part-list.tsx` but not `src/agenting.ts`. A trailing `/` is stripped before
|
|
127
|
+
* matching, so `'agent'` and `'agent/'` behave identically. Applied as a post-filter over the
|
|
128
|
+
* final findings, so it uniformly covers every kind — both the GUARD_RULES registry loop and the
|
|
129
|
+
* inline-handled kinds (raw-surface, raw-html-layout, sub-16-input-font, …).
|
|
130
|
+
*
|
|
131
|
+
* Required (like every other GuardConfig field, defaulted via DEFAULT_GUARD_CONFIG to `{}`) —
|
|
132
|
+
* `exactOptionalPropertyTypes` rejects the `?? DEFAULT_GUARD_CONFIG.x` pattern used to build a
|
|
133
|
+
* GuardConfig from BasaltConfig (where the field IS optional) if this were optional too.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* { exemptRules: { 'inline-display': ['agent'] } } // inline-display never fires under src/agent/**
|
|
137
|
+
*/
|
|
138
|
+
readonly exemptRules: Partial<Record<GuardKind, string[]>>
|
|
117
139
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export {
|
|
|
13
13
|
type BasaltErrorContext,
|
|
14
14
|
} from './provider'
|
|
15
15
|
export { createBasaltTheme, baseTheme, cssVariablesResolver } from './theme'
|
|
16
|
+
export type { BasaltFontsConfig, CreateBasaltThemeOptions } from './theme'
|
|
16
17
|
export { ThemeToggle, type ThemeToggleProps } from './theme-toggle'
|
|
17
18
|
export { MOTION_DURATION, MOTION_SPRING, MOTION_EASE_STANDARD } from './motion'
|
|
18
19
|
export {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `composeInjectedCss` — the CSS-cascade ORDER of the four override blocks `BasaltBridge` injects.
|
|
3
|
+
* `buildPaletteCss`/`buildFontsCss`/`buildRadiusCss`/`buildDensityCss` all emit a bare `:root { ... }`
|
|
4
|
+
* block, so they tie on selector specificity; only document order decides which declaration a
|
|
5
|
+
* browser actually paints when two blocks declare the same `--vx-*`/`--basalt-font-*` var. Reordering
|
|
6
|
+
* the array `composeInjectedCss` concatenates silently breaks the density/radius/fonts knobs with
|
|
7
|
+
* every OTHER existing test still green (each builder's own test only checks its OWN isolated
|
|
8
|
+
* output) — this file is the one place that ordering itself is under test (Fix 5 / B5).
|
|
9
|
+
*
|
|
10
|
+
* The `BasaltBridge density wiring` block below covers the layer `composeInjectedCss` alone can't:
|
|
11
|
+
* that `BasaltBridge` (not just the pure `composeInjectedCss` helper) actually reads
|
|
12
|
+
* `theme.other.basaltDensity` off the RUNNING theme and feeds it through `buildDensityCss` into the
|
|
13
|
+
* injected `<style>`, end to end from `createBasaltTheme(undefined, { density })`. No
|
|
14
|
+
* `@testing-library/react`/jsdom is configured in this repo (see `tokens/build-fonts-css.test.ts`'s
|
|
15
|
+
* doc for that same limitation elsewhere) — `react-dom/server`'s `renderToStaticMarkup` renders the
|
|
16
|
+
* real `BasaltProvider` tree without a DOM, which is enough since the injected `<style>` is plain
|
|
17
|
+
* text content, not something that needs a live DOM to assert on.
|
|
18
|
+
*/
|
|
19
|
+
import { describe, expect, test } from 'bun:test'
|
|
20
|
+
import { renderToStaticMarkup } from 'react-dom/server'
|
|
21
|
+
import { BasaltProvider, composeInjectedCss } from './index'
|
|
22
|
+
import { createBasaltTheme } from '../theme'
|
|
23
|
+
import { buildDensityCss, buildFontsCss, buildPaletteCss, buildRadiusCss } from '../tokens'
|
|
24
|
+
import { deriveRadius, deriveSpacing } from '../tokens/palette'
|
|
25
|
+
|
|
26
|
+
describe('composeInjectedCss orders overrides so density/radius/fonts win the cascade over the base palette', () => {
|
|
27
|
+
test('density block is textually LAST in the composed string — same :root selector, so document order decides', () => {
|
|
28
|
+
const base = buildPaletteCss()
|
|
29
|
+
const densityCss = buildDensityCss(deriveSpacing(3))
|
|
30
|
+
const composed = composeInjectedCss(base, '', '', densityCss)
|
|
31
|
+
expect(composed.indexOf(densityCss)).toBeGreaterThan(composed.indexOf(base))
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('a real declaration resolves to the LAST occurrence in composed order — the actual mechanism a browser cascade uses, not just index order', () => {
|
|
35
|
+
// base emits --vx-space-row-inset-x: 10px (level 0); density (level 3) overrides it to 13px.
|
|
36
|
+
const base = buildPaletteCss()
|
|
37
|
+
const densityCss = buildDensityCss(deriveSpacing(3))
|
|
38
|
+
const composed = composeInjectedCss(base, '', '', densityCss)
|
|
39
|
+
const matches = [...composed.matchAll(/--vx-space-row-inset-x: (\d+)px;/g)].map((m) => m[1])
|
|
40
|
+
expect(matches).toEqual(['10', '13'])
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
test('radius overrides resolve to their retuned value at the end of the composed string too', () => {
|
|
44
|
+
const base = buildPaletteCss()
|
|
45
|
+
const radiusCss = buildRadiusCss(deriveRadius(3))
|
|
46
|
+
const composed = composeInjectedCss(base, '', radiusCss, '')
|
|
47
|
+
const matches = [...composed.matchAll(/--vx-radius-card: (\d+)px;/g)].map((m) => m[1])
|
|
48
|
+
expect(matches.at(-1)).toBe(String(deriveRadius(3).card))
|
|
49
|
+
expect(matches.at(-1)).not.toBe(String(deriveRadius(0).card))
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('fonts overrides land at the end of the composed string too (base emits no --basalt-font-* at all)', () => {
|
|
53
|
+
const base = buildPaletteCss()
|
|
54
|
+
const fontsCss = buildFontsCss({ sans: 'CustomFont, sans-serif' })
|
|
55
|
+
const composed = composeInjectedCss(base, fontsCss, '', '')
|
|
56
|
+
expect(base).not.toContain('--basalt-font-sans')
|
|
57
|
+
expect(composed.trim().endsWith(fontsCss.trim())).toBe(true)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('regression proof: reversing the order (the exact defect this file guards against) flips which value wins', () => {
|
|
61
|
+
const base = buildPaletteCss()
|
|
62
|
+
const densityCss = buildDensityCss(deriveSpacing(3))
|
|
63
|
+
// The OLD/broken shape this order could silently regress to — density concatenated BEFORE base.
|
|
64
|
+
const brokenComposed = [densityCss, base].filter(Boolean).join('\n')
|
|
65
|
+
const matches = [...brokenComposed.matchAll(/--vx-space-row-inset-x: (\d+)px;/g)].map(
|
|
66
|
+
(m) => m[1],
|
|
67
|
+
)
|
|
68
|
+
// Base now wins over density (LAST occurrence is the un-retuned 10, not 13) — the exact silent
|
|
69
|
+
// breakage `composeInjectedCss`'s fixed order exists to prevent.
|
|
70
|
+
expect(matches.at(-1)).toBe('10')
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('BasaltBridge reads theme.other.basaltDensity and injects it end to end', () => {
|
|
75
|
+
test('a non-default density option lands its buildDensityCss output in the rendered <style>', () => {
|
|
76
|
+
const html = renderToStaticMarkup(
|
|
77
|
+
<BasaltProvider theme={createBasaltTheme(undefined, { density: -2 })}>
|
|
78
|
+
<div>content</div>
|
|
79
|
+
</BasaltProvider>,
|
|
80
|
+
)
|
|
81
|
+
// Fails if `BasaltBridge` stops reading `theme.other.basaltDensity` (e.g. reads a different key,
|
|
82
|
+
// or never passes it to `buildDensityCss`) — the exact retuned block would then be absent.
|
|
83
|
+
expect(html).toContain(buildDensityCss(deriveSpacing(-2)))
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('the default (level-0) theme injects no density override block at all', () => {
|
|
87
|
+
const html = renderToStaticMarkup(
|
|
88
|
+
<BasaltProvider theme={createBasaltTheme()}>
|
|
89
|
+
<div>content</div>
|
|
90
|
+
</BasaltProvider>,
|
|
91
|
+
)
|
|
92
|
+
// Fails if `BasaltBridge` injects a density block even when `theme.other.basaltDensity` is unset
|
|
93
|
+
// (`createBasaltTheme()`'s default path never sets it — `density-option.test.ts`). The BASE
|
|
94
|
+
// palette CSS already emits `--vx-space-row-inset-x` once (`frameworkDerived`'s own
|
|
95
|
+
// `DEFAULT_SPACE_VALUES` decls) — a stray SECOND occurrence is the signature of an unwanted
|
|
96
|
+
// density override block getting appended on top of it.
|
|
97
|
+
expect(html).not.toContain(buildDensityCss(deriveSpacing(-2)))
|
|
98
|
+
expect(html.split('--vx-space-row-inset-x').length - 1).toBe(1)
|
|
99
|
+
})
|
|
100
|
+
})
|
package/src/provider/index.tsx
CHANGED
|
@@ -15,15 +15,18 @@
|
|
|
15
15
|
*
|
|
16
16
|
* Mantine usage is allowed in this `./` root layer (unlike `src/charts/**` and `src/tokens/**`).
|
|
17
17
|
*/
|
|
18
|
-
import { MantineProvider, useComputedColorScheme } from '@mantine/core'
|
|
18
|
+
import { MantineProvider, useComputedColorScheme, useMantineTheme } from '@mantine/core'
|
|
19
19
|
import type { MantineProviderProps } from '@mantine/core'
|
|
20
|
-
import { Component, useEffect } from 'react'
|
|
20
|
+
import { Component, useEffect, useMemo } from 'react'
|
|
21
21
|
import type { ErrorInfo, ReactNode } from 'react'
|
|
22
22
|
import { VxThemeProvider } from '../charts/theme'
|
|
23
23
|
import { ConnectivityProvider } from '../connectivity'
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
24
|
+
import { cssVariablesResolver } from '../theme'
|
|
25
|
+
import { useLabTheme } from './lab-theme'
|
|
26
|
+
import { buildDensityCss, buildFontsCss, buildPaletteCss, buildRadiusCss } from '../tokens'
|
|
26
27
|
import type { BuildPaletteOpts } from '../tokens'
|
|
28
|
+
import { isDefaultDeriveConfig } from '../tokens/derive'
|
|
29
|
+
import { buildPaletteData } from '../tokens/palette'
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* Where an error surfaced — drives consumer routing (a render error vs a global rejection differ).
|
|
@@ -47,7 +50,22 @@ export type BasaltProviderProps = {
|
|
|
47
50
|
theme?: MantineProviderProps['theme']
|
|
48
51
|
/**
|
|
49
52
|
* Inject the `--vx-*` palette stylesheet once via an inline `<style>`. Default `true`. Set
|
|
50
|
-
* `false` to skip it (SSR / head injection — emit `buildPaletteCss(paletteOptions)` yourself
|
|
53
|
+
* `false` to skip it (SSR / head injection — emit `buildPaletteCss(paletteOptions)` yourself, all
|
|
54
|
+
* three builders importable from `basalt-ui/tokens`).
|
|
55
|
+
* A `{ fonts }` config passed to `createBasaltTheme` rides this SAME injection (its
|
|
56
|
+
* `--basalt-font-*` declarations are appended to the same `<style>`), so `injectPalette={false}`
|
|
57
|
+
* opts fonts out too — emit `buildFontsCss(theme.other.basaltFonts)` yourself alongside the
|
|
58
|
+
* palette CSS in that case.
|
|
59
|
+
* A `{ radius }` config rides the SAME injection too (its `--vx-radius-*` override declarations
|
|
60
|
+
* are appended alongside), so `injectPalette={false}` opts radius out just the same — an SSR
|
|
61
|
+
* consumer disabling injection must also emit `buildRadiusCss(theme.other.basaltRadius)`
|
|
62
|
+
* themselves, or `var(--vx-radius-*)` consumers render at their defaults instead of the retuned
|
|
63
|
+
* level.
|
|
64
|
+
* A `{ density }` config rides the SAME injection too (its `--vx-space-*` override declarations
|
|
65
|
+
* are appended alongside), so `injectPalette={false}` opts density out just the same — an SSR
|
|
66
|
+
* consumer disabling injection must also emit `buildDensityCss(theme.other.basaltDensity)`
|
|
67
|
+
* themselves, or `var(--vx-space-*)` consumers render at their defaults instead of the retuned
|
|
68
|
+
* level.
|
|
51
69
|
*/
|
|
52
70
|
injectPalette?: boolean
|
|
53
71
|
/**
|
|
@@ -136,6 +154,28 @@ export class BasaltErrorBoundary extends Component<BoundaryProps, BoundaryState>
|
|
|
136
154
|
}
|
|
137
155
|
}
|
|
138
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Compose the four independently-built override CSS blocks into ONE injected `<style>` body, in
|
|
159
|
+
* cascade-winning order. Every builder (`buildPaletteCss`/`buildFontsCss`/`buildRadiusCss`/
|
|
160
|
+
* `buildDensityCss`) emits its declarations under a bare `:root { ... }` block — EQUAL selector
|
|
161
|
+
* specificity across all four — so nothing but DOCUMENT ORDER decides which value a browser paints
|
|
162
|
+
* when two blocks declare the same custom property. `density` must come LAST (its `--vx-space-*`
|
|
163
|
+
* overrides must out-cascade the base palette's own defaults), `radius` after `fonts`, `fonts` after
|
|
164
|
+
* `base` — reorder this array and the density/radius/fonts knobs silently stop working, with every
|
|
165
|
+
* OTHER existing test still green (each builder is tested for its OWN output in isolation, not for
|
|
166
|
+
* where it lands in the concatenated string). Exported as a pure function (not inlined in
|
|
167
|
+
* `BasaltBridge`'s `useMemo`) purely so `provider/index.test.ts` can assert the ORDER holds without
|
|
168
|
+
* rendering a React tree.
|
|
169
|
+
*/
|
|
170
|
+
export function composeInjectedCss(
|
|
171
|
+
base: string,
|
|
172
|
+
fontsCss: string,
|
|
173
|
+
radiusCss: string,
|
|
174
|
+
densityCss: string,
|
|
175
|
+
): string {
|
|
176
|
+
return [base, fontsCss, radiusCss, densityCss].filter(Boolean).join('\n')
|
|
177
|
+
}
|
|
178
|
+
|
|
139
179
|
// ── Inner bridge ──────────────────────────────────────────────────────────────────────────────────
|
|
140
180
|
|
|
141
181
|
/**
|
|
@@ -160,6 +200,32 @@ function BasaltBridge({
|
|
|
160
200
|
// (fallback 'dark' before hydration, matching the provider's defaultColorScheme).
|
|
161
201
|
const resolved = useComputedColorScheme('dark')
|
|
162
202
|
|
|
203
|
+
// `createBasaltTheme`'s non-default `{ derive }` / `{ fonts }` / `{ radius }` / `{ density }`
|
|
204
|
+
// paths stash the resolved values on `theme.other.basaltDerive` / `theme.other.basaltFonts` /
|
|
205
|
+
// `theme.other.basaltRadius` / `theme.other.basaltDensity` — read them here (INSIDE
|
|
206
|
+
// MantineProvider, so `useMantineTheme` sees the fully-merged runtime theme) to decide whether the
|
|
207
|
+
// pre-baked static palette CSS still applies or a re-derived one is needed, and whether any
|
|
208
|
+
// `--basalt-font-*` / `--vx-radius-*` / `--vx-space-*` override declarations must ride along.
|
|
209
|
+
// Default/absent config -> zero extra derivation work.
|
|
210
|
+
const theme = useMantineTheme()
|
|
211
|
+
const deriveConfig = theme.other?.basaltDerive
|
|
212
|
+
const fontsConfig = theme.other?.basaltFonts
|
|
213
|
+
const radiusConfig = theme.other?.basaltRadius
|
|
214
|
+
const densityConfig = theme.other?.basaltDensity
|
|
215
|
+
const paletteCss = useMemo(() => {
|
|
216
|
+
if (!injectPalette) return ''
|
|
217
|
+
const base =
|
|
218
|
+
deriveConfig === undefined || isDefaultDeriveConfig(deriveConfig)
|
|
219
|
+
? buildPaletteCss(paletteOptions)
|
|
220
|
+
: // Memoized by `buildPaletteData` (keyed on the config value), so retuning is never a
|
|
221
|
+
// per-render re-derivation once a given config has been built once.
|
|
222
|
+
buildPaletteCss(paletteOptions, buildPaletteData(deriveConfig))
|
|
223
|
+
const fontsCss = buildFontsCss(fontsConfig)
|
|
224
|
+
const radiusCss = buildRadiusCss(radiusConfig)
|
|
225
|
+
const densityCss = buildDensityCss(densityConfig)
|
|
226
|
+
return composeInjectedCss(base, fontsCss, radiusCss, densityCss)
|
|
227
|
+
}, [injectPalette, deriveConfig, fontsConfig, radiusConfig, densityConfig, paletteOptions])
|
|
228
|
+
|
|
163
229
|
useEffect(() => {
|
|
164
230
|
// SSR guard — window is not available in server contexts
|
|
165
231
|
if (typeof window === 'undefined') return
|
|
@@ -183,7 +249,7 @@ function BasaltBridge({
|
|
|
183
249
|
|
|
184
250
|
return (
|
|
185
251
|
<VxThemeProvider colorScheme={resolved}>
|
|
186
|
-
{injectPalette ? <style nonce={nonce}>{
|
|
252
|
+
{injectPalette ? <style nonce={nonce}>{paletteCss}</style> : null}
|
|
187
253
|
{children}
|
|
188
254
|
</VxThemeProvider>
|
|
189
255
|
)
|
|
@@ -206,9 +272,15 @@ export function BasaltProvider({
|
|
|
206
272
|
}: BasaltProviderProps) {
|
|
207
273
|
const errorHandler = onError ?? defaultOnError
|
|
208
274
|
|
|
275
|
+
// `createBasaltTheme(theme)` — plus, when the theme lab's "Apply" switch is on, the delta of its
|
|
276
|
+
// persisted config, so the dev tool moves the numeric `defaultProps` and `theme.spacing` a `<style>`
|
|
277
|
+
// tag cannot reach. No lab override (every production app) → the consumer theme merged onto the
|
|
278
|
+
// Basalt base and nothing else. See `./lab-theme.ts`.
|
|
279
|
+
const resolvedTheme = useLabTheme(theme)
|
|
280
|
+
|
|
209
281
|
return (
|
|
210
282
|
<MantineProvider
|
|
211
|
-
theme={
|
|
283
|
+
theme={resolvedTheme}
|
|
212
284
|
cssVariablesResolver={cssVariablesResolver}
|
|
213
285
|
defaultColorScheme={defaultColorScheme}
|
|
214
286
|
{...rest}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The theme lab's theme-OBJECT seam (`./lab-theme.ts`).
|
|
3
|
+
*
|
|
4
|
+
* The lab used to apply a config through a `<style>` tag alone, which can only move CSS custom
|
|
5
|
+
* properties — so the Radius/Density sliders moved the CSS-module-styled surfaces and left
|
|
6
|
+
* `theme.radius`/`theme.spacing` and every numeric `defaultProps` frozen at level 0. Two things have
|
|
7
|
+
* to hold for the tool to be honest, and both are asserted here:
|
|
8
|
+
*
|
|
9
|
+
* 1. The delta an active override contributes really carries the theme-object numbers (`radius`,
|
|
10
|
+
* `spacing`, the `defaultProps` `buildTheme` bakes in), so they follow the sliders.
|
|
11
|
+
* 2. It carries NOTHING ELSE — no function-valued field (fresh closure per `buildTheme` call, would
|
|
12
|
+
* clobber a consumer's own `vars`/`classNames`), and no field the config doesn't actually move.
|
|
13
|
+
* That second half is what lets the delta be merged LAST, over a consumer theme, without eating
|
|
14
|
+
* the consumer's overrides.
|
|
15
|
+
*
|
|
16
|
+
* Expected values are read from `deriveRadius`/`deriveSpacing` rather than hardcoded — the LAW is
|
|
17
|
+
* locked by `theme/radius.test.ts` + `theme/spacing.test.ts`; what this file locks is that the law's
|
|
18
|
+
* output reaches the theme object the provider hands to `MantineProvider`.
|
|
19
|
+
*/
|
|
20
|
+
import { describe, expect, test } from 'bun:test'
|
|
21
|
+
import { applyLabOverride, themeOverrideDelta } from './lab-theme'
|
|
22
|
+
import { baseTheme, createBasaltTheme } from '../theme'
|
|
23
|
+
import { pxRem } from '../tokens'
|
|
24
|
+
import { DEFAULT_DERIVE_CONFIG } from '../tokens/derive'
|
|
25
|
+
import { deriveRadius, deriveSpacing } from '../tokens/palette'
|
|
26
|
+
import type { DeriveOverride } from '../theme-lab/derive-state'
|
|
27
|
+
|
|
28
|
+
const at = (radiusLevel: number, densityLevel: number): DeriveOverride => ({
|
|
29
|
+
config: DEFAULT_DERIVE_CONFIG,
|
|
30
|
+
radiusLevel,
|
|
31
|
+
densityLevel,
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
/** Read a dotted path out of a partial theme without a cast at every assertion. */
|
|
35
|
+
const pick = (theme: unknown, path: string): unknown =>
|
|
36
|
+
path.split('.').reduce<unknown>((acc, key) => {
|
|
37
|
+
if (acc === null || typeof acc !== 'object') return undefined
|
|
38
|
+
return (acc as Record<string, unknown>)[key]
|
|
39
|
+
}, theme)
|
|
40
|
+
|
|
41
|
+
describe('themeOverrideDelta', () => {
|
|
42
|
+
test('a theme against itself yields an empty override', () => {
|
|
43
|
+
expect(themeOverrideDelta(baseTheme, baseTheme)).toEqual({})
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('two independently built default themes still yield an empty override', () => {
|
|
47
|
+
// The guard against a false-positive delta: `buildTheme` allocates fresh `vars`/`classNames`
|
|
48
|
+
// closures every call, so a reference-comparing diff would report dozens of changed fields for
|
|
49
|
+
// two configs that are in fact identical — and then clobber them on every consumer.
|
|
50
|
+
expect(themeOverrideDelta(createBasaltTheme(), createBasaltTheme())).toEqual({})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('never carries a function-valued field', () => {
|
|
54
|
+
const delta = themeOverrideDelta(baseTheme, createBasaltTheme(undefined, { radius: -2 }))
|
|
55
|
+
const functions: string[] = []
|
|
56
|
+
const walk = (node: unknown, path: string): void => {
|
|
57
|
+
if (typeof node === 'function') functions.push(path)
|
|
58
|
+
if (node === null || typeof node !== 'object' || Array.isArray(node)) return
|
|
59
|
+
for (const [key, value] of Object.entries(node)) walk(value, path ? `${path}.${key}` : key)
|
|
60
|
+
}
|
|
61
|
+
walk(delta, '')
|
|
62
|
+
expect(functions).toEqual([])
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe('a radius override reaches the theme object', () => {
|
|
67
|
+
const delta = themeOverrideDelta(baseTheme, createBasaltTheme(undefined, { radius: -2 }))
|
|
68
|
+
const radius = deriveRadius(-2)
|
|
69
|
+
|
|
70
|
+
test('the Mantine radius scale moves', () => {
|
|
71
|
+
expect(pick(delta, 'radius.md')).toBe(pxRem(radius.ctrl))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test("Badge's numeric defaultProps radius moves — the case a <style> tag can never reach", () => {
|
|
75
|
+
expect(pick(delta, 'components.Badge.defaultProps.radius')).toBe(radius.ctrl)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('the floating tier moves with it (Tooltip/Popover/Modal/Notification)', () => {
|
|
79
|
+
expect(pick(delta, 'components.Tooltip.defaultProps.radius')).toBe(radius.floating)
|
|
80
|
+
expect(pick(delta, 'components.Popover.defaultProps.radius')).toBe(radius.floating)
|
|
81
|
+
expect(pick(delta, 'components.Modal.defaultProps.radius')).toBe(radius.floating)
|
|
82
|
+
expect(pick(delta, 'components.Notification.defaultProps.radius')).toBe(radius.floating)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test('Card/Paper are NOT in it — they read var(--vx-radius-card), so the CSS half owns them', () => {
|
|
86
|
+
expect(pick(delta, 'components.Card')).toBeUndefined()
|
|
87
|
+
expect(pick(delta, 'components.Paper')).toBeUndefined()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('the resolved values ride along for the provider to inject as CSS', () => {
|
|
91
|
+
expect(pick(delta, 'other.basaltRadius')).toEqual(radius)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
test('spacing is untouched — a radius level moves radius only', () => {
|
|
95
|
+
expect(pick(delta, 'spacing')).toBeUndefined()
|
|
96
|
+
expect(pick(delta, 'other.basaltDensity')).toBeUndefined()
|
|
97
|
+
})
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
describe('a density override reaches the theme object', () => {
|
|
101
|
+
const delta = themeOverrideDelta(baseTheme, createBasaltTheme(undefined, { density: -1 }))
|
|
102
|
+
const spacing = deriveSpacing(-1)
|
|
103
|
+
|
|
104
|
+
test("theme.spacing moves — every p='md' / gap='sm' in the app follows", () => {
|
|
105
|
+
expect(pick(delta, 'spacing.md')).toBe(pxRem(spacing.scale.md))
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test("Timeline's bulletSize and Progress's size move", () => {
|
|
109
|
+
expect(pick(delta, 'components.Timeline.defaultProps.bulletSize')).toBe(
|
|
110
|
+
spacing.step.timelineBullet,
|
|
111
|
+
)
|
|
112
|
+
expect(pick(delta, 'components.Progress.defaultProps.size')).toBe(spacing.step.progressBarSize)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test('the resolved values ride along for the provider to inject as CSS', () => {
|
|
116
|
+
expect(pick(delta, 'other.basaltDensity')).toEqual(spacing)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('applyLabOverride', () => {
|
|
121
|
+
test('no override → the consumer theme merged onto the base, exactly as before', () => {
|
|
122
|
+
expect(applyLabOverride(undefined, null)).toBe(baseTheme)
|
|
123
|
+
expect(applyLabOverride({ primaryColor: 'teal' }, null)).toEqual(
|
|
124
|
+
createBasaltTheme({ primaryColor: 'teal' }),
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('an override at level 0 with the default palette changes nothing', () => {
|
|
129
|
+
expect(applyLabOverride(undefined, at(0, 0))).toEqual(baseTheme)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('the override wins over a consumer theme that bakes in level-0 numbers', () => {
|
|
133
|
+
// The documented mount is `theme={createBasaltTheme()}` — a COMPLETE theme carrying every
|
|
134
|
+
// level-0 number. Merged last (which is `BasaltProvider`'s contract) it would clobber the lab
|
|
135
|
+
// right back to level 0; the delta is what out-cascades it.
|
|
136
|
+
const resolved = applyLabOverride(createBasaltTheme(), at(-2, -1))
|
|
137
|
+
expect(pick(resolved, 'components.Badge.defaultProps.radius')).toBe(deriveRadius(-2).ctrl)
|
|
138
|
+
expect(pick(resolved, 'spacing.md')).toBe(pxRem(deriveSpacing(-1).scale.md))
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("a consumer's own unrelated overrides survive the override", () => {
|
|
142
|
+
const resolved = applyLabOverride({ primaryColor: 'teal', other: { myFlag: true } }, at(-2, -1))
|
|
143
|
+
expect(pick(resolved, 'primaryColor')).toBe('teal')
|
|
144
|
+
expect(pick(resolved, 'other.myFlag')).toBe(true)
|
|
145
|
+
expect(pick(resolved, 'components.Badge.defaultProps.radius')).toBe(deriveRadius(-2).ctrl)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The theme lab's theme-object seam — what makes the dev tool an HONEST measuring instrument.
|
|
3
|
+
*
|
|
4
|
+
* `DeriveControls` applies a config by injecting a `<style>` tag, which can only move CSS custom
|
|
5
|
+
* properties. Part of what the Radius and Density knobs control is NOT a CSS var but a plain number
|
|
6
|
+
* baked into the theme OBJECT by `buildTheme`, and a `<style>` tag cannot reach a number inside a JS
|
|
7
|
+
* object. Exactly what that is (the set is small and knowable — `lab-theme.test.ts` pins it):
|
|
8
|
+
*
|
|
9
|
+
* - `theme.radius` and `theme.spacing` — the generic Mantine `xs`..`xl` scales, i.e. every `p="md"` /
|
|
10
|
+
* `gap="sm"` / `radius="md"` prop in the app.
|
|
11
|
+
* - `defaultProps.radius` on Badge / SegmentedControl / Progress / Tooltip / Popover / Modal /
|
|
12
|
+
* Notification, `defaultProps.size` on Progress, `defaultProps.bulletSize` on Timeline.
|
|
13
|
+
*
|
|
14
|
+
* (Card and Paper are NOT in that set — their radius resolves through `var(--vx-radius-card)` in
|
|
15
|
+
* `styles.root`, so the CSS half always covered them. Same for Input/Button/ActionIcon heights, which
|
|
16
|
+
* read `--vx-space-*` through `vars`.)
|
|
17
|
+
*
|
|
18
|
+
* Before this seam existed the sliders moved the CSS-var surfaces (the CSS-module-heavy app sidebar
|
|
19
|
+
* most of all) and left the generic Mantine scales frozen at level 0 — so the tool under-reported its
|
|
20
|
+
* own knobs, unevenly across surfaces, which is precisely the reading a density retune is judged by.
|
|
21
|
+
*
|
|
22
|
+
* `BasaltProvider` therefore rebuilds a real theme through `createBasaltTheme(undefined, { derive,
|
|
23
|
+
* radius, density })` and merges the result over the consumer's theme. The subtlety is the merge
|
|
24
|
+
* DIRECTION. `BasaltProvider`'s contract is `createBasaltTheme(consumerTheme)` — consumer overrides
|
|
25
|
+
* win, last. But the documented mount is `theme={createBasaltTheme()}`, i.e. the consumer hands over
|
|
26
|
+
* a COMPLETE theme carrying every level-0 number; merging that last would clobber the lab's rebuilt
|
|
27
|
+
* numbers right back to level 0 and reproduce the original bug one layer down. So the lab does not
|
|
28
|
+
* merge its whole theme — it merges only its DELTA against the shipped base
|
|
29
|
+
* ({@link themeOverrideDelta}): the fields a given config actually moves, and nothing else. A
|
|
30
|
+
* consumer's `primaryColor: 'teal'` survives untouched; only what the sliders genuinely control is
|
|
31
|
+
* out-cascaded.
|
|
32
|
+
*
|
|
33
|
+
* The delta also carries `other.basaltDerive`/`basaltRadius`/`basaltDensity`, so `BasaltBridge`'s
|
|
34
|
+
* existing injection emits the matching `--vx-*` CSS off the running theme — one path, both halves.
|
|
35
|
+
*
|
|
36
|
+
* DEV-tool path only, twice over: it is compiled out of a production build entirely (see
|
|
37
|
+
* {@link LAB_ENABLED}), and even in a dev build, with the "Apply" switch off — or in any app that
|
|
38
|
+
* never mounts the panel, since the persisted key is written by nothing else —
|
|
39
|
+
* {@link applyLabOverride} returns the consumer theme verbatim.
|
|
40
|
+
*/
|
|
41
|
+
import { mergeThemeOverrides } from '@mantine/core'
|
|
42
|
+
import type { MantineThemeOverride } from '@mantine/core'
|
|
43
|
+
import { useMemo } from 'react'
|
|
44
|
+
import { useDeriveControlsState, toDeriveOverride } from '../theme-lab/derive-state'
|
|
45
|
+
import type { DeriveOverride } from '../theme-lab/derive-state'
|
|
46
|
+
import { baseTheme, createBasaltTheme } from '../theme'
|
|
47
|
+
|
|
48
|
+
type Plain = Record<string, unknown>
|
|
49
|
+
|
|
50
|
+
const isPlainObject = (value: unknown): value is Plain =>
|
|
51
|
+
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Structural equality for theme leaves. Values here are JSON-shaped (numbers, strings, and the
|
|
55
|
+
* 10-stop color tuples), so a serialized compare is both correct and cheaper to read than an
|
|
56
|
+
* element-wise walk.
|
|
57
|
+
*/
|
|
58
|
+
function sameLeaf(a: unknown, b: unknown): boolean {
|
|
59
|
+
if (a === b) return true
|
|
60
|
+
if (a === undefined || b === undefined) return false
|
|
61
|
+
return JSON.stringify(a) === JSON.stringify(b)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function deltaOf(base: Plain, next: Plain): Plain {
|
|
65
|
+
const out: Plain = {}
|
|
66
|
+
for (const [key, nextValue] of Object.entries(next)) {
|
|
67
|
+
// A key `next` explicitly sets to `undefined` configures nothing — emitting it would hand
|
|
68
|
+
// `mergeThemeOverrides` an undefined that clobbers a real consumer value.
|
|
69
|
+
if (nextValue === undefined) continue
|
|
70
|
+
// Functions are rebuilt fresh by every `buildTheme` call (`vars`/`classNames`/`styles`
|
|
71
|
+
// callbacks), so a reference compare would report EVERY one of them as changed and the delta
|
|
72
|
+
// would clobber a consumer's own `vars`/`classNames` overrides for those components. Skipping
|
|
73
|
+
// them is safe because none of them closes over a radius/spacing value — every radius- and
|
|
74
|
+
// density-anchored number in `buildTheme` sits in a plain data position (`theme.radius`,
|
|
75
|
+
// `theme.spacing`, `defaultProps`), which `theme/radius.test.ts` + `theme/spacing.test.ts` lock.
|
|
76
|
+
if (typeof nextValue === 'function') continue
|
|
77
|
+
const baseValue = base[key]
|
|
78
|
+
if (isPlainObject(nextValue) && isPlainObject(baseValue)) {
|
|
79
|
+
const nested = deltaOf(baseValue, nextValue)
|
|
80
|
+
if (Object.keys(nested).length > 0) out[key] = nested
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
if (!sameLeaf(baseValue, nextValue)) out[key] = nextValue
|
|
84
|
+
}
|
|
85
|
+
return out
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The minimal override that carries `base` to `next` — every field `next` sets to something `base`
|
|
90
|
+
* doesn't already say, recursed into nested plain objects (so a single changed `defaultProps` number
|
|
91
|
+
* yields just that one key, not the whole `components` map). Function-valued fields are skipped; see
|
|
92
|
+
* the comment in `deltaOf`.
|
|
93
|
+
*
|
|
94
|
+
* Exported for `lab-theme.test.ts`.
|
|
95
|
+
*/
|
|
96
|
+
export function themeOverrideDelta(
|
|
97
|
+
base: MantineThemeOverride,
|
|
98
|
+
next: MantineThemeOverride,
|
|
99
|
+
): MantineThemeOverride {
|
|
100
|
+
return deltaOf(base as Plain, next as Plain) as MantineThemeOverride
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Resolve the theme `BasaltProvider` hands to `MantineProvider`: the consumer's theme merged onto
|
|
105
|
+
* the Basalt base as always, plus — when a lab override is active — the delta that override makes
|
|
106
|
+
* against the shipped base.
|
|
107
|
+
*
|
|
108
|
+
* Pure and synchronous so `lab-theme.test.ts` can assert the merge result without a DOM.
|
|
109
|
+
*/
|
|
110
|
+
export function applyLabOverride(
|
|
111
|
+
overrides: MantineThemeOverride | undefined,
|
|
112
|
+
override: DeriveOverride | null,
|
|
113
|
+
): MantineThemeOverride {
|
|
114
|
+
const theme = createBasaltTheme(overrides)
|
|
115
|
+
if (override === null) return theme
|
|
116
|
+
const labTheme = createBasaltTheme(undefined, {
|
|
117
|
+
derive: override.config,
|
|
118
|
+
radius: override.radiusLevel,
|
|
119
|
+
density: override.densityLevel,
|
|
120
|
+
})
|
|
121
|
+
// An all-defaults override resolves back to `baseTheme` itself, so the delta is empty and this
|
|
122
|
+
// merge is a no-op — the "Apply" switch on at level 0 changes nothing, as it should.
|
|
123
|
+
return mergeThemeOverrides(theme, themeOverrideDelta(baseTheme, labTheme))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* DEV-build gate. `BasaltProvider` is the mandatory `.` entry, so an unconditional subscription to
|
|
128
|
+
* the lab store would make EVERY production app pay a localStorage read + schema validation on first
|
|
129
|
+
* render and keep a `window` 'storage' listener registered for its whole lifetime — to answer a
|
|
130
|
+
* question ("is the dev lab active?") that is always "no" in an app that never mounts
|
|
131
|
+
* `<DeriveControls>`. Resolved ONCE at module scope, so it also lets a bundler drop
|
|
132
|
+
* `useLabThemeDev` (and with it the `theme-lab/derive-state` import) from a production build.
|
|
133
|
+
*
|
|
134
|
+
* The cost: the lab does nothing in a PRODUCTION BUILD of a playground/dev app. It is a dev tool run
|
|
135
|
+
* through a dev server (`bun run dev`), so that is the right side of the trade — but if you ever
|
|
136
|
+
* preview the playground via `vite build && vite preview`, the sliders will be inert there.
|
|
137
|
+
*/
|
|
138
|
+
const LAB_ENABLED = process.env['NODE_ENV'] !== 'production'
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Dev build: subscribed to the lab store.
|
|
142
|
+
*
|
|
143
|
+
* `state` is a referentially STABLE snapshot — `createPersistedState` caches the parsed value keyed
|
|
144
|
+
* on the raw localStorage string — so it is a sound memo dep, and one write (a slider drag) is
|
|
145
|
+
* exactly one recompute. The memo matters: `createBasaltTheme`'s non-default paths allocate a fresh
|
|
146
|
+
* theme per call, and an unmemoized result would hand `MantineProvider` a new `theme` reference every
|
|
147
|
+
* render and churn every consumer of Mantine's theme context (the reason `createBasaltTheme`'s own
|
|
148
|
+
* JSDoc says to call it at module scope).
|
|
149
|
+
*/
|
|
150
|
+
function useLabThemeDev(overrides: MantineThemeOverride | undefined): MantineThemeOverride {
|
|
151
|
+
const [state] = useDeriveControlsState()
|
|
152
|
+
return useMemo(() => applyLabOverride(overrides, toDeriveOverride(state)), [overrides, state])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Production build: the pre-existing path verbatim — no store, no listener, no extra import. */
|
|
156
|
+
function useLabThemeProd(overrides: MantineThemeOverride | undefined): MantineThemeOverride {
|
|
157
|
+
return useMemo(() => createBasaltTheme(overrides), [overrides])
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* `BasaltProvider`'s theme resolution. Picked at module scope, not per render — both implementations
|
|
162
|
+
* call their hooks unconditionally at their own top level, and which one is bound never changes for
|
|
163
|
+
* the app's lifetime, so the hook order is as stable as a plain function's (a `LAB_ENABLED ? use…()`
|
|
164
|
+
* inline in one function body would be a conditional hook call and a `react/rules-of-hooks` error).
|
|
165
|
+
*/
|
|
166
|
+
export const useLabTheme = LAB_ENABLED ? useLabThemeDev : useLabThemeProd
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
flex-shrink: 0;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
@media (max-width: 47.
|
|
52
|
+
@media (max-width: 47.99375em) {
|
|
53
53
|
.bar {
|
|
54
54
|
flex-wrap: wrap;
|
|
55
55
|
align-content: center;
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
.pageActions {
|
|
68
68
|
order: 3;
|
|
69
69
|
flex-basis: 100%;
|
|
70
|
-
height:
|
|
70
|
+
height: var(--vx-space-app-header-mobile-actions-height);
|
|
71
71
|
justify-content: flex-start;
|
|
72
72
|
}
|
|
73
73
|
}
|