@flipova/foundation 2.2.1 → 2.4.0-beta.1

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +157 -156
  3. package/components/ui/accordion/ANIMATION_CUSTOMIZATION.md +16 -7
  4. package/components/ui/accordion/AccordionAnimatedHeight.tsx +3 -15
  5. package/components/ui/accordion/AccordionAnimatedIcon.tsx +2 -9
  6. package/components/ui/accordion/AnimatedHeight.tsx +3 -15
  7. package/components/ui/accordion/AnimatedIcon.tsx +2 -9
  8. package/components/ui/accordion/MIGRATION_SUMMARY.md +22 -11
  9. package/components/ui/accordion/USAGE_EXAMPLE.tsx +10 -25
  10. package/components/ui/accordion/index.tsx +71 -139
  11. package/components/ui/actionsheet/index.tsx +63 -105
  12. package/components/ui/alert/index.tsx +20 -50
  13. package/components/ui/alert-dialog/index.tsx +23 -48
  14. package/components/ui/avatar/index.tsx +32 -68
  15. package/components/ui/badge/index.tsx +18 -49
  16. package/components/ui/bottomsheet/index.tsx +20 -52
  17. package/components/ui/box/index.tsx +4 -9
  18. package/components/ui/box/index.web.tsx +3 -9
  19. package/components/ui/button/index.tsx +73 -109
  20. package/components/ui/calendar/creator.tsx +69 -30
  21. package/components/ui/calendar/index.tsx +81 -159
  22. package/components/ui/calendar/styles.tsx +10 -10
  23. package/components/ui/card/index.tsx +8 -9
  24. package/components/ui/card/index.web.tsx +4 -10
  25. package/components/ui/center/index.tsx +6 -11
  26. package/components/ui/center/index.web.tsx +3 -9
  27. package/components/ui/checkbox/index.tsx +46 -107
  28. package/components/ui/date-time-picker/creator.tsx +14 -1
  29. package/components/ui/date-time-picker/index.tsx +107 -156
  30. package/components/ui/date-time-picker/index.web.tsx +11 -33
  31. package/components/ui/date-time-picker/styles.tsx +5 -5
  32. package/components/ui/divider/index.tsx +5 -6
  33. package/components/ui/drawer/index.tsx +108 -128
  34. package/components/ui/fab/index.tsx +25 -68
  35. package/components/ui/flat-list/index.tsx +11 -8
  36. package/components/ui/form-control/index.tsx +49 -90
  37. package/components/ui/gluestack-ui-provider/config.ts +69 -2
  38. package/components/ui/gluestack-ui-provider/index.tsx +32 -12
  39. package/components/ui/gluestack-ui-provider/index.web.tsx +43 -16
  40. package/components/ui/gluestack-ui-provider/script.ts +13 -8
  41. package/components/ui/gluestack-ui-provider/theme-context.ts +36 -1
  42. package/components/ui/gluestack-ui-provider/useGluestackColors.ts +11 -4
  43. package/components/ui/grid/index.tsx +128 -165
  44. package/components/ui/grid/index.web.tsx +17 -19
  45. package/components/ui/grid/styles.tsx +1 -3
  46. package/components/ui/heading/index.tsx +146 -169
  47. package/components/ui/heading/index.web.tsx +7 -28
  48. package/components/ui/heading/styles.tsx +5 -5
  49. package/components/ui/hstack/index.tsx +16 -15
  50. package/components/ui/hstack/index.web.tsx +17 -17
  51. package/components/ui/hstack/styles.tsx +5 -5
  52. package/components/ui/icon/index.tsx +95 -486
  53. package/components/ui/icon/index.web.tsx +79 -439
  54. package/components/ui/image/index.tsx +13 -18
  55. package/components/ui/image-viewer/index.tsx +149 -221
  56. package/components/ui/image-viewer/index.web.tsx +88 -113
  57. package/components/ui/input/index.tsx +20 -33
  58. package/components/ui/link/index.tsx +16 -22
  59. package/components/ui/liquid-glass/index.tsx +19 -25
  60. package/components/ui/menu/index.tsx +44 -66
  61. package/components/ui/modal/index.tsx +70 -91
  62. package/components/ui/popover/index.tsx +102 -121
  63. package/components/ui/portal/index.tsx +5 -6
  64. package/components/ui/pressable/index.tsx +5 -9
  65. package/components/ui/progress/index.tsx +4 -11
  66. package/components/ui/radio/index.tsx +47 -83
  67. package/components/ui/select/index.tsx +38 -59
  68. package/components/ui/select/select-actionsheet.tsx +61 -108
  69. package/components/ui/skeleton/index.tsx +22 -43
  70. package/components/ui/skeleton/index.web.tsx +63 -75
  71. package/components/ui/slider/index.tsx +36 -56
  72. package/components/ui/spinner/index.tsx +1 -10
  73. package/components/ui/switch/index.tsx +6 -13
  74. package/components/ui/table/index.tsx +39 -102
  75. package/components/ui/table/index.web.tsx +41 -79
  76. package/components/ui/tabs/TabsAnimatedIndicator.tsx +10 -38
  77. package/components/ui/tabs/creator.tsx +32 -24
  78. package/components/ui/tabs/index.tsx +253 -309
  79. package/components/ui/text/index.tsx +23 -37
  80. package/components/ui/text/index.web.tsx +33 -35
  81. package/components/ui/text/styles.tsx +5 -5
  82. package/components/ui/textarea/index.tsx +24 -38
  83. package/components/ui/toast/index.tsx +47 -52
  84. package/components/ui/tooltip/index.tsx +12 -28
  85. package/components/ui/vstack/index.tsx +17 -17
  86. package/components/ui/vstack/index.web.tsx +17 -17
  87. package/components/ui/vstack/styles.tsx +5 -5
  88. package/design/canonical.index.txt +15 -1
  89. package/design/manifest.xml +2 -0
  90. package/design/schema.xsd +11 -0
  91. package/design/themes.xml +175 -2
  92. package/design/tools/design.js +15 -12
  93. package/design/tools/npm.js +4 -3
  94. package/design/tools/sources/.generate/config.py +60 -2
  95. package/dist/{chunk-RPLDFHEZ.mjs → chunk-2R66P5X5.mjs} +1907 -3130
  96. package/dist/chunk-2R66P5X5.mjs.map +1 -0
  97. package/dist/{chunk-JVHJUIXV.js → chunk-LCTFQJZM.js} +1909 -3129
  98. package/dist/chunk-LCTFQJZM.js.map +1 -0
  99. package/dist/index.d.mts +1 -1
  100. package/dist/index.d.ts +1 -1
  101. package/dist/index.js +303 -291
  102. package/dist/index.mjs +1 -1
  103. package/dist/ui/index.d.mts +44 -3
  104. package/dist/ui/index.d.ts +44 -3
  105. package/dist/ui/index.js +303 -291
  106. package/dist/ui/index.mjs +1 -1
  107. package/package.json +12 -7
  108. package/dist/chunk-JVHJUIXV.js.map +0 -1
  109. package/dist/chunk-RPLDFHEZ.mjs.map +0 -1
