react-restyle-components 0.2.77 → 0.2.78
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/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/package.json +1 -1
- package/lib/src/core-hooks/index.d.ts +4 -0
- package/lib/src/core-hooks/index.d.ts.map +1 -0
- package/lib/src/core-hooks/index.js +3 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.d.ts +4 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/useClickOutside/useClickOutside.hook.js +46 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.d.ts +2 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/useDebounce/useDebounce.hook.js +30 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.d.ts +2 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.d.ts.map +1 -0
- package/lib/src/core-hooks/usePreventEKey/usePreventEKey.hook.js +8 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.d.ts +2 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.d.ts.map +1 -0
- package/lib/src/core-utils/convert/typography/camelCaseToTitleCase.util.js +5 -0
- package/lib/src/core-utils/index.d.ts +1 -0
- package/lib/src/core-utils/index.d.ts.map +1 -1
- package/lib/src/core-utils/index.js +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/lib/index.js
CHANGED
package/lib/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,wCAAwC,CAAC;AACvD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,sCAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClickOutside.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/useClickOutside/useClickOutside.hook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,eAAO,MAAM,eAAe,QAAS,GAAG,WAAW,GAAG,SAwBrD,CAAC;AAEF,eAAO,MAAM,2BAA2B,QACjC,MAAM,SAAS,CAAC,WAAW,CAAC,YACvB,MAAM,IAAI,SAkBrB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
export const useClickOutside = (ref, handler) => {
|
|
3
|
+
useEffect(() => {
|
|
4
|
+
let startedInside = false;
|
|
5
|
+
let startedWhenMounted = false;
|
|
6
|
+
const listener = (event) => {
|
|
7
|
+
// Do nothing if `mousedown` or `touchstart` started inside ref element
|
|
8
|
+
if (startedInside || !startedWhenMounted)
|
|
9
|
+
return;
|
|
10
|
+
// Do nothing if clicking ref's element or descendent elements
|
|
11
|
+
if (!ref.current || ref.current.contains(event.target))
|
|
12
|
+
return;
|
|
13
|
+
handler(event);
|
|
14
|
+
};
|
|
15
|
+
const validateEventStart = (event) => {
|
|
16
|
+
startedWhenMounted = ref.current;
|
|
17
|
+
startedInside = ref.current && ref.current.contains(event.target);
|
|
18
|
+
};
|
|
19
|
+
document.addEventListener('mousedown', validateEventStart);
|
|
20
|
+
document.addEventListener('touchstart', validateEventStart);
|
|
21
|
+
document.addEventListener('click', listener);
|
|
22
|
+
return () => {
|
|
23
|
+
document.removeEventListener('mousedown', validateEventStart);
|
|
24
|
+
document.removeEventListener('touchstart', validateEventStart);
|
|
25
|
+
document.removeEventListener('click', listener);
|
|
26
|
+
};
|
|
27
|
+
}, [ref, handler]);
|
|
28
|
+
};
|
|
29
|
+
export const useClickOutsideWithoutInput = (ref, callback) => {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const handleClickOutside = (event) => {
|
|
32
|
+
// Check if the target is an input element
|
|
33
|
+
if (event.target.tagName === 'INPUT') {
|
|
34
|
+
return; // Skip calling the callback if the target is an input
|
|
35
|
+
}
|
|
36
|
+
// Check if the click is outside the ref element
|
|
37
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
38
|
+
callback();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
44
|
+
};
|
|
45
|
+
}, [ref, callback]);
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/useDebounce/useDebounce.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,qBAAsB,GAAG,KAAK,IAAI,SAAS,MAAM,aAKpD,GAAG,SAyBvB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
export const useDebounce = (callback, delay) => {
|
|
3
|
+
const timeoutRef = useRef(null);
|
|
4
|
+
const debouncedCallback = useMemo(() => {
|
|
5
|
+
const debounce = (func, wait) => {
|
|
6
|
+
return (value) => {
|
|
7
|
+
if (timeoutRef.current) {
|
|
8
|
+
clearTimeout(timeoutRef.current);
|
|
9
|
+
}
|
|
10
|
+
timeoutRef.current = setTimeout(() => {
|
|
11
|
+
if (typeof func === 'function') {
|
|
12
|
+
func(value);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error('func is not a function');
|
|
16
|
+
}
|
|
17
|
+
}, wait);
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
return debounce(callback, delay);
|
|
21
|
+
}, [callback, delay]);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
return () => {
|
|
24
|
+
if (timeoutRef.current) {
|
|
25
|
+
clearTimeout(timeoutRef.current);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
return debouncedCallback;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreventEKey.hook.d.ts","sourceRoot":"","sources":["../../../../src/core-hooks/usePreventEKey/usePreventEKey.hook.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,YACF,mBAAmB,CAAC,gBAAgB,CAAC,SAK7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camelCaseToTitleCase.util.d.ts","sourceRoot":"","sources":["../../../../../src/core-utils/convert/typography/camelCaseToTitleCase.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QAAS,MAAM,WAI/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core-utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yCAAyC,CAAC;AACxD,cAAc,gDAAgD,CAAC"}
|