react-restyle-components 0.2.77 → 0.2.79
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/colors/color.util.d.ts +2 -0
- package/lib/src/core-utils/colors/color.util.d.ts.map +1 -0
- package/lib/src/core-utils/colors/color.util.js +15 -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/form-helper/form-helper.util.d.ts +35 -0
- package/lib/src/core-utils/form-helper/form-helper.util.d.ts.map +1 -0
- package/lib/src/core-utils/form-helper/form-helper.util.js +82 -0
- package/lib/src/core-utils/index.d.ts +4 -0
- package/lib/src/core-utils/index.d.ts.map +1 -1
- package/lib/src/core-utils/index.js +4 -0
- package/lib/src/core-utils/uuid/uuid.util.d.ts +2 -0
- package/lib/src/core-utils/uuid/uuid.util.d.ts.map +1 -0
- package/lib/src/core-utils/uuid/uuid.util.js +8 -0
- package/lib/src/tc.module.css +2 -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":"color.util.d.ts","sourceRoot":"","sources":["../../../../src/core-utils/colors/color.util.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS,sCAgBrB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable unicorn/number-literal-case */
|
|
2
|
+
export const invertHex = (hexcolor) => {
|
|
3
|
+
// If a leading # is provided, remove it
|
|
4
|
+
if (hexcolor?.slice(0, 1) === '#') {
|
|
5
|
+
hexcolor = hexcolor?.slice(1);
|
|
6
|
+
}
|
|
7
|
+
// Convert to RGB value
|
|
8
|
+
const r = Number.parseInt(hexcolor?.slice(0, 2), 16);
|
|
9
|
+
const g = Number.parseInt(hexcolor?.slice(2, 4), 16);
|
|
10
|
+
const b = Number.parseInt(hexcolor?.slice(4, 6), 16);
|
|
11
|
+
// Get YIQ ratio
|
|
12
|
+
const yiq = (r * 299 + g * 587 + b * 114) / 1000;
|
|
13
|
+
// Check contrast
|
|
14
|
+
return yiq >= 128 ? 'black' : 'white';
|
|
15
|
+
};
|
|
@@ -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,35 @@
|
|
|
1
|
+
declare class FormHelper {
|
|
2
|
+
static patterns: {
|
|
3
|
+
email: RegExp;
|
|
4
|
+
emptySpace: RegExp;
|
|
5
|
+
emptyString: RegExp;
|
|
6
|
+
nonEmptyString: RegExp;
|
|
7
|
+
userName: RegExp;
|
|
8
|
+
password: RegExp;
|
|
9
|
+
mobileNo: RegExp;
|
|
10
|
+
panNumber: RegExp;
|
|
11
|
+
panNumberPartialMatch: RegExp;
|
|
12
|
+
aadhaarNumber: RegExp;
|
|
13
|
+
otp: RegExp;
|
|
14
|
+
};
|
|
15
|
+
static isUserNameValid(userName: string): boolean;
|
|
16
|
+
static isEmailValid(email: string): boolean;
|
|
17
|
+
static isAddressLengthInvalid(value: string): boolean;
|
|
18
|
+
static isAddressLength(value: string): boolean;
|
|
19
|
+
static addressNonEmpty(value: string): boolean;
|
|
20
|
+
static isAddressMoreLengthInvalid(value: string): boolean;
|
|
21
|
+
static isNameLengthInvalid(value: string): boolean;
|
|
22
|
+
static isPincodeLengthInvalid(value: string): boolean;
|
|
23
|
+
static isDateValid(date: string, month?: string, year?: string): boolean;
|
|
24
|
+
static isMobileNoValid(number: string): boolean;
|
|
25
|
+
static isMonthValid(month: string): boolean;
|
|
26
|
+
static isYearValid(year: string): boolean;
|
|
27
|
+
static isPasswordValid(password: string): boolean;
|
|
28
|
+
static isValidHeight(height?: string): boolean;
|
|
29
|
+
static isValidWeight(weight?: string): boolean;
|
|
30
|
+
static isNumberAvailable(val: string): boolean;
|
|
31
|
+
static isValidPAN(panNo: string, partial?: boolean): boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare const formHelperValidation: typeof FormHelper;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=form-helper.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-helper.util.d.ts","sourceRoot":"","sources":["../../../../src/core-utils/form-helper/form-helper.util.ts"],"names":[],"mappings":"AAAA,cAAM,UAAU;IACd,MAAM,CAAC,QAAQ;;;;;;;;;;;;MAab;IAEF,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIjD,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI3C,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIrD,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlD,MAAM,CAAC,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIrD,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAA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([A-Z]{3}P)|([A-Z]{0,3})$/,
|
|
12
|
+
aadhaarNumber: /^[2-9]{1}\d{3}\d{4}\d{4}$/,
|
|
13
|
+
otp: /\b\d{6}\b/,
|
|
14
|
+
};
|
|
15
|
+
static isUserNameValid(userName) {
|
|
16
|
+
return this.patterns.userName.test(userName);
|
|
17
|
+
}
|
|
18
|
+
static isEmailValid(email) {
|
|
19
|
+
return this.patterns.email.test(email);
|
|
20
|
+
}
|
|
21
|
+
static isAddressLengthInvalid(value) {
|
|
22
|
+
return value?.length < 3 || value?.length > 60;
|
|
23
|
+
}
|
|
24
|
+
static isAddressLength(value) {
|
|
25
|
+
return value?.length > 2;
|
|
26
|
+
}
|
|
27
|
+
static addressNonEmpty(value) {
|
|
28
|
+
return this.patterns.nonEmptyString.test(value);
|
|
29
|
+
}
|
|
30
|
+
static isAddressMoreLengthInvalid(value) {
|
|
31
|
+
return value?.length > 60;
|
|
32
|
+
}
|
|
33
|
+
static isNameLengthInvalid(value) {
|
|
34
|
+
return value?.length < 3 || value?.length > 30;
|
|
35
|
+
}
|
|
36
|
+
static isPincodeLengthInvalid(value) {
|
|
37
|
+
return value?.length < 5;
|
|
38
|
+
}
|
|
39
|
+
static isDateValid(date, month, year) {
|
|
40
|
+
if (!Number(month) || !Number(year)) {
|
|
41
|
+
return !!Number(date) && Number(date) <= 31;
|
|
42
|
+
}
|
|
43
|
+
const daysInMonth = new Date(Number(year), Number(month), 0).getDate();
|
|
44
|
+
return Number(date) <= daysInMonth;
|
|
45
|
+
}
|
|
46
|
+
static isMobileNoValid(number) {
|
|
47
|
+
return this.patterns.mobileNo.test(number);
|
|
48
|
+
}
|
|
49
|
+
static isMonthValid(month) {
|
|
50
|
+
return !!Number(month) && Number(month) <= 12;
|
|
51
|
+
}
|
|
52
|
+
static isYearValid(year) {
|
|
53
|
+
return !!Number(year) && year.length === 4;
|
|
54
|
+
}
|
|
55
|
+
static isPasswordValid(password) {
|
|
56
|
+
return this.patterns.password.test(password);
|
|
57
|
+
}
|
|
58
|
+
static isValidHeight(height) {
|
|
59
|
+
return !!Number(height) && Number(height) <= 214;
|
|
60
|
+
}
|
|
61
|
+
static isValidWeight(weight) {
|
|
62
|
+
return !!Number(weight) && Number(weight) <= 150;
|
|
63
|
+
}
|
|
64
|
+
static isNumberAvailable(val) {
|
|
65
|
+
const matches = val.match(/\d+/g);
|
|
66
|
+
if (val) {
|
|
67
|
+
if (matches != null)
|
|
68
|
+
return true;
|
|
69
|
+
else
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
static isValidPAN(panNo, partial = true) {
|
|
75
|
+
const pattern = partial
|
|
76
|
+
? this.patterns.panNumberPartialMatch
|
|
77
|
+
: this.patterns.panNumber;
|
|
78
|
+
const panNoMatch = `${panNo}`.trim().match(pattern);
|
|
79
|
+
return !!panNoMatch?.length && panNoMatch[0] === panNo;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export const formHelperValidation = FormHelper;
|
|
@@ -1,4 +1,8 @@
|
|
|
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';
|
|
5
|
+
export * from './colors/color.util';
|
|
6
|
+
export * from './uuid/uuid.util';
|
|
7
|
+
export * from './form-helper/form-helper.util';
|
|
4
8
|
//# 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;AAC/D,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gCAAgC,CAAC"}
|
|
@@ -1,3 +1,7 @@
|
|
|
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';
|
|
5
|
+
export * from './colors/color.util';
|
|
6
|
+
export * from './uuid/uuid.util';
|
|
7
|
+
export * from './form-helper/form-helper.util';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.util.d.ts","sourceRoot":"","sources":["../../../../src/core-utils/uuid/uuid.util.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,OAMjC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/* eslint-disable unicorn/prefer-math-trunc */
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
export function uuidv4(len) {
|
|
4
|
+
return _.repeat('x', len).replace(/[xy]/g, function (c) {
|
|
5
|
+
const r = (Math.random() * len) | 0, v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
6
|
+
return v.toString(len);
|
|
7
|
+
});
|
|
8
|
+
}
|
package/lib/src/tc.module.css
CHANGED