TabGroup.vue 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div class="border-b border-gray-200">
  3. <div class="flex gap-4">
  4. <div
  5. v-for="tab in tabs"
  6. :key="tab.value"
  7. @click="selectTab(tab.value)"
  8. class="px-4 py-2 text-sm font-medium transition-colors relative"
  9. :class="[
  10. modelValue === tab.value
  11. ? 'text-blue-600'
  12. : 'text-gray-600 hover:text-gray-900'
  13. ]"
  14. >
  15. {{ tab.label }}
  16. <div
  17. v-if="modelValue === tab.value"
  18. class="absolute bottom-0 left-0 right-0 h-0.5 bg-blue-600"
  19. ></div>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script setup lang="ts">
  25. interface Tab {
  26. label: string
  27. value: string
  28. }
  29. interface Props {
  30. modelValue: string
  31. tabs: Tab[]
  32. }
  33. interface Emits {
  34. (e: 'update:modelValue', value: string): void
  35. }
  36. const props = defineProps<Props>()
  37. const emit = defineEmits<Emits>()
  38. const selectTab = (value: string) => {
  39. emit('update:modelValue', value)
  40. }
  41. </script>