Skip to content

Commit 92e515c

Browse files
committed
chore: move dialog types from frontend api to the dialog component
1 parent 2dce379 commit 92e515c

File tree

3 files changed

+103
-84
lines changed

3 files changed

+103
-84
lines changed

adminforth/spa/src/afcl/Dialog.vue

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,93 @@ import Button from "./Button.vue";
6161
import { ref, computed, type Ref } from 'vue';
6262
import { Modal } from '@/afcl'
6363
import { useI18n } from "vue-i18n";
64-
import type { IDialogInsideButtonClickHandler, DialogButton, DialogProps } from '@/types/FrontendAPI';
6564
6665
const { t } = useI18n();
6766
6867
68+
interface IDialogInsideButtonClickHandler {
69+
hide: () => void
70+
}
71+
72+
73+
interface DialogButton {
74+
label: string
75+
onclick: (dialog: IDialogInsideButtonClickHandler) => void
76+
options?: Record<string, any>
77+
}
78+
79+
80+
interface DialogProps {
81+
/**
82+
* The header text to display in the dialog. If not provided, no header will be displayed.
83+
*/
84+
header?: string
85+
86+
/**
87+
* If true, a close button will be displayed in the dialog header. Default is true.
88+
*/
89+
headerCloseButton?: boolean
90+
91+
/**
92+
* An array of buttons to display in the dialog footer.
93+
*/
94+
buttons?: DialogButton[]
95+
96+
/**
97+
* If true, clicking outside the dialog will close it. Default is true.
98+
*
99+
* @deprecated Use `closeByClickOutside` instead
100+
*/
101+
clickToCloseOutside?: boolean
102+
103+
/**
104+
* If true, pressing the Esc key will close the dialog. Default is true.
105+
*/
106+
closeByEsc?: boolean
107+
108+
/**
109+
* If true, clicking outside the dialog will close it. Default is true.
110+
*/
111+
closeByClickOutside?: boolean
112+
113+
/**
114+
* Function that will be called before the dialog is closed.
115+
*/
116+
beforeCloseFunction?: (() => void | Promise<void>) | null
117+
118+
/**
119+
* Function that will be called before the dialog is opened.
120+
*/
121+
beforeOpenFunction?: (() => void | Promise<void>) | null
122+
123+
/**
124+
* Disables close on Ecs button
125+
*
126+
* @deprecated Use `closeByEsc` or instead
127+
*/
128+
closable?: boolean
129+
130+
/**
131+
* If true, the dialog will ask for confirmation before closing. Default is false.
132+
*/
133+
askForCloseConfirmation?: boolean
134+
135+
/**
136+
* The text to display in the close confirmation dialog. Default is "Are you sure you want to close this dialog?".
137+
*/
138+
closeConfirmationText?: string
139+
140+
/**
141+
* If true, the dialog will be removed from the DOM when closed. Default is false.
142+
*/
143+
removeFromDomOnClose?: boolean
144+
}
145+
146+
147+
148+
149+
150+
69151
/********** for the backward compatibility ***************/
70152
class Dialog implements IDialogInsideButtonClickHandler {
71153
hide: () => void

adminforth/types/FrontendAPI.ts

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -213,81 +213,3 @@ export enum AlertVariant {
213213
}
214214

215215

216-
export interface IDialogInsideButtonClickHandler {
217-
hide: () => void
218-
}
219-
220-
221-
export interface DialogButton {
222-
label: string
223-
onclick: (dialog: IDialogInsideButtonClickHandler) => void
224-
options?: Record<string, any>
225-
}
226-
export interface DialogProps {
227-
/**
228-
* The header text to display in the dialog. If not provided, no header will be displayed.
229-
*/
230-
header?: string
231-
232-
/**
233-
* If true, a close button will be displayed in the dialog header. Default is true.
234-
*/
235-
headerCloseButton?: boolean
236-
237-
/**
238-
* An array of buttons to display in the dialog footer.
239-
*/
240-
buttons?: DialogButton[]
241-
242-
/**
243-
* If true, clicking outside the dialog will close it. Default is true.
244-
*
245-
* @deprecated Use `closeByClickOutside` instead
246-
*/
247-
clickToCloseOutside?: boolean
248-
249-
/**
250-
* If true, pressing the Esc key will close the dialog. Default is true.
251-
*/
252-
closeByEsc?: boolean
253-
254-
/**
255-
* If true, clicking outside the dialog will close it. Default is true.
256-
*/
257-
closeByClickOutside?: boolean
258-
259-
/**
260-
* Function that will be called before the dialog is closed.
261-
*/
262-
beforeCloseFunction?: (() => void | Promise<void>) | null
263-
264-
/**
265-
* Function that will be called before the dialog is opened.
266-
*/
267-
beforeOpenFunction?: (() => void | Promise<void>) | null
268-
269-
/**
270-
* Disables close on Ecs button
271-
*
272-
* @deprecated Use `closeByEsc` or instead
273-
*/
274-
closable?: boolean
275-
276-
/**
277-
* If true, the dialog will ask for confirmation before closing. Default is false.
278-
*/
279-
askForCloseConfirmation?: boolean
280-
281-
/**
282-
* The text to display in the close confirmation dialog. Default is "Are you sure you want to close this dialog?".
283-
*/
284-
closeConfirmationText?: string
285-
286-
/**
287-
* If true, the dialog will be removed from the DOM when closed. Default is false.
288-
*/
289-
removeFromDomOnClose?: boolean
290-
}
291-
292-
293-

dev-demo/custom/AfComponents.vue

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,20 @@
137137
<div class="flex flex-col gap-10 m-10 mt-20">
138138

139139
<Dialog
140+
ref="dialogRef"
140141
class="w-96"
141142
header="Dialog Header"
143+
:buttons="[
144+
{ label: 'dialog.hide()', options: { variant: 'outline' }, onclick: (dialog) => dialog.hide() },
145+
]"
146+
:closeByClickOutside="true"
147+
:closeByEsc="true"
148+
askForCloseConfirmation
149+
:beforeCloseFunction="() => { console.log('Before close'); }"
150+
:beforeOpenFunction="() => { console.log('Before open');}"
142151
>
143152
<template #trigger>
144-
<Button>Dialog Toggle</Button>
153+
<Button>Dialog Toggle 2</Button>
145154
</template>
146155