@@ -63,10 +63,77 @@ export const colors = {
63
63
  '--info': '14 165 233',
64
64
  '--info-foreground': '255 255 255',
65
65
  },
66
+ 'spring-light': {
67
+ '--background': '240 253 244',
68
+ '--foreground': '20 83 45',
69
+ '--card': '255 255 255',
70
+ '--card-foreground': '20 83 45',
71
+ '--popover': '255 255 255',
72
+ '--popover-foreground': '20 83 45',
73
+ '--primary': '22 163 74',
74
+ '--primary-foreground': '255 255 255',
75
+ '--secondary': '34 197 94',
76
+ '--secondary-foreground': '255 255 255',
77
+ '--muted': '220 252 231',
78
+ '--muted-foreground': '21 128 61',
79
+ '--accent': '187 247 208',
80
+ '--accent-foreground': '20 83 45',
81
+ '--destructive': '220 38 38',
82
+ '--destructive-foreground': '255 255 255',
83
+ '--border': '187 247 208',
84
+ '--input': '187 247 208',
85
+ '--ring': '74 222 128',
86
+ '--success': '22 163 74',
87
+ '--success-foreground': '255 255 255',
88
+ '--warning': '217 119 6',
89
+ '--warning-foreground': '255 255 255',
90
+ '--error': '220 38 38',
91
+ '--error-foreground': '255 255 255',
92
+ '--info': '2 132 199',
93
+ '--info-foreground': '255 255 255',
94
+ },
95
+ 'spring-dark': {
96
+ '--background': '5 46 22',
97
+ '--foreground': '240 253 244',
98
+ '--card': '20 83 45',
99
+ '--card-foreground': '240 253 244',
100
+ '--popover': '20 83 45',
101
+ '--popover-foreground': '240 253 244',
102
+ '--primary': '74 222 128',
103
+ '--primary-foreground': '5 46 22',
104
+ '--secondary': '134 239 172',
105
+ '--secondary-foreground': '5 46 22',
106
+ '--muted': '20 83 45',
107
+ '--muted-foreground': '187 247 208',
108
+ '--accent': '22 101 52',
109
+ '--accent-foreground': '240 253 244',
110
+ '--destructive': '239 68 68',
111
+ '--destructive-foreground': '255 255 255',
112
+ '--border': '22 101 52',
113
+ '--input': '22 101 52',
114
+ '--ring': '134 239 172',
115
+ '--success': '74 222 128',
116
+ '--success-foreground': '5 46 22',
117
+ '--warning': '251 191 36',
118
+ '--warning-foreground': '5 46 22',
119
+ '--error': '248 113 113',
120
+ '--error-foreground': '5 46 22',
121
+ '--info': '56 189 248',
122
+ '--info-foreground': '5 46 22',
123
+ },
66
124
  };
