1-
21<div align =" center " >
32
43# 📚 API Reference
@@ -12,6 +11,7 @@ Detailed reference for all hooks, utilities, and configuration options.
1211---
1312
1413## 📚 Table of Contents
14+
1515- [ 🔨 Core Hooks] ( #-core-hooks )
1616- [ 🌈 Utilities] ( #-utilities )
1717- [ 🧪 Experimental APIs] ( #-experimental-apis )
@@ -34,18 +34,18 @@ const [staleValue, setter] = useUI(key, initial, flag?);
3434
3535#### Parameters
3636
37- | Parameter | Type | Description |
38- |-----------| ------| -------------|
39- | ` key ` | ` string ` | The state key (becomes ` data - {key }` attribute) |
40- | ` initial ` | ` T ` | Initial/default value for SSR |
41- | ` flag ? ` | ` typeof CssVar ` | Optional: Use CSS variables instead of data attributes |
37+ | Parameter | Type | Description |
38+ | --------- | -- ------------- | ------------------------------------------------------ |
39+ | ` key ` | ` string ` | The state key (becomes ` data - {key }` attribute) |
40+ | ` initial ` | ` T ` | Initial/default value for SSR |
41+ | ` flag ? ` | ` typeof CssVar ` | Optional: Use CSS variables instead of data attributes |
4242
4343#### Returns
4444
45- | Return | Type | Description |
46- |--------| ------| -------------|
47- | ` staleValue ` | ` T ` | Initial value (doesn't update, use for SSR only) |
48- | ` setter ` | ` GlobalSetterFn <T >` | Function to update the global state |
45+ | Return | Type | Description |
46+ | ------------ | ------------------- | ------------------------------------------------ |
47+ | ` staleValue ` | ` T ` | Initial value (doesn't update, use for SSR only) |
48+ | ` setter ` | ` GlobalSetterFn <T >` | Function to update the global state |
4949
5050#### Examples
5151
@@ -62,7 +62,7 @@ const [color, setColor] = useUI('primary', '#blue', CssVar);
6262setColor (' #red' ); // Sets --primary: #red on <body>
6363
6464// Functional updates
65- setTheme (prev => prev === ' light' ? ' dark' : ' light' );
65+ setTheme (( prev ) => ( prev === ' light' ? ' dark' : ' light' ) );
6666` ` `
6767
6868---
@@ -81,35 +81,33 @@ Same as `useUI`, but affects only the element assigned to `setter.ref`.
8181
8282#### Returns
8383
84- | Return | Type | Description |
85- |--------| ------| -------------|
86- | ` staleValue ` | ` T ` | Initial value (doesn't update, use for SSR only) |
87- | ` setter ` | ` ScopedSetterFn <T >` | Function with attached ` ref ` property |
84+ | Return | Type | Description |
85+ | ------------ | ------------------- | ------------------------------------------------ |
86+ | ` staleValue ` | ` T ` | Initial value (doesn't update, use for SSR only) |
87+ | ` setter ` | ` ScopedSetterFn <T >` | Function with attached ` ref ` property |
8888
8989#### Examples
9090
9191` ` ` tsx
9292// Basic scoped usage
9393const [modal , setModal ] = useScopedUI (' modal' , ' closed' );
9494
95- <div
95+ <div
9696 ref = { setModal .ref }
9797 data-modal = { modal } // Prevents FOUC
98- className = " modal-closed:hidden modal-open:block"
99- >
98+ className = " modal-closed:hidden modal-open:block" >
10099 Modal content
101- </div >
100+ </div >;
102101
103102// With CSS variables
104103const [blur , setBlur ] = useScopedUI (' blur' , ' 0px' , CssVar );
105104
106- <div
105+ <div
107106 ref = { setBlur .ref }
108107 style = { { ' --blur' : blur }}
109- className = " backdrop-blur-[var(--blur)]"
110- >
108+ className = " backdrop-blur-[var(--blur)]" >
111109 Blurred content
112- </div >
110+ </div >;
113111` ` `
114112
115113---
@@ -148,10 +146,10 @@ const clickHandler = zeroSSR.onClick(key, values);
148146
149147#### Parameters
150148
151- | Parameter | Type | Description |
152- |-----------| ------| -------------|
153- | ` key ` | ` string ` | State key (kebab-case required) |
154- | ` values ` | ` string []` | Array of values to cycle through |
149+ | Parameter | Type | Description |
150+ | --------- | -- -------- | -------------------------------- |
151+ | ` key ` | ` string ` | State key (kebab-case required) |
152+ | ` values ` | ` string []` | Array of values to cycle through |
155153
156154#### Returns
157155
@@ -189,13 +187,9 @@ Same as `zeroSSR.onClick`, but affects the closest ancestor with `data-{key}` at
189187
190188` ` ` tsx
191189<div data-modal = " closed" >
192- <button { ... scopedZeroSSR .onClick (' modal' , [' closed' , ' open' ])} >
193- Open Modal
194- </button >
195-
196- <div className = " modal-closed:hidden modal-open:block" >
197- Modal content
198- </div >
190+ <button { ... scopedZeroSSR .onClick (' modal' , [' closed' , ' open' ])} >Open Modal</button >
191+
192+ <div className = " modal-closed:hidden modal-open:block" >Modal content</div >
199193</div >
200194` ` `
201195
@@ -214,8 +208,8 @@ activateZeroUiRuntime(variantKeyMap);
214208
215209#### Parameters
216210
217- | Parameter | Type | Description |
218- |-----------| ------| -------------|
211+ | Parameter | Type | Description |
212+ | ------------ | -------------------------- | -------------------------------------------- |
219213| ` variantMap ` | ` Record <string , string []>` | Generated variant mapping from build process |
220214
221215#### Setup
@@ -285,16 +279,13 @@ interface ScopedSetterFn<T extends string = string> {
285279## 🚨 Limitations & Constraints
286280
287281### State Key Requirements
282+
288283- DO NOT USE IMPORTED VARIABLES IN THE STATE KEY
289284- Must be valid HTML attribute names
290285- Kebab-case required: ` ' sidebar-state' ` not ` ' sidebarState' `
291286- Avoid conflicts with existing data attributes
292287- Must resolve to a non-spaced string: ` ' sidebar-state' ` not ` ' sidebar State' `
293- - Must be a local constant that resolves to a string:
294-
295-
296-
297-
288+ - Must be a local constant that resolves to a string:
298289
299290### Scoped UI Constraints
300291
@@ -325,12 +316,11 @@ Generated variant mapping for runtime activation.
325316` ` ` ts
326317/* AUTO-GENERATED - DO NOT EDIT */
327318export const bodyAttributes = {
328- " data-theme" : " light" ,
329- " data-accent" : " violet" ,
330- " data-scrolled" : " up " ,
331- // ...
319+ ' data-theme' : ' light' ,
320+ ' data-accent' : ' violet' ,
321+ ' data-scrolled' : ' up ' ,
322+ // ...
332323};
333-
334324` ` `
335325
336326### ` .zero - ui / styles .css ` (Vite)
@@ -339,7 +329,7 @@ Generated CSS variants for Vite projects.
339329
340330` ` ` css
341331/* Auto-generated Tailwind variants */
342- [data - theme = " dark" ] .theme - dark \: bg - gray - 900 {
332+ [data - theme = ' dark' ] .theme - dark \: bg - gray - 900 {
343333 background-color: rgb (17 24 39 );
344334}
345335/* ... */
@@ -385,14 +375,14 @@ cat .zero-ui/attributes.ts
385375
386376` ` ` tsx
387377// ✅ Good: Descriptive and clear
388- useUI (' theme' , ' light' )
389- useUI (' sidebar-state' , ' collapsed' )
390- useUI (' modal-visibility' , ' hidden' )
378+ useUI (' theme' , ' light' );
379+ useUI (' sidebar-state' , ' collapsed' );
380+ useUI (' modal-visibility' , ' hidden' );
391381
392382// ❌ Avoid: Generic or unclear
393- useUI (' state' , ' on' )
394- useUI (' x' , ' y' )
395- useUI (' toggle' , ' true' )
383+ useUI (' state' , ' on' );
384+ useUI (' x' , ' y' );
385+ useUI (' toggle' , ' true' );
396386` ` `
397387
398388### TypeScript Usage
@@ -411,13 +401,13 @@ const [, setModal] = useUI<ModalState>('modal', 'closed');
411401
412402` ` ` tsx
413403// ✅ Use CSS for conditional rendering
414- <div className = " modal-closed:hidden modal-open:block" >
415- Modal content
416- </div >
404+ <div className = " modal-closed:hidden modal-open:block" >Modal content</div >;
417405
418406// ❌ Avoid reading stale values for logic
419407const [modal , setModal ] = useUI (' modal' , ' closed' );
420- {modal === ' open' && <Modal />} // Won't work as expected
408+ {
409+ modal === ' open' && <Modal />;
410+ } // Won't work as expected
421411` ` `
422412
423413---
@@ -428,4 +418,4 @@ const [modal, setModal] = useUI('modal', 'closed');
428418
429419[**📋 Usage Examples**](./usage-examples.md) | [**🔧 Troubleshooting**](./troubleshooting.md) | [**🔄 Migration Guide**](./migration-guide.md)
430420
431- </div>
421+ </div>
0 commit comments