@devtron-labs/devtron-fe-common-lib 0.3.1 → 0.3.2-beta-1
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/Common/Helper.d.ts +0 -6
- package/dist/Shared/Hooks/index.d.ts +1 -0
- package/dist/Shared/Hooks/useForm/index.d.ts +2 -0
- package/dist/Shared/Hooks/useForm/useForm.d.ts +29 -0
- package/dist/Shared/Hooks/useForm/useForm.types.d.ts +30 -0
- package/dist/Shared/Hooks/useForm/useForm.utils.d.ts +10 -0
- package/dist/{cssMode-V4gOdo97.js → cssMode-ImfOWSq8.js} +1 -1
- package/dist/{freemarker2-B3nU0rzE.js → freemarker2-BJ-2NO05.js} +1 -1
- package/dist/{handlebars-BS1jC8LD.js → handlebars-S1Dcde3S.js} +1 -1
- package/dist/{html-DlzH2FAN.js → html-bRe4LTd-.js} +1 -1
- package/dist/{htmlMode-CBGvlMrI.js → htmlMode-jC_3p_EM.js} +1 -1
- package/dist/{index-Dm6hBNN0.js → index-OXtj7T5P.js} +15834 -15806
- package/dist/index.js +1 -1
- package/dist/{javascript-CUndAAQ9.js → javascript-S39_Kd8d.js} +1 -1
- package/dist/{jsonMode-CGlEguOI.js → jsonMode-D07yabof.js} +1 -1
- package/dist/{liquid-BDv4HsxQ.js → liquid-D5VU8OXu.js} +1 -1
- package/dist/{mdx-BS8IMx8x.js → mdx-DULFR6p6.js} +1 -1
- package/dist/{python-BT_GZlwi.js → python-B48J-3tG.js} +1 -1
- package/dist/{razor-B_DFgIaZ.js → razor-CEmTA50y.js} +1 -1
- package/dist/{tsMode-C66_QUY9.js → tsMode-D6BCsW2e.js} +1 -1
- package/dist/{typescript-CqSw7Ghb.js → typescript-ChQA5UDJ.js} +1 -1
- package/dist/{xml-VSpcM9oj.js → xml-DnTl2a0T.js} +1 -1
- package/dist/{yaml-D8S0c-D4.js → yaml-Dg6m_Zyc.js} +1 -1
- package/package.json +1 -1
package/dist/Common/Helper.d.ts
CHANGED
|
@@ -22,12 +22,6 @@ export declare const refresh: () => void;
|
|
|
22
22
|
export declare const reportIssue: () => void;
|
|
23
23
|
export declare function useEffectAfterMount(cb: any, dependencies: any): void;
|
|
24
24
|
export declare function getCookie(sKey: any): string;
|
|
25
|
-
export declare function useForm(stateSchema: any, validationSchema: {}, callback: any): {
|
|
26
|
-
state: any;
|
|
27
|
-
disable: boolean;
|
|
28
|
-
handleOnChange: (event: any) => void;
|
|
29
|
-
handleOnSubmit: (event: any) => void;
|
|
30
|
-
};
|
|
31
25
|
export declare function handleUTCTime(ts: string, isRelativeTime?: boolean): string;
|
|
32
26
|
export declare function useSearchString(): UseSearchString;
|
|
33
27
|
export declare const closeOnEscKeyPressed: (e: any, actionClose: () => void) => void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ChangeEvent, FormEvent } from 'react';
|
|
2
|
+
import { UseFormSubmitHandler, UseFormValidations } from './useForm.types';
|
|
3
|
+
/**
|
|
4
|
+
* A custom hook to manage form state, validation, and submission handling.
|
|
5
|
+
*
|
|
6
|
+
* @template T - A record type representing form data.
|
|
7
|
+
* @param options (optional) - Options for initial form values, validation rules, and form mode.
|
|
8
|
+
* @param options.validations - An object containing validation rules for form fields.
|
|
9
|
+
* @param options.initialValues - An object representing the initial values of the form.
|
|
10
|
+
* @param options.mode (default: `onChange`) - A string to set validation mode, either 'onChange' or 'onBlur'.
|
|
11
|
+
* @returns Returns form state, handlers for change and submission, validation errors, and a trigger function for manual validation.
|
|
12
|
+
*/
|
|
13
|
+
export declare const useForm: <T extends Record<keyof T, any> = {}>(options?: {
|
|
14
|
+
validations?: UseFormValidations<T>;
|
|
15
|
+
initialValues?: Partial<T>;
|
|
16
|
+
mode?: "onChange" | "onBlur";
|
|
17
|
+
}) => {
|
|
18
|
+
data: T;
|
|
19
|
+
errors: Partial<Record<keyof T, string | string[]>>;
|
|
20
|
+
register: <S extends unknown>(name: keyof T, sanitizeFn?: (value: string) => S) => {
|
|
21
|
+
onChange: (e: ChangeEvent<HTMLInputElement & HTMLSelectElement>) => void;
|
|
22
|
+
onBlur: () => void;
|
|
23
|
+
};
|
|
24
|
+
handleSubmit: (onValid: UseFormSubmitHandler<T>) => (e: FormEvent<HTMLFormElement>) => void;
|
|
25
|
+
trigger: (name: keyof T | (keyof T)[]) => (string | string[]) | (string | string[])[];
|
|
26
|
+
touchedFields: Partial<Record<keyof T, boolean>>;
|
|
27
|
+
dirtyFields: Partial<Record<keyof T, boolean>>;
|
|
28
|
+
isDirty: boolean;
|
|
29
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FormEvent } from 'react';
|
|
2
|
+
type ValidationRequired = boolean | {
|
|
3
|
+
value: boolean;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
type ValidationPattern = {
|
|
7
|
+
value: RegExp;
|
|
8
|
+
message: string;
|
|
9
|
+
} | {
|
|
10
|
+
value: RegExp;
|
|
11
|
+
message: string;
|
|
12
|
+
}[];
|
|
13
|
+
type ValidationCustom = {
|
|
14
|
+
isValid: (value: string) => boolean;
|
|
15
|
+
message: string;
|
|
16
|
+
} | {
|
|
17
|
+
isValid: (value: string) => boolean;
|
|
18
|
+
message: string;
|
|
19
|
+
}[];
|
|
20
|
+
export interface UseFormValidation {
|
|
21
|
+
required?: ValidationRequired;
|
|
22
|
+
pattern?: ValidationPattern;
|
|
23
|
+
custom?: ValidationCustom;
|
|
24
|
+
}
|
|
25
|
+
export type UseFormErrors<T> = Partial<Record<keyof T, string | string[]>>;
|
|
26
|
+
export type DirtyFields<T> = Partial<Record<keyof T, boolean>>;
|
|
27
|
+
export type TouchedFields<T> = Partial<Record<keyof T, boolean>>;
|
|
28
|
+
export type UseFormValidations<T extends {}> = Partial<Record<keyof T, UseFormValidation>>;
|
|
29
|
+
export type UseFormSubmitHandler<T extends {}> = (data: T, e?: FormEvent<HTMLFormElement>) => void;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UseFormValidation } from './useForm.types';
|
|
2
|
+
/**
|
|
3
|
+
* Validates a form field based on the provided validation rules.
|
|
4
|
+
*
|
|
5
|
+
* @template T - A record type representing form data.
|
|
6
|
+
* @param value - The value of the form field to be validated.
|
|
7
|
+
* @param validation - The validation rules for the form field.
|
|
8
|
+
* @returns Returns error message(s) or null if valid.
|
|
9
|
+
*/
|
|
10
|
+
export declare const checkValidation: <T extends Record<keyof T, any> = {}>(value: T[keyof T], validation: UseFormValidation) => string | string[] | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Fe = Object.defineProperty;
|
|
2
2
|
var Le = (e, n, i) => n in e ? Fe(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
3
|
var k = (e, n, i) => Le(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
|
-
import { m as je } from "./index-
|
|
4
|
+
import { m as je } from "./index-OXtj7T5P.js";
|
|
5
5
|
/*!-----------------------------------------------------------------------------
|
|
6
6
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
7
|
* Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as f } from "./index-
|
|
1
|
+
import { m as f } from "./index-OXtj7T5P.js";
|
|
2
2
|
/*!-----------------------------------------------------------------------------
|
|
3
3
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
* Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as l } from "./index-
|
|
1
|
+
import { m as l } from "./index-OXtj7T5P.js";
|
|
2
2
|
/*!-----------------------------------------------------------------------------
|
|
3
3
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
* Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as s } from "./index-
|
|
1
|
+
import { m as s } from "./index-OXtj7T5P.js";
|
|
2
2
|
/*!-----------------------------------------------------------------------------
|
|
3
3
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
* Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Be = Object.defineProperty;
|
|
2
2
|
var $e = (e, n, i) => n in e ? Be(e, n, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[n] = i;
|
|
3
3
|
var k = (e, n, i) => $e(e, typeof n != "symbol" ? n + "" : n, i);
|
|
4
|
-
import { m as qe } from "./index-
|
|
4
|
+
import { m as qe } from "./index-OXtj7T5P.js";
|
|
5
5
|
/*!-----------------------------------------------------------------------------
|
|
6
6
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
7
|
* Version: 0.44.0(3e047efd345ff102c8c61b5398fb30845aaac166)
|