v2.15.0

CheckboxGroup

Список с множественным выбором на кнопочных элементах.

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

Значением CheckboxGroup управляет директива v-model, а если управлять состоянием не нужно, начальное значение задаёт пропс default-value.

Системная
Светлая
Тёмная
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref(['Системная'])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref(['Системная'])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>

Элементы

Пропс items — массив строк или чисел:

Системная
Светлая
Тёмная
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref(['Системная'])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref(['Системная'])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>

Можно передать и массив объектов со свойствами:

  • label?: string
  • description?: string
  • value?: string
  • disabled?: boolean
  • icon?: IconComponent
  • class?: any
  • b24ui?: { item?: ClassNameValue, container?: ClassNameValue, base?: ClassNameValue, 'indicator'?: ClassNameValue, wrapper?: ClassNameValue, label?: ClassNameValue, description?: ClassNameValue }
Системная

Это первый вариант.

Светлая

Это второй вариант.

Тёмная

Это третий вариант.

<script setup lang="ts">
import type { CheckboxGroupItem } from '@bxshefby/b24ui-nuxt'

const items = ref<CheckboxGroupItem[]>([
  {
    label: 'Системная',
    description: 'Это первый вариант.',
    value: 'system'
  },
  {
    label: 'Светлая',
    description: 'Это второй вариант.',
    value: 'light'
  },
  {
    label: 'Тёмная',
    description: 'Это третий вариант.',
    value: 'dark'
  }
])
const value = ref([
  'system'
])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { CheckboxGroupItem } from '@bxshefby/b24ui-nuxt'

const items = ref<CheckboxGroupItem[]>([
  {
    label: 'Системная',
    description: 'Это первый вариант.',
    value: 'system'
  },
  {
    label: 'Светлая',
    description: 'Это второй вариант.',
    value: 'light'
  },
  {
    label: 'Тёмная',
    description: 'Это третий вариант.',
    value: 'dark'
  }
])
const value = ref([
  'system'
])
</script>

<template>
  <B24CheckboxGroup v-model="value" :items="items" />
</template>
Если элементы — объекты, в v-model или default-value указывайте свойство value объекта.

Ключ значения

Свойство, из которого берётся значение, меняет пропс value-key. По умолчанию — value.

Системная

Это первый вариант.

Светлая

Это второй вариант.

Тёмная

Это третий вариант.

<script setup lang="ts">
import type { CheckboxGroupItem } from '@bxshefby/b24ui-nuxt'

const items = ref<CheckboxGroupItem[]>([
  {
    label: 'Системная',
    description: 'Это первый вариант.',
    id: 'system'
  },
  {
    label: 'Светлая',
    description: 'Это второй вариант.',
    id: 'light'
  },
  {
    label: 'Тёмная',
    description: 'Это третий вариант.',
    id: 'dark'
  }
])
const value = ref([
  'light'
])
</script>

<template>
  <B24CheckboxGroup v-model="value" value-key="id" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { CheckboxGroupItem } from '@bxshefby/b24ui-nuxt'

const items = ref<CheckboxGroupItem[]>([
  {
    label: 'Системная',
    description: 'Это первый вариант.',
    id: 'system'
  },
  {
    label: 'Светлая',
    description: 'Это второй вариант.',
    id: 'light'
  },
  {
    label: 'Тёмная',
    description: 'Это третий вариант.',
    id: 'dark'
  }
])
const value = ref([
  'light'
])
</script>

<template>
  <B24CheckboxGroup v-model="value" value-key="id" :items="items" />
</template>

Легенда

Пропс legend задаёт легенду CheckboxGroup.

Тема
Системная
Светлая
Тёмная
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    legend="Тема"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    legend="Тема"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Цвет

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

Системная
Светлая
Тёмная
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    color="air-primary-copilot"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    color="air-primary-copilot"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Вариант

Пропс variant меняет вариант CheckboxGroup.

<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    color="air-primary-copilot"
    variant="card"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    color="air-primary-copilot"
    variant="card"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Размер

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

<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    size="lg"
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    size="lg"
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Ориентация

Пропс orientation меняет ориентацию CheckboxGroup. По умолчанию — vertical.

<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    orientation="horizontal"
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    orientation="horizontal"
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Индикатор

Пропс indicator меняет положение индикатора или скрывает его. По умолчанию — start.

Пока индикатор виден, icon элемента заменяет галочку, а при hidden показывается над подписью.
<script setup lang="ts">
import type { CheckboxGroupItem } from '@bxshefby/b24ui-nuxt'
import ThemeIcon from '@bitrix24/b24icons-vue/outline/ThemeIcon'
import SunIcon from '@bitrix24/b24icons-vue/outline/SunIcon'
import MoonIcon from '@bitrix24/b24icons-vue/outline/MoonIcon'

const items: CheckboxGroupItem[] = [
  { label: 'Системная', value: 'system', icon: ThemeIcon, class: 'w-24' },
  { label: 'Светлая', value: 'light', icon: SunIcon, class: 'w-24' },
  { label: 'Тёмная', value: 'dark', icon: MoonIcon, class: 'w-24' }
]
</script>

<template>
  <B24CheckboxGroup
    :items="items"
    :default-value="['system']"
    indicator="hidden"
    orientation="horizontal"
    variant="table"
  />
</template>
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    indicator="end"
    variant="card"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    indicator="end"
    variant="card"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Отключение

Пропс disabled отключает CheckboxGroup.

<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    disabled
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    disabled
    variant="list"
    :default-value="{
      '0': 'Системная'
    }"
    :items="items"
  />
</template>

Максимум 2.15+

Пропс max ограничивает число отмечаемых элементов. Когда предел достигнут, остальные элементы отметить нельзя.

Системная
Светлая
Тёмная
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    :max="2"
    :default-value="{
      '0': 'Системная',
      '1': 'Светлая'
    }"
    :items="items"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>

<template>
  <B24CheckboxGroup
    :max="2"
    :default-value="{
      '0': 'Системная',
      '1': 'Светлая'
    }"
    :items="items"
  />
</template>

Примеры

Раскладка настроек

Вариант card вместе со слотом #label даёт выбор в стиле настроек: у каждого варианта есть заголовок, описание, ссылка «Learn more» и картинка предпросмотра. Слот подписи отрисовывается внутри <span>, поэтому подойдёт любая раскладка из фразового содержимого (flex, ссылка, изображение).

<script setup lang="ts">
type CapabilityItem = {
  value: string
  title: string
  text: string
  href: string
}

const value = ref<string[]>(['columns'])

const items: CapabilityItem[] = [
  {
    value: 'columns',
    title: 'В колонках',
    text: 'Выберите для ресурсов, которые всегда должны быть на виду у менеджера. Это основные ресурсы, вокруг которых строится расписание.',
    href: 'https://helpdesk.bitrix24.com/'
  },
  {
    value: 'list',
    title: 'В дополнительном списке',
    text: 'Выберите для ресурсов, которые бронируются только вместе с основным. Например, если основной ресурс — специалисты, оборудование попадает в дополнительный список.',
    href: 'https://helpdesk.bitrix24.com/'
  }
]
</script>

<template>
  <B24CheckboxGroup
    v-model="value"
    variant="card"
    size="md"
    :items="items"
    class="w-full max-w-2xl"
  >
    <template #label="{ item }">
      <span class="flex gap-3 items-start w-full">
        <span class="flex-1 min-w-0 flex flex-col gap-1">
          <span class="text-(length:--ui-font-size-md) font-(--ui-font-weight-medium)">
            {{ item.title }}
          </span>
          <span class="text-(length:--ui-font-size-sm) text-description font-(--ui-font-weight-regular)">
            {{ item.text }}
          </span>
          <B24Link
            :to="item.href"
            target="_blank"
            class="self-start mt-1 text-(length:--ui-font-size-sm)"
            @click.stop
          >
            Подробнее
          </B24Link>
        </span>
        <Placeholder class="hidden sm:flex shrink-0 w-[120px] h-[72px] text-(length:--ui-font-size-xs) text-description">
          Предпросмотр
        </Placeholder>
      </span>
    </template>
  </B24CheckboxGroup>
</template>
<script setup lang="ts">
import { ref } from 'vue'

type CapabilityItem = {
  value: string
  title: string
  text: string
  href: string
}

const value = ref<string[]>(['columns'])

const items: CapabilityItem[] = [
  {
    value: 'columns',
    title: 'В колонках',
    text: 'Выберите для ресурсов, которые всегда должны быть на виду у менеджера. Это основные ресурсы, вокруг которых строится расписание.',
    href: 'https://helpdesk.bitrix24.com/'
  },
  {
    value: 'list',
    title: 'В дополнительном списке',
    text: 'Выберите для ресурсов, которые бронируются только вместе с основным. Например, если основной ресурс — специалисты, оборудование попадает в дополнительный список.',
    href: 'https://helpdesk.bitrix24.com/'
  }
]
</script>

