@unison-ui/native 0.0.0-pr12-20261120174747

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mark de Graaff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @unison-ui/native
2
+
3
+ The React Native renderers for Unison components (Expo, New Architecture).
4
+
5
+ You normally install [`@unison-ui/ui`](https://www.npmjs.com/package/@unison-ui/ui) instead,
6
+ which re-exports this package in React Native.
7
+
8
+ ```bash
9
+ pnpm add @unison-ui/native
10
+ ```
11
+
12
+ Exports today: `Box`, `MotionBadge`, `BoxProps`. Components read the typed theme from
13
+ `@unison-ui/tokens/native` and follow the system colour scheme; no CSS needed.
14
+
15
+ Requires React 19 and React Native 0.88+ (Expo SDK 58) on the New Architecture.
16
+
17
+ > **Preview.** Only `0.0.0-pr…` snapshot builds exist so far; the API will change before `0.1.0`.
18
+ > Part of [Unison](https://github.com/m-de-graaff/unison), a design system for React on the web
19
+ > and React Native, with motion built in. MIT licensed.
package/dist/box.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { BoxProps } from "@unison-ui/core";
2
+ export declare function Box({ tone, testID, children }: BoxProps): import("react").JSX.Element;
package/dist/box.js ADDED
@@ -0,0 +1,22 @@
1
+ import { token, useUnisonTheme } from "./theme.js";
2
+ import { boxStyles } from "@unison-ui/core";
3
+ import { View } from "react-native";
4
+ import { jsx } from "react/jsx-runtime";
5
+ // src/box.tsx
6
+ function Box({ tone = "accent", testID, children }) {
7
+ const theme = useUnisonTheme();
8
+ const size = token(theme, boxStyles.size);
9
+ return /* @__PURE__ */ jsx(View, {
10
+ testID,
11
+ style: {
12
+ width: size,
13
+ height: size,
14
+ borderRadius: token(theme, boxStyles.radius),
15
+ borderWidth: 1,
16
+ borderColor: token(theme, boxStyles.border),
17
+ backgroundColor: token(theme, boxStyles.background[tone])
18
+ },
19
+ children
20
+ });
21
+ }
22
+ export { Box };
@@ -0,0 +1,7 @@
1
+ import { Box } from "./box.js";
2
+ import { MotionBadge } from "./motion-badge.js";
3
+ import { NativeThemeState, NativeThemes, StorageAdapter, UnisonProvider, UnisonProviderProps } from "./provider.js";
4
+ import { useTheme } from "./theme.js";
5
+ import { ThemeScope } from "./theme-scope.js";
6
+ import { BoxProps, ColorScheme, ResolvedScheme, ThemeScopeProps, ThemeState } from "@unison-ui/core";
7
+ export { Box, type BoxProps, type ColorScheme, MotionBadge, type NativeThemeState, type NativeThemes, type ResolvedScheme, type StorageAdapter, ThemeScope, type ThemeScopeProps, type ThemeState, UnisonProvider, type UnisonProviderProps, useTheme };
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { Box } from "./box.js";
2
+ import { MotionBadge } from "./motion-badge.js";
3
+ import { UnisonProvider } from "./provider.js";
4
+ import { useTheme } from "./theme.js";
5
+ import { ThemeScope } from "./theme-scope.js";
6
+ export { Box, MotionBadge, ThemeScope, UnisonProvider, useTheme };
@@ -0,0 +1 @@
1
+ export declare function MotionBadge(): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { Text } from "react-native";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useReducedMotion } from "@unison-ui/motion";
4
+ // src/motion-badge.tsx
5
+ function MotionBadge() {
6
+ const reduced = useReducedMotion();
7
+ return /* @__PURE__ */ jsx(Text, {
8
+ testID: "motion-badge",
9
+ children: `motion: ${reduced ? "reduced" : "full"}`
10
+ });
11
+ }
12
+ export { MotionBadge };
@@ -0,0 +1,30 @@
1
+ import { ColorScheme, ResolvedScheme, ThemeState } from "@unison-ui/core";
2
+ import { ReactNode } from "react";
3
+ import { UnisonTheme } from "@unison-ui/tokens/types";
4
+ /** AsyncStorage, MMKV or anything with these two methods (sync or async). */
5
+ export interface StorageAdapter {
6
+ getItem(key: string): string | null | Promise<string | null>;
7
+ setItem(key: string, value: string): void | Promise<void>;
8
+ }
9
+ export type NativeThemes = Record<string, {
10
+ light: UnisonTheme;
11
+ dark: UnisonTheme;
12
+ }>;
13
+ export type NativeThemeState = ThemeState & {
14
+ tokens: UnisonTheme;
15
+ };
16
+ export interface UnisonProviderProps {
17
+ /** The generated `themes` object (`unison/native/theme.js`). */
18
+ themes: NativeThemes;
19
+ defaultTheme?: string;
20
+ defaultScheme?: ColorScheme;
21
+ /** Persists the choice across launches; without it the choice lasts for the session. */
22
+ storage?: StorageAdapter;
23
+ /** Keys are `<storageKey>-scheme` and `<storageKey>-theme`; default `"unison"`. */
24
+ storageKey?: string;
25
+ /** Tell the app's Tailwind engine (e.g. Uniwind) about changes; the library never imports one. */
26
+ onThemeChange?: (theme: string, scheme: ResolvedScheme) => void;
27
+ children: ReactNode;
28
+ }
29
+ /** Theme and colour scheme state for React Native. */
30
+ export declare function UnisonProvider({ themes, defaultTheme, defaultScheme, storage, storageKey, onThemeChange, children }: UnisonProviderProps): import("react").JSX.Element;
@@ -0,0 +1,99 @@
1
+ import { Appearance, useColorScheme } from "react-native";
2
+ import { createContext, useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/provider.tsx
5
+ /** @internal Shared with theme.ts and theme-scope.tsx. */
6
+ const ThemeContext = createContext(null);
7
+ const SCHEMES = [
8
+ "light",
9
+ "dark",
10
+ "system"
11
+ ];
12
+ /** Theme and colour scheme state for React Native. */
13
+ function UnisonProvider({ themes, defaultTheme = "default", defaultScheme = "system", storage, storageKey = "unison", onThemeChange, children }) {
14
+ const names = useMemo(() => Object.keys(themes), [themes]);
15
+ const [scheme, setSchemeState] = useState(defaultScheme);
16
+ const [theme, setThemeState] = useState(defaultTheme);
17
+ const touched = useRef({
18
+ scheme: false,
19
+ theme: false
20
+ });
21
+ useEffect(() => {
22
+ if (!storage) return;
23
+ let live = true;
24
+ (async () => {
25
+ try {
26
+ const [s, t] = await Promise.all([storage.getItem(`${storageKey}-scheme`), storage.getItem(`${storageKey}-theme`)]);
27
+ if (!live) return;
28
+ if (s && SCHEMES.includes(s) && !touched.current.scheme) setSchemeState(s);
29
+ if (t && Object.hasOwn(themes, t) && !touched.current.theme) setThemeState(t);
30
+ } catch {}
31
+ })();
32
+ return () => {
33
+ live = false;
34
+ };
35
+ }, [
36
+ storage,
37
+ storageKey,
38
+ themes
39
+ ]);
40
+ useEffect(() => {
41
+ Appearance.setColorScheme?.(scheme === "system" ? "unspecified" : scheme);
42
+ }, [scheme]);
43
+ const system = useColorScheme();
44
+ const resolvedScheme = scheme === "system" ? system === "dark" ? "dark" : "light" : scheme;
45
+ const active = Object.hasOwn(themes, theme) ? theme : defaultTheme;
46
+ useEffect(() => {
47
+ onThemeChange?.(active, resolvedScheme);
48
+ }, [
49
+ onThemeChange,
50
+ active,
51
+ resolvedScheme
52
+ ]);
53
+ const persist = useCallback((key, value) => {
54
+ try {
55
+ Promise.resolve(storage?.setItem(`${storageKey}-${key}`, value)).catch(() => {});
56
+ } catch {}
57
+ }, [storage, storageKey]);
58
+ const setScheme = useCallback((s) => {
59
+ touched.current.scheme = true;
60
+ setSchemeState(s);
61
+ persist("scheme", s);
62
+ }, [persist]);
63
+ const setTheme = useCallback((t) => {
64
+ if (!Object.hasOwn(themes, t)) throw new Error(`unknown theme "${t}" (themes: ${names.join(", ")})`);
65
+ touched.current.theme = true;
66
+ setThemeState(t);
67
+ persist("theme", t);
68
+ }, [
69
+ themes,
70
+ names,
71
+ persist
72
+ ]);
73
+ const tokens = ((Object.hasOwn(themes, active) ? themes[active] : void 0) ?? Object.values(themes)[0])?.[resolvedScheme];
74
+ if (!tokens) throw new Error("UnisonProvider needs at least one theme");
75
+ const value = useMemo(() => ({
76
+ scheme,
77
+ resolvedScheme,
78
+ setScheme,
79
+ theme: active,
80
+ setTheme,
81
+ themes: names,
82
+ tokens,
83
+ all: themes
84
+ }), [
85
+ scheme,
86
+ resolvedScheme,
87
+ setScheme,
88
+ active,
89
+ setTheme,
90
+ names,
91
+ tokens,
92
+ themes
93
+ ]);
94
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, {
95
+ value,
96
+ children
97
+ });
98
+ }
99
+ export { ThemeContext, UnisonProvider };
@@ -0,0 +1,7 @@
1
+ import { ThemeScopeProps } from "@unison-ui/core";
2
+ /**
3
+ * Overrides the theme and/or scheme for a subtree: `useTheme()` and `useUnisonTheme()` inside it
4
+ * see the scoped values. Must be inside `UnisonProvider`. Style the subtree from
5
+ * `useTheme().tokens`; a global Tailwind engine can't follow a nested scope.
6
+ */
7
+ export declare function ThemeScope({ theme, scheme, children }: ThemeScopeProps): import("react").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { ThemeContext } from "./provider.js";
2
+ import { useContext, useMemo } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/theme-scope.tsx
5
+ /**
6
+ * Overrides the theme and/or scheme for a subtree: `useTheme()` and `useUnisonTheme()` inside it
7
+ * see the scoped values. Must be inside `UnisonProvider`. Style the subtree from
8
+ * `useTheme().tokens`; a global Tailwind engine can't follow a nested scope.
9
+ */
10
+ function ThemeScope({ theme, scheme, children }) {
11
+ const parent = useContext(ThemeContext);
12
+ if (!parent) throw new Error("ThemeScope must be used inside UnisonProvider");
13
+ const name = theme ?? parent.theme;
14
+ const resolvedScheme = scheme ?? parent.resolvedScheme;
15
+ const tokens = Object.hasOwn(parent.all, name) ? parent.all[name]?.[resolvedScheme] : void 0;
16
+ if (!tokens) throw new Error(`unknown theme "${name}" (themes: ${parent.themes.join(", ")})`);
17
+ const value = useMemo(() => ({
18
+ ...parent,
19
+ theme: name,
20
+ resolvedScheme,
21
+ tokens
22
+ }), [
23
+ parent,
24
+ name,
25
+ resolvedScheme,
26
+ tokens
27
+ ]);
28
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, {
29
+ value,
30
+ children
31
+ });
32
+ }
33
+ export { ThemeScope };
@@ -0,0 +1,4 @@
1
+ import { NativeThemeState } from "./provider.js";
2
+ import "@unison-ui/tokens/types";
3
+ /** The current theme and scheme, the setters and the resolved `tokens`. Throws outside `UnisonProvider`. */
4
+ export declare function useTheme(): NativeThemeState;
package/dist/theme.js ADDED
@@ -0,0 +1,27 @@
1
+ import { ThemeContext } from "./provider.js";
2
+ import { useColorScheme } from "react-native";
3
+ import { themes } from "@unison-ui/tokens/native";
4
+ import { nativeKey } from "@unison-ui/tokens/paths";
5
+ import { useContext } from "react";
6
+ // src/theme.ts
7
+ /** The current theme and scheme, the setters and the resolved `tokens`. Throws outside `UnisonProvider`. */
8
+ function useTheme() {
9
+ const state = useContext(ThemeContext);
10
+ if (!state) throw new Error("useTheme must be used inside UnisonProvider");
11
+ const { all: _all, ...rest } = state;
12
+ return rest;
13
+ }
14
+ /**
15
+ * The tokens for the current theme and scheme. Outside a provider it falls back to the built-in
16
+ * default theme and the system scheme ("light" when unknown).
17
+ */
18
+ function useUnisonTheme() {
19
+ const state = useContext(ThemeContext);
20
+ const scheme = useColorScheme();
21
+ return state ? state.tokens : themes.default[scheme === "dark" ? "dark" : "light"];
22
+ }
23
+ /** Typed lookup by semantic token path: `token(theme, "color.accent")`. */
24
+ function token(theme, path) {
25
+ return nativeKey(path).reduce((node, key) => node[key], theme);
26
+ }
27
+ export { token, useTheme, useUnisonTheme };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@unison-ui/native",
3
+ "version": "0.0.0-pr12-20261120174747",
4
+ "description": "The React Native renderers for Unison components (Expo, New Architecture).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/m-de-graaff/unison.git",
9
+ "directory": "packages/native"
10
+ },
11
+ "homepage": "https://github.com/m-de-graaff/unison#readme",
12
+ "type": "module",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "@unison-ui/core": "^0.0.0-pr12-20261120174747",
25
+ "@unison-ui/motion": "^0.0.0-pr12-20261120174747",
26
+ "@unison-ui/tokens": "^0.0.0-pr12-20261120174747"
27
+ },
28
+ "peerDependencies": {
29
+ "react": ">=19",
30
+ "react-native": ">=0.88"
31
+ },
32
+ "devDependencies": {
33
+ "@react-native/jest-preset": "0.88.1",
34
+ "@testing-library/react-native": "^14.1.0",
35
+ "@types/jest": "^30.0.0",
36
+ "@types/react": "~19.3.0",
37
+ "@unison-ui/tsconfig": "0.0.0",
38
+ "expo": "~58.0.26",
39
+ "jest": "^30.5.2",
40
+ "jest-expo": "~58.0.15",
41
+ "react": "19.3.0",
42
+ "react-native": "0.88.1",
43
+ "test-renderer": "^1.3.1",
44
+ "tsdown": "^0.23.7",
45
+ "typescript": "7.0.2",
46
+ "vitest": "^5.1.1"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "scripts": {
53
+ "build": "tsdown",
54
+ "dev": "tsdown --watch --no-clean",
55
+ "typecheck": "tsc --noEmit",
56
+ "test": "jest && vitest run --typecheck.only"
57
+ }
58
+ }