|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="h-tab" |
| 4 | + :class="{ |
| 5 | + 'h-tab--behavior-active': isCurrentTab, |
| 6 | + 'h-tab--behavior-disabled': $props.disabled, |
| 7 | + }" |
| 8 | + @click="handleChange" |
| 9 | + > |
| 10 | + {{ label }}<slot /> |
| 11 | + </div> |
| 12 | +</template> |
| 13 | + |
| 14 | +<script setup> |
| 15 | +import { inject, computed } from 'vue'; |
| 16 | +import { BTabsKey } from './tabs-key'; |
| 17 | +
|
| 18 | +const $props = defineProps({ |
| 19 | + label: { |
| 20 | + type: String, |
| 21 | + default: undefined, |
| 22 | + }, |
| 23 | + value: { |
| 24 | + type: [String, Number], |
| 25 | + required: true, |
| 26 | + }, |
| 27 | + disabled: { |
| 28 | + type: Boolean, |
| 29 | + default: undefined, |
| 30 | + }, |
| 31 | +}); |
| 32 | +
|
| 33 | +const { currentTab, handleTabsChange } = inject(BTabsKey); |
| 34 | +const $emits = defineEmits(['change']); |
| 35 | +
|
| 36 | +const handleChange = () => { |
| 37 | + if ($props.disabled) return; |
| 38 | + $emits('change', $props.value); |
| 39 | + handleTabsChange($props.value); |
| 40 | +}; |
| 41 | +const isCurrentTab = computed(() => currentTab.value === $props.value); |
| 42 | +</script> |
| 43 | + |
| 44 | +<style lang="scss"> |
| 45 | +:root { |
| 46 | + --h-tab--background-color: var(--color-theme-secondary-800); |
| 47 | + --h-tab--color: var(--color-theme-white); |
| 48 | + --h-tab--font-weight: 500; |
| 49 | +} |
| 50 | +
|
| 51 | +.h-tab { |
| 52 | + display: flex; |
| 53 | + justify-content: center; |
| 54 | + align-items: center; |
| 55 | + flex:1; |
| 56 | + text-transform: uppercase; |
| 57 | + background-color: var(--h-tab--background-color); |
| 58 | + color: var(--h-tab--color); |
| 59 | + font-weight: var(--h-tab--font-weight); |
| 60 | +
|
| 61 | + &--behavior { |
| 62 | + &-disabled { |
| 63 | + --h-tab--background-color: var(--color-grey-scale-400); |
| 64 | + --h-tab--color: var(--color-grey-scale-700); |
| 65 | + } |
| 66 | + } |
| 67 | +
|
| 68 | + &:not(.h-tab--behavior-active):not(.h-tab--behavior-disabled) { |
| 69 | + --h-tab--color: var(--color-grey-scale-100); |
| 70 | + } |
| 71 | +} |
| 72 | +</style> |
0 commit comments