@fiscozen/dialog 0.1.13 → 0.1.15

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/dialog",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "description": "Design System Dialog component",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -9,9 +9,9 @@
9
9
  "peerDependencies": {
10
10
  "tailwindcss": "^3.4.1",
11
11
  "vue": "^3.4.13",
12
- "@fiscozen/button": "^0.1.6",
12
+ "@fiscozen/style": "^0.1.1",
13
13
  "@fiscozen/composables": "^0.1.25",
14
- "@fiscozen/style": "^0.1.1"
14
+ "@fiscozen/button": "^0.1.6"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
@@ -65,7 +65,8 @@ const props = withDefaults(defineProps<FzConfirmDialogProps>(), {
65
65
  disableConfirm: false,
66
66
  confirmButtonEnabled: true,
67
67
  doesCancelButtonCloseDialog: true,
68
- doesConfirmButtonCloseDialog: true
68
+ doesConfirmButtonCloseDialog: true,
69
+ unrenderOnClose: true
69
70
  });
70
71
  const emit = defineEmits(["fzmodal:confirm", "fzmodal:cancel"]);
71
72
 
package/src/FzDialog.vue CHANGED
@@ -1,11 +1,12 @@
1
1
  <template>
2
2
  <div
3
+ v-if="shouldRender || !props.unrenderOnClose"
3
4
  ref="backdrop"
4
5
  v-show="visible"
5
6
  class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-start sm:justify-center z-30">
6
7
  <dialog
7
8
  ref="dialog"
8
- @close="visible = false"
9
+ @close="closeModal"
9
10
  :class="[dialogStaticClasses, dialogClasses]"
10
11
  >
11
12
  <div ref="innerDialog" :class="[staticClasses, classes]">
@@ -29,7 +30,7 @@
29
30
  </template>
30
31
 
31
32
  <script setup lang="ts">
32
- import { computed, ref } from "vue";
33
+ import { computed, ref, watch } from "vue";
33
34
  import { FzDialogProps } from "./types";
34
35
  import { useKeyUp } from "@fiscozen/composables";
35
36
  import { useClickOutside } from "@fiscozen/composables";
@@ -37,6 +38,7 @@ import { useClickOutside } from "@fiscozen/composables";
37
38
  const props = withDefaults(defineProps<FzDialogProps>(), {
38
39
  size: "md",
39
40
  closeOnBackdrop: true,
41
+ unrenderOnClose: true
40
42
  });
41
43
  const emit = defineEmits(["fzmodal:cancel"]);
42
44
 
@@ -44,6 +46,7 @@ const dialog = ref<HTMLDialogElement>();
44
46
  const backdrop = ref<HTMLDialogElement>();
45
47
  const innerDialog = ref<HTMLDivElement>();
46
48
  const visible = ref(false);
49
+ const shouldRender = ref(false);
47
50
 
48
51
  let backdropClickTimeout = false;
49
52
 
@@ -51,14 +54,34 @@ const showModal = () => {
51
54
  backdropClickTimeout = true;
52
55
  setTimeout(() => {
53
56
  backdropClickTimeout = false;
54
- }, 100)
55
- dialog.value!.show();
56
- visible.value = true;
57
+ }, 100);
58
+
59
+ if (props.unrenderOnClose) {
60
+ shouldRender.value = true;
61
+ } else {
62
+ dialog.value!.show();
63
+ visible.value = true;
64
+ }
65
+ };
66
+
67
+ const closeModal = (returnVal?: string) => {
68
+ dialog.value!.close(returnVal);
69
+ visible.value = false;
70
+ if (props.unrenderOnClose) {
71
+ shouldRender.value = false;
72
+ }
57
73
  };
58
74
 
75
+ watch(dialog, (dialog) => {
76
+ if (dialog && shouldRender.value) {
77
+ dialog.show();
78
+ visible.value = true;
79
+ }
80
+ });
81
+
59
82
  defineExpose({
60
83
  show: showModal,
61
- close: (returnVal?: string): void => dialog.value!.close(returnVal),
84
+ close: closeModal,
62
85
  visible,
63
86
  });
64
87
 
package/src/types.ts CHANGED
@@ -39,6 +39,10 @@ export type FzDialogProps = {
39
39
  | string[]
40
40
  | Record<string, boolean | undefined>
41
41
  | Array<string | Record<string, boolean | undefined>>;
42
+ /**
43
+ * Whether the component gets unrendered on close
44
+ */
45
+ unrenderOnClose?: boolean;
42
46
  };
43
47
 
44
48
  export type FzConfirmDialogProps = FzDialogProps & {