mtxuilib 0.1.278 → 0.1.280

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.
@@ -3,12 +3,14 @@ export type ConfirmModalProps = {};
3
3
  export interface ConfirmModalState extends ConfirmModalProps {
4
4
  open?: boolean;
5
5
  setOpen: (_open: boolean) => void;
6
- onConfirm?: () => void;
6
+ onConfirm?: (values: any) => void;
7
7
  onCancel?: () => void;
8
- setOnConfirm: (_onConfirm: () => void) => void;
8
+ setOnConfirm: (_onConfirm: (values: any) => void) => void;
9
9
  setOnCancel: (_onCancel: () => void) => void;
10
10
  options?: ConfirmModalOptions;
11
11
  setOptions: (_options: ConfirmModalOptions) => void;
12
+ values?: any;
13
+ setValues: (_values: any) => void;
12
14
  }
13
15
  export declare const createAppSlice: StateCreator<ConfirmModalState, [
14
16
  ], [
@@ -24,11 +26,14 @@ interface ConfirmModalOptions {
24
26
  description?: string;
25
27
  confirmText?: string;
26
28
  cancelText?: string;
29
+ onConfirm: (values: any) => void;
30
+ onCancel?: () => void;
27
31
  }
28
32
  interface UseConfirmProps extends ConfirmModalProps {
29
- onConfirm: () => void;
33
+ options: ConfirmModalOptions;
30
34
  }
31
35
  export declare const useConfirm: (props: UseConfirmProps) => {
32
- showConfirm: (options: ConfirmModalOptions) => void;
36
+ showConfirm: (values: any) => void;
33
37
  };
38
+ export declare function useConfirmV2(message: any, onConfirm: any, onAbort: any): (values: any) => void;
34
39
  export {};
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo, } from "react";
4
4
  import { createStore, useStore } from "zustand";
5
5
  import { useShallow } from "zustand/react/shallow";
6
6
  import { ConfirmModal } from "./Confrom";
@@ -14,6 +14,7 @@ export const createAppSlice = (set, get, init) => {
14
14
  setOnConfirm: (onConfirm) => set({ onConfirm }),
15
15
  setOnCancel: (onCancel) => set({ onCancel }),
16
16
  setOptions: (options) => set({ options }),
17
+ setValues: (values) => set({ values }),
17
18
  };
18
19
  };
19
20
  const createMtAppStore = (initProps) => {
@@ -40,17 +41,28 @@ export function useConfirmStore(selector) {
40
41
  return useStore(store);
41
42
  }
42
43
  export const useConfirm = (props) => {
43
- const confirm = useConfirmStore();
44
44
  const setOpen = useConfirmStore((x) => x.setOpen);
45
45
  const setOnConfirm = useConfirmStore((x) => x.setOnConfirm);
46
- const setOnCancel = useConfirmStore((x) => x.setOnCancel);
46
+ const setOptions = useConfirmStore((x) => x.setOptions);
47
+ const setValues = useConfirmStore((x) => x.setValues);
47
48
  useEffect(() => {
48
- confirm.setOnConfirm(props.onConfirm);
49
- }, []);
50
- const showConfirm = useCallback((options) => {
49
+ setOptions(props.options);
50
+ setOnConfirm(props.options.onConfirm);
51
+ }, [props.options, setOptions, setOnConfirm]);
52
+ const showConfirm = useCallback((values) => {
51
53
  setOpen(true);
52
- }, [setOpen]);
54
+ setValues(values);
55
+ }, [setOpen, setValues]);
53
56
  return {
54
57
  showConfirm: showConfirm,
55
58
  };
56
59
  };
60
+ export function useConfirmV2(message, onConfirm, onAbort) {
61
+ const confirm = useCallback((values) => {
62
+ if (window.confirm(message))
63
+ onConfirm(values);
64
+ else
65
+ onAbort();
66
+ }, [message, onConfirm, onAbort]);
67
+ return confirm;
68
+ }
@@ -1,9 +1,21 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { Dialog, DialogContent, DialogTitle } from "../../ui/dialog";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Button } from "../../ui/button";
4
+ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle, } from "../../ui/dialog";
4
5
  import { useConfirmStore } from "./ConfirmProvider";
5
6
  export function ConfirmModal() {
6
7
  const open = useConfirmStore((x) => x.open);
7
8
  const setOpen = useConfirmStore((x) => x.setOpen);
8
- return (_jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsx(DialogContent, { children: _jsx(DialogTitle, { children: "Confirm" }) }) }));
9
+ const onConfirm = useConfirmStore((x) => x.onConfirm);
10
+ const options = useConfirmStore((x) => x.options);
11
+ const values = useConfirmStore((x) => x.values);
12
+ const title = options?.title || "Confirm";
13
+ const message = options?.message || "Are you sure?";
14
+ const confirmText = options?.confirmText || "Confirm";
15
+ const cancelText = options?.cancelText || "Cancel";
16
+ return (_jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { children: [_jsx(DialogTitle, { children: title }), _jsx(DialogDescription, { children: message }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", className: "min-w-14", onClick: () => setOpen(false), children: cancelText }), _jsx(Button, { className: "min-w-14", onClick: () => {
17
+ setOpen(false);
18
+ console.log("onConfirm", values);
19
+ onConfirm?.(values);
20
+ }, children: confirmText })] })] }) }));
9
21
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mtxuilib",
3
3
  "private": false,
4
- "version": "0.1.278",
4
+ "version": "0.1.280",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },