@rootnative/core 0.0.0-alpha.28 → 0.0.0-alpha.29

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 CHANGED
@@ -14,7 +14,7 @@ Design-system agnostic theme engine for [RootNative UI](https://github.com/rootn
14
14
  pnpm add @rootnative/core @rootnative/inertia
15
15
  ```
16
16
 
17
- Peer dependencies: `react >=19.2.3`, `react-native >=0.83.0 <0.87.0`, `@rootnative/inertia >=0.0.10 <0.1.0`
17
+ Peer dependencies: `react >=19.3.0`, `react-native >=0.88.0 <0.89.0`, `@rootnative/inertia >=0.0.20 <0.1.0`
18
18
 
19
19
  `@rootnative/inertia` is required — every animation in the library runs on it.
20
20
  npm and pnpm install required peers automatically; Yarn classic does not, so add
@@ -226,6 +226,7 @@ const { width } = useWindowDimensions()
226
226
  - `ThemeProvider` — Theme context provider (works with any design system, defaults to MD3)
227
227
  - `useTheme` — Access current theme (generic)
228
228
  - `useIconResolver` — Access the configured icon resolver
229
+ - `useThemeScope` / `ThemeScopeProvider` — Read the providers of one place as one value, and provide them again at another place, for content rendered through a portal
229
230
  - `defineTheme` — Type-safe theme creation helper
230
231
  - `createMaterialTheme` — Generate MD3 themes from a seed color (import from `@rootnative/core/create-theme`)
231
232
  - `schemeGuardScript` / `schemeGuardCss` — Hide the light first paint of a static web export from a dark-scheme reader (import from `@rootnative/core/static-export`, with `SCHEME_ATTRIBUTE` and `THEME_READY_ATTRIBUTE`)
@@ -237,7 +238,7 @@ const { width } = useWindowDimensions()
237
238
  - `lightTheme` / `darkTheme` — Built-in MD3 themes
238
239
  - `defaultTopAppBarTokens` — MD3 top app bar defaults
239
240
  - `motionTransitions` — The named-transition registry mounted by `ThemeProvider`
240
- - `BaseTheme`, `Theme`, `MaterialTheme`, `Colors`, `Typography`, `TypographyToken`, `FontWeight`, `Shape`, `Spacing`, `Elevation`, `ElevationLevel`, `ShadowOffset`, `StateLayer`, `Motion`, `MotionSpring`, `TopAppBarTokens`, `IconResolver`, `IconRenderProps`, `IconSource`, `ThemeProviderProps`, `Breakpoint`, `BreakpointValues` — Types
241
+ - `BaseTheme`, `Theme`, `MaterialTheme`, `Colors`, `Typography`, `TypographyToken`, `FontWeight`, `Shape`, `Spacing`, `Elevation`, `ElevationLevel`, `ShadowOffset`, `StateLayer`, `Motion`, `MotionSpring`, `TopAppBarTokens`, `IconResolver`, `IconRenderProps`, `IconSource`, `ThemeProviderProps`, `ThemeScope`, `ThemeScopeProviderProps`, `Breakpoint`, `BreakpointValues` — Types
241
242
 
242
243
  ## Docs
243
244
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { T as Theme, a as TopAppBarTokens, B as BaseTheme, M as Motion, S as Shape } from './types-BQpoSlhx.mjs';
2
2
  export { C as Colors, E as Elevation, b as ElevationLevel, F as FontWeight, c as MaterialTheme, d as MotionSpring, e as ShadowOffset, f as Spacing, g as StateLayer, h as Typography, i as TypographyToken } from './types-BQpoSlhx.mjs';
3
- import { TransitionConfig, NamedTransitions } from '@rootnative/inertia';
3
+ import { TransitionConfig, NamedTransitions, MotionConfigValue } from '@rootnative/inertia';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
  import * as React from 'react';
6
6
  import { ScaledSize } from 'react-native';
@@ -319,6 +319,53 @@ declare function useThemeMode(): ThemeModeContextValue;
319
319
  */
320
320
  declare function useIconResolver(): IconResolver | null;
321
321
 
322
+ /**
323
+ * Everything a `ThemeProvider` gives its descendants, read at one place in
324
+ * the tree so that it can be provided again at another. Treat it as opaque:
325
+ * read it with `useThemeScope()` and hand it to `ThemeScopeProvider`.
326
+ */
327
+ interface ThemeScope {
328
+ /** The resolved theme at the call site. */
329
+ readonly theme: BaseTheme;
330
+ /** The mode value at the call site; `null` under a single-theme provider. */
331
+ readonly mode: ThemeModeContextValue | null;
332
+ /** The icon resolver at the call site; `null` when none is set. */
333
+ readonly iconResolver: IconResolver | null;
334
+ /** The merged motion config at the call site. */
335
+ readonly motion: MotionConfigValue;
336
+ }
337
+ /**
338
+ * Reads the theme, the mode, the icon resolver and the motion config of the
339
+ * nearest providers, as one value for `ThemeScopeProvider`.
340
+ *
341
+ * Use the pair when you render content at another place in the tree, for
342
+ * example through a portal. The content then reads the theme of the place
343
+ * where you wrote it, not the theme of the place where it renders.
344
+ * `@rootnative/components` does this in `Portal`, so every overlay follows
345
+ * the provider it is written under.
346
+ *
347
+ * @example
348
+ * function MyPortal({ children }) {
349
+ * const scope = useThemeScope()
350
+ * return createPortal(
351
+ * <ThemeScopeProvider scope={scope}>{children}</ThemeScopeProvider>,
352
+ * host,
353
+ * )
354
+ * }
355
+ */
356
+ declare function useThemeScope(): ThemeScope;
357
+ interface ThemeScopeProviderProps {
358
+ /** The value that `useThemeScope()` returned at the place to copy. */
359
+ scope: ThemeScope;
360
+ children: React.ReactNode;
361
+ }
362
+ /**
363
+ * Provides a `ThemeScope` to its descendants, as if the providers at the
364
+ * place that read it stood here. A `ThemeProvider` below it inherits from it
365
+ * the same way it inherits from a real parent provider.
366
+ */
367
+ declare function ThemeScopeProvider({ scope, children, }: ThemeScopeProviderProps): react_jsx_runtime.JSX.Element;
368
+
322
369
  /**
323
370
  * Material Design 3 window size classes.
324
371
  * @see https://m3.material.io/foundations/layout/applying-layout/window-size-classes
@@ -421,4 +468,4 @@ declare const material: {
421
468
  readonly defaultTopAppBarTokens: TopAppBarTokens;
422
469
  };
423
470
 
424
- export { BaseTheme, type Breakpoint, type BreakpointValues, type ColorScheme, type IconRenderProps, type IconResolver, type IconSource, Motion, Shape, THEME_MODE_STORAGE_KEY, Theme, type ThemeMode, type ThemeModeContextValue, type ThemeModeStorage, type ThemePair, ThemeProvider, type ThemeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme, useThemeMode, useWindowDimensions };
471
+ export { BaseTheme, type Breakpoint, type BreakpointValues, type ColorScheme, type IconRenderProps, type IconResolver, type IconSource, Motion, Shape, THEME_MODE_STORAGE_KEY, Theme, type ThemeMode, type ThemeModeContextValue, type ThemeModeStorage, type ThemePair, ThemeProvider, type ThemeProviderProps, type ThemeScope, ThemeScopeProvider, type ThemeScopeProviderProps, TopAppBarTokens, applyRoundness, breakpoints, darkTheme, defaultTopAppBarTokens, defineTheme, lightTheme, material, motionTransitions, useBreakpoint, useBreakpointValue, useIconResolver, useTheme, useThemeMode, useThemeScope, useWindowDimensions };
package/dist/index.mjs CHANGED
@@ -391,6 +391,34 @@ function useIconResolver() {
391
391
  return useContext4(IconResolverContext);
392
392
  }
393
393
 
394
+ // src/provider/ThemeScope.tsx
395
+ import { MotionConfig as MotionConfig2, useMotionConfig } from "@rootnative/inertia";
396
+ import * as React5 from "react";
397
+ import { jsx as jsx2 } from "react/jsx-runtime";
398
+ function useThemeScope() {
399
+ const theme = React5.useContext(ThemeContext);
400
+ const mode = React5.useContext(ThemeModeContext);
401
+ const iconResolver = React5.useContext(IconResolverContext);
402
+ const motion = useMotionConfig();
403
+ return React5.useMemo(
404
+ () => ({ theme, mode, iconResolver, motion }),
405
+ [theme, mode, iconResolver, motion]
406
+ );
407
+ }
408
+ function ThemeScopeProvider({
409
+ scope,
410
+ children
411
+ }) {
412
+ return /* @__PURE__ */ jsx2(ThemeContext.Provider, { value: scope.theme, children: /* @__PURE__ */ jsx2(ThemeModeContext.Provider, { value: scope.mode, children: /* @__PURE__ */ jsx2(IconResolverContext.Provider, { value: scope.iconResolver, children: /* @__PURE__ */ jsx2(
413
+ MotionConfig2,
414
+ {
415
+ reducedMotion: scope.motion.reducedMotion,
416
+ transitions: scope.motion.transitions,
417
+ children
418
+ }
419
+ ) }) }) });
420
+ }
421
+
394
422
  // src/responsive/useWindowDimensions.ts
395
423
  import { useWindowDimensions as useMeasuredWindowDimensions } from "react-native";
396
424
  var SERVER_WINDOW = Object.freeze({
@@ -451,6 +479,7 @@ var material = {
451
479
  export {
452
480
  THEME_MODE_STORAGE_KEY,
453
481
  ThemeProvider,
482
+ ThemeScopeProvider,
454
483
  applyRoundness,
455
484
  breakpoints,
456
485
  darkTheme,
@@ -464,5 +493,6 @@ export {
464
493
  useIconResolver,
465
494
  useTheme,
466
495
  useThemeMode,
496
+ useThemeScope,
467
497
  useWindowDimensions
468
498
  };
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.28
4
- > Peer deps: react >=19.2.3 <20.0.0, react-native >=0.83.0 <0.87.0, @rootnative/inertia >=0.0.19 <0.1.0 (required — every animation runs on it)
3
+ > Version: 0.0.0-alpha.29
4
+ > Peer deps: react >=19.3.0 <20.0.0, react-native >=0.88.0 <0.89.0, @rootnative/inertia >=0.0.20 <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
@@ -134,7 +134,23 @@ What a nested provider takes from its parent:
134
134
 
135
135
  A nested provider with a single theme has no mode, so `useThemeMode()` throws below it.
136
136
 
137
- **An overlay does not carry the whole nested theme.** `Dialog`, `Menu`, `Tooltip`, `BottomSheet`, `SearchView`, the modal `NavigationDrawer` and the snackbar render through a `Portal` at the `PortalHost`, which is usually above the nested provider. The overlay surface reads the theme where you write the overlay, so it takes the nested colors. The components in the overlay content read the theme at the `PortalHost`, so a `Button` in a `Dialog` takes the root colors. To give the content the nested theme, wrap it in a nested provider with the same theme (for `Dialog`, inside the slot: `<Dialog.Content><ThemeProvider theme={themes}>…</ThemeProvider></Dialog.Content>`), or, for `Menu`, `Tooltip`, `BottomSheet` and the modal `NavigationDrawer`, put a named `PortalHost` inside the nested provider and pass its name as `hostName`.
137
+ **An overlay carries the nested theme.** `Dialog`, `Menu`, `Tooltip`, `BottomSheet`, `SearchView`, the modal `NavigationDrawer` and the snackbar render through a `Portal` at the `PortalHost`, which is usually above the nested provider. `Portal` reads the theme, the mode, the icon resolver and the named transitions where you write the overlay, and provides them again at the host, so the overlay surface and every component in its content take the nested theme.
138
+
139
+ ### useThemeScope() and ThemeScopeProvider
140
+
141
+ The pair that `Portal` uses, for content you render at another place yourself, for example through `createPortal` or a third-party modal. `useThemeScope()` reads the theme, the mode, the icon resolver and the motion config of the call site as one `ThemeScope` value. `<ThemeScopeProvider scope={scope}>` provides that value to its children, as if the providers of the call site stood there. A `ThemeProvider` below it inherits from it the same way it inherits from a real parent. Treat `ThemeScope` as opaque.
142
+
143
+ ```tsx
144
+ import { ThemeScopeProvider, useThemeScope } from '@rootnative/core'
145
+
146
+ function MyPortal({ children }) {
147
+ const scope = useThemeScope()
148
+ return createPortal(
149
+ <ThemeScopeProvider scope={scope}>{children}</ThemeScopeProvider>,
150
+ host,
151
+ )
152
+ }
153
+ ```
138
154
 
139
155
  ### useTheme()
140
156
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rootnative/core",
3
- "version": "0.0.0-alpha.28",
3
+ "version": "0.0.0-alpha.29",
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,
@@ -62,22 +62,22 @@
62
62
  "md3"
63
63
  ],
64
64
  "peerDependencies": {
65
- "@rootnative/inertia": ">=0.0.19 <0.1.0",
66
- "react": ">=19.2.3 <20.0.0",
67
- "react-native": ">=0.83.0 <0.87.0"
65
+ "@rootnative/inertia": ">=0.0.20 <0.1.0",
66
+ "react": ">=19.3.0 <20.0.0",
67
+ "react-native": ">=0.88.0 <0.89.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@material/material-color-utilities": "^0.4.0",
71
- "@react-native/babel-preset": "^0.86.3",
72
- "@react-native/jest-preset": "^0.86.3",
73
- "@rootnative/inertia": "0.0.19",
71
+ "@react-native/babel-preset": "^0.88.0",
72
+ "@react-native/jest-preset": "^0.88.0",
73
+ "@rootnative/inertia": "0.0.20",
74
74
  "@testing-library/react-native": "^13.3.3",
75
75
  "@types/jest": "^29.5.14",
76
76
  "@types/react": "^19.0.0",
77
77
  "jest": "^29.7.0",
78
- "react": "19.2.3",
79
- "react-native": "0.86.3",
80
- "react-test-renderer": "19.2.3",
78
+ "react": "19.3.0",
79
+ "react-native": "0.88.0",
80
+ "react-test-renderer": "19.3.0",
81
81
  "tsup": "^8.0.0",
82
82
  "typescript": "^5.0.0"
83
83
  },