-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make proposal sidebar resizable
- Loading branch information
Showing
2 changed files
with
217 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<script lang="ts" setup> | ||
const props = defineProps<{ | ||
width: number; | ||
max?: number; | ||
min?: number; | ||
}>(); | ||
const containerEl = ref<HTMLElement | null>(null); | ||
const sliderEl = ref<HTMLElement | null>(null); | ||
const initialized = ref(false); | ||
const sliderOriginalPositionX = ref(0); | ||
const { x, y } = useDraggable(sliderEl, { | ||
axis: 'x' | ||
}); | ||
const containerWidth = computed(() => { | ||
const width = getWidth(x.value); | ||
if (props.max && width > props.max) return props.max; | ||
if (props.min && width < props.min) return props.min; | ||
return width; | ||
}); | ||
function getWidth(newSliderPositionX: number): number { | ||
const offset = sliderOriginalPositionX.value - newSliderPositionX; | ||
return props.width + offset; | ||
} | ||
function initResizer() { | ||
if (!sliderEl.value || !containerEl.value) return; | ||
const position = sliderEl.value.getBoundingClientRect(); | ||
sliderOriginalPositionX.value = position.x; | ||
x.value = position.x; | ||
y.value = position.y; | ||
initialized.value = true; | ||
} | ||
onMounted(() => { | ||
initResizer(); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div ref="containerEl" :style="{ width: `${containerWidth}px` }"> | ||
<div ref="sliderEl" class="slider" /> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.slider { | ||
@apply block fixed z-[99] w-[5px] h-full ml-[-2px]; | ||
&:before { | ||
@apply h-full border-l block ml-[2px]; | ||
content: ''; | ||
} | ||
&:hover { | ||
@apply bg-skin-border cursor-col-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