@kbach/native 0.1.1 → 0.1.3
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 +61 -58
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Tailwind-like utility classes for **React Native and Expo**. One package includes everything: the core engine, JSX runtime, Babel plugin for compile-time optimization, and Metro config helper.
|
|
4
4
|
|
|
5
|
-
```
|
|
5
|
+
```
|
|
6
6
|
import { View, Text, TouchableOpacity } from 'react-native';
|
|
7
7
|
import { styled } from '@kbach/native';
|
|
8
8
|
|
|
@@ -65,7 +65,7 @@ module.exports = withKbach(config);
|
|
|
65
65
|
|
|
66
66
|
### 3. Wrap your app
|
|
67
67
|
|
|
68
|
-
```
|
|
68
|
+
```
|
|
69
69
|
import { ThemeProvider } from '@kbach/native';
|
|
70
70
|
|
|
71
71
|
export default function App() {
|
|
@@ -85,21 +85,21 @@ npx expo start --clear
|
|
|
85
85
|
|
|
86
86
|
## API
|
|
87
87
|
|
|
88
|
-
###
|
|
88
|
+
### className prop
|
|
89
89
|
|
|
90
|
-
Works on any React Native component —
|
|
90
|
+
Works on any React Native component — View, Text, TouchableOpacity, TextInput, and third-party components.
|
|
91
91
|
|
|
92
|
-
```
|
|
92
|
+
```
|
|
93
93
|
<View className="flex-1 bg-gray-2 dark:bg-gray-11 p-4" />
|
|
94
94
|
<Text className="text-lg font-bold text-gray-10 dark:text-white" />
|
|
95
95
|
<TouchableOpacity className="bg-blue-7 pressed:bg-blue-8 rounded-xl px-6 py-3" />
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
###
|
|
98
|
+
### styled(Component, classes)
|
|
99
99
|
|
|
100
|
-
Pre-style any component. Handles interaction states (
|
|
100
|
+
Pre-style any component. Handles interaction states (pressed, focus, etc.) automatically.
|
|
101
101
|
|
|
102
|
-
```
|
|
102
|
+
```
|
|
103
103
|
import { styled } from '@kbach/native';
|
|
104
104
|
import { View, Text, TouchableOpacity, TextInput } from 'react-native';
|
|
105
105
|
|
|
@@ -117,17 +117,17 @@ const Input = styled(
|
|
|
117
117
|
|
|
118
118
|
Pass extra classes at use time with the `tw` prop:
|
|
119
119
|
|
|
120
|
-
```
|
|
120
|
+
```
|
|
121
121
|
<Card tw="mt-4 mb-2">
|
|
122
122
|
<Title tw="text-3xl">Hello</Title>
|
|
123
123
|
</Card>
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
###
|
|
126
|
+
### useStyles(classes)
|
|
127
127
|
|
|
128
128
|
Resolve classes to a style object inside a component. Use this when you need a value for the `style` prop.
|
|
129
129
|
|
|
130
|
-
```
|
|
130
|
+
```
|
|
131
131
|
import { useStyles } from '@kbach/native';
|
|
132
132
|
import { View, Text } from 'react-native';
|
|
133
133
|
|
|
@@ -143,11 +143,11 @@ function Badge() {
|
|
|
143
143
|
}
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
###
|
|
146
|
+
### tw(classes)
|
|
147
147
|
|
|
148
|
-
Resolve classes outside a component, for use in
|
|
148
|
+
Resolve classes outside a component, for use in StyleSheet.create() or static contexts.
|
|
149
149
|
|
|
150
|
-
```
|
|
150
|
+
```
|
|
151
151
|
import { StyleSheet } from 'react-native';
|
|
152
152
|
import { tw } from '@kbach/native';
|
|
153
153
|
|
|
@@ -157,11 +157,11 @@ const styles = StyleSheet.create({
|
|
|
157
157
|
});
|
|
158
158
|
```
|
|
159
159
|
|
|
160
|
-
###
|
|
160
|
+
### cx(...classes)
|
|
161
161
|
|
|
162
162
|
Conditionally join class strings. Falsy values are ignored.
|
|
163
163
|
|
|
164
|
-
```
|
|
164
|
+
```
|
|
165
165
|
import { cx } from '@kbach/native';
|
|
166
166
|
|
|
167
167
|
<View className={cx(
|
|
@@ -171,9 +171,9 @@ import { cx } from '@kbach/native';
|
|
|
171
171
|
)} />
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
###
|
|
174
|
+
### useTheme()
|
|
175
175
|
|
|
176
|
-
```
|
|
176
|
+
```
|
|
177
177
|
import { useTheme } from '@kbach/native';
|
|
178
178
|
|
|
179
179
|
const { mode, resolvedMode, isDark, setMode, toggle } = useTheme();
|
|
@@ -181,44 +181,44 @@ const { mode, resolvedMode, isDark, setMode, toggle } = useTheme();
|
|
|
181
181
|
|
|
182
182
|
| Value | Type | Description |
|
|
183
183
|
|---|---|---|
|
|
184
|
-
|
|
|
185
|
-
|
|
|
186
|
-
|
|
|
187
|
-
|
|
|
188
|
-
|
|
|
184
|
+
| mode | `'light' \| 'dark' \| 'system'` | User-selected mode |
|
|
185
|
+
| resolvedMode | `'light' \| 'dark'` | Resolved after system lookup |
|
|
186
|
+
| isDark | boolean | Shorthand for `resolvedMode === 'dark'` |
|
|
187
|
+
| setMode | function | Set mode explicitly |
|
|
188
|
+
| toggle | function | Toggle between light and dark |
|
|
189
189
|
|
|
190
|
-
###
|
|
190
|
+
### ThemeToggle
|
|
191
191
|
|
|
192
192
|
Drop-in toggle component that works on both web and native.
|
|
193
193
|
|
|
194
|
-
```
|
|
195
|
-
<ThemeToggle />
|
|
196
|
-
<ThemeToggle variant="switch" />
|
|
197
|
-
<ThemeToggle variant="icon-button" />
|
|
198
|
-
<ThemeToggle variant="button" includeSystem />
|
|
194
|
+
```
|
|
195
|
+
<ThemeToggle /> // button (default)
|
|
196
|
+
<ThemeToggle variant="switch" /> // toggle switch
|
|
197
|
+
<ThemeToggle variant="icon-button" /> // icon button
|
|
198
|
+
<ThemeToggle variant="button" includeSystem /> // three-way selector
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
## Modifiers
|
|
202
202
|
|
|
203
|
-
Up to
|
|
203
|
+
Up to 3 modifiers can be chained in any order.
|
|
204
204
|
|
|
205
205
|
| Modifier | Trigger |
|
|
206
206
|
|---|---|
|
|
207
|
-
|
|
|
208
|
-
|
|
|
209
|
-
|
|
|
210
|
-
|
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
214
|
-
```
|
|
207
|
+
| dark: | Dark mode active |
|
|
208
|
+
| light: | Light mode active |
|
|
209
|
+
| pressed: | Touch pressed |
|
|
210
|
+
| focus: | Element focused |
|
|
211
|
+
| active: | Element active |
|
|
212
|
+
| disabled: | Element disabled |
|
|
213
|
+
|
|
214
|
+
```
|
|
215
215
|
<View className="dark:bg-gray-10" />
|
|
216
216
|
<TouchableOpacity className="dark:pressed:bg-indigo-8" />
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
## Arbitrary values
|
|
220
220
|
|
|
221
|
-
```
|
|
221
|
+
```
|
|
222
222
|
<View className="bg-[#6366f1]" />
|
|
223
223
|
<View className="p-[14px]" />
|
|
224
224
|
<Text className="text-[18px]" />
|
|
@@ -228,41 +228,42 @@ Up to **3 modifiers** can be chained in any order.
|
|
|
228
228
|
|
|
229
229
|
## Negative values
|
|
230
230
|
|
|
231
|
-
```
|
|
232
|
-
<View className="-mt-4" />
|
|
233
|
-
<View className="-mx-2" />
|
|
231
|
+
```
|
|
232
|
+
<View className="-mt-4" /> // marginTop: -16
|
|
233
|
+
<View className="-mx-2" /> // marginHorizontal: -8
|
|
234
234
|
```
|
|
235
235
|
|
|
236
236
|
## Color with opacity
|
|
237
237
|
|
|
238
|
-
```
|
|
239
|
-
<View className="bg-blue-6/50" />
|
|
240
|
-
<View className="bg-gray-10/75" />
|
|
238
|
+
```
|
|
239
|
+
<View className="bg-blue-6/50" /> // 50% opacity
|
|
240
|
+
<View className="bg-gray-10/75" /> // 75% opacity
|
|
241
241
|
```
|
|
242
242
|
|
|
243
243
|
## Color scale
|
|
244
244
|
|
|
245
|
-
Colors use an 11-shade scale
|
|
245
|
+
Colors use an 11-shade scale — 1 is lightest, 11 is darkest.
|
|
246
246
|
|
|
247
247
|
```
|
|
248
|
-
|
|
248
|
+
shade 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10 · 11
|
|
249
|
+
light ─────────────────────────────────────────────────────────── dark
|
|
249
250
|
```
|
|
250
251
|
|
|
251
|
-
Available families:
|
|
252
|
+
Available families: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.
|
|
252
253
|
|
|
253
254
|
## Common utilities
|
|
254
255
|
|
|
255
256
|
| Category | Examples |
|
|
256
257
|
|---|---|
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
|
|
|
262
|
-
|
|
|
263
|
-
|
|
|
264
|
-
|
|
|
265
|
-
|
|
|
258
|
+
| Background | `bg-white`, `bg-gray-10`, `bg-blue-6`, `bg-[#fff]` |
|
|
259
|
+
| Text | `text-sm`, `text-2xl`, `text-gray-10`, `font-bold` |
|
|
260
|
+
| Padding | `p-4`, `px-6`, `py-3` |
|
|
261
|
+
| Margin | `m-4`, `mx-auto`, `mt-2`, `-mt-4` |
|
|
262
|
+
| Size | `w-full`, `h-12`, `w-[200px]` |
|
|
263
|
+
| Flex | `flex-1`, `flex-row`, `items-center`, `justify-between`, `gap-4` |
|
|
264
|
+
| Border | `border`, `border-2`, `border-gray-4`, `rounded-xl` |
|
|
265
|
+
| Shadow | `shadow`, `shadow-md`, `shadow-lg` |
|
|
266
|
+
| Opacity | `opacity-50`, `opacity-75` |
|
|
266
267
|
|
|
267
268
|
## Configuration
|
|
268
269
|
|
|
@@ -295,7 +296,9 @@ module.exports = {
|
|
|
295
296
|
};
|
|
296
297
|
```
|
|
297
298
|
|
|
298
|
-
|
|
299
|
+
Apply at runtime:
|
|
300
|
+
|
|
301
|
+
```
|
|
299
302
|
import { updateConfig } from '@kbach/native';
|
|
300
303
|
|
|
301
304
|
updateConfig({ extend: { theme: { colors: { brand: { 6: '#6366f1' } } } } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kbach/native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Single-package Kbach install for React Native and Expo — includes core, components, Babel plugin, and Metro config",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@kbach/core": "0.1.0",
|
|
37
|
-
"@kbach/react": "0.1.
|
|
37
|
+
"@kbach/react": "0.1.3",
|
|
38
38
|
"babel-plugin-kbach": "0.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|