@oxyhq/bloom 0.6.17 → 0.6.18
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/lib/commonjs/theme/BloomThemeProvider.js +13 -4
- package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
- package/lib/commonjs/theme/apply-dark-class.js +10 -7
- package/lib/commonjs/theme/apply-dark-class.js.map +1 -1
- package/lib/commonjs/theme/color-scope/index.js +3 -10
- package/lib/commonjs/theme/color-scope/index.js.map +1 -1
- package/lib/commonjs/theme/color-scope/index.web.js +7 -5
- package/lib/commonjs/theme/color-scope/index.web.js.map +1 -1
- package/lib/commonjs/theme/color-scope/style-builder.js +18 -0
- package/lib/commonjs/theme/color-scope/style-builder.js.map +1 -1
- package/lib/module/theme/BloomThemeProvider.js +14 -5
- package/lib/module/theme/BloomThemeProvider.js.map +1 -1
- package/lib/module/theme/apply-dark-class.js +10 -7
- package/lib/module/theme/apply-dark-class.js.map +1 -1
- package/lib/module/theme/color-scope/index.js +4 -11
- package/lib/module/theme/color-scope/index.js.map +1 -1
- package/lib/module/theme/color-scope/index.web.js +7 -5
- package/lib/module/theme/color-scope/index.web.js.map +1 -1
- package/lib/module/theme/color-scope/style-builder.js +17 -0
- package/lib/module/theme/color-scope/style-builder.js.map +1 -1
- package/lib/typescript/commonjs/icons/common.d.ts +8 -8
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts +8 -1
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts +5 -4
- package/lib/typescript/commonjs/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts +6 -7
- package/lib/typescript/commonjs/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts +8 -0
- package/lib/typescript/commonjs/theme/color-scope/style-builder.d.ts.map +1 -1
- package/lib/typescript/module/icons/common.d.ts +8 -8
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts +8 -1
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/module/theme/apply-dark-class.d.ts +5 -4
- package/lib/typescript/module/theme/apply-dark-class.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.d.ts +1 -1
- package/lib/typescript/module/theme/color-scope/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/index.web.d.ts +6 -7
- package/lib/typescript/module/theme/color-scope/index.web.d.ts.map +1 -1
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts +8 -0
- package/lib/typescript/module/theme/color-scope/style-builder.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/theme/BloomThemeProvider.tsx +32 -4
- package/src/theme/apply-dark-class.ts +8 -8
- package/src/theme/color-scope/index.tsx +4 -17
- package/src/theme/color-scope/index.web.tsx +16 -13
- package/src/theme/color-scope/style-builder.ts +25 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './init-css-interop';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
4
|
import { type AppColorName } from './color-presets';
|
|
4
5
|
import { type BloomThemeStorage } from './persistence';
|
|
5
6
|
import type { Theme, ThemeMode } from './types';
|
|
@@ -52,7 +53,13 @@ export interface BloomThemeProviderProps {
|
|
|
52
53
|
fonts?: boolean;
|
|
53
54
|
/** Rendered while native fonts load. Ignored on web. */
|
|
54
55
|
onFontsLoading?: React.ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Style applied to the native `<View>` wrapper that carries the preset's
|
|
58
|
+
* CSS vars. Defaults to `{ flex: 1 }`. Ignored on web (the provider writes
|
|
59
|
+
* vars to `document.documentElement` instead of using a wrapper).
|
|
60
|
+
*/
|
|
61
|
+
nativeWrapperStyle?: StyleProp<ViewStyle>;
|
|
55
62
|
children: React.ReactNode;
|
|
56
63
|
}
|
|
57
|
-
export declare function BloomThemeProvider({ mode: controlledMode, colorPreset: controlledPreset, defaultMode, defaultColorPreset, onModeChange, onColorPresetChange, persistKey, storage, awaitHydration, onHydrating, fonts, onFontsLoading, children, }: BloomThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
export declare function BloomThemeProvider({ mode: controlledMode, colorPreset: controlledPreset, defaultMode, defaultColorPreset, onModeChange, onColorPresetChange, persistKey, storage, awaitHydration, onHydrating, fonts, onFontsLoading, nativeWrapperStyle, children, }: BloomThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
58
65
|
//# sourceMappingURL=BloomThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BloomThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theme/BloomThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAQN,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BloomThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theme/BloomThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAQN,MAAM,OAAO,CAAC;AACf,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKhD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,YAAY,CAAC;IAC1B,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C;;;;OAIG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,8CAAqD,CAAC;AAEpF,MAAM,WAAW,uBAAuB;IACtC,uFAAuF;IACvF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,mEAAmE;IACnE,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,mEAAmE;IACnE,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACzC,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAErD;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE9B,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wDAAwD;IACxD,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAEjC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAkJD,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,gBAAgB,EAC7B,WAA0B,EAC1B,kBAAmC,EACnC,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACX,KAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,QAAQ,GACT,EAAE,uBAAuB,2CA+DzB"}
|
|
@@ -4,10 +4,11 @@ export declare function applyDarkClass(resolved: 'light' | 'dark'): void;
|
|
|
4
4
|
* Apply a color preset's CSS custom properties to the document root.
|
|
5
5
|
* No-op on native — only affects web.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `hsl(var(--primary))
|
|
10
|
-
*
|
|
7
|
+
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
8
|
+
* resolved `--color-*` vars (`--color-primary: hsl(185 100% 20%)`) so both
|
|
9
|
+
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
10
|
+
* utilities resolve consistently. Includes extended tokens (card, chart-*,
|
|
11
|
+
* content-area, sidebar-*) so consumer apps don't need to synthesize them.
|
|
11
12
|
*/
|
|
12
13
|
export declare function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark'): void;
|
|
13
14
|
//# sourceMappingURL=apply-dark-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,QAUpF"}
|
|
@@ -17,7 +17,7 @@ export declare function BloomColorScope({ colorPreset, asChild, style, children,
|
|
|
17
17
|
/**
|
|
18
18
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
19
19
|
* caller. Returns a stable native style object carrying the preset's CSS vars.
|
|
20
|
-
* Returns `undefined` when nativewind is not installed.
|
|
20
|
+
* Returns `undefined` on web or when `nativewind` is not installed.
|
|
21
21
|
*/
|
|
22
22
|
export declare function useColorScopeStyle(colorPreset: AppColorName): StyleProp<ViewStyle>;
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iFAAiF;IACjF,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAuBtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -4,19 +4,18 @@ export interface BloomColorScopeProps {
|
|
|
4
4
|
/** Preset to apply within this subtree. */
|
|
5
5
|
colorPreset: AppColorName;
|
|
6
6
|
/**
|
|
7
|
-
* When `true`, do not render a wrapping element. The caller
|
|
8
|
-
*
|
|
9
|
-
* CSS vars (via `useColorScopeStyle`).
|
|
7
|
+
* When `true`, do not render a wrapping element. The caller owns the
|
|
8
|
+
* DOM node that receives the CSS vars (via `useColorScopeStyle`).
|
|
10
9
|
*/
|
|
11
10
|
asChild?: boolean;
|
|
11
|
+
/** Additional style applied to the wrapping `<div>`. Ignored with `asChild`. */
|
|
12
|
+
style?: React.CSSProperties;
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
}
|
|
14
|
-
export declare function BloomColorScope({ colorPreset, asChild, children }: BloomColorScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function BloomColorScope({ colorPreset, asChild, style, children, }: BloomColorScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
15
16
|
/**
|
|
16
17
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
17
|
-
* caller
|
|
18
|
-
* prop). Returns a stable React `style` object carrying every CSS custom
|
|
19
|
-
* property of the preset.
|
|
18
|
+
* caller. Returns a stable React style object carrying the preset's CSS vars.
|
|
20
19
|
*/
|
|
21
20
|
export declare function useColorScopeStyle(colorPreset: AppColorName): React.CSSProperties;
|
|
22
21
|
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gFAAgF;IAChF,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAuBtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
1
2
|
import type { AppColorName } from '../color-presets';
|
|
2
3
|
/**
|
|
3
4
|
* Build the CSS custom-property map for a preset, ready to be applied to a
|
|
@@ -5,4 +6,11 @@ import type { AppColorName } from '../color-presets';
|
|
|
5
6
|
* `@theme` utilities (e.g. `bg-background`) honour the scope.
|
|
6
7
|
*/
|
|
7
8
|
export declare function buildScopeVars(colorPreset: AppColorName, mode: 'light' | 'dark'): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Build a native style object carrying every CSS var of the preset, using
|
|
11
|
+
* NativeWind's `vars()` when available. Returns `undefined` on web (where the
|
|
12
|
+
* provider writes vars to `documentElement` instead) or when `nativewind` is
|
|
13
|
+
* not installed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildNativePresetStyle(colorPreset: AppColorName, mode: 'light' | 'dark'): StyleProp<ViewStyle>;
|
|
8
16
|
//# sourceMappingURL=style-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-builder.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/style-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"style-builder.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/style-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AASrD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,YAAY,EACzB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,YAAY,EACzB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,SAAS,CAAC,SAAS,CAAC,CAKtB"}
|
|
@@ -37,6 +37,14 @@ export declare function useCommonSVGProps(props: Props): {
|
|
|
37
37
|
title?: string | undefined;
|
|
38
38
|
children?: React.ReactNode;
|
|
39
39
|
filter?: string | undefined;
|
|
40
|
+
color?: ColorValue | undefined;
|
|
41
|
+
scale?: import("react-native-svg").NumberArray | undefined;
|
|
42
|
+
scaleX?: import("react-native-svg").NumberProp | undefined;
|
|
43
|
+
scaleY?: import("react-native-svg").NumberProp | undefined;
|
|
44
|
+
translateX?: import("react-native-svg").NumberProp | undefined;
|
|
45
|
+
translateY?: import("react-native-svg").NumberProp | undefined;
|
|
46
|
+
skewX?: import("react-native-svg").NumberProp | undefined;
|
|
47
|
+
skewY?: import("react-native-svg").NumberProp | undefined;
|
|
40
48
|
hitSlop?: number | import("react-native").Insets | undefined;
|
|
41
49
|
id?: string | undefined;
|
|
42
50
|
needsOffscreenAlphaCompositing?: boolean | undefined | undefined;
|
|
@@ -128,14 +136,6 @@ export declare function useCommonSVGProps(props: Props): {
|
|
|
128
136
|
accessibilityShowsLargeContentViewer?: boolean | undefined | undefined;
|
|
129
137
|
accessibilityLargeContentTitle?: string | undefined | undefined;
|
|
130
138
|
accessibilityRespondsToUserInteraction?: boolean | undefined | undefined;
|
|
131
|
-
color?: ColorValue | undefined;
|
|
132
|
-
scale?: import("react-native-svg").NumberArray | undefined;
|
|
133
|
-
scaleX?: import("react-native-svg").NumberProp | undefined;
|
|
134
|
-
scaleY?: import("react-native-svg").NumberProp | undefined;
|
|
135
|
-
translateX?: import("react-native-svg").NumberProp | undefined;
|
|
136
|
-
translateY?: import("react-native-svg").NumberProp | undefined;
|
|
137
|
-
skewX?: import("react-native-svg").NumberProp | undefined;
|
|
138
|
-
skewY?: import("react-native-svg").NumberProp | undefined;
|
|
139
139
|
fontSize?: import("react-native-svg").NumberProp | undefined;
|
|
140
140
|
fontWeight?: import("react-native-svg").FontWeight | undefined;
|
|
141
141
|
fontStyle?: import("react-native-svg").FontStyle | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import './init-css-interop';
|
|
2
2
|
import React from 'react';
|
|
3
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
3
4
|
import { type AppColorName } from './color-presets';
|
|
4
5
|
import { type BloomThemeStorage } from './persistence';
|
|
5
6
|
import type { Theme, ThemeMode } from './types';
|
|
@@ -52,7 +53,13 @@ export interface BloomThemeProviderProps {
|
|
|
52
53
|
fonts?: boolean;
|
|
53
54
|
/** Rendered while native fonts load. Ignored on web. */
|
|
54
55
|
onFontsLoading?: React.ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Style applied to the native `<View>` wrapper that carries the preset's
|
|
58
|
+
* CSS vars. Defaults to `{ flex: 1 }`. Ignored on web (the provider writes
|
|
59
|
+
* vars to `document.documentElement` instead of using a wrapper).
|
|
60
|
+
*/
|
|
61
|
+
nativeWrapperStyle?: StyleProp<ViewStyle>;
|
|
55
62
|
children: React.ReactNode;
|
|
56
63
|
}
|
|
57
|
-
export declare function BloomThemeProvider({ mode: controlledMode, colorPreset: controlledPreset, defaultMode, defaultColorPreset, onModeChange, onColorPresetChange, persistKey, storage, awaitHydration, onHydrating, fonts, onFontsLoading, children, }: BloomThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
64
|
+
export declare function BloomThemeProvider({ mode: controlledMode, colorPreset: controlledPreset, defaultMode, defaultColorPreset, onModeChange, onColorPresetChange, persistKey, storage, awaitHydration, onHydrating, fonts, onFontsLoading, nativeWrapperStyle, children, }: BloomThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
58
65
|
//# sourceMappingURL=BloomThemeProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BloomThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theme/BloomThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAQN,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"BloomThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theme/BloomThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,CAAC;AAE5B,OAAO,KAQN,MAAM,OAAO,CAAC;AACf,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKhD,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,YAAY,CAAC;IAC1B,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C;;;;OAIG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,eAAO,MAAM,iBAAiB,8CAAqD,CAAC;AAEpF,MAAM,WAAW,uBAAuB;IACtC,uFAAuF;IACvF,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,mEAAmE;IACnE,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,mEAAmE;IACnE,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,YAAY,CAAC;IAElC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACzC,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAErD;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iDAAiD;IACjD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAE9B,2DAA2D;IAC3D,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,wDAAwD;IACxD,cAAc,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAEjC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAE1C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAkJD,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,gBAAgB,EAC7B,WAA0B,EAC1B,kBAAmC,EACnC,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,OAAO,EACP,cAAc,EACd,WAAW,EACX,KAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,QAAQ,GACT,EAAE,uBAAuB,2CA+DzB"}
|
|
@@ -4,10 +4,11 @@ export declare function applyDarkClass(resolved: 'light' | 'dark'): void;
|
|
|
4
4
|
* Apply a color preset's CSS custom properties to the document root.
|
|
5
5
|
* No-op on native — only affects web.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* `hsl(var(--primary))
|
|
10
|
-
*
|
|
7
|
+
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
8
|
+
* resolved `--color-*` vars (`--color-primary: hsl(185 100% 20%)`) so both
|
|
9
|
+
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
10
|
+
* utilities resolve consistently. Includes extended tokens (card, chart-*,
|
|
11
|
+
* content-area, sidebar-*) so consumer apps don't need to synthesize them.
|
|
11
12
|
*/
|
|
12
13
|
export declare function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark'): void;
|
|
13
14
|
//# sourceMappingURL=apply-dark-class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"apply-dark-class.d.ts","sourceRoot":"","sources":["../../../../src/theme/apply-dark-class.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGvE,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,QAIxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,QAUpF"}
|
|
@@ -17,7 +17,7 @@ export declare function BloomColorScope({ colorPreset, asChild, style, children,
|
|
|
17
17
|
/**
|
|
18
18
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
19
19
|
* caller. Returns a stable native style object carrying the preset's CSS vars.
|
|
20
|
-
* Returns `undefined` when nativewind is not installed.
|
|
20
|
+
* Returns `undefined` on web or when `nativewind` is not installed.
|
|
21
21
|
*/
|
|
22
22
|
export declare function useColorScopeStyle(colorPreset: AppColorName): StyleProp<ViewStyle>;
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAQ,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAIpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iFAAiF;IACjF,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAuBtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAUlF"}
|
|
@@ -4,19 +4,18 @@ export interface BloomColorScopeProps {
|
|
|
4
4
|
/** Preset to apply within this subtree. */
|
|
5
5
|
colorPreset: AppColorName;
|
|
6
6
|
/**
|
|
7
|
-
* When `true`, do not render a wrapping element. The caller
|
|
8
|
-
*
|
|
9
|
-
* CSS vars (via `useColorScopeStyle`).
|
|
7
|
+
* When `true`, do not render a wrapping element. The caller owns the
|
|
8
|
+
* DOM node that receives the CSS vars (via `useColorScopeStyle`).
|
|
10
9
|
*/
|
|
11
10
|
asChild?: boolean;
|
|
11
|
+
/** Additional style applied to the wrapping `<div>`. Ignored with `asChild`. */
|
|
12
|
+
style?: React.CSSProperties;
|
|
12
13
|
children: React.ReactNode;
|
|
13
14
|
}
|
|
14
|
-
export declare function BloomColorScope({ colorPreset, asChild, children }: BloomColorScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function BloomColorScope({ colorPreset, asChild, style, children, }: BloomColorScopeProps): import("react/jsx-runtime").JSX.Element;
|
|
15
16
|
/**
|
|
16
17
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
17
|
-
* caller
|
|
18
|
-
* prop). Returns a stable React `style` object carrying every CSS custom
|
|
19
|
-
* property of the preset.
|
|
18
|
+
* caller. Returns a stable React style object carrying the preset's CSS vars.
|
|
20
19
|
*/
|
|
21
20
|
export declare function useColorScopeStyle(colorPreset: AppColorName): React.CSSProperties;
|
|
22
21
|
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/index.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGrD,MAAM,WAAW,oBAAoB;IACnC,2CAA2C;IAC3C,WAAW,EAAE,YAAY,CAAC;IAC1B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gFAAgF;IAChF,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAC5B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,OAAe,EACf,KAAK,EACL,QAAQ,GACT,EAAE,oBAAoB,2CAuBtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,YAAY,GAAG,KAAK,CAAC,aAAa,CAUjF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
1
2
|
import type { AppColorName } from '../color-presets';
|
|
2
3
|
/**
|
|
3
4
|
* Build the CSS custom-property map for a preset, ready to be applied to a
|
|
@@ -5,4 +6,11 @@ import type { AppColorName } from '../color-presets';
|
|
|
5
6
|
* `@theme` utilities (e.g. `bg-background`) honour the scope.
|
|
6
7
|
*/
|
|
7
8
|
export declare function buildScopeVars(colorPreset: AppColorName, mode: 'light' | 'dark'): Record<string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Build a native style object carrying every CSS var of the preset, using
|
|
11
|
+
* NativeWind's `vars()` when available. Returns `undefined` on web (where the
|
|
12
|
+
* provider writes vars to `documentElement` instead) or when `nativewind` is
|
|
13
|
+
* not installed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildNativePresetStyle(colorPreset: AppColorName, mode: 'light' | 'dark'): StyleProp<ViewStyle>;
|
|
8
16
|
//# sourceMappingURL=style-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style-builder.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/style-builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"style-builder.d.ts","sourceRoot":"","sources":["../../../../../src/theme/color-scope/style-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAGxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AASrD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,WAAW,EAAE,YAAY,EACzB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAExB;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,YAAY,EACzB,IAAI,EAAE,OAAO,GAAG,MAAM,GACrB,SAAS,CAAC,SAAS,CAAC,CAKtB"}
|
package/package.json
CHANGED
|
@@ -13,7 +13,13 @@ import React, {
|
|
|
13
13
|
useRef,
|
|
14
14
|
useState,
|
|
15
15
|
} from 'react';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
Platform,
|
|
18
|
+
View,
|
|
19
|
+
useColorScheme as useRNColorScheme,
|
|
20
|
+
type StyleProp,
|
|
21
|
+
type ViewStyle,
|
|
22
|
+
} from 'react-native';
|
|
17
23
|
|
|
18
24
|
import { useControllableState } from '../hooks/useControllableState';
|
|
19
25
|
import { FontLoader } from '../fonts/FontLoader';
|
|
@@ -21,6 +27,7 @@ import { FontLoader } from '../fonts/FontLoader';
|
|
|
21
27
|
import { applyDarkClass, applyColorPresetVars } from './apply-dark-class';
|
|
22
28
|
import { buildTheme } from './build-theme';
|
|
23
29
|
import { type AppColorName } from './color-presets';
|
|
30
|
+
import { buildNativePresetStyle } from './color-scope/style-builder';
|
|
24
31
|
import {
|
|
25
32
|
readPersistedTheme,
|
|
26
33
|
readPersistedThemeSync,
|
|
@@ -91,6 +98,13 @@ export interface BloomThemeProviderProps {
|
|
|
91
98
|
/** Rendered while native fonts load. Ignored on web. */
|
|
92
99
|
onFontsLoading?: React.ReactNode;
|
|
93
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Style applied to the native `<View>` wrapper that carries the preset's
|
|
103
|
+
* CSS vars. Defaults to `{ flex: 1 }`. Ignored on web (the provider writes
|
|
104
|
+
* vars to `document.documentElement` instead of using a wrapper).
|
|
105
|
+
*/
|
|
106
|
+
nativeWrapperStyle?: StyleProp<ViewStyle>;
|
|
107
|
+
|
|
94
108
|
children: React.ReactNode;
|
|
95
109
|
}
|
|
96
110
|
|
|
@@ -251,6 +265,7 @@ export function BloomThemeProvider({
|
|
|
251
265
|
onHydrating,
|
|
252
266
|
fonts = true,
|
|
253
267
|
onFontsLoading,
|
|
268
|
+
nativeWrapperStyle,
|
|
254
269
|
children,
|
|
255
270
|
}: BloomThemeProviderProps) {
|
|
256
271
|
const rnScheme = useRNColorScheme();
|
|
@@ -295,11 +310,24 @@ export function BloomThemeProvider({
|
|
|
295
310
|
const shouldAwait = awaitHydration ?? Boolean(persistKey && storage);
|
|
296
311
|
const isGated = shouldAwait && !hydrated;
|
|
297
312
|
|
|
313
|
+
const nativeVarsStyle = useMemo(
|
|
314
|
+
() => (Platform.OS === 'web' ? undefined : buildNativePresetStyle(colorPreset, resolved)),
|
|
315
|
+
[colorPreset, resolved],
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const content = (
|
|
319
|
+
<FontLoader enabled={fonts} fallback={onFontsLoading}>
|
|
320
|
+
{isGated ? onHydrating ?? null : children}
|
|
321
|
+
</FontLoader>
|
|
322
|
+
);
|
|
323
|
+
|
|
298
324
|
return (
|
|
299
325
|
<BloomThemeContext.Provider value={contextValue}>
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
326
|
+
{Platform.OS === 'web' ? (
|
|
327
|
+
content
|
|
328
|
+
) : (
|
|
329
|
+
<View style={[{ flex: 1 }, nativeVarsStyle, nativeWrapperStyle]}>{content}</View>
|
|
330
|
+
)}
|
|
303
331
|
</BloomThemeContext.Provider>
|
|
304
332
|
);
|
|
305
333
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
import { APP_COLOR_PRESETS, type AppColorName } from './color-presets';
|
|
3
|
+
import { getPresetVars } from './preset-vars';
|
|
3
4
|
|
|
4
5
|
export function applyDarkClass(resolved: 'light' | 'dark') {
|
|
5
6
|
if (Platform.OS === 'web' && typeof document !== 'undefined') {
|
|
@@ -11,18 +12,17 @@ export function applyDarkClass(resolved: 'light' | 'dark') {
|
|
|
11
12
|
* Apply a color preset's CSS custom properties to the document root.
|
|
12
13
|
* No-op on native — only affects web.
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `hsl(var(--primary))
|
|
17
|
-
*
|
|
15
|
+
* Writes both the raw HSL triples (e.g. `--primary: 185 100% 20%`) and the
|
|
16
|
+
* resolved `--color-*` vars (`--color-primary: hsl(185 100% 20%)`) so both
|
|
17
|
+
* shadcn-style `hsl(var(--primary))` plumbing and Tailwind v4 `@theme`
|
|
18
|
+
* utilities resolve consistently. Includes extended tokens (card, chart-*,
|
|
19
|
+
* content-area, sidebar-*) so consumer apps don't need to synthesize them.
|
|
18
20
|
*/
|
|
19
21
|
export function applyColorPresetVars(preset: AppColorName, resolved: 'light' | 'dark') {
|
|
20
22
|
if (Platform.OS !== 'web' || typeof document === 'undefined') return;
|
|
23
|
+
if (!APP_COLOR_PRESETS[preset]) return;
|
|
21
24
|
|
|
22
|
-
const
|
|
23
|
-
if (!config) return;
|
|
24
|
-
|
|
25
|
-
const vars = resolved === 'dark' ? config.dark : config.light;
|
|
25
|
+
const vars = getPresetVars(preset, resolved, { includeResolvedColorVars: true });
|
|
26
26
|
const root = document.documentElement.style;
|
|
27
27
|
|
|
28
28
|
for (const [key, value] of Object.entries(vars)) {
|
|
@@ -4,20 +4,7 @@ import { View, type StyleProp, type ViewStyle } from 'react-native';
|
|
|
4
4
|
import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
|
|
5
5
|
import { buildTheme } from '../build-theme';
|
|
6
6
|
import type { AppColorName } from '../color-presets';
|
|
7
|
-
import {
|
|
8
|
-
import { buildScopeVars } from './style-builder';
|
|
9
|
-
|
|
10
|
-
interface NativeWindVarsModule {
|
|
11
|
-
vars: (record: Record<string, string>) => StyleProp<ViewStyle>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const getNativeWindVars = lazyRequire<NativeWindVarsModule>('nativewind');
|
|
15
|
-
|
|
16
|
-
function presetStyle(colorPreset: AppColorName, mode: 'light' | 'dark'): StyleProp<ViewStyle> {
|
|
17
|
-
const module = getNativeWindVars();
|
|
18
|
-
if (!module || typeof module.vars !== 'function') return undefined;
|
|
19
|
-
return module.vars(buildScopeVars(colorPreset, mode));
|
|
20
|
-
}
|
|
7
|
+
import { buildNativePresetStyle } from './style-builder';
|
|
21
8
|
|
|
22
9
|
export interface BloomColorScopeProps {
|
|
23
10
|
/** Preset to apply within this subtree. */
|
|
@@ -51,7 +38,7 @@ export function BloomColorScope({
|
|
|
51
38
|
}, [colorPreset, resolvedMode, parent]);
|
|
52
39
|
|
|
53
40
|
const varsStyle = useMemo(
|
|
54
|
-
() =>
|
|
41
|
+
() => buildNativePresetStyle(colorPreset, resolvedMode),
|
|
55
42
|
[colorPreset, resolvedMode],
|
|
56
43
|
);
|
|
57
44
|
|
|
@@ -65,7 +52,7 @@ export function BloomColorScope({
|
|
|
65
52
|
/**
|
|
66
53
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
67
54
|
* caller. Returns a stable native style object carrying the preset's CSS vars.
|
|
68
|
-
* Returns `undefined` when nativewind is not installed.
|
|
55
|
+
* Returns `undefined` on web or when `nativewind` is not installed.
|
|
69
56
|
*/
|
|
70
57
|
export function useColorScopeStyle(colorPreset: AppColorName): StyleProp<ViewStyle> {
|
|
71
58
|
const parent = useContext(BloomThemeContext);
|
|
@@ -74,7 +61,7 @@ export function useColorScopeStyle(colorPreset: AppColorName): StyleProp<ViewSty
|
|
|
74
61
|
}
|
|
75
62
|
const resolvedMode = parent.theme.mode;
|
|
76
63
|
return useMemo(
|
|
77
|
-
() =>
|
|
64
|
+
() => buildNativePresetStyle(colorPreset, resolvedMode),
|
|
78
65
|
[colorPreset, resolvedMode],
|
|
79
66
|
);
|
|
80
67
|
}
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import React, { useContext, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import { BloomThemeContext } from '../BloomThemeProvider';
|
|
3
|
+
import { BloomThemeContext, type BloomThemeContextValue } from '../BloomThemeProvider';
|
|
4
4
|
import { buildTheme } from '../build-theme';
|
|
5
5
|
import type { AppColorName } from '../color-presets';
|
|
6
|
-
import { BloomThemeContextValue } from '../BloomThemeProvider';
|
|
7
6
|
import { buildScopeVars } from './style-builder';
|
|
8
7
|
|
|
9
8
|
export interface BloomColorScopeProps {
|
|
10
9
|
/** Preset to apply within this subtree. */
|
|
11
10
|
colorPreset: AppColorName;
|
|
12
11
|
/**
|
|
13
|
-
* When `true`, do not render a wrapping element. The caller
|
|
14
|
-
*
|
|
15
|
-
* CSS vars (via `useColorScopeStyle`).
|
|
12
|
+
* When `true`, do not render a wrapping element. The caller owns the
|
|
13
|
+
* DOM node that receives the CSS vars (via `useColorScopeStyle`).
|
|
16
14
|
*/
|
|
17
15
|
asChild?: boolean;
|
|
16
|
+
/** Additional style applied to the wrapping `<div>`. Ignored with `asChild`. */
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
18
|
children: React.ReactNode;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function BloomColorScope({
|
|
21
|
+
export function BloomColorScope({
|
|
22
|
+
colorPreset,
|
|
23
|
+
asChild = false,
|
|
24
|
+
style,
|
|
25
|
+
children,
|
|
26
|
+
}: BloomColorScopeProps) {
|
|
22
27
|
const parent = useContext(BloomThemeContext);
|
|
23
28
|
if (!parent) {
|
|
24
29
|
throw new Error('BloomColorScope must be used within a <BloomThemeProvider>');
|
|
@@ -31,23 +36,21 @@ export function BloomColorScope({ colorPreset, asChild = false, children }: Bloo
|
|
|
31
36
|
return { ...parent, theme, colorPreset };
|
|
32
37
|
}, [colorPreset, resolvedMode, parent]);
|
|
33
38
|
|
|
34
|
-
const
|
|
35
|
-
() => buildScopeVars(colorPreset, resolvedMode) as React.CSSProperties,
|
|
36
|
-
[colorPreset, resolvedMode],
|
|
39
|
+
const varsStyle = useMemo(
|
|
40
|
+
() => ({ ...(buildScopeVars(colorPreset, resolvedMode) as React.CSSProperties), ...style }),
|
|
41
|
+
[colorPreset, resolvedMode, style],
|
|
37
42
|
);
|
|
38
43
|
|
|
39
44
|
return (
|
|
40
45
|
<BloomThemeContext.Provider value={contextValue}>
|
|
41
|
-
{asChild ? children : <div style={
|
|
46
|
+
{asChild ? children : <div style={varsStyle}>{children}</div>}
|
|
42
47
|
</BloomThemeContext.Provider>
|
|
43
48
|
);
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
/**
|
|
47
52
|
* Escape hatch for advanced cases where the wrapping element is owned by the
|
|
48
|
-
* caller
|
|
49
|
-
* prop). Returns a stable React `style` object carrying every CSS custom
|
|
50
|
-
* property of the preset.
|
|
53
|
+
* caller. Returns a stable React style object carrying the preset's CSS vars.
|
|
51
54
|
*/
|
|
52
55
|
export function useColorScopeStyle(colorPreset: AppColorName): React.CSSProperties {
|
|
53
56
|
const parent = useContext(BloomThemeContext);
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { Platform, type StyleProp, type ViewStyle } from 'react-native';
|
|
2
|
+
|
|
1
3
|
import { getPresetVars } from '../preset-vars';
|
|
2
4
|
import type { AppColorName } from '../color-presets';
|
|
5
|
+
import { lazyRequire } from '../../utils/lazy-require';
|
|
6
|
+
|
|
7
|
+
interface NativeWindVarsModule {
|
|
8
|
+
vars: (record: Record<string, string>) => StyleProp<ViewStyle>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const getNativeWindVars = lazyRequire<NativeWindVarsModule>('nativewind');
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
14
|
* Build the CSS custom-property map for a preset, ready to be applied to a
|
|
@@ -12,3 +21,19 @@ export function buildScopeVars(
|
|
|
12
21
|
): Record<string, string> {
|
|
13
22
|
return getPresetVars(colorPreset, mode, { includeResolvedColorVars: true });
|
|
14
23
|
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Build a native style object carrying every CSS var of the preset, using
|
|
27
|
+
* NativeWind's `vars()` when available. Returns `undefined` on web (where the
|
|
28
|
+
* provider writes vars to `documentElement` instead) or when `nativewind` is
|
|
29
|
+
* not installed.
|
|
30
|
+
*/
|
|
31
|
+
export function buildNativePresetStyle(
|
|
32
|
+
colorPreset: AppColorName,
|
|
33
|
+
mode: 'light' | 'dark',
|
|
34
|
+
): StyleProp<ViewStyle> {
|
|
35
|
+
if (Platform.OS === 'web') return undefined;
|
|
36
|
+
const module = getNativeWindVars();
|
|
37
|
+
if (!module || typeof module.vars !== 'function') return undefined;
|
|
38
|
+
return module.vars(buildScopeVars(colorPreset, mode));
|
|
39
|
+
}
|