@kolking/react-ui 1.9.1 → 1.9.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.
@@ -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<object>>;
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<object>>;
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), [d, g] = f({}), [m, i] = f(s?.defaultOpen ?? !1), [w, l] = f();
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 p = t((r, h = {}) => {
7
- e.current || (a.current = h, i(!0), l(r), n.current?.onShow?.(r));
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?.()), i(!1), l(void 0), e.current = !1;
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
- }, []), C = t(() => o(), [o]), O = t((r) => o(r), [o]), b = t(async (r) => {
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: C },
22
- trigger: { ...d, onClick: p },
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: p,
25
- cancel: C,
28
+ show: C,
29
+ cancel: d,
26
30
  confirm: O,
27
31
  preventClose: b
28
32
  };
@@ -1,12 +1,18 @@
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): React.ComponentType<ComponentProps<T, R>>;
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
+ useTrigger(): {
14
+ props: Record<string, unknown>;
15
+ show(_values: T, _showOptions?: DialogShowOptions<R>): void;
16
+ };
17
+ };
12
18
  export {};
@@ -1,22 +1,32 @@
1
- import { jsxs as d, Fragment as g, jsx as r } from "react/jsx-runtime";
2
- import { Dialog as f } from "./Dialog.js";
3
- import { useDialog as u } from "./useDialog.js";
4
- function j(t, i) {
5
- function a({
6
- children: n,
7
- defaultOpen: p,
8
- onShow: e,
9
- onConfirm: s,
10
- onCancel: l,
11
- ...m
1
+ import { jsxs as h, Fragment as w, jsx as r } from "react/jsx-runtime";
2
+ import i, { useMemo as x } from "react";
3
+ import { Dialog as d } from "./Dialog.js";
4
+ import { useDialog as D } from "./useDialog.js";
5
+ function j(a, p) {
6
+ const e = i.createContext({
7
+ props: {},
8
+ show(t, n) {
9
+ throw new Error("Dialog context is not available");
10
+ }
11
+ });
12
+ function s({
13
+ children: t,
14
+ defaultOpen: n,
15
+ onShow: u,
16
+ onConfirm: g,
17
+ onCancel: c,
18
+ ...l
12
19
  }) {
13
- const o = u({ defaultOpen: p, onShow: e, onConfirm: s, onCancel: l }), c = { ...i, ...m, ...o.props };
14
- return /* @__PURE__ */ d(g, { children: [
15
- n(o),
16
- /* @__PURE__ */ r(f, { ...c, children: o.data && /* @__PURE__ */ r(t, { ...o.data, dialog: o }) })
20
+ const o = D({ defaultOpen: n, onShow: u, onConfirm: g, onCancel: c }), m = { ...p, ...l, ...o.props }, f = x(() => ({
21
+ props: o.triggerProps,
22
+ show: o.show
23
+ }), [o.show, o.triggerProps]);
24
+ return /* @__PURE__ */ h(w, { children: [
25
+ /* @__PURE__ */ r(e, { value: f, children: typeof t == "function" ? t(o) : t }),
26
+ /* @__PURE__ */ r(d, { ...m, children: o.data && /* @__PURE__ */ r(a, { ...o.data, dialog: o }) })
17
27
  ] });
18
28
  }
19
- return a;
29
+ return s.useTrigger = () => i.useContext(e), s;
20
30
  }
21
31
  export {
22
32
  j as withDialog
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolking/react-ui",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "React component library for building user interfaces",
5
5
  "author": "Nick Seryakov (https://github.com/kolking)",
6
6
  "license": "MIT",