@kbach/react 0.1.5 → 0.1.9
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 +29 -29
- package/dist/{chunk-FUSJKUE7.mjs → chunk-CNS23UB5.mjs} +9 -7
- package/dist/chunk-PYBA3DFG.mjs +2046 -0
- package/dist/index.d.mts +128 -9
- package/dist/index.d.ts +128 -9
- package/dist/index.js +1985 -40
- package/dist/index.mjs +26 -35
- package/dist/jsx-dev-runtime.js +1943 -18
- package/dist/jsx-dev-runtime.mjs +2 -2
- package/dist/jsx-runtime.js +1943 -18
- package/dist/jsx-runtime.mjs +2 -2
- package/package.json +1 -4
- package/dist/chunk-IZK5HMWK.mjs +0 -85
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
|
+
```jsx
|
|
6
6
|
/** @jsxImportSource @kbach/react */
|
|
7
7
|
|
|
8
8
|
<div className="bg-white dark:bg-gray-10 p-4 rounded-xl shadow" />
|
|
@@ -22,7 +22,7 @@ npm install @kbach/react
|
|
|
22
22
|
|
|
23
23
|
**tsconfig.json**
|
|
24
24
|
|
|
25
|
-
```
|
|
25
|
+
```json
|
|
26
26
|
{
|
|
27
27
|
"compilerOptions": {
|
|
28
28
|
"jsx": "react-jsx",
|
|
@@ -33,7 +33,7 @@ npm install @kbach/react
|
|
|
33
33
|
|
|
34
34
|
**Vite**
|
|
35
35
|
|
|
36
|
-
```
|
|
36
|
+
```js
|
|
37
37
|
// vite.config.ts
|
|
38
38
|
import { defineConfig } from 'vite';
|
|
39
39
|
import react from '@vitejs/plugin-react';
|
|
@@ -45,7 +45,7 @@ export default defineConfig({
|
|
|
45
45
|
|
|
46
46
|
**Babel**
|
|
47
47
|
|
|
48
|
-
```
|
|
48
|
+
```js
|
|
49
49
|
// babel.config.js
|
|
50
50
|
module.exports = {
|
|
51
51
|
presets: [
|
|
@@ -56,13 +56,13 @@ module.exports = {
|
|
|
56
56
|
|
|
57
57
|
**Per-file pragma** (no config change required)
|
|
58
58
|
|
|
59
|
-
```
|
|
59
|
+
```js
|
|
60
60
|
/** @jsxImportSource @kbach/react */
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
### 2. Wrap your app
|
|
64
64
|
|
|
65
|
-
```
|
|
65
|
+
```jsx
|
|
66
66
|
import { ThemeProvider } from '@kbach/react';
|
|
67
67
|
|
|
68
68
|
export default function Root() {
|
|
@@ -80,7 +80,7 @@ export default function Root() {
|
|
|
80
80
|
|
|
81
81
|
Works on any HTML element or React component once the JSX runtime is configured.
|
|
82
82
|
|
|
83
|
-
```
|
|
83
|
+
```jsx
|
|
84
84
|
<div className="bg-white dark:bg-gray-10 p-4 rounded-xl" />
|
|
85
85
|
<p className="text-gray-10 dark:text-white text-lg font-bold" />
|
|
86
86
|
<button className="bg-blue-7 hover:bg-blue-8 pressed:bg-blue-8 rounded-lg px-4 py-2" />
|
|
@@ -88,9 +88,9 @@ Works on any HTML element or React component once the JSX runtime is configured.
|
|
|
88
88
|
|
|
89
89
|
### styled(Component, classes)
|
|
90
90
|
|
|
91
|
-
Pre-style any component. Returns a new component that merges the base classes with any `className` or `
|
|
91
|
+
Pre-style any component. Returns a new component that merges the base classes with any `className` or `kb` prop passed at use time.
|
|
92
92
|
|
|
93
|
-
```
|
|
93
|
+
```jsx
|
|
94
94
|
import { styled } from '@kbach/react';
|
|
95
95
|
|
|
96
96
|
const Card = styled('div', 'bg-white dark:bg-gray-9 rounded-2xl p-6 shadow');
|
|
@@ -101,8 +101,8 @@ const Button = styled(
|
|
|
101
101
|
);
|
|
102
102
|
|
|
103
103
|
// Pass extra classes at use time
|
|
104
|
-
<Card
|
|
105
|
-
<Title
|
|
104
|
+
<Card kb="mt-4 mb-2">
|
|
105
|
+
<Title kb="text-3xl">Hello</Title>
|
|
106
106
|
</Card>
|
|
107
107
|
```
|
|
108
108
|
|
|
@@ -110,7 +110,7 @@ const Button = styled(
|
|
|
110
110
|
|
|
111
111
|
Resolve classes to a style object inside a component.
|
|
112
112
|
|
|
113
|
-
```
|
|
113
|
+
```jsx
|
|
114
114
|
import { useStyles } from '@kbach/react';
|
|
115
115
|
|
|
116
116
|
function Badge() {
|
|
@@ -123,7 +123,7 @@ function Badge() {
|
|
|
123
123
|
|
|
124
124
|
Resolve classes outside a component (static contexts).
|
|
125
125
|
|
|
126
|
-
```
|
|
126
|
+
```js
|
|
127
127
|
import { tw } from '@kbach/react';
|
|
128
128
|
|
|
129
129
|
const cardStyle = tw('bg-white p-4 rounded-xl') as React.CSSProperties;
|
|
@@ -133,7 +133,7 @@ const cardStyle = tw('bg-white p-4 rounded-xl') as React.CSSProperties;
|
|
|
133
133
|
|
|
134
134
|
Conditionally join class strings. Falsy values are ignored.
|
|
135
135
|
|
|
136
|
-
```
|
|
136
|
+
```jsx
|
|
137
137
|
import { cx } from '@kbach/react';
|
|
138
138
|
|
|
139
139
|
<div className={cx(
|
|
@@ -145,7 +145,7 @@ import { cx } from '@kbach/react';
|
|
|
145
145
|
|
|
146
146
|
### useTheme()
|
|
147
147
|
|
|
148
|
-
```
|
|
148
|
+
```js
|
|
149
149
|
import { useTheme } from '@kbach/react';
|
|
150
150
|
|
|
151
151
|
const { mode, resolvedMode, isDark, setMode, toggle } = useTheme();
|
|
@@ -163,7 +163,7 @@ const { mode, resolvedMode, isDark, setMode, toggle } = useTheme();
|
|
|
163
163
|
|
|
164
164
|
Drop-in toggle component.
|
|
165
165
|
|
|
166
|
-
```
|
|
166
|
+
```jsx
|
|
167
167
|
<ThemeToggle /> // button (default)
|
|
168
168
|
<ThemeToggle variant="switch" /> // toggle switch
|
|
169
169
|
<ThemeToggle variant="icon-button" /> // icon button
|
|
@@ -176,22 +176,22 @@ Up to 3 modifiers can be chained in any order.
|
|
|
176
176
|
|
|
177
177
|
| Modifier | Trigger |
|
|
178
178
|
|---|---|
|
|
179
|
-
| dark
|
|
180
|
-
| light
|
|
181
|
-
| hover
|
|
182
|
-
| pressed
|
|
183
|
-
| focus
|
|
184
|
-
| active
|
|
185
|
-
| disabled
|
|
186
|
-
|
|
187
|
-
```
|
|
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
|
+
|
|
187
|
+
```jsx
|
|
188
188
|
<div className="dark:hover:bg-gray-9" />
|
|
189
189
|
<button className="dark:pressed:bg-indigo-8" />
|
|
190
190
|
```
|
|
191
191
|
|
|
192
192
|
## Arbitrary values
|
|
193
193
|
|
|
194
|
-
```
|
|
194
|
+
```jsx
|
|
195
195
|
<div className="bg-[#6366f1]" />
|
|
196
196
|
<div className="p-[14px]" />
|
|
197
197
|
<div className="text-[18px]" />
|
|
@@ -200,7 +200,7 @@ Up to 3 modifiers can be chained in any order.
|
|
|
200
200
|
|
|
201
201
|
## Color with opacity
|
|
202
202
|
|
|
203
|
-
```
|
|
203
|
+
```jsx
|
|
204
204
|
<div className="bg-blue-6/50" /> // 50% opacity
|
|
205
205
|
<div className="bg-gray-10/75" /> // 75% opacity
|
|
206
206
|
```
|
|
@@ -232,7 +232,7 @@ Available families: slate, gray, zinc, neutral, stone, red, orange, amber, yello
|
|
|
232
232
|
|
|
233
233
|
## Configuration
|
|
234
234
|
|
|
235
|
-
```
|
|
235
|
+
```js
|
|
236
236
|
// kbach.config.js
|
|
237
237
|
module.exports = {
|
|
238
238
|
darkMode: 'attribute', // 'attribute' | 'class' | 'media'
|
|
@@ -263,7 +263,7 @@ module.exports = {
|
|
|
263
263
|
|
|
264
264
|
Apply at runtime:
|
|
265
265
|
|
|
266
|
-
```
|
|
266
|
+
```js
|
|
267
267
|
import { updateConfig } from '@kbach/react';
|
|
268
268
|
|
|
269
269
|
updateConfig({ extend: { theme: { colors: { brand: { 6: '#6366f1' } } } } });
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InteractiveWrapper,
|
|
3
|
+
flatten,
|
|
4
|
+
getConfig,
|
|
5
|
+
isWeb,
|
|
6
|
+
resolve,
|
|
3
7
|
useGlobalDarkMode
|
|
4
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-PYBA3DFG.mjs";
|
|
5
9
|
|
|
6
10
|
// src/jsx-runtime.tsx
|
|
7
11
|
import { jsx as _jsx, jsxs as _jsxs, Fragment } from "react/jsx-runtime";
|
|
8
|
-
import { isWeb, getConfig, resolve, flatten as flatten2 } from "@kbach/core";
|
|
9
12
|
|
|
10
13
|
// src/DarkWrapper.tsx
|
|
11
14
|
import React from "react";
|
|
12
|
-
import { flatten } from "@kbach/core";
|
|
13
15
|
var DarkWrapper = React.forwardRef(
|
|
14
16
|
function DarkWrapper2({ Component, resolvedStyle, style: styleProp, children, ...rest }, ref) {
|
|
15
17
|
const isDark = useGlobalDarkMode();
|
|
@@ -31,7 +33,7 @@ function hasInteractiveBuckets(resolved) {
|
|
|
31
33
|
return true;
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
var CONSUMED_PROPS = /* @__PURE__ */ new Set(["className", "
|
|
36
|
+
var CONSUMED_PROPS = /* @__PURE__ */ new Set(["className", "kb", "__kbachStyles", "__kbachClasses"]);
|
|
35
37
|
function omitConsumed(props) {
|
|
36
38
|
const out = {};
|
|
37
39
|
for (const key of Object.keys(props)) {
|
|
@@ -49,8 +51,8 @@ function makeElement(isStaticChildren, type, props, key) {
|
|
|
49
51
|
}
|
|
50
52
|
function processElement(type, rawProps, key, isStaticChildren) {
|
|
51
53
|
if (!rawProps) return _jsx(type, null, key);
|
|
52
|
-
const { className,
|
|
53
|
-
const classStr = className ??
|
|
54
|
+
const { className, kb: kbProp, __kbachStyles, __kbachClasses } = rawProps;
|
|
55
|
+
const classStr = className ?? kbProp ?? __kbachClasses;
|
|
54
56
|
if (!classStr && !__kbachStyles) {
|
|
55
57
|
return makeElement(isStaticChildren, type, rawProps, key);
|
|
56
58
|
}
|
|
@@ -78,7 +80,7 @@ function processElement(type, rawProps, key, isStaticChildren) {
|
|
|
78
80
|
...passProps
|
|
79
81
|
}, key);
|
|
80
82
|
}
|
|
81
|
-
const computedStyle =
|
|
83
|
+
const computedStyle = flatten(resolved, false);
|
|
82
84
|
const finalStyle = mergeStyle(computedStyle, userStyle);
|
|
83
85
|
return makeElement(isStaticChildren, type, {
|
|
84
86
|
...passProps,
|