@fiscozen/dialog 0.1.9 → 0.1.11

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 +8 -5
  2. package/src/FzDialog.vue +14 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/dialog",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Design System Dialog component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -11,9 +11,11 @@
11
11
  "vue": "^3.4.13",
12
12
  "@fiscozen/button": "^0.1.6",
13
13
  "@fiscozen/style": "^0.1.1",
14
- "@fiscozen/composables": "^0.1.10"
14
+ "@fiscozen/composables": "^0.1.15"
15
15
  },
16
16
  "devDependencies": {
17
+ "@fortawesome/fontawesome-svg-core": "^6.5.1",
18
+ "@fortawesome/vue-fontawesome": "^3.0.6",
17
19
  "@rushstack/eslint-patch": "^1.3.3",
18
20
  "@types/jsdom": "^21.1.6",
19
21
  "@types/node": "^18.19.3",
@@ -21,21 +23,22 @@
21
23
  "@vitest/coverage-v8": "^1.2.1",
22
24
  "@vue/test-utils": "^2.4.3",
23
25
  "@vue/tsconfig": "^0.5.0",
24
- "vite-plugin-dts": "^3.8.3",
25
26
  "eslint": "^8.49.0",
26
27
  "jsdom": "^23.0.1",
27
28
  "prettier": "^3.0.3",
28
29
  "typescript": "~5.3.0",
29
30
  "vite": "^5.0.10",
31
+ "vite-plugin-dts": "^3.8.3",
30
32
  "vitest": "^1.2.0",
31
33
  "vue-tsc": "^1.8.25",
32
- "@fortawesome/fontawesome-svg-core": "^6.5.1",
33
- "@fortawesome/vue-fontawesome": "^3.0.6",
34
34
  "@fiscozen/eslint-config": "^0.1.0",
35
35
  "@fiscozen/prettier-config": "^0.1.0",
36
36
  "@fiscozen/tsconfig": "^0.1.0"
37
37
  },
38
38
  "license": "MIT",
39
+ "dependencies": {
40
+ "@fiscozen/composables": "^0.1.15"
41
+ },
39
42
  "scripts": {
40
43
  "coverage": "vitest run --coverage",
41
44
  "format": "prettier --write src/",
package/src/FzDialog.vue CHANGED
@@ -1,13 +1,14 @@
1
1
  <template>
2
2
  <div
3
+ ref="backdrop"
3
4
  v-show="visible"
4
- class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-center">
5
+ class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-center z-30">
5
6
  <dialog
6
7
  ref="dialog"
7
8
  @close="visible = false"
8
9
  :class="[dialogStaticClasses, dialogClasses]"
9
10
  >
10
- <div :class="[staticClasses, classes]">
11
+ <div ref="innerDialog" :class="[staticClasses, classes]">
11
12
  <div
12
13
  class="flex items-center p-12 w-full border-b-1 border-grey-100 border-solid"
13
14
  >
@@ -28,9 +29,10 @@
28
29
  </template>
29
30
 
30
31
  <script setup lang="ts">
31
- import { computed, ref, onMounted, onUnmounted } from "vue";
32
+ import { computed, ref } from "vue";
32
33
  import { FzDialogProps } from "./types";
33
34
  import { useKeyUp } from "@fiscozen/composables";
35
+ import { useClickOutside } from "@fiscozen/composables";
34
36
 
35
37
  const props = withDefaults(defineProps<FzDialogProps>(), {
36
38
  size: "md",
@@ -39,6 +41,8 @@ const props = withDefaults(defineProps<FzDialogProps>(), {
39
41
  const emit = defineEmits(["fzmodal:cancel"]);
40
42
 
41
43
  const dialog = ref<HTMLDialogElement>();
44
+ const backdrop = ref<HTMLDialogElement>();
45
+ const innerDialog = ref<HTMLDivElement>();
42
46
  const visible = ref(false);
43
47
 
44
48
  let backdropClickTimeout = false;
@@ -58,21 +62,15 @@ defineExpose({
58
62
  visible,
59
63
  });
60
64
 
61
- const handleBackdropClick = (event: MouseEvent) => {
62
- if (backdropClickTimeout || !visible.value) {
63
- return;
64
- }
65
- var rect = dialog.value!.getBoundingClientRect();
66
- var isInDialog =
67
- rect.top <= event.clientY &&
68
- event.clientY <= rect.top + rect.height &&
69
- rect.left <= event.clientX &&
70
- event.clientX <= rect.left + rect.width;
71
- if (!isInDialog && props.closeOnBackdrop) {
65
+ useClickOutside(
66
+ innerDialog,
67
+ () => {
68
+ if (!props.closeOnBackdrop) return;
72
69
  dialog.value!.close();
73
70
  emit("fzmodal:cancel");
74
- }
75
- };
71
+ },
72
+ backdrop,
73
+ );
76
74
 
77
75
  const handleKeyUp = (e: KeyboardEvent) => {
78
76
  if (!visible.value || e.key !== "Escape") {
@@ -84,13 +82,6 @@ const handleKeyUp = (e: KeyboardEvent) => {
84
82
 
85
83
  useKeyUp(handleKeyUp);
86
84
 
87
- onMounted(() => {
88
- document.addEventListener("click", handleBackdropClick);
89
- });
90
- onUnmounted(() => {
91
- document.removeEventListener("click", handleBackdropClick);
92
- });
93
-
94
85
  const staticClasses = ["flex", "flex-col", "bg-core-white"];
95
86
 
96
87
  const dialogStaticClasses = {