@newtonedev/components 0.1.5 → 0.1.6
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/dist/composites/actions/Button/Button.d.ts.map +1 -1
- package/dist/composites/actions/Button/Button.styles.d.ts +3 -1
- package/dist/composites/actions/Button/Button.styles.d.ts.map +1 -1
- package/dist/index.cjs +360 -226
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +357 -228
- package/dist/index.js.map +1 -1
- package/dist/primitives/Frame/Frame.d.ts +2 -3
- package/dist/primitives/Frame/Frame.d.ts.map +1 -1
- package/dist/primitives/Frame/Frame.types.d.ts +4 -15
- package/dist/primitives/Frame/Frame.types.d.ts.map +1 -1
- package/dist/primitives/Text/Text.d.ts.map +1 -1
- package/dist/primitives/Text/Text.types.d.ts +9 -4
- package/dist/primitives/Text/Text.types.d.ts.map +1 -1
- package/dist/primitives/Wrapper/Wrapper.d.ts +1 -1
- package/dist/primitives/Wrapper/Wrapper.types.d.ts +1 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/theme/FrameContext.d.ts +7 -5
- package/dist/theme/FrameContext.d.ts.map +1 -1
- package/dist/theme/NewtoneProvider.d.ts +5 -6
- package/dist/theme/NewtoneProvider.d.ts.map +1 -1
- package/dist/theme/defaults.d.ts.map +1 -1
- package/dist/theme/types.d.ts +38 -24
- package/dist/theme/types.d.ts.map +1 -1
- package/dist/tokens/computeTokens.d.ts +82 -7
- package/dist/tokens/computeTokens.d.ts.map +1 -1
- package/dist/tokens/types.d.ts +58 -16
- package/dist/tokens/types.d.ts.map +1 -1
- package/dist/tokens/useTokens.d.ts +2 -23
- package/dist/tokens/useTokens.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/composites/actions/Button/Button.styles.ts +53 -80
- package/src/composites/actions/Button/Button.tsx +6 -2
- package/src/composites/form-controls/Select/SelectOption.tsx +2 -2
- package/src/composites/form-controls/Toggle/Toggle.styles.ts +1 -1
- package/src/composites/range-inputs/ColorScaleSlider/ColorScaleSlider.styles.ts +1 -1
- package/src/composites/range-inputs/Slider/Slider.styles.ts +2 -2
- package/src/index.ts +11 -4
- package/src/primitives/Frame/Frame.tsx +10 -18
- package/src/primitives/Frame/Frame.types.ts +5 -17
- package/src/primitives/Text/Text.tsx +18 -8
- package/src/primitives/Text/Text.types.ts +9 -4
- package/src/primitives/Wrapper/Wrapper.tsx +1 -1
- package/src/primitives/Wrapper/Wrapper.types.ts +1 -1
- package/src/registry/registry.ts +28 -7
- package/src/theme/FrameContext.tsx +7 -5
- package/src/theme/NewtoneProvider.tsx +5 -10
- package/src/theme/defaults.ts +0 -9
- package/src/theme/types.ts +53 -26
- package/src/tokens/computeTokens.ts +338 -116
- package/src/tokens/types.ts +74 -16
- package/src/tokens/useTokens.ts +16 -33
|
@@ -15,33 +15,12 @@ export interface UseTokensResult extends ResolvedTokens {
|
|
|
15
15
|
* 2. FrameContext values (from nearest parent Frame) are used when elevation is omitted
|
|
16
16
|
* 3. Falls back to NewtoneProvider theme + elevation 1
|
|
17
17
|
*
|
|
18
|
-
*
|
|
18
|
+
* When inside a Frame and no explicit elevation override is given, reuses the
|
|
19
|
+
* Frame's pre-computed tokens to avoid redundant computeTokens calls.
|
|
19
20
|
*
|
|
20
21
|
* @param elevation - Elevation level (0=sunken, 1=default, 2=elevated).
|
|
21
22
|
* When omitted, reads from FrameContext or defaults to 1.
|
|
22
23
|
* @returns Resolved design tokens with all necessary colors + resolved elevation
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* // Inside a <Frame theme="primary" elevation={1}>:
|
|
27
|
-
* function MyComponent() {
|
|
28
|
-
* const tokens = useTokens(); // Gets primary theme, elevation 2 (mapped from Frame's 1)
|
|
29
|
-
* return (
|
|
30
|
-
* <View style={{ backgroundColor: srgbToHex(tokens.background.srgb) }} />
|
|
31
|
-
* );
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```tsx
|
|
37
|
-
* // Elevation-aware component:
|
|
38
|
-
* function ElevationAwareButton() {
|
|
39
|
-
* const tokens = useTokens();
|
|
40
|
-
* // Use tokens.elevation to make color decisions
|
|
41
|
-
* const bg = tokens.elevation === 2 ? tokens.background : tokens.backgroundSunken;
|
|
42
|
-
* return <View style={{ backgroundColor: srgbToHex(bg.srgb) }} />;
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
24
|
*/
|
|
46
25
|
export declare function useTokens(elevation?: ElevationLevel): UseTokensResult;
|
|
47
26
|
//# sourceMappingURL=useTokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/tokens/useTokens.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED
|
|
1
|
+
{"version":3,"file":"useTokens.d.ts","sourceRoot":"","sources":["../../src/tokens/useTokens.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,cAAc;IACrD,SAAS,EAAE,cAAc,CAAC;CAC3B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,SAAS,CAAC,EAAE,cAAc,GAAG,eAAe,CA+BrE"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { srgbToHex } from 'newtone';
|
|
2
2
|
import type { UseTokensResult } from '../../../tokens/useTokens';
|
|
3
|
+
import type { PaletteTokens } from '../../../tokens/types';
|
|
3
4
|
import type { ButtonVariant, ButtonSemantic, ButtonSize } from './Button.types';
|
|
4
5
|
import type { TextSize } from '../../../primitives/Text/Text.types';
|
|
5
6
|
|
|
@@ -9,6 +10,7 @@ import type { TextSize } from '../../../primitives/Text/Text.types';
|
|
|
9
10
|
export interface ButtonConfig {
|
|
10
11
|
variantColors: {
|
|
11
12
|
bg: string;
|
|
13
|
+
hoveredBg: string;
|
|
12
14
|
pressedBg: string;
|
|
13
15
|
textColor: string;
|
|
14
16
|
iconColor: string;
|
|
@@ -34,17 +36,6 @@ export interface ButtonPadding {
|
|
|
34
36
|
paddingBottom: number;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
|
-
/**
|
|
38
|
-
* Add opacity to a hex color string.
|
|
39
|
-
* @param hexColor - Hex color string (e.g., "#ff0000")
|
|
40
|
-
* @param opacity - Opacity value from 0 to 1
|
|
41
|
-
* @returns Hex color with alpha channel
|
|
42
|
-
*/
|
|
43
|
-
function withOpacity(hexColor: string, opacity: number): string {
|
|
44
|
-
const alpha = Math.round(opacity * 255).toString(16).padStart(2, '0');
|
|
45
|
-
return `${hexColor}${alpha}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
39
|
/**
|
|
49
40
|
* Compute asymmetric button padding based on icon/text presence.
|
|
50
41
|
*
|
|
@@ -122,16 +113,17 @@ export function computeButtonPadding(
|
|
|
122
113
|
}
|
|
123
114
|
|
|
124
115
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* @param tokens - Resolved tokens for current elevation
|
|
129
|
-
* @returns Background color hex string
|
|
116
|
+
* Resolve the PaletteTokens for a given semantic.
|
|
117
|
+
* Returns undefined for 'neutral' (handled separately).
|
|
130
118
|
*/
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
function getPaletteTokens(semantic: ButtonSemantic, tokens: UseTokensResult): PaletteTokens | undefined {
|
|
120
|
+
switch (semantic) {
|
|
121
|
+
case 'accent': return tokens.accent;
|
|
122
|
+
case 'success': return tokens.success;
|
|
123
|
+
case 'error': return tokens.error;
|
|
124
|
+
case 'warning': return tokens.warning;
|
|
125
|
+
default: return undefined;
|
|
126
|
+
}
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
/**
|
|
@@ -141,7 +133,8 @@ function getNeutralPrimaryBg(tokens: UseTokensResult): string {
|
|
|
141
133
|
* Layout concerns (flexbox, spacing, alignment) are handled by Wrapper primitive.
|
|
142
134
|
* Typography concerns (font, size, weight) are handled by Text primitive.
|
|
143
135
|
*
|
|
144
|
-
*
|
|
136
|
+
* Elevation-aware: neutral primary uses backgroundInteractive for consistent contrast.
|
|
137
|
+
* Semantic variants use proper PaletteTokens — no opacity hacks.
|
|
145
138
|
*
|
|
146
139
|
* @param variant - Button type (primary, secondary, tertiary)
|
|
147
140
|
* @param semantic - Button semantic meaning (neutral, accent, success, error, warning)
|
|
@@ -226,10 +219,12 @@ function getVariantColors(
|
|
|
226
219
|
// Disabled state overrides for all variants
|
|
227
220
|
if (disabled) {
|
|
228
221
|
const baseColors = getVariantColorsForState(variant, semantic, tokens);
|
|
222
|
+
const disabledBg = srgbToHex(tokens.backgroundSunken.srgb);
|
|
229
223
|
return {
|
|
230
224
|
...baseColors,
|
|
231
|
-
bg:
|
|
232
|
-
|
|
225
|
+
bg: disabledBg,
|
|
226
|
+
hoveredBg: disabledBg,
|
|
227
|
+
pressedBg: disabledBg,
|
|
233
228
|
textColor: srgbToHex(tokens.textSecondary.srgb),
|
|
234
229
|
iconColor: srgbToHex(tokens.textSecondary.srgb),
|
|
235
230
|
};
|
|
@@ -241,74 +236,50 @@ function getVariantColors(
|
|
|
241
236
|
/**
|
|
242
237
|
* Get variant colors for non-disabled state.
|
|
243
238
|
* Implements 3 types × 5 semantics = 15 combinations.
|
|
239
|
+
* Uses proper PaletteTokens for all semantic variants — no opacity hacks.
|
|
244
240
|
*/
|
|
245
241
|
function getVariantColorsForState(
|
|
246
242
|
variant: ButtonVariant,
|
|
247
243
|
semantic: ButtonSemantic,
|
|
248
244
|
tokens: UseTokensResult
|
|
249
245
|
) {
|
|
250
|
-
|
|
251
|
-
const getSemanticColor = (): string => {
|
|
252
|
-
switch (semantic) {
|
|
253
|
-
case 'accent':
|
|
254
|
-
return srgbToHex(tokens.interactive.srgb);
|
|
255
|
-
case 'success':
|
|
256
|
-
return srgbToHex(tokens.success.srgb);
|
|
257
|
-
case 'error':
|
|
258
|
-
return srgbToHex(tokens.error.srgb);
|
|
259
|
-
case 'warning':
|
|
260
|
-
return srgbToHex(tokens.warning.srgb);
|
|
261
|
-
default:
|
|
262
|
-
return srgbToHex(tokens.textPrimary.srgb);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
246
|
+
const paletteTokens = getPaletteTokens(semantic, tokens);
|
|
265
247
|
|
|
266
248
|
// PRIMARY VARIANT: Filled background
|
|
267
249
|
if (variant === 'primary') {
|
|
268
250
|
if (semantic === 'neutral') {
|
|
269
|
-
// Neutral primary - uses backgroundInteractive for consistent contrast across elevations
|
|
270
|
-
const bg = getNeutralPrimaryBg(tokens);
|
|
251
|
+
// Neutral primary - uses backgroundInteractive tokens for consistent contrast across elevations
|
|
271
252
|
return {
|
|
272
|
-
bg,
|
|
273
|
-
|
|
253
|
+
bg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
254
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
255
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveActive.srgb),
|
|
274
256
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
275
257
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
276
258
|
borderWidth: 1,
|
|
277
|
-
borderColor: 'transparent',
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (semantic === 'accent') {
|
|
282
|
-
// Accent primary = old primary (interactive bg, contrast text)
|
|
283
|
-
return {
|
|
284
|
-
bg: srgbToHex(tokens.interactive.srgb),
|
|
285
|
-
pressedBg: srgbToHex(tokens.interactiveActive.srgb),
|
|
286
|
-
textColor: srgbToHex(tokens.background.srgb), // Contrast inversion
|
|
287
|
-
iconColor: srgbToHex(tokens.background.srgb),
|
|
288
|
-
borderWidth: 1,
|
|
289
|
-
borderColor: 'transparent', // Invisible border for consistent sizing
|
|
259
|
+
borderColor: 'transparent',
|
|
290
260
|
};
|
|
291
261
|
}
|
|
292
262
|
|
|
293
|
-
// Semantic primary (success, error, warning)
|
|
294
|
-
const semanticColor = getSemanticColor();
|
|
263
|
+
// Semantic primary (accent, success, error, warning) — uses palette fill tokens
|
|
295
264
|
return {
|
|
296
|
-
bg:
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
265
|
+
bg: srgbToHex(paletteTokens!.fill.srgb),
|
|
266
|
+
hoveredBg: srgbToHex(paletteTokens!.fillHover.srgb),
|
|
267
|
+
pressedBg: srgbToHex(paletteTokens!.fillActive.srgb),
|
|
268
|
+
textColor: srgbToHex(paletteTokens!.onFill.srgb),
|
|
269
|
+
iconColor: srgbToHex(paletteTokens!.onFill.srgb),
|
|
300
270
|
borderWidth: 1,
|
|
301
|
-
borderColor: 'transparent',
|
|
271
|
+
borderColor: 'transparent',
|
|
302
272
|
};
|
|
303
273
|
}
|
|
304
274
|
|
|
305
275
|
// SECONDARY VARIANT: Outlined (border + subtle background for non-neutral)
|
|
306
276
|
if (variant === 'secondary') {
|
|
307
277
|
if (semantic === 'neutral') {
|
|
308
|
-
//
|
|
278
|
+
// Shifted action scale: transparent → 01 (hover) → 02 (pressed)
|
|
309
279
|
return {
|
|
310
280
|
bg: 'transparent',
|
|
311
|
-
|
|
281
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
282
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
312
283
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
313
284
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
314
285
|
borderWidth: 1,
|
|
@@ -316,47 +287,49 @@ function getVariantColorsForState(
|
|
|
316
287
|
};
|
|
317
288
|
}
|
|
318
289
|
|
|
319
|
-
// Semantic secondary
|
|
320
|
-
const semanticColor = getSemanticColor();
|
|
290
|
+
// Semantic secondary — uses palette surface tokens for subtle bg
|
|
321
291
|
return {
|
|
322
|
-
bg:
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
292
|
+
bg: srgbToHex(paletteTokens!.background.srgb),
|
|
293
|
+
hoveredBg: srgbToHex(paletteTokens!.backgroundInteractive.srgb),
|
|
294
|
+
pressedBg: srgbToHex(paletteTokens!.backgroundInteractiveHover.srgb),
|
|
295
|
+
textColor: srgbToHex(paletteTokens!.fill.srgb),
|
|
296
|
+
iconColor: srgbToHex(paletteTokens!.fill.srgb),
|
|
326
297
|
borderWidth: 1,
|
|
327
|
-
borderColor: 'transparent',
|
|
298
|
+
borderColor: 'transparent',
|
|
328
299
|
};
|
|
329
300
|
}
|
|
330
301
|
|
|
331
302
|
// TERTIARY VARIANT: Ghost (text-only, no visible border)
|
|
332
303
|
if (variant === 'tertiary') {
|
|
333
304
|
if (semantic === 'neutral') {
|
|
334
|
-
//
|
|
305
|
+
// Shifted action scale: transparent → 01 (hover) → 02 (pressed)
|
|
335
306
|
return {
|
|
336
307
|
bg: 'transparent',
|
|
337
|
-
|
|
308
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
309
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
338
310
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
339
311
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
340
312
|
borderWidth: 1,
|
|
341
|
-
borderColor: 'transparent',
|
|
313
|
+
borderColor: 'transparent',
|
|
342
314
|
};
|
|
343
315
|
}
|
|
344
316
|
|
|
345
|
-
// Semantic tertiary
|
|
346
|
-
const semanticColor = getSemanticColor();
|
|
317
|
+
// Semantic tertiary — uses palette surface tokens for hover/pressed
|
|
347
318
|
return {
|
|
348
319
|
bg: 'transparent',
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
320
|
+
hoveredBg: srgbToHex(paletteTokens!.background.srgb),
|
|
321
|
+
pressedBg: srgbToHex(paletteTokens!.backgroundInteractive.srgb),
|
|
322
|
+
textColor: srgbToHex(paletteTokens!.fill.srgb),
|
|
323
|
+
iconColor: srgbToHex(paletteTokens!.fill.srgb),
|
|
352
324
|
borderWidth: 1,
|
|
353
|
-
borderColor: 'transparent',
|
|
325
|
+
borderColor: 'transparent',
|
|
354
326
|
};
|
|
355
327
|
}
|
|
356
328
|
|
|
357
329
|
// Fallback (should never reach here with proper types)
|
|
358
330
|
return {
|
|
359
331
|
bg: 'transparent',
|
|
332
|
+
hoveredBg: 'transparent',
|
|
360
333
|
pressedBg: 'transparent',
|
|
361
334
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
362
335
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
@@ -70,7 +70,7 @@ export function Button({
|
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
72
|
<Pressable disabled={disabled} {...pressableProps}>
|
|
73
|
-
{({ pressed }) => (
|
|
73
|
+
{({ pressed, hovered }: { pressed: boolean; hovered?: boolean }) => (
|
|
74
74
|
// Wrapper handles layout: direction, gap, alignment (padding via style)
|
|
75
75
|
<Wrapper
|
|
76
76
|
direction="horizontal"
|
|
@@ -80,7 +80,11 @@ export function Button({
|
|
|
80
80
|
style={[
|
|
81
81
|
{
|
|
82
82
|
...padding, // Asymmetric horizontal padding for text optical balance
|
|
83
|
-
backgroundColor: pressed && !disabled
|
|
83
|
+
backgroundColor: pressed && !disabled
|
|
84
|
+
? variantColors.pressedBg
|
|
85
|
+
: hovered && !disabled
|
|
86
|
+
? variantColors.hoveredBg
|
|
87
|
+
: variantColors.bg,
|
|
84
88
|
borderRadius: sizeTokens.borderRadius,
|
|
85
89
|
borderWidth: variantColors.borderWidth, // Always 1 for consistent sizing
|
|
86
90
|
borderColor: variantColors.borderColor || 'transparent',
|
|
@@ -80,7 +80,7 @@ export function SelectOptionRow({
|
|
|
80
80
|
},
|
|
81
81
|
isSelected && {
|
|
82
82
|
fontWeight: tokens.typography.weight.semibold as any,
|
|
83
|
-
color: srgbToHex(tokens.
|
|
83
|
+
color: srgbToHex(tokens.accent.fill.srgb),
|
|
84
84
|
},
|
|
85
85
|
option.disabled && {
|
|
86
86
|
color: srgbToHex(tokens.textSecondary.srgb),
|
|
@@ -95,7 +95,7 @@ export function SelectOptionRow({
|
|
|
95
95
|
<Icon
|
|
96
96
|
name="check"
|
|
97
97
|
size={fontSize}
|
|
98
|
-
color={srgbToHex(tokens.
|
|
98
|
+
color={srgbToHex(tokens.accent.fill.srgb)}
|
|
99
99
|
/>
|
|
100
100
|
</View>
|
|
101
101
|
)}
|
|
@@ -30,7 +30,7 @@ export function getToggleStyles(
|
|
|
30
30
|
height: TRACK_HEIGHT,
|
|
31
31
|
borderRadius: TRACK_HEIGHT / 2,
|
|
32
32
|
backgroundColor: value
|
|
33
|
-
? srgbToHex(tokens.
|
|
33
|
+
? srgbToHex(tokens.accent.fill.srgb)
|
|
34
34
|
: srgbToHex(tokens.border.srgb),
|
|
35
35
|
justifyContent: 'center',
|
|
36
36
|
paddingHorizontal: THUMB_OFFSET,
|
|
@@ -52,7 +52,7 @@ export function getColorScaleSliderStyles(tokens: ResolvedTokens, disabled: bool
|
|
|
52
52
|
fontFamily: tokens.typography.fonts.default,
|
|
53
53
|
fontSize: tokens.typography.size.xs,
|
|
54
54
|
fontWeight: tokens.typography.weight.medium as any,
|
|
55
|
-
color: srgbToHex(tokens.error.srgb),
|
|
55
|
+
color: srgbToHex(tokens.error.fill.srgb),
|
|
56
56
|
},
|
|
57
57
|
});
|
|
58
58
|
}
|
|
@@ -60,14 +60,14 @@ export function getSliderStyles(tokens: ResolvedTokens, disabled: boolean) {
|
|
|
60
60
|
left: 0,
|
|
61
61
|
height: TRACK_HEIGHT,
|
|
62
62
|
borderRadius: TRACK_HEIGHT / 2,
|
|
63
|
-
backgroundColor: srgbToHex(tokens.
|
|
63
|
+
backgroundColor: srgbToHex(tokens.accent.fill.srgb),
|
|
64
64
|
},
|
|
65
65
|
thumb: {
|
|
66
66
|
position: 'absolute',
|
|
67
67
|
width: THUMB_SIZE,
|
|
68
68
|
height: THUMB_SIZE,
|
|
69
69
|
borderRadius: THUMB_SIZE / 2,
|
|
70
|
-
backgroundColor: srgbToHex(tokens.
|
|
70
|
+
backgroundColor: srgbToHex(tokens.accent.fill.srgb),
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
export { NewtoneProvider, useNewtoneTheme } from './theme/NewtoneProvider';
|
|
3
3
|
export type {
|
|
4
4
|
ColorMode,
|
|
5
|
-
ThemeName,
|
|
6
5
|
ElevationLevel,
|
|
7
6
|
FrameElevation,
|
|
8
|
-
ThemeMapping,
|
|
9
7
|
ColorSystemConfig,
|
|
10
8
|
NewtoneThemeConfig,
|
|
11
9
|
NewtoneThemeContext,
|
|
12
10
|
FontConfig,
|
|
11
|
+
TokenOverrides,
|
|
13
12
|
} from './theme/types';
|
|
14
13
|
export { useFrameContext } from './theme/FrameContext';
|
|
15
14
|
export type { FrameContextValue } from './theme/FrameContext';
|
|
@@ -17,8 +16,16 @@ export { DEFAULT_THEME_CONFIG } from './theme/defaults';
|
|
|
17
16
|
|
|
18
17
|
// Tokens
|
|
19
18
|
export { useTokens } from './tokens/useTokens';
|
|
20
|
-
export {
|
|
21
|
-
|
|
19
|
+
export {
|
|
20
|
+
computeTokens,
|
|
21
|
+
NEUTRAL_DEFAULTS,
|
|
22
|
+
ACCENT_DEFAULTS,
|
|
23
|
+
SUCCESS_DEFAULTS,
|
|
24
|
+
WARNING_DEFAULTS,
|
|
25
|
+
ERROR_DEFAULTS,
|
|
26
|
+
} from './tokens/computeTokens';
|
|
27
|
+
export type { PaletteDefaults } from './tokens/computeTokens';
|
|
28
|
+
export type { ResolvedTokens, PaletteTokens } from './tokens/types';
|
|
22
29
|
|
|
23
30
|
// Composite Components
|
|
24
31
|
export { Button } from './composites/actions/Button/Button';
|
|
@@ -61,7 +61,7 @@ function toElevationLevel(frameElevation: FrameElevation): ElevationLevel {
|
|
|
61
61
|
* // Basic layout
|
|
62
62
|
* <Frame direction="horizontal" gap="md" padding="lg" align="center">
|
|
63
63
|
* <Button onPress={() => {}}>Save</Button>
|
|
64
|
-
* <Button variant="
|
|
64
|
+
* <Button variant="tertiary" onPress={() => {}}>Cancel</Button>
|
|
65
65
|
* </Frame>
|
|
66
66
|
* ```
|
|
67
67
|
*
|
|
@@ -69,7 +69,6 @@ function toElevationLevel(frameElevation: FrameElevation): ElevationLevel {
|
|
|
69
69
|
* ```tsx
|
|
70
70
|
* // Card-like frame
|
|
71
71
|
* <Frame
|
|
72
|
-
* theme="primary"
|
|
73
72
|
* elevation={2}
|
|
74
73
|
* radius="lg"
|
|
75
74
|
* padding="xl"
|
|
@@ -92,8 +91,7 @@ function toElevationLevel(frameElevation: FrameElevation): ElevationLevel {
|
|
|
92
91
|
*/
|
|
93
92
|
export function Frame({
|
|
94
93
|
children,
|
|
95
|
-
//
|
|
96
|
-
theme,
|
|
94
|
+
// Elevation
|
|
97
95
|
elevation,
|
|
98
96
|
// Layout
|
|
99
97
|
layout,
|
|
@@ -132,15 +130,11 @@ export function Frame({
|
|
|
132
130
|
// Style override
|
|
133
131
|
style,
|
|
134
132
|
}: FrameProps) {
|
|
135
|
-
// Read the global theme configuration
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
// Read the theme/elevation from the nearest parent Frame (if nested).
|
|
133
|
+
// Read the global theme configuration and current color mode (light/dark).
|
|
134
|
+
const { config, mode } = useNewtoneTheme();
|
|
135
|
+
// Read the elevation from the nearest parent Frame (if nested).
|
|
139
136
|
const parentFrameCtx = useFrameContext();
|
|
140
137
|
|
|
141
|
-
// Decide which theme to use. Priority: this Frame's prop > parent Frame > NewtoneProvider.
|
|
142
|
-
const resolvedTheme = theme ?? parentFrameCtx?.theme ?? providerTheme;
|
|
143
|
-
|
|
144
138
|
// The user-facing elevation (-2 to 2) controls visual depth (shadows, background).
|
|
145
139
|
const resolvedFrameElevation: FrameElevation = elevation ?? 0;
|
|
146
140
|
|
|
@@ -156,19 +150,17 @@ export function Frame({
|
|
|
156
150
|
// so it needs to compute fresh tokens from the resolved theme/elevation.
|
|
157
151
|
// Wrapped in useMemo so it only recalculates when the theme/mode/elevation changes.
|
|
158
152
|
const tokens = useMemo(() => {
|
|
159
|
-
const themeMapping = config.themes[resolvedTheme];
|
|
160
153
|
return computeTokens(
|
|
161
154
|
config.colorSystem,
|
|
162
155
|
mode,
|
|
163
|
-
themeMapping,
|
|
164
156
|
resolvedElevation,
|
|
165
|
-
config.elevation.offsets,
|
|
166
157
|
config.spacing,
|
|
167
158
|
config.radius,
|
|
168
159
|
config.typography,
|
|
169
160
|
config.icons,
|
|
161
|
+
config.tokenOverrides,
|
|
170
162
|
);
|
|
171
|
-
}, [config, mode,
|
|
163
|
+
}, [config, mode, resolvedElevation]);
|
|
172
164
|
|
|
173
165
|
// Calculate all visual styles (background, layout, border, shadow, etc.).
|
|
174
166
|
// Only recalculates when one of the style-related props changes.
|
|
@@ -208,8 +200,8 @@ export function Frame({
|
|
|
208
200
|
// This is the value that child components will inherit via FrameContext.
|
|
209
201
|
// Any nested Frame, Text, Icon, etc. will read this theme and elevation.
|
|
210
202
|
const contextValue = useMemo(
|
|
211
|
-
() => ({
|
|
212
|
-
[
|
|
203
|
+
() => ({ elevation: resolvedElevation, tokens }),
|
|
204
|
+
[resolvedElevation, tokens],
|
|
213
205
|
);
|
|
214
206
|
|
|
215
207
|
// Some styles only work on web browsers (CSS grid, inset shadows).
|
|
@@ -241,7 +233,7 @@ export function Frame({
|
|
|
241
233
|
const focusRingStyle = isFocusVisible && !disabled ? {
|
|
242
234
|
outlineWidth: 2,
|
|
243
235
|
outlineStyle: 'solid',
|
|
244
|
-
outlineColor: srgbToHex(tokens.
|
|
236
|
+
outlineColor: srgbToHex(tokens.accent.fill.srgb),
|
|
245
237
|
outlineOffset: 2,
|
|
246
238
|
} as unknown as ViewStyle : undefined; // web-only
|
|
247
239
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { View, ViewStyle, GestureResponderEvent } from 'react-native';
|
|
2
|
-
import type {
|
|
2
|
+
import type { FrameElevation } from '../../theme/types';
|
|
3
3
|
|
|
4
4
|
// ── Spacing Types ──────────────────────────────────────────────
|
|
5
5
|
|
|
@@ -115,14 +115,14 @@ export type Justification = 'start' | 'center' | 'end' | 'between' | 'around' |
|
|
|
115
115
|
* // Horizontal toolbar with consistent spacing
|
|
116
116
|
* <Frame direction="horizontal" gap="md" padding="lg" align="center">
|
|
117
117
|
* <Button onPress={() => {}}>Save</Button>
|
|
118
|
-
* <Button variant="
|
|
118
|
+
* <Button variant="tertiary" onPress={() => {}}>Cancel</Button>
|
|
119
119
|
* </Frame>
|
|
120
120
|
* ```
|
|
121
121
|
*
|
|
122
122
|
* @example
|
|
123
123
|
* ```tsx
|
|
124
|
-
* // Elevated card
|
|
125
|
-
* <Frame
|
|
124
|
+
* // Elevated card
|
|
125
|
+
* <Frame elevation={2} radius="lg" padding="xl" bordered>
|
|
126
126
|
* <Text>Elevated card content</Text>
|
|
127
127
|
* </Frame>
|
|
128
128
|
* ```
|
|
@@ -142,19 +142,7 @@ export interface FrameProps {
|
|
|
142
142
|
*/
|
|
143
143
|
readonly children: React.ReactNode;
|
|
144
144
|
|
|
145
|
-
// ──
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Theme override for this frame and all descendants.
|
|
149
|
-
* When omitted, inherits from parent Frame or NewtoneProvider.
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* ```tsx
|
|
153
|
-
* <Frame theme="primary"> // Blue-ish surface
|
|
154
|
-
* <Frame theme="strong"> // High-contrast surface
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
readonly theme?: ThemeName;
|
|
145
|
+
// ── Elevation ──
|
|
158
146
|
|
|
159
147
|
/**
|
|
160
148
|
* Surface elevation: controls background lightness and shadow.
|
|
@@ -3,15 +3,25 @@ import { Text as RNText } from 'react-native';
|
|
|
3
3
|
import type { TextStyle } from 'react-native';
|
|
4
4
|
import { srgbToHex } from 'newtone';
|
|
5
5
|
import { useTokens } from '../../tokens/useTokens';
|
|
6
|
+
import type { UseTokensResult } from '../../tokens/useTokens';
|
|
6
7
|
import type { TextProps, TextColor } from './Text.types';
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Resolve a semantic text color to a hex string from the current tokens.
|
|
11
|
+
* Neutral text colors are top-level; palette colors use nested PaletteTokens.fill.
|
|
12
|
+
*/
|
|
13
|
+
function resolveTextColor(color: TextColor, tokens: UseTokensResult): string {
|
|
14
|
+
switch (color) {
|
|
15
|
+
case 'primary': return srgbToHex(tokens.textPrimary.srgb);
|
|
16
|
+
case 'secondary': return srgbToHex(tokens.textSecondary.srgb);
|
|
17
|
+
case 'tertiary': return srgbToHex(tokens.textTertiary.srgb);
|
|
18
|
+
case 'disabled': return srgbToHex(tokens.textDisabled.srgb);
|
|
19
|
+
case 'accent': return srgbToHex(tokens.accent.fill.srgb);
|
|
20
|
+
case 'success': return srgbToHex(tokens.success.fill.srgb);
|
|
21
|
+
case 'warning': return srgbToHex(tokens.warning.fill.srgb);
|
|
22
|
+
case 'error': return srgbToHex(tokens.error.fill.srgb);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
15
25
|
|
|
16
26
|
/**
|
|
17
27
|
* Token-aware text primitive.
|
|
@@ -61,7 +71,7 @@ export function Text({
|
|
|
61
71
|
// Font weight is stored as a number (e.g. 400, 600) but React Native expects a string.
|
|
62
72
|
fontWeight: String(tokens.typography.weight[weight]) as TextStyle['fontWeight'],
|
|
63
73
|
// Convert the theme color from internal sRGB format to a hex string (e.g. '#1a1a1a').
|
|
64
|
-
color:
|
|
74
|
+
color: resolveTextColor(color, tokens),
|
|
65
75
|
// Line height = font size × multiplier (e.g. 16px × 1.5 = 24px line height).
|
|
66
76
|
lineHeight: fontSize * tokens.typography.lineHeight[lineHeight],
|
|
67
77
|
textAlign: align,
|
|
@@ -8,7 +8,7 @@ export type TextSize = 'xs' | 'sm' | 'base' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
|
8
8
|
export type TextWeight = 'regular' | 'medium' | 'semibold' | 'bold';
|
|
9
9
|
|
|
10
10
|
/** Semantic text color tokens — resolved from the current theme's token palette. */
|
|
11
|
-
export type TextColor = 'primary' | 'secondary' | '
|
|
11
|
+
export type TextColor = 'primary' | 'secondary' | 'tertiary' | 'disabled' | 'accent' | 'success' | 'warning' | 'error';
|
|
12
12
|
|
|
13
13
|
/** Font family tokens — maps to `tokens.typography.fonts.*` font stacks. */
|
|
14
14
|
export type TextFont = 'default' | 'display' | 'mono';
|
|
@@ -58,9 +58,14 @@ export interface TextProps {
|
|
|
58
58
|
/**
|
|
59
59
|
* Semantic color token.
|
|
60
60
|
*
|
|
61
|
-
* - `'primary'` — Main text color
|
|
62
|
-
* - `'secondary'` — Subdued/muted text
|
|
63
|
-
* - `'
|
|
61
|
+
* - `'primary'` — Main text color, high contrast
|
|
62
|
+
* - `'secondary'` — Subdued/muted text (captions, labels)
|
|
63
|
+
* - `'tertiary'` — Hints, placeholders
|
|
64
|
+
* - `'disabled'` — Disabled text elements
|
|
65
|
+
* - `'accent'` — Accent palette color for links/actions
|
|
66
|
+
* - `'success'` — Success palette color for positive indicators
|
|
67
|
+
* - `'warning'` — Warning palette color for caution indicators
|
|
68
|
+
* - `'error'` — Error palette color for destructive/error indicators
|
|
64
69
|
*
|
|
65
70
|
* @default 'primary'
|
|
66
71
|
*/
|
|
@@ -18,7 +18,7 @@ import { useTokens } from '../../tokens/useTokens';
|
|
|
18
18
|
* ```tsx
|
|
19
19
|
* <Wrapper direction="horizontal" gap="md" align="center">
|
|
20
20
|
* <Button onPress={() => {}}>Save</Button>
|
|
21
|
-
* <Button variant="
|
|
21
|
+
* <Button variant="tertiary" onPress={() => {}}>Cancel</Button>
|
|
22
22
|
* </Wrapper>
|
|
23
23
|
* ```
|
|
24
24
|
*
|
|
@@ -23,7 +23,7 @@ import type {
|
|
|
23
23
|
* // Horizontal row with spacing
|
|
24
24
|
* <Wrapper direction="horizontal" gap="md" align="center">
|
|
25
25
|
* <Button onPress={() => {}}>Save</Button>
|
|
26
|
-
* <Button variant="
|
|
26
|
+
* <Button variant="tertiary" onPress={() => {}}>Cancel</Button>
|
|
27
27
|
* </Wrapper>
|
|
28
28
|
* ```
|
|
29
29
|
*
|