fix: tabhead and scrolling issue (#2966)

Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
Anwarul Islam
2023-04-05 21:56:42 +06:00
committed by GitHub
parent 1d397af674
commit 62058d5dfe
6 changed files with 128 additions and 50 deletions

View File

@@ -16,7 +16,6 @@ declare module '@vue/runtime-core' {
AppHeader: typeof import('./components/app/Header.vue')['default'] AppHeader: typeof import('./components/app/Header.vue')['default']
AppInterceptor: typeof import('./components/app/Interceptor.vue')['default'] AppInterceptor: typeof import('./components/app/Interceptor.vue')['default']
AppLogo: typeof import('./components/app/Logo.vue')['default'] AppLogo: typeof import('./components/app/Logo.vue')['default']
AppNavigation: typeof import('./components/app/Navigation.vue')['default']
AppOptions: typeof import('./components/app/Options.vue')['default'] AppOptions: typeof import('./components/app/Options.vue')['default']
AppPaneLayout: typeof import('./components/app/PaneLayout.vue')['default'] AppPaneLayout: typeof import('./components/app/PaneLayout.vue')['default']
AppPowerSearch: typeof import('./components/app/PowerSearch.vue')['default'] AppPowerSearch: typeof import('./components/app/PowerSearch.vue')['default']
@@ -117,6 +116,7 @@ declare module '@vue/runtime-core' {
HttpTests: typeof import('./components/http/Tests.vue')['default'] HttpTests: typeof import('./components/http/Tests.vue')['default']
HttpURLEncodedParams: typeof import('./components/http/URLEncodedParams.vue')['default'] HttpURLEncodedParams: typeof import('./components/http/URLEncodedParams.vue')['default']
IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default'] IconLucideArrowLeft: typeof import('~icons/lucide/arrow-left')['default']
IconLucideBrush: typeof import('~icons/lucide/brush')['default']
IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default'] IconLucideCheckCircle: typeof import('~icons/lucide/check-circle')['default']
IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default'] IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']
IconLucideGlobe: typeof import('~icons/lucide/globe')['default'] IconLucideGlobe: typeof import('~icons/lucide/globe')['default']
@@ -125,6 +125,7 @@ declare module '@vue/runtime-core' {
IconLucideInfo: typeof import('~icons/lucide/info')['default'] IconLucideInfo: typeof import('~icons/lucide/info')['default']
IconLucideLayers: typeof import('~icons/lucide/layers')['default'] IconLucideLayers: typeof import('~icons/lucide/layers')['default']
IconLucideMinus: typeof import('~icons/lucide/minus')['default'] IconLucideMinus: typeof import('~icons/lucide/minus')['default']
IconLucideRss: typeof import('~icons/lucide/rss')['default']
IconLucideSearch: typeof import('~icons/lucide/search')['default'] IconLucideSearch: typeof import('~icons/lucide/search')['default']
IconLucideUser: typeof import('~icons/lucide/user')['default'] IconLucideUser: typeof import('~icons/lucide/user')['default']
IconLucideUsers: typeof import('~icons/lucide/users')['default'] IconLucideUsers: typeof import('~icons/lucide/users')['default']

View File

@@ -16,19 +16,33 @@
:key="tab.id" :key="tab.id"
:label="tab.document.request.name" :label="tab.document.request.name"
:is-removable="tabs.length > 1" :is-removable="tabs.length > 1"
:close-visibility="'hover'"
> >
<template #tabhead> <template #tabhead>
<span <div
class="font-semibold truncate text-tiny w-10" v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
:class="getMethodLabelColorClassOf(tab.document.request)" :title="tab.document.request.name"
class="truncate px-2"
> >
{{ tab.document.request.method }} <span
</span> class="font-semibold text-tiny"
<span class="text-green-600 mr-1" v-if="tab.document.isDirty"> :class="getMethodLabelColorClassOf(tab.document.request)"
>
</span> {{ tab.document.request.method }}
<span class="truncate flex-1"> </span>
{{ tab.document.request.name }} <span class="leading-8 px-2">
{{ tab.document.request.name }}
</span>
</div>
</template>
<template #suffix>
<span
class="text-green-600 text-[8px] group-hover:hidden w-4"
v-if="tab.document.isDirty"
>
<svg viewBox="0 0 24 24" width="1.2em" height="1.2em">
<circle cx="12" cy="12" r="10" fill="currentColor"></circle>
</svg>
</span> </span>
</template> </template>
<HttpRequestTab <HttpRequestTab

View File

@@ -4,6 +4,7 @@
"version": "0.0.1", "version": "0.0.1",
"type": "module", "type": "module",
"scripts": { "scripts": {
"watch": "vite build --watch",
"build": "vite build", "build": "vite build",
"story:dev": "histoire dev", "story:dev": "histoire dev",
"story:build": "histoire build", "story:build": "histoire build",

View File

@@ -21,23 +21,32 @@ import { TabMeta, TabProvider } from "./Windows.vue"
const slots = useSlots() const slots = useSlots()
const props = defineProps({ const props = withDefaults(
label: { type: String, default: null }, defineProps<{
info: { type: String, default: null }, label: string | null
id: { type: String, default: null, required: true }, info: string | null
isRemovable: { type: Boolean, default: true }, id: string
selected: { isRemovable: boolean
type: Boolean, closeVisibility: "hover" | "always" | "never"
default: false, selected: boolean
}, }>(),
}) {
label: null,
info: null,
isRemovable: true,
closeVisibility: "always",
selected: false,
}
)
const tabMeta = computed<TabMeta>(() => ({ const tabMeta = computed<TabMeta>(() => ({
info: props.info, info: props.info,
label: props.label, label: props.label,
isRemovable: props.isRemovable, isRemovable: props.isRemovable,
icon: slots.icon, icon: slots.icon,
tabhead: slots.tabhead suffix: slots.suffix,
tabhead: slots.tabhead,
closeVisibility: props.closeVisibility,
})) }))
const { const {

View File

@@ -1,43 +1,95 @@
<template> <template>
<div class="flex flex-col flex-1 h-auto overflow-y-hidden flex-nowrap"> <div class="flex flex-col flex-1 h-auto overflow-y-hidden flex-nowrap">
<div class="relative sticky top-0 z-10 flex-shrink-0 overflow-x-auto tabs bg-primaryLight"> <div
<div class="flex flex-1 flex-shrink-0 w-0 overflow-x-auto" ref="scrollContainer"> class="relative sticky top-0 z-10 flex-shrink-0 overflow-x-auto tabs bg-primaryLight"
<div class="flex justify-between divide-x divide-dividerLight" @wheel="scrollOnWindows"> >
<div
class="flex flex-1 flex-shrink-0 w-0 overflow-x-auto"
ref="scrollContainer"
>
<div
class="flex justify-between divide-x divide-dividerLight"
@wheel.prevent="scroll"
>
<div class="flex"> <div class="flex">
<draggable v-bind="dragOptions" :list="tabEntries" :style="tabStyles" :item-key="'window-'" <draggable
class="flex flex-shrink-0 overflow-x-auto transition divide-x divide-dividerLight" @sort="sortTabs"> v-bind="dragOptions"
:list="tabEntries"
:style="tabStyles"
:item-key="'window-'"
class="flex flex-shrink-0 overflow-x-auto transition divide-x divide-dividerLight"
@sort="sortTabs"
>
<template #item="{ element: [tabID, tabMeta] }"> <template #item="{ element: [tabID, tabMeta] }">
<button :key="`removable-tab-${tabID}`" class="tab" :class="[{ active: modelValue === tabID }]" <button
:aria-label="tabMeta.label || ''" role="button" @keyup.enter="selectTab(tabID)" :key="`removable-tab-${tabID}`"
@click="selectTab(tabID)"> class="tab group px-2"
:class="[{ active: modelValue === tabID }]"
:aria-label="tabMeta.label || ''"
role="button"
@keyup.enter="selectTab(tabID)"
@click="selectTab(tabID)"
>
<span
v-if="tabMeta.icon"
class="flex items-center justify-center cursor-pointer"
>
<component :is="tabMeta.icon" class="w-4 h-4 svg-icons" />
</span>
<div v-if="!tabMeta.tabhead" class="flex items-stretch truncate"> <div
<span v-if="tabMeta.icon" class="flex items-center justify-center mx-4 cursor-pointer"> v-if="!tabMeta.tabhead"
<component :is="tabMeta.icon" class="w-4 h-4 svg-icons" /> class="truncate w-full text-left px-2"
</span> >
<span class="truncate pl-4"> <span class="truncate">
{{ tabMeta.label }} {{ tabMeta.label }}
</span> </span>
</div> </div>
<div v-else class="truncate flex items-center justify-start mx-4"> <div v-else class="truncate w-full text-left">
<component :is="tabMeta.tabhead" /> <component :is="tabMeta.tabhead" />
</div> </div>
<HoppButtonSecondary v-tippy="{ theme: 'tooltip', delay: [500, 20] }" :icon="IconX" :style="{ <component v-if="tabMeta.suffix" :is="tabMeta.suffix" />
display: tabMeta.isRemovable ? 'flex' : 'none',
}" :title="closeText ?? t?.('action.close') ?? 'Close'" <HoppButtonSecondary
:class="[{ active: modelValue === tabID }, 'close']" class="mx-2 !p-0.5" v-if="tabMeta.isRemovable"
@click.stop="emit('removeTab', tabID)" /> v-tippy="{ theme: 'tooltip', delay: [500, 20] }"
:icon="IconX"
:title="closeText ?? t?.('action.close') ?? 'Close'"
:class="[
{ active: modelValue === tabID },
{
flex: tabMeta.closeVisibility === 'always',
'group-hover:flex hidden':
tabMeta.closeVisibility === 'hover',
hidden: tabMeta.closeVisibility === 'never',
},
'close',
]"
class="!p-0.5"
@click.stop="emit('removeTab', tabID)"
/>
</button> </button>
</template> </template>
</draggable> </draggable>
</div> </div>
<div class="sticky right-0 flex items-center justify-center flex-shrink-0 overflow-x-auto z-8"> <div
class="sticky right-0 flex items-center justify-center flex-shrink-0 overflow-x-auto z-8"
>
<slot name="actions"> <slot name="actions">
<span v-if="canAddNewTab" class="flex items-center justify-center px-2 py-1.5 bg-primaryLight z-8"> <span
<HoppButtonSecondary v-tippy="{ theme: 'tooltip' }" :title="newText ?? t?.('action.new') ?? 'New'" v-if="canAddNewTab"
:icon="IconPlus" class="rounded !p-1" filled @click="addTab" /> class="flex items-center justify-center px-2 py-1.5 bg-primaryLight z-8 h-full"
>
<HoppButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="newText ?? t?.('action.new') ?? 'New'"
:icon="IconPlus"
class="rounded !p-1"
filled
@click="addTab"
/>
</span> </span>
</slot> </slot>
</div> </div>
@@ -66,9 +118,11 @@ import { HoppUIPluginOptions, HOPP_UI_OPTIONS } from "./../../index"
export type TabMeta = { export type TabMeta = {
label: string | null label: string | null
icon: Slot | undefined icon: Slot | undefined
suffix: Slot | undefined
tabhead: Slot | undefined tabhead: Slot | undefined
info: string | null info: string | null
isRemovable: boolean isRemovable: boolean
closeVisibility: "hover" | "always" | "never"
} }
export type TabProvider = { export type TabProvider = {
// Whether inactive tabs should remain rendered // Whether inactive tabs should remain rendered
@@ -187,12 +241,11 @@ const addTab = () => {
emit("addTab") emit("addTab")
} }
const scrollContainer = ref<HTMLElement|null>(null) const scrollContainer = ref<HTMLElement | null>(null)
const scrollOnWindows = (event: WheelEvent) => { const scroll = (e: WheelEvent) => {
event.preventDefault() scrollContainer.value!.scrollLeft += e.deltaY
if(scrollContainer.value) scrollContainer.value!.scrollLeft += e.deltaX
scrollContainer.value.scrollLeft += event.deltaY
} }
</script> </script>