Skip to content

feat: show view size while dragging split pane #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 4, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/SplitPane.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script setup lang="ts">
import { computed, inject, reactive, ref, toRef } from 'vue'
import { computed, inject, reactive, ref, toRef, onMounted } from 'vue'
import { injectKeyStore } from './types'

const props = defineProps<{ layout?: 'horizontal' | 'vertical' }>()
const isVertical = computed(() => props.layout === 'vertical')

const container = ref()
const rightView = ref()

// mobile only
const store = inject(injectKeyStore)!
Expand All @@ -14,6 +15,8 @@ const showOutput = toRef(store, 'showOutput')
const state = reactive({
dragging: false,
split: 50,
viewHeight: 0,
viewWidth: 0,
})

const boundSplit = computed(() => {
Expand All @@ -38,12 +41,20 @@ function dragMove(e: MouseEvent) {
: container.value.offsetWidth
const dp = position - startPosition
state.split = startSplit + +((dp / totalSize) * 100).toFixed(2)

state.viewHeight = rightView.value.offsetHeight - 38
state.viewWidth = rightView.value.offsetWidth
}
}

function dragEnd() {
state.dragging = false
}

onMounted(() => {
state.viewHeight = rightView.value.offsetHeight - 38
state.viewWidth = rightView.value.offsetWidth
})
</script>

<template>
Expand All @@ -67,9 +78,13 @@ function dragEnd() {
<div class="dragger" @mousedown.prevent="dragStart" />
</div>
<div
ref="rightView"
class="right"
:style="{ [isVertical ? 'height' : 'width']: 100 - boundSplit + '%' }"
>
<div class="view-size" v-show="state.dragging">
{{ `${state.viewWidth}px x ${state.viewHeight}px` }}
</div>
<slot name="right" />
</div>

Expand Down Expand Up @@ -97,6 +112,14 @@ function dragEnd() {
position: relative;
height: 100%;
}
.view-size {
position: absolute;
top: 40px;
left: 10px;
font-size: 12px;
color: var(--text-light);
z-index: 100;
}
.left {
border-right: 1px solid var(--border);
}
Expand Down