@selfhelp/shared 1.8.0 → 1.10.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 (46) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/{common-B96dASgu.d.mts → common-CJSHQL1E.d.mts} +13 -1
  3. package/dist/{common-B96dASgu.d.ts → common-CJSHQL1E.d.ts} +13 -1
  4. package/dist/index.d.mts +7 -44
  5. package/dist/index.d.ts +7 -44
  6. package/dist/index.js +395 -8
  7. package/dist/index.mjs +371 -8
  8. package/dist/plugin-sdk/index.d.mts +2 -2
  9. package/dist/plugin-sdk/index.d.ts +2 -2
  10. package/dist/plugin-sdk/index.js +10 -1
  11. package/dist/plugin-sdk/index.mjs +10 -1
  12. package/dist/registry/index.d.mts +42 -4
  13. package/dist/registry/index.d.ts +42 -4
  14. package/dist/registry/index.js +56 -3
  15. package/dist/registry/index.mjs +48 -2
  16. package/dist/{styles.registry-ClluRYkN.d.ts → styles.registry-BV1iF7k-.d.ts} +678 -461
  17. package/dist/{styles.registry-nl8uzvMN.d.mts → styles.registry-DkoT-FmN.d.mts} +678 -461
  18. package/dist/theme/index.d.mts +225 -4
  19. package/dist/theme/index.d.ts +225 -4
  20. package/dist/theme/index.js +343 -9
  21. package/dist/theme/index.mjs +325 -8
  22. package/dist/theme/tailwind.d.mts +2 -2
  23. package/dist/theme/tailwind.d.ts +2 -2
  24. package/package.json +1 -1
  25. package/src/registry/__tests__/platform.test.ts +187 -0
  26. package/src/registry/index.ts +73 -0
  27. package/src/registry/styles.registry.ts +60 -0
  28. package/src/theme/__tests__/mantineVariant.test.ts +87 -0
  29. package/src/theme/__tests__/semantic.test.ts +231 -0
  30. package/src/theme/index.ts +2 -0
  31. package/src/theme/mantineVariant.ts +145 -0
  32. package/src/theme/semantic.ts +472 -0
  33. package/src/theme/tailwind.ts +2 -2
  34. package/src/theme/tokens.ts +2 -2
  35. package/src/types/mantine/common.ts +13 -0
  36. package/src/types/styles/auth.ts +11 -11
  37. package/src/types/styles/base.ts +4 -4
  38. package/src/types/styles/composite.ts +59 -45
  39. package/src/types/styles/error.ts +24 -13
  40. package/src/types/styles/forms.ts +184 -184
  41. package/src/types/styles/interactive.ts +81 -76
  42. package/src/types/styles/layout.ts +103 -85
  43. package/src/types/styles/media.ts +20 -20
  44. package/src/types/styles/typography.ts +39 -39
  45. package/src/types/styles/unknown.ts +20 -2
  46. package/src/utils/spacing.ts +1 -1
@@ -34,6 +34,37 @@ SPDX-License-Identifier: MPL-2.0
34
34
 
35
35
  import type { TStyleName } from '../types/styles/unknown';
36
36
 
