@mysetup/hooks 1.0.0
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +23 -0
- package/dist/src/useBreakpoint/index.d.ts +2 -0
- package/dist/src/useBreakpoint/index.d.ts.map +1 -0
- package/dist/src/useBreakpoint/index.js +17 -0
- package/dist/src/useBreakpoint/useBreakpoint.d.ts +2 -0
- package/dist/src/useBreakpoint/useBreakpoint.d.ts.map +1 -0
- package/dist/src/useBreakpoint/useBreakpoint.js +41 -0
- package/dist/src/useDebounce/index.d.ts +2 -0
- package/dist/src/useDebounce/index.d.ts.map +1 -0
- package/dist/src/useDebounce/index.js +17 -0
- package/dist/src/useDebounce/useDebounce.d.ts +2 -0
- package/dist/src/useDebounce/useDebounce.d.ts.map +1 -0
- package/dist/src/useDebounce/useDebounce.js +16 -0
- package/dist/src/useForm/helpers.d.ts +12 -0
- package/dist/src/useForm/helpers.d.ts.map +1 -0
- package/dist/src/useForm/helpers.js +84 -0
- package/dist/src/useForm/index.d.ts +3 -0
- package/dist/src/useForm/index.d.ts.map +1 -0
- package/dist/src/useForm/index.js +18 -0
- package/dist/src/useForm/rulesList.d.ts +3 -0
- package/dist/src/useForm/rulesList.d.ts.map +1 -0
- package/dist/src/useForm/rulesList.js +102 -0
- package/dist/src/useForm/types.d.ts +45 -0
- package/dist/src/useForm/types.d.ts.map +1 -0
- package/dist/src/useForm/types.js +15 -0
- package/dist/src/useForm/useForm.d.ts +28 -0
- package/dist/src/useForm/useForm.d.ts.map +1 -0
- package/dist/src/useForm/useForm.js +301 -0
- package/dist/src/useForm/useFormArray.d.ts +28 -0
- package/dist/src/useForm/useFormArray.d.ts.map +1 -0
- package/dist/src/useForm/useFormArray.js +329 -0
- package/dist/src/useFormatPhoneNumber/index.d.ts +2 -0
- package/dist/src/useFormatPhoneNumber/index.d.ts.map +1 -0
- package/dist/src/useFormatPhoneNumber/index.js +17 -0
- package/dist/src/useFormatPhoneNumber/useFormatPhoneNumber.d.ts +2 -0
- package/dist/src/useFormatPhoneNumber/useFormatPhoneNumber.d.ts.map +1 -0
- package/dist/src/useFormatPhoneNumber/useFormatPhoneNumber.js +18 -0
- package/dist/src/useIsBreakpoint/index.d.ts +2 -0
- package/dist/src/useIsBreakpoint/index.d.ts.map +1 -0
- package/dist/src/useIsBreakpoint/index.js +17 -0
- package/dist/src/useIsBreakpoint/useIsBreakpoint.d.ts +3 -0
- package/dist/src/useIsBreakpoint/useIsBreakpoint.d.ts.map +1 -0
- package/dist/src/useIsBreakpoint/useIsBreakpoint.js +15 -0
- package/dist/src/useModal/index.d.ts +2 -0
- package/dist/src/useModal/index.d.ts.map +1 -0
- package/dist/src/useModal/index.js +17 -0
- package/dist/src/useModal/useModal.d.ts +6 -0
- package/dist/src/useModal/useModal.d.ts.map +1 -0
- package/dist/src/useModal/useModal.js +19 -0
- package/dist/src/useTouchEndFix/index.d.ts +2 -0
- package/dist/src/useTouchEndFix/index.d.ts.map +1 -0
- package/dist/src/useTouchEndFix/index.js +17 -0
- package/dist/src/useTouchEndFix/useTouchEndFix.d.ts +2 -0
- package/dist/src/useTouchEndFix/useTouchEndFix.d.ts.map +1 -0
- package/dist/src/useTouchEndFix/useTouchEndFix.js +34 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.tsx"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./useBreakpoint";
|
|
2
|
+
export * from "./useDebounce";
|
|
3
|
+
export * from "./useForm";
|
|
4
|
+
export * from "./useFormatPhoneNumber";
|
|
5
|
+
export * from "./useIsBreakpoint";
|
|
6
|
+
export * from "./useModal";
|
|
7
|
+
export * from "./useTouchEndFix";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useBreakpoint"), exports);
|
|
18
|
+
__exportStar(require("./useDebounce"), exports);
|
|
19
|
+
__exportStar(require("./useForm"), exports);
|
|
20
|
+
__exportStar(require("./useFormatPhoneNumber"), exports);
|
|
21
|
+
__exportStar(require("./useIsBreakpoint"), exports);
|
|
22
|
+
__exportStar(require("./useModal"), exports);
|
|
23
|
+
__exportStar(require("./useTouchEndFix"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/useBreakpoint/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useBreakpoint"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBreakpoint.d.ts","sourceRoot":"","sources":["../../../src/useBreakpoint/useBreakpoint.tsx"],"names":[],"mappings":"AAQA,eAAO,MAAM,aAAa,0BAoCzB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBreakpoint = void 0;
|
|
4
|
+
var types_1 = require("@mysetup/types");
|
|
5
|
+
var react_1 = require("react");
|
|
6
|
+
var useBreakpoint = function () {
|
|
7
|
+
var _a = (0, react_1.useState)(), breakpoint = _a[0], setBreakpoint = _a[1];
|
|
8
|
+
var _b = (0, react_1.useState)({
|
|
9
|
+
width: undefined,
|
|
10
|
+
height: undefined,
|
|
11
|
+
}), windowSize = _b[0], setWindowSize = _b[1];
|
|
12
|
+
var handleResize = (0, react_1.useCallback)(function () {
|
|
13
|
+
setWindowSize({
|
|
14
|
+
width: window.innerWidth,
|
|
15
|
+
height: window.innerHeight,
|
|
16
|
+
});
|
|
17
|
+
if (windowSize.width) {
|
|
18
|
+
if (windowSize.width < types_1.BreakpointSize.md) {
|
|
19
|
+
setBreakpoint(types_1.Breakpoint.Small);
|
|
20
|
+
}
|
|
21
|
+
else if (windowSize.width < types_1.BreakpointSize.lg) {
|
|
22
|
+
setBreakpoint(types_1.Breakpoint.Medium);
|
|
23
|
+
}
|
|
24
|
+
else if (windowSize.width < types_1.BreakpointSize.xl) {
|
|
25
|
+
setBreakpoint(types_1.Breakpoint.Large);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
setBreakpoint(types_1.Breakpoint.XLarge);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}, [windowSize.width]);
|
|
32
|
+
(0, react_1.useEffect)(function () {
|
|
33
|
+
handleResize();
|
|
34
|
+
window.addEventListener("resize", handleResize);
|
|
35
|
+
return function () {
|
|
36
|
+
window.removeEventListener("resize", handleResize);
|
|
37
|
+
};
|
|
38
|
+
}, [handleResize]);
|
|
39
|
+
return breakpoint;
|
|
40
|
+
};
|
|
41
|
+
exports.useBreakpoint = useBreakpoint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/useDebounce/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useDebounce"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounce.d.ts","sourceRoot":"","sources":["../../../src/useDebounce/useDebounce.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,CAAC,CAc1D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDebounce = useDebounce;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
function useDebounce(value, delay) {
|
|
6
|
+
var _a = (0, react_1.useState)(value), debouncedValue = _a[0], setDebouncedValue = _a[1];
|
|
7
|
+
(0, react_1.useEffect)(function () {
|
|
8
|
+
var timer = setTimeout(function () {
|
|
9
|
+
setDebouncedValue(value);
|
|
10
|
+
}, delay !== null && delay !== void 0 ? delay : 500);
|
|
11
|
+
return function () {
|
|
12
|
+
clearTimeout(timer);
|
|
13
|
+
};
|
|
14
|
+
}, [value, delay]);
|
|
15
|
+
return debouncedValue;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type AlertState } from "@mysetup/types";
|
|
2
|
+
import type { RuleInfo, RuleName, Validations } from "./types";
|
|
3
|
+
export declare const message: <T extends Record<keyof T, unknown> = object>(rule: RuleName, field: keyof T, rulesList: Record<RuleName, RuleInfo>, validations: Validations<T>) => string;
|
|
4
|
+
export declare const humanizeFieldName: (field: string) => string;
|
|
5
|
+
export declare const valueOrEmptyString: (value: unknown) => {};
|
|
6
|
+
export declare const size: (val: string, type: unknown) => number;
|
|
7
|
+
export declare const sizeText: (type: unknown) => "" | " characters" | " elements";
|
|
8
|
+
export declare const isBlank: (value: unknown) => boolean;
|
|
9
|
+
export declare const testRegex: (value: string, regex: string | RegExp) => boolean;
|
|
10
|
+
export declare const getValidationClass: (value?: AlertState, customClass?: string[]) => string[] | undefined;
|
|
11
|
+
export declare const getValidationMessage: (value?: AlertState) => import("react").JSX.Element;
|
|
12
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/useForm/helpers.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAChD,QAAQ,SACP,MAAM,CAAC,aACH,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,eACxB,WAAW,CAAC,CAAC,CAAC,WA4B9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,MAAM,WAO9C,CAAC;AAEF,eAAO,MAAM,kBAAkB,UAAW,OAAO,OAEhD,CAAC;AAEF,eAAO,MAAM,IAAI,QAAS,MAAM,QAAQ,OAAO,WAQ9C,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAU,OAAO,qCAOrC,CAAC;AAEF,eAAO,MAAM,OAAO,UAAW,OAAO,YAMrC,CAAC;AAEF,eAAO,MAAM,SAAS,UAAW,MAAM,SAAS,MAAM,GAAG,MAAM,YAE9D,CAAC;AAEF,eAAO,MAAM,kBAAkB,WACnB,UAAU,gBACJ,MAAM,EAAE,yBAGzB,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAY,UAAU,gCAYtD,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValidationMessage = exports.getValidationClass = exports.testRegex = exports.isBlank = exports.sizeText = exports.size = exports.valueOrEmptyString = exports.humanizeFieldName = exports.message = void 0;
|
|
4
|
+
var classnames_1 = require("@mysetup/classnames");
|
|
5
|
+
var types_1 = require("./types");
|
|
6
|
+
var message = function (rule, field, rulesList, validations) {
|
|
7
|
+
var _a;
|
|
8
|
+
var messageString = "";
|
|
9
|
+
var customMessages = (_a = validations[field]) === null || _a === void 0 ? void 0 : _a.customMessages;
|
|
10
|
+
if (customMessages) {
|
|
11
|
+
if (Object.prototype.hasOwnProperty.call(customMessages, rule)) {
|
|
12
|
+
var ruleMessage = customMessages[rule]
|
|
13
|
+
? String(customMessages[rule])
|
|
14
|
+
: "";
|
|
15
|
+
messageString = "".concat(ruleMessage, ".");
|
|
16
|
+
}
|
|
17
|
+
else if (Object.prototype.hasOwnProperty.call(customMessages, "others") &&
|
|
18
|
+
rule !== "required") {
|
|
19
|
+
var ruleMessage = customMessages.others
|
|
20
|
+
? String(customMessages.others)
|
|
21
|
+
: "";
|
|
22
|
+
messageString = "".concat(ruleMessage, ".");
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
messageString = rulesList[rule].message;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
messageString = rulesList[rule].message;
|
|
30
|
+
}
|
|
31
|
+
return messageString.replace(":attribute", (0, exports.humanizeFieldName)(String(field)));
|
|
32
|
+
};
|
|
33
|
+
exports.message = message;
|
|
34
|
+
var humanizeFieldName = function (field) {
|
|
35
|
+
// supports snake_case or camelCase
|
|
36
|
+
var regex = /(?:[a-z0-9])(?:[A-Z])/g;
|
|
37
|
+
var fieldName = field.replace(regex, "$1 $2").replace(/_/g, " ");
|
|
38
|
+
return (String(fieldName.charAt(0).toUpperCase()) + String(fieldName.slice(1)));
|
|
39
|
+
};
|
|
40
|
+
exports.humanizeFieldName = humanizeFieldName;
|
|
41
|
+
var valueOrEmptyString = function (value) {
|
|
42
|
+
return typeof value === "undefined" || value === null ? "" : value;
|
|
43
|
+
};
|
|
44
|
+
exports.valueOrEmptyString = valueOrEmptyString;
|
|
45
|
+
var size = function (val, type) {
|
|
46
|
+
// if an array or string get the length, else return the value.
|
|
47
|
+
if (type === "string" || type === undefined || type === "array") {
|
|
48
|
+
return val.length;
|
|
49
|
+
}
|
|
50
|
+
else if (type === "num") {
|
|
51
|
+
return parseFloat(val);
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
};
|
|
55
|
+
exports.size = size;
|
|
56
|
+
var sizeText = function (type) {
|
|
57
|
+
if (type === "string" || type === undefined) {
|
|
58
|
+
return " characters";
|
|
59
|
+
}
|
|
60
|
+
else if (type === "array") {
|
|
61
|
+
return " elements";
|
|
62
|
+
}
|
|
63
|
+
return "";
|
|
64
|
+
};
|
|
65
|
+
exports.sizeText = sizeText;
|
|
66
|
+
var isBlank = function (value) {
|
|
67
|
+
return (typeof value === "undefined" ||
|
|
68
|
+
value === null ||
|
|
69
|
+
(0, exports.testRegex)(value, /^\s*$/));
|
|
70
|
+
};
|
|
71
|
+
exports.isBlank = isBlank;
|
|
72
|
+
var testRegex = function (value, regex) {
|
|
73
|
+
return value.toString().match(regex) !== null;
|
|
74
|
+
};
|
|
75
|
+
exports.testRegex = testRegex;
|
|
76
|
+
var getValidationClass = function (value, customClass) {
|
|
77
|
+
return value ? [types_1.stateInputClassesManditory[value.type]] : customClass;
|
|
78
|
+
};
|
|
79
|
+
exports.getValidationClass = getValidationClass;
|
|
80
|
+
var getValidationMessage = function (value) {
|
|
81
|
+
var messageClasses = (0, classnames_1.classNames)("mt-1 text-[10px] leading-[18px]", value && types_1.stateMessageClasses[value.type]);
|
|
82
|
+
return (React.createElement(React.Fragment, null, value ? (React.createElement("div", { className: messageClasses }, value.message)) : null));
|
|
83
|
+
};
|
|
84
|
+
exports.getValidationMessage = getValidationMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/useForm/index.tsx"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useForm"), exports);
|
|
18
|
+
__exportStar(require("./useFormArray"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rulesList.d.ts","sourceRoot":"","sources":["../../../src/useForm/rulesList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CA8FhD,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rulesList = void 0;
|
|
4
|
+
var helpers_1 = require("./helpers");
|
|
5
|
+
exports.rulesList = {
|
|
6
|
+
alpha: {
|
|
7
|
+
message: "The :attribute may only contain letters.",
|
|
8
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z]*$/i); },
|
|
9
|
+
},
|
|
10
|
+
alpha_space: {
|
|
11
|
+
message: "The :attribute may only contain letters and spaces.",
|
|
12
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z\s]*$/i); },
|
|
13
|
+
},
|
|
14
|
+
alpha_dash_space: {
|
|
15
|
+
message: "The :attribute may only contain letters, spaces, and dashes.",
|
|
16
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z-\s]*$/i); },
|
|
17
|
+
},
|
|
18
|
+
alpha_num_space: {
|
|
19
|
+
message: "The :attribute may only contain letters, numbers, and spaces.",
|
|
20
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z0-9\s]*$/i); },
|
|
21
|
+
},
|
|
22
|
+
alpha_num_dash: {
|
|
23
|
+
message: "The :attribute may only contain letters, numbers, and dashes.",
|
|
24
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z0-9_-]*$/i); },
|
|
25
|
+
},
|
|
26
|
+
alpha_num_dash_space: {
|
|
27
|
+
message: "The :attribute may only contain letters, numbers, dashes, and spaces.",
|
|
28
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z0-9_-\s]*$/i); },
|
|
29
|
+
},
|
|
30
|
+
alpha_num_no_special: {
|
|
31
|
+
message: "The :attribute may only contain letters, numbers, dashes, commas, periods and spaces.",
|
|
32
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^[A-Z0-9\s.,'-]*$/i); },
|
|
33
|
+
},
|
|
34
|
+
email: {
|
|
35
|
+
message: "The :attribute must be a isValid email address.",
|
|
36
|
+
rule: function (val) {
|
|
37
|
+
return (0, helpers_1.testRegex)(val, /^[A-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
match: {
|
|
41
|
+
message: "Given :attribute does not match",
|
|
42
|
+
rule: function (val, params) {
|
|
43
|
+
if (params === void 0) { params = []; }
|
|
44
|
+
return val === params[0];
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
min: {
|
|
48
|
+
message: "The :attribute must be at least :min:type.",
|
|
49
|
+
rule: function (val, params) {
|
|
50
|
+
if (params === void 0) { params = []; }
|
|
51
|
+
return (0, helpers_1.size)(val, params[1]) >= parseFloat(params[0]);
|
|
52
|
+
},
|
|
53
|
+
messageReplace: function (messageString, params) {
|
|
54
|
+
return messageString
|
|
55
|
+
.replace(":min", params[0])
|
|
56
|
+
.replace(":type", (0, helpers_1.sizeText)(params[1]));
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
max: {
|
|
60
|
+
message: "The :attribute may not be greater than :max:type.",
|
|
61
|
+
rule: function (val, params) {
|
|
62
|
+
if (params === void 0) { params = []; }
|
|
63
|
+
return (0, helpers_1.size)(val, params[1]) <= parseFloat(params[0]);
|
|
64
|
+
},
|
|
65
|
+
messageReplace: function (messageString, params) {
|
|
66
|
+
return messageString
|
|
67
|
+
.replace(":max", params[0])
|
|
68
|
+
.replace(":type", (0, helpers_1.sizeText)(params[1]));
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
not_same: {
|
|
72
|
+
message: "The :attribute is invalid.",
|
|
73
|
+
rule: function (val) {
|
|
74
|
+
return val.length > 1
|
|
75
|
+
? !val.split("").every(function (char) { return char === val[0]; })
|
|
76
|
+
: true;
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
not_only_number: {
|
|
80
|
+
message: "The :attribute must not contains number only.",
|
|
81
|
+
rule: function (val) { return !(0, helpers_1.testRegex)(val, /^\d*$/i); },
|
|
82
|
+
},
|
|
83
|
+
num: {
|
|
84
|
+
message: "Your :attribute must be a number.",
|
|
85
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^\d*$/i); },
|
|
86
|
+
},
|
|
87
|
+
phone: {
|
|
88
|
+
message: "The :attribute must be a valid phone number.",
|
|
89
|
+
rule: function (val) {
|
|
90
|
+
return (0, helpers_1.testRegex)(val, /^(?:\(\d{3}\) \d{3}-\d{4}|\d{10})$/);
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
required: {
|
|
94
|
+
message: "The :attribute field is required.",
|
|
95
|
+
rule: function (val) { return !(0, helpers_1.isBlank)(val); },
|
|
96
|
+
required: true,
|
|
97
|
+
},
|
|
98
|
+
zipcode: {
|
|
99
|
+
message: "Invalid Zip Code.",
|
|
100
|
+
rule: function (val) { return (0, helpers_1.testRegex)(val, /^\d{5}(?:-\d{4})?$/); },
|
|
101
|
+
},
|
|
102
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type AlertType } from "@mysetup/types";
|
|
2
|
+
export interface CustomMessages {
|
|
3
|
+
alpha?: string;
|
|
4
|
+
alpha_space?: string;
|
|
5
|
+
alpha_dash_space?: string;
|
|
6
|
+
alpha_num_space?: string;
|
|
7
|
+
alpha_num_dash?: string;
|
|
8
|
+
alpha_num_dash_space?: string;
|
|
9
|
+
alpha_num_no_special?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
match?: string;
|
|
12
|
+
min?: string;
|
|
13
|
+
max?: string;
|
|
14
|
+
not_same?: string;
|
|
15
|
+
not_only_number?: string;
|
|
16
|
+
num?: string;
|
|
17
|
+
phone?: string;
|
|
18
|
+
required?: string;
|
|
19
|
+
zipcode?: string;
|
|
20
|
+
others?: string;
|
|
21
|
+
}
|
|
22
|
+
export type Validation<T extends object> = {
|
|
23
|
+
rules: string[];
|
|
24
|
+
customMessages?: CustomMessages;
|
|
25
|
+
customValidation?: never;
|
|
26
|
+
} | {
|
|
27
|
+
rules?: string[];
|
|
28
|
+
customMessages?: CustomMessages;
|
|
29
|
+
customValidation: (value: unknown, formData: T) => {
|
|
30
|
+
isValid: boolean;
|
|
31
|
+
message: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type RuleName = "alpha" | "alpha_space" | "alpha_dash_space" | "alpha_num_space" | "alpha_num_dash" | "alpha_num_dash_space" | "alpha_num_no_special" | "email" | "match" | "min" | "max" | "not_same" | "not_only_number" | "num" | "phone" | "required" | "zipcode";
|
|
35
|
+
export type FormValue = string | string[] | boolean | number | bigint | null;
|
|
36
|
+
export interface RuleInfo {
|
|
37
|
+
rule: (val: string, params?: string[]) => boolean;
|
|
38
|
+
message: string;
|
|
39
|
+
messageReplace?: (messageString: string, params: string[]) => string;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export type Validations<T extends object> = Partial<Record<keyof T, Validation<T>>>;
|
|
43
|
+
export declare const stateInputClassesManditory: Record<AlertType, string>;
|
|
44
|
+
export declare const stateMessageClasses: Record<AlertType, string>;
|
|
45
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/useForm/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IACjC;IACI,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,gBAAgB,CAAC,EAAE,KAAK,CAAC;CAC5B,GACD;IACI,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,gBAAgB,EAAE,CACd,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,CAAC,KACV;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACnB,CAAC;CACL,CAAC;AAER,MAAM,MAAM,QAAQ,GACd,OAAO,GACP,aAAa,GACb,kBAAkB,GAClB,iBAAiB,GACjB,gBAAgB,GAChB,sBAAsB,GACtB,sBAAsB,GACtB,OAAO,GACP,OAAO,GACP,KAAK,GACL,KAAK,GACL,UAAU,GACV,iBAAiB,GACjB,KAAK,GACL,OAAO,GACP,UAAU,GACV,SAAS,CAAC;AAEhB,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7E,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IACrE,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAC/C,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CACjC,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAKhE,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAKzD,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stateMessageClasses = exports.stateInputClassesManditory = void 0;
|
|
4
|
+
exports.stateInputClassesManditory = {
|
|
5
|
+
error: "!border-error",
|
|
6
|
+
info: "!border-info",
|
|
7
|
+
success: "!border-success",
|
|
8
|
+
warning: "!border-warning",
|
|
9
|
+
};
|
|
10
|
+
exports.stateMessageClasses = {
|
|
11
|
+
error: "text-error",
|
|
12
|
+
info: "text-info",
|
|
13
|
+
success: "text-success",
|
|
14
|
+
warning: "text-warning",
|
|
15
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FormEvent } from "react";
|
|
2
|
+
import type { AlertState } from "@mysetup/types";
|
|
3
|
+
import type { FormValue, Validations } from "./types";
|
|
4
|
+
export declare const useForm: <T extends Record<keyof T, unknown> = object>(options?: {
|
|
5
|
+
validations: Validations<T>;
|
|
6
|
+
initialValues?: Partial<T>;
|
|
7
|
+
onReset?: () => void;
|
|
8
|
+
onSubmit?: () => void;
|
|
9
|
+
}) => {
|
|
10
|
+
addInputHandlers: (name: keyof T) => {
|
|
11
|
+
onBlur: () => void;
|
|
12
|
+
onChange: (value: FormValue) => void;
|
|
13
|
+
onFocus: () => void;
|
|
14
|
+
state: Partial<Record<keyof T, AlertState>>[keyof T];
|
|
15
|
+
value: T[keyof T];
|
|
16
|
+
name: keyof T;
|
|
17
|
+
};
|
|
18
|
+
clearError: (field: keyof T) => void;
|
|
19
|
+
data: T;
|
|
20
|
+
handleChange: (key: keyof T, value: FormValue, showError?: boolean) => void;
|
|
21
|
+
handleSubmit: (e?: FormEvent<HTMLFormElement>) => Promise<void>;
|
|
22
|
+
handleValidation: (key: keyof T, showError?: boolean) => void;
|
|
23
|
+
isSubmitted: boolean;
|
|
24
|
+
errors: Partial<Record<keyof T, AlertState>>;
|
|
25
|
+
passed: Partial<Record<keyof T, AlertState>>;
|
|
26
|
+
reset: (initialValues?: Partial<T>) => void;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../../src/useForm/useForm.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAY,WAAW,EAAE,MAAM,SAAS,CAAC;AAKhE,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,qBAAqB;IAC3E,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB;6BAmRmC,MAAM,CAAC;;0BAKb,SAAS;;;;;;;;wBA9Q1B,MAAM,CAAC,SACL,SAAS;uBAmIY,SAAS,CAAC,eAAe,CAAC;4BApH3B,MAAM,CAAC;;;;4BA0QP,OAAO,CAAC,CAAC,CAAC;CAsB5C,CAAC"}
|