@kbach/react 0.6.49 → 0.6.51
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/KBACH.md +1044 -0
- package/README.md +110 -6
- package/dist/core/index.d.ts +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/native.d.ts +314 -0
- package/dist/native.js +99 -0
- package/kbach-react.md +27 -1
- package/package.json +18 -2
- package/src/native/babel/index.js +30 -0
- package/src/native/babel-plugin/index.js +605 -0
- package/src/native/babel-plugin/index.test.ts +86 -0
package/kbach-react.md
CHANGED
|
@@ -71,6 +71,32 @@ export default { plugins: [kbach(), reactRouter()] };
|
|
|
71
71
|
```
|
|
72
72
|
Default scan dirs include `app/`. Library mode (client-only, no meta-framework Vite plugin involved) needs no special handling beyond the standard Vite setup above.
|
|
73
73
|
|
|
74
|
+
### React Native / Expo
|
|
75
|
+
Same `npm install @kbach/react` — no separate package. `@kbach/native` still exists but is now a deprecated compatibility shim that re-exports this package.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
// babel.config.js
|
|
79
|
+
module.exports = function (api) {
|
|
80
|
+
api.cache(true);
|
|
81
|
+
return { presets: ['babel-preset-expo', '@kbach/react/babel'] };
|
|
82
|
+
};
|
|
83
|
+
```
|
|
84
|
+
One-liner: `const { createKbachConfig } = require('@kbach/react/native'); module.exports = createKbachConfig();`. Merge into an existing config with `withKbachBabel({ presets: [...] })` (same module). After editing this file: `npx expo start --clear`.
|
|
85
|
+
|
|
86
|
+
```jsx
|
|
87
|
+
import { ThemeProvider } from '@kbach/react/native';
|
|
88
|
+
<ThemeProvider defaultMode="system"><App /></ThemeProvider>
|
|
89
|
+
```
|
|
90
|
+
Native-aware — reads `useColorScheme()`/`useWindowDimensions()` automatically. The plain `ThemeProvider` from `@kbach/react` (no `/native`) has no automatic RN wiring; import the `/native` one on React Native.
|
|
91
|
+
|
|
92
|
+
`disablePersistence` on `<ThemeProvider>` saves to `AsyncStorage` on native (vs. `localStorage` on web) — same prop, platform-appropriate storage.
|
|
93
|
+
|
|
94
|
+
Utility Reference below is tagged inline: `(web only)` entries no-op silently on native. Native-only additions not in the main tables: `tint-{color}` (Image/icon tinting), `perspective-{n}`, `backface-hidden`, `text-shadow`/`text-shadow-lg`. `ring-*` is a partial exception — falls back to `borderWidth`/`borderColor` on native (no box-shadow in RN), which *does* affect layout and shares properties with `border-*`.
|
|
95
|
+
|
|
96
|
+
In a browser (Expo Web, Metro web), `@kbach/react` switches to the same CSS-class strategy as plain web automatically — RN components substitute to HTML elements (`View`→`div`, `Text`→`span`, etc.), RN-only props map to HTML equivalents, and either the Vite plugin (recommended, same as Static CSS setup above) or a `<KbachReset />` near the root covers the base reset.
|
|
97
|
+
|
|
98
|
+
CSS inheritance doesn't exist in React Native — apply font utilities to each `Text`, or define a styled component once: `const Body = styled(Text, 'font-sans text-gray-10 dark:text-white');`.
|
|
99
|
+
|
|
74
100
|
---
|
|
75
101
|
|
|
76
102
|
## Vite Plugin
|
|
@@ -189,7 +215,7 @@ colors.white // '#ffffff'
|
|
|
189
215
|
colors['white/20'] // 'rgba(255,255,255,0.2)'
|
|
190
216
|
colors.alpha('#ff6b35', 60) // 'rgba(255,107,53,0.6)'
|
|
191
217
|
```
|
|
192
|
-
Typed against the built-in theme by default — `colors.blu` (typo) is a compile error. Custom `kbach.config.js` colors work too, with **zero setup**: the Vite plugin (and
|
|
218
|
+
Typed against the built-in theme by default — `colors.blu` (typo) is a compile error. Custom `kbach.config.js` colors work too, with **zero setup**: the Vite plugin (and the Babel plugin, on React Native) automatically generate a `kbach-types.d.ts` next to your config, kept in sync every time the dev server / Metro picks up an edit to it — safe to add to `.gitignore`. `useColors()`/`useSpacing()` see your custom names immediately, no type parameter needed, same typo-catching as the built-in ones.
|
|
193
219
|
|
|
194
220
|
If you'd rather commit the types instead of generating them (a library package with no dev server/bundler step of its own, for instance), hand-author the same thing in any `.d.ts` your tsconfig includes:
|
|
195
221
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kbach/react",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.51",
|
|
4
4
|
"description": "React / React Native components and hooks for the Kbach framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,7 +40,15 @@
|
|
|
40
40
|
"source": "./src/vite-plugin.ts",
|
|
41
41
|
"import": "./dist/vite-plugin.mjs",
|
|
42
42
|
"require": "./dist/vite-plugin.js"
|
|
43
|
-
}
|
|
43
|
+
},
|
|
44
|
+
"./native": {
|
|
45
|
+
"types": "./dist/native.d.ts",
|
|
46
|
+
"source": "./src/native/index.ts",
|
|
47
|
+
"import": "./dist/native.js",
|
|
48
|
+
"require": "./dist/native.js"
|
|
49
|
+
},
|
|
50
|
+
"./babel": "./src/native/babel/index.js",
|
|
51
|
+
"./babel-plugin": "./src/native/babel-plugin/index.js"
|
|
44
52
|
},
|
|
45
53
|
"scripts": {
|
|
46
54
|
"build": "tsup",
|
|
@@ -50,6 +58,7 @@
|
|
|
50
58
|
"postinstall": "node scripts/postinstall.js"
|
|
51
59
|
},
|
|
52
60
|
"devDependencies": {
|
|
61
|
+
"@babel/core": "^7.29.7",
|
|
53
62
|
"@testing-library/react": "^16.3.2",
|
|
54
63
|
"@types/node": "^20.19.42",
|
|
55
64
|
"@types/react": "^19.2.0",
|
|
@@ -61,11 +70,15 @@
|
|
|
61
70
|
"vitest": "^1.0.0"
|
|
62
71
|
},
|
|
63
72
|
"peerDependencies": {
|
|
73
|
+
"@babel/core": "^7.0.0",
|
|
64
74
|
"react": ">=18.0.0",
|
|
65
75
|
"react-native": ">=0.70.0",
|
|
66
76
|
"vite": ">=4.0.0"
|
|
67
77
|
},
|
|
68
78
|
"peerDependenciesMeta": {
|
|
79
|
+
"@babel/core": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
69
82
|
"react-native": {
|
|
70
83
|
"optional": true
|
|
71
84
|
},
|
|
@@ -79,10 +92,13 @@
|
|
|
79
92
|
"files": [
|
|
80
93
|
"dist",
|
|
81
94
|
"scripts",
|
|
95
|
+
"src/native/babel-plugin",
|
|
96
|
+
"src/native/babel",
|
|
82
97
|
"types.d.ts",
|
|
83
98
|
"jsx-runtime.js",
|
|
84
99
|
"jsx-dev-runtime.js",
|
|
85
100
|
"kbach-react.md",
|
|
101
|
+
"KBACH.md",
|
|
86
102
|
"README.md"
|
|
87
103
|
]
|
|
88
104
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @kbach/react/babel — Babel preset (NativeWind-style).
|
|
5
|
+
*
|
|
6
|
+
* babel.config.js:
|
|
7
|
+
* ```js
|
|
8
|
+
* module.exports = function(api) {
|
|
9
|
+
* api.cache(true);
|
|
10
|
+
* return {
|
|
11
|
+
* presets: [
|
|
12
|
+
* 'babel-preset-expo',
|
|
13
|
+
* '@kbach/react/babel',
|
|
14
|
+
* ],
|
|
15
|
+
* };
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Presets run in reverse order, so this preset's plugin runs BEFORE
|
|
20
|
+
* babel-preset-expo's JSX transform — which is the correct ordering:
|
|
21
|
+
* kbach renames className/tw attributes first, then the JSX transform
|
|
22
|
+
* compiles JSX using @kbach/react/jsx-runtime.
|
|
23
|
+
*/
|
|
24
|
+
module.exports = function kbachBabelPreset(api, options = {}) {
|
|
25
|
+
return {
|
|
26
|
+
plugins: [
|
|
27
|
+
[require('../babel-plugin'), options],
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
};
|