37
+ /**
38
+ * Concrete render targets a CMS style can support. The web frontend
39
+ * renders `web`; the mobile app renders `mobile`.
40
+ */
41
+ export type TConcretePlatform = 'web' | 'mobile';
42
+
43
+ /**
44
+ * Where a style may be placed in the section tree:
45
+ * - `any` (default) — page root or inside any container.
46
+ * - `rootOnly` — page/root level only (e.g. a page-overlay style).
47
+ * - `containerOnly`— only inside a parent container, never at page root.
48
+ *
49
+ * Distinct from parent/child `rel_styles_allowed_relationships`: placement is a
50
+ * coarse root-vs-container rule the CMS picker enforces in addition to the
51
+ * fine-grained compound parent/child rules.
52
+ */
53
+ export type TStylePlacement = 'any' | 'rootOnly' | 'containerOnly';
54
+
55
+ /**
56
+ * CMS-facing render target of a style. Mirrors the backend
57
+ * `styles.id_render_target` (`styleRenderTargets` lookup) and the
58
+ * `renderTarget` field returned by the style schema/catalog API. `both`
59
+ * expands to `['web','mobile']`. A platform's dispatcher silently skips a
60
+ * style whose render target excludes it — distinct from the
61
+ * "compatible-but-unimplemented" `UnknownStyle` / "Open on web" fallback.
62
+ *
63
+ * Page render target is NOT modelled here: a page's web/mobile/both scope is
64
+ * the existing `pageAccessTypes` value, never a duplicate page platform field.
65
+ */
66
+ export type TStylePlatform = TConcretePlatform | 'both';
67
+
37
68
  export interface IStyleRegistryEntry {
38
69
  /** Human description for docs / tooling. */
39
70
  description: string;
@@ -59,6 +90,25 @@ export interface IStyleRegistryEntry {
59
90
  * children traversal.
60
91
  */
61
92
  canHaveChildren: boolean;
93
+ /**
94
+ * Render targets this style supports (compile-time fallback for the
95
+ * backend `renderTarget`). Omitted = both platforms (`['web','mobile']`),
96
+ * which is the default for every established core style. A mobile-only
97
+ * style sets `['mobile']`; a web-only style sets `['web']`. The renderer
98
+ * reads this through `getStylePlatforms()` / `isStyleSupportedOnPlatform()`
99
+ * and silently skips styles that do not target the current platform.
100
+ *
101
+ * Runtime filtering should prefer the per-section `renderTarget` from the
102
+ * backend payload when present (installed catalog data may differ from the
103
+ * app build); this registry value is the compile-time source of truth.
104
+ */
105
+ platforms?: readonly TConcretePlatform[];
106
+ /**
107
+ * Placement rule in the section tree. Omitted = `any`. The CMS add-section
108
+ * picker hides `rootOnly` styles when adding as a child and `containerOnly`
109
+ * styles when adding at page root.
110
+ */
111
+ placement?: TStylePlacement;
62
112
  }
63
113
 
64
114
  /**
@@ -172,6 +222,16 @@ export const BASE_STYLE_REGISTRY = {
172
222
  'entry-record': { description: 'Single-record container', category: 'composite', frontendOnly: true, canHaveChildren: true },
173
223
  'entry-record-delete': { description: 'Inline delete confirmation for an entry', category: 'composite', frontendOnly: true, canHaveChildren: false },
174
224
  loop: { description: 'Loop / repeater over backend-provided rows', category: 'composite', frontendOnly: true, canHaveChildren: true },
225
+ 'timeline-item': { description: 'A single entry inside a timeline (child-only)', category: 'composite', frontendOnly: true, canHaveChildren: true },
226
+
227
+ // ===== system / data / reference (established backend catalog) =====
228
+ 'no-access': { description: 'Access-denied surface shown when the user lacks page access', category: 'auth', frontendOnly: true, canHaveChildren: false },
229
+ missing: { description: 'Generic "content missing" system surface', category: 'auth', frontendOnly: true, canHaveChildren: false },
230
+ 'not-found': { description: 'Page-not-found system surface', category: 'auth', frontendOnly: true, canHaveChildren: false },
231
+ version: { description: 'Build/version diagnostic surface', category: 'auth', frontendOnly: true, canHaveChildren: false },
232
+ 'ref-container': { description: 'Renders content referenced from another section', category: 'layout', frontendOnly: true, canHaveChildren: true },
233
+ 'data-container': { description: 'Data-scoped container (renders subtree against a data scope)', category: 'layout', frontendOnly: true, canHaveChildren: true },
234
+ 'show-user-input': { description: 'Displays previously submitted user input as a list/card view', category: 'forms', frontendOnly: true, canHaveChildren: false },
175
235
  } as const satisfies Record<string, IStyleRegistryEntry>;
176
236
 
177
237
  /**
@@ -0,0 +1,87 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+ import { resolveMantineVariant } from '../mantineVariant';
7
+ import { COLOR_PALETTE, COLOR_SCALES } from '../tokens';
8
+
9
+ /**
10
+ * The Mantine palette resolver is the single cross-repo source of truth for
11
+ * `web_color` + `web_variant` -> concrete RGB (consumed by the mobile Expo Web
12
+ * preview fallback). Every variant branch is pinned so a regression surfaces
13
+ * immediately and neither repo re-implements the ladder.
14
+ */
15
+ describe('resolveMantineVariant', () => {
16
+ const red = COLOR_SCALES.red;
17
+
18
+ it('filled uses the accent as background with white foreground', () => {
19
+ const v = resolveMantineVariant('filled', 'red');
20
+ expect(v.background).toBe(COLOR_PALETTE.red);
21
+ expect(v.foreground).toBe('#ffffff');
22
+ expect(v.borderWidth).toBe(0);
23
+ });
24
+
25
+ it('gradient collapses onto filled', () => {
26
+ expect(resolveMantineVariant('gradient', 'red')).toEqual(
27
+ resolveMantineVariant('filled', 'red'),
28
+ );
29
+ });
30
+
31
+ it('light uses soft fill + dark palette text, no border', () => {
32
+ const v = resolveMantineVariant('light', 'red');
33
+ expect(v.background).toBe(red[0]);
34
+ expect(v.foreground).toBe(red[8]);
35
+ expect(v.border).toBe('transparent');
36
+ });
37
+
38
+ it('outline is transparent with a palette border', () => {
39
+ const v = resolveMantineVariant('outline', 'red');
40
+ expect(v.background).toBe('transparent');
41
+ expect(v.border).toBe(red[6]);
42
+ expect(v.borderWidth).toBe(1);
43
+ });
44
+
45
+ it('default is the neutral white/gray surface', () => {
46
+ const v = resolveMantineVariant('default', 'red');
47
+ expect(v.background).toBe('#ffffff');
48
+ expect(v.border).toBe('#dee2e6');
49
+ expect(v.borderWidth).toBe(1);
50
+ });
51
+
52
+ it('subtle and transparent have no border; transparent has no pressed surface', () => {
53
+ const subtle = resolveMantineVariant('subtle', 'red');
54
+ const transparent = resolveMantineVariant('transparent', 'red');
55
+ expect(subtle.background).toBe('transparent');
56
+ expect(subtle.pressedBackground).toBe(red[0]);
57
+ expect(transparent.pressedBackground).toBe('transparent');
58
+ });
59
+
60
+ it('dot keeps a neutral bordered chip surface', () => {
61
+ const v = resolveMantineVariant('dot', 'red');
62
+ expect(v.background).toBe('transparent');
63
+ expect(v.borderWidth).toBe(1);
64
+ });
65
+
66
+ it('defaults variant to filled and color to blue when omitted', () => {
67
+ const v = resolveMantineVariant(undefined, undefined);
68
+ expect(v.background).toBe(COLOR_PALETTE.blue);
69
+ expect(v.foreground).toBe('#ffffff');
70
+ });
71
+
72
+ it('falls back to the blue scale for an unknown color', () => {
73
+ const unknown = resolveMantineVariant('light', 'not-a-color');
74
+ const blue = resolveMantineVariant('light', 'blue');
75
+ expect(unknown.background).toBe(blue.background);
76
+ });
77
+
78
+ it('covers every variant without throwing', () => {
79
+ for (const variant of [
80
+ 'filled', 'light', 'outline', 'default', 'subtle', 'transparent', 'gradient', 'dot',
81
+ ]) {
82
+ const v = resolveMantineVariant(variant, 'green');
83
+ expect(typeof v.background).toBe('string');
84
+ expect(typeof v.foreground).toBe('string');
85
+ }
86
+ });
87
+ });
@@ -0,0 +1,231 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ import { describe, expect, it } from 'vitest';
6
+ import {
7
+ FULL_RADIUS_PX,
8
+ mapIntentToHeroUiButtonVariant,
9
+ mapIntentToHeroUiColor,
10
+ mapIntentToMantine,
11
+ mapRadiusToMantine,
12
+ mapRadiusToPx,
13
+ mapSizeToHeroUi,
14
+ mapSizeToMantine,
15
+ mapSpacingToPx,
16
+ resolveSharedStyle,
17
+ resolveSharedStyleProps,
18
+ toHeroUiSemanticProps,
19
+ toMantineSemanticProps,
20
+ toReactNativeSemanticStyle,
21
+ type TSemanticIntent,
22
+ type TSemanticSize,
23
+ } from '../semantic';
24
+ import { RADIUS_PX, SPACING_PX } from '../tokens';
25
+
26
+ /**
27
+ * The semantic mapper is the single source of truth that turns CMS
28
+ * cross-platform (`shared_*`) values into per-platform props. Per the mobile
29
+ * rendering plan (section 8.2) it does NOT clamp: the shared scales
30
+ * (`size` = sm|md|lg, `radius` = none|sm|md|lg|full) are the true common
31
+ * denominator, so every value maps 1:1 to both platforms. Every mapping is
32
+ * pinned here so a regression surfaces immediately on web and mobile.
33
+ */
34
+ describe('semantic style mapper', () => {
35
+ describe('size (sm|md|lg, no clamp)', () => {
36
+ it('passes sm|md|lg through unchanged on Mantine (web)', () => {
37
+ for (const s of ['sm', 'md', 'lg'] as TSemanticSize[]) {
38
+ expect(mapSizeToMantine(s)).toBe(s);
39
+ }
40
+ });
41
+
42
+ it('maps sm|md|lg 1:1 onto HeroUI (no clamp)', () => {
43
+ expect(mapSizeToHeroUi('sm')).toBe('sm');
44
+ expect(mapSizeToHeroUi('md')).toBe('md');
45
+ expect(mapSizeToHeroUi('lg')).toBe('lg');
46
+ expect(mapSizeToHeroUi(undefined)).toBeUndefined();
47
+ });
48
+ });
49
+
50
+ describe('radius (none|sm|md|lg|full)', () => {
51
+ it('resolves to px for mobile (none=0, full=pill, tokens via RADIUS_PX)', () => {
52
+ expect(mapRadiusToPx('none')).toBe(0);
53
+ expect(mapRadiusToPx('full')).toBe(FULL_RADIUS_PX);
54
+ expect(mapRadiusToPx('sm')).toBe(RADIUS_PX.sm);
55
+ expect(mapRadiusToPx('md')).toBe(RADIUS_PX.md);
56
+ expect(mapRadiusToPx('lg')).toBe(RADIUS_PX.lg);
57
+ expect(mapRadiusToPx(undefined)).toBeUndefined();
58
+ });
59
+
60
+ it('resolves to token/number for Mantine (web)', () => {
61
+ expect(mapRadiusToMantine('sm')).toBe('sm');
62
+ expect(mapRadiusToMantine('md')).toBe('md');
63
+ expect(mapRadiusToMantine('lg')).toBe('lg');
64
+ expect(mapRadiusToMantine('none')).toBe(0);
65
+ expect(mapRadiusToMantine('full')).toBe(FULL_RADIUS_PX);
66
+ });
67
+ });
68
+
69
+ describe('spacing', () => {
70
+ it('resolves tokens to px (none=0)', () => {
71
+ expect(mapSpacingToPx('none')).toBe(0);
72
+ expect(mapSpacingToPx('md')).toBe(SPACING_PX.md);
73
+ expect(mapSpacingToPx('xl')).toBe(SPACING_PX.xl);
74
+ expect(mapSpacingToPx(undefined)).toBeUndefined();
75
+ });
76
+ });
77
+
78
+ describe('intent', () => {
79
+ it('maps to Mantine color + variant', () => {
80
+ expect(mapIntentToMantine('primary')).toEqual({ color: 'blue', variant: 'filled' });
81
+ expect(mapIntentToMantine('secondary')).toEqual({ color: 'gray', variant: 'light' });
82
+ expect(mapIntentToMantine('success')).toEqual({ color: 'green', variant: 'filled' });
83
+ expect(mapIntentToMantine('warning')).toEqual({ color: 'yellow', variant: 'filled' });
84
+ expect(mapIntentToMantine('danger')).toEqual({ color: 'red', variant: 'filled' });
85
+ expect(mapIntentToMantine('neutral')).toEqual({ color: 'gray', variant: 'default' });
86
+ });
87
+
88
+ it('maps intent to a HeroUI button variant (status color carried separately)', () => {
89
+ expect(mapIntentToHeroUiButtonVariant('primary')).toBe('primary');
90
+ expect(mapIntentToHeroUiButtonVariant('secondary')).toBe('secondary');
91
+ expect(mapIntentToHeroUiButtonVariant('danger')).toBe('danger');
92
+ // HeroUI has no success/warning BUTTON variant; the status colour is
93
+ // carried by mapIntentToHeroUiColor, the button stays prominent.
94
+ expect(mapIntentToHeroUiButtonVariant('success')).toBe('primary');
95
+ expect(mapIntentToHeroUiButtonVariant('warning')).toBe('primary');
96
+ expect(mapIntentToHeroUiButtonVariant('neutral')).toBe('secondary');
97
+ });
98
+
99
+ it('maps to HeroUI semantic color preserving success/warning', () => {
100
+ expect(mapIntentToHeroUiColor('primary')).toBe('accent');
101
+ expect(mapIntentToHeroUiColor('secondary')).toBe('default');
102
+ expect(mapIntentToHeroUiColor('success')).toBe('success');
103
+ expect(mapIntentToHeroUiColor('warning')).toBe('warning');
104
+ expect(mapIntentToHeroUiColor('danger')).toBe('danger');
105
+ expect(mapIntentToHeroUiColor('neutral')).toBe('default');
106
+ });
107
+ });
108
+
109
+ describe('resolveSharedStyleProps (read CMS fields)', () => {
110
+ it('reads valid shared_* values', () => {
111
+ expect(
112
+ resolveSharedStyleProps({
113
+ shared_size: 'lg',
114
+ shared_radius: 'full',
115
+ shared_intent: 'danger',
116
+ shared_full_width: '1',
117
+ }),
118
+ ).toEqual({ size: 'lg', radius: 'full', intent: 'danger', fullWidth: true });
119
+ });
120
+
121
+ it('ignores out-of-domain values instead of clamping them', () => {
122
+ // Stale Mantine values (xs/xl) are NOT mapped; the renderer falls
123
+ // through to its component default rather than silently clamping.
124
+ const resolved = resolveSharedStyleProps({
125
+ shared_size: 'xl',
126
+ shared_radius: 'xs',
127
+ shared_intent: 'bogus',
128
+ });
129
+ expect(resolved.size).toBeUndefined();
130
+ expect(resolved.radius).toBeUndefined();
131
+ expect(resolved.intent).toBeUndefined();
132
+ });
133
+
134
+ it('coerces shared_full_width booleans', () => {
135
+ expect(resolveSharedStyleProps({ shared_full_width: '0' }).fullWidth).toBe(false);
136
+ expect(resolveSharedStyleProps({ shared_full_width: true }).fullWidth).toBe(true);
137
+ expect(resolveSharedStyleProps({}).fullWidth).toBeUndefined();
138
+ });
139
+ });
140
+
141
+ describe('platform resolvers', () => {
142
+ it('resolves a danger / lg / full / fullWidth control consistently (no clamp)', () => {
143
+ const props = {
144
+ intent: 'danger' as const,
145
+ size: 'lg' as const,
146
+ radius: 'full' as const,
147
+ spacing: 'md' as const,
148
+ states: ['disabled', 'required'] as const,
149
+ fullWidth: true,
150
+ };
151
+
152
+ expect(toMantineSemanticProps(props)).toMatchObject({
153
+ size: 'lg',
154
+ color: 'red',
155
+ variant: 'filled',
156
+ radius: FULL_RADIUS_PX,
157
+ spacing: 'md',
158
+ disabled: true,
159
+ required: true,
160
+ fullWidth: true,
161
+ });
162
+
163
+ expect(toHeroUiSemanticProps(props)).toMatchObject({
164
+ size: 'lg', // 1:1, not clamped
165
+ buttonVariant: 'danger',
166
+ color: 'danger',
167
+ radiusPx: FULL_RADIUS_PX,
168
+ spacingPx: SPACING_PX.md,
169
+ isDisabled: true,
170
+ isRequired: true,
171
+ fullWidth: true,
172
+ });
173
+ });
174
+
175
+ it('resolveSharedStyle returns both platform shapes', () => {
176
+ const { web, mobile } = resolveSharedStyle({ size: 'md', intent: 'primary' });
177
+ expect(web.size).toBe('md');
178
+ expect(web.color).toBe('blue');
179
+ expect(mobile.size).toBe('md');
180
+ expect(mobile.buttonVariant).toBe('primary');
181
+ });
182
+
183
+ it('leaves unset values undefined on both platforms', () => {
184
+ const { web, mobile } = resolveSharedStyle({});
185
+ expect(web.color).toBeUndefined();
186
+ expect(web.disabled).toBeUndefined();
187
+ expect(mobile.buttonVariant).toBeUndefined();
188
+ expect(mobile.isDisabled).toBeUndefined();
189
+ });
190
+
191
+ it('covers every intent without throwing', () => {
192
+ for (const intent of ['primary', 'secondary', 'success', 'warning', 'danger', 'neutral'] as TSemanticIntent[]) {
193
+ const { web, mobile } = resolveSharedStyle({ intent });
194
+ expect(web.color).toBeDefined();
195
+ expect(mobile.color).toBeDefined();
196
+ expect(mobile.buttonVariant).toBeDefined();
197
+ }
198
+ });
199
+ });
200
+
201
+ describe('toReactNativeSemanticStyle', () => {
202
+ it('derives a plain RN style from shared props', () => {
203
+ expect(
204
+ toReactNativeSemanticStyle({ radius: 'md', spacing: 'lg', fullWidth: true }),
205
+ ).toEqual({
206
+ borderRadius: RADIUS_PX.md,
207
+ padding: SPACING_PX.lg,
208
+ alignSelf: 'stretch',
209
+ width: '100%',
210
+ });
211
+ });
212
+
213
+ it('honours none/full radius edge values', () => {
214
+ expect(toReactNativeSemanticStyle({ radius: 'none' }).borderRadius).toBe(0);
215
+ expect(toReactNativeSemanticStyle({ radius: 'full' }).borderRadius).toBe(FULL_RADIUS_PX);
216
+ });
217
+
218
+ it('applies theme scale overrides without an implicit default fallback', () => {
219
+ const style = toReactNativeSemanticStyle(
220
+ { radius: 'md', spacing: 'md' },
221
+ { radiusPx: { md: 99 }, spacingPx: { md: 7 } },
222
+ );
223
+ expect(style.borderRadius).toBe(99);
224
+ expect(style.padding).toBe(7);
225
+ });
226
+
227
+ it('returns an empty object for empty props', () => {
228
+ expect(toReactNativeSemanticStyle({})).toEqual({});
229
+ });
230
+ });
231
+ });
@@ -4,3 +4,5 @@ SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  export * from './tokens';
6
6
  export * from './tailwind';
7
+ export * from './semantic';
8
+ export * from './mantineVariant';
@@ -0,0 +1,145 @@
1
+ /*
2
+ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
+ SPDX-License-Identifier: MPL-2.0
4
+ */
5
+ /**
6
+ * Mantine `variant + color` -> resolved concrete colors.
7
+ *
8
+ * This is the single, cross-repo source of truth for turning a Mantine
9
+ * palette `color` + `variant` pair into concrete background / foreground /
10
+ * border values. It lives in `@selfhelp/shared` so neither the web frontend
11
+ * nor the mobile app re-implements the variant ladder.
12
+ *
13
+ * SCOPE — this is NOT the semantic mapper (`semantic.ts`). The two have
14
+ * different input domains and both live here so there is exactly one home
15
+ * for style mapping:
16
+ * - `semantic.ts` maps renderer-agnostic shared fields
17
+ * (`intent` / `size` / `radius` / `spacing`) per platform.
18
+ * - `mantineVariant.ts` resolves the web-specific `web_color` / `web_variant`
19
+ * Mantine palette into concrete RGB. Its only runtime
20
+ * consumer today is the mobile **Expo Web preview**
21
+ * fallback (where `heroui-native` cannot render and the
22
+ * renderer reproduces the Mantine look); the web
23
+ * frontend uses Mantine components directly.
24
+ *
25
+ * Mantine offers six interactive variants:
26
+ * - filled solid fill, white text
27
+ * - light soft fill (color-0 / color-1), color-8 text
28
+ * - outline transparent bg, color-6 border + text
29
+ * - default white bg, gray border, gray-9 text (the "neutral" one)
30
+ * - subtle transparent bg, color-7 text, hover bg color-0
31
+ * - transparent transparent bg, color-7 text, no hover surface
32
+ *
33
+ * `gradient` and `dot` (used by Alert/Card/Badge) collapse onto
34
+ * `filled` / `dot` here so the surface stays tight and consistent.
35
+ */
36
+
37
+ import { COLOR_PALETTE, COLOR_SCALES, type TCanonicalColor } from './tokens';
38
+
39
+ /**
40
+ * Variant keys this resolver understands. Superset of the canonical
41
+ * `TMantineVariant` (it adds `dot`, used by Alert/Badge); kept internal so it
42
+ * never collides with the exported `TMantineVariant` from `types/mantine`.
43
+ */
44
+ type TMantineVariantKey =
45
+ | 'filled'
46
+ | 'light'
47
+ | 'outline'
48
+ | 'default'
49
+ | 'subtle'
50
+ | 'transparent'
51
+ | 'gradient'
52
+ | 'dot';
53
+
54
+ export interface IResolvedVariant {
55
+ background: string;
56
+ foreground: string;
57
+ border: string;
58
+ borderWidth: number;
59
+ pressedBackground: string;
60
+ accent: string;
61
+ }
62
+
63
+ const TRANSPARENT = 'transparent';
64
+
65
+ function scale(color: string | undefined): readonly string[] {
66
+ if (!color) return COLOR_SCALES.blue;
67
+ return COLOR_SCALES[color as TCanonicalColor] ?? COLOR_SCALES.blue;
68
+ }
69
+
70
+ export function resolveMantineVariant(
71
+ variant: string | undefined,
72
+ color: string | undefined,
73
+ ): IResolvedVariant {
74
+ const palette = scale(color);
75
+ const accent = COLOR_PALETTE[color as TCanonicalColor] ?? palette[6] ?? '#228be6';
76
+ const v = (variant ?? 'filled') as TMantineVariantKey;
77
+
78
+ switch (v) {
79
+ case 'light':
80
+ return {
81
+ background: palette[0],
82
+ foreground: palette[8],
83
+ border: TRANSPARENT,
84
+ borderWidth: 0,
85
+ pressedBackground: palette[1],
86
+ accent,
87
+ };
88
+ case 'outline':
89
+ return {
90
+ background: TRANSPARENT,
91
+ foreground: palette[7],
92
+ border: palette[6],
93
+ borderWidth: 1,
94
+ pressedBackground: palette[0],
95
+ accent,
96
+ };
97
+ case 'default':
98
+ return {
99
+ background: '#ffffff',
100
+ foreground: '#212529',
101
+ border: '#dee2e6',
102
+ borderWidth: 1,
103
+ pressedBackground: '#f1f3f5',
104
+ accent,
105
+ };
106
+ case 'subtle':
107
+ return {
108
+ background: TRANSPARENT,
109
+ foreground: palette[7],
110
+ border: TRANSPARENT,
111
+ borderWidth: 0,
112
+ pressedBackground: palette[0],
113
+ accent,
114
+ };
115
+ case 'transparent':
116
+ return {
117
+ background: TRANSPARENT,
118
+ foreground: palette[7],
119
+ border: TRANSPARENT,
120
+ borderWidth: 0,
121
+ pressedBackground: TRANSPARENT,
122
+ accent,
123
+ };
124
+ case 'dot':
125
+ return {
126
+ background: TRANSPARENT,
127
+ foreground: palette[7],
128
+ border: '#dee2e6',
129
+ borderWidth: 1,
130
+ pressedBackground: '#f8f9fa',
131
+ accent,
132
+ };
133
+ case 'filled':
134
+ case 'gradient':
135
+ default:
136
+ return {
137
+ background: accent,
138
+ foreground: '#ffffff',
139
+ border: TRANSPARENT,
140
+ borderWidth: 0,
141
+ pressedBackground: palette[7] ?? accent,
142
+ accent,
143
+ };
144
+ }
145
+ }