@selfhelp/shared 1.14.4 → 1.14.7

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.
@@ -28,7 +28,7 @@ SPDX-License-Identifier: MPL-2.0
28
28
  */
29
29
 
30
30
  import { RADIUS_PX, SPACING_PX, type TCanonicalSpacing } from './tokens';
31
- import type { TSharedRadius, TSharedSize } from '../types/mantine/common';
31
+ import type { TMantineColor, TMantineVariant, TSharedRadius, TSharedSize } from '../types/mantine/common';
32
32
 
33
33
  // ===== shared semantic scales (what the CMS stores) =====
34
34
 
@@ -46,6 +46,18 @@ export type TSemanticIntent =
46
46
  | 'neutral';
47
47
  export type TSemanticState = 'disabled' | 'loading' | 'invalid' | 'required';
48
48
 
49
+ /**
50
+ * Cross-platform colour + variant authored in the CMS (`shared_color` /
51
+ * `shared_variant`). These are stored as Mantine palette / variant *values* —
52
+ * the catalog keeps them verbatim (migration `Version20260618143216` renamed the
53
+ * legacy `mantine_*` fields to `shared_*` without touching the values). They are
54
+ * the REAL cross-platform appearance fields (there is no `shared_intent` in the
55
+ * live catalog); the mapper maps them onto HeroUI Native for mobile, while the
56
+ * web renderer feeds them straight into Mantine.
57
+ */
58
+ export type TSemanticColor = TMantineColor;
59
+ export type TSemanticVariant = TMantineVariant;
60
+
49
61
  /** Pixel value used for a fully-rounded ("pill") radius on both platforms. */
50
62
  export const FULL_RADIUS_PX = 9999;
51
63
 
@@ -69,6 +81,15 @@ export interface ISharedStyleProps {
69
81
  size?: TSemanticSize;
70
82
  spacing?: TSemanticSpacing;
71
83
  radius?: TSemanticRadius;
84
+ /** Mantine palette colour authored via `shared_color` (cross-platform). */
85
+ color?: TSemanticColor;
86
+ /** Mantine variant authored via `shared_variant` (cross-platform). */
87
+ variant?: TSemanticVariant;
88
+ /**
89
+ * Legacy semantic intent. Kept for back-compat; `shared_intent` is NOT in the
90
+ * live catalog, so real CMS sections drive appearance through `color` /
91
+ * `variant` above. Used as the final fallback in the platform resolvers.
92
+ */
72
93
  intent?: TSemanticIntent;
73
94
  /** Active boolean states. Stored as a small set so multiple can apply. */
74
95
  states?: readonly TSemanticState[];
@@ -325,6 +346,93 @@ export function mapIntentToHeroUiColor(
325
346
  }
326
347
  }
327
348
 
