@oxyhq/bloom 0.6.13 → 0.6.15
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/hooks/useControllableState.js +35 -0
- package/lib/commonjs/hooks/useControllableState.js.map +1 -0
- package/lib/commonjs/theme/BloomThemeProvider.js +148 -112
- package/lib/commonjs/theme/BloomThemeProvider.js.map +1 -1
- package/lib/commonjs/theme/build-theme.js +110 -0
- package/lib/commonjs/theme/build-theme.js.map +1 -0
- package/lib/commonjs/theme/color-presets.js +15 -0
- package/lib/commonjs/theme/color-presets.js.map +1 -1
- package/lib/commonjs/theme/index.js +15 -1
- package/lib/commonjs/theme/index.js.map +1 -1
- package/lib/commonjs/theme/persistence.js +147 -0
- package/lib/commonjs/theme/persistence.js.map +1 -0
- package/lib/commonjs/theme/use-isomorphic-layout-effect.js +15 -0
- package/lib/commonjs/theme/use-isomorphic-layout-effect.js.map +1 -0
- package/lib/module/hooks/useControllableState.js +31 -0
- package/lib/module/hooks/useControllableState.js.map +1 -0
- package/lib/module/theme/BloomThemeProvider.js +149 -112
- package/lib/module/theme/BloomThemeProvider.js.map +1 -1
- package/lib/module/theme/build-theme.js +105 -0
- package/lib/module/theme/build-theme.js.map +1 -0
- package/lib/module/theme/color-presets.js +15 -0
- package/lib/module/theme/color-presets.js.map +1 -1
- package/lib/module/theme/index.js +3 -1
- package/lib/module/theme/index.js.map +1 -1
- package/lib/module/theme/persistence.js +139 -0
- package/lib/module/theme/persistence.js.map +1 -0
- package/lib/module/theme/use-isomorphic-layout-effect.js +12 -0
- package/lib/module/theme/use-isomorphic-layout-effect.js.map +1 -0
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts +19 -0
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts +35 -12
- package/lib/typescript/commonjs/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/build-theme.d.ts +20 -0
- package/lib/typescript/commonjs/theme/build-theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/color-presets.d.ts +18 -3
- package/lib/typescript/commonjs/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/index.d.ts +7 -4
- package/lib/typescript/commonjs/theme/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/theme/persistence.d.ts +50 -0
- package/lib/typescript/commonjs/theme/persistence.d.ts.map +1 -0
- package/lib/typescript/commonjs/theme/use-isomorphic-layout-effect.d.ts +8 -0
- package/lib/typescript/commonjs/theme/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/lib/typescript/module/hooks/useControllableState.d.ts +19 -0
- package/lib/typescript/module/hooks/useControllableState.d.ts.map +1 -0
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts +35 -12
- package/lib/typescript/module/theme/BloomThemeProvider.d.ts.map +1 -1
- package/lib/typescript/module/theme/build-theme.d.ts +20 -0
- package/lib/typescript/module/theme/build-theme.d.ts.map +1 -0
- package/lib/typescript/module/theme/color-presets.d.ts +18 -3
- package/lib/typescript/module/theme/color-presets.d.ts.map +1 -1
- package/lib/typescript/module/theme/index.d.ts +7 -4
- package/lib/typescript/module/theme/index.d.ts.map +1 -1
- package/lib/typescript/module/theme/persistence.d.ts +50 -0
- package/lib/typescript/module/theme/persistence.d.ts.map +1 -0
- package/lib/typescript/module/theme/use-isomorphic-layout-effect.d.ts +8 -0
- package/lib/typescript/module/theme/use-isomorphic-layout-effect.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/BloomThemeProvider.modes.test.tsx +159 -0
- package/src/__tests__/BloomThemeProvider.persistence.test.tsx +321 -0
- package/src/__tests__/persistence.test.ts +155 -0
- package/src/__tests__/theme.test.ts +1 -1
- package/src/hooks/useControllableState.ts +44 -0
- package/src/theme/BloomThemeProvider.tsx +251 -157
- package/src/theme/build-theme.ts +128 -0
- package/src/theme/color-presets.ts +19 -3
- package/src/theme/index.ts +16 -4
- package/src/theme/persistence.ts +174 -0
- package/src/theme/use-isomorphic-layout-effect.ts +10 -0
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
export type AppColorName = 'teal' | 'blue' | 'green' | 'amber' | 'yellow' | 'red' | 'purple' | 'pink' | 'sky' | 'orange' | 'mint' | 'oxy' | 'faircoin';
|
|
2
|
+
/**
|
|
3
|
+
* Palette tokens for a single mode (light or dark) of a color preset.
|
|
4
|
+
*
|
|
5
|
+
* Keys carry a leading `--` for historical reasons (shadcn-style CSS variable
|
|
6
|
+
* names) — keep in mind the values are platform-agnostic **raw HSL triples**
|
|
7
|
+
* (e.g. `'185 100% 20%'` or `'185 100% 20% / 0.5'`), not CSS-resolved colors.
|
|
8
|
+
* The same map drives both:
|
|
9
|
+
* - the web layer (written verbatim into `document.documentElement.style`
|
|
10
|
+
* so Tailwind's `hsl(var(--primary))` plumbing picks them up), and
|
|
11
|
+
* - the native layer (`buildTheme` resolves them into `hsl(...)` strings
|
|
12
|
+
* consumable by React Native styles).
|
|
13
|
+
*
|
|
14
|
+
* The `--` prefix is an implementation detail we will drop in a future major.
|
|
15
|
+
*/
|
|
16
|
+
export type PresetTokens = Record<string, string>;
|
|
2
17
|
export interface AppColorPreset {
|
|
3
18
|
name: AppColorName;
|
|
4
19
|
hex: string;
|
|
5
|
-
light:
|
|
6
|
-
dark:
|
|
20
|
+
light: PresetTokens;
|
|
21
|
+
dark: PresetTokens;
|
|
7
22
|
}
|
|
8
|
-
export declare const APP_COLOR_NAMES: AppColorName[];
|
|
23
|
+
export declare const APP_COLOR_NAMES: readonly AppColorName[];
|
|
9
24
|
export declare const HEX_TO_APP_COLOR: Record<string, AppColorName>;
|
|
10
25
|
export declare function hexToAppColorName(hex: string): AppColorName;
|
|
11
26
|
export declare const APP_COLOR_PRESETS: Record<AppColorName, AppColorPreset>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-presets.d.ts","sourceRoot":"","sources":["../../../../src/theme/color-presets.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,CAAC;AAEvJ,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"color-presets.d.ts","sourceRoot":"","sources":["../../../../src/theme/color-presets.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,CAAC;AAEvJ;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAAsH,CAAC;AAE1K,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAczD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAE3D;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,YAAY,EAAE,cAAc,CAkmBlE,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { BloomThemeProvider, BloomColorScope
|
|
2
|
-
export type { BloomThemeProviderProps, BloomThemeContextValue, BloomColorScopeProps } from './BloomThemeProvider';
|
|
1
|
+
export { BloomThemeProvider, BloomColorScope } from './BloomThemeProvider';
|
|
2
|
+
export type { BloomThemeProviderProps, BloomThemeContextValue, BloomColorScopeProps, } from './BloomThemeProvider';
|
|
3
|
+
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
3
4
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
4
5
|
export type { Theme, ThemeColors, ThemeMode } from './types';
|
|
5
|
-
export type { AppColorName, AppColorPreset } from './color-presets';
|
|
6
|
-
export { APP_COLOR_NAMES, APP_COLOR_PRESETS, HEX_TO_APP_COLOR, hexToAppColorName } from './color-presets';
|
|
6
|
+
export type { AppColorName, AppColorPreset, PresetTokens } from './color-presets';
|
|
7
|
+
export { APP_COLOR_NAMES, APP_COLOR_PRESETS, HEX_TO_APP_COLOR, hexToAppColorName, } from './color-presets';
|
|
7
8
|
export { applyDarkClass } from './apply-dark-class';
|
|
8
9
|
export { setColorSchemeSafe } from './set-color-scheme-safe';
|
|
9
10
|
export { initCssInteropDarkMode } from './init-css-interop';
|
|
11
|
+
export type { BloomThemeStorage, PersistedThemeState } from './persistence';
|
|
12
|
+
export { webLocalStorage } from './persistence';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC3E,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
import type { ThemeMode } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Storage adapter for persisting Bloom theme state.
|
|
5
|
+
*
|
|
6
|
+
* Methods may be synchronous or asynchronous. The provider awaits both, so
|
|
7
|
+
* `AsyncStorage`-compatible adapters on native and `localStorage`-backed
|
|
8
|
+
* adapters on web both work without consumer-side branching.
|
|
9
|
+
*
|
|
10
|
+
* On web, a synchronous adapter lets Bloom hydrate before the first paint —
|
|
11
|
+
* preventing a flash of the default palette. On native, the provider can
|
|
12
|
+
* gate `children` rendering until hydration completes (see
|
|
13
|
+
* `awaitHydration` on `BloomThemeProvider`).
|
|
14
|
+
*/
|
|
15
|
+
export interface BloomThemeStorage {
|
|
16
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
17
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
18
|
+
removeItem?(key: string): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface PersistedThemeState {
|
|
21
|
+
mode?: ThemeMode;
|
|
22
|
+
colorPreset?: AppColorName;
|
|
23
|
+
}
|
|
24
|
+
export type SyncReadResult = {
|
|
25
|
+
kind: 'sync';
|
|
26
|
+
state: PersistedThemeState | null;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'async';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'none';
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Read persisted state during the first render. Returns a discriminated union
|
|
34
|
+
* so the provider can tell apart:
|
|
35
|
+
* - `none`: persistence not configured.
|
|
36
|
+
* - `sync`: adapter returned a value synchronously (web `localStorage`).
|
|
37
|
+
* Provider can render immediately with the resolved state.
|
|
38
|
+
* - `async`: adapter returned a Promise (native `AsyncStorage`). Provider
|
|
39
|
+
* must await `readPersistedTheme` before painting if gating is enabled.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readPersistedThemeSync(persistKey: string | undefined, storage: BloomThemeStorage | undefined): SyncReadResult;
|
|
42
|
+
export declare function readPersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined): Promise<PersistedThemeState | null>;
|
|
43
|
+
export declare function writePersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined, state: PersistedThemeState): Promise<void>;
|
|
44
|
+
export declare function removePersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* `localStorage`-backed storage adapter. Only defined on web; on native the
|
|
47
|
+
* export is `undefined` so consumers pass an `AsyncStorage` adapter explicitly.
|
|
48
|
+
*/
|
|
49
|
+
export declare const webLocalStorage: BloomThemeStorage | undefined;
|
|
50
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../src/theme/persistence.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,KAA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E,iBAAiB,GAAG,SAAS,GACrC,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,iBAAiB,GAAG,SA8B9C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `useLayoutEffect` on web (and native — react-native polyfills it) but falls
|
|
4
|
+
* back to `useEffect` during SSR to avoid the React warning. Bloom apps are
|
|
5
|
+
* primarily Expo (no SSR), but Next.js consumers of the web bundle need this.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
8
|
+
//# sourceMappingURL=use-isomorphic-layout-effect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../../../src/theme/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,OAAO,CAAC;AAGnD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,kBACkD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface UseControllableStateOptions<T> {
|
|
2
|
+
/** Controlled value. When defined, the hook does not own internal state. */
|
|
3
|
+
value?: T;
|
|
4
|
+
/** Initial value used when uncontrolled. */
|
|
5
|
+
defaultValue: T;
|
|
6
|
+
/** Notified whenever the value changes, controlled or not. */
|
|
7
|
+
onChange?: (next: T) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Canonical Radix/shadcn-style controllable state hook. Returns a tuple of the
|
|
11
|
+
* current value and a setter that:
|
|
12
|
+
* - updates internal state when uncontrolled, and
|
|
13
|
+
* - always calls `onChange` (so controlled parents stay in sync).
|
|
14
|
+
*
|
|
15
|
+
* Switching between controlled and uncontrolled at runtime is supported but
|
|
16
|
+
* discouraged; the hook keeps the latest `value` for reads either way.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useControllableState<T>({ value, defaultValue, onChange, }: UseControllableStateOptions<T>): [T, (next: T) => void];
|
|
19
|
+
//# sourceMappingURL=useControllableState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useControllableState.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,2BAA2B,CAAC,CAAC;IAC5C,4EAA4E;IAC5E,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,4CAA4C;IAC5C,YAAY,EAAE,CAAC,CAAC;IAChB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,EACtC,KAAK,EACL,YAAY,EACZ,QAAQ,GACT,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC,CAmBzD"}
|
|
@@ -1,40 +1,63 @@
|
|
|
1
1
|
import './init-css-interop';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { type AppColorName } from './color-presets';
|
|
4
|
+
import { type BloomThemeStorage } from './persistence';
|
|
4
5
|
import type { Theme, ThemeMode } from './types';
|
|
5
|
-
/** Build a Theme object from a color preset name and resolved light/dark mode. */
|
|
6
|
-
export declare function buildTheme(appColor: AppColorName, resolved: 'light' | 'dark', isAdaptive?: boolean): Theme;
|
|
7
6
|
export interface BloomThemeContextValue {
|
|
8
7
|
theme: Theme;
|
|
9
8
|
mode: ThemeMode;
|
|
10
9
|
colorPreset: AppColorName;
|
|
11
10
|
setMode: (mode: ThemeMode) => void;
|
|
12
11
|
setColorPreset: (preset: AppColorName) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Restore mode and color preset to the provider defaults
|
|
14
|
+
* (`defaultMode` / `defaultColorPreset`) and clear the persisted entry.
|
|
15
|
+
* Use this when signing out or otherwise resetting per-user state.
|
|
16
|
+
*/
|
|
17
|
+
resetTheme: () => void;
|
|
13
18
|
}
|
|
14
19
|
export declare const BloomThemeContext: React.Context<BloomThemeContextValue | null>;
|
|
15
20
|
export interface BloomThemeProviderProps {
|
|
21
|
+
/** Controlled mode. Omit to use Bloom's internal state (with optional persistence). */
|
|
16
22
|
mode?: ThemeMode;
|
|
23
|
+
/** Controlled color preset. Omit to use Bloom's internal state. */
|
|
17
24
|
colorPreset?: AppColorName;
|
|
25
|
+
/** Initial mode when uncontrolled and nothing is persisted yet. */
|
|
26
|
+
defaultMode?: ThemeMode;
|
|
27
|
+
/** Initial color preset when uncontrolled and nothing is persisted yet. */
|
|
28
|
+
defaultColorPreset?: AppColorName;
|
|
18
29
|
onModeChange?: (mode: ThemeMode) => void;
|
|
19
30
|
onColorPresetChange?: (preset: AppColorName) => void;
|
|
20
31
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
32
|
+
* Persist mode + preset under this storage key. Bloom becomes the single
|
|
33
|
+
* source of truth — apps don't need their own theme store. Has no effect
|
|
34
|
+
* without `storage`.
|
|
24
35
|
*/
|
|
25
|
-
|
|
36
|
+
persistKey?: string;
|
|
26
37
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* before the bundled fonts resolve.
|
|
38
|
+
* Storage adapter paired with `persistKey`. Use `webLocalStorage` on web,
|
|
39
|
+
* or pass an `AsyncStorage`-compatible adapter on native.
|
|
30
40
|
*/
|
|
41
|
+
storage?: BloomThemeStorage;
|
|
42
|
+
/**
|
|
43
|
+
* Block rendering until persisted state has been read. Default `true` when
|
|
44
|
+
* both `persistKey` and `storage` are provided, ensuring native apps don't
|
|
45
|
+
* flash the default palette. Web hydrates synchronously so this is a no-op
|
|
46
|
+
* there.
|
|
47
|
+
*/
|
|
48
|
+
awaitHydration?: boolean;
|
|
49
|
+
/** Rendered while async hydration is pending. */
|
|
50
|
+
onHydrating?: React.ReactNode;
|
|
51
|
+
/** Load and inject Bloom's font system. Default `true`. */
|
|
52
|
+
fonts?: boolean;
|
|
53
|
+
/** Rendered while native fonts load. Ignored on web. */
|
|
31
54
|
onFontsLoading?: React.ReactNode;
|
|
32
55
|
children: React.ReactNode;
|
|
33
56
|
}
|
|
34
|
-
export declare function BloomThemeProvider({ mode: controlledMode, colorPreset: controlledPreset, onModeChange, onColorPresetChange, fonts, onFontsLoading, children, }: BloomThemeProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
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;
|
|
35
58
|
/**
|
|
36
|
-
* Scoped color override for a subtree.
|
|
37
|
-
*
|
|
59
|
+
* Scoped color override for a subtree. Inherits the resolved mode from the
|
|
60
|
+
* parent `BloomThemeProvider` but renders descendants with a different preset.
|
|
38
61
|
*/
|
|
39
62
|
export interface BloomColorScopeProps {
|
|
40
63
|
colorPreset: AppColorName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BloomThemeProvider.d.ts","sourceRoot":"","sources":["../../../../src/theme/BloomThemeProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,oBAAoB,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;AAQf,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAKL,KAAK,iBAAiB,EAEvB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKhD,MA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V,OAAO,EACP,cAAc,EACd,WAAW,EACX,KAAY,EACZ,cAAc,EACd,QAAQ,GACT,EAAE,uBAAuB,2CAkDzB;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,YAAY,CAAC;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,oBAAoB,2CAc9E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
import type { Theme } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Status colors used across the design system. Independent of the accent
|
|
5
|
+
* preset so semantic intent stays stable across themes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const STATUS_COLORS: {
|
|
8
|
+
readonly success: "#10B981";
|
|
9
|
+
readonly error: "#EF4444";
|
|
10
|
+
readonly warning: "#F59E0B";
|
|
11
|
+
readonly info: "#3B82F6";
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Build a `Theme` from a color preset and a resolved light/dark mode.
|
|
15
|
+
*
|
|
16
|
+
* When `isAdaptive` is true and the platform exposes adaptive (Material You /
|
|
17
|
+
* iOS dynamic) colors, those override the preset-derived palette.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildTheme(preset: AppColorName, resolved: 'light' | 'dark', isAdaptive?: boolean): Theme;
|
|
20
|
+
//# sourceMappingURL=build-theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-theme.d.ts","sourceRoot":"","sources":["../../../../src/theme/build-theme.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,YAAY,EAAqB,MAAM,iBAAiB,CAAC;AAE1F,OAAO,KAAK,EAAE,KAAK,EAAe,MAAM,SAAS,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AA6FX;;;;;GAKG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,OAAO,GAAG,MAAM,EAC1B,UAAU,GAAE,OAAe,GAC1B,KAAK,CAUP"}
|
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
export type AppColorName = 'teal' | 'blue' | 'green' | 'amber' | 'yellow' | 'red' | 'purple' | 'pink' | 'sky' | 'orange' | 'mint' | 'oxy' | 'faircoin';
|
|
2
|
+
/**
|
|
3
|
+
* Palette tokens for a single mode (light or dark) of a color preset.
|
|
4
|
+
*
|
|
5
|
+
* Keys carry a leading `--` for historical reasons (shadcn-style CSS variable
|
|
6
|
+
* names) — keep in mind the values are platform-agnostic **raw HSL triples**
|
|
7
|
+
* (e.g. `'185 100% 20%'` or `'185 100% 20% / 0.5'`), not CSS-resolved colors.
|
|
8
|
+
* The same map drives both:
|
|
9
|
+
* - the web layer (written verbatim into `document.documentElement.style`
|
|
10
|
+
* so Tailwind's `hsl(var(--primary))` plumbing picks them up), and
|
|
11
|
+
* - the native layer (`buildTheme` resolves them into `hsl(...)` strings
|
|
12
|
+
* consumable by React Native styles).
|
|
13
|
+
*
|
|
14
|
+
* The `--` prefix is an implementation detail we will drop in a future major.
|
|
15
|
+
*/
|
|
16
|
+
export type PresetTokens = Record<string, string>;
|
|
2
17
|
export interface AppColorPreset {
|
|
3
18
|
name: AppColorName;
|
|
4
19
|
hex: string;
|
|
5
|
-
light:
|
|
6
|
-
dark:
|
|
20
|
+
light: PresetTokens;
|
|
21
|
+
dark: PresetTokens;
|
|
7
22
|
}
|
|
8
|
-
export declare const APP_COLOR_NAMES: AppColorName[];
|
|
23
|
+
export declare const APP_COLOR_NAMES: readonly AppColorName[];
|
|
9
24
|
export declare const HEX_TO_APP_COLOR: Record<string, AppColorName>;
|
|
10
25
|
export declare function hexToAppColorName(hex: string): AppColorName;
|
|
11
26
|
export declare const APP_COLOR_PRESETS: Record<AppColorName, AppColorPreset>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"color-presets.d.ts","sourceRoot":"","sources":["../../../../src/theme/color-presets.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,CAAC;AAEvJ,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"color-presets.d.ts","sourceRoot":"","sources":["../../../../src/theme/color-presets.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,UAAU,CAAC;AAEvJ;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,YAAY,EAAsH,CAAC;AAE1K,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAczD,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAE3D;AAED,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,YAAY,EAAE,cAAc,CAkmBlE,CAAC"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
export { BloomThemeProvider, BloomColorScope
|
|
2
|
-
export type { BloomThemeProviderProps, BloomThemeContextValue, BloomColorScopeProps } from './BloomThemeProvider';
|
|
1
|
+
export { BloomThemeProvider, BloomColorScope } from './BloomThemeProvider';
|
|
2
|
+
export type { BloomThemeProviderProps, BloomThemeContextValue, BloomColorScopeProps, } from './BloomThemeProvider';
|
|
3
|
+
export { buildTheme, STATUS_COLORS } from './build-theme';
|
|
3
4
|
export { useTheme, useThemeColor, useBloomTheme } from './use-theme';
|
|
4
5
|
export type { Theme, ThemeColors, ThemeMode } from './types';
|
|
5
|
-
export type { AppColorName, AppColorPreset } from './color-presets';
|
|
6
|
-
export { APP_COLOR_NAMES, APP_COLOR_PRESETS, HEX_TO_APP_COLOR, hexToAppColorName } from './color-presets';
|
|
6
|
+
export type { AppColorName, AppColorPreset, PresetTokens } from './color-presets';
|
|
7
|
+
export { APP_COLOR_NAMES, APP_COLOR_PRESETS, HEX_TO_APP_COLOR, hexToAppColorName, } from './color-presets';
|
|
7
8
|
export { applyDarkClass } from './apply-dark-class';
|
|
8
9
|
export { setColorSchemeSafe } from './set-color-scheme-safe';
|
|
9
10
|
export { initCssInteropDarkMode } from './init-css-interop';
|
|
11
|
+
export type { BloomThemeStorage, PersistedThemeState } from './persistence';
|
|
12
|
+
export { webLocalStorage } from './persistence';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/theme/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC3E,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACrE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AppColorName } from './color-presets';
|
|
2
|
+
import type { ThemeMode } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Storage adapter for persisting Bloom theme state.
|
|
5
|
+
*
|
|
6
|
+
* Methods may be synchronous or asynchronous. The provider awaits both, so
|
|
7
|
+
* `AsyncStorage`-compatible adapters on native and `localStorage`-backed
|
|
8
|
+
* adapters on web both work without consumer-side branching.
|
|
9
|
+
*
|
|
10
|
+
* On web, a synchronous adapter lets Bloom hydrate before the first paint —
|
|
11
|
+
* preventing a flash of the default palette. On native, the provider can
|
|
12
|
+
* gate `children` rendering until hydration completes (see
|
|
13
|
+
* `awaitHydration` on `BloomThemeProvider`).
|
|
14
|
+
*/
|
|
15
|
+
export interface BloomThemeStorage {
|
|
16
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
17
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
18
|
+
removeItem?(key: string): void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
export interface PersistedThemeState {
|
|
21
|
+
mode?: ThemeMode;
|
|
22
|
+
colorPreset?: AppColorName;
|
|
23
|
+
}
|
|
24
|
+
export type SyncReadResult = {
|
|
25
|
+
kind: 'sync';
|
|
26
|
+
state: PersistedThemeState | null;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'async';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'none';
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Read persisted state during the first render. Returns a discriminated union
|
|
34
|
+
* so the provider can tell apart:
|
|
35
|
+
* - `none`: persistence not configured.
|
|
36
|
+
* - `sync`: adapter returned a value synchronously (web `localStorage`).
|
|
37
|
+
* Provider can render immediately with the resolved state.
|
|
38
|
+
* - `async`: adapter returned a Promise (native `AsyncStorage`). Provider
|
|
39
|
+
* must await `readPersistedTheme` before painting if gating is enabled.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readPersistedThemeSync(persistKey: string | undefined, storage: BloomThemeStorage | undefined): SyncReadResult;
|
|
42
|
+
export declare function readPersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined): Promise<PersistedThemeState | null>;
|
|
43
|
+
export declare function writePersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined, state: PersistedThemeState): Promise<void>;
|
|
44
|
+
export declare function removePersistedTheme(persistKey: string | undefined, storage: BloomThemeStorage | undefined): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* `localStorage`-backed storage adapter. Only defined on web; on native the
|
|
47
|
+
* export is `undefined` so consumers pass an `AsyncStorage` adapter explicitly.
|
|
48
|
+
*/
|
|
49
|
+
export declare const webLocalStorage: BloomThemeStorage | undefined;
|
|
50
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../src/theme/persistence.ts"],"names":[],"mappings":"AACA,OAAO,E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BAAoB,CACxC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACrC,OAAO,CAAC,IAAI,CAAC,CAYf;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,iBAAiB,GAAG,SA8B9C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* `useLayoutEffect` on web (and native — react-native polyfills it) but falls
|
|
4
|
+
* back to `useEffect` during SSR to avoid the React warning. Bloom apps are
|
|
5
|
+
* primarily Expo (no SSR), but Next.js consumers of the web bundle need this.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
|
8
|
+
//# sourceMappingURL=use-isomorphic-layout-effect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-isomorphic-layout-effect.d.ts","sourceRoot":"","sources":["../../../../src/theme/use-isomorphic-layout-effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,OAAO,CAAC;AAGnD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,kBACkD,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text } from 'react-native';
|
|
3
|
+
import { render } from '@testing-library/react-native';
|
|
4
|
+
|
|
5
|
+
let mockColorScheme: 'light' | 'dark' | null = 'light';
|
|
6
|
+
|
|
7
|
+
jest.mock('react-native', () => {
|
|
8
|
+
const actual = jest.requireActual('react-native');
|
|
9
|
+
return {
|
|
10
|
+
...actual,
|
|
11
|
+
useColorScheme: () => mockColorScheme,
|
|
12
|
+
Appearance: {
|
|
13
|
+
...actual.Appearance,
|
|
14
|
+
setColorScheme: jest.fn(),
|
|
15
|
+
getColorScheme: () => mockColorScheme,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
import { BloomThemeProvider } from '../theme/BloomThemeProvider';
|
|
21
|
+
import { useTheme } from '../theme/use-theme';
|
|
22
|
+
import { Appearance } from 'react-native';
|
|
23
|
+
|
|
24
|
+
function Display() {
|
|
25
|
+
const t = useTheme();
|
|
26
|
+
return (
|
|
27
|
+
<>
|
|
28
|
+
<Text testID="resolved">{t.mode}</Text>
|
|
29
|
+
<Text testID="isDark">{String(t.isDark)}</Text>
|
|
30
|
+
</>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
mockColorScheme = 'light';
|
|
36
|
+
(Appearance.setColorScheme as jest.Mock).mockClear();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('BloomThemeProvider — light/dark/system/adaptive flow', () => {
|
|
40
|
+
it('resolves system to light when OS is light', () => {
|
|
41
|
+
mockColorScheme = 'light';
|
|
42
|
+
const { getByTestId } = render(
|
|
43
|
+
<BloomThemeProvider mode="system">
|
|
44
|
+
<Display />
|
|
45
|
+
</BloomThemeProvider>,
|
|
46
|
+
);
|
|
47
|
+
expect(getByTestId('resolved').props.children).toBe('light');
|
|
48
|
+
expect(getByTestId('isDark').props.children).toBe('false');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('resolves system to dark when OS is dark', () => {
|
|
52
|
+
mockColorScheme = 'dark';
|
|
53
|
+
const { getByTestId } = render(
|
|
54
|
+
<BloomThemeProvider mode="system">
|
|
55
|
+
<Display />
|
|
56
|
+
</BloomThemeProvider>,
|
|
57
|
+
);
|
|
58
|
+
expect(getByTestId('resolved').props.children).toBe('dark');
|
|
59
|
+
expect(getByTestId('isDark').props.children).toBe('true');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('falls back to light when OS exposes no scheme', () => {
|
|
63
|
+
mockColorScheme = null;
|
|
64
|
+
const { getByTestId } = render(
|
|
65
|
+
<BloomThemeProvider mode="system">
|
|
66
|
+
<Display />
|
|
67
|
+
</BloomThemeProvider>,
|
|
68
|
+
);
|
|
69
|
+
expect(getByTestId('resolved').props.children).toBe('light');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('treats adaptive mode like system for resolution', () => {
|
|
73
|
+
mockColorScheme = 'dark';
|
|
74
|
+
const { getByTestId } = render(
|
|
75
|
+
<BloomThemeProvider mode="adaptive">
|
|
76
|
+
<Display />
|
|
77
|
+
</BloomThemeProvider>,
|
|
78
|
+
);
|
|
79
|
+
expect(getByTestId('resolved').props.children).toBe('dark');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('explicit light overrides OS dark', () => {
|
|
83
|
+
mockColorScheme = 'dark';
|
|
84
|
+
const { getByTestId } = render(
|
|
85
|
+
<BloomThemeProvider mode="light">
|
|
86
|
+
<Display />
|
|
87
|
+
</BloomThemeProvider>,
|
|
88
|
+
);
|
|
89
|
+
expect(getByTestId('resolved').props.children).toBe('light');
|
|
90
|
+
expect(getByTestId('isDark').props.children).toBe('false');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('explicit dark overrides OS light', () => {
|
|
94
|
+
mockColorScheme = 'light';
|
|
95
|
+
const { getByTestId } = render(
|
|
96
|
+
<BloomThemeProvider mode="dark">
|
|
97
|
+
<Display />
|
|
98
|
+
</BloomThemeProvider>,
|
|
99
|
+
);
|
|
100
|
+
expect(getByTestId('resolved').props.children).toBe('dark');
|
|
101
|
+
expect(getByTestId('isDark').props.children).toBe('true');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('installs explicit override via Appearance.setColorScheme for dark', () => {
|
|
105
|
+
render(
|
|
106
|
+
<BloomThemeProvider mode="dark">
|
|
107
|
+
<Display />
|
|
108
|
+
</BloomThemeProvider>,
|
|
109
|
+
);
|
|
110
|
+
expect(Appearance.setColorScheme).toHaveBeenCalledWith('dark');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('installs explicit override via Appearance.setColorScheme for light', () => {
|
|
114
|
+
render(
|
|
115
|
+
<BloomThemeProvider mode="light">
|
|
116
|
+
<Display />
|
|
117
|
+
</BloomThemeProvider>,
|
|
118
|
+
);
|
|
119
|
+
expect(Appearance.setColorScheme).toHaveBeenCalledWith('light');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('does NOT install an override in system mode (preserves OS link)', () => {
|
|
123
|
+
render(
|
|
124
|
+
<BloomThemeProvider mode="system">
|
|
125
|
+
<Display />
|
|
126
|
+
</BloomThemeProvider>,
|
|
127
|
+
);
|
|
128
|
+
// On non-iOS the call is skipped entirely; we also assert it was NEVER
|
|
129
|
+
// called with 'system' (which would install a bogus override).
|
|
130
|
+
const calls = (Appearance.setColorScheme as jest.Mock).mock.calls;
|
|
131
|
+
for (const call of calls) {
|
|
132
|
+
expect(call[0]).not.toBe('system');
|
|
133
|
+
expect(call[0]).not.toBe('dark');
|
|
134
|
+
expect(call[0]).not.toBe('light');
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('produces different colors for light vs dark resolution', () => {
|
|
139
|
+
mockColorScheme = 'light';
|
|
140
|
+
const { getByTestId: getLight, unmount } = render(
|
|
141
|
+
<BloomThemeProvider mode="system" colorPreset="blue">
|
|
142
|
+
<Display />
|
|
143
|
+
</BloomThemeProvider>,
|
|
144
|
+
);
|
|
145
|
+
const lightResolved = getLight('resolved').props.children;
|
|
146
|
+
unmount();
|
|
147
|
+
|
|
148
|
+
mockColorScheme = 'dark';
|
|
149
|
+
const { getByTestId: getDark } = render(
|
|
150
|
+
<BloomThemeProvider mode="system" colorPreset="blue">
|
|
151
|
+
<Display />
|
|
152
|
+
</BloomThemeProvider>,
|
|
153
|
+
);
|
|
154
|
+
const darkResolved = getDark('resolved').props.children;
|
|
155
|
+
|
|
156
|
+
expect(lightResolved).toBe('light');
|
|
157
|
+
expect(darkResolved).toBe('dark');
|
|
158
|
+
});
|
|
159
|
+
});
|