<template>
  <B24CheckboxGroup
    v-model="value"
    variant="card"
    size="md"
    :items="items"
    class="w-full max-w-2xl"
  >
    <template #label="{ item }">
      <span class="flex gap-3 items-start w-full">
        <span class="flex-1 min-w-0 flex flex-col gap-1">
          <span class="text-(length:--ui-font-size-md) font-(--ui-font-weight-medium)">
            {{ item.title }}
          </span>
          <span class="text-(length:--ui-font-size-sm) text-description font-(--ui-font-weight-regular)">
            {{ item.text }}
          </span>
          <B24Link
            :to="item.href"
            target="_blank"
            class="self-start mt-1 text-(length:--ui-font-size-sm)"
            @click.stop
          >
            Подробнее
          </B24Link>
        </span>
        <Placeholder class="hidden sm:flex shrink-0 w-[120px] h-[72px] text-(length:--ui-font-size-xs) text-description">
          Предпросмотр
        </Placeholder>
      </span>
    </template>
  </B24CheckboxGroup>
</template>

Собрать расширенный выбор настроек на карточках с чекбоксами (предпросмотр, описание, ссылка).

Чтобы щелчок по встроенной ссылке не переключал чекбокс, добавьте ей @click.stop.
Тот же приём работает и для выбора одного варианта — см. RadioGroup → Раскладка настроек. Для сеток «иконка + описание» (без картинки предпросмотра) используйте B24PageCardGroup.

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

legend string
valueKey'value' VK

When items is an array of objects, select the field to use as the value.

labelKey'label' keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>>

When items is an array of objects, select the field to use as the label.

descriptionKey'description' keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>>

When items is an array of objects, select the field to use as the description.

items T
modelValue GetItemValue<T, VK, undefined, NestedItem<T>>[]

The controlled value of the CheckboxGroup. Can be bind as v-model.

defaultValue GetItemValue<T, VK, undefined, NestedItem<T>>[]

The value of the CheckboxGroup when initially rendered. Use when you do not need to control the state of the CheckboxGroup.

size'md' "xs" | "sm" | "md" | "lg"
variant'list' "card" | "list" | "table"
orientation'vertical' "horizontal" | "vertical"

The orientation the checkbox buttons are laid out.

disabledboolean

When true, prevents the user from interacting with the checkboxes

loopfalseboolean

Whether keyboard navigation should loop around

max null | number

The maximum number of values that can be selected. Once reached, the unchecked checkboxes get aria-disabled but stay focusable, so consider telling users about the limit. Style them with [aria-disabled="true"].

name string

The name of the field. Submitted with its owning form as part of a name/value pair.

requiredboolean

When true, indicates that the user must set the value before the owning form can be submitted.

iconicons.checkIconComponent

The icon displayed when checked, or above the label when indicator is hidden.

color'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot"
highlightboolean

Highlight the ring color like a focus state.

indicator'start' "start" | "end" | "hidden"

Position of the indicator.

b24ui { root?: SlotClass; fieldset?: SlotClass; legend?: SlotClass; item?: SlotClass; } & { root?: SlotClass; base?: SlotClass; indicator?: SlotClass; container?: SlotClass; icon?: SlotClass; wrapper?: SlotClass; label?: SlotClass; description?: SlotClass; }

Слоты

Slot Type
legend{}
label{ item: Exclude<T[number] & { id: string; }, AcceptableValue>; }
description{ item: Exclude<T[number] & { id: string; }, AcceptableValue>; }

События

