@devtron-labs/devtron-fe-common-lib 0.3.5-beta-1 → 0.3.5-beta-2

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.
Files changed (31) hide show
  1. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  2. package/dist/Common/CustomInput/Types.d.ts +1 -1
  3. package/dist/Common/DeleteComponentModal/types.d.ts +4 -1
  4. package/dist/Common/Drawer/Drawer.d.ts +1 -1
  5. package/dist/Common/Helper.d.ts +0 -6
  6. package/dist/Shared/Components/TabGroup/TabGroup.types.d.ts +1 -6
  7. package/dist/Shared/Components/TabGroup/TabGroup.utils.d.ts +0 -1
  8. package/dist/Shared/Hooks/index.d.ts +1 -0
  9. package/dist/Shared/Hooks/useForm/index.d.ts +2 -0
  10. package/dist/Shared/Hooks/useForm/useForm.d.ts +71 -0
  11. package/dist/Shared/Hooks/useForm/useForm.types.d.ts +69 -0
  12. package/dist/Shared/Hooks/useForm/useForm.utils.d.ts +10 -0
  13. package/dist/assets/index.css +1 -1
  14. package/dist/{cssMode-D66JTW_V.js → cssMode-uwn3xArb.js} +1 -1
  15. package/dist/{freemarker2-CY4JSAnd.js → freemarker2-CaMhuqPe.js} +1 -1
  16. package/dist/{handlebars-BdiSWeoR.js → handlebars-CTnClFcN.js} +1 -1
  17. package/dist/{html-Dox8CHQk.js → html-dSNw58aO.js} +1 -1
  18. package/dist/{htmlMode-DK5fOy44.js → htmlMode-YCmi4Oec.js} +1 -1
  19. package/dist/{index-BFMaIgeF.js → index-CQ_tnSZb.js} +16676 -16627
  20. package/dist/index.js +1 -1
  21. package/dist/{javascript-BENpilKz.js → javascript-BOjyNMQb.js} +1 -1
  22. package/dist/{jsonMode-CaV7ZBKe.js → jsonMode-Wch8DjET.js} +1 -1
  23. package/dist/{liquid-DXpc-UyL.js → liquid-yOyHP9Wm.js} +1 -1
  24. package/dist/{mdx-CTKVUr6n.js → mdx-CkdjZgHK.js} +1 -1
  25. package/dist/{python-Gh-QVJAm.js → python-CuKcH7j4.js} +1 -1
  26. package/dist/{razor-CRsts3uU.js → razor-CMkeVh_3.js} +1 -1
  27. package/dist/{tsMode-Be0FzPJg.js → tsMode-C6w4n8l9.js} +1 -1
  28. package/dist/{typescript-BYQLkHCK.js → typescript-isK37BH_.js} +1 -1
  29. package/dist/{xml-D4wjO4IJ.js → xml-BlWNjX_p.js} +1 -1
  30. package/dist/{yaml-Ck4Ls2ov.js → yaml-BFN6QLOY.js} +1 -1
  31. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
1
  import { CustomInputProps } from './Types';
