Skip to content

Commit f1fbd85

Browse files
authored
fix: demo page react and zero-ui to be the same (#7)
* fix: demo page react and zero-ui to be exactly the same. * fix: ran format * fix: ran correct format config.
1 parent 1e36281 commit f1fbd85

30 files changed

+1124
-1093
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/examples
21
pnpm-lock.yaml
32
packages/core/__tests__/fixtures/vite/vite.config.ts
43
packages/core/__tests__/fixtures/next/tsconfig.json

AGENTS.md

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,74 @@
1+
<!-- purpose: AI and codegen agents should use this to generate correct Zero-UI examples -->
2+
13
# Guidelines for AI Agents in this Repo
24

35
This repository contains **React Zero-UI**, a library for global UI state without React re-renders.
46
Use these tips when working with the codebase or generating examples.
57

68
## How React Zero-UI works
79

8-
1. `useUI()` writes to `document.body.dataset` using keys you specify (e.g. `theme``data-theme`).
9-
2. Build tooling scans for all keys and values, generating CSS variants for each.
10-
3. When a setter is called, the corresponding body attribute changes instantly with no React re-render.
10+
1. `useUI()` writes to `document.body.dataset` using keys you specify.
11+
12+
```tsx
13+
const [staleValue, setValue] = useUI<'open' | 'closed'>('sidebar', 'closed');
14+
```
15+
16+
- `key` → becomes `data-{key}` on `<body>` (e.g., `sidebar``data-sidebar="closed"`).
17+
- `defaultValue` → used for SSR to avoid FOUC.
18+
- The first value is **always stale** — do NOT rely on it for reactive updates.
19+
20+
2. Consumption is done strictly with tailwind variant classNames:
21+
22+
```html
23+
<div className="sidebar-open:translate-x-0 sidebar-closed:-translate-x-full" />
24+
```
25+
26+
3. Build-time tooling scans all `useUI()` keys and values, then generates matching Tailwind variants.
27+
28+
4. At runtime, calling the setter updates the `data-*` attribute on `<body>` immediately. No VDOM. No re-renders.
29+
30+
---
31+
32+
## Best Practices for AI Agents
33+
34+
- ✅ Use `useUI()` **only for UI state**: themes, layout flags, open/closed toggles, etc.
35+
- ✅ Prefer **kebab-case keys**: e.g. `sidebar-open`, `theme-dark`.
36+
- ✅ Always provide a `defaultValue`: prevents FOUC and enables SSR.
37+
- ✅ Do **NOT** use the first value from `useUI()` for logic — it DOES NOT UPDATE.
38+
- ✅ You can call setters **from anywhere** in the app — no prop drilling or context needed.
39+
- ✅ Tailwind classes must use `key-value:` pattern:
40+
41+
- `theme-dark:bg-black`
42+
- `accent-blue:text-blue-500`
43+
- `sidebar-open:translate-x-0`
44+
45+
---
46+
47+
## Example: Toggle Theme
48+
49+
```tsx
50+
// Set state
51+
const [, setTheme] = useUI<'light' | 'dark'>('theme', 'light');
52+
<button onClick={() => setTheme('dark')}>Switch to dark</button>;
53+
```
54+
55+
```html
56+
<!-- React component with Tailwind variant -->
57+
<div className="theme-light:bg-white theme-dark:bg-black" />
58+
```
59+
60+
---
61+
62+
## What NOT to do
63+
64+
- ❌ Don't use `useUI()` for business logic or data fetching
65+
- ❌ Don't rely on the first tuple value for reactivity
66+
- ❌ Don't use camelCase keys (will break variant generation)
67+
68+
---
69+
70+
## Summary
1171

12-
## Best practices
72+
**React Zero-UI is a ZERO re-render UI state engine with global state baked in.** It replaces traditional VDOM cycles with `data-*` attribute flips and compile-time CSS. No React context. No prop drilling. No runtime cost.
1373

14-
- Only use `useUI` for UI-only state (themes, flags, etc.).
15-
- Prefer kebab-case keys (`sidebar-open`) so generated variants are predictable.
16-
- Always pass a default value to `useUI(key, defaultValue)` to avoid flashes during SSR.
17-
- The first value is ALWAYS STALE, do not use it if you need reactivity.
18-
- Mutate the state anywhere in the app: `const [, setTheme] = useUI('theme', 'light');` then call `setTheme('dark')`.
19-
- Compose Tailwind classes anywhere with the pattern `key-value:` like `theme-dark:bg-black`.
74+
Think of it as writing atomic Tailwind variants for every UI state — but flipping them dynamically at runtime without re-rendering anything.

examples/demo/.prettierignore

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/demo/.prettierrc.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/demo/.zero-ui/attributes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const bodyAttributes = {
44
"data-active": "zero",
55
"data-menu-open": "false",
66
"data-mobile-menu": "closed",
7-
"data-scrolled": "down",
7+
"data-scrolled": "up",
88
"data-theme": "light",
99
"data-theme-test": "light"
1010
};

examples/demo/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NextConfig } from 'next';
22

