@sohanemon/utils 4.0.4 → 4.0.6

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.
@@ -1,8 +1,10 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  export { Icon as Iconify } from '@iconify/react';
4
+ // @ts-ignore
5
+ import styles from './responsiveness-indicator.module.css';
4
6
  export function TailwindIndicator() {
5
7
  if (process.env.NODE_ENV === 'production')
6
8
  return null;
7
- return (_jsxs("div", { className: 'fixed bottom-1 left-1 z-50 flex h-6 w-6 items-center justify-center rounded-full bg-gray-800 p-3 font-mono text-xs text-white', children: [_jsx("div", { className: 'block sm:hidden', children: "xs" }), _jsx("div", { className: 'hidden sm:block md:hidden', children: "sm" }), _jsx("div", { className: 'hidden md:block lg:hidden', children: "md" }), _jsx("div", { className: 'hidden lg:block xl:hidden', children: "lg" }), _jsx("div", { className: 'hidden xl:block 2xl:hidden', children: "xl" }), _jsx("div", { className: 'hidden 2xl:block', children: "2xl" })] }));
9
+ return (_jsxs("div", { className: styles.fixedBottomLeft, children: [_jsx("div", { className: styles.xs, children: "xs" }), _jsx("div", { className: styles.sm, children: "sm" }), _jsx("div", { className: styles.md, children: "md" }), _jsx("div", { className: styles.lg, children: "lg" }), _jsx("div", { className: styles.xl, children: "xl" }), _jsx("div", { className: styles['two-xl'], children: "2xl" })] }));
8
10
  }
@@ -8,5 +8,6 @@ export declare const useIsomorphicEffect: any;
8
8
  export declare function useTimeout(callback: () => void, delay?: number | null): void;
9
9
  export declare function useWindowEvent<K extends string = keyof WindowEventMap>(type: K, listener: K extends keyof WindowEventMap ? (this: Window, ev: WindowEventMap[K]) => void : (this: Window, ev: CustomEvent) => void, options?: boolean | AddEventListenerOptions): void;
10
10
  type LocalStorageValue<T> = [T, Dispatch<SetStateAction<T>>];
11
- declare const useLocalStorage: <T extends Record<string, any>>(key: string, defaultValue: T) => LocalStorageValue<T>;
12
- export default useLocalStorage;
11
+ export declare const useLocalStorage: <T extends Record<string, any>>(key: string, defaultValue: T) => LocalStorageValue<T>;
12
+ export declare const useUrlParams: <T extends string | number | boolean>(key: string, defaultValue: T) => [T, (value: T) => void];
13
+ export {};
@@ -102,7 +102,7 @@ export function useWindowEvent(type, listener, options) {
102
102
  }, [type, listener]);
103
103
  }
104
104
  // Custom hook for using local storage with a specified key and default value
105
- const useLocalStorage = (key, defaultValue) => {
105
+ export const useLocalStorage = (key, defaultValue) => {
106
106
  const [storedValue, setStoredValue] = useState(defaultValue);
107
107
  // Use effect to retrieve the stored value from local storage on component mount
108
108
  useEffect(() => {
@@ -126,4 +126,23 @@ const useLocalStorage = (key, defaultValue) => {
126
126
  };
127
127
  return [storedValue, updateStoredValue];
128
128
  };
129
- export default useLocalStorage;
129
+ // Custom hook for using URL parameters with a specified key and default value
130
+ export const useUrlParams = (key, defaultValue) => {
131
+ const [value, setValue] = useState(defaultValue);
132
+ // Use effect to retrieve the value from URL parameters on component mount
133
+ useEffect(() => {
134
+ const params = new URLSearchParams(window.location.search);
135
+ const value = params.get(key);
136
+ if (value !== null) {
137
+ setValue(value);
138
+ }
139
+ }, [key]);
140
+ // Function to update the value in URL parameters and state
141
+ const updateValue = (newValue) => {
142
+ const params = new URLSearchParams(window.location.search);
143
+ params.set(key, String(newValue));
144
+ window.history.pushState({}, '', `${window.location.pathname}?${params}`);
145
+ setValue(newValue);
146
+ };
147
+ return [value, updateValue];
148
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohanemon/utils",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/index.js",