Использование
Директива v-model управляет нажатыми элементами ToggleGroup.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
const value = ref('day')
</script>
<template>
<B24ToggleGroup v-model="value" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
const value = ref('day')
</script>
<template>
<B24ToggleGroup v-model="value" :items="items" />
</template>
Пропс default-value задаёт начальное значение, когда состоянием не нужно управлять.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup default-value="week" :items="items" />
</template>
Элементы
Пропс items — массив объектов. Они принимают пропсы Button, кроме пропсов ссылки, и поле value: по умолчанию это индекс элемента строкой, поэтому модель тоже хранит строки.
value?: AcceptableValuelabel?: stringicon?: IconComponentdisabled?: booleanclass?: anyb24ui?: ButtonProps['b24ui']
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup default-value="week" :items="items" />
</template>
items, включая href, to и обработчики, попадают в кнопку. Не собирайте items из недоверенных данных.Иконки
Элементы с icon и без подписи требуют aria-label: по нему кнопку находят скринридеры.
<script setup lang="ts">
import { RocketIcon } from '@bitrix24/b24icons-vue/main/RocketIcon'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
value: 'day',
'aria-label': 'День'
},
{
value: 'week',
'aria-label': 'Неделя'
},
{
value: 'month',
'aria-label': 'Месяц'
}
])
</script>
<template>
<B24ToggleGroup default-value="day" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { RocketIcon } from '@bitrix24/b24icons-vue/main/RocketIcon'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
value: 'day',
'aria-label': 'День'
},
{
value: 'week',
'aria-label': 'Неделя'
},
{
value: 'month',
'aria-label': 'Месяц'
}
])
</script>
<template>
<B24ToggleGroup default-value="day" :items="items" />
</template>
Несколько значений
Значение multiple в пропсе type разрешает нажимать сразу несколько элементов. Модель тогда — массив.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'Жирный',
value: 'bold'
},
{
label: 'Курсив',
value: 'italic'
},
{
label: 'Подчёркнутый',
value: 'underline'
}
])
</script>
<template>
<B24ToggleGroup
type="multiple"
:default-value="{
'0': 'bold',
'1': 'italic'
}"
:items="items"
/>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'Жирный',
value: 'bold'
},
{
label: 'Курсив',
value: 'italic'
},
{
label: 'Подчёркнутый',
value: 'underline'
}
])
</script>
<template>
<B24ToggleGroup
type="multiple"
:default-value="{
'0': 'bold',
'1': 'italic'
}"
:items="items"
/>
</template>
Ориентация
Пропс orientation меняет направление раскладки. По умолчанию horizontal.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup orientation="vertical" default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup orientation="vertical" default-value="week" :items="items" />
</template>
Соединение
Пропс attached соединяет элементы в одну группу, как в FieldGroup.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup attached default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup attached default-value="week" :items="items" />
</template>
--ui-btn-radius: пропс rounded у элемента на них не действует. Если в группе есть и кнопки, и ссылки (to превращает элемент в <a>), скругление получится неверным: первая и последняя кнопки определяются отдельно для каждого тега.Цвет
Пропс color задаёт цвет неактивных элементов. По умолчанию air-secondary-no-accent.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup color="air-tertiary-no-accent" default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup color="air-tertiary-no-accent" default-value="week" :items="items" />
</template>
Цвет нажатого
Пропс active-color задаёт цвет нажатых элементов. По умолчанию air-primary.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup active-color="air-primary-success" default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup active-color="air-primary-success" default-value="week" :items="items" />
</template>
Размер
Пропс size меняет размер элементов.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup size="xl" default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup size="xl" default-value="week" :items="items" />
</template>
Отключение
Пропс disabled отключает ToggleGroup.
<script setup lang="ts">
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup disabled default-value="week" :items="items" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ToggleGroupItem } from '@bxshefby/b24ui-nuxt'
const items = ref<ToggleGroupItem[]>([
{
label: 'День',
value: 'day'
},
{
label: 'Неделя',
value: 'week'
},
{
label: 'Месяц',
value: 'month'
}
])
</script>
<template>
<B24ToggleGroup disabled default-value="week" :items="items" />
</template>
API
Пропсы
Слоты
События
Тема
export default {
slots: {
root: 'relative',
item: ''
},
variants: {
orientation: {
horizontal: {
root: 'inline-flex items-center gap-1'
},
vertical: {
root: 'flex flex-col gap-1'
}
},
attached: {
true: {
item: 'rounded-none data-[state=on]:z-[1] focus-visible:z-[2]'
}
}
},
compoundVariants: [
{
orientation: 'horizontal',
attached: true,
class: {
root: 'gap-0',
item: 'not-first-of-type:-ms-px first-of-type:rounded-s-(--ui-btn-radius) last-of-type:rounded-e-(--ui-btn-radius)'
}
},
{
orientation: 'vertical',
attached: true,
class: {
root: 'gap-0',
item: 'not-first-of-type:-mt-px first-of-type:rounded-t-(--ui-btn-radius) last-of-type:rounded-b-(--ui-btn-radius)'
}
}
],
defaultVariants: {
orientation: 'horizontal'
}
}