@kolking/react-ui 1.9.1 → 1.9.3
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.
|
@@ -7,7 +7,7 @@ export type DialogProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
|
7
7
|
width?: React.CSSProperties['width'];
|
|
8
8
|
lockScroll?: boolean;
|
|
9
9
|
requestClose: () => void;
|
|
10
|
-
setTriggerProps?: React.Dispatch<React.SetStateAction<
|
|
10
|
+
setTriggerProps?: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;
|
|
11
11
|
};
|
|
12
12
|
export declare const Dialog: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
13
13
|
open?: boolean;
|
|
@@ -15,7 +15,7 @@ export declare const Dialog: React.ForwardRefExoticComponent<React.HTMLAttribute
|
|
|
15
15
|
width?: React.CSSProperties["width"];
|
|
16
16
|
lockScroll?: boolean;
|
|
17
17
|
requestClose: () => void;
|
|
18
|
-
setTriggerProps?: React.Dispatch<React.SetStateAction<
|
|
18
|
+
setTriggerProps?: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;
|
|
19
19
|
} & React.RefAttributes<HTMLDivElement>>;
|
|
20
20
|
export declare const DialogTitle: ({ className, children, ...props }: Omit<HeadingProps, "title">) => import("react/jsx-runtime").JSX.Element;
|
|
21
21
|
export declare const DialogContent: (props: React.HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type DialogShowOptions<R> = {
|
|
1
|
+
export type DialogShowOptions<R> = {
|
|
2
2
|
onConfirm?: (values: R) => void;
|
|
3
3
|
onCancel?: () => void;
|
|
4
4
|
};
|
|
@@ -11,9 +11,13 @@ export declare function useDialog<T, R>(options?: DialogOptions<T, R>): {
|
|
|
11
11
|
props: {
|
|
12
12
|
ref: import('react').RefObject<HTMLDivElement | null>;
|
|
13
13
|
open: boolean;
|
|
14
|
-
setTriggerProps: import('react').Dispatch<import('react').SetStateAction<
|
|
14
|
+
setTriggerProps: import('react').Dispatch<import('react').SetStateAction<Record<string, unknown>>>;
|
|
15
15
|
requestClose: () => void;
|
|
16
16
|
};
|
|
17
|
+
triggerProps: Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated The property will be removed in the next major release
|
|
20
|
+
*/
|
|
17
21
|
trigger: {
|
|
18
22
|
onClick: (values: T, showOptions?: DialogShowOptions<R>) => void;
|
|
19
23
|
};
|
|
@@ -23,4 +27,3 @@ export declare function useDialog<T, R>(options?: DialogOptions<T, R>): {
|
|
|
23
27
|
confirm: (values: R) => void;
|
|
24
28
|
preventClose: <T_1>(promise: Promise<T_1>) => Promise<T_1>;
|
|
25
29
|
};
|
|
26
|
-
export {};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { useRef as c, useState as f, useCallback as t } from "react";
|
|
2
2
|
import { afterTransition as v } from "../../utils/helpers.js";
|
|
3
3
|
function S(s) {
|
|
4
|
-
const u = c(null), e = c(!1), n = c(s), a = c(void 0), [
|
|
4
|
+
const u = c(null), e = c(!1), n = c(s), a = c(void 0), [i, g] = f({}), [m, l] = f(s?.defaultOpen ?? !1), [w, p] = f();
|
|
5
5
|
n.current = s;
|
|
6
|
-
const
|
|
7
|
-
e.current || (a.current = h,
|
|
6
|
+
const C = t((r, h = {}) => {
|
|
7
|
+
e.current || (a.current = h, l(!0), p(r), n.current?.onShow?.(r));
|
|
8
8
|
}, []), o = t((r) => {
|
|
9
9
|
e.current || (e.current = !0, u.current?.setAttribute("data-open", "false"), v(u.current, () => {
|
|
10
|
-
r !== void 0 ? (n.current?.onConfirm?.(r), a.current?.onConfirm?.(r)) : (n.current?.onCancel?.(), a.current?.onCancel?.()),
|
|
10
|
+
r !== void 0 ? (n.current?.onConfirm?.(r), a.current?.onConfirm?.(r)) : (n.current?.onCancel?.(), a.current?.onCancel?.()), l(!1), p(void 0), e.current = !1;
|
|
11
11
|
}));
|
|
12
|
-
}, []),
|
|
12
|
+
}, []), d = t(() => o(), [o]), O = t((r) => o(r), [o]), b = t(async (r) => {
|
|
13
13
|
e.current = !0;
|
|
14
14
|
try {
|
|
15
15
|
return await r;
|
|
@@ -18,11 +18,15 @@ function S(s) {
|
|
|
18
18
|
}
|
|
19
19
|
}, []);
|
|
20
20
|
return {
|
|
21
|
-
props: { ref: u, open: m, setTriggerProps: g, requestClose:
|
|
22
|
-
|
|
21
|
+
props: { ref: u, open: m, setTriggerProps: g, requestClose: d },
|
|
22
|
+
triggerProps: i,
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated The property will be removed in the next major release
|
|
25
|
+
*/
|
|
26
|
+
trigger: { ...i, onClick: C },
|
|
23
27
|
data: w,
|
|
24
|
-
show:
|
|
25
|
-
cancel:
|
|
28
|
+
show: C,
|
|
29
|
+
cancel: d,
|
|
26
30
|
confirm: O,
|
|
27
31
|
preventClose: b
|
|
28
32
|
};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { DialogProps } from './Dialog';
|
|
3
|
-
import { DialogOptions, DialogType } from './useDialog';
|
|
3
|
+
import { DialogOptions, DialogShowOptions, DialogType } from './useDialog';
|
|
4
4
|
type PartialDialogProps = Omit<DialogProps, 'children' | 'ref' | 'requestClose'>;
|
|
5
5
|
type ComponentProps<T, R> = PartialDialogProps & DialogOptions<T, R> & {
|
|
6
|
-
children: (dialog: DialogType<T, R>) => React.ReactNode;
|
|
6
|
+
children: React.ReactNode | ((dialog: DialogType<T, R>) => React.ReactNode);
|
|
7
7
|
};
|
|
8
8
|
export type WithDialogProps<T extends object, R> = T & {
|
|
9
9
|
dialog: DialogType<T, R>;
|
|
10
10
|
};
|
|
11
|
-
export declare function withDialog<T extends object, R>(Component: React.ComponentType<WithDialogProps<T, R>>, withProps?: PartialDialogProps):
|
|
11
|
+
export declare function withDialog<T extends object, R>(Component: React.ComponentType<WithDialogProps<T, R>>, withProps?: PartialDialogProps): {
|
|
12
|
+
({ children, defaultOpen, onShow, onConfirm, onCancel, ...props }: ComponentProps<T, R>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
useDialogShow(): (_values: T, _showOptions?: DialogShowOptions<R>) => void;
|
|
14
|
+
};
|
|
12
15
|
export {};
|
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { jsxs as g, Fragment as x, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import i from "react";
|
|
3
|
+
import { Dialog as d } from "./Dialog.js";
|
|
4
|
+
import { useDialog as h } from "./useDialog.js";
|
|
5
|
+
function C(s, l) {
|
|
6
|
+
const e = i.createContext((t, n) => {
|
|
7
|
+
throw new Error("Dialog context is not available");
|
|
8
|
+
});
|
|
5
9
|
function a({
|
|
6
|
-
children:
|
|
7
|
-
defaultOpen:
|
|
8
|
-
onShow:
|
|
9
|
-
onConfirm:
|
|
10
|
-
onCancel:
|
|
11
|
-
...
|
|
10
|
+
children: t,
|
|
11
|
+
defaultOpen: n,
|
|
12
|
+
onShow: p,
|
|
13
|
+
onConfirm: u,
|
|
14
|
+
onCancel: c,
|
|
15
|
+
...f
|
|
12
16
|
}) {
|
|
13
|
-
const o =
|
|
14
|
-
return /* @__PURE__ */
|
|
15
|
-
|
|
16
|
-
/* @__PURE__ */ r(
|
|
17
|
+
const o = h({ defaultOpen: n, onShow: p, onConfirm: u, onCancel: c }), m = { ...l, ...f, ...o.props };
|
|
18
|
+
return /* @__PURE__ */ g(x, { children: [
|
|
19
|
+
/* @__PURE__ */ r(e, { value: o.show, children: typeof t == "function" ? t(o) : t }),
|
|
20
|
+
/* @__PURE__ */ r(d, { ...m, children: o.data && /* @__PURE__ */ r(s, { ...o.data, dialog: o }) })
|
|
17
21
|
] });
|
|
18
22
|
}
|
|
19
|
-
return a;
|
|
23
|
+
return a.useDialogShow = () => i.useContext(e), a;
|
|
20
24
|
}
|
|
21
25
|
export {
|
|
22
|
-
|
|
26
|
+
C as withDialog
|
|
23
27
|
};
|