@devtron-labs/devtron-fe-common-lib 0.3.0 → 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/Components/Button/Button.component.d.ts +6 -1
- package/dist/Shared/Components/Button/constants.d.ts +3 -0
- package/dist/Shared/Components/Button/types.d.ts +29 -12
- package/dist/Shared/Components/Button/utils.d.ts +3 -1
- 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/assets/index.css +1 -1
- package/dist/{cssMode-gAMETjhs.js → cssMode-ImfOWSq8.js} +1 -1
- package/dist/{freemarker2-1LUPRZvK.js → freemarker2-BJ-2NO05.js} +1 -1
- package/dist/{handlebars-FFlW7wcF.js → handlebars-S1Dcde3S.js} +1 -1
- package/dist/{html-Bje_q8_h.js → html-bRe4LTd-.js} +1 -1
- package/dist/{htmlMode--Ajs2w0s.js → htmlMode-jC_3p_EM.js} +1 -1
- package/dist/{index-H6WWnur7.js → index-OXtj7T5P.js} +17212 -17143
- package/dist/index.js +1 -1
- package/dist/{javascript-DWqTbQ2W.js → javascript-S39_Kd8d.js} +1 -1
- package/dist/{jsonMode-hm7gyx36.js → jsonMode-D07yabof.js} +1 -1
- package/dist/{liquid-BgJmUwJB.js → liquid-D5VU8OXu.js} +1 -1
- package/dist/{mdx-B8aQgpZ8.js → mdx-DULFR6p6.js} +1 -1
- package/dist/{python-1rHBUaWD.js → python-B48J-3tG.js} +1 -1
- package/dist/{razor-DKD66wkm.js → razor-CEmTA50y.js} +1 -1
- package/dist/{tsMode-CzgxhWLn.js → tsMode-D6BCsW2e.js} +1 -1
- package/dist/{typescript-Bup97xWo.js → typescript-ChQA5UDJ.js} +1 -1
- package/dist/{xml-Lw75qqS-.js → xml-DnTl2a0T.js} +1 -1
- package/dist/{yaml-DXNYWuXp.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;
|
|
@@ -57,6 +57,11 @@ import { ButtonProps } from './types';
|
|
|
57
57
|
* ```tsx
|
|
58
58
|
* <Button component={ButtonComponentType.link} linkProps={{ to: '#' }} />
|
|
59
59
|
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Icon button
|
|
62
|
+
* ```tsx
|
|
63
|
+
* <Button icon={<ICCube />} ariaLabel="Label" />
|
|
64
|
+
* ```
|
|
60
65
|
*/
|
|
61
|
-
declare const Button: ({ dataTestId, text, variant, size, style, startIcon, endIcon, disabled, isLoading, showTooltip, tooltipProps, ...props }: ButtonProps) => JSX.Element;
|
|
66
|
+
declare const Button: ({ dataTestId, text, variant, size, style, startIcon, endIcon, disabled, isLoading, showTooltip, tooltipProps, icon, ariaLabel, ...props }: ButtonProps) => JSX.Element;
|
|
62
67
|
export default Button;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { ProgressingProps } from '../../../Common/Types';
|
|
2
2
|
import { ButtonProps } from './types';
|
|
3
3
|
export declare const BUTTON_SIZE_TO_CLASS_NAME_MAP: Record<ButtonProps['size'], string>;
|
|
4
|
+
export declare const ICON_BUTTON_SIZE_TO_CLASS_NAME_MAP: Record<ButtonProps['size'], string>;
|
|
4
5
|
export declare const BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP: Record<ButtonProps['size'], string>;
|
|
6
|
+
export declare const ICON_BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP: Record<ButtonProps['size'], string>;
|
|
5
7
|
export declare const BUTTON_SIZE_TO_LOADER_SIZE_MAP: Record<ButtonProps['size'], ProgressingProps['size']>;
|
|
8
|
+
export declare const ICON_BUTTON_SIZE_TO_LOADER_SIZE_MAP: Record<ButtonProps['size'], ProgressingProps['size']>;
|
|
@@ -11,6 +11,7 @@ export declare enum ButtonVariantType {
|
|
|
11
11
|
export declare enum ButtonStyleType {
|
|
12
12
|
default = "default",
|
|
13
13
|
negative = "negative",
|
|
14
|
+
negativeGrey = "negative-grey",
|
|
14
15
|
positive = "positive",
|
|
15
16
|
warning = "warning",
|
|
16
17
|
neutral = "neutral"
|
|
@@ -59,18 +60,6 @@ export type ButtonProps = ({
|
|
|
59
60
|
* @default ButtonStyleType.default
|
|
60
61
|
*/
|
|
61
62
|
style?: ButtonStyleType;
|
|
62
|
-
/**
|
|
63
|
-
* Text to be displayed in the button
|
|
64
|
-
*/
|
|
65
|
-
text: string;
|
|
66
|
-
/**
|
|
67
|
-
* If provided, icon to be displayed at the start of the button
|
|
68
|
-
*/
|
|
69
|
-
startIcon?: ReactElement;
|
|
70
|
-
/**
|
|
71
|
-
* If provided, icon to be displayed at the end of the button
|
|
72
|
-
*/
|
|
73
|
-
endIcon?: ReactElement;
|
|
74
63
|
/**
|
|
75
64
|
* If true, the loading state is shown for the button with disabled
|
|
76
65
|
*/
|
|
@@ -97,4 +86,32 @@ export type ButtonProps = ({
|
|
|
97
86
|
} | {
|
|
98
87
|
showTooltip?: never;
|
|
99
88
|
tooltipProps?: never;
|
|
89
|
+
}) & ({
|
|
90
|
+
icon?: never;
|
|
91
|
+
ariaLabel?: never;
|
|
92
|
+
/**
|
|
93
|
+
* Text to be displayed in the button
|
|
94
|
+
*/
|
|
95
|
+
text: string;
|
|
96
|
+
/**
|
|
97
|
+
* If provided, icon to be displayed at the start of the button
|
|
98
|
+
*/
|
|
99
|
+
startIcon?: ReactElement;
|
|
100
|
+
/**
|
|
101
|
+
* If provided, icon to be displayed at the end of the button
|
|
102
|
+
*/
|
|
103
|
+
endIcon?: ReactElement;
|
|
104
|
+
} | {
|
|
105
|
+
/**
|
|
106
|
+
* If provided, icon button is rendered
|
|
107
|
+
*/
|
|
108
|
+
icon: ReactElement;
|
|
109
|
+
/**
|
|
110
|
+
* Label for the icon button for accessibility.
|
|
111
|
+
* Shown on hover in tooltip if tippy is not provided explicitly
|
|
112
|
+
*/
|
|
113
|
+
ariaLabel: string;
|
|
114
|
+
text?: never;
|
|
115
|
+
startIcon?: never;
|
|
116
|
+
endIcon?: never;
|
|
100
117
|
});
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { ButtonProps } from './types';
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const getButtonIconClassName: ({ size, icon }: Pick<ButtonProps, "size" | "icon">) => string;
|
|
3
|
+
export declare const getButtonLoaderSize: ({ size, icon }: Pick<ButtonProps, "size" | "icon">) => number;
|
|
4
|
+
export declare const getButtonDerivedClass: ({ size, variant, style, isLoading, icon, }: Pick<ButtonProps, "variant" | "size" | "style" | "isLoading" | "icon">) => string;
|
|
@@ -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;
|