2
- export declare const CustomInput: ({ name, value, error, onChange, onFocus, label, type, disabled, labelClassName, placeholder, tabIndex, dataTestid, isRequiredField, autoFocus, rootClassName, autoComplete, helperText, handleOnBlur, readOnly, noTrim, onKeyPress, defaultValue, onKeyDown, required, additionalErrorInfo, inputWrapClassName, inputProps, }: CustomInputProps) => JSX.Element;
2
+ export declare const CustomInput: ({ name, value, error, onChange, onFocus, label, type, disabled, labelClassName, placeholder, tabIndex, dataTestid, isRequiredField, autoFocus, rootClassName, autoComplete, helperText, onBlur, readOnly, noTrim, onKeyPress, defaultValue, onKeyDown, required, additionalErrorInfo, inputWrapClassName, inputProps, }: CustomInputProps) => JSX.Element;
@@ -17,7 +17,7 @@ export interface CustomInputProps {
17
17
  rootClassName?: string;
18
18
  error?: string[] | string;
19
19
  helperText?: ReactNode;
20
- handleOnBlur?: (e: any) => void;
20
+ onBlur?: (e: any) => void;
21
21
  readOnly?: boolean;
22
22
  noTrim?: boolean;
23
23
  onKeyPress?: (e: any) => void;
@@ -1,5 +1,8 @@
1
1
  export interface DeleteComponentProps {
2
- setDeleting: (boolean: any) => void;
2
+ /**
3
+ * @deprecated - Delete component internally handles loading for the `Delete Button`.
4
+ */
5
+ setDeleting?: (boolean: any) => void;
3
6
  toggleConfirmation: any;
4
7
  deleteComponent: (any: any) => Promise<any>;
5
8
  title: string;
@@ -10,5 +10,5 @@ interface drawerInterface {
10
10
  parentClassName?: string;
11
11
  onEscape?: (e?: any) => void;
12
12
  }
13
- export declare const Drawer: ({ children, position, height, width, minWidth, maxWidth, parentClassName, onEscape, onClose, }: drawerInterface) => JSX.Element;
13
+ export declare const Drawer: ({ children, position, height, width, minWidth, maxWidth, parentClassName, onEscape, }: drawerInterface) => JSX.Element;
14
14
  export {};
@@ -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;
@@ -51,11 +51,6 @@ export type TabProps = {
51
51
  * Text label for the tab.
52
52
  */
53
53
  label: string;
54
- /**
55
- * Description for the tab.
56
- * @note - If passed as a `string[]`, it will be rendered with a bullet in-between strings.
57
- */
58
- description?: string | string[];
59
54
  /**
60
55
  * Icon component to be displayed in the tab.
61
56
  * This should be a functional component that renders an SVG.
@@ -97,7 +92,7 @@ export interface TabGroupProps {
97
92
  * Size of the tabs.
98
93
  * @default ComponentSizeType.large
99
94
  */
100
- size?: ComponentSizeType.large | ComponentSizeType.medium | ComponentSizeType.xl;
95
+ size?: ComponentSizeType.large | ComponentSizeType.medium;
101
96
  /**
102
97
  * Optional component to be rendered on the right side of the tab list.
103
98
  */
@@ -5,4 +5,3 @@ export declare const getClassNameBySizeMap: ({ hideTopPadding, alignActiveBorder
5
5
  badgeClassName: string;
6
6
  }>;
7
7
  export declare const getIconColorClassMap: ({ active }: Pick<TabProps, "active">) => Record<TabProps["iconType"], string>;
8
- export declare const tabGroupClassMap: Record<TabGroupProps['size'], string>;
@@ -1,3 +1,4 @@
1
1
  export * from './UsePrompt';
2
2
  export * from './useGetResourceKindsOptions';
3
3
  export * from './UseDownload';
4
+ export * from './useForm';
@@ -0,0 +1,2 @@
1
+ export * from './useForm';
2
+ export * from './useForm.types';
@@ -0,0 +1,71 @@
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
+ * @param options - Optional configuration object for the form.
7
+ * @returns The form state and utility methods
8
+ */
9
+ export declare const useForm: <T extends Record<keyof T, any> = {}>(options?: {
10
+ /** An object containing validation rules for each form field. */
11
+ validations?: UseFormValidations<T>;
12
+ /** An object representing the initial values for the form fields. */
13
+ initialValues?: Partial<T>;
14
+ /** Defines when validation should occur:
15
+ * - 'onChange': Validation occurs when the user modifies the input
16
+ * - 'onBlur': Validation occurs when the input loses focus.
17
+ * @default 'onChange'
18
+ */
19
+ validationMode?: "onChange" | "onBlur";
20
+ }) => {
21
+ /** The current form data. */
22
+ data: T;
23
+ /** An object containing validation errors for each form field. */
24
+ errors: Partial<Record<keyof T, string | string[]>>;
25
+ /**
26
+ * Registers form input fields with onChange, onBlur and onFocus handlers.
27
+ *
28
+ * @param name - The key of the form field to register.
29
+ * @param sanitizeFn - An optional function to sanitize the input value.
30
+ * @returns An object containing form field `name`, `onChange`, `onBlur` and `onFocus` event handlers.
31
+ */
32
+ register: <V extends unknown = string, S extends unknown = unknown>(name: keyof T, sanitizeFn?: (value: V) => S, registerOptions?: {
33
+ /**
34
+ * Prevents the input value from being trimmed.
35
+ *
36
+ * If `noTrim` is set to true, the input value will not be automatically trimmed.\
37
+ * This can be useful when whitespace is required for certain inputs.
38
+ *
39
+ * @default false - By default, the input will be trimmed.
40
+ */
41
+ noTrim?: boolean;
42
+ }) => {
43
+ onChange: (e: ChangeEvent<HTMLInputElement>) => void;
44
+ onBlur: () => void;
45
+ onFocus: () => void;
46
+ name: keyof T;
47
+ };
48
+ /**
49
+ * Handles form submission, validates all form fields, and calls the provided `onValid` function if valid.
50
+ *
51
+ * @param onValid - A function to handle valid form data on submission.
52
+ * @returns The event handler for form submission.
53
+ */
54
+ handleSubmit: (onValid: UseFormSubmitHandler<T>) => (e: FormEvent<HTMLFormElement>) => void;
55
+ /**
56
+ * Manually triggers validation for specific form fields.
57
+ *
58
+ * @param name - The key(s) of the form field(s) to validate.
59
+ * @returns The validation error(s), if any.
60
+ */
61
+ trigger: (name: keyof T | (keyof T)[]) => (string | string[]) | (string | string[])[];
62
+ /** An object representing additional form state. */
63
+ formState: {
64
+ /** An object indicating which fields have been touched (interacted with). */
65
+ touchedFields: Partial<Record<keyof T, boolean>>;
66
+ /** An object indicating which fields have been modified. */
67
+ dirtyFields: Partial<Record<keyof T, boolean>>;
68
+ /** A boolean indicating if any field has been modified. */
69
+ isDirty: boolean;
70
+ };
71
+ };
@@ -0,0 +1,69 @@
1
+ import { FormEvent } from 'react';
2
+ /**
3
+ * Describes the "required" validation rule.
4
+ * It can be a simple boolean or an object containing a boolean value and an error message.
5
+ */
6
+ type ValidationRequired = boolean | {
7
+ value: boolean;
8
+ message: string;
9
+ };
10
+ /**
11
+ * Describes the "pattern" validation rule, which ensures a value matches a specific regular expression.
12
+ * It can be a single validation object or an array of multiple patterns.
13
+ */
14
+ type ValidationPattern = {
15
+ value: RegExp;
16
+ message: string;
17
+ } | {
18
+ value: RegExp;
19
+ message: string;
20
+ }[];
21
+ /**
22
+ * Describes custom validation logic.
23
+ * It checks if a value passes a custom validation function, which returns a boolean.
24
+ * If validation fails, an error message is provided.
25
+ */
26
+ type ValidationCustom = {
27
+ isValid: (value: string) => boolean;
28
+ message: string;
29
+ } | {
30
+ isValid: (value: string) => boolean;
31
+ message: string;
32
+ }[];
33
+ /**
34
+ * Defines the validation rules for form fields.
35
+ * Includes `required`, `pattern`, and `custom` validation types.
36
+ */
37
+ export interface UseFormValidation {
38
+ required?: ValidationRequired;
39
+ pattern?: ValidationPattern;
40
+ custom?: ValidationCustom;
41
+ }
42
+ /**
43
+ * Represents the structure for form validation errors.
44
+ * Maps each field to an error message or an array of error messages.
45
+ */
46
+ export type UseFormErrors<T> = Partial<Record<keyof T, string | string[]>>;
47
+ /**
48
+ * Represents the fields that have been modified ("dirty") in the form.
49
+ * Maps each field to a boolean value indicating whether it has been changed.
50
+ */
51
+ export type DirtyFields<T> = Partial<Record<keyof T, boolean>>;
52
+ /**
53
+ * Represents the fields that have been interacted with ("touched") in the form.
54
+ * Maps each field to a boolean value indicating whether it has been focused or interacted with.
55
+ */
56
+ export type TouchedFields<T> = Partial<Record<keyof T, boolean>>;
57
+ /**
58
+ * Defines the structure for form validations.
59
+ * Maps each form field to its corresponding validation rules.
60
+ */
61
+ export type UseFormValidations<T extends {}> = Partial<Record<keyof T, UseFormValidation>>;
62
+ /**
63
+ * Describes the function signature for handling form submission.
64
+ *
65
+ * @param data - The form data collected during submission.
66
+ * @param e - The form event, optionally passed when the form is submitted.
67
+ */
68
+ export type UseFormSubmitHandler<T extends {}> = (data: T, e?: FormEvent<HTMLFormElement>) => void;
69
+ 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;