Skip to content

Commit 69b88f4

Browse files
committed
docs: dynamic presets
1 parent ab60d20 commit 69b88f4

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ npm install windctrl
2424
## Quick Start
2525

2626
```typescript
27-
import { windctrl } from "windctrl";
27+
import { windctrl, dynamic as d } from "windctrl";
2828

2929
const button = windctrl({
3030
base: "rounded px-4 py-2 font-medium transition duration-200",
@@ -44,8 +44,7 @@ const button = windctrl({
4444
glass: "backdrop-blur-md bg-white/10 border border-white/20 shadow-xl",
4545
},
4646
dynamic: {
47-
w: (val) =>
48-
typeof val === "number" ? { style: { width: `${val}px` } } : val,
47+
w: d.px("width"),
4948
},
5049
defaultVariants: {
5150
intent: "primary",
@@ -80,12 +79,46 @@ Interpolated variants provide a **Unified API** that bridges static Tailwind cla
8079
This is **JIT-friendly by design**, as long as the class strings you return are statically enumerable (i.e. appear in your source code).
8180
For truly unbounded values (e.g. pixel sizes), prefer returning style to avoid relying on arbitrary-value class generation.
8281

82+
#### Dynamic Presets
83+
84+
WindCtrl provides built-in presets for common dynamic patterns:
85+
86+
```typescript
87+
import { windctrl, dynamic as d } from "windctrl";
88+
89+
const box = windctrl({
90+
dynamic: {
91+
// d.px() - pixel values (width, height, top, left, etc.)
92+
w: d.px("width"),
93+
h: d.px("height"),
94+
95+
// d.num() - unitless numbers (zIndex, flexGrow, order, etc.)
96+
z: d.num("zIndex"),
97+
98+
// d.opacity() - opacity values
99+
fade: d.opacity(),
100+
101+
// d.var() - CSS custom properties
102+
x: d.var("--translate-x", { unit: "px" }),
103+
},
104+
});
105+
106+
// Usage
107+
box({ w: 200 }); // -> style: { width: "200px" }
108+
box({ w: "w-full" }); // -> className: "w-full"
109+
box({ z: 50 }); // -> style: { zIndex: 50 }
110+
box({ fade: 0.5 }); // -> style: { opacity: 0.5 }
111+
box({ x: 10 }); // -> style: { "--translate-x": "10px" }
112+
```
113+
114+
#### Custom Resolvers
115+
116+
You can also write custom resolvers for more complex logic:
117+
83118
```typescript
84119
const button = windctrl({
85120
dynamic: {
86-
// Recommended pattern:
87-
// - Numbers -> inline styles (unbounded values)
88-
// - Strings -> Tailwind utilities (must be statically enumerable for JIT)
121+
// Custom resolver example
89122
w: (val) =>
90123
typeof val === "number" ? { style: { width: `${val}px` } } : val,
91124
},

0 commit comments

Comments
 (0)