@postxl/ui-components 1.2.0 → 1.2.1

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/dist/index.js CHANGED
@@ -48,7 +48,7 @@ import * as React$4 from "react";
48
48
  import * as React$3 from "react";
49
49
  import * as React$2 from "react";
50
50
  import * as React$1 from "react";
51
- import React, { memo, useEffect, useMemo, useRef, useState } from "react";
51
+ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
52
52
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
53
53
  import { cva } from "class-variance-authority";
54
54
  import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog";
@@ -6837,8 +6837,27 @@ function SidebarMenuSubButton({ asChild = false, size = "md", isActive = false,
6837
6837
 
6838
6838
  //#endregion
6839
6839
  //#region src/slicer/slicer.tsx
6840
- function Slicer({ filterValues, selectedValues, onChange, title, isLoading = false, optionsHeight = 200, className, defaultCollapsed = false }) {
6841
- const [isCollapsed, setIsCollapsed] = useState(defaultCollapsed);
6840
+ function usePersistedState(storageKey, defaultValue) {
6841
+ const [state, setState] = useState(() => {
6842
+ if (!storageKey) return defaultValue;
6843
+ try {
6844
+ const stored = localStorage.getItem(storageKey);
6845
+ return stored === null ? defaultValue : JSON.parse(stored);
6846
+ } catch {
6847
+ return defaultValue;
6848
+ }
6849
+ });
6850
+ const setPersistedState = useCallback((value) => {
6851
+ setState(value);
6852
+ if (storageKey) try {
6853
+ localStorage.setItem(storageKey, JSON.stringify(value));
6854
+ } catch {}
6855
+ }, [storageKey]);
6856
+ return [state, setPersistedState];
6857
+ }
6858
+ function Slicer({ filterValues, selectedValues, onChange, title, isLoading = false, optionsHeight = 200, className, defaultCollapsed = false, storageKey }) {
6859
+ const effectiveStorageKey = storageKey === null ? void 0 : storageKey ?? `slicer-collapsed-${title}`;
6860
+ const [isCollapsed, setIsCollapsed] = usePersistedState(effectiveStorageKey, defaultCollapsed);
6842
6861
  const [searchQuery, setSearchQuery] = useState("");
6843
6862
  const filteredOptions = useMemo(() => {
6844
6863
  if (!searchQuery) return filterValues;