@devtron-labs/devtron-fe-common-lib 0.3.11 → 0.3.13

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 (38) hide show
  1. package/dist/Common/Constants.d.ts +1 -0
  2. package/dist/Common/CustomInput/CustomInput.d.ts +1 -1
  3. package/dist/Common/CustomInput/Types.d.ts +1 -1
  4. package/dist/Common/DeleteComponentModal/types.d.ts +4 -1
  5. package/dist/Common/Helper.d.ts +0 -6
  6. package/dist/Common/Tooltip/ShortcutKeyComboTooltipContent.d.ts +3 -0
  7. package/dist/Common/Tooltip/Tooltip.d.ts +1 -1
  8. package/dist/Common/Tooltip/index.d.ts +1 -0
  9. package/dist/Common/Tooltip/types.d.ts +39 -0
  10. package/dist/Shared/Components/Button/types.d.ts +1 -1
  11. package/dist/Shared/Components/CICDHistory/History.components.d.ts +54 -1
  12. package/dist/Shared/Components/CICDHistory/LogsRenderer.d.ts +55 -2
  13. package/dist/Shared/Components/CICDHistory/index.d.ts +1 -1
  14. package/dist/Shared/Components/CICDHistory/types.d.ts +11 -1
  15. package/dist/Shared/Hooks/index.d.ts +1 -0
  16. package/dist/Shared/Hooks/useForm/index.d.ts +2 -0
  17. package/dist/Shared/Hooks/useForm/useForm.d.ts +71 -0
  18. package/dist/Shared/Hooks/useForm/useForm.types.d.ts +69 -0
  19. package/dist/Shared/Hooks/useForm/useForm.utils.d.ts +10 -0
  20. package/dist/assets/index.css +1 -1
  21. package/dist/{cssMode-B8Y-xMip.js → cssMode-D469QiX9.js} +1 -1
  22. package/dist/{freemarker2-DOvVGj3n.js → freemarker2-DNt6wd9O.js} +1 -1
  23. package/dist/{handlebars-D0O-tcXK.js → handlebars-7qVNk6EF.js} +1 -1
  24. package/dist/{html-BOb6n13b.js → html-Ag7hvB8j.js} +1 -1
  25. package/dist/{htmlMode-CCC7xcDC.js → htmlMode-Bs_17ey3.js} +1 -1
  26. package/dist/{index-I7an8O5T.js → index-SVvTekb4.js} +22125 -22041
  27. package/dist/index.js +372 -371
  28. package/dist/{javascript-B4D0zI1U.js → javascript-DM1FHLQj.js} +1 -1
  29. package/dist/{jsonMode-r8WFzvFy.js → jsonMode-BVDYc4wj.js} +1 -1
  30. package/dist/{liquid-Y3VzcIfd.js → liquid-Bidob1Ke.js} +1 -1
  31. package/dist/{mdx-Bq7YcN5X.js → mdx-DdTKE1D9.js} +1 -1
  32. package/dist/{python-q8AEx_zc.js → python-CxoljM3K.js} +1 -1
  33. package/dist/{razor-tZ5gtNKf.js → razor-DaS8V23r.js} +1 -1
  34. package/dist/{tsMode-CUD3aBgM.js → tsMode-HBSoB7he.js} +1 -1
  35. package/dist/{typescript-B8bXuWP5.js → typescript-YKaAUYN6.js} +1 -1
  36. package/dist/{xml-C-_MvPzK.js → xml-Cnybjh9q.js} +1 -1
  37. package/dist/{yaml-C3JO3lKo.js → yaml-DPjLZMIY.js} +1 -1
  38. package/package.json +2 -1
@@ -286,3 +286,4 @@ export declare const VULNERABILITIES_SORT_PRIORITY: {
286
286
  low: number;
287
287
  unknown: number;
288
288
  };
289
+ export declare const IS_PLATFORM_MAC_OS: boolean;
@@ -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;
@@ -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,3 @@
1
+ import { TooltipProps } from './types';
2
+ declare const ShortcutKeyComboTooltipContent: ({ text, combo }: TooltipProps["shortcutKeyCombo"]) => JSX.Element;
3
+ export default ShortcutKeyComboTooltipContent;
@@ -1,3 +1,3 @@
1
1
  import { TooltipProps } from './types';
