@ostack.tech/ui-kform 0.16.2 → 0.16.4
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/ostack-ui-kform.js +228 -123
- package/dist/ostack-ui-kform.js.map +1 -1
- package/package.json +2 -2
- package/types/components/PathLink/PathLink.d.ts +22 -1
- package/types/components/ResetOnChange/ResetOnChange.d.ts +40 -0
- package/types/components/ResetOnChange/ResetOnChangeContext.d.ts +7 -0
- package/types/components/ResetOnChange/index.d.ts +3 -0
- package/types/components/ResetOnChange/useResetOnChange.d.ts +96 -0
- package/types/components/TableControl/TableControlColumnFns.d.ts +5 -28
- package/types/components/TableControl/TableControlRemoveRowTrigger.d.ts +10 -20
- package/types/index.d.ts +1 -1
- package/types/utils/extractConfirmDialogOptions.d.ts +13 -0
- package/types/utils/useResetOnChange.d.ts +0 -98
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ostack.tech/ui-kform",
|
|
3
3
|
"description": "Integration of ostack/UI with ostack/KForm.",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.4",
|
|
5
5
|
"homepage": "https://ui.ostack.tech/",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Opensoft",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@fortawesome/free-solid-svg-icons": "^6.2.0 || ^7.0.0",
|
|
52
52
|
"@ostack.tech/kform": "~1.0.0-rc.1",
|
|
53
53
|
"@ostack.tech/kform-react": "~1.0.0-rc.1",
|
|
54
|
-
"@ostack.tech/ui": "~0.16.
|
|
54
|
+
"@ostack.tech/ui": "~0.16.4",
|
|
55
55
|
"@types/react": "^19.0.0",
|
|
56
56
|
"@types/react-dom": "^19.0.0",
|
|
57
57
|
"date-fns": "^4.1.0",
|
|
@@ -9,5 +9,26 @@ export interface PathLinkOwnProps extends LinkOwnProps {
|
|
|
9
9
|
/** KForm path to link to. */
|
|
10
10
|
to: string | Path;
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* The path link component creates a link (although typically rendered as a
|
|
14
|
+
* `<button>`) to a part of the form identified by the provided path. It is
|
|
15
|
+
* built on top of the [`Link`
|
|
16
|
+
* component](/docs/ostack-ui-typography-link--docs).
|
|
17
|
+
*
|
|
18
|
+
* Example usage:
|
|
19
|
+
*
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { Alert } from "@ostack.tech/ui";
|
|
22
|
+
* import { PathLink } from "@ostack.tech/ui-kform";
|
|
23
|
+
*
|
|
24
|
+
* function ProfileNotice() {
|
|
25
|
+
* return (
|
|
26
|
+
* <Alert>
|
|
27
|
+
* Your profile URL will be generated using your handle. To change it,
|
|
28
|
+
* update your <PathLink to="/username">username</PathLink>.
|
|
29
|
+
* </Alert>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
13
34
|
export declare function PathLink<TAs extends PathLinkAs = "button">({ as, to, onClick, ...otherProps }: PathLinkProps<TAs>): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Path } from "@ostack.tech/kform";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { type UseResetOnChangeOptions } from "./useResetOnChange.tsx";
|
|
4
|
+
/** Properties of the reset on change component. */
|
|
5
|
+
export interface ResetOnChangeProps extends UseResetOnChangeOptions {
|
|
6
|
+
/** Paths to reset. */
|
|
7
|
+
reset: string | Path | (string | Path)[];
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Component used to reset path(s) to their initial value when the value of
|
|
12
|
+
* controls within it change (according to the `when` function). Built on top of
|
|
13
|
+
* the `useResetOnChange` hook.
|
|
14
|
+
*
|
|
15
|
+
* Optionally requests user-confirmation via alert dialog if `showConfirmation`
|
|
16
|
+
* is provided.
|
|
17
|
+
*
|
|
18
|
+
* When using wildcards in `reset`, certain fields may be excluded via
|
|
19
|
+
* `exclude`.
|
|
20
|
+
*
|
|
21
|
+
* Example usage:
|
|
22
|
+
*
|
|
23
|
+
* ```tsx
|
|
24
|
+
* import { CheckboxControl, ResetOnChange } from "@ostack.tech/ui-kform";
|
|
25
|
+
*
|
|
26
|
+
* function SameAddressControl() {
|
|
27
|
+
* return (
|
|
28
|
+
* <ResetOnChange
|
|
29
|
+
* reset="/mailingAddress"
|
|
30
|
+
* when={({ value }) => Boolean(value)}
|
|
31
|
+
* >
|
|
32
|
+
* <CheckboxControl path="/sameAddress">
|
|
33
|
+
* Same as residential address
|
|
34
|
+
* </CheckboxControl>
|
|
35
|
+
* </ResetOnChange>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function ResetOnChange({ reset, children, ...otherProps }: ResetOnChangeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UseResetOnChangeResult } from "./useResetOnChange.tsx";
|
|
2
|
+
/** Value of the reset on change context. */
|
|
3
|
+
export type ResetOnChangeContextValue = UseResetOnChangeResult;
|
|
4
|
+
/** Reset on change context. */
|
|
5
|
+
export declare const ResetOnChangeContext: import("react").Context<UseResetOnChangeResult | undefined>;
|
|
6
|
+
/** Function providing access to the reset on change context value. */
|
|
7
|
+
export declare function useResetOnChangeContext(): ResetOnChangeContextValue | undefined;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type FormManager, type Path, type SealedValueEvent } from "@ostack.tech/kform";
|
|
2
|
+
import { type PrefixedConfirmDialogOptions } from "../../utils/extractConfirmDialogOptions.ts";
|
|
3
|
+
/** Options of the `useResetOnChange` hook. */
|
|
4
|
+
export interface UseResetOnChangeOptions<T = unknown> extends PrefixedConfirmDialogOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Function which determines whether to reset the fields when the value
|
|
7
|
+
* changes. By default, fields are reset whenever the value changes.
|
|
8
|
+
*
|
|
9
|
+
* @param event Value event.
|
|
10
|
+
*/
|
|
11
|
+
when?: (event: SealedValueEvent<T>) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Fields in `toReset` that should be excluded from being reset (relative to
|
|
14
|
+
* the current path). This is useful when using wildcards in `toReset` and you
|
|
15
|
+
* want to exclude some of the fields that match the wildcard.
|
|
16
|
+
*
|
|
17
|
+
* E.g. `{ toReset: ["/a/*"], excludeFromReset: ["/a/b"] }` will reset all
|
|
18
|
+
* children of `/a` except `/a/b`.
|
|
19
|
+
*/
|
|
20
|
+
exclude?: string | Path | (string | Path)[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether to show a confirmation message before performing the reset.
|
|
23
|
+
*
|
|
24
|
+
* If the confirmation is cancelled, the event which caused the reset in the
|
|
25
|
+
* first place is undone.
|
|
26
|
+
*
|
|
27
|
+
* This property is `false` by default, but is automatically set to `true` if
|
|
28
|
+
* a `confirmDialogMessage` is provided.
|
|
29
|
+
*/
|
|
30
|
+
showConfirmation?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to set the fields as untouched when resetting.
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
setUntouched?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to set the fields as pristine when resetting.
|
|
39
|
+
*
|
|
40
|
+
* @default true
|
|
41
|
+
*/
|
|
42
|
+
setPristine?: boolean;
|
|
43
|
+
/** Function used to undo the change when the user cancels the confirmation. */
|
|
44
|
+
undo?: (formManager: FormManager, event: SealedValueEvent<T>) => PromiseLike<void>;
|
|
45
|
+
}
|
|
46
|
+
/** Event handler returned by the `useResetOnChange` hook. */
|
|
47
|
+
export type UseResetOnChangeResult = (event: SealedValueEvent<any>) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Hook which returns an `onValueChange` event handler which resets the fields
|
|
50
|
+
* at the provided `reset` path(s) to their initial value when a value changes
|
|
51
|
+
* (according to the `when` function).
|
|
52
|
+
*
|
|
53
|
+
* Optionally requests user-confirmation via alert dialog if `showConfirmation`
|
|
54
|
+
* is provided.
|
|
55
|
+
*
|
|
56
|
+
* When using wildcards in `reset`, certain fields may be excluded via
|
|
57
|
+
* `exclude`.
|
|
58
|
+
*
|
|
59
|
+
* Example usage:
|
|
60
|
+
*
|
|
61
|
+
* ```tsx
|
|
62
|
+
* import {
|
|
63
|
+
* CheckboxControl,
|
|
64
|
+
* useResetOnChange,
|
|
65
|
+
* } from "@ostack.tech/ui-kform";
|
|
66
|
+
*
|
|
67
|
+
* function NoTransactionsControl() {
|
|
68
|
+
* const handleOnChange = useResetOnChange("/transactions", {
|
|
69
|
+
* when: ({ value }) => Boolean(value),
|
|
70
|
+
* confirmDialogTitle: "Confirm no transactions",
|
|
71
|
+
* confirmDialogMessage: (
|
|
72
|
+
* <>
|
|
73
|
+
* By checking this box, the “Itemised transactions” table will be
|
|
74
|
+
* cleared. Are you sure you want to continue?
|
|
75
|
+
* </>
|
|
76
|
+
* ),
|
|
77
|
+
* confirmDialogOkText: "Confirm",
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* return (
|
|
81
|
+
* <CheckboxControl
|
|
82
|
+
* path="/noTransactions"
|
|
83
|
+
* onValueChange={handleOnChange}
|
|
84
|
+
* >
|
|
85
|
+
* I declare that no taxable transactions were performed during this
|
|
86
|
+
* filing period.
|
|
87
|
+
* </CheckboxControl>
|
|
88
|
+
* );
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @param reset Path(s) to reset when the value changes (relative to the current
|
|
93
|
+
* path). Wildcards in paths (`*` or `**`) are supported.
|
|
94
|
+
* @param options Hook options. See {@link UseResetOnChangeOptions}.
|
|
95
|
+
*/
|
|
96
|
+
export declare function useResetOnChange<T = unknown>(reset: string | Path | (string | Path)[], { when, exclude, confirmDialogMessage, showConfirmation, setUntouched, setPristine, undo, ...confirmDialogOptions }?: UseResetOnChangeOptions<T>): UseResetOnChangeResult;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
import { type PrefixedConfirmDialogOptions } from "../../utils/extractConfirmDialogOptions.ts";
|
|
2
3
|
import type { TableControlColumnObject } from "./TableControlColumn.tsx";
|
|
3
|
-
import { type TableControlRemoveRowTriggerProps } from "./TableControlRemoveRowTrigger.tsx";
|
|
4
|
+
import { type TableControlRemoveRowTriggerProps, type TableControlRemoveRowTriggerPropsBase } from "./TableControlRemoveRowTrigger.tsx";
|
|
4
5
|
/** Properties used to configure the `tableControlIndexColumn` function. */
|
|
5
6
|
export interface TableControlIndexColumnFnProps<T = unknown, TValue = any> extends TableControlColumnObject<T, TValue> {
|
|
6
7
|
}
|
|
@@ -13,7 +14,7 @@ export interface TableControlIndexColumnFnProps<T = unknown, TValue = any> exten
|
|
|
13
14
|
*/
|
|
14
15
|
export declare function tableControlIndexColumn<T = unknown, TValue = any>({ render, ...otherProps }?: TableControlIndexColumnFnProps<T, TValue>): TableControlColumnObject<T, TValue>;
|
|
15
16
|
/** Properties used to configure the `tableControlActionsColumn` function. */
|
|
16
|
-
export interface TableControlActionsColumnFnProps<T = unknown, TValue = any> extends TableControlColumnObject<T, TValue> {
|
|
17
|
+
export interface TableControlActionsColumnFnProps<T = unknown, TValue = any> extends TableControlColumnObject<T, TValue>, Omit<PrefixedConfirmDialogOptions<"confirmRowRemovalDialog">, "confirmRowRemovalDialogMessage"> {
|
|
17
18
|
/**
|
|
18
19
|
* Set the `label` property of the `TableControlRemoveRowTrigger` component
|
|
19
20
|
* rendered by default.
|
|
@@ -46,14 +47,6 @@ export interface TableControlActionsColumnFnProps<T = unknown, TValue = any> ext
|
|
|
46
47
|
* overridden.
|
|
47
48
|
*/
|
|
48
49
|
onRowRemoved?: () => void;
|
|
49
|
-
/**
|
|
50
|
-
* Sets the `confirmDialogTitle` property of the
|
|
51
|
-
* `TableControlRemoveRowTrigger` component rendered by default.
|
|
52
|
-
*
|
|
53
|
-
* **Note:** This property has no effect if the column's `render` function is
|
|
54
|
-
* overridden.
|
|
55
|
-
*/
|
|
56
|
-
confirmRowRemovalDialogTitle?: ReactNode;
|
|
57
50
|
/**
|
|
58
51
|
* Sets the `confirmDialogMessage` property of the
|
|
59
52
|
* `TableControlRemoveRowTrigger` component rendered by default.
|
|
@@ -61,23 +54,7 @@ export interface TableControlActionsColumnFnProps<T = unknown, TValue = any> ext
|
|
|
61
54
|
* **Note:** This property has no effect if the column's `render` function is
|
|
62
55
|
* overridden.
|
|
63
56
|
*/
|
|
64
|
-
confirmRowRemovalDialogMessage?:
|
|
65
|
-
/**
|
|
66
|
-
* Sets the `confirmDialogOkText` property of the
|
|
67
|
-
* `TableControlRemoveRowTrigger` component rendered by default.
|
|
68
|
-
*
|
|
69
|
-
* **Note:** This property has no effect if the column's `render` function is
|
|
70
|
-
* overridden.
|
|
71
|
-
*/
|
|
72
|
-
confirmRowRemovalDialogOkText?: ReactNode;
|
|
73
|
-
/**
|
|
74
|
-
* Sets the `confirmDialogCancelText` property of the
|
|
75
|
-
* `TableControlRemoveRowTrigger` component rendered by default.
|
|
76
|
-
*
|
|
77
|
-
* **Note:** This property has no effect if the column's `render` function is
|
|
78
|
-
* overridden.
|
|
79
|
-
*/
|
|
80
|
-
confirmRowRemovalDialogCancelText?: ReactNode;
|
|
57
|
+
confirmRowRemovalDialogMessage?: TableControlRemoveRowTriggerPropsBase["confirmDialogMessage"];
|
|
81
58
|
/**
|
|
82
59
|
* Properties to pass to the `TableControlRemoveRowTrigger` component rendered
|
|
83
60
|
* by default.
|
|
@@ -110,4 +87,4 @@ export interface TableControlActionsColumnFnProps<T = unknown, TValue = any> ext
|
|
|
110
87
|
* @param overrides Column properties used to display the actions of each row.
|
|
111
88
|
* @returns Table control column used to display the actions of each row.
|
|
112
89
|
*/
|
|
113
|
-
export declare function tableControlActionsColumn<T = unknown, TValue = any>({ removeRowLabel, showRowRemovalConfirmation, onConfirmRowRemoval, onRowRemoved,
|
|
90
|
+
export declare function tableControlActionsColumn<T = unknown, TValue = any>({ removeRowLabel, showRowRemovalConfirmation, onConfirmRowRemoval, onRowRemoved, confirmRowRemovalDialogMessage, removeRowProps, render, ...otherProps }?: TableControlActionsColumnFnProps<T, TValue>): TableControlColumnObject<T, TValue>;
|
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
import { type IconButtonProps } from "@ostack.tech/ui";
|
|
2
2
|
import { type ComponentProps, type ReactNode } from "react";
|
|
3
|
+
import { type PrefixedConfirmDialogOptions } from "../../utils/extractConfirmDialogOptions.ts";
|
|
3
4
|
/** Properties of the table control remove row trigger component. */
|
|
4
5
|
export type TableControlRemoveRowTriggerProps = TableControlRemoveRowTriggerChildlessProps | TableControlRemoveRowTriggerChildrenProps;
|
|
5
6
|
/** Base properties of the table control remove row trigger component. */
|
|
6
|
-
export interface
|
|
7
|
+
export interface TableControlRemoveRowTriggerPropsBase extends Omit<PrefixedConfirmDialogOptions, "confirmDialogMessage"> {
|
|
7
8
|
/**
|
|
8
9
|
* Whether to show a confirmation message when removing a row.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* Defaults to `false` unless `confirmDialogMessage` is set, in which case
|
|
12
|
+
* defaults to `true`.
|
|
11
13
|
*/
|
|
12
14
|
showConfirmation?: boolean;
|
|
13
15
|
/**
|
|
14
16
|
* Function called after confirmation that the row is to be removed (this
|
|
15
|
-
* function is called even if `showConfirmation` is
|
|
17
|
+
* function is called even if `showConfirmation` is `false`).
|
|
16
18
|
*/
|
|
17
19
|
onConfirmRowRemoval?: () => void;
|
|
18
20
|
/** Function called after the row has been removed. */
|
|
19
21
|
onRowRemoved?: () => void;
|
|
20
|
-
/** Title of the confirmation dialog when `showConfirmation` is `true`. */
|
|
21
|
-
confirmDialogTitle?: ReactNode;
|
|
22
22
|
/**
|
|
23
|
-
* Message of the confirmation dialog
|
|
23
|
+
* Message of the confirmation dialog.
|
|
24
24
|
*
|
|
25
25
|
* @param index Index of the row being removed.
|
|
26
26
|
*/
|
|
27
|
-
confirmDialogMessage?: (index: number) => ReactNode;
|
|
28
|
-
/**
|
|
29
|
-
* Ok button text of the confirmation dialog when `showConfirmation` is
|
|
30
|
-
* `true`.
|
|
31
|
-
*/
|
|
32
|
-
confirmDialogOkText?: ReactNode;
|
|
33
|
-
/**
|
|
34
|
-
* Cancel button text of the confirmation dialog when `showConfirmation` is
|
|
35
|
-
* `true`.
|
|
36
|
-
*/
|
|
37
|
-
confirmDialogCancelText?: ReactNode;
|
|
27
|
+
confirmDialogMessage?: ReactNode | ((index: number) => ReactNode);
|
|
38
28
|
/**
|
|
39
29
|
* Whether to show the trigger when the table is read-only.
|
|
40
30
|
*
|
|
@@ -46,7 +36,7 @@ export interface TableControlRemoveRowTriggerChildlessPropsBase {
|
|
|
46
36
|
* Base properties of the table control remove row trigger component when
|
|
47
37
|
* rendered without children.
|
|
48
38
|
*/
|
|
49
|
-
export interface TableControlRemoveRowTriggerChildlessProps extends
|
|
39
|
+
export interface TableControlRemoveRowTriggerChildlessProps extends TableControlRemoveRowTriggerPropsBase, Omit<Partial<IconButtonProps>, "asChild" | "children"> {
|
|
50
40
|
/**
|
|
51
41
|
* Label of the icon button.
|
|
52
42
|
*
|
|
@@ -59,7 +49,7 @@ export interface TableControlRemoveRowTriggerChildlessProps extends TableControl
|
|
|
59
49
|
* Base properties of the table control remove row trigger component when
|
|
60
50
|
* rendered with children.
|
|
61
51
|
*/
|
|
62
|
-
export interface TableControlRemoveRowTriggerChildrenProps extends
|
|
52
|
+
export interface TableControlRemoveRowTriggerChildrenProps extends TableControlRemoveRowTriggerPropsBase, Partial<ComponentProps<"button">> {
|
|
63
53
|
children: ReactNode;
|
|
64
54
|
}
|
|
65
55
|
/**
|
|
@@ -68,4 +58,4 @@ export interface TableControlRemoveRowTriggerChildrenProps extends TableControlR
|
|
|
68
58
|
* By default, it renders an icon button with label `defaultButtonLabel`,
|
|
69
59
|
* however, this can be overriden by providing `children`.
|
|
70
60
|
*/
|
|
71
|
-
export declare function TableControlRemoveRowTrigger({
|
|
61
|
+
export declare function TableControlRemoveRowTrigger({ onConfirmRowRemoval, onRowRemoved, confirmDialogMessage, confirmDialogTitle, confirmDialogOkText, confirmDialogCancelText, showConfirmation, showWhenReadOnly, disabled, onClick, children, ...otherProps }: TableControlRemoveRowTriggerProps): import("react").JSX.Element | null;
|
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from "./components/NumericControl";
|
|
|
19
19
|
export * from "./components/PathLink";
|
|
20
20
|
export * from "./components/PrintAction";
|
|
21
21
|
export * from "./components/RadioGroupControl";
|
|
22
|
+
export * from "./components/ResetOnChange";
|
|
22
23
|
export * from "./components/SaveAction";
|
|
23
24
|
export * from "./components/SelectControl";
|
|
24
25
|
export * from "./components/SelectMultipleControl";
|
|
@@ -37,4 +38,3 @@ export * from "./utils/useFormLoader.tsx";
|
|
|
37
38
|
export * from "./utils/useFormSaver.tsx";
|
|
38
39
|
export * from "./utils/useFormValidator.ts";
|
|
39
40
|
export * from "./utils/useRegisterControl.tsx";
|
|
40
|
-
export * from "./utils/useResetOnChange.tsx";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConfirmDialogOptions } from "@ostack.tech/ui";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
/** Confirm dialog options with a prefix. */
|
|
4
|
+
export type PrefixedConfirmDialogOptions<TPrefix extends string = "confirmDialog"> = {
|
|
5
|
+
[K in keyof ConfirmDialogOptions as `${TPrefix}${Capitalize<string & K>}`]: ConfirmDialogOptions[K];
|
|
6
|
+
} & Partial<Record<`${TPrefix}Message`, ReactNode>>;
|
|
7
|
+
/** Result of the {@link extractConfirmDialogOptions} function. */
|
|
8
|
+
export type ExtractConfirmDialogOptionsResult<TOptions extends PrefixedConfirmDialogOptions<TPrefix>, TPrefix extends string = "confirmDialog", TNewPrefix extends string = ""> = [
|
|
9
|
+
TNewPrefix extends "" ? ConfirmDialogOptions : PrefixedConfirmDialogOptions<TNewPrefix>,
|
|
10
|
+
Omit<TOptions, keyof PrefixedConfirmDialogOptions<TPrefix>>
|
|
11
|
+
];
|
|
12
|
+
/** Function used to extract confirm dialog options with a given prefix. */
|
|
13
|
+
export declare function extractConfirmDialogOptions<TOptions extends PrefixedConfirmDialogOptions<TPrefix>, TPrefix extends string = "confirmDialog", TNewPrefix extends string = "">(options: TOptions, prefix?: TPrefix, newPrefix?: TNewPrefix): ExtractConfirmDialogOptionsResult<TOptions, TPrefix, TNewPrefix>;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import type { Path, SealedValueEvent } from "@ostack.tech/kform";
|
|
2
|
-
import { type AlertDialogContentColor, type ConfirmDialogOptions } from "@ostack.tech/ui";
|
|
3
|
-
import { type ReactNode } from "react";
|
|
4
|
-
/** Options of the reset confirmation dialog. */
|
|
5
|
-
export interface ResetConfirmDialogOption extends ConfirmDialogOptions {
|
|
6
|
-
/** Message of the confirmation dialog. */
|
|
7
|
-
message: ReactNode;
|
|
8
|
-
/**
|
|
9
|
-
* Confirmation dialog content color.
|
|
10
|
-
*
|
|
11
|
-
* @default "warning"
|
|
12
|
-
*/
|
|
13
|
-
color?: AlertDialogContentColor;
|
|
14
|
-
}
|
|
15
|
-
/** Options of the `useResetOnChange` hook. */
|
|
16
|
-
export interface UseResetOnChangeOptions<T = unknown> {
|
|
17
|
-
/**
|
|
18
|
-
* Function which determines whether to reset the fields when the value
|
|
19
|
-
* changes. By default, fields are reset whenever the value changes.
|
|
20
|
-
*
|
|
21
|
-
* @param event Value event.
|
|
22
|
-
*/
|
|
23
|
-
when?: (event: SealedValueEvent<T>) => boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Fields in `toReset` that should be excluded from being reset (relative to
|
|
26
|
-
* the current path). This is useful when using wildcards in `toReset` and you
|
|
27
|
-
* want to exclude some of the fields that match the wildcard.
|
|
28
|
-
*
|
|
29
|
-
* E.g. `{ toReset: ["/a/*"], excludeFromReset: ["/a/b"] }` will reset all
|
|
30
|
-
* children of `/a` except `/a/b`.
|
|
31
|
-
*/
|
|
32
|
-
exclude?: string | Path | (string | Path)[];
|
|
33
|
-
/**
|
|
34
|
-
* Confirmation dialog options. When provided, a confirmation dialog will be
|
|
35
|
-
* presented to the user before resetting the fields.
|
|
36
|
-
*
|
|
37
|
-
* If this option is **not** provided, the fields will be reset without
|
|
38
|
-
* confirmation.
|
|
39
|
-
*/
|
|
40
|
-
confirmation?: ResetConfirmDialogOption;
|
|
41
|
-
/**
|
|
42
|
-
* Whether to set the fields as untouched when resetting.
|
|
43
|
-
*
|
|
44
|
-
* @default true
|
|
45
|
-
*/
|
|
46
|
-
setUntouched?: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Whether to set the fields as pristine when resetting.
|
|
49
|
-
*
|
|
50
|
-
* @default true
|
|
51
|
-
*/
|
|
52
|
-
setPristine?: boolean;
|
|
53
|
-
}
|
|
54
|
-
/** Event handler returned by the `useResetOnChange` hook. */
|
|
55
|
-
export type UseResetOnChangeResult = (event: SealedValueEvent<any>) => void;
|
|
56
|
-
/**
|
|
57
|
-
* Hook which returns an `onValueChange` event handler which resets the fields
|
|
58
|
-
* at the provided `toReset` paths to their initial value when the value changes
|
|
59
|
-
* (according to the `when` function).
|
|
60
|
-
*
|
|
61
|
-
* Optionally requests user-confirmation via dialog if `confirmation` is
|
|
62
|
-
* provided.
|
|
63
|
-
*
|
|
64
|
-
* When using wildcards in `toReset`, certain fields may be excluded via
|
|
65
|
-
* `exclude`.
|
|
66
|
-
*
|
|
67
|
-
* Example usage:
|
|
68
|
-
*
|
|
69
|
-
* ```tsx
|
|
70
|
-
* function NoTransactionsControl() {
|
|
71
|
-
* const handleOnChange = useResetOnChange("/transactions/*", {
|
|
72
|
-
* when: ({ value }) => value,
|
|
73
|
-
* confirmation: {
|
|
74
|
-
* title: "Confirm no transactions",
|
|
75
|
-
* message: (
|
|
76
|
-
* <>
|
|
77
|
-
* By checking this box, all fields in section “Transactions” will
|
|
78
|
-
* be cleared. Are you sure you want to continue?
|
|
79
|
-
* </>
|
|
80
|
-
* ),
|
|
81
|
-
* okText: "Confirm",
|
|
82
|
-
* },
|
|
83
|
-
* });
|
|
84
|
-
*
|
|
85
|
-
* return (
|
|
86
|
-
* <CheckboxControl
|
|
87
|
-
* path="noTransactions"
|
|
88
|
-
* onValueChange={handleOnChange}
|
|
89
|
-
* />
|
|
90
|
-
* );
|
|
91
|
-
* }
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param toReset Paths to reset up when the value changes (relative to the
|
|
95
|
-
* current path). Wildcards in paths (`*` or `**`) are supported.
|
|
96
|
-
* @param options Hook options. See {@link UseResetOnChangeOptions}.
|
|
97
|
-
*/
|
|
98
|
-
export declare function useResetOnChange<T = unknown>(toReset: string | Path | (string | Path)[], { when, exclude, confirmation, setUntouched, setPristine, }?: UseResetOnChangeOptions<T>): UseResetOnChangeResult;
|