Skip to content

Commit 565c6da

Browse files
committed
feat: create useModal composable
1 parent 8f45120 commit 565c6da

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

app/components/HeaderAccountMenu.client.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { useModal } from '~/composables/useModal'
3+
24
const {
35
isConnected: isNpmConnected,
46
isConnecting: isNpmConnecting,
@@ -42,23 +44,21 @@ onUnmounted(() => {
4244
document.removeEventListener('click', handleClickOutside)
4345
})
4446
47+
const connectorModal = useModal('connector-modal')
48+
4549
function openConnectorModal() {
46-
const connectorModal = document.querySelector<HTMLDialogElement>('#connector-modal')
4750
if (connectorModal) {
4851
isOpen.value = false
49-
setTimeout(() => {
50-
connectorModal.showModal()
51-
})
52+
connectorModal.open()
5253
}
5354
}
5455
56+
const authModal = useModal('auth-modal')
57+
5558
function openAuthModal() {
56-
const authModal = document.querySelector<HTMLDialogElement>('#auth-modal')
5759
if (authModal) {
5860
isOpen.value = false
59-
setTimeout(() => {
60-
authModal.showModal()
61-
})
61+
authModal.open()
6262
}
6363
}
6464
</script>

app/composables/useModal.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export function useModal(modalId: string) {
2+
const modal = document.querySelector<HTMLDialogElement>(`#${modalId}`)
3+
4+
function open() {
5+
if (modal) {
6+
setTimeout(() => {
7+
modal.showModal()
8+
})
9+
}
10+
}
11+
12+
function close() {
13+
if (modal) {
14+
modal.close()
15+
}
16+
}
17+
18+
return {
19+
open,
20+
close,
21+
}
22+
}

0 commit comments

Comments
 (0)