2
- declare const Tooltip: ({ alwaysShowTippyOnHover, showOnTruncate, wordBreak, children: child, ...rest }: TooltipProps) => JSX.Element;
2
+ declare const Tooltip: ({ shortcutKeyCombo, alwaysShowTippyOnHover, showOnTruncate, wordBreak, children: child, ...rest }: TooltipProps) => JSX.Element;
3
3
  export default Tooltip;
@@ -1,2 +1,3 @@
1
1
  export { default as Tooltip } from './Tooltip';
2
+ export type { SupportedKeyboardKeysType } from './types';
2
3
  export { TOOLTIP_CONTENTS } from './constants';
@@ -1,4 +1,11 @@
1
1
  import { TippyProps } from '@tippyjs/react';
2
+ export declare const KEYBOARD_KEYS_MAP: {
3
+ readonly Control: "⌘" | "Ctrl";
4
+ readonly Shift: "⇧";
5
+ readonly F: "F";
6
+ readonly E: "E";
7
+ };
8
+ export type SupportedKeyboardKeysType = keyof typeof KEYBOARD_KEYS_MAP;
2
9
  type BaseTooltipProps = {
3
10
  /**
4
11
  * If true, show tippy on truncate
@@ -10,6 +17,12 @@ type BaseTooltipProps = {
10
17
  * @default false
11
18
  */
12
19
  alwaysShowTippyOnHover?: never;
20
+ /**
21
+ * If true, use the common styling for shortcuts
22
+ * @default undefined
23
+ */
24
+ shortcutKeyCombo?: never;
25
+ content: TippyProps['content'];
13
26
  } | {
14
27
  /**
15
28
  * If alwaysShowTippyOnHover is defined this prop doesn't work
@@ -18,9 +31,35 @@ type BaseTooltipProps = {
18
31
  showOnTruncate?: never;
19
32
  /**
20
33
  * If true, wrap with tippy irrespective of other options
34
+ * @default true
35
+ */
36
+ alwaysShowTippyOnHover: boolean;
37
+ /**
38
+ * If true, use the common styling for shortcuts
39
+ * @default undefined
40
+ */
41
+ shortcutKeyCombo?: never;
42
+ content: TippyProps['content'];
43
+ } | {
44
+ /**
45
+ * If true, show tippy on truncate
46
+ * @default false
47
+ */
48
+ showOnTruncate?: never;
49
+ /**
50
+ * If showOnTruncate is defined this prop doesn't work
21
51
  * @default false
22
52
  */
23
53
  alwaysShowTippyOnHover?: boolean;
54
+ /**
55
+ * If true, use the common styling for shortcuts
56
+ * @default undefined
57
+ */
58
+ shortcutKeyCombo: {
59
+ text: string;
60
+ combo: SupportedKeyboardKeysType[];
61
+ };
62
+ content?: never;
24
63
  };