33
const nextConfig: NextConfig = {
4-
/* config options here */
4+
/* config options here */
55
};
66

77
export default nextConfig;

examples/demo/package.json

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
{
2-
"name": "react-zero",
3-
"version": "0.1.0",
4-
"private": true,
5-
"type": "module",
6-
"scripts": {
7-
"dev": "next dev",
8-
"build": "next build",
9-
"start": "next start",
10-
"lint": "next lint",
11-
"lint:fix": "next lint --fix",
12-
"format": "prettier --write .",
13-
"format:check": "prettier --check .",
14-
"type-check": "tsc --noEmit",
15-
"clean": "rm -rf .next"
16-
},
17-
"dependencies": {
18-
"@austinserb/react-zero-ui": "^1.0.19",
19-
"@vercel/analytics": "^1.5.0",
20-
"clsx": "^2.1.1",
21-
"motion": "^12.16.0",
22-
"next": "15.3.3",
23-
"react": "^19.0.0",
24-
"react-dom": "^19.0.0"
25-
},
26-
"devDependencies": {
27-
"@tailwindcss/postcss": "^4.1.10",
28-
"@types/node": "^20",
29-
"@types/react": "^19",
30-
"@types/react-dom": "^19",
31-
"postcss": "^8.5.5",
32-
"prettier": "^3.5.3",
33-
"prettier-plugin-tailwindcss": "^0.6.12",
34-
"tailwindcss": "^4.1.10",
35-
"typescript": "^5"
36-
}
37-
}
2+
"name": "react-zero",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "next dev",
8+
"build": "next build",
9+
"start": "next start",
10+
"lint": "next lint",
11+
"lint:fix": "next lint --fix",
12+
"format": "prettier --write .",
13+
"format:check": "prettier --check .",
14+
"type-check": "tsc --noEmit",
15+
"clean": "rm -rf .next"
16+
},
17+
"dependencies": {
18+
"@austinserb/react-zero-ui": "^1.0.21",
19+
"@vercel/analytics": "^1.5.0",
20+
"clsx": "^2.1.1",
21+
"motion": "^12.16.0",
22+
"next": "15.3.3",
23+
"react": "^19.0.0",
24+
"react-dom": "^19.0.0"
25+
},
26+
"devDependencies": {
27+
"@tailwindcss/postcss": "^4.1.10",
28+
"@types/node": "^20",
29+
"@types/react": "^19",
30+
"@types/react-dom": "^19",
31+
"postcss": "^8.5.5",
32+
"tailwindcss": "^4.1.10",
33+
"typescript": "^5"
34+
}
35+
}

examples/demo/postcss.config.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// postcss.config.mjs
22

3-
const config = {
4-
plugins: ['@austinserb/react-zero-ui/postcss', '@tailwindcss/postcss'],
5-
};
3+
const config = { plugins: ['@austinserb/react-zero-ui/postcss', '@tailwindcss/postcss'] };
64

75
export default config;

0 commit comments

Comments
 (0)