v2.15.0

Chip

Индикатор: число или состояние.

Использование

Оберните любой компонент в Chip, чтобы показать индикатор.

<template>
  <B24Chip>
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Цвет

Пропс color меняет цвет Chip.

<template>
  <B24Chip color="air-primary-warning">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Инверсия

Пропс inverted инвертирует цвет Chip.

Доступно только для цветов air-primary*.
<template>
  <B24Chip inverted color="air-primary">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Размер

Пропс size меняет размер Chip.

<template>
  <B24Chip size="lg">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Текст

Пропс text задаёт текст Chip.

+5
<template>
  <B24Chip text="+5" size="lg">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Скрыть ноль

Пропс hideZero скрывает текст, если он равен 0.

1
<template>
  <B24Chip hide-zero :text="1" size="lg">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Иконка справа

Пропс trailing-icon задаёт иконку справа.

+1
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24Chip :trailing-icon="RocketIcon" text="+1" size="lg" hide-zero>
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Положение

Пропс position меняет положение Chip.

<template>
  <B24Chip position="bottom-left">
    <B24Button color="air-secondary-no-accent" label="Кнопка" />
  </B24Chip>
</template>

Внутри компонента

Пропс inset показывает Chip внутри компонента. Это удобно для скруглённых компонентов.

<template>
  <B24Chip inset>
    <B24Avatar src="/b24ui/avatar/employee.png" loading="lazy" />
  </B24Chip>
</template>

Отдельный индикатор

Пропс standalone вместе с пропсом inset показывает Chip в строке.

<template>
  <B24Chip standalone inset />
</template>
Так он используется, например, в компонентах CommandPalette, InputMenu, Select и SelectMenu.

Примеры

Управление видимостью

Видимостью Chip управляет пропс show.

<script setup lang="ts">
const statuses = ['online', 'away', 'busy', 'offline']
const status = ref(statuses[0])

const color = computed(() => status.value ? { online: 'air-primary-success', away: 'air-primary-warning', busy: 'air-primary-alert', offline: 'air-tertiary' }[status.value] as any : 'online')

const show = computed(() => status.value !== 'offline')

// Примечание: только для демонстрации. Не повторяйте это в рабочем коде.
onMounted(() => {
  setInterval(() => {
    if (status.value) {
      status.value = statuses[(statuses.indexOf(status.value) + 1) % statuses.length]
    }
  }, 1000)
})
</script>

<template>
  <B24Chip :color="color" :show="show" inset>
    <B24Avatar src="/b24ui/avatar/employee.png" loading="lazy" />
  </B24Chip>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'

const statuses = ['online', 'away', 'busy', 'offline']
const status = ref(statuses[0])

const color = computed(() => status.value ? { online: 'air-primary-success', away: 'air-primary-warning', busy: 'air-primary-alert', offline: 'air-tertiary' }[status.value] as any : 'online')

const show = computed(() => status.value !== 'offline')

// Примечание: только для демонстрации. Не повторяйте это в рабочем коде.
onMounted(() => {
  setInterval(() => {
    if (status.value) {
      status.value = statuses[(statuses.indexOf(status.value) + 1) % statuses.length]
    }
  }, 1000)
})
</script>

<template>
  <B24Chip :color="color" :show="show" inset>
    <B24Avatar src="/b24ui/avatar/employee.png" loading="lazy" />
  </B24Chip>
</template>
В этом примере у каждого статуса свой цвет Chip, а показывается он, когда статус не offline.

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

text string | number

Display some text inside the chip.

trailingIconIconComponent

The icon displayed on the right side of the chip.

color'danger'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary" | "air-secondary-accent" | "air-secondary-accent-1" | "air-tertiary"
invertedfalseboolean

If set to true the color is inverted. Used for 'air-primary', 'air-primary-success', 'air-primary-alert', 'air-primary-copilot' and 'air-primary-warning' colors.

size'sm' "sm" | "md" | "lg"
position'top-right' "top-right" | "bottom-right" | "top-left" | "bottom-left"

The position of the chip.

insetfalseboolean

When true, keep the chip inside the component for rounded elements

standalonefalseboolean

When true, render the chip relatively to the parent.

hideZerofalseboolean

When true, hide chip if value='0'

showtrueboolean
b24ui { root?: SlotClass; base?: SlotClass; trailingIcon?: SlotClass; }

Слоты

Slot Type
default{}
content{}
trailing{}

События