25
64
  export type TooltipProps = BaseTooltipProps & TippyProps & {
26
65
  /**
@@ -82,7 +82,7 @@ export type ButtonProps = ({
82
82
  /**
83
83
  * Props for tooltip
84
84
  */
85
- tooltipProps: Omit<TooltipProps, 'alwaysShowTippyOnHover' | 'showOnTruncate'>;
85
+ tooltipProps: Omit<TooltipProps, 'alwaysShowTippyOnHover' | 'showOnTruncate' | 'shortcutKeyCombo'> | (Omit<TooltipProps, 'alwaysShowTippyOnHover' | 'showOnTruncate' | 'content'> & Required<Pick<TooltipProps, 'shortcutKeyCombo'>>);
86
86
  } | {
87
87
  showTooltip?: never;
88
88
  tooltipProps?: never;
@@ -1,4 +1,57 @@
1
+ import { IWithShortcut } from 'react-keybind';
1
2
  import { GitChangesType, LogResizeButtonType, ScrollerType } from './types';
2
- export declare const LogResizeButton: ({ fullScreenView, setFullScreenView }: LogResizeButtonType) => JSX.Element;
3
+ export declare const LogResizeButton: {
4
+ new (props: Readonly<LogResizeButtonType & IWithShortcut>): {
5
+ render(): JSX.Element;
6
+ context: any;
7
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<LogResizeButtonType & IWithShortcut>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: (() => void) | undefined): void;
8
+ forceUpdate(callback?: (() => void) | undefined): void;
9
+ readonly props: Readonly<LogResizeButtonType & IWithShortcut> & Readonly<{
10
+ children?: import('react').ReactNode;
11
+ }>;
12
+ state: Readonly<{}>;
13
+ refs: {
14
+ [key: string]: import('react').ReactInstance;
15
+ };
16
+ componentDidMount?(): void;
17
+ shouldComponentUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): boolean;
18
+ componentWillUnmount?(): void;
19
+ componentDidCatch?(error: Error, errorInfo: import('react').ErrorInfo): void;
20
+ getSnapshotBeforeUpdate?(prevProps: Readonly<LogResizeButtonType & IWithShortcut>, prevState: Readonly<{}>): any;
21
+ componentDidUpdate?(prevProps: Readonly<LogResizeButtonType & IWithShortcut>, prevState: Readonly<{}>, snapshot?: any): void;
22
+ componentWillMount?(): void;
23
+ UNSAFE_componentWillMount?(): void;
24
+ componentWillReceiveProps?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextContext: any): void;
25
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextContext: any): void;
26
+ componentWillUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
27
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
28
+ };
29
+ new (props: LogResizeButtonType & IWithShortcut, context?: any): {
30
+ render(): JSX.Element;
31
+ context: any;
32
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<LogResizeButtonType & IWithShortcut>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: (() => void) | undefined): void;
33
+ forceUpdate(callback?: (() => void) | undefined): void;
34
+ readonly props: Readonly<LogResizeButtonType & IWithShortcut> & Readonly<{
35
+ children?: import('react').ReactNode;
36
+ }>;
37
+ state: Readonly<{}>;
38
+ refs: {
39
+ [key: string]: import('react').ReactInstance;
40
+ };
41
+ componentDidMount?(): void;
42
+ shouldComponentUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): boolean;
43
+ componentWillUnmount?(): void;
44
+ componentDidCatch?(error: Error, errorInfo: import('react').ErrorInfo): void;
45
+ getSnapshotBeforeUpdate?(prevProps: Readonly<LogResizeButtonType & IWithShortcut>, prevState: Readonly<{}>): any;
46
+ componentDidUpdate?(prevProps: Readonly<LogResizeButtonType & IWithShortcut>, prevState: Readonly<{}>, snapshot?: any): void;
47
+ componentWillMount?(): void;
48
+ UNSAFE_componentWillMount?(): void;
49
+ componentWillReceiveProps?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextContext: any): void;
50
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextContext: any): void;
51
+ componentWillUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
52
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<LogResizeButtonType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
53
+ };
54
+ contextType?: import('react').Context<any> | undefined;
55
+ };
3
56
  export declare const Scroller: ({ scrollToTop, scrollToBottom, style }: ScrollerType) => JSX.Element;
4
57
  export declare const GitChanges: ({ gitTriggers, ciMaterials, artifact, userApprovalMetadata, triggeredByEmail, ciPipelineId, artifactId, imageComment, imageReleaseTags, appReleaseTagNames, tagsEditable, hideImageTaggingHardDelete, appliedFilters, appliedFiltersTimestamp, promotionApprovalMetadata, selectedEnvironmentName, renderCIListHeader, }: GitChangesType) => JSX.Element;
@@ -1,3 +1,56 @@
1
+ import { IWithShortcut } from 'react-keybind';
1
2
  import { LogsRendererType } from './types';
