oihana-next-ui 0.1.35 → 0.1.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oihana-next-ui",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "private": false,
5
5
  "description": "Oihana Next.js UI component library — reusable components, hooks and utilities built with React 19, Next.js, Tailwind CSS and DaisyUI",
6
6
  "author": {
@@ -16,19 +16,20 @@
16
16
  *
17
17
  * @example
18
18
  * ```js
19
+ * // With persistence
19
20
  * const [ display , saveDisplay , clearDisplay ] = useDisplayPreference( 'products' , 'flex' ) ;
20
21
  *
21
- * saveDisplay( 'masonry' ) ; // localStorage + cookie display__products=masonry
22
- * clearDisplay() ; // removes both
22
+ * // Without persistence (pageKey absent) save/clear are no-ops
23
+ * const [ display , saveDisplay , clearDisplay ] = useDisplayPreference( null , 'flex' ) ;
23
24
  * ```
24
25
  */
25
26
 
26
27
  import { useSyncExternalStore } from 'react' ;
27
28
 
28
- import readStorage from '../helpers/storage/readStorage' ;
29
- import removeStorage from '../helpers/storage/removeStorage' ;
30
- import subscribeStorage from '../helpers/storage/subscribeStorage' ;
31
- import writeStorage from '../helpers/storage/writeStorage' ;
29
+ import readStorage from 'oihana-next-ui/helpers/storage/readStorage' ;
30
+ import writeStorage from 'oihana-next-ui/helpers/storage/writeStorage' ;
31
+ import removeStorage from 'oihana-next-ui/helpers/storage/removeStorage' ;
32
+ import subscribeStorage from 'oihana-next-ui/helpers/storage/subscribeStorage' ;
32
33
 
33
34
  /**
34
35
  * Prefix applied to all display preference storage keys.
@@ -45,22 +46,25 @@ export const DISPLAY_STORAGE_PREFIX = 'display__' ;
45
46
  export const getDisplayStorageKey = pageKey => `${ DISPLAY_STORAGE_PREFIX }${ pageKey }` ;
46
47
 
47
48
  /**
48
- * @param {string} pageKey - Page identifier — use `url` or `path` prop from ThingsPage.
49
- * @param {string} [defaultValue='flex'] - Fallback when nothing is stored.
49
+ * @param {string|null|undefined} pageKey - Page identifier — use `url` or `path` prop from ThingsPage.
50
+ * Pass null/undefined to disable persistence entirely.
51
+ * @param {string} [defaultValue='flex'] - Fallback when nothing is stored.
50
52
  * @returns {[ string , (mode: string) => void , () => void ]}
51
53
  */
52
54
  const useDisplayPreference = ( pageKey , defaultValue = 'flex' ) =>
53
55
  {
54
- const key = getDisplayStorageKey( pageKey ) ;
56
+ const key = pageKey ? getDisplayStorageKey( pageKey ) : null ;
55
57
 
56
- const subscribe = cb => subscribeStorage( cb ) ;
57
- const getSnapshot = () => readStorage( key ) ?? defaultValue ;
58
+ const subscribe = cb => key ? subscribeStorage( cb ) : () => {} ;
59
+ const getSnapshot = () => key ? ( readStorage( key ) ?? defaultValue ) : defaultValue ;
58
60
  const getServerSnapshot = () => defaultValue ;
59
61
 
60
62
  const value = useSyncExternalStore( subscribe , getSnapshot , getServerSnapshot ) ;
61
63
 
62
64
  const save = mode =>
63
65
  {
66
+ if ( !key ) return ;
67
+
64
68
  if ( mode )
65
69
  {
66
70
  writeStorage( key , mode ) ;
@@ -71,7 +75,7 @@ const useDisplayPreference = ( pageKey , defaultValue = 'flex' ) =>
71
75
  }
72
76
  } ;
73
77
 
74
- const clear = () => removeStorage( key ) ;
78
+ const clear = () => key && removeStorage( key ) ;
75
79
 
76
80
  return [ value , save , clear ] ;
77
81
  } ;
package/src/version.js CHANGED
@@ -1,3 +1,3 @@
1
- const version = "0.1.35" ;
1
+ const version = "0.1.36" ;
2
2
 
3
3
  export default version ;