@selfhelp/shared 1.14.20 → 1.14.24
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/CHANGELOG.md +109 -0
- package/dist/{common-DMm4kymA.d.mts → common-qaDIAYS3.d.mts} +5 -4
- package/dist/{common-DMm4kymA.d.ts → common-qaDIAYS3.d.ts} +5 -4
- package/dist/index.d.mts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +99 -175
- package/dist/index.mjs +99 -172
- package/dist/plugin-sdk/index.d.mts +2 -2
- package/dist/plugin-sdk/index.d.ts +2 -2
- package/dist/plugin-sdk/index.js +90 -91
- package/dist/plugin-sdk/index.mjs +90 -91
- package/dist/registry/index.d.mts +3 -3
- package/dist/registry/index.d.ts +3 -3
- package/dist/registry/index.js +90 -90
- package/dist/registry/index.mjs +90 -90
- package/dist/{styles.registry-B8IaEULk.d.ts → styles.registry-4W0LzmZB.d.mts} +194 -365
- package/dist/{styles.registry-DhkxrV2-.d.mts → styles.registry-D6xMm5VR.d.ts} +194 -365
- package/dist/theme/index.d.mts +42 -91
- package/dist/theme/index.d.ts +42 -91
- package/dist/theme/index.js +9 -85
- package/dist/theme/index.mjs +9 -82
- package/dist/theme/tailwind.d.mts +2 -2
- package/dist/theme/tailwind.d.ts +2 -2
- package/package.json +1 -1
- package/src/plugin-sdk/define.ts +0 -1
- package/src/registry/__tests__/platform.test.ts +0 -4
- package/src/registry/__tests__/registry.test.ts +0 -2
- package/src/registry/styles.registry.ts +90 -96
- package/src/theme/__tests__/mantineVariant.test.ts +2 -2
- package/src/theme/__tests__/semantic.test.ts +34 -71
- package/src/theme/mantineVariant.ts +3 -3
- package/src/theme/semantic.ts +45 -185
- package/src/theme/tailwind.ts +2 -2
- package/src/theme/tokens.ts +3 -3
- package/src/types/__tests__/mobile-adapters.test.ts +1 -1
- package/src/types/mantine/common.ts +4 -3
- package/src/types/mobile-adapters.ts +4 -4
- package/src/types/styles/auth.ts +10 -10
- package/src/types/styles/base.ts +2 -2
- package/src/types/styles/composite.ts +7 -9
- package/src/types/styles/error.ts +9 -9
- package/src/types/styles/forms.ts +74 -58
- package/src/types/styles/interactive.ts +34 -32
- package/src/types/styles/layout.ts +42 -42
- package/src/types/styles/media.ts +6 -6
- package/src/types/styles/typography.ts +13 -13
- package/src/utils/spacing.ts +1 -1
|
@@ -7,9 +7,6 @@ import {
|
|
|
7
7
|
FULL_RADIUS_PX,
|
|
8
8
|
gridSpanToReactNativeColumn,
|
|
9
9
|
mapDividerVariantToReactNative,
|
|
10
|
-
mapIntentToHeroUiButtonVariant,
|
|
11
|
-
mapIntentToHeroUiColor,
|
|
12
|
-
mapIntentToMantine,
|
|
13
10
|
mapMantineColorToHeroUiButtonVariant,
|
|
14
11
|
mapMantineColorToHeroUiColor,
|
|
15
12
|
mapAccordionVariantToHeroUiVariant,
|
|
@@ -27,15 +24,14 @@ import {
|
|
|
27
24
|
toHeroUiSemanticProps,
|
|
28
25
|
toMantineSemanticProps,
|
|
29
26
|
toReactNativeSemanticStyle,
|
|
30
|
-
type TSemanticIntent,
|
|
31
27
|
type TSemanticSize,
|
|
32
28
|
} from '../semantic';
|
|
33
29
|
import { RADIUS_PX, SPACING_PX } from '../tokens';
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* The semantic mapper is the single source of truth that turns CMS
|
|
37
|
-
* cross-platform (
|
|
38
|
-
* rendering plan (section 8.2) it does NOT clamp: the shared scales
|
|
33
|
+
* cross-platform (unprefixed portable) values into per-platform props. Per the
|
|
34
|
+
* mobile rendering plan (section 8.2) it does NOT clamp: the shared scales
|
|
39
35
|
* (`size` = sm|md|lg, `radius` = none|sm|md|lg|full) are the true common
|
|
40
36
|
* denominator, so every value maps 1:1 to both platforms. Every mapping is
|
|
41
37
|
* pinned here so a regression surfaces immediately on web and mobile.
|
|
@@ -84,82 +80,48 @@ describe('semantic style mapper', () => {
|
|
|
84
80
|
});
|
|
85
81
|
});
|
|
86
82
|
|
|
87
|
-
describe('intent', () => {
|
|
88
|
-
it('maps to Mantine color + variant', () => {
|
|
89
|
-
expect(mapIntentToMantine('primary')).toEqual({ color: 'blue', variant: 'filled' });
|
|
90
|
-
expect(mapIntentToMantine('secondary')).toEqual({ color: 'gray', variant: 'light' });
|
|
91
|
-
expect(mapIntentToMantine('success')).toEqual({ color: 'green', variant: 'filled' });
|
|
92
|
-
expect(mapIntentToMantine('warning')).toEqual({ color: 'yellow', variant: 'filled' });
|
|
93
|
-
expect(mapIntentToMantine('danger')).toEqual({ color: 'red', variant: 'filled' });
|
|
94
|
-
expect(mapIntentToMantine('neutral')).toEqual({ color: 'gray', variant: 'default' });
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('maps intent to a HeroUI button variant (status color carried separately)', () => {
|
|
98
|
-
expect(mapIntentToHeroUiButtonVariant('primary')).toBe('primary');
|
|
99
|
-
expect(mapIntentToHeroUiButtonVariant('secondary')).toBe('secondary');
|
|
100
|
-
expect(mapIntentToHeroUiButtonVariant('danger')).toBe('danger');
|
|
101
|
-
// HeroUI has no success/warning BUTTON variant; the status colour is
|
|
102
|
-
// carried by mapIntentToHeroUiColor, the button stays prominent.
|
|
103
|
-
expect(mapIntentToHeroUiButtonVariant('success')).toBe('primary');
|
|
104
|
-
expect(mapIntentToHeroUiButtonVariant('warning')).toBe('primary');
|
|
105
|
-
expect(mapIntentToHeroUiButtonVariant('neutral')).toBe('secondary');
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('maps to HeroUI semantic color preserving success/warning', () => {
|
|
109
|
-
expect(mapIntentToHeroUiColor('primary')).toBe('accent');
|
|
110
|
-
expect(mapIntentToHeroUiColor('secondary')).toBe('default');
|
|
111
|
-
expect(mapIntentToHeroUiColor('success')).toBe('success');
|
|
112
|
-
expect(mapIntentToHeroUiColor('warning')).toBe('warning');
|
|
113
|
-
expect(mapIntentToHeroUiColor('danger')).toBe('danger');
|
|
114
|
-
expect(mapIntentToHeroUiColor('neutral')).toBe('default');
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
83
|
describe('resolveSharedStyleProps (read CMS fields)', () => {
|
|
119
|
-
it('reads valid
|
|
84
|
+
it('reads valid portable values', () => {
|
|
120
85
|
expect(
|
|
121
86
|
resolveSharedStyleProps({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
shared_full_width: '1',
|
|
87
|
+
size: 'lg',
|
|
88
|
+
radius: 'full',
|
|
89
|
+
full_width: '1',
|
|
126
90
|
}),
|
|
127
|
-
).toEqual({ size: 'lg', radius: 'full',
|
|
91
|
+
).toEqual({ size: 'lg', radius: 'full', fullWidth: true });
|
|
128
92
|
});
|
|
129
93
|
|
|
130
94
|
it('ignores out-of-domain values instead of clamping them', () => {
|
|
131
95
|
// Stale Mantine values (xs/xl) are NOT mapped; the renderer falls
|
|
132
96
|
// through to its component default rather than silently clamping.
|
|
133
97
|
const resolved = resolveSharedStyleProps({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
shared_intent: 'bogus',
|
|
98
|
+
size: 'xl',
|
|
99
|
+
radius: 'xs',
|
|
137
100
|
});
|
|
138
101
|
expect(resolved.size).toBeUndefined();
|
|
139
102
|
expect(resolved.radius).toBeUndefined();
|
|
140
|
-
expect(resolved.intent).toBeUndefined();
|
|
141
103
|
});
|
|
142
104
|
|
|
143
|
-
it('coerces
|
|
144
|
-
expect(resolveSharedStyleProps({
|
|
145
|
-
expect(resolveSharedStyleProps({
|
|
105
|
+
it('coerces full_width booleans', () => {
|
|
106
|
+
expect(resolveSharedStyleProps({ full_width: '0' }).fullWidth).toBe(false);
|
|
107
|
+
expect(resolveSharedStyleProps({ full_width: true }).fullWidth).toBe(true);
|
|
146
108
|
expect(resolveSharedStyleProps({}).fullWidth).toBeUndefined();
|
|
147
109
|
});
|
|
148
110
|
|
|
149
|
-
it('reads
|
|
150
|
-
const resolved = resolveSharedStyleProps({
|
|
111
|
+
it('reads color and variant (the REAL cross-platform fields)', () => {
|
|
112
|
+
const resolved = resolveSharedStyleProps({ color: 'red', variant: 'light' });
|
|
151
113
|
expect(resolved.color).toBe('red');
|
|
152
114
|
expect(resolved.variant).toBe('light');
|
|
153
115
|
});
|
|
154
116
|
|
|
155
|
-
it('treats an empty
|
|
156
|
-
const resolved = resolveSharedStyleProps({
|
|
117
|
+
it('treats an empty color / variant as absent', () => {
|
|
118
|
+
const resolved = resolveSharedStyleProps({ color: '', variant: '' });
|
|
157
119
|
expect(resolved.color).toBeUndefined();
|
|
158
120
|
expect(resolved.variant).toBeUndefined();
|
|
159
121
|
});
|
|
160
122
|
});
|
|
161
123
|
|
|
162
|
-
describe('Mantine colour/variant -> HeroUI Native (real
|
|
124
|
+
describe('Mantine colour/variant -> HeroUI Native (real color/variant)', () => {
|
|
163
125
|
it('maps a Mantine palette colour to a HeroUI semantic colour', () => {
|
|
164
126
|
expect(mapMantineColorToHeroUiColor('red')).toBe('danger');
|
|
165
127
|
expect(mapMantineColorToHeroUiColor('green')).toBe('success');
|
|
@@ -199,26 +161,26 @@ describe('semantic style mapper', () => {
|
|
|
199
161
|
expect(mapMantineColorToHeroUiButtonVariant('blue')).toBe('primary');
|
|
200
162
|
});
|
|
201
163
|
|
|
202
|
-
it('toHeroUiSemanticProps prefers
|
|
164
|
+
it('toHeroUiSemanticProps prefers variant, then color', () => {
|
|
203
165
|
expect(
|
|
204
|
-
toHeroUiSemanticProps({ variant: 'outline', color: 'red'
|
|
166
|
+
toHeroUiSemanticProps({ variant: 'outline', color: 'red' }).buttonVariant,
|
|
205
167
|
).toBe('outline');
|
|
206
168
|
expect(toHeroUiSemanticProps({ color: 'red' })).toMatchObject({
|
|
207
169
|
buttonVariant: 'danger',
|
|
208
170
|
color: 'danger',
|
|
209
171
|
});
|
|
210
|
-
expect(toHeroUiSemanticProps({
|
|
172
|
+
expect(toHeroUiSemanticProps({ color: 'green' })).toMatchObject({
|
|
211
173
|
buttonVariant: 'primary',
|
|
212
174
|
color: 'success',
|
|
213
175
|
});
|
|
214
176
|
});
|
|
215
177
|
|
|
216
|
-
it('resolves a real CMS button section (
|
|
178
|
+
it('resolves a real CMS button section (color + variant + size)', () => {
|
|
217
179
|
const props = resolveSharedStyleProps({
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
180
|
+
color: 'red',
|
|
181
|
+
variant: 'filled',
|
|
182
|
+
size: 'lg',
|
|
183
|
+
radius: 'md',
|
|
222
184
|
});
|
|
223
185
|
expect(toHeroUiSemanticProps(props)).toMatchObject({
|
|
224
186
|
size: 'lg',
|
|
@@ -230,9 +192,10 @@ describe('semantic style mapper', () => {
|
|
|
230
192
|
});
|
|
231
193
|
|
|
232
194
|
describe('platform resolvers', () => {
|
|
233
|
-
it('resolves a
|
|
195
|
+
it('resolves a red / filled / lg / full / fullWidth control consistently (no clamp)', () => {
|
|
234
196
|
const props = {
|
|
235
|
-
|
|
197
|
+
color: 'red' as const,
|
|
198
|
+
variant: 'filled' as const,
|
|
236
199
|
size: 'lg' as const,
|
|
237
200
|
radius: 'full' as const,
|
|
238
201
|
spacing: 'md' as const,
|
|
@@ -253,8 +216,8 @@ describe('semantic style mapper', () => {
|
|
|
253
216
|
|
|
254
217
|
expect(toHeroUiSemanticProps(props)).toMatchObject({
|
|
255
218
|
size: 'lg', // 1:1, not clamped
|
|
256
|
-
buttonVariant: '
|
|
257
|
-
color: 'danger',
|
|
219
|
+
buttonVariant: 'primary', // filled -> primary
|
|
220
|
+
color: 'danger', // red -> danger
|
|
258
221
|
radiusPx: FULL_RADIUS_PX,
|
|
259
222
|
spacingPx: SPACING_PX.md,
|
|
260
223
|
isDisabled: true,
|
|
@@ -264,7 +227,7 @@ describe('semantic style mapper', () => {
|
|
|
264
227
|
});
|
|
265
228
|
|
|
266
229
|
it('resolveSharedStyle returns both platform shapes', () => {
|
|
267
|
-
const { web, mobile } = resolveSharedStyle({ size: 'md',
|
|
230
|
+
const { web, mobile } = resolveSharedStyle({ size: 'md', color: 'blue' });
|
|
268
231
|
expect(web.size).toBe('md');
|
|
269
232
|
expect(web.color).toBe('blue');
|
|
270
233
|
expect(mobile.size).toBe('md');
|
|
@@ -279,9 +242,9 @@ describe('semantic style mapper', () => {
|
|
|
279
242
|
expect(mobile.isDisabled).toBeUndefined();
|
|
280
243
|
});
|
|
281
244
|
|
|
282
|
-
it('covers every
|
|
283
|
-
for (const
|
|
284
|
-
const { web, mobile } = resolveSharedStyle({
|
|
245
|
+
it('covers every mapped colour without throwing', () => {
|
|
246
|
+
for (const color of ['blue', 'gray', 'green', 'yellow', 'red'] as const) {
|
|
247
|
+
const { web, mobile } = resolveSharedStyle({ color });
|
|
285
248
|
expect(web.color).toBeDefined();
|
|
286
249
|
expect(mobile.color).toBeDefined();
|
|
287
250
|
expect(mobile.buttonVariant).toBeDefined();
|
|
@@ -13,10 +13,10 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
13
13
|
* SCOPE — this is NOT the semantic mapper (`semantic.ts`). The two have
|
|
14
14
|
* different input domains and both live here so there is exactly one home
|
|
15
15
|
* for style mapping:
|
|
16
|
-
* - `semantic.ts` maps renderer-agnostic
|
|
17
|
-
* (`
|
|
16
|
+
* - `semantic.ts` maps renderer-agnostic unprefixed portable fields
|
|
17
|
+
* (`color` / `variant` / `size` / `radius` / `spacing`) per platform.
|
|
18
18
|
* - `mantineVariant.ts` resolves a Mantine palette `color` + `variant` value
|
|
19
|
-
* pair (e.g. the
|
|
19
|
+
* pair (e.g. the portable `color` + `variant`)
|
|
20
20
|
* into concrete RGB. Its only runtime
|
|
21
21
|
* consumer today is the mobile **Expo Web preview**
|
|
22
22
|
* fallback (where `heroui-native` cannot render and the
|
package/src/theme/semantic.ts
CHANGED
|
@@ -4,8 +4,9 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Shared semantic style mapper — the single source of truth that turns
|
|
7
|
-
* renderer-agnostic CMS values (
|
|
8
|
-
* props. Renderers consume this module instead of duplicating
|
|
7
|
+
* renderer-agnostic CMS values (the unprefixed portable fields) into concrete
|
|
8
|
+
* per-platform props. Renderers consume this module instead of duplicating
|
|
9
|
+
* mapping logic.
|
|
9
10
|
*
|
|
10
11
|
* - Web -> Mantine (`toMantineSemanticProps`)
|
|
11
12
|
* - Mobile -> HeroUI Native (`toHeroUiSemanticProps`)
|
|
@@ -13,18 +14,19 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
13
14
|
*
|
|
14
15
|
* Design rules (mobile rendering plan, section 8.2):
|
|
15
16
|
* - NO value clamping. The shared scales are the true common denominator
|
|
16
|
-
* (`
|
|
17
|
+
* (`size` = sm|md|lg, `radius` = none|sm|md|lg|full), so every
|
|
17
18
|
* value maps 1:1 to each platform. The backend enforces the same domain
|
|
18
19
|
* (migration `Version20260618195450`).
|
|
19
20
|
* - NO implicit cross-platform fallback. These functions take already-resolved
|
|
20
|
-
*
|
|
21
|
-
* component default is applied by each platform renderer,
|
|
21
|
+
* portable props; the precedence `web_*`/`mobile_*` override -> portable
|
|
22
|
+
* (unprefixed) -> component default is applied by each platform renderer,
|
|
23
|
+
* never here.
|
|
22
24
|
* - Exhaustive enum handling (every switch covers the full domain).
|
|
23
25
|
*
|
|
24
|
-
* Platform-specific props stay separate from these
|
|
26
|
+
* Platform-specific props stay separate from these portable values:
|
|
25
27
|
* - `web_*` Mantine-only fields
|
|
26
28
|
* - `mobile_*` HeroUI/native-only fields
|
|
27
|
-
* -
|
|
29
|
+
* - portable the unprefixed semantic fields mapped here
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
import { RADIUS_PX, SPACING_PX, type TCanonicalSpacing } from './tokens';
|
|
@@ -37,23 +39,14 @@ export type TSemanticSize = TSharedSize; // 'sm' | 'md' | 'lg'
|
|
|
37
39
|
export type TSemanticSpacing = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
38
40
|
/** Cross-platform radius. `full` = pill; `none` = square. */
|
|
39
41
|
export type TSemanticRadius = TSharedRadius; // 'none' | 'sm' | 'md' | 'lg' | 'full'
|
|
40
|
-
export type TSemanticIntent =
|
|
41
|
-
| 'primary'
|
|
42
|
-
| 'secondary'
|
|
43
|
-
| 'success'
|
|
44
|
-
| 'warning'
|
|
45
|
-
| 'danger'
|
|
46
|
-
| 'neutral';
|
|
47
42
|
export type TSemanticState = 'disabled' | 'loading' | 'invalid' | 'required';
|
|
48
43
|
|
|
49
44
|
/**
|
|
50
|
-
* Cross-platform colour + variant authored in the CMS (`
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* live catalog); the mapper maps them onto HeroUI Native for mobile, while the
|
|
56
|
-
* web renderer feeds them straight into Mantine.
|
|
45
|
+
* Cross-platform colour + variant authored in the CMS (`color` /
|
|
46
|
+
* `variant`), stored as Mantine palette / variant *values* kept verbatim by the
|
|
47
|
+
* catalog. They are the canonical cross-platform appearance fields; the mapper
|
|
48
|
+
* maps them onto HeroUI Native for mobile, while the web renderer feeds them
|
|
49
|
+
* straight into Mantine.
|
|
57
50
|
*/
|
|
58
51
|
export type TSemanticColor = TMantineColor;
|
|
59
52
|
export type TSemanticVariant = TMantineVariant;
|
|
@@ -63,14 +56,6 @@ export const FULL_RADIUS_PX = 9999;
|
|
|
63
56
|
|
|
64
57
|
const SEMANTIC_SIZES: readonly TSemanticSize[] = ['sm', 'md', 'lg'];
|
|
65
58
|
const SEMANTIC_RADII: readonly TSemanticRadius[] = ['none', 'sm', 'md', 'lg', 'full'];
|
|
66
|
-
const SEMANTIC_INTENTS: readonly TSemanticIntent[] = [
|
|
67
|
-
'primary',
|
|
68
|
-
'secondary',
|
|
69
|
-
'success',
|
|
70
|
-
'warning',
|
|
71
|
-
'danger',
|
|
72
|
-
'neutral',
|
|
73
|
-
];
|
|
74
59
|
|
|
75
60
|
/**
|
|
76
61
|
* Renderer-agnostic style values configured in the CMS. Every field is
|
|
@@ -81,16 +66,10 @@ export interface ISharedStyleProps {
|
|
|
81
66
|
size?: TSemanticSize;
|
|
82
67
|
spacing?: TSemanticSpacing;
|
|
83
68
|
radius?: TSemanticRadius;
|
|
84
|
-
/** Mantine palette colour authored via `
|
|
69
|
+
/** Mantine palette colour authored via `color` (cross-platform). */
|
|
85
70
|
color?: TSemanticColor;
|
|
86
|
-
/** Mantine variant authored via `
|
|
71
|
+
/** Mantine variant authored via `variant` (cross-platform). */
|
|
87
72
|
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
|
-
*/
|
|
93
|
-
intent?: TSemanticIntent;
|
|
94
73
|
/** Active boolean states. Stored as a small set so multiple can apply. */
|
|
95
74
|
states?: readonly TSemanticState[];
|
|
96
75
|
/** Layout: stretch the control to the full width of its container. */
|
|
@@ -99,19 +78,13 @@ export interface ISharedStyleProps {
|
|
|
99
78
|
|
|
100
79
|
// ===== Mantine (web) target shapes =====
|
|
101
80
|
|
|
102
|
-
export type TMantineMappedColor =
|
|
103
|
-
| 'blue'
|
|
104
|
-
| 'gray'
|
|
105
|
-
| 'green'
|
|
106
|
-
| 'yellow'
|
|
107
|
-
| 'red';
|
|
108
|
-
export type TMantineMappedVariant = 'filled' | 'light' | 'outline' | 'default';
|
|
109
|
-
|
|
110
81
|
export interface IMantineResolvedStyle {
|
|
111
82
|
/** Mantine accepts sm|md|lg 1:1 (a subset of its xs..xl scale). */
|
|
112
83
|
size?: TSemanticSize;
|
|
113
|
-
color
|
|
114
|
-
|
|
84
|
+
/** Mantine palette colour, read verbatim from the `color` field. */
|
|
85
|
+
color?: TSemanticColor;
|
|
86
|
+
/** Mantine variant, read verbatim from the `variant` field. */
|
|
87
|
+
variant?: TSemanticVariant;
|
|
115
88
|
/** Mantine `radius` accepts a token or a number; pill => FULL_RADIUS_PX. */
|
|
116
89
|
radius?: TSemanticSize | number;
|
|
117
90
|
/** Margin/padding spacing token (xs..xl); `none` => undefined. */
|
|
@@ -141,9 +114,9 @@ export type THeroUiColor = 'accent' | 'default' | 'success' | 'warning' | 'dange
|
|
|
141
114
|
|
|
142
115
|
export interface IHeroUiResolvedStyle {
|
|
143
116
|
size?: THeroUiSize;
|
|
144
|
-
/**
|
|
117
|
+
/** Button variant derived from the Mantine `variant`/`color`. */
|
|
145
118
|
buttonVariant?: THeroUiButtonVariant;
|
|
146
|
-
/**
|
|
119
|
+
/** Semantic color derived from the Mantine `color` (Chip/Tag/etc). */
|
|
147
120
|
color?: THeroUiColor;
|
|
148
121
|
/** Resolved radius in px (pill => FULL_RADIUS_PX, none => 0). */
|
|
149
122
|
radiusPx?: number;
|
|
@@ -243,113 +216,10 @@ export function mapSpacingToPx(spacing: TSemanticSpacing | undefined): number |
|
|
|
243
216
|
return SPACING_PX[spacing as TCanonicalSpacing];
|
|
244
217
|
}
|
|
245
218
|
|
|
246
|
-
// ===== intent =====
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Map a semantic intent to a Mantine `{ color, variant }` pair.
|
|
250
|
-
* primary -> blue / filled
|
|
251
|
-
* secondary -> gray / light
|
|
252
|
-
* success -> green / filled
|
|
253
|
-
* warning -> yellow / filled
|
|
254
|
-
* danger -> red / filled
|
|
255
|
-
* neutral -> gray / default
|
|
256
|
-
*/
|
|
257
|
-
export function mapIntentToMantine(
|
|
258
|
-
intent: TSemanticIntent | undefined,
|
|
259
|
-
): { color: TMantineMappedColor; variant: TMantineMappedVariant } | undefined {
|
|
260
|
-
if (!intent) return undefined;
|
|
261
|
-
switch (intent) {
|
|
262
|
-
case 'primary':
|
|
263
|
-
return { color: 'blue', variant: 'filled' };
|
|
264
|
-
case 'secondary':
|
|
265
|
-
return { color: 'gray', variant: 'light' };
|
|
266
|
-
case 'success':
|
|
267
|
-
return { color: 'green', variant: 'filled' };
|
|
268
|
-
case 'warning':
|
|
269
|
-
return { color: 'yellow', variant: 'filled' };
|
|
270
|
-
case 'danger':
|
|
271
|
-
return { color: 'red', variant: 'filled' };
|
|
272
|
-
case 'neutral':
|
|
273
|
-
return { color: 'gray', variant: 'default' };
|
|
274
|
-
default:
|
|
275
|
-
return undefined;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Map a semantic intent to a HeroUI Native **Button** variant.
|
|
281
|
-
*
|
|
282
|
-
* HeroUI buttons have no dedicated success/warning variant. Rather than
|
|
283
|
-
* silently collapse them, the dedicated status surfaces use
|
|
284
|
-
* {@link mapIntentToHeroUiColor}; the Button variant maps success/warning to
|
|
285
|
-
* `primary` because that is the closest *prominent* action affordance, and the
|
|
286
|
-
* status color is carried separately. This is an explicit semantic choice, not
|
|
287
|
-
* a clamp that hides an unsupported size/scale value.
|
|
288
|
-
* primary -> primary
|
|
289
|
-
* secondary -> secondary
|
|
290
|
-
* success -> primary (status color carried by mapIntentToHeroUiColor)
|
|
291
|
-
* warning -> primary (status color carried by mapIntentToHeroUiColor)
|
|
292
|
-
* danger -> danger
|
|
293
|
-
* neutral -> secondary
|
|
294
|
-
*/
|
|
295
|
-
export function mapIntentToHeroUiButtonVariant(
|
|
296
|
-
intent: TSemanticIntent | undefined,
|
|
297
|
-
): THeroUiButtonVariant | undefined {
|
|
298
|
-
if (!intent) return undefined;
|
|
299
|
-
switch (intent) {
|
|
300
|
-
case 'primary':
|
|
301
|
-
return 'primary';
|
|
302
|
-
case 'secondary':
|
|
303
|
-
return 'secondary';
|
|
304
|
-
case 'success':
|
|
305
|
-
return 'primary';
|
|
306
|
-
case 'warning':
|
|
307
|
-
return 'primary';
|
|
308
|
-
case 'danger':
|
|
309
|
-
return 'danger';
|
|
310
|
-
case 'neutral':
|
|
311
|
-
return 'secondary';
|
|
312
|
-
default:
|
|
313
|
-
return undefined;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Map a semantic intent to a HeroUI Native semantic color (Chip/Tag/
|
|
319
|
-
* status surfaces, which DO support success/warning).
|
|
320
|
-
* primary -> accent
|
|
321
|
-
* secondary -> default
|
|
322
|
-
* success -> success
|
|
323
|
-
* warning -> warning
|
|
324
|
-
* danger -> danger
|
|
325
|
-
* neutral -> default
|
|
326
|
-
*/
|
|
327
|
-
export function mapIntentToHeroUiColor(
|
|
328
|
-
intent: TSemanticIntent | undefined,
|
|
329
|
-
): THeroUiColor | undefined {
|
|
330
|
-
if (!intent) return undefined;
|
|
331
|
-
switch (intent) {
|
|
332
|
-
case 'primary':
|
|
333
|
-
return 'accent';
|
|
334
|
-
case 'secondary':
|
|
335
|
-
return 'default';
|
|
336
|
-
case 'success':
|
|
337
|
-
return 'success';
|
|
338
|
-
case 'warning':
|
|
339
|
-
return 'warning';
|
|
340
|
-
case 'danger':
|
|
341
|
-
return 'danger';
|
|
342
|
-
case 'neutral':
|
|
343
|
-
return 'default';
|
|
344
|
-
default:
|
|
345
|
-
return undefined;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
219
|
// ===== color / variant (the REAL cross-platform appearance fields) =====
|
|
350
220
|
|
|
351
221
|
/**
|
|
352
|
-
* Map a Mantine palette colour (`
|
|
222
|
+
* Map a Mantine palette colour (`color`) onto a HeroUI Native semantic
|
|
353
223
|
* colour (Chip / Tag / status surfaces). The Mantine palette is broad; it
|
|
354
224
|
* collapses onto HeroUI's five semantic colours by hue family:
|
|
355
225
|
* red/pink -> danger
|
|
@@ -382,8 +252,8 @@ export function mapMantineColorToHeroUiColor(
|
|
|
382
252
|
}
|
|
383
253
|
|
|
384
254
|
/**
|
|
385
|
-
* Map a Mantine palette colour (`
|
|
386
|
-
* variant when no explicit `
|
|
255
|
+
* Map a Mantine palette colour (`color`) onto a HeroUI Native **Button**
|
|
256
|
+
* variant when no explicit `variant` is authored. HeroUI buttons encode
|
|
387
257
|
* colour in the variant, so the destructive hue becomes `danger`, neutral hues
|
|
388
258
|
* become `secondary`, and everything else stays the prominent `primary`.
|
|
389
259
|
*/
|
|
@@ -404,7 +274,7 @@ export function mapMantineColorToHeroUiButtonVariant(
|
|
|
404
274
|
}
|
|
405
275
|
|
|
406
276
|
/**
|
|
407
|
-
* Map a Mantine variant (`
|
|
277
|
+
* Map a Mantine variant (`variant`) onto the HeroUI Native Button
|
|
408
278
|
* vocabulary:
|
|
409
279
|
* filled / gradient -> primary
|
|
410
280
|
* light / white / default -> secondary
|
|
@@ -434,7 +304,7 @@ export function mapMantineVariantToHeroUiButtonVariant(
|
|
|
434
304
|
}
|
|
435
305
|
|
|
436
306
|
/**
|
|
437
|
-
* Map the accordion variant token (`
|
|
307
|
+
* Map the accordion variant token (`accordion_variant`: Mantine
|
|
438
308
|
* default/contained/filled/separated) onto the HeroUI Native Accordion `variant`
|
|
439
309
|
* vocabulary. HeroUI Native only has `default` (plain list) and `surface`
|
|
440
310
|
* (grouped container), so every "boxed" Mantine variant collapses to `surface`.
|
|
@@ -454,7 +324,7 @@ export function mapAccordionVariantToHeroUiVariant(
|
|
|
454
324
|
}
|
|
455
325
|
|
|
456
326
|
/**
|
|
457
|
-
* Map the chip variant token (`
|
|
327
|
+
* Map the chip variant token (`chip_variant`: Mantine
|
|
458
328
|
* filled/outline/light) onto the HeroUI Native Chip `variant` vocabulary
|
|
459
329
|
* (`primary`/`secondary`/`tertiary`/`soft`):
|
|
460
330
|
* - filled -> primary (solid accent fill)
|
|
@@ -475,14 +345,14 @@ export function mapChipVariantToHeroUiVariant(
|
|
|
475
345
|
}
|
|
476
346
|
}
|
|
477
347
|
|
|
478
|
-
// ===== layout dimensions (shared_width / shared_height / grid span / divider) =====
|
|
348
|
+
// ===== layout dimensions (shared_width / shared_height / mih/miw/mah/maw / grid span / divider) =====
|
|
479
349
|
|
|
480
350
|
/** A React Native-safe dimension: a px number, a percentage string, or "auto". */
|
|
481
351
|
export type TReactNativeDimension = number | `${number}%` | 'auto';
|
|
482
352
|
|
|
483
353
|
/**
|
|
484
|
-
* Parse a CMS dimension string (`shared_width`/`shared_height`/`
|
|
485
|
-
* `
|
|
354
|
+
* Parse a CMS dimension string (`shared_width`/`shared_height`/`mih`/`miw`/
|
|
355
|
+
* `mah`/`maw`) into a React Native-safe value. Web (Mantine) accepts the raw
|
|
486
356
|
* string verbatim ("320px", "100%", "auto"); React Native does NOT accept a
|
|
487
357
|
* unit suffix, so a px value must become a unitless number:
|
|
488
358
|
* "320px" | "320" | 320 -> 320 (number)
|
|
@@ -552,7 +422,7 @@ export function gridSpanToReactNativeColumn(
|
|
|
552
422
|
}
|
|
553
423
|
|
|
554
424
|
/**
|
|
555
|
-
* Map a `
|
|
425
|
+
* Map a `divider_variant` (solid/dashed/dotted) onto a React Native
|
|
556
426
|
* `borderStyle`. The vocabularies are identical, so this validates the domain
|
|
557
427
|
* and falls back to 'solid'.
|
|
558
428
|
*/
|
|
@@ -601,38 +471,31 @@ function readBool(value: unknown): boolean | undefined {
|
|
|
601
471
|
export function resolveSharedStyleProps(fields: Record<string, unknown>): ISharedStyleProps {
|
|
602
472
|
const resolved: ISharedStyleProps = {};
|
|
603
473
|
|
|
604
|
-
const size = readString(fields.
|
|
474
|
+
const size = readString(fields.size);
|
|
605
475
|
if (size !== undefined && (SEMANTIC_SIZES as readonly string[]).includes(size)) {
|
|
606
476
|
resolved.size = size as TSemanticSize;
|
|
607
477
|
}
|
|
608
478
|
|
|
609
|
-
const radius = readString(fields.
|
|
479
|
+
const radius = readString(fields.radius);
|
|
610
480
|
if (radius !== undefined && (SEMANTIC_RADII as readonly string[]).includes(radius)) {
|
|
611
481
|
resolved.radius = radius as TSemanticRadius;
|
|
612
482
|
}
|
|
613
483
|
|
|
614
|
-
// `
|
|
484
|
+
// `color` / `variant` are the REAL cross-platform appearance
|
|
615
485
|
// fields (Mantine palette/variant values stored verbatim). Read them
|
|
616
486
|
// open-domain — the palette is intentionally broad and platform mappers
|
|
617
487
|
// collapse it; an unknown value simply falls through to a renderer default.
|
|
618
|
-
const color = readString(fields.
|
|
488
|
+
const color = readString(fields.color);
|
|
619
489
|
if (color !== undefined) {
|
|
620
490
|
resolved.color = color;
|
|
621
491
|
}
|
|
622
492
|
|
|
623
|
-
const variant = readString(fields.
|
|
493
|
+
const variant = readString(fields.variant);
|
|
624
494
|
if (variant !== undefined) {
|
|
625
495
|
resolved.variant = variant as TSemanticVariant;
|
|
626
496
|
}
|
|
627
497
|
|
|
628
|
-
|
|
629
|
-
// any forward-compat seed still resolves. Domain-checked like size/radius.
|
|
630
|
-
const intent = readString(fields.shared_intent);
|
|
631
|
-
if (intent !== undefined && (SEMANTIC_INTENTS as readonly string[]).includes(intent)) {
|
|
632
|
-
resolved.intent = intent as TSemanticIntent;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
const fullWidth = readBool(fields.shared_full_width);
|
|
498
|
+
const fullWidth = readBool(fields.full_width);
|
|
636
499
|
if (fullWidth !== undefined) {
|
|
637
500
|
resolved.fullWidth = fullWidth;
|
|
638
501
|
}
|
|
@@ -644,12 +507,11 @@ export function resolveSharedStyleProps(fields: Record<string, unknown>): IShare
|
|
|
644
507
|
|
|
645
508
|
/** Resolve shared props into Mantine (web) props. */
|
|
646
509
|
export function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolvedStyle {
|
|
647
|
-
const intent = mapIntentToMantine(props.intent);
|
|
648
510
|
const spacing = props.spacing && props.spacing !== 'none' ? props.spacing : undefined;
|
|
649
511
|
return {
|
|
650
512
|
size: mapSizeToMantine(props.size),
|
|
651
|
-
color:
|
|
652
|
-
variant:
|
|
513
|
+
color: props.color,
|
|
514
|
+
variant: props.variant,
|
|
653
515
|
radius: mapRadiusToMantine(props.radius),
|
|
654
516
|
spacing,
|
|
655
517
|
disabled: hasState(props.states, 'disabled') || undefined,
|
|
@@ -665,17 +527,15 @@ export function toMantineSemanticProps(props: ISharedStyleProps): IMantineResolv
|
|
|
665
527
|
*
|
|
666
528
|
* Appearance precedence (mirrors the web renderer, which reads the same CMS
|
|
667
529
|
* fields straight into Mantine):
|
|
668
|
-
* 1. `
|
|
669
|
-
* 2. else `
|
|
670
|
-
*
|
|
671
|
-
* The semantic `color` is resolved from `shared_color` first, then `intent`.
|
|
530
|
+
* 1. `variant` (Mantine variant) mapped onto the HeroUI button vocab;
|
|
531
|
+
* 2. else `color` (Mantine palette) mapped onto a button variant.
|
|
532
|
+
* The semantic `color` is resolved from `color`.
|
|
672
533
|
*/
|
|
673
534
|
export function toHeroUiSemanticProps(props: ISharedStyleProps): IHeroUiResolvedStyle {
|
|
674
535
|
const buttonVariant =
|
|
675
536
|
mapMantineVariantToHeroUiButtonVariant(props.variant) ??
|
|
676
|
-
mapMantineColorToHeroUiButtonVariant(props.color)
|
|
677
|
-
|
|
678
|
-
const color = mapMantineColorToHeroUiColor(props.color) ?? mapIntentToHeroUiColor(props.intent);
|
|
537
|
+
mapMantineColorToHeroUiButtonVariant(props.color);
|
|
538
|
+
const color = mapMantineColorToHeroUiColor(props.color);
|
|
679
539
|
return {
|
|
680
540
|
size: mapSizeToHeroUi(props.size),
|
|
681
541
|
buttonVariant,
|
package/src/theme/tailwind.ts
CHANGED
|
@@ -5,8 +5,8 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
5
5
|
/**
|
|
6
6
|
* Shared Tailwind preset extended by both the web frontend (Tailwind v4)
|
|
7
7
|
* and the mobile app (Uniwind v4 inside HeroUI Native). Anchors the same
|
|
8
|
-
* scale values that drive `
|
|
9
|
-
* `
|
|
8
|
+
* scale values that drive `size`, `radius`,
|
|
9
|
+
* `spacing`, and the color palette so a class like `p-md` or
|
|
10
10
|
* `text-blue-6` resolves identically on web and mobile.
|
|
11
11
|
*/
|
|
12
12
|
|
package/src/theme/tokens.ts
CHANGED
|
@@ -4,7 +4,7 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Mantine semantic token tables. Both the web Mantine theme and the
|
|
7
|
-
* mobile HeroUI Native theme extend these so a `
|
|
7
|
+
* mobile HeroUI Native theme extend these so a `size: 'md'` on a
|
|
8
8
|
* section renders identical sizing regardless of platform.
|
|
9
9
|
*
|
|
10
10
|
* Pixel values come straight from Mantine v9 defaults:
|
|
@@ -91,8 +91,8 @@ export const CONTAINER_SIZE_PX: Record<TMantineSize, number> = {
|
|
|
91
91
|
/**
|
|
92
92
|
* Mantine palette base colors (color-6 from each scale). Each renderer
|
|
93
93
|
* maps these to its own theme tokens. For HeroUI Native we feed these
|
|
94
|
-
* into the theme builder so `
|
|
95
|
-
* same Mantine-blue look on mobile.
|
|
94
|
+
* into the theme builder so the portable `color: 'blue'` field resolves
|
|
95
|
+
* to the same Mantine-blue look on mobile.
|
|
96
96
|
*/
|
|
97
97
|
export const COLOR_PALETTE: Record<TCanonicalColor, string> = {
|
|
98
98
|
gray: '#868e96',
|
|
@@ -59,7 +59,7 @@ void _exhaustiveBackward;
|
|
|
59
59
|
/**
|
|
60
60
|
* Compile-time lock for the authored-colour button passthrough: `MobileButton`
|
|
61
61
|
* accepts an optional `accentColor` (resolved hex) so a CMS style can colour the
|
|
62
|
-
* button for cross-platform parity (e.g. `login`'s `
|
|
62
|
+
* button for cross-platform parity (e.g. `login`'s `color`). If the prop
|
|
63
63
|
* is removed or retyped, this assignment fails to type-check.
|
|
64
64
|
*/
|
|
65
65
|
const _buttonAcceptsAccentColor: IMobileButtonProps = { accentColor: '#fab005' };
|