@nexdom/uimed-vue 2.0.0-beta.7 → 2.0.0-beta.9
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/AGENTS.md +85 -12
- package/README.md +1 -1
- package/dist/components.d.ts +128 -60
- package/dist/components.js +339 -70
- package/dist/composables.d.ts +130 -4
- package/dist/composables.js +55 -3
- package/dist/types-HPMP8IrV.d.ts +49 -0
- package/dist/use-dialog-Ck2_ZW7T.js +124 -0
- package/package.json +1 -1
- package/dist/types-BPXXtbmW.d.ts +0 -5
- package/dist/use-toast-CACuYhK_.js +0 -53
package/dist/composables.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as useDialog, o as useToast, t as openDialog } from "./use-dialog-Ck2_ZW7T.js";
|
|
2
2
|
import { computed, ref } from "vue";
|
|
3
|
-
//#region src/composables/dialogs/use-run-or-toast
|
|
3
|
+
//#region src/composables/dialogs/use-run-or-toast.ts
|
|
4
4
|
const { toast } = useToast();
|
|
5
5
|
/**
|
|
6
6
|
* Generate `run` method and a computed property `isRunning`.
|
|
@@ -62,4 +62,56 @@ function useRunOrToast() {
|
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
//#endregion
|
|
65
|
-
|
|
65
|
+
//#region src/composables/dialogs/use-confirm.ts
|
|
66
|
+
/**
|
|
67
|
+
* Composable which returns a function to run actions only after the user confirms them in a
|
|
68
|
+
* dialog, and a computed property `isRunning`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const { confirm, isRunning } = useConfirm();
|
|
73
|
+
*
|
|
74
|
+
* const removed = await confirm(
|
|
75
|
+
* { title: "Excluir paciente", message: "Esta ação não pode ser desfeita.", confirmText: "Excluir", color: "danger" },
|
|
76
|
+
* () => api.deletePatient(id),
|
|
77
|
+
* );
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
function useConfirm() {
|
|
81
|
+
const { run, isRunning } = useRunOrToast();
|
|
82
|
+
/**
|
|
83
|
+
* Displays a confirmation dialog and, if the user confirms, runs the given function while the
|
|
84
|
+
* dialog shows the confirm button loading. If the function throws an error, the dialog closes
|
|
85
|
+
* and a toast shows the error message.
|
|
86
|
+
* @returns the function returned value, or `false` if the user cancels or the function fails
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const { confirm } = useConfirm();
|
|
91
|
+
*
|
|
92
|
+
* // Call like this:
|
|
93
|
+
* const result1 = await confirm({ message: "Salvar alterações?" }, () => save(form));
|
|
94
|
+
*
|
|
95
|
+
* // Or this:
|
|
96
|
+
* const result2 = await confirm({ message: "Salvar alterações?" }, save, form);
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function confirm(options, action, ...params) {
|
|
100
|
+
return openDialog({
|
|
101
|
+
title: options.title,
|
|
102
|
+
message: options.message,
|
|
103
|
+
role: "alertdialog",
|
|
104
|
+
actions: [{ text: options.cancelText ?? "Cancelar" }, {
|
|
105
|
+
text: options.confirmText ?? "Confirmar",
|
|
106
|
+
value: "confirm",
|
|
107
|
+
color: options.color
|
|
108
|
+
}]
|
|
109
|
+
}, (value) => value === "confirm" ? run(action, ...params) : false);
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
confirm,
|
|
113
|
+
isRunning
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { useConfirm, useDialog, useRunOrToast, useToast };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/composables/colors/types.d.ts
|
|
2
|
+
type ColorVariant = "primary" | "secondary" | FeedbackColorVariant;
|
|
3
|
+
type FeedbackColorVariant = "positive" | "informative" | "caution" | "danger";
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/components/button/types.d.ts
|
|
6
|
+
type ButtonVariant = "primary" | "secondary" | "ghost";
|
|
7
|
+
/**
|
|
8
|
+
* Props exposed by the {@link Button} component.
|
|
9
|
+
*/
|
|
10
|
+
type ButtonProps = {
|
|
11
|
+
/**
|
|
12
|
+
* Applies a distinct style variation to the button.
|
|
13
|
+
* One of `primary`, `secondary`, or `ghost`.
|
|
14
|
+
* @default "primary"
|
|
15
|
+
*/
|
|
16
|
+
variant?: ButtonVariant;
|
|
17
|
+
/**
|
|
18
|
+
* Applies a distinct behavior to the button.
|
|
19
|
+
* One of `button` or `submit`.
|
|
20
|
+
* @default "button"
|
|
21
|
+
*/
|
|
22
|
+
type?: "submit" | "button";
|
|
23
|
+
/**
|
|
24
|
+
* Applies a color to the button.
|
|
25
|
+
* One of `primary`, `secondary`, `positive`, `informative`, `caution`, or `danger`.
|
|
26
|
+
* @default "primary"
|
|
27
|
+
*/
|
|
28
|
+
color?: ColorVariant;
|
|
29
|
+
/**
|
|
30
|
+
* Removes the ability to click or target the button.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Displays a loading indicator on the button, disabling interaction.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
loading?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Associated [form](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/form) id.
|
|
41
|
+
*/
|
|
42
|
+
form?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Component id to use on automated tests.
|
|
45
|
+
*/
|
|
46
|
+
dataTestid?: string;
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { FeedbackColorVariant as i, ButtonVariant as n, ColorVariant as r, ButtonProps as t };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { computed, ref, toValue } from "vue";
|
|
2
|
+
const colorToVuetifyColor = {
|
|
3
|
+
primary: "primary",
|
|
4
|
+
secondary: "secondary",
|
|
5
|
+
positive: "success",
|
|
6
|
+
informative: "info",
|
|
7
|
+
caution: "warning",
|
|
8
|
+
danger: "error"
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/composables/colors/use-vuetify-color.ts
|
|
12
|
+
function useVuetifyColor(color) {
|
|
13
|
+
return computed(() => {
|
|
14
|
+
const colorValue = toValue(color);
|
|
15
|
+
return colorValue ? colorToVuetifyColor[colorValue] : colorToVuetifyColor.primary;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/composables/dialogs/use-toast.ts
|
|
20
|
+
const messages = ref([]);
|
|
21
|
+
/**
|
|
22
|
+
* Composable which returns a function to display toast messages.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* const { toast } = useToast();
|
|
27
|
+
* toast({ message: "Hello, World!" });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function useToast() {
|
|
31
|
+
return { toast };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Displays a toast message.
|
|
35
|
+
* @param {ToastOptions} options - Options for the toast message.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* toast({ message: "Hello, World!" });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
function toast(options) {
|
|
43
|
+
const text = options.message;
|
|
44
|
+
const color = useVuetifyColor(options.color ?? "informative");
|
|
45
|
+
const toastMessage = {
|
|
46
|
+
text,
|
|
47
|
+
color: color.value,
|
|
48
|
+
prependIcon: `$${color.value}`
|
|
49
|
+
};
|
|
50
|
+
messages.value.push(toastMessage);
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/composables/dialogs/use-dialog.ts
|
|
54
|
+
/**
|
|
55
|
+
* Dialogs waiting to be displayed, shared by `useDialog` and `useConfirm`. The first one is the
|
|
56
|
+
* dialog on display (or about to be).
|
|
57
|
+
*/
|
|
58
|
+
const requests = ref([]);
|
|
59
|
+
/**
|
|
60
|
+
* Mounted `Dialog` components, in mounting order. Only the first one displays dialogs, so pages
|
|
61
|
+
* with more than one `UMain` don't display duplicates.
|
|
62
|
+
*/
|
|
63
|
+
const owners = ref([]);
|
|
64
|
+
/**
|
|
65
|
+
* Queues a dialog and resolves with what `onSelect` returns for the clicked action's value
|
|
66
|
+
* (`undefined` when the dialog is dismissed).
|
|
67
|
+
*/
|
|
68
|
+
function openDialog(options, onSelect) {
|
|
69
|
+
const { actions, ...content } = options;
|
|
70
|
+
const lastIndex = actions.length - 1;
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
requests.value.push({
|
|
73
|
+
...content,
|
|
74
|
+
actions: actions.map((action, index) => ({
|
|
75
|
+
...action,
|
|
76
|
+
variant: action.variant ?? (index === lastIndex ? "primary" : "ghost")
|
|
77
|
+
})),
|
|
78
|
+
async select(value) {
|
|
79
|
+
resolve(await onSelect(value));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Composable which returns a function to display dialogs.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* const { dialog } = useDialog();
|
|
90
|
+
*
|
|
91
|
+
* const answer = await dialog({
|
|
92
|
+
* title: "Sessão expirando",
|
|
93
|
+
* message: "Deseja continuar conectado?",
|
|
94
|
+
* actions: [
|
|
95
|
+
* { text: "Sair", value: "leave" },
|
|
96
|
+
* { text: "Continuar", value: "stay" },
|
|
97
|
+
* ],
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function useDialog() {
|
|
102
|
+
return { dialog };
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Displays a dialog. Dialogs are displayed one at a time, in the order they were requested.
|
|
106
|
+
* @param {DialogOptions} options - Options for the dialog.
|
|
107
|
+
* @returns the `value` of the clicked action, or `undefined` when the dialog is closed by the
|
|
108
|
+
* default action, the `Esc` key, a click outside it or the browser's back button.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* await dialog({ title: "Aviso", message: "Seu cadastro foi enviado para análise." });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
function dialog(options) {
|
|
116
|
+
return openDialog({
|
|
117
|
+
title: options.title,
|
|
118
|
+
message: options.message,
|
|
119
|
+
role: "dialog",
|
|
120
|
+
actions: options.actions ?? [{ text: "Fechar" }]
|
|
121
|
+
}, (value) => value);
|
|
122
|
+
}
|
|
123
|
+
//#endregion
|
|
124
|
+
export { messages as a, useDialog as i, owners as n, useToast as o, requests as r, useVuetifyColor as s, openDialog as t };
|
package/package.json
CHANGED
package/dist/types-BPXXtbmW.d.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { computed, ref, toValue } from "vue";
|
|
2
|
-
const colorToVuetifyColor = {
|
|
3
|
-
primary: "primary",
|
|
4
|
-
secondary: "secondary",
|
|
5
|
-
positive: "success",
|
|
6
|
-
informative: "info",
|
|
7
|
-
caution: "warning",
|
|
8
|
-
danger: "error"
|
|
9
|
-
};
|
|
10
|
-
//#endregion
|
|
11
|
-
//#region src/composables/colors/use-vuetify-color.ts
|
|
12
|
-
function useVuetifyColor(color) {
|
|
13
|
-
return computed(() => {
|
|
14
|
-
const colorValue = toValue(color);
|
|
15
|
-
return colorValue ? colorToVuetifyColor[colorValue] : colorToVuetifyColor.primary;
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/composables/dialogs/use-toast.ts
|
|
20
|
-
const messages = ref([]);
|
|
21
|
-
/**
|
|
22
|
-
* Composable which returns a function to display toast messages.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```ts
|
|
26
|
-
* const { toast } = useToast();
|
|
27
|
-
* toast({ message: "Hello, World!" });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
function useToast() {
|
|
31
|
-
return { toast };
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Displays a toast message.
|
|
35
|
-
* @param {ToastOptions} options - Options for the toast message.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* toast({ message: "Hello, World!" });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
function toast(options) {
|
|
43
|
-
const text = options.message;
|
|
44
|
-
const color = useVuetifyColor(options.color ?? "informative");
|
|
45
|
-
const toastMessage = {
|
|
46
|
-
text,
|
|
47
|
-
color: color.value,
|
|
48
|
-
prependIcon: `$${color.value}`
|
|
49
|
-
};
|
|
50
|
-
messages.value.push(toastMessage);
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { useToast as n, useVuetifyColor as r, messages as t };
|