@newtonedev/components 0.1.5 → 0.1.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.
- 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 +603 -249
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +599 -251
- 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/Icon/Icon.d.ts +1 -1
- package/dist/primitives/Icon/Icon.d.ts.map +1 -1
- package/dist/primitives/Icon/Icon.types.d.ts +7 -12
- package/dist/primitives/Icon/Icon.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/icons.d.ts +7 -0
- package/dist/registry/icons.d.ts.map +1 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/registry.d.ts.map +1 -1
- package/dist/registry/types.d.ts +1 -1
- package/dist/registry/types.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 +13 -4
- package/src/primitives/Frame/Frame.tsx +10 -18
- package/src/primitives/Frame/Frame.types.ts +5 -17
- package/src/primitives/Icon/Icon.tsx +4 -6
- package/src/primitives/Icon/Icon.types.ts +7 -14
- 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/icons.ts +111 -0
- package/src/registry/index.ts +3 -0
- package/src/registry/registry.ts +40 -24
- package/src/registry/types.ts +1 -1
- 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
package/src/tokens/types.ts
CHANGED
|
@@ -1,9 +1,59 @@
|
|
|
1
1
|
import type { ColorResult } from 'newtone';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Complete token set for a non-neutral palette (accent, success, warning, error).
|
|
5
|
+
*
|
|
6
|
+
* Fill tokens use the palette's key NV position (user-chosen or WCAG auto-derived).
|
|
7
|
+
* Surface tokens use standard positions from PaletteDefaults, rendered in the palette's hue/saturation.
|
|
8
|
+
*/
|
|
9
|
+
export interface PaletteTokens {
|
|
10
|
+
// --- Fill: the palette's key color for prominent surfaces ---
|
|
11
|
+
/** Key color at the palette's keyNormalizedValue (used for primary Button fills, badges, indicators) */
|
|
12
|
+
readonly fill: ColorResult;
|
|
13
|
+
/** Key color shifted for hover state */
|
|
14
|
+
readonly fillHover: ColorResult;
|
|
15
|
+
/** Key color shifted for pressed/active state */
|
|
16
|
+
readonly fillActive: ColorResult;
|
|
17
|
+
/** High-contrast color for text/icons on top of fill (auto: dark text on light fills, light on dark) */
|
|
18
|
+
readonly onFill: ColorResult;
|
|
19
|
+
|
|
20
|
+
// --- Surface: subtle palette-tinted backgrounds ---
|
|
21
|
+
/** Palette-tinted background at current elevation */
|
|
22
|
+
readonly background: ColorResult;
|
|
23
|
+
/** Palette-tinted elevated surface */
|
|
24
|
+
readonly backgroundElevated: ColorResult;
|
|
25
|
+
/** Palette-tinted sunken surface */
|
|
26
|
+
readonly backgroundSunken: ColorResult;
|
|
27
|
+
|
|
28
|
+
// --- Interactive surface: interactive elements on palette surfaces ---
|
|
29
|
+
/** Interactive element background within palette surface */
|
|
30
|
+
readonly backgroundInteractive: ColorResult;
|
|
31
|
+
/** Hover state for interactive elements within palette surface */
|
|
32
|
+
readonly backgroundInteractiveHover: ColorResult;
|
|
33
|
+
/** Pressed/active state for interactive elements within palette surface */
|
|
34
|
+
readonly backgroundInteractiveActive: ColorResult;
|
|
35
|
+
|
|
36
|
+
// --- Text: palette-hued text on neutral backgrounds ---
|
|
37
|
+
/** High-contrast palette-colored text */
|
|
38
|
+
readonly textPrimary: ColorResult;
|
|
39
|
+
/** Medium-contrast palette-colored text */
|
|
40
|
+
readonly textSecondary: ColorResult;
|
|
41
|
+
/** Low-contrast palette-colored text */
|
|
42
|
+
readonly textTertiary: ColorResult;
|
|
43
|
+
/** Disabled palette-colored text */
|
|
44
|
+
readonly textDisabled: ColorResult;
|
|
45
|
+
|
|
46
|
+
// --- Border ---
|
|
47
|
+
/** Palette-colored border */
|
|
48
|
+
readonly border: ColorResult;
|
|
49
|
+
}
|
|
50
|
+
|
|
3
51
|
/**
|
|
4
52
|
* Resolved design tokens for a specific mode/theme/elevation combination
|
|
5
53
|
*/
|
|
6
54
|
export interface ResolvedTokens {
|
|
55
|
+
// --- Neutral palette (top-level for convenience — most-used palette) ---
|
|
56
|
+
|
|
7
57
|
/** Background color for the current surface */
|
|
8
58
|
readonly background: ColorResult;
|
|
9
59
|
/** Background color for elevated surfaces (cards, modals) */
|
|
@@ -12,32 +62,40 @@ export interface ResolvedTokens {
|
|
|
12
62
|
readonly backgroundSunken: ColorResult;
|
|
13
63
|
/**
|
|
14
64
|
* Background color for interactive components with neutral backgrounds.
|
|
15
|
-
* Uses a fixed
|
|
65
|
+
* Uses a fixed NV offset from current background to ensure
|
|
16
66
|
* consistent visual contrast across all elevations (-2 to 2).
|
|
17
67
|
*
|
|
18
|
-
* Use for: Button (neutral primary), and future components with neutral filled backgrounds.
|
|
68
|
+
* Use for: Button (neutral primary enabled), and future components with neutral filled backgrounds.
|
|
19
69
|
* Don't use for: Semantic variants (accent/success/error/warning), transparent backgrounds,
|
|
20
70
|
* or primitives (Frame/Wrapper/Text/Icon already handle elevation correctly).
|
|
21
71
|
*/
|
|
22
72
|
readonly backgroundInteractive: ColorResult;
|
|
23
|
-
/**
|
|
73
|
+
/** Hover state for neutral interactive components (enabled + hoverShift) */
|
|
74
|
+
readonly backgroundInteractiveHover: ColorResult;
|
|
75
|
+
/** Pressed/active state for neutral interactive components (enabled + activeShift) */
|
|
76
|
+
readonly backgroundInteractiveActive: ColorResult;
|
|
77
|
+
/** Primary text color (high contrast for body text, 4.5:1 default) */
|
|
24
78
|
readonly textPrimary: ColorResult;
|
|
25
|
-
/** Secondary text color (lower contrast for captions, labels) */
|
|
79
|
+
/** Secondary text color (lower contrast for captions, labels, 3.0:1 default) */
|
|
26
80
|
readonly textSecondary: ColorResult;
|
|
27
|
-
/**
|
|
28
|
-
readonly
|
|
29
|
-
/**
|
|
30
|
-
readonly
|
|
31
|
-
/** Interactive element active/pressed state */
|
|
32
|
-
readonly interactiveActive: ColorResult;
|
|
81
|
+
/** Tertiary text color (hints, placeholders, 2.0:1 default) */
|
|
82
|
+
readonly textTertiary: ColorResult;
|
|
83
|
+
/** Disabled text color (disabled elements, 1.5:1 default) */
|
|
84
|
+
readonly textDisabled: ColorResult;
|
|
33
85
|
/** Border color for subtle separators */
|
|
34
86
|
readonly border: ColorResult;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
87
|
+
|
|
88
|
+
// --- Per-palette token sets ---
|
|
89
|
+
|
|
90
|
+
/** Accent palette tokens (palette index 1) — interactive elements, brand color */
|
|
91
|
+
readonly accent: PaletteTokens;
|
|
92
|
+
/** Success palette tokens (palette index 2) — positive state indicators */
|
|
93
|
+
readonly success: PaletteTokens;
|
|
94
|
+
/** Warning palette tokens (palette index 3) — caution state indicators */
|
|
95
|
+
readonly warning: PaletteTokens;
|
|
96
|
+
/** Error palette tokens (palette index 4) — destructive/error state indicators */
|
|
97
|
+
readonly error: PaletteTokens;
|
|
98
|
+
|
|
41
99
|
/** Spacing tokens for paddings, gaps, and margins.
|
|
42
100
|
* Token names represent pixel values at Medium (8px) spacing preset.
|
|
43
101
|
* Actual values scale based on the selected spacing preset. */
|
package/src/tokens/useTokens.ts
CHANGED
|
@@ -21,59 +21,42 @@ export interface UseTokensResult extends ResolvedTokens {
|
|
|
21
21
|
* 2. FrameContext values (from nearest parent Frame) are used when elevation is omitted
|
|
22
22
|
* 3. Falls back to NewtoneProvider theme + elevation 1
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* When inside a Frame and no explicit elevation override is given, reuses the
|
|
25
|
+
* Frame's pre-computed tokens to avoid redundant computeTokens calls.
|
|
25
26
|
*
|
|
26
27
|
* @param elevation - Elevation level (0=sunken, 1=default, 2=elevated).
|
|
27
28
|
* When omitted, reads from FrameContext or defaults to 1.
|
|
28
29
|
* @returns Resolved design tokens with all necessary colors + resolved elevation
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```tsx
|
|
32
|
-
* // Inside a <Frame theme="primary" elevation={1}>:
|
|
33
|
-
* function MyComponent() {
|
|
34
|
-
* const tokens = useTokens(); // Gets primary theme, elevation 2 (mapped from Frame's 1)
|
|
35
|
-
* return (
|
|
36
|
-
* <View style={{ backgroundColor: srgbToHex(tokens.background.srgb) }} />
|
|
37
|
-
* );
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```tsx
|
|
43
|
-
* // Elevation-aware component:
|
|
44
|
-
* function ElevationAwareButton() {
|
|
45
|
-
* const tokens = useTokens();
|
|
46
|
-
* // Use tokens.elevation to make color decisions
|
|
47
|
-
* const bg = tokens.elevation === 2 ? tokens.background : tokens.backgroundSunken;
|
|
48
|
-
* return <View style={{ backgroundColor: srgbToHex(bg.srgb) }} />;
|
|
49
|
-
* }
|
|
50
|
-
* ```
|
|
51
30
|
*/
|
|
52
31
|
export function useTokens(elevation?: ElevationLevel): UseTokensResult {
|
|
53
|
-
const { config, mode
|
|
32
|
+
const { config, mode } = useNewtoneTheme();
|
|
54
33
|
const frameCtx = useFrameContext();
|
|
55
34
|
|
|
56
|
-
// Resolve theme: FrameContext overrides provider
|
|
57
|
-
const resolvedTheme = frameCtx?.theme ?? providerTheme;
|
|
58
|
-
|
|
59
35
|
// Resolve elevation: explicit param > FrameContext > default 1
|
|
60
36
|
const resolvedElevation: ElevationLevel = elevation ?? frameCtx?.elevation ?? 1;
|
|
61
37
|
|
|
38
|
+
// Optimization: reuse Frame's pre-computed tokens when elevation matches
|
|
39
|
+
// and no explicit elevation override was given.
|
|
40
|
+
const canReuse = frameCtx !== null
|
|
41
|
+
&& elevation === undefined
|
|
42
|
+
&& frameCtx.elevation === resolvedElevation;
|
|
43
|
+
|
|
62
44
|
return useMemo(() => {
|
|
63
|
-
|
|
45
|
+
if (canReuse) {
|
|
46
|
+
return { ...frameCtx!.tokens, elevation: resolvedElevation };
|
|
47
|
+
}
|
|
48
|
+
|
|
64
49
|
const tokens = computeTokens(
|
|
65
50
|
config.colorSystem,
|
|
66
51
|
mode,
|
|
67
|
-
themeMapping,
|
|
68
52
|
resolvedElevation,
|
|
69
|
-
config.elevation.offsets,
|
|
70
53
|
config.spacing,
|
|
71
54
|
config.radius,
|
|
72
55
|
config.typography,
|
|
73
|
-
config.icons
|
|
56
|
+
config.icons,
|
|
57
|
+
config.tokenOverrides
|
|
74
58
|
);
|
|
75
59
|
|
|
76
|
-
// Return tokens + elevation for elevation-aware components
|
|
77
60
|
return { ...tokens, elevation: resolvedElevation };
|
|
78
|
-
}, [config, mode,
|
|
61
|
+
}, [config, mode, resolvedElevation, canReuse, frameCtx?.tokens]);
|
|
79
62
|
}
|