2
- export declare const LogsRenderer: ({ triggerDetails, isBlobStorageConfigured, parentType, fullScreenView, }: LogsRendererType) => JSX.Element;
3
- export default LogsRenderer;
3
+ declare const _default: {
4
+ new (props: Readonly<LogsRendererType & IWithShortcut>): {
5
+ render(): JSX.Element;
6
+ context: any;
7
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<LogsRendererType & IWithShortcut>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: (() => void) | undefined): void;
8
+ forceUpdate(callback?: (() => void) | undefined): void;
9
+ readonly props: Readonly<LogsRendererType & IWithShortcut> & Readonly<{
10
+ children?: import('react').ReactNode;
11
+ }>;
12
+ state: Readonly<{}>;
13
+ refs: {
14
+ [key: string]: import('react').ReactInstance;
15
+ };
16
+ componentDidMount?(): void;
17
+ shouldComponentUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): boolean;
18
+ componentWillUnmount?(): void;
19
+ componentDidCatch?(error: Error, errorInfo: import('react').ErrorInfo): void;
20
+ getSnapshotBeforeUpdate?(prevProps: Readonly<LogsRendererType & IWithShortcut>, prevState: Readonly<{}>): any;
21
+ componentDidUpdate?(prevProps: Readonly<LogsRendererType & IWithShortcut>, prevState: Readonly<{}>, snapshot?: any): void;
22
+ componentWillMount?(): void;
23
+ UNSAFE_componentWillMount?(): void;
24
+ componentWillReceiveProps?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextContext: any): void;
25
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextContext: any): void;
26
+ componentWillUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
27
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
28
+ };
29
+ new (props: LogsRendererType & IWithShortcut, context?: any): {
30
+ render(): JSX.Element;
31
+ context: any;
32
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<LogsRendererType & IWithShortcut>) => {} | Pick<{}, K>) | Pick<{}, K>, callback?: (() => void) | undefined): void;
33
+ forceUpdate(callback?: (() => void) | undefined): void;
34
+ readonly props: Readonly<LogsRendererType & IWithShortcut> & Readonly<{
35
+ children?: import('react').ReactNode;
36
+ }>;
37
+ state: Readonly<{}>;
38
+ refs: {
39
+ [key: string]: import('react').ReactInstance;
40
+ };
41
+ componentDidMount?(): void;
42
+ shouldComponentUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): boolean;
43
+ componentWillUnmount?(): void;
44
+ componentDidCatch?(error: Error, errorInfo: import('react').ErrorInfo): void;
45
+ getSnapshotBeforeUpdate?(prevProps: Readonly<LogsRendererType & IWithShortcut>, prevState: Readonly<{}>): any;
46
+ componentDidUpdate?(prevProps: Readonly<LogsRendererType & IWithShortcut>, prevState: Readonly<{}>, snapshot?: any): void;
47
+ componentWillMount?(): void;
48
+ UNSAFE_componentWillMount?(): void;
49
+ componentWillReceiveProps?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextContext: any): void;
50
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextContext: any): void;
51
+ componentWillUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
52
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<LogsRendererType & IWithShortcut>, nextState: Readonly<{}>, nextContext: any): void;
53
+ };
54
+ contextType?: import('react').Context<any> | undefined;
55
+ };
56
+ export default _default;
@@ -10,7 +10,7 @@ export * from './service';
10
10
  export * from './History.components';
11
11
  export * from './utils';
12
12
  export * from './TriggerOutput';
13
- export * from './LogsRenderer';
13
+ export { default as LogsRenderer } from './LogsRenderer';
14
14
  export * from './DeploymentHistoryDiff';
15
15
  export * from './CiPipelineSourceConfig';
16
16
  export * from './StatusFilterButtonComponent';
@@ -1,5 +1,5 @@
1
1
  import { CSSProperties, ReactElement } from 'react';
2
- import { OptionType, UserApprovalMetadataType, ReleaseTag, ImageComment, PromotionApprovalMetadataType, FilterConditionsListType, DeploymentAppTypes, ResponseType, PaginationProps, useScrollable, SortingOrder } from '../../../Common';
2
+ import { OptionType, UserApprovalMetadataType, ReleaseTag, ImageComment, PromotionApprovalMetadataType, FilterConditionsListType, DeploymentAppTypes, ResponseType, PaginationProps, useScrollable, SortingOrder, SupportedKeyboardKeysType } from '../../../Common';
3
3
  import { DeploymentStageType } from '../../constants';
4
4
  import { AggregationKeys, GitTriggers, Node, NodeType, ResourceKindType, ResourceVersionType } from '../../types';
5
5
  export declare enum HistoryComponentType {
@@ -14,6 +14,16 @@ export declare enum FetchIdDataStatus {
14
14
  SUSPEND = "SUSPEND"
15
15
  }
16
16
  export interface LogResizeButtonType {
17
+ /**
18
+ * If given, that shortcut combo will be bound to the button
19
+ * @default null
20
+ */
21
+ shortcutCombo?: SupportedKeyboardKeysType[];
22
+ /**
23
+ * If true, only show the button when location.pathname contains '/logs'
24
+ * @default true
25
+ */
26
+ showOnlyWhenPathIncludesLogs?: boolean;
17
27
  fullScreenView: boolean;
18
28
  setFullScreenView: React.Dispatch<React.SetStateAction<boolean>>;
19
29
  }
@@ -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;