Использование
Директива v-model управляет значением RadioGroup, а пропс default-value задаёт начальное значение, когда управлять состоянием не нужно.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref('Системная')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref('Системная')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
Элементы
Пропс items — массив строк или чисел:
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref('Системная')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
const value = ref('Системная')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
Можно передать и массив объектов со свойствами:
label?: stringdescription?: stringvalue?: stringdisabled?: booleanicon?: IconComponentclass?: anyb24ui?: { item?: ClassNameValue, container?: ClassNameValue, base?: ClassNameValue, 'indicator'?: ClassNameValue, wrapper?: ClassNameValue, label?: ClassNameValue, icon?: ClassNameValue, description?: ClassNameValue }
<script setup lang="ts">
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Системная',
description: 'Это первый вариант.',
value: 'system'
},
{
label: 'Светлая',
description: 'Это второй вариант.',
value: 'light'
},
{
label: 'Тёмная',
description: 'Это третий вариант.',
value: 'dark'
}
])
const value = ref('system')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Системная',
description: 'Это первый вариант.',
value: 'system'
},
{
label: 'Светлая',
description: 'Это второй вариант.',
value: 'light'
},
{
label: 'Тёмная',
description: 'Это третий вариант.',
value: 'dark'
}
])
const value = ref('system')
</script>
<template>
<B24RadioGroup v-model="value" :items="items" />
</template>
v-model или пропсе default-value нужно указывать свойство value объекта.Ключ значения
Свойство, из которого берётся значение, меняется пропсом value-key. По умолчанию value.
<script setup lang="ts">
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Системная',
description: 'Это первый вариант.',
id: 'system'
},
{
label: 'Светлая',
description: 'Это второй вариант.',
id: 'light'
},
{
label: 'Тёмная',
description: 'Это третий вариант.',
id: 'dark'
}
])
const value = ref('light')
</script>
<template>
<B24RadioGroup v-model="value" value-key="id" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Системная',
description: 'Это первый вариант.',
id: 'system'
},
{
label: 'Светлая',
description: 'Это второй вариант.',
id: 'light'
},
{
label: 'Тёмная',
description: 'Это третий вариант.',
id: 'dark'
}
])
const value = ref('light')
</script>
<template>
<B24RadioGroup v-model="value" value-key="id" :items="items" />
</template>
Легенда
Пропс legend задаёт легенду RadioGroup.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup legend="Тема" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup legend="Тема" default-value="Системная" :items="items" />
</template>
Цвет
Пропс color меняет цвет RadioGroup.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup color="air-primary-copilot" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup color="air-primary-copilot" default-value="Системная" :items="items" />
</template>
Вариант
Пропс variant меняет вариант RadioGroup.
<script setup lang="ts">
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Pro',
value: 'pro',
description: 'Для независимых разработчиков, фрилансеров и одиночных основателей.'
},
{
label: 'Стартап',
value: 'startup',
description: 'Подходит небольшим командам, стартапам и агентствам.'
},
{
label: 'Корпоративный',
value: 'enterprise',
description: 'Для крупных команд и организаций.'
}
])
</script>
<template>
<B24RadioGroup color="air-primary-copilot" variant="card" default-value="pro" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { RadioGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<RadioGroupItem[]>([
{
label: 'Pro',
value: 'pro',
description: 'Для независимых разработчиков, фрилансеров и одиночных основателей.'
},
{
label: 'Стартап',
value: 'startup',
description: 'Подходит небольшим командам, стартапам и агентствам.'
},
{
label: 'Корпоративный',
value: 'enterprise',
description: 'Для крупных команд и организаций.'
}
])
</script>
<template>
<B24RadioGroup color="air-primary-copilot" variant="card" default-value="pro" :items="items" />
</template>
Размер
Пропс size меняет размер RadioGroup.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup size="lg" variant="list" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup size="lg" variant="list" default-value="Системная" :items="items" />
</template>
Ориентация
Пропс orientation меняет ориентацию RadioGroup. По умолчанию vertical.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup orientation="horizontal" variant="list" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup orientation="horizontal" variant="list" default-value="Системная" :items="items" />
</template>
Индикатор
Пропс indicator меняет положение индикатора или скрывает его. По умолчанию start.
icon элемента показывается только при indicator, равном hidden, и стоит над подписью: внутри индикатора у переключателя иконки нет.<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup indicator="end" variant="card" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup indicator="end" variant="card" default-value="Системная" :items="items" />
</template>
Отключение
Пропс disabled отключает RadioGroup.
<script setup lang="ts">
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup disabled variant="list" default-value="Системная" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const items = ref(['Системная', 'Светлая', 'Тёмная'])
</script>
<template>
<B24RadioGroup disabled variant="list" default-value="Системная" :items="items" />
</template>
Примеры
Раскладка настроек
Вариант card вместе со слотом #label даёт выбор в стиле настроек: у каждого варианта есть заголовок, описание, ссылка «Learn more» и картинка предпросмотра. Слот подписи отрисовывается внутри <span>, поэтому подойдёт любая раскладка из фразового содержимого (flex, ссылка, изображение).
Собрать расширенный выбор настроек на карточках с переключателями (предпросмотр, описание, ссылка).
Соберите выбор настроек на B24RadioGroup с variant="card". У каждого варианта — заголовок, многострочное описание, встроенная ссылка «Learn more» и картинка предпросмотра справа; всё раскладывается через слот #label.
Прежде чем генерировать код, спросите недостающие сведения, не угадывайте:
- сколько вариантов и какими должны быть их
value,titleи описание; - какой адрес у каждой ссылки «Learn more» (один на всех или у каждого свой);
- откуда берётся предпросмотр: настоящая картинка,
<Placeholder>до готовности графики или его нет вовсе; - нужно ли сохранять выбор (куда привязан
v-model: локальныйref, хранилище Pinia, query-параметр, сервер); - какие
size(sm/md/lg) и токенcolorподходят странице; - находится ли выбор внутри
B24Form(тогда его нужно обернуть вB24FormFieldс подписью).
Требования после подтверждения деталей:
- Объявите локальный
interfaceдля формы элемента (value,title,text,href, необязательныйpreview) и типизируйте им массив — НЕ используйтеRadioGroupItem[](он расширяет пользовательские поля доany) - Внутри слота
#labelиспользуйте только обёртки<span>(без<div>и<p>: в вариантеcardслот отрисовывается как<span>) - Применяйте семантические утилиты (
text-description,text-(length:--ui-font-size-md)и т. п.), а не «сырые» цвета палитры Tailwind - Скрывайте предпросмотр ниже контрольной точки
sm(hidden sm:flex) - Добавьте
@click.stopвстроенномуB24Link, чтобы щелчок по ссылке не переключал переключатель - Если
item.hrefможет прийти из ненадёжного источника, проверьте его перед привязкой (отклоняйтеjavascript:,data:и адреса открытого редиректа)
@click.stop.B24PageCardGroup.API
Пропсы
Слоты
События
Тема
export default {
slots: {
root: 'relative',
fieldset: 'flex',
legend: 'mb-1.5 block text-label',
item: 'flex items-start',
icon: 'shrink-0',
base: 'cursor-pointer rounded-(--ui-border-radius-pill) ring ring-inset ring-(--ui-color-base-5) outline-(--ui-color-background-transparent) focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--b24ui-background)',
indicator: 'flex items-center justify-center size-full rounded-(--ui-border-radius-pill) after:bg-(--b24ui-color) after:rounded-(--ui-border-radius-pill) bg-(--b24ui-background)',
container: 'flex items-center',
wrapper: 'font-[family-name:var(--ui-font-family-primary)] font-(--ui-font-weight-regular) w-full',
label: 'cursor-pointer block text-label',
description: 'text-description'
},
variants: {
color: {
'air-primary': {
root: 'style-filled'
},
'air-primary-success': {
root: 'style-filled-success'
},
'air-primary-alert': {
root: 'style-filled-alert'
},
'air-primary-copilot': {
root: 'style-filled-copilot'
},
'air-primary-warning': {
root: 'style-filled-warning'
},
default: {
root: 'style-old-default'
},
danger: {
root: 'style-old-danger'
},
success: {
root: 'style-old-success'
},
warning: {
root: 'style-old-warning'
},
primary: {
root: 'style-old-primary'
},
secondary: {
root: 'style-old-secondary'
},
collab: {
root: 'style-old-collab'
},
ai: {
root: '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 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]'
}
},
orientation: {
horizontal: {
fieldset: 'flex-row',
root: 'me-2'
},
vertical: {
fieldset: 'flex-col'
}
},
indicator: {
start: {
item: 'flex-row',
base: 'me-2'
},
end: {
item: 'flex-row-reverse',
base: 'ms-2'
},
hidden: {
base: 'sr-only',
item: 'outline-(--ui-color-background-transparent) has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-(--b24ui-background)',
wrapper: 'flex flex-col items-center gap-1 text-center'
}
},
size: {
xs: {
fieldset: 'gap-x-[12px] gap-y-[4px]',
legend: 'text-(length:--ui-font-size-xs)',
base: 'size-[12px]',
item: 'text-(length:--ui-font-size-xs)',
label: 'leading-[11px]',
container: 'h-[12px]',
indicator: 'after:size-[4px]'
},
sm: {
fieldset: 'gap-x-[14px] gap-y-[6px]',
legend: 'text-(length:--ui-font-size-xs)',
base: 'size-[14px]',
item: 'text-(length:--ui-font-size-sm)',
label: 'leading-[14px]',
container: 'h-[14px]',
indicator: 'after:size-[6px]'
},
md: {
fieldset: 'gap-x-[16px] gap-y-2',
legend: 'text-(length:--ui-font-size-sm)',
base: 'size-[16px]',
item: 'text-(length:--ui-font-size-lg)',
label: 'leading-[15px]',
container: 'h-[16px]',
indicator: 'after:size-[6px]'
},
lg: {
fieldset: 'gap-x-[16px] gap-y-2',
legend: 'text-(length:--ui-font-size-sm)',
base: 'size-[20px]',
item: 'text-(length:--ui-font-size-xl)',
label: 'leading-4.5',
container: 'h-[20px]',
indicator: 'after:size-2'
}
},
disabled: {
true: {
item: 'opacity-30',
base: 'cursor-not-allowed',
label: 'cursor-not-allowed',
description: 'cursor-not-allowed'
}
},
required: {
true: {
label: "after:content-['*'] after:ms-0.5 after:text-(--ui-color-accent-main-alert)"
}
},
highlight: {
true: {
base: 'ring ring-inset ring-(--b24ui-border-color)'
}
}
},
compoundVariants: [
{
indicator: 'hidden',
class: {
container: 'h-auto'
}
},
{
size: 'xs',
indicator: 'hidden',
class: {
icon: 'size-3'
}
},
{
size: 'sm',
indicator: 'hidden',
class: {
icon: 'size-3.5'
}
},
{
size: 'md',
indicator: 'hidden',
class: {
icon: 'size-4'
}
},
{
size: 'lg',
indicator: 'hidden',
class: {
icon: 'size-4.5'
}
},
{
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: [
'card',
'table'
],
disabled: true,
class: {
item: 'cursor-not-allowed'
}
}
],
defaultVariants: {
color: 'air-primary',
size: 'md',
variant: 'list',
indicator: 'start'
}
}