# Pull Request Template ## Description This PR includes the following updates: 1. Updated the design system color tokens by introducing new tokens for surfaces, overlays, buttons, labels, and cards, along with refinements to existing shades. 2. Refreshed both light and dark themes with adjusted background, border, and solid colors. 3. Replaced static Inter font files with the Inter variable font (including italic), supporting weights from 100–900. 4. Added custom font weights (420, 440, 460, 520) along with custom typography classes to enable more fine-grained and consistent typography control. ## Type of change - [x] New feature (non-breaking change which adds functionality) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Pranav <pranav@chatwoot.com>
106 lines
2.9 KiB
Vue
106 lines
2.9 KiB
Vue
<script setup>
|
|
import { computed, ref, onMounted, nextTick, watch } from 'vue';
|
|
import { useResizeObserver } from '@vueuse/core';
|
|
|
|
const props = defineProps({
|
|
initialActiveTab: {
|
|
type: Number,
|
|
default: 0,
|
|
},
|
|
tabs: {
|
|
type: Array,
|
|
required: true,
|
|
validator: value => {
|
|
return value.every(
|
|
tab =>
|
|
typeof tab.label === 'string' &&
|
|
(tab.count ? typeof tab.count === 'number' : true)
|
|
);
|
|
},
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['tabChanged']);
|
|
|
|
const activeTab = computed(() => props.initialActiveTab);
|
|
|
|
const tabRefs = ref([]);
|
|
const indicatorStyle = ref({});
|
|
const enableTransition = ref(false);
|
|
|
|
const activeElement = computed(() => tabRefs.value[activeTab.value]);
|
|
|
|
const updateIndicator = () => {
|
|
nextTick(() => {
|
|
if (!activeElement.value) return;
|
|
|
|
indicatorStyle.value = {
|
|
left: `${activeElement.value.offsetLeft}px`,
|
|
width: `${activeElement.value.offsetWidth}px`,
|
|
};
|
|
});
|
|
};
|
|
|
|
useResizeObserver(activeElement, updateIndicator);
|
|
|
|
// Watch for prop/tabs changes to update indicator position
|
|
watch([() => props.initialActiveTab, () => props.tabs], updateIndicator, {
|
|
immediate: true,
|
|
});
|
|
|
|
onMounted(() => {
|
|
nextTick(() => {
|
|
enableTransition.value = true;
|
|
});
|
|
});
|
|
|
|
const selectTab = index => {
|
|
emit('tabChanged', props.tabs[index]);
|
|
};
|
|
|
|
const showDivider = index => {
|
|
return (
|
|
// Show dividers after the active tab, but not after the last tab
|
|
(index > activeTab.value && index < props.tabs.length - 1) ||
|
|
// Show dividers before the active tab, but not immediately before it and not before the first tab
|
|
(index < activeTab.value - 1 && index > -1)
|
|
);
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="relative flex items-center h-8 rounded-lg bg-n-alpha-1 dark:bg-n-solid-1 w-fit transition-all duration-200 ease-out has-[button:active]:scale-[1.01]"
|
|
>
|
|
<div
|
|
class="absolute rounded-lg bg-n-solid-active shadow-sm pointer-events-none h-8 outline-1 outline outline-n-container inset-y-0"
|
|
:class="{ 'transition-all duration-300 ease-out': enableTransition }"
|
|
:style="indicatorStyle"
|
|
/>
|
|
|
|
<template v-for="(tab, index) in tabs" :key="index">
|
|
<button
|
|
:ref="el => (tabRefs[index] = el)"
|
|
class="relative z-10 px-4 truncate py-1.5 text-sm border-0 outline-1 outline-transparent rounded-lg transition-all duration-200 ease-out hover:text-n-brand active:scale-[1.02]"
|
|
:class="[
|
|
activeTab === index
|
|
? 'text-n-blue-11 scale-100'
|
|
: 'text-n-slate-10 scale-[0.98]',
|
|
]"
|
|
@click="selectTab(index)"
|
|
>
|
|
{{ tab.label }} {{ tab.count ? `(${tab.count})` : '' }}
|
|
</button>
|
|
<div
|
|
v-if="index < tabs.length - 1"
|
|
class="w-px h-3.5 rounded my-auto transition-colors duration-300 ease-in-out"
|
|
:class="
|
|
showDivider(index)
|
|
? 'bg-n-strong'
|
|
: 'bg-transparent dark:bg-transparent'
|
|
"
|
|
/>
|
|
</template>
|
|
</div>
|
|
</template>
|