147156
<div class="space-y-4">
@@ -150,6 +159,11 @@
150159
</div>
151160
</Dialog>
152161

162+
<Button @click="dialogRef?.open()">
163+
dialog.open()
164+
</Button>
165+
166+
153167
<Dropzone
154168
:extensions="['.jpg', '.jpeg', '.png']"
155169
:maxSizeBytes="1024 * 1024 * 2"
@@ -301,18 +315,18 @@
301315
/>
302316

303317

304-
<Modal class="w-96" clickToCloseOutside>
318+
<Modal class="w-96" :closeByClickOutside="true" :closeByEsc="true" askForCloseConfirmation >
305319
<template #trigger>
306320
<Button>Modal Toggle</Button>
307321
</template>
308322

309-
<div class="space-y-4">
310-
<p>This is the first paragraph of dialog content.</p>
323+
<div class="space-y-4 p-4">
324+
<p>This is the first paragraph of modal content.</p>
311325
<p>And this is the second paragraph.</p>
312326
</div>
313327
</Modal>
314328

315-
<Button class="mt-48 ml-48" @click="createJob"> Create Job</Button>
329+
<!-- <Button class="mt-48 ml-48" @click="createJob"> Create Job</Button> -->
316330

317331

318332

@@ -367,6 +381,7 @@ const enable = ref(false)
367381
const selected = ref(null)
368382
const selected2 = ref([])
369383
const valueStart = ref()
384+
const dialogRef = ref()
370385
371386
const deltaToColor = (delta: number) => {
372387
if (delta < -10) return '#B91C1C' // bright red

0 commit comments

Comments
 (0)