# ZeenTab

Компонент Таб

# Пример:

Первый Таб
Первый Таб
Второй Таб

Текст Первого Контента

# Props

Название Тип Обязательный По умолчанию
tabOptions Object + false

# Пример tabOption

нечего ему делать в папке компонента напиши тут

# Slots

Название Описание Обязательный По умолчанию
tab-button Кнопка таба - title из tabOptions
tab-content-${id} Контент таба, где id берется из tabOptions - props - emptyText из tabOptions

# Source Code - исходный код компонента

<template lang="pug">
  .zeen-tab
    .zeen-tab__header
      .zeen-tab__part.zeen-tab__name
        slot(name='tab-name')
          .zeen-tab__name {{activeTitle}}
      .zeen-tab__part
        .zeen-tab__button-container(
          v-for='(item, index) in tabOptions'
          :key='`${item.id}-${index}`'
          @click='switchTab(index)'
        )
          .zeen-tab__wrapper
            //- закомментировано до момента реализации оповещений
            //- .zeen-tab__new-message
            ZeenActionIcon.zeen-tab__button(
              size='big'
              :class='{"zeen-tab__button-active": index === activeIndex}'
            )
              slot(name='tab-icon' :item='item')
                svg(width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg')
                  path(d='M13.6288 20.4718L13.0867 21.3877C12.6035 22.204 11.3965 22.204 10.9133 21.3877L10.3712 20.4718C9.95073 19.7614 9.74049 19.4063 9.40279 19.2098C9.06509 19.0134 8.63992 19.0061 7.78958 18.9915C6.53422 18.9698 5.74689 18.8929 5.08658 18.6194C3.86144 18.1119 2.88807 17.1386 2.3806 15.9134C2 14.9946 2 13.8297 2 11.5V10.5C2 7.22657 2 5.58985 2.7368 4.38751C3.14908 3.71473 3.71473 3.14908 4.38751 2.7368C5.58985 2 7.22657 2 10.5 2H13.5C16.7734 2 18.4101 2 19.6125 2.7368C20.2853 3.14908 20.8509 3.71473 21.2632 4.38751C22 5.58985 22 7.22657 22 10.5V11.5C22 13.8297 22 14.9946 21.6194 15.9134C21.1119 17.1386 20.1386 18.1119 18.9134 18.6194C18.2531 18.8929 17.4658 18.9698 16.2104 18.9915C15.36 19.0061 14.9349 19.0134 14.5972 19.2098C14.2595 19.4062 14.0492 19.7614 13.6288 20.4718Z')
            .zeen-tab__tooltip
              ZeenTooltip
                span {{item.data.title}}
    .zeen-tab__content
      .zeen-tab__content-area
        slot(:name='tabContentName')

  
</template>
<script>
import ZeenActionIcon from '../ZeenActionIcon/ZeenActionIcon.vue'
import ZeenTooltip from '../ZeenTooltip/ZeenTooltip.vue'
export default {
  name: 'ZeenTab',
  components: {ZeenActionIcon, ZeenTooltip},
  props: {
    tabOptions: {
      type: Array,
    },
  },
  data() {
    return {
      activeIndex: 0,
    }
  },
  methods: {
    tabHeadSlotName: function () {
      return `tab-${this.activeIndex}`
    },
    switchTab: function (index) {
      this.activeIndex = index
    },
  },
  computed: {
    activeTab() {
      return this.tabOptions[this.activeIndex] ?? {}
    },
    activeTitle() {
      return this.activeTab?.data?.title ?? ''
    },
    tabContentName() {
      return `tab-content-${this.activeTab?.id}`
    },
  },
  watch: {
    tabOptions(newVal, oldVal) {
      if (newVal.length < oldVal.length && this.activeIndex >= newVal.length) {
        this.activeIndex = Math.max(0, newVal.length - 1)
      }
    },
  },
}
</script>
<style lang="scss">
:root {
  /* Размеры */
  --zeen-tab-full-size: 100%;
  --zeen-tab-gap: 0;
  --zeen-tab-border-width: 1px;
  --zeen-tab-fontsize: var(--main-smallest-text);
  --zeen-tab-container-basis: 50%;
  --zeen-tab-button-container-height: 48px;
  --zeen-tab-name-font-weight: 700;
  --zeen-tab-name-font-size: 14px;
  --zeen-tab-name-line-height: 1.4;
  --zeen-tab-container-width: 48px;
  --zeen-tab-header-border-width: 1px;
  --zeen-tab-header-border-bottom: 0;
  --zeen-tab-header-border-left: var(--zeen-tab-header-padding);
  --zeen-tab-header-border-right: var(--zeen-tab-header-border-left);
  --zeen-tab-tooltip-top: -32px;
  --zeen-tab-tooltip-left: -7px;
  --zeen-tab-new-message-border-width: 1px;
  --zeen-tab-new-message-size: 8px;
  --zeen-tab-new-message-top: 1px;
  --zeen-tab-new-message-right: 0;
  --zeen-tab-header-padding: 20px;
  --zeen-tab-header-padding-right: 20px;

  --zeen-tab-border: var(--zeen-tab-border-width) solid var(--zeen-tab-border-color);

  /* Цвета */
  --zeen-tab-general-color: var(--main-color);
  --zeen-tab-border-color: var(--gray-1);
  --zeen-tab-container-background: transperent;
  --zeen-tab-active-border-bottom-color: var(--zeen-tab-general-color);
  --zeen-tab-name-color: var(--main-text-color);
  --zeen-tab-header-border-color: var(--gray-1);
  --zeen-tab-icon-color: var(--gray-2);
  --zeen-tab-icon-color-active: var(--main-color);
  --zeen-tab-new-message-background: var(--main-color);
  --zeen-tab-background: var(--gray-3);
}
</style>
<style lang="scss" scoped>
@import '../../styles/mixins.scss';

.zeen-tab {
  min-height: var(--zeen-tab-full-size);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  position: relative;

  &__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: var(--zeen-tab-header-padding);
    padding-right: var(--zeen-tab-header-padding-right);
    background: var(--zeen-tab-background);
    position: relative;

    &::after {
      content: '';
      display: block;
      height: var(--zeen-tab-header-border-width);
      background: var(--zeen-tab-header-border-color);
      position: absolute;
      bottom: var(--zeen-tab-header-border-bottom);
      left: var(--zeen-tab-header-border-left);
      right: var(--zeen-tab-header-border-right);
    }
  }

  &__part {
    width: 50%;
    display: flex;
    align-items: center;

    &:last-of-type {
      justify-content: flex-end;
    }
  }

  &__name {
    font-weight: var(--zeen-tab-name-font-weight);
    font-size: var(--zeen-tab-name-font-size);
    line-height: var(--zeen-tab-name-line-height);
    color: var(--zeen-tab-name-color);
  }

  &__tooltip {
    display: none;
    position: absolute;
    top: var(--zeen-tab-tooltip-top);
    left: var(--zeen-tab-tooltip-left);
    z-index: 100;
  }

  &__wrapper {
    position: relative;

    &:hover {
      .zeen-tab__tooltip {
        display: block;
      }
    }
  }

  &__new-message {
    display: block;
    width: var(--zeen-tab-new-message-size);
    height: var(--zeen-tab-new-message-size);
    border-radius: 50%;
    border: var(--zeen-tab-new-message-border-width) solid var(--zeen-tab-background);
    position: absolute;
    background: var(--zeen-tab-new-message-background);
    right: var(--zeen-tab-new-message-right);
    top: var(--zeen-tab-new-message-top);
  }

  &__button {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--zeen-tab-fontsize);
    padding: var(--zeen-tab-gap);
    color: var(--zeen-tab-icon-color);

    &-container {
      width: var(--zeen-tab-container-width);
      background: var(--zeen-tab-container-background);
      height: var(--zeen-tab-button-container-height);
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      cursor: pointer;

      &:first-of-type {
        border-left: 0;
      }

      & svg {
        fill: currentColor;
      }
    }

    img {
      max-height: var(--zeen-tab-full-size);
    }

    &-active {
      color: var(--zeen-tab-icon-color-active);
    }
  }

  &__content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    position: relative;

    &-area {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    }
  }
}
</style>