@fiscozen/dialog 0.1.8 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/FzDialog.vue +43 -24
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/dialog",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Design System Dialog component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
package/src/FzDialog.vue CHANGED
@@ -1,26 +1,30 @@
1
1
  <template>
2
- <dialog
3
- ref="dialog"
4
- @close="visible = false"
5
- :class="[dialogStaticClasses, dialogClasses]"
6
- >
7
- <div :class="[staticClasses, classes]">
8
- <div
9
- class="flex items-center p-12 w-full border-b-1 border-grey-100 border-solid"
10
- >
11
- <slot name="header"></slot>
2
+ <div
3
+ v-show="visible"
4
+ class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-center">
5
+ <dialog
6
+ ref="dialog"
7
+ @close="visible = false"
8
+ :class="[dialogStaticClasses, dialogClasses]"
9
+ >
10
+ <div :class="[staticClasses, classes]">
11
+ <div
12
+ class="flex items-center p-12 w-full border-b-1 border-grey-100 border-solid"
13
+ >
14
+ <slot name="header"></slot>
15
+ </div>
16
+ <div :class="['grow', 'p-12', bodyClasses]">
17
+ <slot name="body"></slot>
18
+ </div>
19
+ <div
20
+ v-if="$slots.footer"
21
+ class="flex flex-row p-12 border-t-1 border-grey-100 items-center border-solid"
22
+ >
23
+ <slot name="footer"></slot>
24
+ </div>
12
25
  </div>
13
- <div :class="['grow', 'p-12', bodyClasses]">
14
- <slot name="body"></slot>
15
- </div>
16
- <div
17
- v-if="$slots.footer"
18
- class="flex flex-row p-12 border-t-1 border-grey-100 items-center border-solid"
19
- >
20
- <slot name="footer"></slot>
21
- </div>
22
- </div>
23
- </dialog>
26
+ </dialog>
27
+ </div>
24
28
  </template>
25
29
 
26
30
  <script setup lang="ts">
@@ -37,8 +41,14 @@ const emit = defineEmits(["fzmodal:cancel"]);
37
41
  const dialog = ref<HTMLDialogElement>();
38
42
  const visible = ref(false);
39
43
 
44
+ let backdropClickTimeout = false;
45
+
40
46
  const showModal = () => {
41
- dialog.value!.showModal();
47
+ backdropClickTimeout = true;
48
+ setTimeout(() => {
49
+ backdropClickTimeout = false;
50
+ }, 100)
51
+ dialog.value!.show();
42
52
  visible.value = true;
43
53
  };
44
54
 
@@ -49,6 +59,9 @@ defineExpose({
49
59
  });
50
60
 
51
61
  const handleBackdropClick = (event: MouseEvent) => {
62
+ if (backdropClickTimeout || !visible.value) {
63
+ return;
64
+ }
52
65
  var rect = dialog.value!.getBoundingClientRect();
53
66
  var isInDialog =
54
67
  rect.top <= event.clientY &&
@@ -65,16 +78,17 @@ const handleKeyUp = (e: KeyboardEvent) => {
65
78
  if (!visible.value || e.key !== "Escape") {
66
79
  return;
67
80
  }
81
+ dialog.value!.close();
68
82
  emit("fzmodal:cancel");
69
83
  };
70
84
 
71
85
  useKeyUp(handleKeyUp);
72
86
 
73
87
  onMounted(() => {
74
- dialog.value?.addEventListener("click", handleBackdropClick);
88
+ document.addEventListener("click", handleBackdropClick);
75
89
  });
76
90
  onUnmounted(() => {
77
- dialog.value?.removeEventListener("click", handleBackdropClick);
91
+ document.removeEventListener("click", handleBackdropClick);
78
92
  });
79
93
 
80
94
  const staticClasses = ["flex", "flex-col", "bg-core-white"];
@@ -175,4 +189,9 @@ dialog::backdrop {
175
189
  background: var(--core-black, #2c282f);
176
190
  opacity: 0.8;
177
191
  }
192
+ .fz-dialog__backdrop {
193
+ background-color: rgba(44, 40, 47, 0.8);
194
+ top: 0;
195
+ left: 0;
196
+ }
178
197
  </style>