349
+ // ===== color / variant (the REAL cross-platform appearance fields) =====
350
+
351
+ /**
352
+ * Map a Mantine palette colour (`shared_color`) onto a HeroUI Native semantic
353
+ * colour (Chip / Tag / status surfaces). The Mantine palette is broad; it
354
+ * collapses onto HeroUI's five semantic colours by hue family:
355
+ * red/pink -> danger
356
+ * green/teal/lime -> success
357
+ * yellow/orange -> warning
358
+ * gray/dark -> default
359
+ * blue/cyan/indigo/… -> accent (the brand/primary hue)
360
+ */
361
+ export function mapMantineColorToHeroUiColor(
362
+ color: TSemanticColor | undefined,
363
+ ): THeroUiColor | undefined {
364
+ if (!color) return undefined;
365
+ switch (color) {
366
+ case 'red':
367
+ case 'pink':
368
+ return 'danger';
369
+ case 'green':
370
+ case 'teal':
371
+ case 'lime':
372
+ return 'success';
373
+ case 'yellow':
374
+ case 'orange':
375
+ return 'warning';
376
+ case 'gray':
377
+ case 'dark':
378
+ return 'default';
379
+ default:
380
+ return 'accent';
381
+ }
382
+ }
383
+
384
+ /**
385
+ * Map a Mantine palette colour (`shared_color`) onto a HeroUI Native **Button**
386
+ * variant when no explicit `shared_variant` is authored. HeroUI buttons encode
387
+ * colour in the variant, so the destructive hue becomes `danger`, neutral hues
388
+ * become `secondary`, and everything else stays the prominent `primary`.
389
+ */
390
+ export function mapMantineColorToHeroUiButtonVariant(
391
+ color: TSemanticColor | undefined,
392
+ ): THeroUiButtonVariant | undefined {
393
+ if (!color) return undefined;
394
+ switch (color) {
395
+ case 'red':
396
+ case 'pink':
397
+ return 'danger';
398
+ case 'gray':
399
+ case 'dark':
400
+ return 'secondary';
401
+ default:
402
+ return 'primary';
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Map a Mantine variant (`shared_variant`) onto the HeroUI Native Button
408
+ * vocabulary:
409
+ * filled / gradient -> primary
410
+ * light / white / default -> secondary
411
+ * outline -> outline
412
+ * subtle / transparent -> ghost
413
+ */
414
+ export function mapMantineVariantToHeroUiButtonVariant(
415
+ variant: TSemanticVariant | undefined,
416
+ ): THeroUiButtonVariant | undefined {
417
+ if (!variant) return undefined;
418
+ switch (variant) {
419
+ case 'filled':
420
+ case 'gradient':
421
+ return 'primary';
422
+ case 'light':
423
+ case 'white':
424
+ case 'default':
425
+ return 'secondary';
426
+ case 'outline':
427
+ return 'outline';
428
+ case 'subtle':
429
+ case 'transparent':
430
+ return 'ghost';
431
+ default:
432
+ return undefined;
433
+ }
434
+ }
435
+
328
436
  // ===== state helpers =====
329
437
 
330
438
  function hasState(states: readonly TSemanticState[] | undefined, state: TSemanticState): boolean {
@@ -366,6 +474,22 @@ export function resolveSharedStyleProps(fields: Record<string, unknown>): IShare
366
474
  resolved.radius = radius as TSemanticRadius;
367
475
  }
368
476
 
477
+ // `shared_color` / `shared_variant` are the REAL cross-platform appearance
478
+ // fields (Mantine palette/variant values stored verbatim). Read them
479
+ // open-domain — the palette is intentionally broad and platform mappers
480
+ // collapse it; an unknown value simply falls through to a renderer default.
481
+ const color = readString(fields.shared_color);
482
+ if (color !== undefined) {
483
+ resolved.color = color;
484
+ }
485
+
486
+ const variant = readString(fields.shared_variant);
487
+ if (variant !== undefined) {
488
+ resolved.variant = variant as TSemanticVariant;
489
+ }
490
+
491
+ // Legacy: `shared_intent` is not in the live catalog, but keep reading it so
492
+ // any forward-compat seed still resolves. Domain-checked like size/radius.
369
493
  const intent = readString(fields.shared_intent);
370
494
  if (intent !== undefined && (SEMANTIC_INTENTS as readonly string[]).includes(intent)) {
371
495
  resolved.intent = intent as TSemanticIntent;
@@ -399,12 +523,26 @@ export function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolv
399
523
  };
400
524
  }
401
525
 
402
- /** Resolve shared props into HeroUI Native (mobile) props. */
526
+ /**
527
+ * Resolve shared props into HeroUI Native (mobile) props.
528
+ *
529
+ * Appearance precedence (mirrors the web renderer, which reads the same CMS
530
+ * fields straight into Mantine):
531
+ * 1. `shared_variant` (Mantine variant) mapped onto the HeroUI button vocab;
532
+ * 2. else `shared_color` (Mantine palette) mapped onto a button variant;
533
+ * 3. else the legacy `intent` mapping (back-compat fallback).
534
+ * The semantic `color` is resolved from `shared_color` first, then `intent`.
535
+ */
403
536
  export function toHeroUiSemanticProps(props: ISharedStyleProps): IHeroUiResolvedStyle {
537
+ const buttonVariant =
538
+ mapMantineVariantToHeroUiButtonVariant(props.variant) ??
539
+ mapMantineColorToHeroUiButtonVariant(props.color) ??
540
+ mapIntentToHeroUiButtonVariant(props.intent);
541
+ const color = mapMantineColorToHeroUiColor(props.color) ?? mapIntentToHeroUiColor(props.intent);
404
542
  return {
405
543
  size: mapSizeToHeroUi(props.size),
406
- buttonVariant: mapIntentToHeroUiButtonVariant(props.intent),
407
- color: mapIntentToHeroUiColor(props.intent),
544
+ buttonVariant,
545
+ color,
408
546
  radiusPx: mapRadiusToPx(props.radius),
409
547
  spacingPx: mapSpacingToPx(props.spacing),
410
548
  isDisabled: hasState(props.states, 'disabled') || undefined,
@@ -56,6 +56,15 @@ const _exhaustiveBackward: ContractKey = '' as ListedKey;
56
56
  void _exhaustiveForward;
57
57
  void _exhaustiveBackward;
58
58
 
59
+ /**
60
+ * Compile-time lock for the authored-colour button passthrough: `MobileButton`
61
+ * accepts an optional `accentColor` (resolved hex) so a CMS style can colour the
62
+ * button for cross-platform parity (e.g. `login`'s `shared_color`). If the prop
63
+ * is removed or retyped, this assignment fails to type-check.
64
+ */
65
+ const _buttonAcceptsAccentColor: IMobileButtonProps = { accentColor: '#fab005' };
66
+ void _buttonAcceptsAccentColor;
67
+
59
68
  describe('mobile UI adapter contract', () => {
60
69
  it('exposes exactly the milestone-one capability set', () => {
61
70
  // A trivial component every capability key can hold; proves a complete
@@ -45,6 +45,16 @@ export interface IMobileButtonProps extends IMobileAdapterBaseProps {
45
45
  isLoading?: boolean;
46
46
  isIconOnly?: boolean;
47
47
  fullWidth?: boolean;
48
+ /**
49
+ * Optional concrete background colour (resolved hex) that overrides the
50
+ * variant's themed fill, used for cross-platform parity when a CMS style
51
+ * exposes an authored colour (e.g. `login`'s `shared_color`, which Mantine
52
+ * applies to the web button via `color`). The adapter keeps the variant's
53
+ * readable foreground (white on a filled button). Leave undefined to use the
54
+ * variant's default themed colour. Resolve it through the shared mapper
55
+ * (`resolveMantineVariant(...).accent`), never a hard-coded hex in a renderer.
56
+ */
57
+ accentColor?: string;
48
58
  children?: ReactNode;
49
59
  }
50
60
 
@@ -3,7 +3,7 @@ SPDX-FileCopyrightText: 2026 Humdek, University of Bern
3
3
  SPDX-License-Identifier: MPL-2.0
4
4
  */
5
5
  import type { IContentField, IStyleWithSpacing } from './base';
6
- import type { TMantineRadius } from '../mantine/common';
6
+ import type { TMantineColor, TMantineRadius } from '../mantine/common';
7
7
 
8
8
  export interface ILoginStyle extends IStyleWithSpacing {
9
9
  style_name: 'login';
@@ -13,6 +13,10 @@ export interface ILoginStyle extends IStyleWithSpacing {
13
13
  label_pw_reset?: IContentField<string>;
14
14
  alert_fail?: IContentField<string>;
15
15
  login_title?: IContentField<string>;
16
+ /** Optional subtitle under the title; hidden when empty. */
17
+ subtitle?: IContentField<string>;
18
+ /** Submit-button colour (cross-platform, via the shared mapper). */
19
+ shared_color?: IContentField<TMantineColor>;
16
20
  /** Label of the link that opens the registration page. */
17
21
  label_register?: IContentField<string>;
18
22
  }
@@ -18,7 +18,7 @@ import type { TMantineIconSize } from './typography';
18
18
 
19
19
  export interface IButtonStyle extends IStyleWithSpacing {
20
20
  style_name: 'button';
21
- web_variant?: IContentField<TMantineVariant>;
21
+ shared_variant?: IContentField<TMantineVariant>;
22
22
  shared_color?: IContentField<TMantineColor>;
23
23
  shared_size?: IContentField<TSharedSize>;
24
24
  shared_radius?: IContentField<TSharedRadius>;
@@ -60,31 +60,43 @@ export interface IActionIconStyle extends IStyleWithSpacing {
60
60
 
61
61
  export interface IAlertStyle extends IStyleWithSpacing {
62
62
  style_name: 'alert';
63
- alert_title?: IContentField<string>; web_variant?: IContentField<TMantineVariant>;
63
+ alert_title?: IContentField<string>;
64
+ web_variant?: IContentField<TMantineVariant>;
64
65
  shared_color?: IContentField<TMantineColor>;
65
66
  shared_radius?: IContentField<TSharedRadius>;
66
67
  web_left_icon?: IContentField<string>;
67
- web_with_close_button?: IContentField<string>;
68
- content?: IContentField<string>;}
68
+ /** Cross-platform dismiss toggle (was the web-only `web_with_close_button`). */
69
+ closable?: IContentField<string>;
70
+ content?: IContentField<string>;
71
+ }
69
72
 
70
73
  export interface IBadgeStyle extends IStyleWithSpacing {
71
74
  style_name: 'badge';
72
75
  label?: IContentField<string>;
76
+ /** Cross-platform variant (web Mantine + mobile HeroUI). Primary control. */
77
+ shared_variant?: IContentField<TMantineBadgeVariant>;
78
+ /** Web-only variant override (e.g. `dot`); empty falls back to shared_variant. */
73
79
  web_variant?: IContentField<TMantineBadgeVariant>;
80
+ /** Render as a circle (equal width/height) for short counts. */
81
+ circle?: IContentField<string>;
74
82
  shared_size?: IContentField<TSharedSize>;
75
83
  web_left_icon?: IContentField<string>;
76
84
  shared_radius?: IContentField<TSharedRadius>;
77
- shared_color?: IContentField<TMantineColor>; web_right_icon?: IContentField<string>;
85
+ shared_color?: IContentField<TMantineColor>;
86
+ web_right_icon?: IContentField<string>;
78
87
  web_auto_contrast?: IContentField<string>;
79
88
  }
80
89
 
81
90
  export interface IAvatarStyle extends IStyleWithSpacing {
82
91
  style_name: 'avatar';
83
92
  alt?: IContentField<string>;
84
- web_avatar_variant?: IContentField<TMantineAvatarVariant>;
93
+ /** Person name; seeds auto-initials + a stable auto colour when no image. */
94
+ name?: IContentField<string>;
95
+ web_variant?: IContentField<TMantineAvatarVariant>;
85
96
  shared_size?: IContentField<TSharedSize>;
86
97
  shared_radius?: IContentField<TSharedRadius>;
87
- shared_color?: IContentField<TMantineColor>; web_left_icon?: IContentField<string>;
98
+ shared_color?: IContentField<TMantineColor>;
99
+ web_left_icon?: IContentField<string>;
88
100
  web_avatar_initials?: IContentField<string>;
89
101
  img_src?: IContentField<string>;
90
102
  }