@vuetkit/components 0.0.7 → 0.0.8

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/index.d.ts CHANGED
@@ -1,5 +1,23 @@
1
- import { MessageProps } from "element-plus";
1
+ import { RequestService } from "@vuetkit/core";
2
+ import { MessageProps, MessageType } from "element-plus";
2
3
 
4
+ //#region src/feedback/useAsyncConfirm/index.d.ts
5
+ interface AsyncConfirmOptions {
6
+ title?: string;
7
+ message?: string;
8
+ type?: MessageType;
9
+ confirmButtonText?: string;
10
+ cancelButtonText?: string;
11
+ successMessage?: string;
12
+ errorMessage?: string;
13
+ confirmSuccess?: () => void;
14
+ confirmError?: (error: unknown) => void;
15
+ }
16
+ declare function useAsyncConfirm(confirmService: RequestService, options: AsyncConfirmOptions): {
17
+ loading: import("vue").Ref<boolean, boolean>;
18
+ confirm: (params?: unknown) => void;
19
+ };
20
+ //#endregion
3
21
  //#region src/feedback/useMessage/index.d.ts
4
22
  declare function useMessage(options?: MessageProps): {
5
23
  success: (message: string) => import("element-plus").MessageHandler;
@@ -9,4 +27,4 @@ declare function useMessage(options?: MessageProps): {
9
27
  closeAll: () => void;
10
28
  };
11
29
  //#endregion
12
- export { useMessage };
30
+ export { AsyncConfirmOptions, useAsyncConfirm, useMessage };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { ElMessage } from "element-plus";
1
+ import { useRequest } from "@vuetkit/core";
2
+ import { ElMessage, ElMessageBox } from "element-plus";
2
3
  //#region src/feedback/useMessage/index.ts
3
4
  const DEFAULT_DURATION = 3e3;
4
5
  const DEFAULT_SHOW_CLOSE = true;
@@ -44,4 +45,37 @@ function useMessage(options = {}) {
44
45
  };
45
46
  }
46
47
  //#endregion
47
- export { useMessage };
48
+ //#region src/feedback/useAsyncConfirm/index.ts
49
+ function useAsyncConfirm(confirmService, options) {
50
+ const { title = "Confirm", message = "Sure Confirm?", type = "error", confirmButtonText = "Sure", cancelButtonText = "Cancel", confirmSuccess, confirmError, successMessage, errorMessage } = options || {};
51
+ const { loading, execute: executeConfirm, error } = useRequest(confirmService, { manual: true });
52
+ const { success, error: showError } = useMessage();
53
+ function confirm(params) {
54
+ ElMessageBox.confirm(message, title, {
55
+ confirmButtonText,
56
+ cancelButtonText,
57
+ type,
58
+ beforeClose: async (action, instance, done) => {
59
+ if (action === "confirm") {
60
+ instance.confirmButtonLoading = true;
61
+ await executeConfirm(params);
62
+ instance.confirmButtonLoading = false;
63
+ if (error.value) {
64
+ if (errorMessage) showError(errorMessage);
65
+ confirmError === null || confirmError === void 0 || confirmError(error.value);
66
+ } else {
67
+ if (successMessage) success(successMessage);
68
+ confirmSuccess === null || confirmSuccess === void 0 || confirmSuccess();
69
+ }
70
+ done();
71
+ } else done();
72
+ }
73
+ }).catch(() => {});
74
+ }
75
+ return {
76
+ loading,
77
+ confirm
78
+ };
79
+ }
80
+ //#endregion
81
+ export { useAsyncConfirm, useMessage };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vuetkit/components",
3
3
  "type": "module",
4
- "version": "0.0.7",
4
+ "version": "0.0.8",
5
5
  "description": "Collection of business development components for Vue3 projects",
6
6
  "author": "Kalu5",
7
7
  "license": "MIT",