Event Type
update:modelValue[value: GetItemValue<T, VK, undefined, NestedItem<T>>[]]
change[event: Event]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/checkbox-group.ts
export default {
  slots: {
    root: 'relative',
    fieldset: 'flex gap-x-2',
    legend: 'mb-1.5 block text-label',
    item: ''
  },
  variants: {
    orientation: {
      horizontal: {
        fieldset: 'flex-row'
      },
      vertical: {
        fieldset: 'flex-col'
      }
    },
    color: {
      'air-primary': {
        item: 'style-filled'
      },
      'air-primary-success': {
        item: 'style-filled-success'
      },
      'air-primary-alert': {
        item: 'style-filled-alert'
      },
      'air-primary-copilot': {
        item: 'style-filled-copilot'
      },
      'air-primary-warning': {
        item: 'style-filled-warning'
      },
      default: {
        item: 'style-old-default'
      },
      danger: {
        item: 'style-old-danger'
      },
      success: {
        item: 'style-old-success'
      },
      warning: {
        item: 'style-old-warning'
      },
      primary: {
        item: 'style-old-primary'
      },
      secondary: {
        item: 'style-old-secondary'
      },
      collab: {
        item: 'style-old-collab'
      },
      ai: {
        item: 'style-old-ai'
      }
    },
    variant: {
      list: {
        fieldset: 'flex-wrap'
      },
      card: {
        fieldset: 'flex-wrap',
        item: 'cursor-pointer items-start border border-(--ui-color-design-outline-na-stroke) bg-(--ui-color-design-outline-na-bg) has-data-[state=checked]:border-(--b24ui-border-color)'
      },
      table: {
        item: 'cursor-pointer has-aria-disabled:cursor-not-allowed border border-(--ui-color-design-outline-na-stroke) bg-(--ui-color-design-outline-na-bg) has-data-[state=checked]:bg-(--b24ui-background)/24 has-data-[state=checked]:border-(--b24ui-border-color) has-data-[state=checked]:text-(--b24ui-color) has-data-[state=checked]:z-[1]'
      }
    },
    size: {
      xs: {
        fieldset: 'gap-x-[12px] gap-y-[4px]',
        legend: 'text-(length:--ui-font-size-xs)'
      },
      sm: {
        fieldset: 'gap-x-[14px] gap-y-[6px]',
        legend: 'text-(length:--ui-font-size-xs)'
      },
      md: {
        fieldset: 'gap-x-[16px] gap-y-2',
        legend: 'text-(length:--ui-font-size-sm)'
      },
      lg: {
        fieldset: 'gap-x-[16px] gap-y-2',
        legend: 'text-(length:--ui-font-size-sm)'
      }
    },
    disabled: {
      true: {}
    },
    required: {
      true: {
        label: "after:content-['*'] after:ms-0.5 after:text-(--ui-color-accent-main-alert)"
      }
    }
  },
  compoundVariants: [
    {
      size: 'xs',
      variant: 'card',
      class: {
        item: 'px-[13px] py-[7px] rounded-(--ui-border-radius-xs)'
      }
    },
    {
      size: 'sm',
      variant: 'card',
      class: {
        item: 'px-[13px] py-[9px] rounded-(--ui-border-radius-sm)'
      }
    },
    {
      size: 'md',
      variant: 'card',
      class: {
        item: 'px-[17px] py-[10px] rounded-(--ui-border-radius-md)'
      }
    },
    {
      size: 'lg',
      variant: 'card',
      class: {
        item: 'px-[23px] py-[12px] rounded-(--ui-border-radius-md)'
      }
    },
    {
      size: 'xs',
      variant: 'table',
      class: {
        item: 'px-[13px] py-[7px]'
      }
    },
    {
      size: 'sm',
      variant: 'table',
      class: {
        item: 'px-[13px] py-[9px]'
      }
    },
    {
      size: 'md',
      variant: 'table',
      class: {
        item: 'px-[17px] py-[10px]'
      }
    },
    {
      size: 'lg',
      variant: 'table',
      class: {
        item: 'px-[23px] py-[12px]'
      }
    },
    {
      size: 'xs',
      variant: 'table',
      orientation: 'horizontal',
      class: {
        item: 'first-of-type:rounded-s-(--ui-border-radius-xs) last-of-type:rounded-e-(--ui-border-radius-xs)',
        fieldset: 'gap-0 -space-x-px'
      }
    },
    {
      size: 'xs',
      variant: 'table',
      orientation: 'vertical',
      class: {
        item: 'first-of-type:rounded-t-(--ui-border-radius-xs) last-of-type:rounded-b-(--ui-border-radius-xs)',
        fieldset: 'gap-0 -space-y-px'
      }
    },
    {
      size: 'sm',
      variant: 'table',
      orientation: 'horizontal',
      class: {
        item: 'first-of-type:rounded-s-(--ui-border-radius-sm) last-of-type:rounded-e-(--ui-border-radius-sm)',
        fieldset: 'gap-0 -space-x-px'
      }
    },
    {
      size: 'sm',
      variant: 'table',
      orientation: 'vertical',
      class: {
        item: 'first-of-type:rounded-t-(--ui-border-radius-sm) last-of-type:rounded-b-(--ui-border-radius-sm)',
        fieldset: 'gap-0 -space-y-px'
      }
    },
    {
      size: [
        'lg',
        'md'
      ],
      variant: 'table',
      orientation: 'horizontal',
      class: {
        item: 'first-of-type:rounded-s-(--ui-border-radius-md) last-of-type:rounded-e-(--ui-border-radius-md)',
        fieldset: 'gap-0 -space-x-px'
      }
    },
    {
      size: [
        'lg',
        'md'
      ],
      variant: 'table',
      orientation: 'vertical',
      class: {
        item: 'first-of-type:rounded-t-(--ui-border-radius-md) last-of-type:rounded-b-(--ui-border-radius-md)',
        fieldset: 'gap-0 -space-y-px'
      }
    },
    {
      variant: 'table',
      disabled: true,
      class: {
        item: 'cursor-not-allowed'
      }
    }
  ],
  defaultVariants: {
    size: 'md',
    variant: 'list',
    color: 'air-primary'
  }
}