@signal24/vue-foundation 4.5.0 → 4.6.0

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@signal24/vue-foundation",
3
3
  "type": "module",
4
- "version": "4.5.0",
4
+ "version": "4.6.0",
5
5
  "description": "Common components, directives, and helpers for Vue 3 apps",
6
6
  "module": "./dist/vue-foundation.es.js",
7
7
  "bin": {
@@ -6,5 +6,6 @@ import VfSmartSelect from './smart-select.vue';
6
6
 
7
7
  export * from './alert-helpers';
8
8
  export * from './overlay-container';
9
+ export * from './toast-helpers';
9
10
 
10
11
  export { VfAjaxSelect, VfAlertModal, VfEzSmartSelect, VfModal, VfSmartSelect };
@@ -0,0 +1,10 @@
1
+ import { createOverlayInjection, removeOverlayInjection } from './overlay-container';
2
+ import Toast, { type IToastOptions } from './toast.vue';
3
+
4
+ export function showToast(options: IToastOptions) {
5
+ const injection = createOverlayInjection(Toast, {
6
+ ...options,
7
+ callback: () => {}
8
+ });
9
+ return () => removeOverlayInjection(injection);
10
+ }
@@ -0,0 +1,63 @@
1
+ <template>
2
+ <div class="vf-toast" :class="className" @click.stop="handleClick">
3
+ <div class="content">
4
+ <div class="message">{{ message }}</div>
5
+ <div v-if="!disableClose" class="close">x</div>
6
+ </div>
7
+ <div v-if="durationSecs !== null" class="progress-bar">
8
+ <div ref="progressInnerEl" class="inner"></div>
9
+ </div>
10
+ </div>
11
+ </template>
12
+
13
+ <script lang="ts" setup>
14
+ import { onMounted, ref } from 'vue';
15
+
16
+ export interface IToastOptions {
17
+ message: string;
18
+ className?: string;
19
+ durationSecs?: number | null;
20
+ disableClose?: boolean;
21
+ onClick?: () => void;
22
+ }
23
+
24
+ const props = defineProps<
25
+ IToastOptions & {
26
+ callback: () => void;
27
+ }
28
+ >();
29
+
30
+ function handleClick() {
31
+ if (props.onClick) {
32
+ props.onClick();
33
+ } else if (!props.disableClose) {
34
+ props.callback();
35
+ }
36
+ }
37
+
38
+ const progressInnerEl = ref<HTMLElement>();
39
+ if (props.durationSecs !== null) {
40
+ onMounted(() => {
41
+ const durationSecs = props.durationSecs ?? 5;
42
+ progressInnerEl.value?.animate([{ width: '0%' }, { width: '100%' }], {
43
+ duration: durationSecs * 1000,
44
+ easing: 'linear'
45
+ });
46
+ setTimeout(() => props.callback(), durationSecs * 1000);
47
+ });
48
+ }
49
+ </script>
50
+
51
+ <style lang="scss">
52
+ .vf-toast {
53
+ position: absolute;
54
+ bottom: 50px;
55
+ left: 50%;
56
+ transform: translateX(-50%);
57
+ }
58
+
59
+ .vf-toast .content {
60
+ display: flex;
61
+ align-items: center;
62
+ }
63
+ </style>
@@ -53,7 +53,7 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
53
53
  }
54
54
 
55
55
  if (item.shouldConfirm) {
56
- itemEl.addEventListener('click', () => confirmAction(itemEl, item.handler));
56
+ itemEl.addEventListener('click', e => confirmAction(e, itemEl, item.handler));
57
57
  } else {
58
58
  itemEl.addEventListener('click', () => item.handler());
59
59
  }
@@ -85,7 +85,7 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
85
85
  wrapperEl.remove();
86
86
  }
87
87
 
88
- function confirmAction(itemEl: HTMLElement, handler: () => void) {
88
+ function confirmAction(e: MouseEvent, itemEl: HTMLElement, handler: () => void) {
89
89
  if (itemEl.classList.contains('pending-confirm')) {
90
90
  return handler();
91
91
  }
@@ -106,4 +106,3 @@ export function showContextMenu(e: MouseEvent, config: ContextMenuConfig) {
106
106
  }
107
107
 
108
108
  // TODO: actually de-select text rather than just using CSS to hide its selection
109
- // TODO: confirm isn't working