-
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.
Merge branch 'master' of https://github.com/snapshot-labs/sx-monorepo …
…into fix-voting-power-check
- Loading branch information
Showing
15 changed files
with
395 additions
and
208 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
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
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,110 @@ | ||
<script lang="ts" setup> | ||
import { lsGet, lsSet } from '@/helpers/utils'; | ||
const CACHE_KEY_SUFFIX = 'width'; | ||
const props = defineProps<{ | ||
id: string; | ||
default: number; | ||
max?: number; | ||
min?: number; | ||
}>(); | ||
const containerEl = ref<HTMLElement | null>(null); | ||
const sliderEl = ref<HTMLElement | null>(null); | ||
const initialized = ref(false); | ||
const dragging = ref(false); | ||
const width = ref(lsGet(`${props.id}.${CACHE_KEY_SUFFIX}`, props.default)); | ||
const sliderOutOfBound = ref(false); | ||
const skipNextDragTick = ref(false); | ||
const { x, y } = useDraggable(sliderEl, { | ||
axis: 'x', | ||
onStart: () => { | ||
dragging.value = true; | ||
}, | ||
onEnd: () => { | ||
dragging.value = false; | ||
if (sliderOutOfBound) { | ||
skipNextDragTick.value = true; | ||
} | ||
} | ||
}); | ||
function getNewWidth(width: number, delta: number) { | ||
const newWidth = Math.round(width - delta); | ||
if (props.max && newWidth >= props.max) { | ||
sliderOutOfBound.value = true; | ||
return props.max; | ||
} | ||
if (props.min && newWidth <= props.min) { | ||
sliderOutOfBound.value = true; | ||
return props.min; | ||
} | ||
sliderOutOfBound.value = false; | ||
return newWidth; | ||
} | ||
function initResizer() { | ||
if (!sliderEl.value || !containerEl.value) return; | ||
const position = sliderEl.value.getBoundingClientRect(); | ||
x.value = position.x; | ||
y.value = position.y; | ||
initialized.value = true; | ||
} | ||
watch(x, (newX, oldX) => { | ||
if (!initialized.value || !dragging.value) return; | ||
// useDraggable composable is not clamping x between min and max when given | ||
// The following check will ignore the first x changes, when it's out of bound | ||
if (skipNextDragTick.value) { | ||
skipNextDragTick.value = false; | ||
sliderOutOfBound.value = false; | ||
return; | ||
} | ||
width.value = getNewWidth(width.value, newX - oldX); | ||
lsSet(`${props.id}.${CACHE_KEY_SUFFIX}`, width.value); | ||
}); | ||
onMounted(() => { | ||
initResizer(); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div | ||
ref="containerEl" | ||
class="relative max-md:!w-full" | ||
:style="{ width: `${width}px` }" | ||
> | ||
<div | ||
ref="sliderEl" | ||
:class="[ | ||
'slider', | ||
{ | ||
dragging: dragging | ||
} | ||
]" | ||
/> | ||
<slot /> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.slider { | ||
$sliderSize: 6px; | ||
@apply hidden md:block absolute h-full z-10 select-none left-[-#{calc($sliderSize / 2)}] w-[#{$sliderSize}]; | ||
&:hover, | ||
&.dragging { | ||
@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
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
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
Oops, something went wrong.