@@ -77,6 +77,56 @@ interface DialogButton {
7777 options? : Record <string , any >
7878}
7979
80+ const modalRef = ref ();
81+
82+ const props = withDefaults (defineProps <DialogProps >(), {
83+ header: ' ' ,
84+ headerCloseButton: true ,
85+ buttons : () => [],
86+ clickToCloseOutside: false ,
87+ closeByEsc: true ,
88+ closeByClickOutside: true ,
89+ beforeCloseFunction: null ,
90+ beforeOpenFunction: null ,
91+ closable: false ,
92+ askForCloseConfirmation: false ,
93+ closeConfirmationText: ' Are you sure you want to close this dialog?' ,
94+ removeFromDomOnClose: false ,
95+ })
96+
97+ const buttons = computed <DialogButton []>(() => {
98+ if (props .buttons && props .buttons .length > 0 ) {
99+ return props .buttons ;
100+ }
101+ return [
102+ {
103+ label: ' Close' ,
104+ onclick : (dialog : any ) => {
105+ tryToHideModal ();
106+ },
107+ options: {}
108+ }
109+ ];
110+ });
111+
112+
113+ function open() {
114+ modalRef .value .open ();
115+ }
116+
117+ function close() {
118+ modalRef .value .close ();
119+ }
120+
121+ defineExpose ({
122+ open: open ,
123+ close: close ,
124+ tryToHideModal: tryToHideModal ,
125+ })
126+
127+ function tryToHideModal() {
128+ modalRef .value ?.tryToHideModal ();
129+ }
80130
81131interface DialogProps {
82132 /**
@@ -114,7 +164,7 @@ interface DialogProps {
114164 /**
115165 * Function that will be called before the dialog is closed.
116166 */
117- beforeCloseFunction? : (() => void | Promise <void >) | null
167+ beforeCloseFunction? : (() => void | Promise <void | boolean >) | null
118168
119169 /**
120170 * Function that will be called before the dialog is opened.
@@ -167,58 +217,4 @@ const dialog: Ref<Dialog> = ref(
167217);
168218/** ***********************************************************/
169219
170-
171-
172- const modalRef = ref ();
173-
174- const props = withDefaults (defineProps <DialogProps >(), {
175- header: ' ' ,
176- headerCloseButton: true ,
177- buttons : () => [],
178- clickToCloseOutside: false ,
179- closeByEsc: true ,
180- closeByClickOutside: true ,
181- beforeCloseFunction: null ,
182- beforeOpenFunction: null ,
183- closable: false ,
184- askForCloseConfirmation: false ,
185- closeConfirmationText: ' Are you sure you want to close this dialog?' ,
186- removeFromDomOnClose: false ,
187- })
188-
189- const buttons = computed <DialogButton []>(() => {
190- if (props .buttons && props .buttons .length > 0 ) {
191- return props .buttons ;
192- }
193- return [
194- {
195- label: ' Close' ,
196- onclick : (dialog : any ) => {
197- tryToHideModal ();
198- },
199- options: {}
200- }
201- ];
202- });
203-
204-
205- function open() {
206- modalRef .value .open ();
207- }
208-
209- function close() {
210- modalRef .value .close ();
211- }
212-
213- defineExpose ({
214- open: open ,
215- close: close ,
216- tryToHideModal: tryToHideModal ,
217- })
218-
219- function tryToHideModal() {
220- modalRef .value ?.tryToHideModal ();
221- }
222-
223-
224220 </script >
0 commit comments