Event Type
update:show[value: boolean]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/chip.ts
export default {
  slots: {
    root: 'relative shrink-0 isolate inline-flex items-center justify-center',
    base: 'ui-counter__scope --air font-[family-name:var(--ui-font-family-primary)] font-(--ui-font-weight-medium) select-none relative min-w-(--ui-counter-size) h-(--ui-counter-size) py-0 px-(--ui-counter-inline-space) inline-flex items-center justify-center bg-(--b24ui-background) rounded-(--ui-counter-current-size) ring-(length:--b24ui-border-width) ring-(--b24ui-border-color) text-center align-middle text-(length:--ui-counter-font-size) text-(--b24ui-color) leading-(--ui-counter-current-size) overflow-hidden z-1 text-nowrap',
    trailingIcon: 'size-(--ui-counter-size) text-inherit text-(length:--ui-counter-symbol-font-size) opacity-96 tracking-(--ui-letter-spacing-xl) me-(--ui-counter-symbol-compensation) empty:me-[0]'
  },
  variants: {
    color: {
      'air-primary': {
        base: 'style-filled'
      },
      'air-primary-success': {
        base: 'style-filled-success'
      },
      'air-primary-alert': {
        base: 'style-filled-alert'
      },
      'air-primary-copilot': {
        base: 'style-filled-copilot'
      },
      'air-primary-warning': {
        base: 'style-filled-warning'
      },
      'air-secondary': {
        base: 'style-tinted-no-accent-1'
      },
      'air-secondary-accent': {
        base: 'style-filled-no-accent'
      },
      'air-secondary-accent-1': {
        base: 'style-filled-no-accent-inverted edge-dark:text-(--ui-color-g-content-grey-2)'
      },
      'air-tertiary': {
        base: 'style-outline-no-accent'
      },
      default: {
        base: 'style-old-default'
      },
      danger: {
        base: 'style-old-danger'
      },
      success: {
        base: 'style-old-success'
      },
      warning: {
        base: 'style-old-warning'
      },
      primary: {
        base: 'style-old-primary'
      },
      secondary: {
        base: 'style-old-secondary'
      },
      collab: {
        base: 'style-old-collab'
      },
      ai: {
        base: 'style-old-ai'
      }
    },
    size: {
      sm: 'ui-counter-sm font-(--ui-font-weight-regular)',
      md: 'ui-counter-md',
      lg: 'ui-counter-lg'
    },
    position: {
      'top-right': 'top-0 right-0',
      'bottom-right': 'bottom-0 right-0',
      'top-left': 'top-0 left-0',
      'bottom-left': 'bottom-0 left-0'
    },
    inverted: {
      true: '',
      false: ''
    },
    inset: {
      false: ''
    },
    standalone: {
      true: '',
      false: 'absolute'
    },
    hideZero: {
      true: {
        base: 'data-[value=0]:hidden'
      }
    },
    oneDigit: {
      true: {
        base: 'px-0'
      }
    }
  },
  compoundVariants: [
    {
      position: 'top-right',
      inset: false,
      standalone: false,
      class: '-translate-y-1/2 translate-x-1/2 transform'
    },
    {
      position: 'bottom-right',
      inset: false,
      standalone: false,
      class: 'translate-y-1/2 translate-x-1/2 transform'
    },
    {
      position: 'top-left',
      inset: false,
      standalone: false,
      class: '-translate-y-1/2 -translate-x-1/2 transform'
    },
    {
      position: 'bottom-left',
      inset: false,
      standalone: false,
      class: 'translate-y-1/2 -translate-x-1/2 transform'
    },
    {
      position: 'top-right',
      size: [
        'sm',
        'md',
        'lg'
      ],
      inset: true,
      standalone: false,
      class: '-translate-y-1/3 translate-x-1/3 transform'
    },
    {
      position: 'bottom-right',
      size: [
        'sm',
        'md',
        'lg'
      ],
      inset: true,
      standalone: false,
      class: 'translate-y-1/3 translate-x-1/3 transform'
    },
    {
      position: 'top-left',
      size: [
        'sm',
        'md',
        'lg'
      ],
      inset: true,
      standalone: false,
      class: '-translate-y-1/3 -translate-x-1/3 transform'
    },
    {
      position: 'bottom-left',
      size: [
        'sm',
        'md',
        'lg'
      ],
      inset: true,
      standalone: false,
      class: 'translate-y-1/3 -translate-x-1/3 transform'
    },
    {
      inverted: true,
      color: 'air-primary',
      class: {
        base: 'style-filled-inverted'
      }
    }
  ],
  defaultVariants: {
    size: 'sm',
    color: 'air-primary-alert',
    position: 'top-right',
    inverted: false
  }
}
Some colors in compoundVariants are omitted for readability. Check out the source code on GitHub.