@titan-design/react-ui 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +192 -123
- package/dist/index.d.ts +192 -123
- package/dist/index.js +287 -239
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +142 -101
- package/dist/index.mjs.map +1 -1
- package/dist/theme/index.d.mts +774 -769
- package/dist/theme/index.d.ts +774 -769
- package/dist/theme/index.js +6 -1
- package/dist/theme/index.js.map +1 -1
- package/dist/theme/index.mjs +7 -2
- package/dist/theme/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/custom/Workout/SessionHeader.tsx +9 -11
- package/src/components/custom/Workout/SessionRail.tsx +14 -12
- package/src/components/shell/DashboardShell.tsx +6 -3
- package/src/components/ui/surface/Surface.stories.tsx +50 -1
- package/src/components/ui/surface/Surface.test.tsx +105 -1
- package/src/components/ui/surface/Surface.tsx +69 -19
- package/src/components/ui/surface/SurfaceContext.ts +86 -0
- package/src/components/ui/surface/index.ts +12 -0
- package/src/test/nativewind-stub.ts +13 -0
- package/src/theme/ThemeProvider.test.tsx +24 -0
- package/src/theme/ThemeProvider.tsx +23 -6
|
@@ -13,11 +13,16 @@
|
|
|
13
13
|
//
|
|
14
14
|
// The var maps are the SAME canonical `darkThemeCSSVars` / `lightThemeCSSVars`
|
|
15
15
|
// that generate `global.css`, so native and web resolve to identical values.
|
|
16
|
-
|
|
16
|
+
//
|
|
17
|
+
// It also seeds the on-surface colour context (`<Surface>`'s mode), so titan's
|
|
18
|
+
// JS-resolved on-surface colours track the same theme as the className tokens.
|
|
19
|
+
import { vars, useColorScheme } from 'nativewind'
|
|
17
20
|
import { View, type ViewProps } from 'react-native'
|
|
21
|
+
import { SurfaceContext } from '../components/ui/surface/SurfaceContext'
|
|
18
22
|
import { darkThemeCSSVars, lightThemeCSSVars } from './config'
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
/** `'system'` follows nativewind's `useColorScheme()` (mobile light/dark flip). */
|
|
25
|
+
export type ThemeProviderMode = 'dark' | 'light' | 'system'
|
|
21
26
|
|
|
22
27
|
// Precomputed once — `vars()` is pure, so the same style object is reused across
|
|
23
28
|
// renders. Native == web because these are the maps `tokens-css` emits.
|
|
@@ -27,7 +32,11 @@ const MODE_VARS = {
|
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
export interface ThemeProviderProps extends ViewProps {
|
|
30
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Theme mode to register. `'system'` bridges nativewind's `useColorScheme()`
|
|
37
|
+
* so mobile follows the OS light/dark flip; `'dark'`/`'light'` pin it. Mobile
|
|
38
|
+
* is dark-only today, so this defaults to `dark`.
|
|
39
|
+
*/
|
|
31
40
|
mode?: ThemeProviderMode
|
|
32
41
|
}
|
|
33
42
|
|
|
@@ -42,9 +51,17 @@ export function ThemeProvider({
|
|
|
42
51
|
children,
|
|
43
52
|
...props
|
|
44
53
|
}: ThemeProviderProps): React.JSX.Element {
|
|
54
|
+
// `'system'` → follow nativewind's applied scheme, falling back to dark when
|
|
55
|
+
// no scheme is set. `useColorScheme` runs unconditionally (rules of hooks);
|
|
56
|
+
// its result is only used in the `'system'` branch.
|
|
57
|
+
const { colorScheme } = useColorScheme()
|
|
58
|
+
const resolved = mode === 'system' ? (colorScheme ?? 'dark') : mode
|
|
59
|
+
|
|
45
60
|
return (
|
|
46
|
-
<
|
|
47
|
-
{
|
|
48
|
-
|
|
61
|
+
<SurfaceContext.Provider value={{ mode: resolved, level: 'base' }}>
|
|
62
|
+
<View style={[MODE_VARS[resolved], { flex: 1 }, style]} {...props}>
|
|
63
|
+
{children}
|
|
64
|
+
</View>
|
|
65
|
+
</SurfaceContext.Provider>
|
|
49
66
|
)
|
|
50
67
|
}
|