@rootnative/core 0.0.0-alpha.20 → 0.0.0-alpha.22
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/README.md +1 -1
- package/dist/index.d.mts +9 -5
- package/dist/index.mjs +17 -12
- package/llms.txt +6 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ Provides the theme context to all child components. Works with any design system
|
|
|
49
49
|
| Prop | Type | Default | Description |
|
|
50
50
|
|------|------|---------|-------------|
|
|
51
51
|
| `theme` | `BaseTheme` | `lightTheme` (MD3) | Theme object |
|
|
52
|
-
| `iconResolver` | `IconResolver` |
|
|
52
|
+
| `iconResolver` | `IconResolver` | none | Resolves string icon names (`leadingIcon="check"`) to icon nodes. Set once at the app root to use Lucide, SF Symbols, custom SVGs, etc. Pre-built adapters: [`@rootnative/icons`](https://www.npmjs.com/package/@rootnative/icons) |
|
|
53
53
|
| `children` | `ReactNode` | — | App content |
|
|
54
54
|
|
|
55
55
|
### useTheme()
|
package/dist/index.d.mts
CHANGED
|
@@ -89,8 +89,8 @@ type IconResolver = (name: string, props: IconRenderProps) => React.ReactNode;
|
|
|
89
89
|
* Anything a component will accept for an icon prop:
|
|
90
90
|
*
|
|
91
91
|
* - **string** — a name resolved via the `iconResolver` registered on
|
|
92
|
-
* `ThemeProvider`.
|
|
93
|
-
* resolver is set
|
|
92
|
+
* `ThemeProvider`. Renders nothing, with one warning, when no
|
|
93
|
+
* resolver is set.
|
|
94
94
|
* - **ReactElement** — a pre-rendered icon. The caller is responsible for
|
|
95
95
|
* passing size and color; the component will not override them.
|
|
96
96
|
* - **(props) => ReactNode** — a render function that receives the
|
|
@@ -175,6 +175,10 @@ interface ThemeProviderProps {
|
|
|
175
175
|
* `useThemeMode()`. Pass it to control the mode from your own state — the
|
|
176
176
|
* provider then never changes it on its own, so pair it with `onModeChange`.
|
|
177
177
|
*
|
|
178
|
+
* On a static web export, `'system'` renders light on the server and while
|
|
179
|
+
* the client hydrates, then switches to the OS scheme on the next render.
|
|
180
|
+
* The server cannot know the scheme, so the light theme is the first paint.
|
|
181
|
+
*
|
|
178
182
|
* @default 'system'
|
|
179
183
|
*/
|
|
180
184
|
mode?: ThemeMode;
|
|
@@ -204,7 +208,7 @@ interface ThemeProviderProps {
|
|
|
204
208
|
/**
|
|
205
209
|
* Resolves string icon names (e.g. `leadingIcon="check"`) to icon nodes.
|
|
206
210
|
* Set this once at the app root to use SF Symbols, Lucide, custom SVGs,
|
|
207
|
-
* etc.
|
|
211
|
+
* etc. `mdiResolver` from `@rootnative/components/mdi` gives MaterialDesignIcons.
|
|
208
212
|
*
|
|
209
213
|
* @example
|
|
210
214
|
* import { Check, ArrowRight } from 'lucide-react-native'
|
|
@@ -287,8 +291,8 @@ declare function useThemeMode(): ThemeModeContextValue;
|
|
|
287
291
|
|
|
288
292
|
/**
|
|
289
293
|
* Returns the icon resolver registered on the nearest `ThemeProvider`,
|
|
290
|
-
* or `null` if none was provided.
|
|
291
|
-
*
|
|
294
|
+
* or `null` if none was provided. A string icon renders nothing and logs one
|
|
295
|
+
* warning when no resolver is set.
|
|
292
296
|
*/
|
|
293
297
|
declare function useIconResolver(): IconResolver | null;
|
|
294
298
|
|
package/dist/index.mjs
CHANGED
|
@@ -213,6 +213,20 @@ import { MotionConfig } from "@rootnative/inertia";
|
|
|
213
213
|
import * as React4 from "react";
|
|
214
214
|
import { useColorScheme } from "react-native";
|
|
215
215
|
|
|
216
|
+
// src/internal/useIsHydrating.ts
|
|
217
|
+
import { useSyncExternalStore } from "react";
|
|
218
|
+
var subscribeToNothing = () => () => {
|
|
219
|
+
};
|
|
220
|
+
var notHydrating = () => false;
|
|
221
|
+
var isHydratingOnServer = () => true;
|
|
222
|
+
function useIsHydrating() {
|
|
223
|
+
return useSyncExternalStore(
|
|
224
|
+
subscribeToNothing,
|
|
225
|
+
notHydrating,
|
|
226
|
+
isHydratingOnServer
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
216
230
|
// src/provider/IconResolverContext.ts
|
|
217
231
|
import * as React from "react";
|
|
218
232
|
var IconResolverContext = React.createContext(
|
|
@@ -246,7 +260,8 @@ function ThemeProvider({
|
|
|
246
260
|
children
|
|
247
261
|
}) {
|
|
248
262
|
const pair = theme && isThemePair(theme) ? theme : null;
|
|
249
|
-
const
|
|
263
|
+
const measuredScheme = useColorScheme();
|
|
264
|
+
const systemScheme = useIsHydrating() ? "light" : measuredScheme;
|
|
250
265
|
const [uncontrolledMode, setUncontrolledMode] = React4.useState(defaultMode);
|
|
251
266
|
const isControlled = controlledMode !== void 0;
|
|
252
267
|
const mode = isControlled ? controlledMode : uncontrolledMode;
|
|
@@ -342,12 +357,7 @@ function useIconResolver() {
|
|
|
342
357
|
}
|
|
343
358
|
|
|
344
359
|
// src/responsive/useWindowDimensions.ts
|
|
345
|
-
import { useSyncExternalStore } from "react";
|
|
346
360
|
import { useWindowDimensions as useMeasuredWindowDimensions } from "react-native";
|
|
347
|
-
var subscribeToNothing = () => () => {
|
|
348
|
-
};
|
|
349
|
-
var notHydrating = () => false;
|
|
350
|
-
var isHydratingOnServer = () => true;
|
|
351
361
|
var SERVER_WINDOW = Object.freeze({
|
|
352
362
|
width: 0,
|
|
353
363
|
height: 0,
|
|
@@ -356,12 +366,7 @@ var SERVER_WINDOW = Object.freeze({
|
|
|
356
366
|
});
|
|
357
367
|
function useWindowDimensions() {
|
|
358
368
|
const measured = useMeasuredWindowDimensions();
|
|
359
|
-
|
|
360
|
-
subscribeToNothing,
|
|
361
|
-
notHydrating,
|
|
362
|
-
isHydratingOnServer
|
|
363
|
-
);
|
|
364
|
-
return hydrating ? SERVER_WINDOW : measured;
|
|
369
|
+
return useIsHydrating() ? SERVER_WINDOW : measured;
|
|
365
370
|
}
|
|
366
371
|
|
|
367
372
|
// src/responsive/useBreakpoint.ts
|
package/llms.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @rootnative/core — Theme System for React Native
|
|
2
2
|
|
|
3
|
-
> Version: 0.0.0-alpha.
|
|
4
|
-
> Peer deps: react >=19.2.3 <20.0.0, react-native >=0.83.0 <0.87.0, @rootnative/inertia >=0.0.
|
|
3
|
+
> Version: 0.0.0-alpha.22
|
|
4
|
+
> Peer deps: react >=19.2.3 <20.0.0, react-native >=0.83.0 <0.87.0, @rootnative/inertia >=0.0.17 <0.1.0 (required — every animation runs on it)
|
|
5
5
|
> createMaterialTheme needs no extra install — its color engine (@material/material-color-utilities) is bundled behind the create-theme subpath
|
|
6
6
|
|
|
7
7
|
## Quick Start
|
|
@@ -75,11 +75,11 @@ const custom: Theme = {
|
|
|
75
75
|
|
|
76
76
|
Props:
|
|
77
77
|
- `theme?: BaseTheme | { light: BaseTheme; dark: BaseTheme }` — A single theme, or a light/dark pair. A pair enables `useThemeMode()`. Default: `lightTheme` (MD3)
|
|
78
|
-
- `mode?: 'system' | 'light' | 'dark'` — Controlled mode. Leave unset and use `setMode()` instead. Pair with `onModeChange`
|
|
78
|
+
- `mode?: 'system' | 'light' | 'dark'` — Controlled mode. Leave unset and use `setMode()` instead. Pair with `onModeChange`. On a static web export, `'system'` renders light on the server and while the client hydrates, then follows the OS on the next render. No hydration gate is needed around it
|
|
79
79
|
- `defaultMode?: 'system' | 'light' | 'dark'` — Initial mode when uncontrolled. Default: `'system'`
|
|
80
80
|
- `onModeChange?: (mode: ThemeMode) => void`
|
|
81
81
|
- `storage?: { getItem, setItem }` — Persists the mode. Any AsyncStorage-shaped object; sync or async. Nothing is persisted unless you pass this
|
|
82
|
-
- `iconResolver?: IconResolver`
|
|
82
|
+
- `iconResolver?: IconResolver` — Renders string icon names. Pass `mdiResolver` from `@rootnative/components/mdi` for MaterialDesignIcons, or your own. Without it a string name renders nothing and logs one warning
|
|
83
83
|
- `children: ReactNode`
|
|
84
84
|
|
|
85
85
|
### useThemeMode()
|
|
@@ -346,3 +346,5 @@ A static export (`web.output: 'static'`) renders on a server with no DOM, where
|
|
|
346
346
|
|
|
347
347
|
The practical consequence: a breakpoint-dependent layout **starts compact and widens a frame later** on a static export. That is unavoidable — the server cannot know the viewport — so design the compact variant to be the honest first paint. `Grid` inherits all of this, which matters because it resolves a `columns` map internally and leaves a consumer nowhere to put a gate of their own.
|
|
348
348
|
|
|
349
|
+
`ThemeProvider` reads the same hydration flag for `mode="system"`. The export server has no `matchMedia`, so react-native-web reports `'light'` there and the HTML ships the light theme. The provider keeps light while the client hydrates, then switches to the OS scheme on the same re-render as the window size. A reader with a dark system setting sees one light frame first. The `useColorScheme` hook from `react-native` is **not** hydration-safe: a theme chosen from it stays light in a dark browser.
|
|
350
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rootnative/core",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.22",
|
|
4
4
|
"description": "Design-system agnostic theme engine for RootNative UI — a React Native component library. Ships with Material Design 3 out of the box.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"md3"
|
|
54
54
|
],
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@rootnative/inertia": ">=0.0.
|
|
56
|
+
"@rootnative/inertia": ">=0.0.17 <0.1.0",
|
|
57
57
|
"react": ">=19.2.3 <20.0.0",
|
|
58
58
|
"react-native": ">=0.83.0 <0.87.0"
|
|
59
59
|
},
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@material/material-color-utilities": "^0.4.0",
|
|
62
62
|
"@react-native/babel-preset": "^0.86.3",
|
|
63
63
|
"@react-native/jest-preset": "^0.86.3",
|
|
64
|
-
"@rootnative/inertia": "0.0.
|
|
64
|
+
"@rootnative/inertia": "0.0.17",
|
|
65
65
|
"@testing-library/react-native": "^13.3.3",
|
|
66
66
|
"@types/jest": "^29.5.14",
|
|
67
67
|
"@types/react": "^19.0.0",
|