@sohanemon/utils 4.0.10 → 4.0.11
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 +3 -2
- package/dist/components/index.js +4 -3
- package/dist/components/media-wrapper.d.ts +7 -0
- package/dist/components/media-wrapper.js +10 -0
- package/dist/components/responsive-indicator.d.ts +1 -1
- package/dist/components/responsive-indicator.js +31 -31
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +23 -23
- package/package.json +1 -1
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { Icon as Iconify } from
|
|
2
|
-
export {
|
|
1
|
+
export { Icon as Iconify } from "@iconify/react";
|
|
2
|
+
export { MediaWrapper } from "./media-wrapper";
|
|
3
|
+
export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from "./responsive-indicator";
|
package/dist/components/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export { Icon as Iconify } from
|
|
3
|
-
export {
|
|
1
|
+
"use client";
|
|
2
|
+
export { Icon as Iconify } from "@iconify/react";
|
|
3
|
+
export { MediaWrapper } from "./media-wrapper";
|
|
4
|
+
export { ResponsiveIndicator, ResponsiveIndicator as TailwindIndicator, } from "./responsive-indicator";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type BreakPoints = "sm" | "md" | "lg" | "xl" | "2xl" | "max-sm" | "max-md" | "max-lg" | "max-xl" | "max-2xl";
|
|
3
|
+
type MediaWrapperProps = React.ComponentProps<"div"> & {
|
|
4
|
+
breakpoint: BreakPoints;
|
|
5
|
+
};
|
|
6
|
+
export declare function MediaWrapper({ breakpoint, ...props }: MediaWrapperProps): any;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { useMediaQuery } from "../hooks";
|
|
5
|
+
export function MediaWrapper({ breakpoint, ...props }) {
|
|
6
|
+
const overMedia = useMediaQuery(breakpoint.split("-").pop());
|
|
7
|
+
const isMax = breakpoint.startsWith("max");
|
|
8
|
+
const Wrapper = overMedia === isMax ? React.Fragment : "div";
|
|
9
|
+
return _jsx(Wrapper, { ...props });
|
|
10
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as React from
|
|
1
|
+
import * as React from "react";
|
|
2
2
|
export declare const ResponsiveIndicator: React.FC;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import * as React from
|
|
3
|
+
import * as React from "react";
|
|
4
4
|
export const ResponsiveIndicator = () => {
|
|
5
5
|
const [viewportWidth, setViewportWidth] = React.useState(window.innerWidth);
|
|
6
6
|
const [position, setPosition] = React.useState(0); // State to manage button position
|
|
@@ -8,60 +8,60 @@ export const ResponsiveIndicator = () => {
|
|
|
8
8
|
const handleResize = () => {
|
|
9
9
|
setViewportWidth(window.innerWidth);
|
|
10
10
|
};
|
|
11
|
-
window.addEventListener(
|
|
11
|
+
window.addEventListener("resize", handleResize);
|
|
12
12
|
return () => {
|
|
13
|
-
window.removeEventListener(
|
|
13
|
+
window.removeEventListener("resize", handleResize);
|
|
14
14
|
};
|
|
15
15
|
}, []);
|
|
16
16
|
// Function to handle button click
|
|
17
17
|
const handleClick = () => {
|
|
18
18
|
setPosition((prevPosition) => (prevPosition + 1) % 4); // Cycle through positions
|
|
19
19
|
};
|
|
20
|
-
let text =
|
|
20
|
+
let text = "";
|
|
21
21
|
if (viewportWidth < 640) {
|
|
22
|
-
text =
|
|
22
|
+
text = "xs";
|
|
23
23
|
}
|
|
24
24
|
else if (viewportWidth >= 640 && viewportWidth < 768) {
|
|
25
|
-
text =
|
|
25
|
+
text = "sm";
|
|
26
26
|
}
|
|
27
27
|
else if (viewportWidth >= 768 && viewportWidth < 1024) {
|
|
28
|
-
text =
|
|
28
|
+
text = "md";
|
|
29
29
|
}
|
|
30
30
|
else if (viewportWidth >= 1024 && viewportWidth < 1280) {
|
|
31
|
-
text =
|
|
31
|
+
text = "lg";
|
|
32
32
|
}
|
|
33
33
|
else if (viewportWidth >= 1280 && viewportWidth < 1536) {
|
|
34
|
-
text =
|
|
34
|
+
text = "xl";
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
|
-
text =
|
|
37
|
+
text = "2xl";
|
|
38
38
|
}
|
|
39
39
|
// Define positions
|
|
40
40
|
const positions = [
|
|
41
|
-
{ bottom:
|
|
42
|
-
{ bottom:
|
|
43
|
-
{ top:
|
|
44
|
-
{ top:
|
|
41
|
+
{ bottom: "2rem", left: "2rem" }, // Bottom left
|
|
42
|
+
{ bottom: "2rem", right: "2rem" }, // Bottom right
|
|
43
|
+
{ top: "2rem", right: "2rem" }, // Top right
|
|
44
|
+
{ top: "2rem", left: "2rem" }, // Top left
|
|
45
45
|
];
|
|
46
46
|
const buttonStyle = {
|
|
47
|
-
position:
|
|
47
|
+
position: "fixed",
|
|
48
48
|
zIndex: 50,
|
|
49
|
-
display:
|
|
50
|
-
height:
|
|
51
|
-
width:
|
|
52
|
-
borderRadius:
|
|
53
|
-
placeContent:
|
|
54
|
-
backgroundColor:
|
|
55
|
-
fontFamily:
|
|
56
|
-
fontSize:
|
|
57
|
-
color:
|
|
58
|
-
border:
|
|
59
|
-
boxShadow:
|
|
60
|
-
padding:
|
|
61
|
-
transition:
|
|
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
62
|
...positions[position], // Apply the current position
|
|
63
63
|
};
|
|
64
|
-
if (process.env.NODE_ENV ===
|
|
64
|
+
if (process.env.NODE_ENV === "production")
|
|
65
65
|
return null;
|
|
66
|
-
return (_jsx("button", { style: buttonStyle, onClick: handleClick, children: text }));
|
|
66
|
+
return (_jsx("button", { type: "button", style: buttonStyle, onClick: handleClick, children: text }));
|
|
67
67
|
};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dispatch, EffectCallback, SetStateAction } from
|
|
1
|
+
import { type Dispatch, type EffectCallback, type SetStateAction } from "react";
|
|
2
2
|
export declare const useClickOutside: (callback?: () => void) => any;
|
|
3
|
-
export declare function useMediaQuery(tailwindBreakpoint:
|
|
3
|
+
export declare function useMediaQuery(tailwindBreakpoint: "sm" | "md" | "lg" | "xl" | "2xl" | `(${string})`): any;
|
|
4
4
|
export declare function useEffectOnce(effect: EffectCallback): void;
|
|
5
5
|
export declare function useUpdateEffect(effect: EffectCallback, deps: any[]): void;
|
|
6
6
|
export declare function useDebounce<T>(state: T, delay?: number): T;
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from
|
|
3
|
-
export const useClickOutside = (callback = () => alert(
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
3
|
+
export const useClickOutside = (callback = () => alert("clicked outside")) => {
|
|
4
4
|
const ref = useRef(null);
|
|
5
5
|
const listener = (e) => {
|
|
6
6
|
if (ref.current && !ref.current.contains(e.target)) {
|
|
@@ -8,11 +8,11 @@ export const useClickOutside = (callback = () => alert('clicked outside')) => {
|
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
useEffect(() => {
|
|
11
|
-
document.addEventListener(
|
|
12
|
-
document.addEventListener(
|
|
11
|
+
document.addEventListener("mousedown", listener);
|
|
12
|
+
document.addEventListener("touchstart", listener);
|
|
13
13
|
return () => {
|
|
14
|
-
document.removeEventListener(
|
|
15
|
-
document.removeEventListener(
|
|
14
|
+
document.removeEventListener("mousedown", listener);
|
|
15
|
+
document.removeEventListener("touchstart", listener);
|
|
16
16
|
};
|
|
17
17
|
});
|
|
18
18
|
return ref;
|
|
@@ -20,22 +20,22 @@ export const useClickOutside = (callback = () => alert('clicked outside')) => {
|
|
|
20
20
|
export function useMediaQuery(tailwindBreakpoint) {
|
|
21
21
|
const parsedQuery = useMemo(() => {
|
|
22
22
|
switch (tailwindBreakpoint) {
|
|
23
|
-
case
|
|
24
|
-
return
|
|
25
|
-
case
|
|
26
|
-
return
|
|
27
|
-
case
|
|
28
|
-
return
|
|
29
|
-
case
|
|
30
|
-
return
|
|
31
|
-
case
|
|
32
|
-
return
|
|
23
|
+
case "sm":
|
|
24
|
+
return "(min-width: 640px)";
|
|
25
|
+
case "md":
|
|
26
|
+
return "(min-width: 768px)";
|
|
27
|
+
case "lg":
|
|
28
|
+
return "(min-width: 1024px)";
|
|
29
|
+
case "xl":
|
|
30
|
+
return "(min-width: 1280px)";
|
|
31
|
+
case "2xl":
|
|
32
|
+
return "(min-width: 1536px)";
|
|
33
33
|
default:
|
|
34
34
|
return tailwindBreakpoint;
|
|
35
35
|
}
|
|
36
36
|
}, [tailwindBreakpoint]);
|
|
37
37
|
const getMatches = (parsedQuery) => {
|
|
38
|
-
if (typeof window !==
|
|
38
|
+
if (typeof window !== "undefined") {
|
|
39
39
|
return window.matchMedia(parsedQuery).matches;
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
@@ -47,9 +47,9 @@ export function useMediaQuery(tailwindBreakpoint) {
|
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
const matchMedia = window.matchMedia(parsedQuery);
|
|
49
49
|
handleChange();
|
|
50
|
-
matchMedia.addEventListener(
|
|
50
|
+
matchMedia.addEventListener("change", handleChange);
|
|
51
51
|
return () => {
|
|
52
|
-
matchMedia.removeEventListener(
|
|
52
|
+
matchMedia.removeEventListener("change", handleChange);
|
|
53
53
|
};
|
|
54
54
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
55
|
}, [parsedQuery]);
|
|
@@ -81,7 +81,7 @@ export function useDebounce(state, delay = 500) {
|
|
|
81
81
|
}, [state, delay]);
|
|
82
82
|
return debouncedState;
|
|
83
83
|
}
|
|
84
|
-
export const useIsomorphicEffect = typeof window !==
|
|
84
|
+
export const useIsomorphicEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
85
85
|
export function useTimeout(callback, delay = 1000) {
|
|
86
86
|
const savedCallback = useRef(callback);
|
|
87
87
|
useIsomorphicEffect(() => {
|
|
@@ -114,7 +114,7 @@ export const useLocalStorage = (key, defaultValue) => {
|
|
|
114
114
|
// Function to update the stored value in local storage and state
|
|
115
115
|
const updateStoredValue = (valueOrFn) => {
|
|
116
116
|
let newValue;
|
|
117
|
-
if (typeof valueOrFn ===
|
|
117
|
+
if (typeof valueOrFn === "function") {
|
|
118
118
|
const updateFunction = valueOrFn;
|
|
119
119
|
newValue = updateFunction(storedValue);
|
|
120
120
|
}
|
|
@@ -141,7 +141,7 @@ export const useUrlParams = (key, defaultValue) => {
|
|
|
141
141
|
const updateValue = (newValue) => {
|
|
142
142
|
const params = new URLSearchParams(window.location.search);
|
|
143
143
|
params.set(key, String(newValue));
|
|
144
|
-
window.history.pushState({},
|
|
144
|
+
window.history.pushState({}, "", `${window.location.pathname}?${params}`);
|
|
145
145
|
setValue(newValue);
|
|
146
146
|
};
|
|
147
147
|
return [value, updateValue];
|