mtxuilib 0.1.277 → 0.1.278

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.
@@ -0,0 +1,34 @@
1
+ import { type StateCreator } from "zustand";
2
+ export type ConfirmModalProps = {};
3
+ export interface ConfirmModalState extends ConfirmModalProps {
4
+ open?: boolean;
5
+ setOpen: (_open: boolean) => void;
6
+ onConfirm?: () => void;
7
+ onCancel?: () => void;
8
+ setOnConfirm: (_onConfirm: () => void) => void;
9
+ setOnCancel: (_onCancel: () => void) => void;
10
+ options?: ConfirmModalOptions;
11
+ setOptions: (_options: ConfirmModalOptions) => void;
12
+ }
13
+ export declare const createAppSlice: StateCreator<ConfirmModalState, [
14
+ ], [
15
+ ], ConfirmModalState>;
16
+ export declare const gomtmContext: import("react").Context<import("zustand").StoreApi<ConfirmModalState> | null>;
17
+ type AppProviderProps = React.PropsWithChildren<ConfirmModalProps>;
18
+ export declare const ConfirmModalProvider: (props: AppProviderProps) => import("react/jsx-runtime").JSX.Element;
19
+ export declare function useConfirmStore(): ConfirmModalState;
20
+ export declare function useConfirmStore<T>(selector: (state: ConfirmModalState) => T): T;
21
+ interface ConfirmModalOptions {
22
+ title?: string;
23
+ message: string;
24
+ description?: string;
25
+ confirmText?: string;
26
+ cancelText?: string;
27
+ }
28
+ interface UseConfirmProps extends ConfirmModalProps {
29
+ onConfirm: () => void;
30
+ }
31
+ export declare const useConfirm: (props: UseConfirmProps) => {
32
+ showConfirm: (options: ConfirmModalOptions) => void;
33
+ };
34
+ export {};
@@ -0,0 +1,56 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
4
+ import { createStore, useStore } from "zustand";
5
+ import { useShallow } from "zustand/react/shallow";
6
+ import { ConfirmModal } from "./Confrom";
7
+ export const createAppSlice = (set, get, init) => {
8
+ return {
9
+ open: false,
10
+ ...init,
11
+ setOpen(_open) {
12
+ set({ open: _open });
13
+ },
14
+ setOnConfirm: (onConfirm) => set({ onConfirm }),
15
+ setOnCancel: (onCancel) => set({ onCancel }),
16
+ setOptions: (options) => set({ options }),
17
+ };
18
+ };
19
+ const createMtAppStore = (initProps) => {
20
+ const initialState = { ...initProps };
21
+ return createStore()((...a) => ({
22
+ ...createAppSlice(...a),
23
+ ...initialState,
24
+ }));
25
+ };
26
+ export const gomtmContext = createContext(null);
27
+ export const ConfirmModalProvider = (props) => {
28
+ const { children, ...etc } = props;
29
+ const mystore = useMemo(() => createMtAppStore(etc), [etc]);
30
+ return (_jsxs(gomtmContext.Provider, { value: mystore, children: [children, _jsx(ConfirmModal, {})] }));
31
+ };
32
+ const DEFAULT_USE_SHALLOW = true;
33
+ export function useConfirmStore(selector) {
34
+ const store = useContext(gomtmContext);
35
+ if (!store)
36
+ throw new Error("useConfirmStore must in ConfirmModalProvider");
37
+ if (selector) {
38
+ return useStore(store, DEFAULT_USE_SHALLOW ? useShallow(selector) : selector);
39
+ }
40
+ return useStore(store);
41
+ }
42
+ export const useConfirm = (props) => {
43
+ const confirm = useConfirmStore();
44
+ const setOpen = useConfirmStore((x) => x.setOpen);
45
+ const setOnConfirm = useConfirmStore((x) => x.setOnConfirm);
46
+ const setOnCancel = useConfirmStore((x) => x.setOnCancel);
47
+ useEffect(() => {
48
+ confirm.setOnConfirm(props.onConfirm);
49
+ }, []);
50
+ const showConfirm = useCallback((options) => {
51
+ setOpen(true);
52
+ }, [setOpen]);
53
+ return {
54
+ showConfirm: showConfirm,
55
+ };
56
+ };
@@ -0,0 +1 @@
1
+ export declare function ConfirmModal(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { Dialog, DialogContent, DialogTitle } from "../../ui/dialog";
4
+ import { useConfirmStore } from "./ConfirmProvider";
5
+ export function ConfirmModal() {
6
+ const open = useConfirmStore((x) => x.open);
7
+ const setOpen = useConfirmStore((x) => x.setOpen);
8
+ return (_jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsx(DialogContent, { children: _jsx(DialogTitle, { children: "Confirm" }) }) }));
9
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mtxuilib",
3
3
  "private": false,
4
- "version": "0.1.277",
4
+ "version": "0.1.278",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },