@flipova/foundation 2.2.0 → 2.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cce3ac0: the provider publishes its theme colours in a context and useGluestackColors reads the mounted theme first, so an app that adopted the registries reads its own branding and not the package palette
8
+
3
9
  ## 2.2.0
4
10
 
5
11
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect } from 'react';
2
- import { config } from './config';
2
+ import { config, colors } 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,6 +8,9 @@ import {
8
8
  useGluestackColors as useGluestackColorsHook,
9
9
  useCalendarTheme as useCalendarThemeHook,
10
10
  } from './useGluestackColors';
11
+ import { ThemeContext } from './theme-context';
12
+
13
+ export { ThemeContext, useMountedColors } from './theme-context';
11
14
 
12
15
  export type ModeType = 'light' | 'dark' | 'system';
13
16
 
@@ -17,6 +20,16 @@ export type ModeType = 'light' | 'dark' | 'system';
17
20
  */
18
21
  export type GluestackThemeConfig = Record<string, Record<string, string>>;
19
22
 
23
+ /**
24
+ * What a provider is built from: the `colors` the generated theme exports, and
25
+ * optionally the matching `vars()` config. Passing the whole module works:
26
+ * `createGluestackUIProvider({ colors, config })`.
27
+ */
28
+ export interface GluestackTheme {
29
+ colors: GluestackThemeConfig;
30
+ config?: Record<string, unknown>;
31
+ }
32
+
20
33
  // Re-export color hooks
21
34
  export const useGluestackColors = useGluestackColorsHook;
22
35
  export const useCalendarTheme = useCalendarThemeHook;
@@ -36,7 +49,8 @@ export interface GluestackUIProviderProps {
36
49
  * the result here. The exported `GluestackUIProvider` is this factory applied to
37
50
  * the package's own theme, so nothing changes for an app that did not adopt.
38
51
  */
39
- export function createGluestackUIProvider(theme: GluestackThemeConfig) {
52
+ export function createGluestackUIProvider(theme: GluestackTheme) {
53
+ const vars = theme.config ?? theme.colors;
40
54
  return function ThemedProvider({
41
55
  mode = 'light',
42
56
  ...props
@@ -51,17 +65,19 @@ export function createGluestackUIProvider(theme: GluestackThemeConfig) {
51
65
  return (
52
66
  <View
53
67
  style={[
54
- theme[colorScheme!],
68
+ (vars as Record<string, unknown>)[colorScheme!] as ViewProps['style'],
55
69
  { flex: 1, height: '100%', width: '100%' },
56
70
  props.style,
57
71
  ]}
58
72
  >
59
- <OverlayProvider>
60
- <ToastProvider>{props.children}</ToastProvider>
61
- </OverlayProvider>
73
+ <ThemeContext.Provider value={theme.colors}>
74
+ <OverlayProvider>
75
+ <ToastProvider>{props.children}</ToastProvider>
76
+ </OverlayProvider>
77
+ </ThemeContext.Provider>
62
78
  </View>
63
79
  );
64
80
  };
65
81
  }
66
82
 
67
- export const GluestackUIProvider = createGluestackUIProvider(config);
83
+ export const GluestackUIProvider = createGluestackUIProvider({ colors, config });
@@ -0,0 +1,16 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /**
4
+ * The colour maps of the theme that is actually mounted.
5
+ *
6
+ * `useGluestackColors` used to close over the config this package generates,
7
+ * so an app that adopted the registries and mounted its own provider still read
8
+ * the package colours - the branding would have been cosmetic. The provider
9
+ * publishes what it was built with here instead, and the hook reads this first.
10
+ */
11
+ export type ThemeColors = Record<string, Record<string, string>>;
12
+
13
+ export const ThemeContext = createContext<ThemeColors | null>(null);
14
+
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);
@@ -1,5 +1,6 @@
1
1
  import { useColorScheme } from 'nativewind';
2
2
  import { colors } from './config';
3
+ import { useMountedColors } from './theme-context';
3
4
 
4
5
  /**
5
6
  * Convert CSS variable name to camelCase
@@ -40,12 +41,15 @@ function rgbToHex(rgbString: string): string {
40
41
  */
41
42
  export function useGluestackColors(): Record<string, string> {
42
43
  const { colorScheme } = useColorScheme();
43
- const theme = colors[colorScheme || 'light'];
44
+ // The mounted theme wins: an app that adopted the registries and built its own
45
+ // provider must read its own colours, not the ones shipped with the package.
46
+ const theme = useMountedColors() ?? colors;
47
+ const palette = theme[colorScheme || 'light'];
44
48
 
45
49
  // Dynamically convert all CSS variables to camelCase hex colors
46
50
  const result: Record<string, string> = {};
47
51
 
48
- Object.entries(theme).forEach(([key, value]) => {
52
+ Object.entries(palette).forEach(([key, value]) => {
49
53
  const camelKey = toCamelCase(key);
50
54
  result[camelKey] = rgbToHex(value as string);
51
55
  });
@@ -210,13 +210,13 @@ const ADOPTED_OUTPUTS = {
210
210
  const PROVIDER = `// theme/provider.tsx
211
211
  // Generated by \`npx flipova-design adopt\` -- safe to edit.
212
212
  //
213
- // The theme below is regenerated from your own registries (design/*.xml) into
213
+ // The theme is regenerated from your own registries (design/*.xml) into
214
214
  // theme/config.ts and theme/tokens.js. This provider is the wiring between them
215
215
  // and the components of @flipova/foundation.
216
216
  import { createGluestackUIProvider } from '@flipova/foundation/ui';
217
- import { config } from './config';
217
+ import * as theme from './config';
218
218
 
219
- export const AppThemeProvider = createGluestackUIProvider(config);
219
+ export const AppThemeProvider = createGluestackUIProvider(theme);
220
220
  export default AppThemeProvider;
221
221
  `;
222
222
 
@@ -3850,6 +3850,10 @@ var config = {
3850
3850
  light: nativewind.vars(colors.light),
3851
3851
  dark: nativewind.vars(colors.dark)
3852
3852
  };
3853
+ var ThemeContext = React48.createContext(null);
3854
+ var useMountedColors = () => React48.useContext(ThemeContext);
3855
+
3856
+ // components/ui/gluestack-ui-provider/useGluestackColors.ts
3853
3857
  function toCamelCase(str) {
3854
3858
  return str.replace(/^--/, "").replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
3855
3859
  }
@@ -3865,9 +3869,10 @@ function rgbToHex(rgbString) {
3865
3869
  }
3866
3870
  function useGluestackColors() {
3867
3871
  const { colorScheme } = nativewind.useColorScheme();
3868
- const theme = colors[colorScheme || "light"];
3872
+ const theme = useMountedColors() ?? colors;
3873
+ const palette = theme[colorScheme || "light"];
3869
3874
  const result = {};
3870
- Object.entries(theme).forEach(([key, value]) => {
3875
+ Object.entries(palette).forEach(([key, value]) => {
3871
3876
  const camelKey = toCamelCase(key);
3872
3877
  result[camelKey] = rgbToHex(value);
3873
3878
  });
@@ -3895,6 +3900,7 @@ function useCalendarTheme() {
3895
3900
  var useGluestackColors2 = useGluestackColors;
3896
3901
  var useCalendarTheme2 = useCalendarTheme;
3897
3902
  function createGluestackUIProvider(theme) {
3903
+ const vars2 = theme.config ?? theme.colors;
3898
3904
  return function ThemedProvider({
3899
3905
  mode = "light",
3900
3906
  ...props
@@ -3907,16 +3913,16 @@ function createGluestackUIProvider(theme) {
3907
3913
  reactNative.View,
3908
3914
  {
3909
3915
  style: [
3910
- theme[colorScheme],
3916
+ vars2[colorScheme],
3911
3917
  { flex: 1, height: "100%", width: "100%" },
3912
3918
  props.style
3913
3919
  ],
3914
- children: /* @__PURE__ */ jsxRuntime.jsx(creator$d.OverlayProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(creator$o.ToastProvider, { children: props.children }) })
3920
+ children: /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: theme.colors, children: /* @__PURE__ */ jsxRuntime.jsx(creator$d.OverlayProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(creator$o.ToastProvider, { children: props.children }) }) })
3915
3921
  }
3916
3922
  );
3917
3923
  };
3918
3924
  }
3919
- var GluestackUIProvider = createGluestackUIProvider(config);
3925
+ var GluestackUIProvider = createGluestackUIProvider({ colors, config });
3920
3926
  var gridBaseStyle = nativewindUtils.isWeb ? "grid grid-cols-12" : "box-border flex-row flex-wrap justify-start";
3921
3927
  var gridItemBaseStyle = nativewindUtils.isWeb ? "w-auto col-span-1" : "";
3922
3928
  var gridStyle = nativewindUtils.tva({
@@ -9706,6 +9712,7 @@ exports.TabsTriggerText = TabsTriggerText;
9706
9712
  exports.Text = Text21;
9707
9713
  exports.Textarea = Textarea;
9708
9714
  exports.TextareaInput = TextareaInput;
9715
+ exports.ThemeContext = ThemeContext;
9709
9716
  exports.ThreeDotsIcon = ThreeDotsIcon;
9710
9717
  exports.Toast = Toast;
9711
9718
  exports.ToastDescription = ToastDescription;
@@ -9729,6 +9736,7 @@ exports.createGluestackUIProvider = createGluestackUIProvider;
9729
9736
  exports.createIconUI = createIconUI;
9730
9737
  exports.useCalendarTheme = useCalendarTheme2;
9731
9738
  exports.useGluestackColors = useGluestackColors2;
9739
+ exports.useMountedColors = useMountedColors;
9732
9740
  exports.useToast = useToast;
9733
- //# sourceMappingURL=chunk-TDW7UKG6.js.map
9734
- //# sourceMappingURL=chunk-TDW7UKG6.js.map
9741
+ //# sourceMappingURL=chunk-JVHJUIXV.js.map
9742
+ //# sourceMappingURL=chunk-JVHJUIXV.js.map