@kbach/react-native 1.0.0-beta.8 → 1.0.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/AGENTS.md +495 -0
- package/LICENSE +21 -0
- package/README.md +209 -249
- package/THIRD_PARTY_NOTICES.md +41 -0
- package/android/src/main/jniLibs/arm64-v8a/libkbach_core_engine.so +0 -0
- package/android/src/main/jniLibs/x86_64/libkbach_core_engine.so +0 -0
- package/dist/chunk-7CNURQSH.mjs +112 -0
- package/dist/{chunk-OIW7OQWO.mjs → chunk-HYQFT32E.mjs} +2 -2
- package/dist/chunk-MUPEQJRT.mjs +623 -0
- package/dist/darkModeStore.d.ts +73 -0
- package/dist/darkModeStore.js +118 -0
- package/dist/dynamicTokens.d.ts +53 -0
- package/dist/dynamicTokens.js +75 -0
- package/dist/index.d.ts +90 -71
- package/dist/index.js +1433 -606
- package/dist/index.web.d.ts +91 -1
- package/dist/index.web.js +323 -428
- package/dist/index.web.mjs +297 -11
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +1540 -589
- package/dist/jsx-dev-runtime.web.d.ts +2 -2
- package/dist/jsx-dev-runtime.web.js +20 -340
- package/dist/jsx-dev-runtime.web.mjs +18 -6
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +1530 -579
- package/dist/jsx-runtime.web.d.ts +3 -3
- package/dist/jsx-runtime.web.js +17 -340
- package/dist/jsx-runtime.web.mjs +2 -3
- package/dist/semanticElements-Bk3TB-vt.d.ts +334 -0
- package/dist/theme.d.ts +79 -0
- package/dist/{chunk-4BXM3QUV.mjs → theme.js} +120 -17
- package/llms.txt +38 -0
- package/package.json +15 -13
- package/src/babel-plugin.js +144 -2
- package/dist/ThemeContext-Dc5AC-m0.d.mts +0 -98
- package/dist/ThemeContext-Dc5AC-m0.d.ts +0 -98
- package/dist/chunk-CGU7UM2F.mjs +0 -66
- package/dist/chunk-DLIXI5OW.mjs +0 -53
- package/dist/chunk-JR3BLUAV.mjs +0 -1204
- package/dist/chunk-JS5KIGAB.mjs +0 -192
- package/dist/chunk-KV3ZIXSH.mjs +0 -14
- package/dist/chunk-Z664AKW7.mjs +0 -54
- package/dist/index.d.mts +0 -84
- package/dist/index.mjs +0 -34
- package/dist/index.web.d.mts +0 -15
- package/dist/jsx-dev-runtime.d.mts +0 -10
- package/dist/jsx-dev-runtime.mjs +0 -18
- package/dist/jsx-dev-runtime.web.d.mts +0 -10
- package/dist/jsx-runtime.d.mts +0 -7
- package/dist/jsx-runtime.mjs +0 -15
- package/dist/jsx-runtime.web.d.mts +0 -7
package/README.md
CHANGED
|
@@ -1,295 +1,255 @@
|
|
|
1
1
|
# @kbach/react-native
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
> **Beta.** Native (Android-only, no iOS bridge yet) resolves through a
|
|
8
|
-
> Kotlin/JNI TurboModule to an inline style object; Expo Web /
|
|
9
|
-
> react-native-web resolves through the same Rust engine compiled to WASM,
|
|
10
|
-
> but to real generated CSS instead (full modifier support, including
|
|
11
|
-
> `hover:`/`focus:`/etc. — see "Expo Web" below); Expo Go — which can load
|
|
12
|
-
> neither a TurboModule nor WASM — resolves through a third, pure-JS
|
|
13
|
-
> fallback engine with reduced utility coverage (see "Expo Go" below). The
|
|
14
|
-
> native module ships prebuilt (see Setup below) — no Rust toolchain or
|
|
15
|
-
> manual native wiring required on any platform.
|
|
3
|
+
Utility-class styling for React Native — the same class names as
|
|
4
|
+
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react), resolved to a
|
|
5
|
+
`StyleSheet`-ready style object instead of CSS.
|
|
16
6
|
|
|
17
|
-
|
|
7
|
+
> Native is Android-only (no iOS bridge yet) — on iOS, every
|
|
8
|
+
> build (dev client, CLI, EAS) runs the same reduced-coverage JS-fallback
|
|
9
|
+
> engine as Expo Go, not the full native engine. Ships a prebuilt native
|
|
10
|
+
> module — no Rust toolchain or manual linking.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
18
13
|
|
|
19
14
|
```sh
|
|
20
15
|
npm install @kbach/react-native
|
|
21
16
|
```
|
|
22
17
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
Or skip straight to a working setup: `npx @kbach/cli init` detects Expo
|
|
19
|
+
or React Native CLI, installs this package, and patches
|
|
20
|
+
`babel.config.js` for you (on React Native CLI, it'll even offer to run
|
|
21
|
+
the native rebuild) — see [`@kbach/cli`](https://www.npmjs.com/package/@kbach/cli).
|
|
22
|
+
The steps below are what it automates, and still the fallback it prints
|
|
23
|
+
if your `babel.config.js`'s shape is too unusual for it to edit safely.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
The babel plugin (below) is **required on every target, including Expo
|
|
28
|
+
Go** — it's the only thing that makes `className` get intercepted at all;
|
|
29
|
+
without it, `className` is just an unrecognized prop RN silently ignores
|
|
30
|
+
(no styling, no warning). What differs per target is what happens *after*
|
|
31
|
+
that:
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
| Target | Setup |
|
|
34
|
+
| :-- | :-- |
|
|
35
|
+
| **Expo Go** | Add the babel plugin (below). A pure-JS fallback engine loads automatically after that — no other setup. |
|
|
36
|
+
| **Expo Web** / `react-native-web` | Add the babel plugin (below). Resolves through the same CSS engine `@kbach/react` uses after that — no other setup. |
|
|
37
|
+
| **Expo dev client / prebuild / EAS** | Add the babel plugin (below), then `npx expo prebuild && npx expo run:android`. |
|
|
38
|
+
| **React Native CLI** | Add the babel plugin (below), then restart Metro with `--reset-cache` and rebuild the app. |
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
The babel plugin, added to your existing `babel.config.js`:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
// Expo — keep the function form your project already has:
|
|
44
|
+
module.exports = function (api) {
|
|
45
|
+
api.cache(true);
|
|
46
|
+
return {
|
|
47
|
+
presets: ['babel-preset-expo'],
|
|
48
|
+
plugins: ['@kbach/react-native/babel-plugin'],
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
```
|
|
35
52
|
|
|
36
53
|
```js
|
|
37
|
-
//
|
|
54
|
+
// React Native CLI:
|
|
38
55
|
module.exports = {
|
|
39
56
|
presets: ['module:@react-native/babel-preset'],
|
|
40
57
|
plugins: ['@kbach/react-native/babel-plugin'],
|
|
41
58
|
};
|
|
42
59
|
```
|
|
43
60
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
returns `null` rather than throwing) and transparently falls back to a
|
|
64
|
-
**third resolution engine**: a pure-JavaScript reimplementation of the
|
|
65
|
-
same class-resolution logic, ported by hand from
|
|
66
|
-
[`resolve_style.rs`](https://github.com/semsakadanupol/kbach/blob/main/packages/core-engine/src/resolve_style.rs)
|
|
67
|
-
and its resolvers (see
|
|
68
|
-
[`src/jsEngine`](https://github.com/semsakadanupol/kbach/blob/main/packages/react-native/src/jsEngine)
|
|
69
|
-
in the repo) — no WASM (Hermes has no `WebAssembly` API at all) and no
|
|
70
|
-
native code, so it can run anywhere plain JS runs, Expo Go included. A
|
|
71
|
-
real dev-client or CLI build always has the TurboModule registered, so
|
|
72
|
-
this fallback activates ONLY inside Expo Go itself; every other
|
|
73
|
-
environment is completely unaffected.
|
|
74
|
-
|
|
75
|
-
The tradeoff: the JS engine covers layout, spacing, border/radius,
|
|
76
|
-
plain-hex colors (`bg-*`/`text-*`, no opacity composition), font-weight,
|
|
77
|
-
text-transform (`uppercase`/`lowercase`/`capitalize`), text-decoration-line
|
|
78
|
-
(`underline`/`line-through`/`no-underline`), `italic`/`not-italic`, numeric
|
|
79
|
-
line-height and arbitrary letter-spacing, and `shadow-*` — the same
|
|
80
|
-
native-representable subset
|
|
81
|
-
`resolve_utility_native` (the Rust engine's own native dispatcher) covers,
|
|
82
|
-
minus a WASM/JNI dependency. It does **not** cover anything that subset
|
|
83
|
-
already excludes on native (grid, transforms, filters, gradients, DOM-only
|
|
84
|
-
typography like `truncate`/`decoration-*`/`indent-*`, interactivity/scroll
|
|
85
|
-
utilities) — those were never available outside a dev client/CLI build,
|
|
86
|
-
Expo Go doesn't change that. `dark:`/`active:`/`sm:`-`2xl:` modifiers work
|
|
87
|
-
identically to the native/WASM engines (same gating logic, just inlined
|
|
88
|
-
rather than routed through a shared registry). If you hit a class that
|
|
89
|
-
silently doesn't apply only in Expo Go, check whether it resolves under a
|
|
90
|
-
dev client first — if it does, it's outside this fallback's ported scope,
|
|
91
|
-
not a bug in the class itself.
|
|
92
|
-
|
|
93
|
-
### Expo (dev client / prebuild — Android)
|
|
94
|
-
|
|
95
|
-
A dev client gets you the *full* native engine (the same one the CLI path
|
|
96
|
-
above uses) instead of the JS fallback above — worth it once you need
|
|
97
|
-
something outside that fallback's scope. Built once via `expo prebuild`/
|
|
98
|
-
`expo run:android`, functionally the same "real native project" as the CLI
|
|
99
|
-
path above:
|
|
61
|
+
A plain JS reload isn't enough after adding the plugin or editing
|
|
62
|
+
`kbach.config.js` — Metro's transform cache doesn't reliably pick up a
|
|
63
|
+
babel config change on its own. Restart with `--reset-cache` (`npx
|
|
64
|
+
react-native start --reset-cache` / `npx expo start --clear`).
|
|
65
|
+
|
|
66
|
+
Then write classes:
|
|
67
|
+
|
|
68
|
+
```tsx
|
|
69
|
+
import { View, Text } from 'react-native';
|
|
70
|
+
|
|
71
|
+
<View className="flex-1 items-center justify-center bg-white dark:bg-black">
|
|
72
|
+
<Text className="text-lg font-bold">Hello Kbach</Text>
|
|
73
|
+
</View>;
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Theme
|
|
77
|
+
|
|
78
|
+
Optional. Create `kbach.config.js` at your project root — the babel plugin
|
|
79
|
+
picks it up automatically, no import or `applyKbachConfig()` call needed:
|
|
100
80
|
|
|
101
81
|
```js
|
|
102
|
-
//
|
|
82
|
+
// kbach.config.js
|
|
103
83
|
module.exports = {
|
|
104
|
-
|
|
105
|
-
|
|
84
|
+
extend: {
|
|
85
|
+
colors: {
|
|
86
|
+
brand: '#ff6b35',
|
|
87
|
+
surface: 'gray-2',
|
|
88
|
+
dark: { surface: 'gray-11' }, // makes `bg-surface` mode-aware
|
|
89
|
+
},
|
|
90
|
+
},
|
|
106
91
|
};
|
|
107
92
|
```
|
|
108
93
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
94
|
+
It's plain JavaScript — **quote any key containing a hyphen**
|
|
95
|
+
(`'surface-dim': '#121318'`).
|
|
96
|
+
|
|
97
|
+
Full config reference (colors, spacing, breakpoints, fonts, dark mode) is
|
|
98
|
+
in [AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/AGENTS.md).
|
|
99
|
+
|
|
100
|
+
## Dark mode
|
|
113
101
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
the legacy bridge at all. If you're on an older SDK/config with the New
|
|
117
|
-
Architecture off, turn it on in `app.json`
|
|
118
|
-
(`"newArchEnabled": true` under `expo`) before prebuilding.
|
|
119
|
-
|
|
120
|
-
EAS Build works the same way — it runs the same `prebuild` step, so no
|
|
121
|
-
extra configuration beyond the two steps above.
|
|
122
|
-
|
|
123
|
-
See `apps/expo-sandbox` in the [repo](https://github.com/semsakadanupol/kbach)
|
|
124
|
-
for a full working reference project covering both this section and Expo
|
|
125
|
-
Web below — including the `metro.config.js` a monorepo setup like this one
|
|
126
|
-
needs (a plain single-app install doesn't need it).
|
|
127
|
-
|
|
128
|
-
### Expo Web
|
|
129
|
-
|
|
130
|
-
**Works — no extra setup, no separate package, no init call.** `expo start
|
|
131
|
-
--web` (and EAS's web builds) render through `react-native-web` —
|
|
132
|
-
`View`/`Text`/etc. become real DOM elements with real CSS, not a
|
|
133
|
-
Kotlin/JNI bridge — so on web this package resolves classes through the
|
|
134
|
-
same real-CSS engine
|
|
135
|
-
[`@kbach/react`](https://www.npmjs.com/package/@kbach/react) uses on the
|
|
136
|
-
DOM, not the inline-style-object engine native/Expo Go use. Metro picks
|
|
137
|
-
the right implementation per platform on its own via this package's
|
|
138
|
-
`"browser"` (client bundles) and `"node"` (Expo Router's static-rendering/
|
|
139
|
-
SSR bundles — a genuinely separate resolution axis from `platform: 'web'`,
|
|
140
|
-
see `nativeBridge.web.ts`'s own doc comment) export conditions; your app
|
|
141
|
-
code and JSX never change. The WASM module initializes itself eagerly
|
|
142
|
-
(synchronously, at import time — no `await` needed before your first
|
|
143
|
-
render, unlike a from-scratch WASM setup).
|
|
144
|
-
|
|
145
|
-
**Full modifier support, including `hover:`/`focus:`/`group-hover:`/
|
|
146
|
-
`has-[...]`/container queries/etc.** — every modifier
|
|
147
|
-
[`registry.rs`](https://github.com/semsakadanupol/kbach/blob/main/packages/core-engine/src/registry.rs)
|
|
148
|
-
knows, not just the `dark:`/`active:`/responsive subset native/Expo Go
|
|
149
|
-
gate via a live JS parameter. This is possible specifically *because* Expo
|
|
150
|
-
Web is real DOM: real CSS selectors (`:hover`, `:focus`, `@media`,
|
|
151
|
-
`@container`, ...) work exactly the way they do for `@kbach/react`, no
|
|
152
|
-
polyfilling needed. The one wrinkle: `react-native-web`'s `View`/`Text`/
|
|
153
|
-
`Pressable` don't forward a `className` prop to the DOM at all (checked
|
|
154
|
-
against its own `forwardedProps` whitelist), so this can't render a
|
|
155
|
-
literal `className` the way `@kbach/react` does on plain DOM. What it uses
|
|
156
|
-
instead: RN's `dataSet` prop (which RNW DOES forward, as real `data-*`
|
|
157
|
-
attributes) carries the resolved class text into a `data-kb="..."`
|
|
158
|
-
attribute, and the generated CSS targets it with `[data-kb~="..."]`
|
|
159
|
-
attribute selectors instead of `.class` selectors — functionally
|
|
160
|
-
identical to a real `className`, just reached through RN's own prop
|
|
161
|
-
system instead. This also means `active:` is now REAL CSS `:active` (the
|
|
162
|
-
browser's own press-state detection), not a `Pressable`-specific style-
|
|
163
|
-
function simulation the way native's `active:` still is — one fewer
|
|
164
|
-
special case, and closer to actual Tailwind's own semantics.
|
|
165
|
-
|
|
166
|
-
Everything else about this matches `@kbach/react`'s own web engine
|
|
167
|
-
exactly — same
|
|
168
|
-
[`resolve_utility`](https://github.com/semsakadanupol/kbach/blob/main/packages/core-engine/src/resolvers/mod.rs)
|
|
169
|
-
dispatch (not the reduced `resolve_utility_native` subset), so grid,
|
|
170
|
-
transforms, filters, gradients, and DOM-only typography (`truncate`,
|
|
171
|
-
`decoration-*`, etc.) all resolve on Expo Web even though they don't on
|
|
172
|
-
native or Expo Go — see this README's "What this is" section for what's
|
|
173
|
-
covered elsewhere.
|
|
174
|
-
|
|
175
|
-
#### Expo Router static rendering: `dark:`/responsive on the FIRST paint
|
|
176
|
-
|
|
177
|
-
If you use [static rendering](https://docs.expo.dev/router/reference/static-rendering/)
|
|
178
|
-
(`web.output: "static"` — Expo Router's SSR/pre-render feature), any
|
|
179
|
-
`dark:`/`sm:`/etc. class on content that's part of the **initial,
|
|
180
|
-
pre-rendered HTML** resolves against whatever the **server** (Node.js, no
|
|
181
|
-
real display/viewport) reports — not the visiting browser's actual OS
|
|
182
|
-
preference or window size. React's hydration then adopts that
|
|
183
|
-
server-rendered markup as-is rather than silently overwriting it with the
|
|
184
|
-
client's own (correct) values, because a `style`-attribute-only difference
|
|
185
|
-
doesn't fail hydration the way a text-content mismatch does. Concretely: a
|
|
186
|
-
user with their OS in dark mode can see a `dark:` class resolve to its
|
|
187
|
-
*light* value on first paint, with no error or warning anywhere.
|
|
188
|
-
|
|
189
|
-
**This isn't a Kbach bug** — it's the same fundamental constraint every
|
|
190
|
-
OS-preference-based styling system has under SSR (Next.js's own dark-mode
|
|
191
|
-
docs describe the identical problem and fix). The standard fix applies
|
|
192
|
-
here unchanged: don't resolve preference-dependent classes on
|
|
193
|
-
initially-server-rendered content at all; defer them to after your app has
|
|
194
|
-
mounted client-side, e.g.:
|
|
102
|
+
Zero setup on every target. `dark:` classes react to the OS setting;
|
|
103
|
+
`useTheme()` gives you a manual toggle:
|
|
195
104
|
|
|
196
105
|
```tsx
|
|
197
|
-
import {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
function ThemedScreen() {
|
|
201
|
-
const [mounted, setMounted] = useState(false);
|
|
202
|
-
useEffect(() => setMounted(true), []);
|
|
203
|
-
|
|
204
|
-
// Neutral on the server AND on the client's first paint (matches exactly,
|
|
205
|
-
// no hydration mismatch) — only becomes preference-aware once mounted.
|
|
206
|
-
return (
|
|
207
|
-
<View className={mounted ? 'bg-gray-1 dark:bg-gray-12' : 'bg-gray-1'}>
|
|
208
|
-
<Text>Hello</Text>
|
|
209
|
-
</View>
|
|
210
|
-
);
|
|
211
|
-
}
|
|
106
|
+
import { useTheme } from '@kbach/react-native';
|
|
107
|
+
|
|
108
|
+
const { mode, isDark, setMode, toggle } = useTheme();
|
|
212
109
|
```
|
|
213
110
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
## What this is
|
|
219
|
-
|
|
220
|
-
- A JSX runtime (`@kbach/react-native/jsx-runtime`) that intercepts
|
|
221
|
-
`className`/`kb` props on every element and calls into the native, WASM,
|
|
222
|
-
or pure-JS bridge (whichever platform you're on — see the Setup section
|
|
223
|
-
above), synchronously, on every render. On native and Expo Go this
|
|
224
|
-
resolves to an inline `style` object; on Expo Web it resolves to real
|
|
225
|
-
injected CSS plus a `dataSet={{ kb: '...' }}` prop instead — see "Expo
|
|
226
|
-
Web" below for why the two differ.
|
|
227
|
-
- A Babel plugin (`@kbach/react-native/babel-plugin`) that routes your
|
|
228
|
-
app's own files (never `node_modules`) through that JSX runtime via a
|
|
229
|
-
per-file `@jsxImportSource` pragma.
|
|
230
|
-
- `setTheme()`/`getTheme()` for customizing the color palette and spacing
|
|
231
|
-
scale — the same `ThemeConfig` shape `@kbach/react` uses, kept as an
|
|
232
|
-
independent type here so a native-only project isn't forced to depend on
|
|
233
|
-
a web-oriented package.
|
|
234
|
-
- `shadow-*` resolves to real native shadows — RN's discrete
|
|
235
|
-
`shadowColor`/`shadowOffset`/`shadowOpacity`/`shadowRadius` props plus
|
|
236
|
-
Android's `elevation` (both emitted together; `elevation` is what
|
|
237
|
-
actually renders a shadow on Android — the `shadow*` props are iOS-only
|
|
238
|
-
in RN itself, ready for whenever this package gets an iOS bridge),
|
|
239
|
-
derived from the same named tiers (`sm`/`DEFAULT`/`md`/`lg`/`xl`/`2xl`)
|
|
240
|
-
`@kbach/react`'s CSS `box-shadow` scale uses. `shadow-inner` and
|
|
241
|
-
arbitrary `shadow-[...]` values aren't supported — RN's native shadow
|
|
242
|
-
props can't express an inset shadow, and an arbitrary value is a raw CSS
|
|
243
|
-
string with no mechanical translation into discrete native props.
|
|
244
|
-
- Responsive breakpoints (`sm:`/`md:`/`lg:`/`xl:`/`2xl:`) — same
|
|
245
|
-
mobile-first "min-width and up" semantics as web, freely combinable with
|
|
246
|
-
`dark:`/`active:` (e.g. `dark:md:bg-blue-8`). On native/Expo Go, gated
|
|
247
|
-
live against the current window width (`Dimensions.get('window').width`)
|
|
248
|
-
— call RN's own `useWindowDimensions()` somewhere in your tree to
|
|
249
|
-
re-render on rotation/resize, same role `useColorScheme()` plays for
|
|
250
|
-
`dark:` below. On Expo Web this is real `@media (min-width: ...)` CSS
|
|
251
|
-
instead (see "Expo Web" above) — the browser evaluates it continuously
|
|
252
|
-
on its own, so no `useWindowDimensions()` call is needed there at all.
|
|
111
|
+
Works anywhere, no provider. `<ThemeProvider>` is optional — for seeding a
|
|
112
|
+
startup default and opt-in persistence (`<ThemeProvider persist={AsyncStorage}>`).
|
|
113
|
+
Mount at most one — a second instance logs a dev warning, since dark mode
|
|
114
|
+
is one global store, not scoped per provider.
|
|
253
115
|
|
|
254
|
-
##
|
|
116
|
+
## Dynamic values
|
|
255
117
|
|
|
256
|
-
|
|
118
|
+
For a value that changes at runtime without touching component state —
|
|
119
|
+
a live accent color, a user-picked theme:
|
|
257
120
|
|
|
258
121
|
```tsx
|
|
259
|
-
import {
|
|
122
|
+
import { setDynamicToken, useDynamicToken } from '@kbach/react-native';
|
|
260
123
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
124
|
+
setDynamicToken('accent', '#8b5cf6');
|
|
125
|
+
|
|
126
|
+
<View className="bg-[var(--accent)]" />; // updates instantly, everywhere it's used
|
|
127
|
+
const accent = useDynamicToken('accent'); // '#8b5cf6' | undefined, reactive
|
|
265
128
|
```
|
|
266
129
|
|
|
267
|
-
|
|
268
|
-
|
|
130
|
+
Call `setDynamicToken` from a component's own render (guarded to fire
|
|
131
|
+
once), not from module top-level — see
|
|
132
|
+
[AGENTS.md §8](https://github.com/semsakadanupol/kbach/blob/main/packages/react-native/AGENTS.md)
|
|
133
|
+
for why and the exact pattern.
|
|
134
|
+
|
|
135
|
+
## Colors as values
|
|
136
|
+
|
|
137
|
+
For a real color string rather than a class — a chart prop, a shadow color:
|
|
269
138
|
|
|
270
139
|
```tsx
|
|
271
|
-
import {
|
|
140
|
+
import { useColors } from '@kbach/react-native';
|
|
141
|
+
|
|
142
|
+
const colors = useColors();
|
|
143
|
+
colors.blue[6]; // '#2563eb'
|
|
144
|
+
colors.blue['6/50']; // same at 50% opacity
|
|
145
|
+
colors.get('brand'); // a custom color, typed as plain `string`
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Semantic HTML on web
|
|
272
149
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
150
|
+
On Expo Web, `<View>`/`<Text>` render as a plain `<div>`/`<span>` by
|
|
151
|
+
default (`react-native-web`'s own choice, not this package's). For a real
|
|
152
|
+
`<button>`/`<h1>`-`<h6>`/`<p>` instead, use these — each is just the
|
|
153
|
+
right underlying component with its semantic role pre-set, so `className`
|
|
154
|
+
keeps working exactly like it does on a bare `Pressable`/`Text`:
|
|
277
155
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
156
|
+
```tsx
|
|
157
|
+
import { Button, H1, Paragraph } from '@kbach/react-native';
|
|
158
|
+
|
|
159
|
+
<H1 className="text-2xl font-bold">Page title</H1>
|
|
160
|
+
<Paragraph className="text-sm text-gray-7">Body copy.</Paragraph>
|
|
161
|
+
<Button className="px-4 py-2 rounded bg-blue-6" onPress={...}>Save</Button>
|
|
281
162
|
```
|
|
282
163
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
164
|
+
## What differs on native
|
|
165
|
+
|
|
166
|
+
React Native has no CSS cascade, so a fixed subset of modifiers is
|
|
167
|
+
supported — `dark:`, `sm:`–`2xl:`, `active:`, `hover:`, `focus:`,
|
|
168
|
+
`disabled:`, and `data-[…]:`/`aria-[…]:`. `group-*`/`peer-*`/`has-[…]` and
|
|
169
|
+
container queries parse without error but do not apply. When two classes
|
|
170
|
+
set the same property the more-specific one wins regardless of source
|
|
171
|
+
order (`dark:bg-black bg-white` → black in dark mode).
|
|
172
|
+
|
|
173
|
+
`hover:` only fires for pointer-capable input (mouse/trackpad) — it's
|
|
174
|
+
inert on pure touch, so don't expect it to do anything on a phone/tablet
|
|
175
|
+
with no attached pointer.
|
|
176
|
+
|
|
177
|
+
`disabled:`/`aria-[…]:`/`data-[…]:` read that exact element's own props —
|
|
178
|
+
never a parent's, since there's no `group-disabled:`-style cascade to
|
|
179
|
+
inherit through. `<Pressable disabled><Text className="disabled:text-gray-5">`
|
|
180
|
+
does nothing to the `Text`, silently, because `Text` never received a
|
|
181
|
+
`disabled` prop of its own; the prop has to be repeated on whichever
|
|
182
|
+
element the modifier is written on:
|
|
183
|
+
`<Pressable disabled><Text disabled className="disabled:text-gray-5">`.
|
|
184
|
+
|
|
185
|
+
Expo Go, and iOS in ANY build type (no native engine there yet — see the
|
|
186
|
+
callout at the top), cover the same documented subset of utilities (no
|
|
187
|
+
grid, filters, gradients, or DOM-only typography). Expo Web and a real
|
|
188
|
+
**Android** dev-client/CLI build cover the full set.
|
|
189
|
+
|
|
190
|
+
A malformed or misused value fails safely — a deduped, dev-only
|
|
191
|
+
`console.warn` naming the offending class and the fix, never a crash or
|
|
192
|
+
silently-wrong output. Confirmed across CSS-injection attempts, invalid
|
|
193
|
+
`calc()` operands, and double-mounting.
|
|
194
|
+
|
|
195
|
+
`clsx()` — this package's own bundled copy, `import { clsx } from
|
|
196
|
+
'@kbach/react-native'` — composes conditional class strings the same way
|
|
197
|
+
the standalone `clsx` package does. You don't need it for `dark:`/`sm:`/
|
|
198
|
+
etc. (those work as plain classes), but it's there for `isActive &&
|
|
199
|
+
'bg-blue-6'`-style composition.
|
|
200
|
+
|
|
201
|
+
See [this package's own AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/packages/react-native/AGENTS.md)
|
|
202
|
+
for the complete reference — modifier list, `calc()`/`min()`/`max()`/
|
|
203
|
+
`clamp()` support, dynamic tokens, monorepo setup, and failure modes; see
|
|
204
|
+
the [root AGENTS.md](https://github.com/semsakadanupol/kbach/blob/main/AGENTS.md)
|
|
205
|
+
for `kbach.config.js` and how the underlying engine is built.
|
|
206
|
+
|
|
207
|
+
<!-- kbach:ai-rules:start -->
|
|
208
|
+
## For AI assistants
|
|
209
|
+
|
|
210
|
+
AI models learned Tailwind CSS, not Kbach. Give your assistant these rules (they're also in `llms.txt` in this package, and `npx @kbach/cli ai` writes them into your project's `AGENTS.md`):
|
|
211
|
+
|
|
212
|
+
```text
|
|
213
|
+
Kbach rules. Follow them in every class you write.
|
|
214
|
+
|
|
215
|
+
1. Color shades go from 1 (lightest) to 12 (darkest). Never use 50 to 950.
|
|
216
|
+
Convert: 50→1 100→2 200→3 300→4 400→5 500→6 600→7 700→8 800→9 900→10 950→11.
|
|
217
|
+
Write bg-blue-6, text-gray-11, border-slate-3. Never bg-blue-500.
|
|
218
|
+
2. Color families: amber blue cyan emerald fuchsia gray green indigo lime
|
|
219
|
+
mauve mist neutral olive orange pink purple red rose sky slate stone taupe
|
|
220
|
+
teal violet yellow zinc. Single colors: white black transparent current
|
|
221
|
+
gold silver bronze copper coal.
|
|
222
|
+
3. Every other class follows Tailwind CSS v4.3 names and values: spacing in
|
|
223
|
+
steps of 4px (p-4 is 16px), variants such as hover:, md: and dark:,
|
|
224
|
+
values in square brackets, a slash for opacity (bg-black/50).
|
|
225
|
+
Gradients: bg-linear-to-r from-* via-* to-*.
|
|
226
|
+
4. There is no tailwind.config.js, no @tailwind, no @import "tailwindcss",
|
|
227
|
+
no @theme and no @apply. Settings go in kbach.config.js
|
|
228
|
+
(export default { darkMode, theme, extend }). Custom animations go in
|
|
229
|
+
extend.keyframes and extend.animation and are used as animate-<name>.
|
|
230
|
+
5. Plain HTML page: put <script>window.kbachConfig = { ... }</script> BEFORE
|
|
231
|
+
<script src="https://cdn.jsdelivr.net/npm/@kbach/browser"></script>.
|
|
232
|
+
A theme button calls Kbach.toggle() and needs darkMode: 'class' or
|
|
233
|
+
'attribute' in that config.
|
|
234
|
+
6. React with Vite: import { kbach } from '@kbach/react/vite' and add kbach()
|
|
235
|
+
to plugins; import './kbach.css' once in the entry file. Write every class
|
|
236
|
+
in full: never build one from pieces like 'bg-' + color.
|
|
237
|
+
7. React Native: '@kbach/react-native/babel-plugin' must be in
|
|
238
|
+
babel.config.js. On a phone there is no grid, no gradients, no filters, no
|
|
239
|
+
transitions or animations, no group-*, peer-*, before: or after:. Use
|
|
240
|
+
flex-row for rows (a View is a column). Values in brackets: px or rem only.
|
|
241
|
+
8. Dark mode switches use useTheme() from '@kbach/react' or
|
|
242
|
+
'@kbach/react-native': { mode, isDark, setMode, toggle }.
|
|
243
|
+
|
|
244
|
+
Full documentation: https://kbach.vercel.app
|
|
245
|
+
```
|
|
246
|
+
<!-- kbach:ai-rules:end -->
|
|
292
247
|
|
|
293
248
|
## License
|
|
294
249
|
|
|
295
250
|
MIT
|
|
251
|
+
|
|
252
|
+
Tailwind CSS is a trademark of Tailwind Labs Inc. Kbach is an independent
|
|
253
|
+
project and is not affiliated with, sponsored by, or endorsed by Tailwind Labs.
|
|
254
|
+
See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for the Tailwind CSS
|
|
255
|
+
license notice.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!-- GENERATED from the repo root THIRD_PARTY_NOTICES.md by packages/core-engine/scripts/generate-notices.mjs. Edit the root file, then regenerate. -->
|
|
2
|
+
|
|
3
|
+
# Third-party notices
|
|
4
|
+
|
|
5
|
+
Kbach is MIT-licensed (see `LICENSE`). It also contains material from the
|
|
6
|
+
project below, used under that project's license.
|
|
7
|
+
|
|
8
|
+
## Tailwind CSS
|
|
9
|
+
|
|
10
|
+
Kbach uses Tailwind CSS-compatible utility class names, and some of its
|
|
11
|
+
default theme values (for example the spacing formula and the shadow, radius,
|
|
12
|
+
blur, and line-height scales) are derived from Tailwind CSS.
|
|
13
|
+
|
|
14
|
+
Tailwind CSS is a trademark of Tailwind Labs Inc. Kbach is an independent
|
|
15
|
+
project and is not affiliated with, sponsored by, or endorsed by Tailwind Labs.
|
|
16
|
+
|
|
17
|
+
Source: https://github.com/tailwindlabs/tailwindcss
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
MIT License
|
|
21
|
+
|
|
22
|
+
Copyright (c) Tailwind Labs, Inc.
|
|
23
|
+
|
|
24
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
25
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
26
|
+
in the Software without restriction, including without limitation the rights
|
|
27
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
28
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
29
|
+
furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all
|
|
32
|
+
copies or substantial portions of the Software.
|
|
33
|
+
|
|
34
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
35
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
36
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
37
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
38
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
39
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
40
|
+
SOFTWARE.
|
|
41
|
+
```
|
|
Binary file
|
|
Binary file
|