Skip to content

A self-hosted media server and file management system

chore: convert useModal to typescript

aminnausinfa91518ab970
diff --git a/resources/js/composables/useModal.js b/resources/js/composables/useModal.js
deleted file mode 100755
index 08675d08..00000000
--- a/resources/js/composables/useModal.js
+++ /dev/null
@@ -1,28 +0,0 @@
-import { reactive } from 'vue';
-
-export default function useModal(props) {
- let closingTimeoutID;
- return reactive({
- title: '',
- ...props,
- modalOpen: false,
- isAnimating: false,
- animationTime: props.animationTime ?? 300,
- toggleModal(state = null) {
- if (this.isAnimating) return;
- clearTimeout(closingTimeoutID);
-
- if (state != null) this.modalOpen = state;
- else this.modalOpen = !this.modalOpen;
-
- this.isAnimating = true;
-
- closingTimeoutID = window.setTimeout(() => {
- this.isAnimating = false;
- }, this.animationTime);
- },
- setTitle(title) {
- if (title && this?.title) this.title = title;
- },
- });
-}
diff --git a/resources/js/composables/useModal.ts b/resources/js/composables/useModal.ts
new file mode 100644
index 00000000..5a5a40fd
--- /dev/null
+++ b/resources/js/composables/useModal.ts
@@ -0,0 +1,34 @@
+import { reactive, ref } from 'vue';
+
+export interface ModalProps {
+ title?: string;
+ submitText?: string;
+ animationTime?: number;
+}
+
+export default function useModal(props: ModalProps) {
+ const closingTimeoutID = ref<number | null>(null);
+ return reactive({
+ title: '',
+ ...props,
+ modalOpen: false,
+ isAnimating: false,
+ animationTime: props.animationTime ?? 300,
+ toggleModal(state: boolean | null = null) {
+ if (this.isAnimating) return;
+ if (closingTimeoutID.value) clearTimeout(closingTimeoutID.value);
+
+ if (state != null) this.modalOpen = state;
+ else this.modalOpen = !this.modalOpen;
+
+ this.isAnimating = true;
+
+ closingTimeoutID.value = window.setTimeout(() => {
+ this.isAnimating = false;
+ }, this.animationTime);
+ },
+ setTitle(title: string) {
+ this.title = title;
+ },
+ });
+}