67
125
 
68
126
  // Config for nativewind vars() - used by the provider
69
127
  export const config = {
70
- light: vars(colors.light),
71
- dark: vars(colors.dark),
128
+ light: vars(colors['light']),
129
+ dark: vars(colors['dark']),
130
+ 'spring-light': vars(colors['spring-light']),
131
+ 'spring-dark': vars(colors['spring-dark']),
132
+ };
133
+
134
+ // Theme variants: variant -> mode -> theme id, from the `variant` attribute in
135
+ // design/themes.xml. `default` holds the base light/dark pair.
136
+ export const variants = {
137
+ default: { dark: 'dark', light: 'light' },
138
+ spring: { dark: 'spring-dark', light: 'spring-light' },
72
139
  };
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect } from 'react';
2
- import { config, colors } from './config';
2
+ import { config, colors, variants } from './config';
3
3
  import { View, ViewProps } from 'react-native';
4
4
  import { OverlayProvider } from '@gluestack-ui/core/overlay/creator';
5
5
  import { ToastProvider } from '@gluestack-ui/core/toast/creator';
@@ -8,12 +8,15 @@ import {
8
8
  useGluestackColors as useGluestackColorsHook,
9
9
  useCalendarTheme as useCalendarThemeHook,
10
10
  } from './useGluestackColors';
11
- import { ThemeContext } from './theme-context';
11
+ import { ThemeContext, MountedThemeContext, resolveThemeId } from './theme-context';
12
12
 
13
- export { ThemeContext, useMountedColors } from './theme-context';
13
+ export { ThemeContext, MountedThemeContext, useMountedColors, useMountedTheme, resolveThemeId } from './theme-context';
14
14
 
15
15
  export type ModeType = 'light' | 'dark' | 'system';
16
16
 
17
+ /** A light/dark pair declared in `design/themes.xml` (e.g. `spring`). */
18
+ export type ThemeVariant = keyof typeof variants | (string & {});
19
+
17
20
  /**
18
21
  * The theme a provider is built from: the same shape `config.ts` generates, so
19
22
  * the file an app regenerates from its own registries is accepted as it is.
@@ -28,6 +31,8 @@ export type GluestackThemeConfig = Record<string, Record<string, string>>;
28
31
  export interface GluestackTheme {
29
32
  colors: GluestackThemeConfig;
30
33
  config?: Record<string, unknown>;
34
+ /** variant -> mode -> theme id, generated from the `variant` attribute. */
35
+ variants?: Record<string, Record<string, string>>;
31
36
  }
32
37
 
33
38
  // Re-export color hooks
@@ -37,6 +42,8 @@ export type { GluestackColors } from './useGluestackColors';
37
42
 
38
43
  export interface GluestackUIProviderProps {
39
44
  mode?: ModeType;
45
+ /** Which light/dark pair to mount (e.g. `spring`). Defaults to `default`. */
46
+ variant?: ThemeVariant;
40
47
  children?: React.ReactNode;
41
48
  style?: ViewProps['style'];
42
49
  }
