@sohanemon/utils 4.0.5 → 4.0.7
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/components/index.d.ts +2 -2
- package/dist/components/index.js +64 -5
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +20 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const ResponsiveIndicator: React.FC;
|
package/dist/components/index.js
CHANGED
|
@@ -1,8 +1,67 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsx as _jsx
|
|
3
|
-
|
|
4
|
-
export
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
export const ResponsiveIndicator = () => {
|
|
5
|
+
const [viewportWidth, setViewportWidth] = React.useState(window.innerWidth);
|
|
6
|
+
const [position, setPosition] = React.useState(0); // State to manage button position
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const handleResize = () => {
|
|
9
|
+
setViewportWidth(window.innerWidth);
|
|
10
|
+
};
|
|
11
|
+
window.addEventListener('resize', handleResize);
|
|
12
|
+
return () => {
|
|
13
|
+
window.removeEventListener('resize', handleResize);
|
|
14
|
+
};
|
|
15
|
+
}, []);
|
|
16
|
+
// Function to handle button click
|
|
17
|
+
const handleClick = () => {
|
|
18
|
+
setPosition((prevPosition) => (prevPosition + 1) % 4); // Cycle through positions
|
|
19
|
+
};
|
|
20
|
+
let text = '';
|
|
21
|
+
if (viewportWidth < 640) {
|
|
22
|
+
text = 'xs';
|
|
23
|
+
}
|
|
24
|
+
else if (viewportWidth >= 640 && viewportWidth < 768) {
|
|
25
|
+
text = 'sm';
|
|
26
|
+
}
|
|
27
|
+
else if (viewportWidth >= 768 && viewportWidth < 1024) {
|
|
28
|
+
text = 'md';
|
|
29
|
+
}
|
|
30
|
+
else if (viewportWidth >= 1024 && viewportWidth < 1280) {
|
|
31
|
+
text = 'lg';
|
|
32
|
+
}
|
|
33
|
+
else if (viewportWidth >= 1280 && viewportWidth < 1536) {
|
|
34
|
+
text = 'xl';
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
text = '2xl';
|
|
38
|
+
}
|
|
39
|
+
// Define positions
|
|
40
|
+
const positions = [
|
|
41
|
+
{ bottom: '2rem', left: '2rem' },
|
|
42
|
+
{ bottom: '2rem', right: '2rem' },
|
|
43
|
+
{ top: '2rem', right: '2rem' },
|
|
44
|
+
{ top: '2rem', left: '2rem' }, // Top left
|
|
45
|
+
];
|
|
46
|
+
const buttonStyle = {
|
|
47
|
+
position: 'fixed',
|
|
48
|
+
zIndex: 50,
|
|
49
|
+
display: 'grid',
|
|
50
|
+
height: '2.5rem',
|
|
51
|
+
width: '2.5rem',
|
|
52
|
+
borderRadius: '50%',
|
|
53
|
+
placeContent: 'center',
|
|
54
|
+
backgroundColor: '#2d3748',
|
|
55
|
+
fontFamily: 'Courier New, Courier, monospace',
|
|
56
|
+
fontSize: '1rem',
|
|
57
|
+
color: '#ffffff',
|
|
58
|
+
border: '2px solid #4a5568',
|
|
59
|
+
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
|
|
60
|
+
padding: '0.5rem',
|
|
61
|
+
transition: 'all 0.2s ease-in-out',
|
|
62
|
+
...positions[position], // Apply the current position
|
|
63
|
+
};
|
|
5
64
|
if (process.env.NODE_ENV === 'production')
|
|
6
65
|
return null;
|
|
7
|
-
return (
|
|
8
|
-
}
|
|
66
|
+
return (_jsx("button", { style: buttonStyle, onClick: handleClick, children: text }));
|
|
67
|
+
};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export declare function useTimeout(callback: () => void, delay?: number | null):
|
|
|
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
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];
|
|
12
13
|
export {};
|
package/dist/hooks/index.js
CHANGED
|
@@ -126,3 +126,23 @@ export const useLocalStorage = (key, defaultValue) => {
|
|
|
126
126
|
};
|
|
127
127
|
return [storedValue, updateStoredValue];
|
|
128
128
|
};
|
|
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
|
+
};
|