---
title: "Chip"
description: "Индикатор: число или состояние."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/chip"
---
# Chip

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

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

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

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

### Цвет

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

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

### Инверсия

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

> [!WARNING]
> Доступно только для цветов `air-primary*`.

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

### Размер

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

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

### Текст

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

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

### Скрыть ноль

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

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

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

Пропс `trailing-icon` задаёт [иконку](https://bitrix24.github.io/b24icons/icons/) справа.

```vue
<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.

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

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

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

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

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

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

```vue
<template>
  <B24Chip standalone inset />
</template>
```

> [!NOTE]
> Так он используется, например, в компонентах [`CommandPalette`](https://b24-ui.bx-shef.by/raw/docs/components/command-palette.md), [`InputMenu`](https://b24-ui.bx-shef.by/raw/docs/components/input-menu.md), [`Select`](https://b24-ui.bx-shef.by/raw/docs/components/select.md) и [`SelectMenu`](https://b24-ui.bx-shef.by/raw/docs/components/select-menu.md).

## Примеры

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

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

```vue [ChipShowExample.vue]
<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>
```

> [!NOTE]
> В этом примере у каждого статуса свой цвет Chip, а показывается он, когда статус не `offline`.

## API

### Пропсы

```ts
/**
 * Props for the Chip component
 */
interface ChipProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * Display some text inside the chip.
   */
  text?: string | number | undefined;
  /**
   * The icon displayed on the right side of the chip.
   */
  trailingIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * @default 'danger'
   */
  color?: "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";
  /**
   * 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.
   * @default false
   */
  inverted?: boolean | undefined;
  /**
   * @default 'sm'
   */
  size?: "sm" | "md" | "lg" | undefined;
  /**
   * The position of the chip.
   * @default 'top-right'
   */
  position?: "top-right" | "bottom-right" | "top-left" | "bottom-left" | undefined;
  /**
   * When `true`, keep the chip inside the component for rounded elements
   * @default false
   */
  inset?: boolean | undefined;
  /**
   * When `true`, render the chip relatively to the parent.
   * @default false
   */
  standalone?: boolean | undefined;
  /**
   * When `true`, hide chip if value='0'
   * @default false
   */
  hideZero?: boolean | undefined;
  b24ui?: { root?: SlotClass; base?: SlotClass; trailingIcon?: SlotClass; } | undefined;
  /**
   * @default true
   */
  show?: boolean | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Chip component
 */
interface ChipSlots {
  default(): any;
  content(): any;
  trailing(): any;
}
```

### События

```ts
/**
 * Emitted events for the Chip component
 */
interface ChipEmits {
  update:show: (payload: [value: boolean]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    chip: {
      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'
          }
        },
        {
          inverted: true,
          color: 'air-primary-success',
          class: {
            base: 'style-filled-success-inverted'
          }
        },
        {
          inverted: true,
          color: 'air-primary-alert',
          class: {
            base: 'style-filled-alert-inverted'
          }
        },
        {
          inverted: true,
          color: 'air-primary-copilot',
          class: {
            base: 'style-filled-copilot-inverted'
          }
        },
        {
          inverted: true,
          color: 'air-primary-warning',
          class: {
            base: 'style-filled-warning-inverted'
          }
        }
      ],
      defaultVariants: {
        size: 'sm',
        color: 'air-primary-alert',
        position: 'top-right',
        inverted: false
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
