@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
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React13, { createContext, useState, useMemo, useContext, useEffect, useCallback, useRef } from 'react';
|
|
2
|
-
import { DEFAULT_NEUTRAL_SATURATION, DEFAULT_NEUTRAL_HUE, DEFAULT_ACCENT_SATURATION, DEFAULT_ACCENT_HUE, DEFAULT_SUCCESS_SATURATION, DEFAULT_SUCCESS_HUE, DEFAULT_WARNING_SATURATION, DEFAULT_WARNING_HUE, DEFAULT_ERROR_SATURATION, DEFAULT_ERROR_HUE, getColor,
|
|
2
|
+
import { DEFAULT_NEUTRAL_SATURATION, DEFAULT_NEUTRAL_HUE, DEFAULT_ACCENT_SATURATION, DEFAULT_ACCENT_HUE, DEFAULT_SUCCESS_SATURATION, DEFAULT_SUCCESS_HUE, DEFAULT_WARNING_SATURATION, DEFAULT_WARNING_HUE, DEFAULT_ERROR_SATURATION, DEFAULT_ERROR_HUE, getColor, srgbToHex } from 'newtone';
|
|
3
3
|
import { Text, View, Pressable, TextInput as TextInput$1, ScrollView, PanResponder, Animated, StyleSheet } from 'react-native';
|
|
4
4
|
|
|
5
5
|
// src/theme/NewtoneProvider.tsx
|
|
@@ -17,16 +17,6 @@ var DEFAULT_THEME_CONFIG = {
|
|
|
17
17
|
{ hue: DEFAULT_ERROR_HUE, saturation: DEFAULT_ERROR_SATURATION }
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
|
-
themes: {
|
|
21
|
-
neutral: { paletteIndex: 0, lightModeNv: 0.95, darkModeNv: 0.1 },
|
|
22
|
-
primary: { paletteIndex: 1, lightModeNv: 0.95, darkModeNv: 0.1 },
|
|
23
|
-
secondary: { paletteIndex: 1, lightModeNv: 0.85, darkModeNv: 0.15 },
|
|
24
|
-
strong: { paletteIndex: 0, lightModeNv: 0.1, darkModeNv: 0.95 }
|
|
25
|
-
},
|
|
26
|
-
elevation: {
|
|
27
|
-
offsets: [-0.02, 0, 0.04]
|
|
28
|
-
// [sunken, default, elevated]
|
|
29
|
-
},
|
|
30
20
|
spacing: {
|
|
31
21
|
"00": 0,
|
|
32
22
|
// base * 0
|
|
@@ -190,20 +180,16 @@ var ThemeContext = createContext(null);
|
|
|
190
180
|
function NewtoneProvider({
|
|
191
181
|
config = DEFAULT_THEME_CONFIG,
|
|
192
182
|
initialMode = "light",
|
|
193
|
-
initialTheme = "neutral",
|
|
194
183
|
children
|
|
195
184
|
}) {
|
|
196
185
|
const [mode, setMode] = useState(initialMode);
|
|
197
|
-
const [theme, setTheme] = useState(initialTheme);
|
|
198
186
|
const value = useMemo(
|
|
199
187
|
() => ({
|
|
200
188
|
config,
|
|
201
189
|
mode,
|
|
202
|
-
|
|
203
|
-
setMode,
|
|
204
|
-
setTheme
|
|
190
|
+
setMode
|
|
205
191
|
}),
|
|
206
|
-
[config, mode
|
|
192
|
+
[config, mode]
|
|
207
193
|
);
|
|
208
194
|
return /* @__PURE__ */ React13.createElement(ThemeContext.Provider, { value }, /* @__PURE__ */ React13.createElement(GoogleFontLoader, { fonts: config.typography.fonts }), /* @__PURE__ */ React13.createElement(IconFontLoader, { icons: config.icons }), children);
|
|
209
195
|
}
|
|
@@ -218,19 +204,160 @@ var FrameContext = createContext(null);
|
|
|
218
204
|
function useFrameContext() {
|
|
219
205
|
return useContext(FrameContext);
|
|
220
206
|
}
|
|
207
|
+
var NEUTRAL_DEFAULTS = {
|
|
208
|
+
light: {
|
|
209
|
+
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
210
|
+
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
211
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
212
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
213
|
+
},
|
|
214
|
+
dark: {
|
|
215
|
+
background: { elevated: 0.24, ground: 0.2, sunken: 0.16 },
|
|
216
|
+
text: { primary: 1, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
217
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
218
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
var ACCENT_DEFAULTS = {
|
|
222
|
+
light: {
|
|
223
|
+
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
224
|
+
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
225
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
226
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
227
|
+
},
|
|
228
|
+
dark: {
|
|
229
|
+
background: { elevated: 0.24, ground: 0.2, sunken: 0.16 },
|
|
230
|
+
text: { primary: 1, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
231
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
232
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var SUCCESS_DEFAULTS = {
|
|
236
|
+
light: {
|
|
237
|
+
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
238
|
+
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
239
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
240
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
241
|
+
},
|
|
242
|
+
dark: {
|
|
243
|
+
background: { elevated: 0.24, ground: 0.2, sunken: 0.16 },
|
|
244
|
+
text: { primary: 1, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
245
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
246
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
var WARNING_DEFAULTS = {
|
|
250
|
+
light: {
|
|
251
|
+
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
252
|
+
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
253
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
254
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
255
|
+
},
|
|
256
|
+
dark: {
|
|
257
|
+
background: { elevated: 0.24, ground: 0.2, sunken: 0.16 },
|
|
258
|
+
text: { primary: 1, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
259
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
260
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var ERROR_DEFAULTS = {
|
|
264
|
+
light: {
|
|
265
|
+
background: { elevated: 0, ground: 0.03, sunken: 0.06 },
|
|
266
|
+
text: { primary: 0.9, secondary: 0.7, tertiary: 0.5, disabled: 0.3 },
|
|
267
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
268
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
269
|
+
},
|
|
270
|
+
dark: {
|
|
271
|
+
background: { elevated: 0.24, ground: 0.2, sunken: 0.16 },
|
|
272
|
+
text: { primary: 1, secondary: 0.85, tertiary: 0.7, disabled: 0.55 },
|
|
273
|
+
action: { enabled: 0.04, hovered: 0.06, pressed: 0.08 },
|
|
274
|
+
border: { enabled: 0.08, focused: 0.16, filled: 0.24 }
|
|
275
|
+
}
|
|
276
|
+
};
|
|
221
277
|
function fontConfigToFamily(font) {
|
|
222
278
|
const family = font.family.includes(" ") ? `"${font.family}"` : font.family;
|
|
223
279
|
return `${family}, ${font.fallback}`;
|
|
224
280
|
}
|
|
225
|
-
|
|
281
|
+
var clamp = (n) => Math.max(0, Math.min(1, n));
|
|
282
|
+
function computePaletteTokens(palette, defaults, mode, elevation, dynamicRange, elevationDelta, effectiveTextMode, autoAccentNv, neutralTextPrimary, neutralBgElevated) {
|
|
283
|
+
const modeDefaults = defaults[mode];
|
|
284
|
+
const toEngineNv = (nv) => mode === "light" ? 1 - nv : nv;
|
|
285
|
+
const textToEngineNv = (nv) => effectiveTextMode === "light" ? 1 - nv : nv;
|
|
286
|
+
const colorAt = (engineNv) => getColor(
|
|
287
|
+
palette.hue,
|
|
288
|
+
palette.saturation,
|
|
289
|
+
dynamicRange,
|
|
290
|
+
clamp(engineNv),
|
|
291
|
+
palette.desaturation,
|
|
292
|
+
palette.paletteHueGrading
|
|
293
|
+
);
|
|
294
|
+
const resolveKeyNv = (p) => mode === "dark" ? p.keyNormalizedValueDark : p.keyNormalizedValue;
|
|
295
|
+
const keyNv = resolveKeyNv(palette);
|
|
296
|
+
const fillBaseNv = keyNv ?? autoAccentNv;
|
|
297
|
+
const fillNv = clamp(fillBaseNv + elevationDelta);
|
|
298
|
+
const fill = colorAt(fillNv);
|
|
299
|
+
const hoverDir = effectiveTextMode === "light" ? -modeDefaults.action.hovered : modeDefaults.action.hovered;
|
|
300
|
+
const activeDir = effectiveTextMode === "light" ? -modeDefaults.action.pressed : modeDefaults.action.pressed;
|
|
301
|
+
const fillHover = colorAt(clamp(fillNv + hoverDir));
|
|
302
|
+
const fillActive = colorAt(clamp(fillNv + activeDir));
|
|
303
|
+
const onFill = fill.oklch.L > 0.6 ? neutralTextPrimary : neutralBgElevated;
|
|
304
|
+
const bgNormalized = elevation === 2 ? modeDefaults.background.elevated : elevation === 1 ? modeDefaults.background.ground : modeDefaults.background.sunken;
|
|
305
|
+
const bgNv = clamp(toEngineNv(bgNormalized));
|
|
306
|
+
const background = colorAt(bgNv);
|
|
307
|
+
const backgroundElevated = colorAt(clamp(toEngineNv(modeDefaults.background.elevated)));
|
|
308
|
+
const backgroundSunken = colorAt(clamp(toEngineNv(modeDefaults.background.sunken)));
|
|
309
|
+
const interactiveOffset = modeDefaults.action.enabled;
|
|
310
|
+
const interactiveNv = clamp(bgNv + (effectiveTextMode === "light" ? -interactiveOffset : interactiveOffset));
|
|
311
|
+
const backgroundInteractive = colorAt(interactiveNv);
|
|
312
|
+
const hoverShift = modeDefaults.action.hovered;
|
|
313
|
+
const activeShift = modeDefaults.action.pressed;
|
|
314
|
+
const backgroundInteractiveHover = colorAt(clamp(interactiveNv + (effectiveTextMode === "light" ? -hoverShift : hoverShift)));
|
|
315
|
+
const backgroundInteractiveActive = colorAt(clamp(interactiveNv + (effectiveTextMode === "light" ? -activeShift : activeShift)));
|
|
316
|
+
const textPrimary = colorAt(clamp(textToEngineNv(modeDefaults.text.primary) + elevationDelta));
|
|
317
|
+
const textSecondary = colorAt(clamp(textToEngineNv(modeDefaults.text.secondary) + elevationDelta));
|
|
318
|
+
const textTertiary = colorAt(clamp(textToEngineNv(modeDefaults.text.tertiary) + elevationDelta));
|
|
319
|
+
const textDisabled = colorAt(clamp(textToEngineNv(modeDefaults.text.disabled) + elevationDelta));
|
|
320
|
+
const borderOffset = modeDefaults.border.enabled;
|
|
321
|
+
const borderNv = effectiveTextMode === "light" ? bgNv - borderOffset : bgNv + borderOffset;
|
|
322
|
+
const border = colorAt(clamp(borderNv));
|
|
323
|
+
return {
|
|
324
|
+
fill,
|
|
325
|
+
fillHover,
|
|
326
|
+
fillActive,
|
|
327
|
+
onFill,
|
|
328
|
+
background,
|
|
329
|
+
backgroundElevated,
|
|
330
|
+
backgroundSunken,
|
|
331
|
+
backgroundInteractive,
|
|
332
|
+
backgroundInteractiveHover,
|
|
333
|
+
backgroundInteractiveActive,
|
|
334
|
+
textPrimary,
|
|
335
|
+
textSecondary,
|
|
336
|
+
textTertiary,
|
|
337
|
+
textDisabled,
|
|
338
|
+
border
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
function computeTokens(config, mode, elevation, spacing, radius, typography, icons, tokenOverrides) {
|
|
226
342
|
const { dynamicRange, palettes } = config;
|
|
227
|
-
const palette = palettes[
|
|
343
|
+
const palette = palettes[0];
|
|
228
344
|
if (!palette) {
|
|
229
|
-
throw new Error(
|
|
345
|
+
throw new Error("Neutral palette (index 0) not found");
|
|
230
346
|
}
|
|
231
|
-
const
|
|
232
|
-
const
|
|
233
|
-
const
|
|
347
|
+
const neutralDefaults = NEUTRAL_DEFAULTS[mode];
|
|
348
|
+
const toEngineNv = (nv) => mode === "light" ? 1 - nv : nv;
|
|
349
|
+
const bgElevatedNorm = mode === "light" ? tokenOverrides?.backgroundElevated : tokenOverrides?.backgroundElevatedDark;
|
|
350
|
+
const bgDefaultNorm = mode === "light" ? tokenOverrides?.backgroundDefault : tokenOverrides?.backgroundDefaultDark;
|
|
351
|
+
const bgSunkenNorm = mode === "light" ? tokenOverrides?.backgroundSunken : tokenOverrides?.backgroundSunkenDark;
|
|
352
|
+
const textPrimaryNorm = mode === "light" ? tokenOverrides?.textPrimaryNormalized : tokenOverrides?.textPrimaryNormalizedDark;
|
|
353
|
+
const textSecondaryNorm = mode === "light" ? tokenOverrides?.textSecondaryNormalized : tokenOverrides?.textSecondaryNormalizedDark;
|
|
354
|
+
const textTertiaryNorm = mode === "light" ? tokenOverrides?.textTertiaryNormalized : tokenOverrides?.textTertiaryNormalizedDark;
|
|
355
|
+
const textDisabledNorm = mode === "light" ? tokenOverrides?.textDisabledNormalized : tokenOverrides?.textDisabledNormalizedDark;
|
|
356
|
+
const bgNormalized = elevation === 2 ? bgElevatedNorm ?? neutralDefaults.background.elevated : elevation === 1 ? bgDefaultNorm ?? neutralDefaults.background.ground : bgSunkenNorm ?? neutralDefaults.background.sunken;
|
|
357
|
+
const backgroundNv = clamp(toEngineNv(bgNormalized));
|
|
358
|
+
const elevatedNv = clamp(toEngineNv(bgElevatedNorm ?? neutralDefaults.background.elevated));
|
|
359
|
+
const sunkenNv = clamp(toEngineNv(bgSunkenNorm ?? neutralDefaults.background.sunken));
|
|
360
|
+
const elevationDelta = backgroundNv - elevatedNv;
|
|
234
361
|
const effectiveTextMode = backgroundNv >= 0.5 ? "light" : "dark";
|
|
235
362
|
const background = getColor(
|
|
236
363
|
palette.hue,
|
|
@@ -240,7 +367,6 @@ function computeTokens(config, mode, themeMapping, elevation, elevationOffsets,
|
|
|
240
367
|
palette.desaturation,
|
|
241
368
|
palette.paletteHueGrading
|
|
242
369
|
);
|
|
243
|
-
const elevatedNv = Math.max(0, Math.min(1, baseNv + elevationOffsets[2]));
|
|
244
370
|
const backgroundElevated = getColor(
|
|
245
371
|
palette.hue,
|
|
246
372
|
palette.saturation,
|
|
@@ -249,7 +375,6 @@ function computeTokens(config, mode, themeMapping, elevation, elevationOffsets,
|
|
|
249
375
|
palette.desaturation,
|
|
250
376
|
palette.paletteHueGrading
|
|
251
377
|
);
|
|
252
|
-
const sunkenNv = Math.max(0, Math.min(1, baseNv + elevationOffsets[0]));
|
|
253
378
|
const backgroundSunken = getColor(
|
|
254
379
|
palette.hue,
|
|
255
380
|
palette.saturation,
|
|
@@ -258,8 +383,11 @@ function computeTokens(config, mode, themeMapping, elevation, elevationOffsets,
|
|
|
258
383
|
palette.desaturation,
|
|
259
384
|
palette.paletteHueGrading
|
|
260
385
|
);
|
|
261
|
-
const INTERACTIVE_COMPONENT_OFFSET =
|
|
262
|
-
const
|
|
386
|
+
const INTERACTIVE_COMPONENT_OFFSET = mode === "light" ? tokenOverrides?.interactiveComponentOffset ?? neutralDefaults.action.enabled : tokenOverrides?.interactiveComponentOffsetDark ?? neutralDefaults.action.enabled;
|
|
387
|
+
const HOVER_SHIFT = mode === "light" ? tokenOverrides?.hoverShift ?? neutralDefaults.action.hovered : tokenOverrides?.hoverShiftDark ?? neutralDefaults.action.hovered;
|
|
388
|
+
const ACTIVE_SHIFT = mode === "light" ? tokenOverrides?.activeShift ?? neutralDefaults.action.pressed : tokenOverrides?.activeShiftDark ?? neutralDefaults.action.pressed;
|
|
389
|
+
const BORDER_OFFSET = mode === "light" ? tokenOverrides?.borderOffset ?? neutralDefaults.border.enabled : tokenOverrides?.borderOffsetDark ?? neutralDefaults.border.enabled;
|
|
390
|
+
const interactiveComponentNv = clamp(backgroundNv + (effectiveTextMode === "light" ? -INTERACTIVE_COMPONENT_OFFSET : INTERACTIVE_COMPONENT_OFFSET));
|
|
263
391
|
const backgroundInteractive = getColor(
|
|
264
392
|
palette.hue,
|
|
265
393
|
palette.saturation,
|
|
@@ -268,143 +396,135 @@ function computeTokens(config, mode, themeMapping, elevation, elevationOffsets,
|
|
|
268
396
|
palette.desaturation,
|
|
269
397
|
palette.paletteHueGrading
|
|
270
398
|
);
|
|
271
|
-
const
|
|
399
|
+
const neutralHoverNv = clamp(interactiveComponentNv + (effectiveTextMode === "light" ? -HOVER_SHIFT : HOVER_SHIFT));
|
|
400
|
+
const backgroundInteractiveHover = getColor(
|
|
272
401
|
palette.hue,
|
|
273
402
|
palette.saturation,
|
|
274
403
|
dynamicRange,
|
|
275
|
-
|
|
276
|
-
effectiveTextMode,
|
|
404
|
+
neutralHoverNv,
|
|
277
405
|
palette.desaturation,
|
|
278
|
-
palette.paletteHueGrading
|
|
279
|
-
background
|
|
406
|
+
palette.paletteHueGrading
|
|
280
407
|
);
|
|
281
|
-
const
|
|
408
|
+
const neutralActiveNv = clamp(interactiveComponentNv + (effectiveTextMode === "light" ? -ACTIVE_SHIFT : ACTIVE_SHIFT));
|
|
409
|
+
const backgroundInteractiveActive = getColor(
|
|
282
410
|
palette.hue,
|
|
283
411
|
palette.saturation,
|
|
284
412
|
dynamicRange,
|
|
285
|
-
|
|
286
|
-
effectiveTextMode,
|
|
413
|
+
neutralActiveNv,
|
|
287
414
|
palette.desaturation,
|
|
288
|
-
palette.paletteHueGrading
|
|
289
|
-
background
|
|
415
|
+
palette.paletteHueGrading
|
|
290
416
|
);
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const resolveKeyNv = (p) => mode === "dark" ? p.keyNormalizedValueDark : p.keyNormalizedValue;
|
|
296
|
-
const accentKeyNv = resolveKeyNv(accentPalette);
|
|
297
|
-
const interactive = accentKeyNv !== void 0 ? getColor(
|
|
298
|
-
accentPalette.hue,
|
|
299
|
-
accentPalette.saturation,
|
|
417
|
+
const textToEngineNv = (nv) => effectiveTextMode === "light" ? 1 - nv : nv;
|
|
418
|
+
const textPrimary = getColor(
|
|
419
|
+
palette.hue,
|
|
420
|
+
palette.saturation,
|
|
300
421
|
dynamicRange,
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
)
|
|
305
|
-
|
|
306
|
-
|
|
422
|
+
clamp(textToEngineNv(textPrimaryNorm ?? neutralDefaults.text.primary) + elevationDelta),
|
|
423
|
+
palette.desaturation,
|
|
424
|
+
palette.paletteHueGrading
|
|
425
|
+
);
|
|
426
|
+
const textSecondary = getColor(
|
|
427
|
+
palette.hue,
|
|
428
|
+
palette.saturation,
|
|
307
429
|
dynamicRange,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
accentPalette.paletteHueGrading,
|
|
312
|
-
background
|
|
430
|
+
clamp(textToEngineNv(textSecondaryNorm ?? neutralDefaults.text.secondary) + elevationDelta),
|
|
431
|
+
palette.desaturation,
|
|
432
|
+
palette.paletteHueGrading
|
|
313
433
|
);
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
accentPalette.saturation,
|
|
434
|
+
const textTertiary = getColor(
|
|
435
|
+
palette.hue,
|
|
436
|
+
palette.saturation,
|
|
318
437
|
dynamicRange,
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
438
|
+
clamp(textToEngineNv(textTertiaryNorm ?? neutralDefaults.text.tertiary) + elevationDelta),
|
|
439
|
+
palette.desaturation,
|
|
440
|
+
palette.paletteHueGrading
|
|
322
441
|
);
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
442
|
+
const textDisabled = getColor(
|
|
443
|
+
palette.hue,
|
|
444
|
+
palette.saturation,
|
|
326
445
|
dynamicRange,
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
446
|
+
clamp(textToEngineNv(textDisabledNorm ?? neutralDefaults.text.disabled) + elevationDelta),
|
|
447
|
+
palette.desaturation,
|
|
448
|
+
palette.paletteHueGrading
|
|
330
449
|
);
|
|
331
|
-
const borderNv = effectiveTextMode === "light" ? backgroundNv -
|
|
450
|
+
const borderNv = effectiveTextMode === "light" ? backgroundNv - BORDER_OFFSET : backgroundNv + BORDER_OFFSET;
|
|
332
451
|
const border = getColor(
|
|
333
452
|
palette.hue,
|
|
334
453
|
palette.saturation,
|
|
335
454
|
dynamicRange,
|
|
336
|
-
|
|
455
|
+
clamp(borderNv),
|
|
337
456
|
palette.desaturation,
|
|
338
457
|
palette.paletteHueGrading
|
|
339
458
|
);
|
|
459
|
+
const autoAccentNv = clamp(textToEngineNv(textPrimaryNorm ?? neutralDefaults.text.primary));
|
|
460
|
+
const accentPalette = palettes[1];
|
|
461
|
+
if (!accentPalette) {
|
|
462
|
+
throw new Error("Accent palette (index 1) not found");
|
|
463
|
+
}
|
|
464
|
+
const accent = computePaletteTokens(
|
|
465
|
+
accentPalette,
|
|
466
|
+
ACCENT_DEFAULTS,
|
|
467
|
+
mode,
|
|
468
|
+
elevation,
|
|
469
|
+
dynamicRange,
|
|
470
|
+
elevationDelta,
|
|
471
|
+
effectiveTextMode,
|
|
472
|
+
autoAccentNv,
|
|
473
|
+
textPrimary,
|
|
474
|
+
backgroundElevated
|
|
475
|
+
);
|
|
340
476
|
const successPalette = palettes[2];
|
|
341
477
|
const warningPalette = palettes[3];
|
|
342
478
|
const errorPalette = palettes[4];
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
479
|
+
const success = successPalette ? computePaletteTokens(
|
|
480
|
+
successPalette,
|
|
481
|
+
SUCCESS_DEFAULTS,
|
|
482
|
+
mode,
|
|
483
|
+
elevation,
|
|
347
484
|
dynamicRange,
|
|
348
|
-
|
|
349
|
-
successPalette.desaturation,
|
|
350
|
-
successPalette.paletteHueGrading
|
|
351
|
-
) : getColorByContrast(
|
|
352
|
-
successPalette.hue,
|
|
353
|
-
successPalette.saturation,
|
|
354
|
-
dynamicRange,
|
|
355
|
-
4.5,
|
|
485
|
+
elevationDelta,
|
|
356
486
|
effectiveTextMode,
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
) :
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
warningKeyNv,
|
|
367
|
-
warningPalette.desaturation,
|
|
368
|
-
warningPalette.paletteHueGrading
|
|
369
|
-
) : getColorByContrast(
|
|
370
|
-
warningPalette.hue,
|
|
371
|
-
warningPalette.saturation,
|
|
487
|
+
autoAccentNv,
|
|
488
|
+
textPrimary,
|
|
489
|
+
backgroundElevated
|
|
490
|
+
) : accent;
|
|
491
|
+
const warning = warningPalette ? computePaletteTokens(
|
|
492
|
+
warningPalette,
|
|
493
|
+
WARNING_DEFAULTS,
|
|
494
|
+
mode,
|
|
495
|
+
elevation,
|
|
372
496
|
dynamicRange,
|
|
373
|
-
|
|
497
|
+
elevationDelta,
|
|
374
498
|
effectiveTextMode,
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
) :
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
errorKeyNv,
|
|
385
|
-
errorPalette.desaturation,
|
|
386
|
-
errorPalette.paletteHueGrading
|
|
387
|
-
) : getColorByContrast(
|
|
388
|
-
errorPalette.hue,
|
|
389
|
-
errorPalette.saturation,
|
|
499
|
+
autoAccentNv,
|
|
500
|
+
textPrimary,
|
|
501
|
+
backgroundElevated
|
|
502
|
+
) : accent;
|
|
503
|
+
const error = errorPalette ? computePaletteTokens(
|
|
504
|
+
errorPalette,
|
|
505
|
+
ERROR_DEFAULTS,
|
|
506
|
+
mode,
|
|
507
|
+
elevation,
|
|
390
508
|
dynamicRange,
|
|
391
|
-
|
|
509
|
+
elevationDelta,
|
|
392
510
|
effectiveTextMode,
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
) :
|
|
511
|
+
autoAccentNv,
|
|
512
|
+
textPrimary,
|
|
513
|
+
backgroundElevated
|
|
514
|
+
) : accent;
|
|
397
515
|
return {
|
|
398
516
|
background,
|
|
399
517
|
backgroundElevated,
|
|
400
518
|
backgroundSunken,
|
|
401
519
|
backgroundInteractive,
|
|
520
|
+
backgroundInteractiveHover,
|
|
521
|
+
backgroundInteractiveActive,
|
|
402
522
|
textPrimary,
|
|
403
523
|
textSecondary,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
interactiveActive,
|
|
524
|
+
textTertiary,
|
|
525
|
+
textDisabled,
|
|
407
526
|
border,
|
|
527
|
+
accent,
|
|
408
528
|
success,
|
|
409
529
|
warning,
|
|
410
530
|
error,
|
|
@@ -430,29 +550,26 @@ function computeTokens(config, mode, themeMapping, elevation, elevationOffsets,
|
|
|
430
550
|
|
|
431
551
|
// src/tokens/useTokens.ts
|
|
432
552
|
function useTokens(elevation) {
|
|
433
|
-
const { config, mode
|
|
553
|
+
const { config, mode } = useNewtoneTheme();
|
|
434
554
|
const frameCtx = useFrameContext();
|
|
435
|
-
const resolvedTheme = frameCtx?.theme ?? providerTheme;
|
|
436
555
|
const resolvedElevation = elevation ?? frameCtx?.elevation ?? 1;
|
|
556
|
+
const canReuse = frameCtx !== null && elevation === void 0 && frameCtx.elevation === resolvedElevation;
|
|
437
557
|
return useMemo(() => {
|
|
438
|
-
|
|
558
|
+
if (canReuse) {
|
|
559
|
+
return { ...frameCtx.tokens, elevation: resolvedElevation };
|
|
560
|
+
}
|
|
439
561
|
const tokens = computeTokens(
|
|
440
562
|
config.colorSystem,
|
|
441
563
|
mode,
|
|
442
|
-
themeMapping,
|
|
443
564
|
resolvedElevation,
|
|
444
|
-
config.elevation.offsets,
|
|
445
565
|
config.spacing,
|
|
446
566
|
config.radius,
|
|
447
567
|
config.typography,
|
|
448
|
-
config.icons
|
|
568
|
+
config.icons,
|
|
569
|
+
config.tokenOverrides
|
|
449
570
|
);
|
|
450
571
|
return { ...tokens, elevation: resolvedElevation };
|
|
451
|
-
}, [config, mode,
|
|
452
|
-
}
|
|
453
|
-
function withOpacity(hexColor, opacity) {
|
|
454
|
-
const alpha = Math.round(opacity * 255).toString(16).padStart(2, "0");
|
|
455
|
-
return `${hexColor}${alpha}`;
|
|
572
|
+
}, [config, mode, resolvedElevation, canReuse, frameCtx?.tokens]);
|
|
456
573
|
}
|
|
457
574
|
function computeButtonPadding(size, hasIcon, hasText, iconPosition) {
|
|
458
575
|
const basePadding = {
|
|
@@ -502,8 +619,19 @@ function computeButtonPadding(size, hasIcon, hasText, iconPosition) {
|
|
|
502
619
|
paddingBottom: base
|
|
503
620
|
};
|
|
504
621
|
}
|
|
505
|
-
function
|
|
506
|
-
|
|
622
|
+
function getPaletteTokens(semantic, tokens) {
|
|
623
|
+
switch (semantic) {
|
|
624
|
+
case "accent":
|
|
625
|
+
return tokens.accent;
|
|
626
|
+
case "success":
|
|
627
|
+
return tokens.success;
|
|
628
|
+
case "error":
|
|
629
|
+
return tokens.error;
|
|
630
|
+
case "warning":
|
|
631
|
+
return tokens.warning;
|
|
632
|
+
default:
|
|
633
|
+
return void 0;
|
|
634
|
+
}
|
|
507
635
|
}
|
|
508
636
|
function getButtonConfig(variant, semantic, size, disabled, tokens) {
|
|
509
637
|
const sizeConfig = getSizeConfig(size, tokens);
|
|
@@ -551,10 +679,12 @@ function getSizeConfig(size, tokens) {
|
|
|
551
679
|
function getVariantColors(variant, semantic, disabled, tokens) {
|
|
552
680
|
if (disabled) {
|
|
553
681
|
const baseColors = getVariantColorsForState(variant, semantic, tokens);
|
|
682
|
+
const disabledBg = srgbToHex(tokens.backgroundSunken.srgb);
|
|
554
683
|
return {
|
|
555
684
|
...baseColors,
|
|
556
|
-
bg:
|
|
557
|
-
|
|
685
|
+
bg: disabledBg,
|
|
686
|
+
hoveredBg: disabledBg,
|
|
687
|
+
pressedBg: disabledBg,
|
|
558
688
|
textColor: srgbToHex(tokens.textSecondary.srgb),
|
|
559
689
|
iconColor: srgbToHex(tokens.textSecondary.srgb)
|
|
560
690
|
};
|
|
@@ -562,109 +692,76 @@ function getVariantColors(variant, semantic, disabled, tokens) {
|
|
|
562
692
|
return getVariantColorsForState(variant, semantic, tokens);
|
|
563
693
|
}
|
|
564
694
|
function getVariantColorsForState(variant, semantic, tokens) {
|
|
565
|
-
const
|
|
566
|
-
switch (semantic) {
|
|
567
|
-
case "accent":
|
|
568
|
-
return srgbToHex(tokens.interactive.srgb);
|
|
569
|
-
case "success":
|
|
570
|
-
return srgbToHex(tokens.success.srgb);
|
|
571
|
-
case "error":
|
|
572
|
-
return srgbToHex(tokens.error.srgb);
|
|
573
|
-
case "warning":
|
|
574
|
-
return srgbToHex(tokens.warning.srgb);
|
|
575
|
-
default:
|
|
576
|
-
return srgbToHex(tokens.textPrimary.srgb);
|
|
577
|
-
}
|
|
578
|
-
};
|
|
695
|
+
const paletteTokens = getPaletteTokens(semantic, tokens);
|
|
579
696
|
if (variant === "primary") {
|
|
580
697
|
if (semantic === "neutral") {
|
|
581
|
-
const bg = getNeutralPrimaryBg(tokens);
|
|
582
698
|
return {
|
|
583
|
-
bg,
|
|
584
|
-
|
|
585
|
-
|
|
699
|
+
bg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
700
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
701
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveActive.srgb),
|
|
586
702
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
587
703
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
588
704
|
borderWidth: 1,
|
|
589
705
|
borderColor: "transparent"
|
|
590
|
-
// Invisible border for consistent sizing
|
|
591
706
|
};
|
|
592
707
|
}
|
|
593
|
-
if (semantic === "accent") {
|
|
594
|
-
return {
|
|
595
|
-
bg: srgbToHex(tokens.interactive.srgb),
|
|
596
|
-
pressedBg: srgbToHex(tokens.interactiveActive.srgb),
|
|
597
|
-
textColor: srgbToHex(tokens.background.srgb),
|
|
598
|
-
// Contrast inversion
|
|
599
|
-
iconColor: srgbToHex(tokens.background.srgb),
|
|
600
|
-
borderWidth: 1,
|
|
601
|
-
borderColor: "transparent"
|
|
602
|
-
// Invisible border for consistent sizing
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
const semanticColor = getSemanticColor();
|
|
606
708
|
return {
|
|
607
|
-
bg:
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
textColor: srgbToHex(
|
|
611
|
-
|
|
612
|
-
iconColor: srgbToHex(tokens.background.srgb),
|
|
709
|
+
bg: srgbToHex(paletteTokens.fill.srgb),
|
|
710
|
+
hoveredBg: srgbToHex(paletteTokens.fillHover.srgb),
|
|
711
|
+
pressedBg: srgbToHex(paletteTokens.fillActive.srgb),
|
|
712
|
+
textColor: srgbToHex(paletteTokens.onFill.srgb),
|
|
713
|
+
iconColor: srgbToHex(paletteTokens.onFill.srgb),
|
|
613
714
|
borderWidth: 1,
|
|
614
715
|
borderColor: "transparent"
|
|
615
|
-
// Invisible border for consistent sizing
|
|
616
716
|
};
|
|
617
717
|
}
|
|
618
718
|
if (variant === "secondary") {
|
|
619
719
|
if (semantic === "neutral") {
|
|
620
720
|
return {
|
|
621
721
|
bg: "transparent",
|
|
622
|
-
|
|
722
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
723
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
623
724
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
624
725
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
625
726
|
borderWidth: 1,
|
|
626
727
|
borderColor: srgbToHex(tokens.border.srgb)
|
|
627
728
|
};
|
|
628
729
|
}
|
|
629
|
-
const semanticColor = getSemanticColor();
|
|
630
730
|
return {
|
|
631
|
-
bg:
|
|
632
|
-
|
|
633
|
-
pressedBg:
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
iconColor: semanticColor,
|
|
731
|
+
bg: srgbToHex(paletteTokens.background.srgb),
|
|
732
|
+
hoveredBg: srgbToHex(paletteTokens.backgroundInteractive.srgb),
|
|
733
|
+
pressedBg: srgbToHex(paletteTokens.backgroundInteractiveHover.srgb),
|
|
734
|
+
textColor: srgbToHex(paletteTokens.fill.srgb),
|
|
735
|
+
iconColor: srgbToHex(paletteTokens.fill.srgb),
|
|
637
736
|
borderWidth: 1,
|
|
638
737
|
borderColor: "transparent"
|
|
639
|
-
// Invisible border for consistent sizing
|
|
640
738
|
};
|
|
641
739
|
}
|
|
642
740
|
if (variant === "tertiary") {
|
|
643
741
|
if (semantic === "neutral") {
|
|
644
742
|
return {
|
|
645
743
|
bg: "transparent",
|
|
646
|
-
|
|
744
|
+
hoveredBg: srgbToHex(tokens.backgroundInteractive.srgb),
|
|
745
|
+
pressedBg: srgbToHex(tokens.backgroundInteractiveHover.srgb),
|
|
647
746
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
648
747
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
649
748
|
borderWidth: 1,
|
|
650
749
|
borderColor: "transparent"
|
|
651
|
-
// Invisible border for consistent sizing
|
|
652
750
|
};
|
|
653
751
|
}
|
|
654
|
-
const semanticColor = getSemanticColor();
|
|
655
752
|
return {
|
|
656
753
|
bg: "transparent",
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
textColor:
|
|
660
|
-
iconColor:
|
|
754
|
+
hoveredBg: srgbToHex(paletteTokens.background.srgb),
|
|
755
|
+
pressedBg: srgbToHex(paletteTokens.backgroundInteractive.srgb),
|
|
756
|
+
textColor: srgbToHex(paletteTokens.fill.srgb),
|
|
757
|
+
iconColor: srgbToHex(paletteTokens.fill.srgb),
|
|
661
758
|
borderWidth: 1,
|
|
662
759
|
borderColor: "transparent"
|
|
663
|
-
// Invisible border for consistent sizing
|
|
664
760
|
};
|
|
665
761
|
}
|
|
666
762
|
return {
|
|
667
763
|
bg: "transparent",
|
|
764
|
+
hoveredBg: "transparent",
|
|
668
765
|
pressedBg: "transparent",
|
|
669
766
|
textColor: srgbToHex(tokens.textPrimary.srgb),
|
|
670
767
|
iconColor: srgbToHex(tokens.textPrimary.srgb),
|
|
@@ -731,11 +828,26 @@ function Icon({
|
|
|
731
828
|
name
|
|
732
829
|
);
|
|
733
830
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
831
|
+
function resolveTextColor(color, tokens) {
|
|
832
|
+
switch (color) {
|
|
833
|
+
case "primary":
|
|
834
|
+
return srgbToHex(tokens.textPrimary.srgb);
|
|
835
|
+
case "secondary":
|
|
836
|
+
return srgbToHex(tokens.textSecondary.srgb);
|
|
837
|
+
case "tertiary":
|
|
838
|
+
return srgbToHex(tokens.textTertiary.srgb);
|
|
839
|
+
case "disabled":
|
|
840
|
+
return srgbToHex(tokens.textDisabled.srgb);
|
|
841
|
+
case "accent":
|
|
842
|
+
return srgbToHex(tokens.accent.fill.srgb);
|
|
843
|
+
case "success":
|
|
844
|
+
return srgbToHex(tokens.success.fill.srgb);
|
|
845
|
+
case "warning":
|
|
846
|
+
return srgbToHex(tokens.warning.fill.srgb);
|
|
847
|
+
case "error":
|
|
848
|
+
return srgbToHex(tokens.error.fill.srgb);
|
|
849
|
+
}
|
|
850
|
+
}
|
|
739
851
|
function Text2({
|
|
740
852
|
children,
|
|
741
853
|
size = "base",
|
|
@@ -764,7 +876,7 @@ function Text2({
|
|
|
764
876
|
// Font weight is stored as a number (e.g. 400, 600) but React Native expects a string.
|
|
765
877
|
fontWeight: String(tokens.typography.weight[weight]),
|
|
766
878
|
// Convert the theme color from internal sRGB format to a hex string (e.g. '#1a1a1a').
|
|
767
|
-
color:
|
|
879
|
+
color: resolveTextColor(color, tokens),
|
|
768
880
|
// Line height = font size × multiplier (e.g. 16px × 1.5 = 24px line height).
|
|
769
881
|
lineHeight: fontSize * tokens.typography.lineHeight[lineHeight],
|
|
770
882
|
textAlign: align
|
|
@@ -1021,7 +1133,7 @@ function Button({
|
|
|
1021
1133
|
() => computeButtonPadding(size, !!icon, !!children, iconPosition),
|
|
1022
1134
|
[size, icon, children, iconPosition]
|
|
1023
1135
|
);
|
|
1024
|
-
return /* @__PURE__ */ React13.createElement(Pressable, { disabled, ...pressableProps }, ({ pressed }) => (
|
|
1136
|
+
return /* @__PURE__ */ React13.createElement(Pressable, { disabled, ...pressableProps }, ({ pressed, hovered }) => (
|
|
1025
1137
|
// Wrapper handles layout: direction, gap, alignment (padding via style)
|
|
1026
1138
|
/* @__PURE__ */ React13.createElement(
|
|
1027
1139
|
Wrapper,
|
|
@@ -1034,7 +1146,7 @@ function Button({
|
|
|
1034
1146
|
{
|
|
1035
1147
|
...padding,
|
|
1036
1148
|
// Asymmetric horizontal padding for text optical balance
|
|
1037
|
-
backgroundColor: pressed && !disabled ? variantColors.pressedBg : variantColors.bg,
|
|
1149
|
+
backgroundColor: pressed && !disabled ? variantColors.pressedBg : hovered && !disabled ? variantColors.hoveredBg : variantColors.bg,
|
|
1038
1150
|
borderRadius: sizeTokens.borderRadius,
|
|
1039
1151
|
borderWidth: variantColors.borderWidth,
|
|
1040
1152
|
// Always 1 for consistent sizing
|
|
@@ -1252,8 +1364,7 @@ function toElevationLevel(frameElevation) {
|
|
|
1252
1364
|
}
|
|
1253
1365
|
function Frame({
|
|
1254
1366
|
children,
|
|
1255
|
-
//
|
|
1256
|
-
theme,
|
|
1367
|
+
// Elevation
|
|
1257
1368
|
elevation,
|
|
1258
1369
|
// Layout
|
|
1259
1370
|
layout,
|
|
@@ -1292,25 +1403,22 @@ function Frame({
|
|
|
1292
1403
|
// Style override
|
|
1293
1404
|
style
|
|
1294
1405
|
}) {
|
|
1295
|
-
const { config, mode
|
|
1406
|
+
const { config, mode } = useNewtoneTheme();
|
|
1296
1407
|
const parentFrameCtx = useFrameContext();
|
|
1297
|
-
const resolvedTheme = theme ?? parentFrameCtx?.theme ?? providerTheme;
|
|
1298
1408
|
const resolvedFrameElevation = elevation ?? 0;
|
|
1299
1409
|
const resolvedElevation = elevation !== void 0 ? toElevationLevel(elevation) : parentFrameCtx?.elevation ?? 1;
|
|
1300
1410
|
const tokens = useMemo(() => {
|
|
1301
|
-
const themeMapping = config.themes[resolvedTheme];
|
|
1302
1411
|
return computeTokens(
|
|
1303
1412
|
config.colorSystem,
|
|
1304
1413
|
mode,
|
|
1305
|
-
themeMapping,
|
|
1306
1414
|
resolvedElevation,
|
|
1307
|
-
config.elevation.offsets,
|
|
1308
1415
|
config.spacing,
|
|
1309
1416
|
config.radius,
|
|
1310
1417
|
config.typography,
|
|
1311
|
-
config.icons
|
|
1418
|
+
config.icons,
|
|
1419
|
+
config.tokenOverrides
|
|
1312
1420
|
);
|
|
1313
|
-
}, [config, mode,
|
|
1421
|
+
}, [config, mode, resolvedElevation]);
|
|
1314
1422
|
const styles = useMemo(
|
|
1315
1423
|
() => getFrameStyles({
|
|
1316
1424
|
tokens,
|
|
@@ -1360,8 +1468,8 @@ function Frame({
|
|
|
1360
1468
|
]
|
|
1361
1469
|
);
|
|
1362
1470
|
const contextValue = useMemo(
|
|
1363
|
-
() => ({
|
|
1364
|
-
[
|
|
1471
|
+
() => ({ elevation: resolvedElevation, tokens }),
|
|
1472
|
+
[resolvedElevation, tokens]
|
|
1365
1473
|
);
|
|
1366
1474
|
const webOverrides = [];
|
|
1367
1475
|
if (styles.gridWebStyle) {
|
|
@@ -1376,7 +1484,7 @@ function Frame({
|
|
|
1376
1484
|
const focusRingStyle = isFocusVisible && !disabled ? {
|
|
1377
1485
|
outlineWidth: 2,
|
|
1378
1486
|
outlineStyle: "solid",
|
|
1379
|
-
outlineColor: srgbToHex(tokens.
|
|
1487
|
+
outlineColor: srgbToHex(tokens.accent.fill.srgb),
|
|
1380
1488
|
outlineOffset: 2
|
|
1381
1489
|
} : void 0;
|
|
1382
1490
|
const webFocusProps = isInteractive ? focusProps : {};
|
|
@@ -1831,7 +1939,7 @@ function SelectOptionRow({
|
|
|
1831
1939
|
},
|
|
1832
1940
|
isSelected && {
|
|
1833
1941
|
fontWeight: tokens.typography.weight.semibold,
|
|
1834
|
-
color: srgbToHex(tokens.
|
|
1942
|
+
color: srgbToHex(tokens.accent.fill.srgb)
|
|
1835
1943
|
},
|
|
1836
1944
|
option.disabled && {
|
|
1837
1945
|
color: srgbToHex(tokens.textSecondary.srgb)
|
|
@@ -1846,7 +1954,7 @@ function SelectOptionRow({
|
|
|
1846
1954
|
{
|
|
1847
1955
|
name: "check",
|
|
1848
1956
|
size: fontSize,
|
|
1849
|
-
color: srgbToHex(tokens.
|
|
1957
|
+
color: srgbToHex(tokens.accent.fill.srgb)
|
|
1850
1958
|
}
|
|
1851
1959
|
))
|
|
1852
1960
|
);
|
|
@@ -1989,7 +2097,7 @@ function getToggleStyles(tokens, value, disabled) {
|
|
|
1989
2097
|
width: TRACK_WIDTH,
|
|
1990
2098
|
height: TRACK_HEIGHT,
|
|
1991
2099
|
borderRadius: TRACK_HEIGHT / 2,
|
|
1992
|
-
backgroundColor: value ? srgbToHex(tokens.
|
|
2100
|
+
backgroundColor: value ? srgbToHex(tokens.accent.fill.srgb) : srgbToHex(tokens.border.srgb),
|
|
1993
2101
|
justifyContent: "center",
|
|
1994
2102
|
paddingHorizontal: THUMB_OFFSET
|
|
1995
2103
|
},
|
|
@@ -2089,14 +2197,14 @@ function getSliderStyles(tokens, disabled) {
|
|
|
2089
2197
|
left: 0,
|
|
2090
2198
|
height: TRACK_HEIGHT2,
|
|
2091
2199
|
borderRadius: TRACK_HEIGHT2 / 2,
|
|
2092
|
-
backgroundColor: srgbToHex(tokens.
|
|
2200
|
+
backgroundColor: srgbToHex(tokens.accent.fill.srgb)
|
|
2093
2201
|
},
|
|
2094
2202
|
thumb: {
|
|
2095
2203
|
position: "absolute",
|
|
2096
2204
|
width: THUMB_SIZE2,
|
|
2097
2205
|
height: THUMB_SIZE2,
|
|
2098
2206
|
borderRadius: THUMB_SIZE2 / 2,
|
|
2099
|
-
backgroundColor: srgbToHex(tokens.
|
|
2207
|
+
backgroundColor: srgbToHex(tokens.accent.fill.srgb)
|
|
2100
2208
|
}
|
|
2101
2209
|
});
|
|
2102
2210
|
}
|
|
@@ -2471,7 +2579,7 @@ function getColorScaleSliderStyles(tokens, disabled) {
|
|
|
2471
2579
|
fontFamily: tokens.typography.fonts.default,
|
|
2472
2580
|
fontSize: tokens.typography.size.xs,
|
|
2473
2581
|
fontWeight: tokens.typography.weight.medium,
|
|
2474
|
-
color: srgbToHex(tokens.error.srgb)
|
|
2582
|
+
color: srgbToHex(tokens.error.fill.srgb)
|
|
2475
2583
|
}
|
|
2476
2584
|
});
|
|
2477
2585
|
}
|
|
@@ -2720,13 +2828,17 @@ var COMPONENTS = [
|
|
|
2720
2828
|
variants: [
|
|
2721
2829
|
{ id: "primary-md", label: "Primary", props: { variant: "primary", size: "md" } },
|
|
2722
2830
|
{ id: "secondary-md", label: "Secondary", props: { variant: "secondary", size: "md" } },
|
|
2723
|
-
{ id: "
|
|
2724
|
-
{ id: "outline-md", label: "Outline", props: { variant: "outline", size: "md" } },
|
|
2831
|
+
{ id: "tertiary-md", label: "Tertiary", props: { variant: "tertiary", size: "md" } },
|
|
2725
2832
|
{ id: "primary-sm", label: "Primary Small", props: { variant: "primary", size: "sm" } },
|
|
2726
2833
|
{ id: "primary-lg", label: "Primary Large", props: { variant: "primary", size: "lg" } },
|
|
2834
|
+
{ id: "accent-primary", label: "Accent Primary", props: { variant: "primary", size: "md", semantic: "accent" } },
|
|
2835
|
+
{ id: "accent-secondary", label: "Accent Secondary", props: { variant: "secondary", size: "md", semantic: "accent" } },
|
|
2836
|
+
{ id: "success-primary", label: "Success Primary", props: { variant: "primary", size: "md", semantic: "success" } },
|
|
2837
|
+
{ id: "error-primary", label: "Error Primary", props: { variant: "primary", size: "md", semantic: "error" } },
|
|
2838
|
+
{ id: "warning-primary", label: "Warning Primary", props: { variant: "primary", size: "md", semantic: "warning" } },
|
|
2727
2839
|
{ id: "icon-left", label: "Icon Left", props: { variant: "primary", size: "md", icon: "add" } },
|
|
2728
2840
|
{ id: "icon-right", label: "Icon Right", props: { variant: "primary", size: "md", icon: "arrow_forward", iconPosition: "right" } },
|
|
2729
|
-
{ id: "icon-only", label: "Icon Only", props: { variant: "
|
|
2841
|
+
{ id: "icon-only", label: "Icon Only", props: { variant: "tertiary", size: "md", icon: "settings" } }
|
|
2730
2842
|
],
|
|
2731
2843
|
editableProps: [
|
|
2732
2844
|
{
|
|
@@ -2736,11 +2848,23 @@ var COMPONENTS = [
|
|
|
2736
2848
|
options: [
|
|
2737
2849
|
{ label: "Primary", value: "primary" },
|
|
2738
2850
|
{ label: "Secondary", value: "secondary" },
|
|
2739
|
-
{ label: "
|
|
2740
|
-
{ label: "Outline", value: "outline" }
|
|
2851
|
+
{ label: "Tertiary", value: "tertiary" }
|
|
2741
2852
|
],
|
|
2742
2853
|
defaultValue: "primary"
|
|
2743
2854
|
},
|
|
2855
|
+
{
|
|
2856
|
+
name: "semantic",
|
|
2857
|
+
label: "Semantic",
|
|
2858
|
+
control: "select",
|
|
2859
|
+
options: [
|
|
2860
|
+
{ label: "Neutral", value: "neutral" },
|
|
2861
|
+
{ label: "Accent", value: "accent" },
|
|
2862
|
+
{ label: "Success", value: "success" },
|
|
2863
|
+
{ label: "Warning", value: "warning" },
|
|
2864
|
+
{ label: "Error", value: "error" }
|
|
2865
|
+
],
|
|
2866
|
+
defaultValue: "neutral"
|
|
2867
|
+
},
|
|
2744
2868
|
{
|
|
2745
2869
|
name: "size",
|
|
2746
2870
|
label: "Size",
|
|
@@ -3103,7 +3227,7 @@ var COMPONENTS = [
|
|
|
3103
3227
|
{ id: "subheading", label: "Subheading", props: { size: "lg", weight: "semibold" } },
|
|
3104
3228
|
{ id: "body", label: "Body", props: { size: "base" } },
|
|
3105
3229
|
{ id: "caption", label: "Caption", props: { size: "sm", color: "secondary" } },
|
|
3106
|
-
{ id: "
|
|
3230
|
+
{ id: "accent", label: "Accent", props: { color: "accent", weight: "medium" } },
|
|
3107
3231
|
{ id: "mono", label: "Monospace", props: { font: "mono", size: "sm" } }
|
|
3108
3232
|
],
|
|
3109
3233
|
editableProps: [
|
|
@@ -3141,7 +3265,12 @@ var COMPONENTS = [
|
|
|
3141
3265
|
options: [
|
|
3142
3266
|
{ label: "Primary", value: "primary" },
|
|
3143
3267
|
{ label: "Secondary", value: "secondary" },
|
|
3144
|
-
{ label: "
|
|
3268
|
+
{ label: "Tertiary", value: "tertiary" },
|
|
3269
|
+
{ label: "Disabled", value: "disabled" },
|
|
3270
|
+
{ label: "Accent", value: "accent" },
|
|
3271
|
+
{ label: "Success", value: "success" },
|
|
3272
|
+
{ label: "Warning", value: "warning" },
|
|
3273
|
+
{ label: "Error", value: "error" }
|
|
3145
3274
|
],
|
|
3146
3275
|
defaultValue: "primary"
|
|
3147
3276
|
},
|
|
@@ -3466,6 +3595,6 @@ var SYSTEM_FONTS = [
|
|
|
3466
3595
|
}
|
|
3467
3596
|
];
|
|
3468
3597
|
|
|
3469
|
-
export { AppShell, Button, CATEGORIES, COMPONENTS, Card, ColorScaleSlider, DEFAULT_THEME_CONFIG, Frame, GOOGLE_FONTS, HueSlider, Icon, Navbar, NewtoneProvider, Popover, SYSTEM_FONTS, Select, Sidebar, Slider, Text2 as Text, TextInput, Toggle, Wrapper, buildGoogleFontsUrl, computeTokens, generateComponentCode, getCategory, getComponent, getComponentsByCategory, isOptionGroup, useFocusVisible, useFrameContext, useNewtoneTheme, usePopover, useTokens };
|
|
3598
|
+
export { ACCENT_DEFAULTS, AppShell, Button, CATEGORIES, COMPONENTS, Card, ColorScaleSlider, DEFAULT_THEME_CONFIG, ERROR_DEFAULTS, Frame, GOOGLE_FONTS, HueSlider, Icon, NEUTRAL_DEFAULTS, Navbar, NewtoneProvider, Popover, SUCCESS_DEFAULTS, SYSTEM_FONTS, Select, Sidebar, Slider, Text2 as Text, TextInput, Toggle, WARNING_DEFAULTS, Wrapper, buildGoogleFontsUrl, computeTokens, generateComponentCode, getCategory, getComponent, getComponentsByCategory, isOptionGroup, useFocusVisible, useFrameContext, useNewtoneTheme, usePopover, useTokens };
|
|
3470
3599
|
//# sourceMappingURL=index.js.map
|
|
3471
3600
|
//# sourceMappingURL=index.js.map
|