-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<template> | ||
<div ref="root" class="ShareHorizontalResize" :style="style"> | ||
<div class="ShareHorizontalResize__left"> | ||
<slot name="left" /> | ||
</div> | ||
<hr | ||
class="ShareHorizontalResize__divider" | ||
@mousedown.prevent="handleMouseDown" | ||
/> | ||
<div class="ShareHorizontalResize__right"> | ||
<slot name="right" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, CSSProperties, ref } from "vue"; | ||
const props = defineProps({ | ||
initialLeftSize: { type: Number, required: true }, | ||
}); | ||
const root = ref<HTMLElement | null>(null); | ||
let leftSize = ref(props.initialLeftSize); | ||
const style = computed<CSSProperties>(() => ({ | ||
gridTemplateColumns: `${leftSize.value}px 1px minmax(0, 100%)`, | ||
})); | ||
function handleMouseDown() { | ||
document.addEventListener("mousemove", onMouseMove); | ||
document.addEventListener("mouseup", onMouseUp); | ||
const sliderBoundingRect = root.value.getBoundingClientRect(); | ||
function onMouseMove(event: MouseEvent) { | ||
leftSize.value = event.x - sliderBoundingRect.left; | ||
} | ||
function onMouseUp() { | ||
document.removeEventListener("mouseup", onMouseUp); | ||
document.removeEventListener("mousemove", onMouseMove); | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.ShareHorizontalResize { | ||
display: grid; | ||
height: 100%; | ||
} | ||
.ShareHorizontalResize__divider { | ||
border: none; | ||
background-color: var(--builderSeparatorColor); | ||
height: 100%; | ||
cursor: ew-resize; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters