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 CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './src/core-components';
2
2
  export * from './src/core-utils';
3
+ export * from './src/core-hooks';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -2,3 +2,4 @@
2
2
  // import './global.css';
3
3
  export * from './src/core-components';
4
4
  export * from './src/core-utils';
5
+ export * from './src/core-hooks';
package/lib/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-restyle-components",
3
- "version": "0.2.76",
3
+ "version": "0.2.78",
4
4
  "private": false,
5
5
  "description": "Easy use restyle components",
6
6
  "author": {
@@ -0,0 +1,4 @@
1
+ export * from './useClickOutside/useClickOutside.hook';
2
+ export * from './useDebounce/useDebounce.hook';
3
+ export * from './usePreventEKey/usePreventEKey.hook';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,3 @@
1
+ export * from './useClickOutside/useClickOutside.hook';
2
+ export * from './useDebounce/useDebounce.hook';
3
+ export * from './usePreventEKey/usePreventEKey.hook';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ export declare const useClickOutside: (ref: any, handler: any) => void;
3
+ export declare const useClickOutsideWithoutInput: (ref: React.RefObject<HTMLElement>, callback: () => void) => void;
4
+ //# sourceMappingURL=useClickOutside.hook.d.ts.map
@@ -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,2 @@
1
+ export declare const useDebounce: (callback: (value: any) => void, delay: number) => (value: any) => void;
2
+ //# sourceMappingURL=useDebounce.hook.d.ts.map
@@ -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,2 @@
1
+ export declare const usePreventEKey: () => (e: React.KeyboardEvent<HTMLInputElement>) => void;
2
+ //# sourceMappingURL=usePreventEKey.hook.d.ts.map
@@ -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,8 @@
1
+ import { useCallback } from 'react';
2
+ export const usePreventEKey = () => {
3
+ return useCallback((e) => {
4
+ if (e.key === 'e' || e.key === 'E') {
5
+ e.preventDefault();
6
+ }
7
+ }, []);
8
+ };
@@ -0,0 +1,2 @@
1
+ export declare const camelCaseToTitleCase: (str: string) => string;
2
+ //# sourceMappingURL=camelCaseToTitleCase.util.d.ts.map
@@ -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"}
@@ -0,0 +1,5 @@
1
+ export const camelCaseToTitleCase = (str) => {
2
+ return str
3
+ .replace(/([A-Z])/g, ' $1') // Add space before capital letters
4
+ .replace(/^./, (char) => char.toUpperCase()); // Capitalize the first letter
5
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './utility.util';
2
2
  export * from './calculation/calculation.util';
3
3
  export * from './convert/numberToWords/numToWords.util';
4
+ export * from './convert/typography/camelCaseToTitleCase.util';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -1,3 +1,4 @@
1
1
  export * from './utility.util';
2
2
  export * from './calculation/calculation.util';
3
3
  export * from './convert/numberToWords/numToWords.util';
4
+ export * from './convert/typography/camelCaseToTitleCase.util';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-restyle-components",
3
- "version": "0.2.77",
3
+ "version": "0.2.78",
4
4
  "private": false,
5
5
  "description": "Easy use restyle components",
6
6
  "author": {