@sohanemon/utils 4.0.24 → 4.0.26
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,4 +1,6 @@
|
|
|
1
1
|
export declare const setClientSideCookie: (name: string, value: string, days?: number, path?: string) => void;
|
|
2
2
|
export declare const deleteClientSideCookie: (name: string, path?: string) => void;
|
|
3
3
|
export declare const hasClientSideCookie: (name: string) => boolean;
|
|
4
|
-
export declare const getClientSideCookie: (name: string) =>
|
|
4
|
+
export declare const getClientSideCookie: (name: string) => {
|
|
5
|
+
value: string;
|
|
6
|
+
};
|
package/dist/functions/cookie.js
CHANGED
|
@@ -5,3 +5,4 @@ export declare function cn(...inputs: ClassValue[]): string;
|
|
|
5
5
|
export declare function isNavActive(href: string, path: string): boolean;
|
|
6
6
|
export declare function cleanSrc(src: string): string;
|
|
7
7
|
export declare const scrollTo: (containerSelector: string | React.RefObject<HTMLDivElement>, to: "top" | "bottom") => void;
|
|
8
|
+
export declare const copyToClipboard: (value: string, onSuccess?: () => void) => void;
|
package/dist/functions/index.js
CHANGED
|
@@ -33,3 +33,12 @@ export const scrollTo = (containerSelector, to) => {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
+
export const copyToClipboard = (value, onSuccess = () => { }) => {
|
|
37
|
+
if (typeof window === 'undefined' || !navigator.clipboard?.writeText) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!value) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
navigator.clipboard.writeText(value).then(onSuccess);
|
|
44
|
+
};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -14,3 +14,9 @@ export declare const useUrlParams: <T extends string | number | boolean>(key: st
|
|
|
14
14
|
export declare const useQuerySelector: <T extends Element>(selector: string) => T | null;
|
|
15
15
|
export declare function useIsClient(): boolean;
|
|
16
16
|
export declare function useLockScroll(): void;
|
|
17
|
+
export declare function useCopyToClipboard({ timeout }: {
|
|
18
|
+
timeout?: number;
|
|
19
|
+
}): {
|
|
20
|
+
isCopied: Boolean;
|
|
21
|
+
copy: (value: string) => void;
|
|
22
|
+
};
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
3
|
+
import { copyToClipboard } from '../functions';
|
|
3
4
|
export * from './action';
|
|
4
5
|
export const useClickOutside = (callback = () => alert('clicked outside')) => {
|
|
5
6
|
const ref = useRef(null);
|
|
@@ -189,3 +190,15 @@ export function useLockScroll() {
|
|
|
189
190
|
};
|
|
190
191
|
}, []);
|
|
191
192
|
}
|
|
193
|
+
export function useCopyToClipboard({ timeout = 2000 }) {
|
|
194
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
195
|
+
const copy = (value) => {
|
|
196
|
+
copyToClipboard(value, () => {
|
|
197
|
+
setIsCopied(true);
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
setIsCopied(false);
|
|
200
|
+
}, timeout);
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
return { isCopied, copy };
|
|
204
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sohanemon/utils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.26",
|
|
4
4
|
"author": "Sohan Emon <sohanemon@outlook.com>",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
@@ -15,18 +15,30 @@
|
|
|
15
15
|
},
|
|
16
16
|
"typesVersions": {
|
|
17
17
|
"*": {
|
|
18
|
-
"core": [
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
"core": [
|
|
19
|
+
"dist/index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"hooks": [
|
|
22
|
+
"dist/hooks/index.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"components": [
|
|
25
|
+
"dist/components/index.d.ts"
|
|
26
|
+
]
|
|
21
27
|
}
|
|
22
28
|
},
|
|
23
|
-
"files": [
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
24
33
|
"scripts": {
|
|
25
34
|
"build": "tsc",
|
|
26
35
|
"build:watch": "tsc --watch",
|
|
27
36
|
"export": "tsc && npm publish"
|
|
28
37
|
},
|
|
29
|
-
"keywords": [
|
|
38
|
+
"keywords": [
|
|
39
|
+
"utils",
|
|
40
|
+
"cn"
|
|
41
|
+
],
|
|
30
42
|
"license": "ISC",
|
|
31
43
|
"devDependencies": {
|
|
32
44
|
"@types/node": "^22.4.0",
|