From f814fadc1d5389a32ef6745957f9613e9cae3191 Mon Sep 17 00:00:00 2001 From: Alessio Crea Date: Tue, 10 Dec 2024 10:58:34 +0100 Subject: [PATCH] fix: code formatting and arrow positioning --- .../src/components/popover/PopoverCustom.vue | 5 ++++- .../popover/PopoverCustomButton.vue | 13 ++----------- .../src/components/utils/useFloatingUi.ts | 19 ++++++++++--------- .../ui/tableView/SortAndFilterHeader.vue | 8 ++++---- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/databrowser/src/components/popover/PopoverCustom.vue b/databrowser/src/components/popover/PopoverCustom.vue index 722be6b3..d788d755 100644 --- a/databrowser/src/components/popover/PopoverCustom.vue +++ b/databrowser/src/components/popover/PopoverCustom.vue @@ -42,16 +42,18 @@ import { useFloatingUi } from '../utils/useFloatingUi'; import { computed, ref } from 'vue'; import PopoverTransition from './PopoverTransition.vue'; -withDefaults( +const props = withDefaults( defineProps<{ fullScreenWidth?: boolean; zIndex?: number; hasArrow?: boolean; + leftOffset?: number; }>(), { fullScreenWidth: true, zIndex: undefined, hasArrow: false, + leftOffset: undefined, } ); @@ -61,6 +63,7 @@ const [trigger, container, placement] = useFloatingUi({ placement: 'bottom-start', offset: 8, arrow, + leftOffset: props.leftOffset, }); const arrowClasses = computed(() => diff --git a/databrowser/src/components/popover/PopoverCustomButton.vue b/databrowser/src/components/popover/PopoverCustomButton.vue index 9167e83d..b08c38a0 100644 --- a/databrowser/src/components/popover/PopoverCustomButton.vue +++ b/databrowser/src/components/popover/PopoverCustomButton.vue @@ -12,14 +12,13 @@ SPDX-License-Identifier: AGPL-3.0-or-later :class="{ relative: triggerOnHover, }" - @click="onPopoverButtonClick" > @@ -32,7 +31,7 @@ import { ref } from 'vue'; import { PopoverButton } from '@headlessui/vue'; import { useTimeoutFn } from '@vueuse/core'; -const props = defineProps<{ disabled?: boolean; triggerOnHover?: boolean }>(); +defineProps<{ disabled?: boolean; triggerOnHover?: boolean }>(); const emit = defineEmits(['triggerClick']); @@ -56,14 +55,6 @@ const onTriggerHoverClick = () => { emit('triggerClick'); }; -const onPopoverButtonClick = (e: PointerEvent) => { - if (!e.pointerType || !props.triggerOnHover) { - return; - } - - e.preventDefault(); -}; - const { isPending: isPopoverButtonClickPending, start: startPopoverButtonClick, diff --git a/databrowser/src/components/utils/useFloatingUi.ts b/databrowser/src/components/utils/useFloatingUi.ts index 902839d7..2f3bd7ee 100644 --- a/databrowser/src/components/utils/useFloatingUi.ts +++ b/databrowser/src/components/utils/useFloatingUi.ts @@ -17,6 +17,7 @@ export interface UseFloatingUi { placement: Placement; matchReferenceWidth?: boolean; offset?: number; + leftOffset?: number; arrow?: Ref; } @@ -55,8 +56,14 @@ export const useFloatingUi = ( middleware, }).then(({ x, y, placement: currentPlacement, middlewareData }) => { // Position tooltip + const [staticPlacement, dynamicPlacement] = + currentPlacement.split('-'); + + const leftOffset = + (options.leftOffset || 0) * (dynamicPlacement === 'end' ? 1 : -1); + Object.assign(tooltipEl.style, { - left: `${x}px`, + left: `${x + leftOffset}px`, top: `${y}px`, }); @@ -66,22 +73,16 @@ export const useFloatingUi = ( // If arrow element is provided, handle its positioning if (middlewareData.arrow != null) { const { x: arrowX, y: arrowY } = middlewareData.arrow; - const splittedPlacement = currentPlacement.split('-')[0]; - - const { x: tooltipX } = tooltipEl.getBoundingClientRect(); - const { x: arrowWindowX } = arrowEl.getBoundingClientRect(); - - const leftOffset = tooltipX > arrowWindowX ? 5 : -5; const staticSide = { top: 'bottom', right: 'left', bottom: 'top', left: 'right', - }[splittedPlacement]!; + }[staticPlacement]!; Object.assign(arrowEl.style, { - left: arrowX != null ? `${arrowX + leftOffset}px` : '', + left: arrowX != null ? `${arrowX - leftOffset}px` : '', top: arrowY != null ? `${arrowY}px` : '', right: '', bottom: '', diff --git a/databrowser/src/domain/datasets/ui/tableView/SortAndFilterHeader.vue b/databrowser/src/domain/datasets/ui/tableView/SortAndFilterHeader.vue index c95737f9..fff6a203 100644 --- a/databrowser/src/domain/datasets/ui/tableView/SortAndFilterHeader.vue +++ b/databrowser/src/domain/datasets/ui/tableView/SortAndFilterHeader.vue @@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
{{ title }}
- + - +