@fiscozen/dialog 0.1.19 → 0.1.21

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 +7 -7
  2. package/src/FzDialog.vue +39 -82
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fiscozen/dialog",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
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/composables": "^0.1.29",
13
- "@fiscozen/button": "^0.1.7",
14
- "@fiscozen/style": "^0.1.1"
12
+ "@fiscozen/style": "^0.1.2",
13
+ "@fiscozen/composables": "^0.1.30",
14
+ "@fiscozen/button": "^0.1.7"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@fortawesome/fontawesome-svg-core": "^6.5.1",
@@ -32,13 +32,13 @@
32
32
  "vitest": "^1.2.0",
33
33
  "vue-tsc": "^1.8.25",
34
34
  "@fiscozen/eslint-config": "^0.1.0",
35
- "@fiscozen/prettier-config": "^0.1.0",
36
- "@fiscozen/tsconfig": "^0.1.0"
35
+ "@fiscozen/tsconfig": "^0.1.0",
36
+ "@fiscozen/prettier-config": "^0.1.0"
37
37
  },
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
40
  "dialog-polyfill": "^0.5.6",
41
- "@fiscozen/composables": "^0.1.29"
41
+ "@fiscozen/composables": "^0.1.30"
42
42
  },
43
43
  "scripts": {
44
44
  "coverage": "vitest run --coverage",
package/src/FzDialog.vue CHANGED
@@ -3,7 +3,8 @@
3
3
  v-if="shouldRender || shouldAlwaysRender"
4
4
  ref="backdrop"
5
5
  v-show="visible"
6
- class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-start sm:justify-center z-30">
6
+ class="fz-dialog__backdrop w-screen h-screen fixed flex flex-col items-center justify-start sm:justify-center z-30"
7
+ >
7
8
  <dialog
8
9
  ref="dialog"
9
10
  @close="handleModalClose"
@@ -15,7 +16,7 @@
15
16
  >
16
17
  <slot name="header"></slot>
17
18
  </div>
18
- <div :class="['grow', 'p-12', bodyClasses]">
19
+ <div :class="['grow p-12 overflow-auto', bodyClasses]">
19
20
  <slot name="body"></slot>
20
21
  </div>
21
22
  <div
@@ -30,16 +31,16 @@
30
31
  </template>
31
32
 
32
33
  <script setup lang="ts">
33
- import { computed, ref, watch } from "vue";
34
+ import {computed, onMounted, onUnmounted, ref, watch} from "vue";
34
35
  import { FzDialogProps } from "./types";
35
36
  import { useKeyUp } from "@fiscozen/composables";
36
37
  import { useClickOutside } from "@fiscozen/composables";
37
- import dialogPolyfill from 'dialog-polyfill';
38
- import 'dialog-polyfill/dist/dialog-polyfill.css';
38
+ import dialogPolyfill from "dialog-polyfill";
39
+ import "dialog-polyfill/dist/dialog-polyfill.css";
39
40
 
40
41
  const props = withDefaults(defineProps<FzDialogProps>(), {
41
42
  size: "md",
42
- closeOnBackdrop: true
43
+ closeOnBackdrop: true,
43
44
  });
44
45
  const emit = defineEmits(["fzmodal:cancel"]);
45
46
 
@@ -49,18 +50,28 @@ const innerDialog = ref<HTMLDivElement>();
49
50
  const visible = ref(false);
50
51
  const shouldRender = ref(false);
51
52
 
52
- let backdropClickTimeout = false;
53
+ function updateInnerHeightVar() {
54
+ dialog.value?.style.setProperty('--innerHeight', `${window.innerHeight}px`);
55
+ }
56
+
57
+ function handleDialogRendered() {
58
+ updateInnerHeightVar();
59
+ dialogPolyfill.registerDialog(dialog.value!);
60
+ dialog.value!.show();
61
+ visible.value = true;
62
+ }
63
+
64
+ onMounted(() => {
65
+ window.addEventListener('resize', updateInnerHeightVar);
66
+ });
67
+
68
+ onUnmounted(() => {
69
+ window.removeEventListener('resize', updateInnerHeightVar);
70
+ });
53
71
 
54
72
  const showModal = () => {
55
- backdropClickTimeout = true;
56
- setTimeout(() => {
57
- backdropClickTimeout = false;
58
- }, 100);
59
-
60
73
  if (props.shouldAlwaysRender) {
61
- dialogPolyfill.registerDialog(dialog.value!);
62
- dialog.value!.show();
63
- visible.value = true;
74
+ handleDialogRendered();
64
75
  } else {
65
76
  shouldRender.value = true;
66
77
  }
@@ -79,9 +90,7 @@ function handleModalClose() {
79
90
 
80
91
  watch(dialog, (dialog) => {
81
92
  if (dialog && shouldRender.value) {
82
- dialogPolyfill.registerDialog(dialog);
83
- dialog.show();
84
- visible.value = true;
93
+ handleDialogRendered();
85
94
  }
86
95
  });
87
96
 
@@ -115,91 +124,39 @@ const staticClasses = "flex flex-col bg-core-white";
115
124
  const dialogStaticClasses = "border-1 rounded border-grey-100 p-0";
116
125
 
117
126
  const dialogClasses = computed(() => {
118
- let res: string[] = [];
119
127
  if (props.isDrawer) {
120
- res = ["m-0", "fixed", "top-0", "ml-auto", "max-h-screen"];
121
- return res;
128
+ return "m-0 fixed top-0 ml-auto max-h-screen";
122
129
  }
130
+
123
131
  switch (props.size) {
124
- case "sm":
125
- res = [];
126
- break;
127
132
  case "md":
128
- res = [
129
- "xs:max-sm:m-0",
130
- "xs:max-sm:max-h-screen",
131
- "xs:max-sm:h-dvh",
132
- "xs:max-sm:w-dvw",
133
- "xs:max-sm:max-w-screen-xl",
134
- ];
135
- break;
133
+ return "xs:max-sm:m-0 xs:max-sm:max-h-screen xs:max-sm:h-dvh xs:max-sm:w-dvw xs:max-sm:max-w-screen-xl";
136
134
  case "lg":
137
- res = [
138
- "xs:max-md:m-0",
139
- "xs:max-md:max-h-screen",
140
- "xs:max-md:h-dvh",
141
- "xs:max-md:w-dvw",
142
- "xs:max-md:max-w-screen-xl",
143
- ];
144
- break;
135
+ return "xs:max-md:m-0 xs:max-md:max-h-screen xs:max-md:h-dvh xs:max-md:w-dvw xs:max-md:max-w-screen-xl";
145
136
  case "xl":
146
- res = [
147
- "xs:max-xl:m-0",
148
- "xs:max-xl:max-h-screen",
149
- "xs:max-xl:h-dvh",
150
- "xs:max-xl:w-dvw",
151
- "xs:max-xl:max-w-screen-xl",
152
- ];
153
- break;
154
- default:
155
- res = [];
156
- break;
137
+ return "xs:max-xl:m-0 xs:max-xl:max-h-screen xs:max-xl:h-dvh xs:max-xl:w-dvw xs:max-xl:max-w-screen-xl";
157
138
  }
158
- return res;
159
139
  });
160
140
 
161
141
  const classes = computed(() => {
162
- let res: string[] = [];
163
142
  if (props.isDrawer) {
164
- res = ["w-[480px]", "h-dvh"];
165
- return res;
143
+ return "w-[480px] h-dvh";
166
144
  }
145
+
167
146
  switch (props.size) {
168
147
  case "sm":
169
- res = ["w-[320px]", "min-h-[200px]", "max-h-[432px]"];
170
- break;
148
+ return "w-[320px] min-h-[200px] max-h-[432px]";
171
149
  case "md":
172
- res = [
173
- "w-dvw sm:w-[480px]",
174
- "min-h-[300px]",
175
- "sm:max-h-[600px]",
176
- "h-dvh sm:h-auto",
177
- ];
178
- break;
150
+ return "w-dvw sm:w-[480px] min-h-[300px] sm:max-h-[600px] h-dvh sm:h-auto";
179
151
  case "lg":
180
- res = [
181
- "w-dvw md:w-[640px]",
182
- "min-h-[300px]",
183
- "md:max-h-[600px]",
184
- "h-dvh md:h-auto",
185
- ];
186
- break;
152
+ return "w-dvw md:w-[640px] min-h-[300px] md:max-h-[600px] h-dvh md:h-auto";
187
153
  case "xl":
188
- res = [
189
- "w-dvw xl:w-[960px]",
190
- "min-h-[400px]",
191
- "xl:max-h-[600px]",
192
- "h-dvh xl:h-auto",
193
- ];
194
- break;
195
- default:
196
- break;
154
+ return "w-dvw xl:w-[960px] min-h-[400px] xl:max-h-[600px] h-dvh xl:h-auto";
197
155
  }
198
- return res;
199
156
  });
200
157
  </script>
201
158
 
202
- <style>
159
+ <style scoped>
203
160
  dialog::backdrop {
204
161
  background: var(--core-black, #2c282f);
205
162
  opacity: 0.8;