2022-04-11 06:12:13 -07:00
|
|
|
<template>
|
2022-08-05 06:03:24 -07:00
|
|
|
<div :class="['n8n-tabs', $style.container]">
|
2022-04-11 06:12:13 -07:00
|
|
|
<div :class="$style.back" v-if="scrollPosition > 0" @click="scrollLeft">
|
|
|
|
<n8n-icon icon="chevron-left" size="small" />
|
|
|
|
</div>
|
|
|
|
<div :class="$style.next" v-if="canScrollRight" @click="scrollRight">
|
|
|
|
<n8n-icon icon="chevron-right" size="small" />
|
|
|
|
</div>
|
|
|
|
<div ref="tabs" :class="$style.tabs">
|
2022-11-15 09:20:54 -08:00
|
|
|
<div
|
|
|
|
v-for="option in options"
|
2022-07-20 07:24:03 -07:00
|
|
|
:key="option.value"
|
|
|
|
:id="option.value"
|
|
|
|
:class="{ [$style.alignRight]: option.align === 'right' }"
|
|
|
|
>
|
|
|
|
<n8n-tooltip :disabled="!option.tooltip" placement="bottom">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
|
|
|
<div v-html="option.tooltip" @click="handleTooltipClick(option.value, $event)" />
|
|
|
|
</template>
|
2022-07-20 07:24:03 -07:00
|
|
|
<a
|
|
|
|
v-if="option.href"
|
|
|
|
target="_blank"
|
|
|
|
:href="option.href"
|
|
|
|
:class="[$style.link, $style.tab]"
|
|
|
|
@click="() => handleTabClick(option.value)"
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
{{ option.label }}
|
2022-11-15 09:20:54 -08:00
|
|
|
<span :class="$style.external"
|
|
|
|
><n8n-icon icon="external-link-alt" size="small"
|
|
|
|
/></span>
|
2022-07-20 07:24:03 -07:00
|
|
|
</div>
|
|
|
|
</a>
|
2022-04-11 06:12:13 -07:00
|
|
|
|
2022-07-20 07:24:03 -07:00
|
|
|
<div
|
|
|
|
v-else
|
2023-07-28 00:51:07 -07:00
|
|
|
:class="{ [$style.tab]: true, [$style.activeTab]: modelValue === option.value }"
|
2022-07-20 07:24:03 -07:00
|
|
|
@click="() => handleTabClick(option.value)"
|
|
|
|
>
|
|
|
|
<n8n-icon v-if="option.icon" :icon="option.icon" size="medium" />
|
|
|
|
<span v-if="option.label">{{ option.label }}</span>
|
|
|
|
</div>
|
|
|
|
</n8n-tooltip>
|
2022-04-11 06:12:13 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { PropType } from 'vue';
|
|
|
|
import { defineComponent } from 'vue';
|
2022-04-11 06:12:13 -07:00
|
|
|
import N8nIcon from '../N8nIcon';
|
|
|
|
|
2023-04-12 07:39:45 -07:00
|
|
|
export interface N8nTabOptions {
|
|
|
|
value: string;
|
|
|
|
label?: string;
|
|
|
|
icon?: string;
|
|
|
|
href?: string;
|
|
|
|
tooltip?: string;
|
|
|
|
align?: 'left' | 'right';
|
|
|
|
}
|
|
|
|
|
|
|
|
export default defineComponent({
|
2022-04-11 06:12:13 -07:00
|
|
|
name: 'N8nTabs',
|
|
|
|
components: {
|
|
|
|
N8nIcon,
|
|
|
|
},
|
|
|
|
mounted() {
|
2022-08-29 03:21:40 -07:00
|
|
|
const container = this.$refs.tabs as HTMLDivElement | undefined;
|
2022-04-11 06:12:13 -07:00
|
|
|
if (container) {
|
2022-08-29 03:21:40 -07:00
|
|
|
container.addEventListener('scroll', (event: Event) => {
|
2022-04-11 06:12:13 -07:00
|
|
|
const width = container.clientWidth;
|
|
|
|
const scrollWidth = container.scrollWidth;
|
2022-11-15 09:20:54 -08:00
|
|
|
this.scrollPosition = (event.target as Element).scrollLeft;
|
2022-09-23 07:14:28 -07:00
|
|
|
|
2022-04-11 06:12:13 -07:00
|
|
|
this.canScrollRight = scrollWidth - width > this.scrollPosition;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.resizeObserver = new ResizeObserver(() => {
|
|
|
|
const width = container.clientWidth;
|
|
|
|
const scrollWidth = container.scrollWidth;
|
|
|
|
this.canScrollRight = scrollWidth - width > this.scrollPosition;
|
|
|
|
});
|
|
|
|
this.resizeObserver.observe(container);
|
|
|
|
|
|
|
|
const width = container.clientWidth;
|
|
|
|
const scrollWidth = container.scrollWidth;
|
|
|
|
this.canScrollRight = scrollWidth - width > this.scrollPosition;
|
|
|
|
}
|
|
|
|
},
|
2023-07-28 00:51:07 -07:00
|
|
|
unmounted() {
|
2022-08-29 03:21:40 -07:00
|
|
|
if (this.resizeObserver) {
|
|
|
|
this.resizeObserver.disconnect();
|
|
|
|
}
|
2022-04-11 06:12:13 -07:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
scrollPosition: 0,
|
|
|
|
canScrollRight: false,
|
2022-08-29 03:21:40 -07:00
|
|
|
resizeObserver: null as ResizeObserver | null,
|
2022-04-11 06:12:13 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
props: {
|
2023-07-28 00:51:07 -07:00
|
|
|
modelValue: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
},
|
2023-04-12 07:39:45 -07:00
|
|
|
options: {
|
|
|
|
type: Array as PropType<N8nTabOptions[]>,
|
|
|
|
default: (): N8nTabOptions[] => [],
|
|
|
|
},
|
2022-04-11 06:12:13 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2022-07-20 07:24:03 -07:00
|
|
|
handleTooltipClick(tab: string, event: MouseEvent) {
|
|
|
|
this.$emit('tooltipClick', tab, event);
|
|
|
|
},
|
2022-04-11 06:12:13 -07:00
|
|
|
handleTabClick(tab: string) {
|
2023-07-28 00:51:07 -07:00
|
|
|
this.$emit('update:modelValue', tab);
|
2022-04-11 06:12:13 -07:00
|
|
|
},
|
|
|
|
scrollLeft() {
|
|
|
|
this.scroll(-50);
|
|
|
|
},
|
|
|
|
scrollRight() {
|
|
|
|
this.scroll(50);
|
|
|
|
},
|
|
|
|
scroll(left: number) {
|
2022-11-15 09:20:54 -08:00
|
|
|
const container = this.$refs.tabs as
|
|
|
|
| (HTMLDivElement & { scrollBy: ScrollByFunction })
|
|
|
|
| undefined;
|
2022-04-11 06:12:13 -07:00
|
|
|
if (container) {
|
|
|
|
container.scrollBy({ left, top: 0, behavior: 'smooth' });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-08-29 03:21:40 -07:00
|
|
|
|
2022-11-15 09:20:54 -08:00
|
|
|
type ScrollByFunction = (arg: {
|
|
|
|
left: number;
|
|
|
|
top: number;
|
|
|
|
behavior: 'smooth' | 'instant' | 'auto';
|
|
|
|
}) => void;
|
2022-04-11 06:12:13 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.container {
|
|
|
|
position: relative;
|
|
|
|
height: 24px;
|
|
|
|
min-height: 24px;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tabs {
|
|
|
|
color: var(--color-text-base);
|
|
|
|
font-weight: var(--font-weight-bold);
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
position: absolute;
|
|
|
|
overflow-x: scroll;
|
|
|
|
|
|
|
|
/* Hide scrollbar for Chrome, Safari and Opera */
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hide scrollbar for IE, Edge and Firefox */
|
2022-11-15 09:20:54 -08:00
|
|
|
-ms-overflow-style: none; /* IE and Edge */
|
|
|
|
scrollbar-width: none; /* Firefox */
|
2022-04-11 06:12:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.tab {
|
|
|
|
display: block;
|
|
|
|
padding: 0 var(--spacing-s) var(--spacing-2xs) var(--spacing-s);
|
|
|
|
padding-bottom: var(--spacing-2xs);
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
cursor: pointer;
|
|
|
|
white-space: nowrap;
|
|
|
|
&:hover {
|
|
|
|
color: var(--color-primary);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.activeTab {
|
|
|
|
color: var(--color-primary);
|
|
|
|
border-bottom: var(--color-primary) 2px solid;
|
|
|
|
}
|
|
|
|
|
|
|
|
.alignRight {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.link {
|
|
|
|
cursor: pointer;
|
|
|
|
color: var(--color-text-base);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--color-primary);
|
|
|
|
|
|
|
|
.external {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.external {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button {
|
|
|
|
position: absolute;
|
2022-05-23 08:56:15 -07:00
|
|
|
background-color: var(--color-background-base);
|
2022-04-11 06:12:13 -07:00
|
|
|
z-index: 1;
|
|
|
|
height: 24px;
|
|
|
|
width: 10px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
font-weight: var(--font-weight-bold);
|
|
|
|
}
|
|
|
|
|
|
|
|
.back {
|
|
|
|
composes: tab;
|
|
|
|
composes: button;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.next {
|
|
|
|
composes: tab;
|
|
|
|
composes: button;
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
</style>
|