@pantoken/react-native 0.1.0
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 +37 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.mjs +43 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @pantoken/react-native
|
|
2
|
+
|
|
3
|
+
Instructure design tokens as React Native `StyleSheet`-friendly objects. React Native has no CSS
|
|
4
|
+
variables, so tokens are fully resolved: colors are hex strings, dimensions are numbers (dp), and
|
|
5
|
+
icons are excluded.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @pantoken/react-native
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Also available as `pantoken/reactNative`.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { useColorScheme } from "react-native";
|
|
19
|
+
import { tokensForScheme } from "@pantoken/react-native";
|
|
20
|
+
|
|
21
|
+
const t = tokensForScheme(useColorScheme());
|
|
22
|
+
const styles = { card: { backgroundColor: t.colorBackgroundBase, padding: t.spacingSpaceMd } };
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## API
|
|
26
|
+
|
|
27
|
+
- **`tokensForScheme(scheme): Record<string, RNTokenValue>`** — pick the token object for a color scheme. Pair with React Native's `useColorScheme`; anything other than `"dark"` returns the light set.
|
|
28
|
+
- **`light`, `dark`** — the resolved token objects, exported directly.
|
|
29
|
+
- **`RNTokenValue`** — a token value: a color/string or a numeric dimension.
|
|
30
|
+
|
|
31
|
+
## Related
|
|
32
|
+
|
|
33
|
+
- Reads from `@pantoken/tokens` and resolves through `@pantoken/utils`.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
/** A React Native token value: a colour/string or a numeric dimension. */
|
|
3
|
+
type RNTokenValue = string | number;
|
|
4
|
+
/** The `light`-mode token object. */
|
|
5
|
+
declare const light: Record<string, RNTokenValue>;
|
|
6
|
+
/** The `dark`-mode token object. */
|
|
7
|
+
declare const dark: Record<string, RNTokenValue>;
|
|
8
|
+
/**
|
|
9
|
+
* Select the token object for a colour scheme (pair with RN's `useColorScheme`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { useColorScheme } from "react-native";
|
|
14
|
+
* import { tokensForScheme } from "@pantoken/react-native";
|
|
15
|
+
*
|
|
16
|
+
* const t = tokensForScheme(useColorScheme());
|
|
17
|
+
* const styles = { card: { backgroundColor: t.colorBackgroundBase, padding: t.spacingSpaceMd } };
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function tokensForScheme(scheme: "light" | "dark" | null | undefined): Record<string, RNTokenValue>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { RNTokenValue, dark, light, tokensForScheme };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { tokens } from "@pantoken/tokens";
|
|
2
|
+
import { camelCase, resolveTokens } from "@pantoken/utils";
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* `@pantoken/react-native` — Instructure design tokens as React Native `StyleSheet`-friendly
|
|
6
|
+
* objects. React Native has no CSS variables, so tokens are fully resolved to concrete values:
|
|
7
|
+
* colours stay hex strings, dimensions become numbers (dp), and icons are excluded.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
function build(mode) {
|
|
13
|
+
const resolved = resolveTokens(tokens, { mode });
|
|
14
|
+
const out = {};
|
|
15
|
+
for (const token of tokens) {
|
|
16
|
+
if (token.meta?.kind === "icon") continue;
|
|
17
|
+
const value = (resolved.get(token.name) ?? token.value).trim();
|
|
18
|
+
const dim = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(value);
|
|
19
|
+
out[camelCase(token.name.replace(/^--instui-/, ""))] = dim ? Number(dim[1]) * (dim[2] === "rem" || dim[2] === "em" ? 16 : 1) : value;
|
|
20
|
+
}
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
/** The `light`-mode token object. */
|
|
24
|
+
const light = build("light");
|
|
25
|
+
/** The `dark`-mode token object. */
|
|
26
|
+
const dark = build("dark");
|
|
27
|
+
/**
|
|
28
|
+
* Select the token object for a colour scheme (pair with RN's `useColorScheme`).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { useColorScheme } from "react-native";
|
|
33
|
+
* import { tokensForScheme } from "@pantoken/react-native";
|
|
34
|
+
*
|
|
35
|
+
* const t = tokensForScheme(useColorScheme());
|
|
36
|
+
* const styles = { card: { backgroundColor: t.colorBackgroundBase, padding: t.spacingSpaceMd } };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function tokensForScheme(scheme) {
|
|
40
|
+
return scheme === "dark" ? dark : light;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { dark, light, tokensForScheme };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pantoken/react-native",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Instructure design tokens as React Native StyleSheet-friendly objects (colors as hex, dimensions as numbers).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./dist/index.mjs",
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@pantoken/tokens": "0.1.0",
|
|
19
|
+
"@pantoken/utils": "0.1.0",
|
|
20
|
+
"@pantoken/model": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^24.13.3",
|
|
24
|
+
"typescript": "^6.0.3",
|
|
25
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
|
|
26
|
+
"vite-plus": "0.2.4"
|
|
27
|
+
},
|
|
28
|
+
"pantoken": {
|
|
29
|
+
"key": "reactNative",
|
|
30
|
+
"kind": "subpath"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "vp pack",
|
|
34
|
+
"dev": "vp pack --watch",
|
|
35
|
+
"test": "vp test",
|
|
36
|
+
"check": "vp check"
|
|
37
|
+
}
|
|
38
|
+
}
|