@kbach/react 0.6.0 → 0.6.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 +49 -0
- package/dist/{chunk-6NED62DB.mjs → chunk-GRZ6MVIL.mjs} +659 -179
- package/dist/{chunk-AAAI37Y4.mjs → chunk-NWW57Q5Q.mjs} +12 -71
- package/dist/index.d.mts +142 -3
- package/dist/index.d.ts +142 -3
- package/dist/index.js +345 -395
- package/dist/index.mjs +69 -98
- package/dist/jsx-dev-runtime.js +205 -289
- package/dist/jsx-dev-runtime.mjs +4 -4
- package/dist/jsx-runtime.js +204 -288
- package/dist/jsx-runtime.mjs +3 -3
- package/dist/vite-plugin.d.mts +102 -1
- package/dist/vite-plugin.d.ts +102 -1
- package/dist/vite-plugin.js +139 -163
- package/dist/vite-plugin.mjs +2883 -12
- package/jsx-dev-runtime.js +1 -0
- package/jsx-runtime.js +1 -0
- package/kbach-react.md +7 -0
- package/package.json +3 -3
- package/dist/chunk-D4LJICWZ.mjs +0 -524
- package/dist/types-BESBQANS.d.mts +0 -131
- package/dist/types-BESBQANS.d.ts +0 -131
package/README.md
CHANGED
|
@@ -52,6 +52,12 @@ module.exports = {
|
|
|
52
52
|
|
|
53
53
|
### 2. Add the Vite plugin
|
|
54
54
|
|
|
55
|
+
`@kbach/react` doesn't bundle a React plugin for Vite — if your project doesn't already have one, install it first:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
npm install -D vite @vitejs/plugin-react
|
|
59
|
+
```
|
|
60
|
+
|
|
55
61
|
```ts
|
|
56
62
|
// vite.config.ts
|
|
57
63
|
import { defineConfig } from 'vite';
|
|
@@ -100,6 +106,49 @@ export default function Root() {
|
|
|
100
106
|
}
|
|
101
107
|
```
|
|
102
108
|
|
|
109
|
+
## Next.js
|
|
110
|
+
|
|
111
|
+
Steps 1 and 4 above apply as-is — the JSX runtime setup works via `jsxImportSource` in `tsconfig.json` (Next.js's SWC compiler reads it the same way Vite does), and `ThemeProvider` wraps your app the same way.
|
|
112
|
+
|
|
113
|
+
Two things differ from the Vite setup:
|
|
114
|
+
|
|
115
|
+
**No Vite plugin, no static `kbach.css`.** Next.js builds with webpack/Turbopack, not Vite, so step 2/3 (the `@kbach/react/vite` plugin) don't apply — there's currently no static-CSS build step for Next.js. Styles fall back to runtime injection (the same mechanism used automatically when no `kbach.css` is imported). This works, but since the injection only runs in the browser (there's no `document` during the server render), server-rendered HTML has classes with no matching CSS yet — expect a brief flash of unstyled content on first paint before hydration completes and injects the rules. This is a known limitation, not a bug to work around per-project.
|
|
116
|
+
|
|
117
|
+
**`ThemeProvider` needs a `'use client'` boundary.** `@kbach/react` doesn't ship the `'use client'` directive in its build output, so importing `ThemeProvider` directly into a Server Component (e.g. the App Router root `layout.tsx`, which is a Server Component by default) will fail. Wrap it in your own client component once:
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
// app/providers.tsx
|
|
121
|
+
'use client';
|
|
122
|
+
import { ThemeProvider } from '@kbach/react';
|
|
123
|
+
|
|
124
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
125
|
+
return <ThemeProvider defaultMode="system">{children}</ThemeProvider>;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
// app/layout.tsx (Server Component — no 'use client' needed here)
|
|
131
|
+
import { Providers } from './providers';
|
|
132
|
+
|
|
133
|
+
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
|
134
|
+
return (
|
|
135
|
+
<html lang="en">
|
|
136
|
+
<body>
|
|
137
|
+
<Providers>{children}</Providers>
|
|
138
|
+
</body>
|
|
139
|
+
</html>
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This is the standard pattern for any hook-using npm package that predates the App Router — the same workaround is needed for many other UI libraries.
|
|
145
|
+
|
|
146
|
+
## React Router
|
|
147
|
+
|
|
148
|
+
**Framework mode (v7, SSR by default):** works with the same Vite-based setup as above — framework mode builds with Vite under the hood, so the `@kbach/react/vite` plugin runs normally. `include` defaults to `['src', 'app', 'pages', 'components', 'views', 'layouts']`, which already covers React Router's `app/` routes convention. Because the static `kbach.css` approach ships real CSS (not runtime JS injection), there's no FOUC concern for server-rendered routes the way there is with Next.js.
|
|
149
|
+
|
|
150
|
+
**Library mode (client-only, `createBrowserRouter`/`<BrowserRouter>`):** no SSR involved — set it up exactly like any other Vite + React app per the steps above.
|
|
151
|
+
|
|
103
152
|
## API
|
|
104
153
|
|
|
105
154
|
### className / kb prop
|