Skip to content

Commit

Permalink
Allow click-and-drag to scroll knockout bracket in modal
Browse files Browse the repository at this point in the history
  • Loading branch information
phrasmotica committed Apr 26, 2024
1 parent 43e104d commit 6adcbef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/modals/BracketModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { useI18n } from "vue-i18n"
import KnockoutBracket from "../play/KnockoutBracket.vue"
import { useCursorGrab } from "@/composables/useCursorGrab"
const { t } = useI18n()
const visible = defineModel<boolean>("visible", {
default: false,
})
const {
cursorStyle,
setGrabbing,
} = useCursorGrab()
</script>

<template>
Expand All @@ -16,7 +23,11 @@ const visible = defineModel<boolean>("visible", {
class="bracket-modal mx-4"
v-model:visible="visible"
:header="t('bracket.knockoutBracket')">
<div class="overflow-x-auto">
<div v-dragscroll
class="overflow-x-auto"
:style="cursorStyle"
@mousedown="setGrabbing(true)"
@mouseup="setGrabbing(false)">
<KnockoutBracket />
</div>
</Dialog>
Expand Down
18 changes: 18 additions & 0 deletions src/composables/useCursorGrab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { computed, ref, type CSSProperties } from "vue"

export const useCursorGrab = () => {
const isGrabbing = ref(false)

const cursorStyle = computed<CSSProperties>(() => ({
cursor: isGrabbing.value ? "grabbing" : "grab"
}))

const setGrabbing = (v: boolean) => {
isGrabbing.value = v
}

return {
cursorStyle,
setGrabbing,
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import TabMenu from 'primevue/tabmenu'
import Textarea from 'primevue/textarea'
import Toast from 'primevue/toast'
import ToastService from 'primevue/toastservice'
import VueDragscroll from "vue-dragscroll"

import App from './App.vue'
import router from './router'
Expand Down Expand Up @@ -75,6 +76,7 @@ app.use(createPinia())
app.use(router)
app.use(PrimeVue)
app.use(ToastService)
app.use(VueDragscroll)

app.component("Badge", Badge)
app.component("Button", Button)
Expand Down

0 comments on commit 6adcbef

Please sign in to comment.