Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyunhe committed Oct 31, 2024
2 parents ea19e3c + 8086ec0 commit 35ab27a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = {
},
rules: {
'vue/multi-word-component-names': 0,
'vue/prefer-import-from-vue':0
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"async-validator": "^4.2.5",
"axios": "^1.6.8",
"csstype": "^3.1.3",
"husky": "^9.1.6",
"lodash-es": "^4.17.21",
"lodash-unified": "^1.0.3",
"type-fest": "^4.20.1"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/hooks/useModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { watch } from 'vue'
import { isClient, useEventListener } from '@vueuse/core'
import { EVENT_CODE } from '@/constants'

import type { Ref } from 'vue'

type ModalInstance = {
handleClose: () => void
}

const modalStack: ModalInstance[] = []

const closeModal = (e: KeyboardEvent) => {
if (modalStack.length === 0) return
if (e.code === EVENT_CODE.esc) {
e.stopPropagation()
const topModal = modalStack[modalStack.length - 1]
topModal.handleClose()
}
}

export const useModal = (instance: ModalInstance, visibleRef: Ref<boolean>) => {
watch(visibleRef, (val) => {
if (val) {
modalStack.push(instance)
} else {
modalStack.splice(modalStack.indexOf(instance), 1)
}
})
}

if (isClient) useEventListener(document, 'keydown', closeModal)

0 comments on commit 35ab27a

Please sign in to comment.