@kbach/react 0.1.1 → 0.1.2
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 +47 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @kbach/react
|
|
2
2
|
|
|
3
|
-
Tailwind-like utility classes for **React (web)**.
|
|
3
|
+
Tailwind-like utility classes for **React (web)**. Classes are converted to inline styles at render time through a custom JSX runtime — no stylesheet required.
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
6
|
/** @jsxImportSource @kbach/react */
|
|
@@ -20,7 +20,7 @@ npm install @kbach/react
|
|
|
20
20
|
|
|
21
21
|
### 1. Configure the JSX runtime
|
|
22
22
|
|
|
23
|
-
**tsconfig.json**
|
|
23
|
+
**tsconfig.json**
|
|
24
24
|
|
|
25
25
|
```jsonc
|
|
26
26
|
{
|
|
@@ -76,7 +76,7 @@ export default function Root() {
|
|
|
76
76
|
|
|
77
77
|
## API
|
|
78
78
|
|
|
79
|
-
###
|
|
79
|
+
### className prop
|
|
80
80
|
|
|
81
81
|
Works on any HTML element or React component once the JSX runtime is configured.
|
|
82
82
|
|
|
@@ -86,7 +86,7 @@ Works on any HTML element or React component once the JSX runtime is configured.
|
|
|
86
86
|
<button className="bg-blue-7 hover:bg-blue-8 pressed:bg-blue-8 rounded-lg px-4 py-2" />
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
-
###
|
|
89
|
+
### styled(Component, classes)
|
|
90
90
|
|
|
91
91
|
Pre-style any component. Returns a new component that merges the base classes with any `className` or `tw` prop passed at use time.
|
|
92
92
|
|
|
@@ -106,7 +106,7 @@ const Button = styled(
|
|
|
106
106
|
</Card>
|
|
107
107
|
```
|
|
108
108
|
|
|
109
|
-
###
|
|
109
|
+
### useStyles(classes)
|
|
110
110
|
|
|
111
111
|
Resolve classes to a style object inside a component.
|
|
112
112
|
|
|
@@ -119,7 +119,7 @@ function Badge() {
|
|
|
119
119
|
}
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
-
###
|
|
122
|
+
### tw(classes)
|
|
123
123
|
|
|
124
124
|
Resolve classes outside a component (static contexts).
|
|
125
125
|
|
|
@@ -129,7 +129,7 @@ import { tw } from '@kbach/react';
|
|
|
129
129
|
const cardStyle = tw('bg-white p-4 rounded-xl') as React.CSSProperties;
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
###
|
|
132
|
+
### cx(...classes)
|
|
133
133
|
|
|
134
134
|
Conditionally join class strings. Falsy values are ignored.
|
|
135
135
|
|
|
@@ -143,7 +143,7 @@ import { cx } from '@kbach/react';
|
|
|
143
143
|
)} />
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
###
|
|
146
|
+
### useTheme()
|
|
147
147
|
|
|
148
148
|
```tsx
|
|
149
149
|
import { useTheme } from '@kbach/react';
|
|
@@ -153,36 +153,36 @@ const { mode, resolvedMode, isDark, setMode, toggle } = useTheme();
|
|
|
153
153
|
|
|
154
154
|
| Value | Type | Description |
|
|
155
155
|
|---|---|---|
|
|
156
|
-
|
|
|
157
|
-
|
|
|
158
|
-
|
|
|
159
|
-
|
|
|
160
|
-
|
|
|
156
|
+
| mode | `'light' \| 'dark' \| 'system'` | User-selected mode |
|
|
157
|
+
| resolvedMode | `'light' \| 'dark'` | Resolved after system lookup |
|
|
158
|
+
| isDark | boolean | Shorthand for `resolvedMode === 'dark'` |
|
|
159
|
+
| setMode | function | Set mode explicitly |
|
|
160
|
+
| toggle | function | Toggle between light and dark |
|
|
161
161
|
|
|
162
|
-
###
|
|
162
|
+
### ThemeToggle
|
|
163
163
|
|
|
164
164
|
Drop-in toggle component.
|
|
165
165
|
|
|
166
166
|
```tsx
|
|
167
|
-
<ThemeToggle />
|
|
168
|
-
<ThemeToggle variant="switch" />
|
|
169
|
-
<ThemeToggle variant="icon-button" />
|
|
167
|
+
<ThemeToggle /> // button (default)
|
|
168
|
+
<ThemeToggle variant="switch" /> // toggle switch
|
|
169
|
+
<ThemeToggle variant="icon-button" /> // icon button
|
|
170
170
|
<ThemeToggle variant="button" includeSystem /> // three-way selector
|
|
171
171
|
```
|
|
172
172
|
|
|
173
173
|
## Modifiers
|
|
174
174
|
|
|
175
|
-
Up to
|
|
175
|
+
Up to 3 modifiers can be chained in any order.
|
|
176
176
|
|
|
177
177
|
| Modifier | Trigger |
|
|
178
178
|
|---|---|
|
|
179
|
-
|
|
|
180
|
-
|
|
|
181
|
-
|
|
|
182
|
-
|
|
|
183
|
-
|
|
|
184
|
-
|
|
|
185
|
-
|
|
|
179
|
+
| dark: | Dark mode active |
|
|
180
|
+
| light: | Light mode active |
|
|
181
|
+
| hover: | Mouse hover |
|
|
182
|
+
| pressed: | Click or touch |
|
|
183
|
+
| focus: | Element focused |
|
|
184
|
+
| active: | Element active |
|
|
185
|
+
| disabled: | Element disabled |
|
|
186
186
|
|
|
187
187
|
```tsx
|
|
188
188
|
<div className="dark:hover:bg-gray-9" />
|
|
@@ -201,19 +201,34 @@ Up to **3 modifiers** can be chained in any order.
|
|
|
201
201
|
## Color with opacity
|
|
202
202
|
|
|
203
203
|
```tsx
|
|
204
|
-
<div className="bg-blue-6/50" />
|
|
205
|
-
<div className="bg-gray-10/75" />
|
|
204
|
+
<div className="bg-blue-6/50" /> // 50% opacity
|
|
205
|
+
<div className="bg-gray-10/75" /> // 75% opacity
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
## Color scale
|
|
209
209
|
|
|
210
|
-
Colors use an 11-shade scale
|
|
210
|
+
Colors use an 11-shade scale — 1 is lightest, 11 is darkest.
|
|
211
211
|
|
|
212
212
|
```
|
|
213
|
-
|
|
213
|
+
shade 1 · 2 · 3 · 4 · 5 · 6 · 7 · 8 · 9 · 10 · 11
|
|
214
|
+
light ─────────────────────────────────────────────────────────── dark
|
|
214
215
|
```
|
|
215
216
|
|
|
216
|
-
Available families:
|
|
217
|
+
Available families: slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.
|
|
218
|
+
|
|
219
|
+
## Common utilities
|
|
220
|
+
|
|
221
|
+
| Category | Examples |
|
|
222
|
+
|---|---|
|
|
223
|
+
| Background | `bg-white`, `bg-gray-10`, `bg-blue-6`, `bg-[#fff]` |
|
|
224
|
+
| Text | `text-sm`, `text-2xl`, `text-gray-10`, `font-bold` |
|
|
225
|
+
| Padding | `p-4`, `px-6`, `py-3` |
|
|
226
|
+
| Margin | `m-4`, `mx-auto`, `mt-2`, `-mt-4` |
|
|
227
|
+
| Size | `w-full`, `h-12`, `w-[200px]` |
|
|
228
|
+
| Flex | `flex-1`, `flex-row`, `items-center`, `justify-between`, `gap-4` |
|
|
229
|
+
| Border | `border`, `border-2`, `border-gray-4`, `rounded-xl` |
|
|
230
|
+
| Shadow | `shadow`, `shadow-md`, `shadow-lg` |
|
|
231
|
+
| Opacity | `opacity-50`, `opacity-75` |
|
|
217
232
|
|
|
218
233
|
## Configuration
|
|
219
234
|
|
|
@@ -246,6 +261,8 @@ module.exports = {
|
|
|
246
261
|
};
|
|
247
262
|
```
|
|
248
263
|
|
|
264
|
+
Apply at runtime:
|
|
265
|
+
|
|
249
266
|
```tsx
|
|
250
267
|
import { updateConfig } from '@kbach/react';
|
|
251
268
|
|