@@ -51,10 +58,10 @@ export interface GluestackUIProviderProps {
51
58
  */
52
59
  export function createGluestackUIProvider(theme: GluestackTheme) {
53
60
  const vars = theme.config ?? theme.colors;
54
- return function ThemedProvider({
55
- mode = 'light',
56
- ...props
57
- }: GluestackUIProviderProps) {
61
+ const variantMap = theme.variants;
62
+ const themeIds = Object.keys(vars);
63
+
64
+ return function ThemedProvider({ mode = 'light', variant, ...props }: GluestackUIProviderProps) {
58
65
  const { colorScheme, setColorScheme } = useColorScheme();
59
66
 
60
67
  useEffect(() => {
@@ -62,22 +69,35 @@ export function createGluestackUIProvider(theme: GluestackTheme) {
62
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
63
70
  }, [mode]);
64
71
 
72
+ // Nativewind only reports light/dark, so `system` resolves through it while a
73
+ // named mode is taken as-is; either way the VARIANT picks the pair. Falling
74
+ // back to the mode keeps a theme set without variants working untouched.
75
+ const resolvedMode = mode === 'system' ? (colorScheme ?? 'light') : mode;
76
+ const themeId = resolveThemeId(variantMap, variant, resolvedMode);
77
+ const mountedTheme = React.useMemo(() => ({ themeId, themeIds }), [themeId, themeIds]);
78
+
65
79
  return (
66
80
  <View
67
81
  style={[
68
- (vars as Record<string, unknown>)[colorScheme!] as ViewProps['style'],
82
+ (vars as Record<string, unknown>)[themeId] as ViewProps['style'],
69
83
  { flex: 1, height: '100%', width: '100%' },
70
84
  props.style,
71
85
  ]}
72
86
  >
73
87
  <ThemeContext.Provider value={theme.colors}>
74
- <OverlayProvider>
75
- <ToastProvider>{props.children}</ToastProvider>
76
- </OverlayProvider>
88
+ <MountedThemeContext.Provider value={mountedTheme}>
89
+ <OverlayProvider>
90
+ <ToastProvider>{props.children}</ToastProvider>
91
+ </OverlayProvider>
92
+ </MountedThemeContext.Provider>
77
93
  </ThemeContext.Provider>
78
94
  </View>
79
95
  );
80
96
  };
81
97
  }
82
98
 
83
- export const GluestackUIProvider = createGluestackUIProvider({ colors, config });
99
+ export const GluestackUIProvider = createGluestackUIProvider({
100
+ colors,
101
+ config,
102
+ variants,
103
+ });
@@ -1,13 +1,17 @@
1
1
  'use client';
2
2
  import React, { useEffect, useLayoutEffect } from 'react';
3
- import { config } from './config';
3
+ import { config, variants } from './config';
4
4
  import { OverlayProvider } from '@gluestack-ui/core/overlay/creator';
5
5
  import { ToastProvider } from '@gluestack-ui/core/toast/creator';
6
6
  import { setFlushStyles } from '@gluestack-ui/utils/nativewind-utils';
7
7
  import { script } from './script';
8
+ import { resolveThemeId } from './theme-context';
8
9
 
9
10
  export type ModeType = 'light' | 'dark' | 'system';
10
11
 
12
+ /** A light/dark pair declared in `design/themes.xml` (e.g. `spring`). */
13
+ export type ThemeVariant = keyof typeof variants | (string & {});
14
+
11
15
  const variableStyleTagId = 'nativewind-style';
12
16
  const createStyle = (styleTagId: string) => {
13
17
  const style = document.createElement('style');
@@ -16,45 +20,68 @@ const createStyle = (styleTagId: string) => {
16
20
  return style;
17
21
  };
18
22
 
19
- export const useSafeLayoutEffect =
20
- typeof window !== 'undefined' ? useLayoutEffect : useEffect;
23
+ export const useSafeLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
21
24
 
22
25
  export function GluestackUIProvider({
23
26
  mode = 'light',
27
+ variant,
24
28
  ...props
25
29
  }: {
26
30
  mode?: ModeType;
31
+ variant?: ThemeVariant;
27
32
  children?: React.ReactNode;
28
33
  }) {
34
+ // Every declared theme gets a CSS block. The two default ids keep their historic
35
+ // selectors (:root / .dark) so existing apps and Tailwind's dark: keep working;
36
+ // any OTHER theme (a variant pair such as spring-light/spring-dark) is keyed on
37
+ // [data-theme], which is emitted last so it wins over :root and .dark.
38
+ const themeIds = Object.keys(config);
39
+ const isDefaultId = (id: string) => id === 'light' || id === 'dark';
29
40
  let cssVariablesWithMode = ``;
30
- Object.keys(config).forEach((configKey) => {
31
- cssVariablesWithMode +=
32
- configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
33
- const cssVariables = Object.keys(
34
- config[configKey as keyof typeof config]
35
- ).reduce((acc: string, curr: string) => {
41
+ let variantCss = ``;
42
+ themeIds.forEach((configKey) => {
43
+ const cssVariables = Object.keys(config[configKey as keyof typeof config]).reduce((acc: string, curr: string) => {
36
44
  acc += `${curr}:${config[configKey as keyof typeof config][curr]}; `;
37
45
  return acc;
38
46
  }, '');
39
- cssVariablesWithMode += `${cssVariables} \n}`;
47
+ if (isDefaultId(configKey)) {
48
+ cssVariablesWithMode += configKey === 'dark' ? `\n .dark {\n ` : `\n:root {\n`;
49
+ cssVariablesWithMode += `${cssVariables} \n}`;
50
+ } else {
51
+ variantCss += `\n[data-theme='${configKey}'] {\n${cssVariables} \n}`;
52
+ }
40
53
  });
54
+ cssVariablesWithMode += variantCss;
41
55
 
42
56
  setFlushStyles(cssVariablesWithMode);
43
57
 
44
- const handleMediaQuery = React.useCallback((e: MediaQueryListEvent) => {
45
- script(e.matches ? 'dark' : 'light');
46
- }, []);
58
+ const handleMediaQuery = React.useCallback(
59
+ (e: MediaQueryListEvent) => {
60
+ const resolved = e.matches ? 'dark' : 'light';
61
+ script(resolved, resolveThemeId(variants, variant, resolved), resolved);
62
+ },
63
+ [variant],
64
+ );
65
+
66
+ // The script keeps the light/dark class AND the variant class/attribute in step.
67
+ const activeMode = mode === 'system' ? 'light' : mode;
68
+ const themeId = resolveThemeId(variants, variant, activeMode);
69
+ const modeClass = themeId === activeMode ? '' : themeId;
47
70
 
48
71
  useSafeLayoutEffect(() => {
49
72
  if (mode !== 'system') {
50
73
  const documentElement = document.documentElement;
51
74
  if (documentElement) {
75
+ documentElement.setAttribute('data-theme', themeId);
76
+ documentElement.classList.remove('light', 'dark', modeClass);
52
77
  documentElement.classList.add(mode);
53
- documentElement.classList.remove(mode === 'light' ? 'dark' : 'light');
78
+ if (modeClass) {
79
+ documentElement.classList.add(modeClass);
80
+ }
54
81
  documentElement.style.colorScheme = mode;
55
82
  }
56
83
  }
57
- }, [mode]);
84
+ }, [mode, themeId, modeClass]);
58
85
 
59
86
  useSafeLayoutEffect(() => {
60
87
  if (mode !== 'system') return;
@@ -85,7 +112,7 @@ export function GluestackUIProvider({
85
112
  <script
86
113
  suppressHydrationWarning
87
114
  dangerouslySetInnerHTML={{
88
- __html: `(${script.toString()})('${mode}')`,
115
+ __html: `(${script.toString()})('${mode}', '${themeId}', '${modeClass}')`,
89
116
  }}
90
117
  />
91
118
  <OverlayProvider>
@@ -1,18 +1,23 @@
1
- export const script = (mode: string) => {
1
+ export const script = (mode: string, themeId: string, modeClass: string) => {
2
2
  const documentElement = document.documentElement;
3
3
 
4
4
  function getSystemColorMode() {
5
- return window.matchMedia('(prefers-color-scheme: dark)').matches
6
- ? 'dark'
7
- : 'light';
5
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
8
6
  }
9
7
 
10
8
  try {
11
9
  const isSystem = mode === 'system';
12
- const theme = isSystem ? getSystemColorMode() : mode;
13
- documentElement.classList.remove(theme === 'light' ? 'dark' : 'light');
14
- documentElement.classList.add(theme);
15
- documentElement.style.colorScheme = theme;
10
+ const resolved = isSystem ? getSystemColorMode() : mode;
11
+ // `data-theme` carries the variant pair (spring-light, spring-dark, ...);
12
+ // the light/dark CLASS is kept alongside it so Tailwind's dark: variants
13
+ // keep working while a seasonal palette is mounted.
14
+ documentElement.setAttribute('data-theme', themeId);
15
+ documentElement.classList.remove('light', 'dark', modeClass);
16
+ documentElement.classList.add(resolved);
17
+ if (themeId !== resolved) {
18
+ documentElement.classList.add(modeClass);
19
+ }
20
+ documentElement.style.colorScheme = resolved;
16
21
  } catch (e) {
17
22
  console.error(e);
18
23
  }
@@ -13,4 +13,39 @@ export type ThemeColors = Record<string, Record<string, string>>;
13
13
  export const ThemeContext = createContext<ThemeColors | null>(null);
14
14
 
15
15
  /** The mounted theme, or null when the package's own provider is not in the tree. */
16
- export const useMountedColors = (): ThemeColors | null => useContext(ThemeContext);
16
+ export const useMountedColors = (): ThemeColors | null => useContext(ThemeContext);
17
+
18
+ /**
19
+ * Which theme of the mounted set is active.
20
+ *
21
+ * A theme set declares several light/dark pairs (variants: `spring-light` /
22
+ * `spring-dark`, ...). Nativewind only knows `light` and `dark`, so the provider
23
+ * resolves the pair itself and publishes the resulting id here - otherwise a hook
24
+ * reading colours would look up `colors['dark']` and miss the variant entirely.
25
+ */
26
+ export interface MountedTheme {
27
+ /** The active theme id, e.g. `spring-dark`. */
28
+ themeId: string;
29
+ /** Every id the mounted set declares, so a lookup can fall back safely. */
30
+ themeIds: string[];
31
+ }
32
+
33
+ export const MountedThemeContext = createContext<MountedTheme | null>(null);
34
+
35
+ export const useMountedTheme = (): MountedTheme | null => useContext(MountedThemeContext);
36
+
37
+ /**
38
+ * Resolve a (variant, mode) request to a theme id.
39
+ *
40
+ * The generated `variants` table is authoritative, so a theme id never has to
41
+ * follow a naming convention. An unknown variant falls back to the mode itself,
42
+ * which is exactly the pre-variant behaviour (the `light`/`dark` ids).
43
+ */
44
+ export function resolveThemeId(
45
+ variants: Record<string, Record<string, string>> | undefined,
46
+ variant: string | undefined,
47
+ mode: string,
48
+ ): string {
49
+ const mapped = variant ? variants?.[variant]?.[mode] : undefined;
50
+ return mapped ?? mode;
51
+ }
@@ -1,6 +1,6 @@
1
1
  import { useColorScheme } from 'nativewind';
2
2
  import { colors } from './config';
3
- import { useMountedColors } from './theme-context';
3
+ import { useMountedColors, useMountedTheme } from './theme-context';
4
4
 
5
5
  /**
6
6
  * Convert CSS variable name to camelCase
@@ -24,8 +24,7 @@ function rgbToHex(rgbString: string): string {
24
24
  return isNaN(num) ? 0 : num;
25
25
  });
26
26
 
27
- const toHex = (n: number) =>
28
- Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
27
+ const toHex = (n: number) => Math.max(0, Math.min(255, n)).toString(16).padStart(2, '0');
29
28
  return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
30
29
  }
31
30
 
@@ -44,7 +43,15 @@ export function useGluestackColors(): Record<string, string> {
44
43
  // The mounted theme wins: an app that adopted the registries and built its own
45
44
  // provider must read its own colours, not the ones shipped with the package.
46
45
  const theme = useMountedColors() ?? colors;
47
- const palette = theme[colorScheme || 'light'];
46
+ const mounted = useMountedTheme();
47
+ // The provider resolves the active theme id (a variant pair such as
48
+ // `spring-dark`). Falling back to the raw scheme keeps a tree with no mounted
49
+ // provider working, and an unknown id must not hand `Object.entries` undefined.
50
+ // `theme` is the generated literal object, so index it through a widened view:
51
+ // the active id is only known at runtime.
52
+ const palettes = theme as Record<string, Record<string, string>>;
53
+ const palette =
54
+ palettes[mounted?.themeId ?? ''] ?? palettes[colorScheme || 'light'] ?? palettes[mounted?.themeIds[0] ?? ''] ?? {};
48
55
 
49
56
  // Dynamically convert all CSS variables to camelCase hex colors
50
57
  const result: Record<string, string> = {};