v2.15.0

Toggle Soon

Кнопка, которую можно нажать и отжать: у неё два состояния.

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

Директива v-model управляет нажатым состоянием Toggle.

<script setup lang="ts">
const value = ref(true)
</script>

<template>
  <B24Toggle v-model="value" label="Жирный" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref(true)
</script>

<template>
  <B24Toggle v-model="value" label="Жирный" />
</template>

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

<template>
  <B24Toggle default-value label="Жирный" />
</template>
Toggle построен на Button, поэтому принимает его пропсы: label, icon, size и другие, кроме пропсов ссылки. Нажатое состояние Toggle передаёт в пропс active у Button.

Иконка

Пропс icon показывает иконку. Кнопке без подписи нужен aria-label.

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

<template>
  <B24Toggle :icon="RocketIcon" aria-label="Запуск" />
</template>

Цвет

Пропс color задаёт цвет неактивного Toggle. По умолчанию air-secondary-no-accent.

<template>
  <B24Toggle color="air-tertiary-no-accent" label="Жирный" />
</template>

Цвет нажатого

Пропс active-color задаёт цвет нажатого Toggle. По умолчанию air-primary.

<template>
  <B24Toggle active-color="air-primary-success" default-value label="Жирный" />
</template>

Размер

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

<template>
  <B24Toggle size="xl" label="Жирный" />
</template>

Отключение

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

<template>
  <B24Toggle disabled label="Жирный" />
</template>

Примеры

Стиль нажатого состояния

В нажатом состоянии Toggle получает data-state="on", и его можно оформить вариантом data-[state=on].

<template>
  <B24Toggle label="Жирный" class="data-[state=on]:italic" />
</template>

API

Пропсы

Prop Default Type
as'button'any

The element or component this component should render as when not a link.

id string
color'air-secondary-no-accent'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "link"

The color of the toggle when not pressed.

activeColor'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "link"

The color of the toggle when pressed.

iconIconComponent

Display an icon on the left side.

avatar AvatarProps

Display an avatar on the left side.

loadingboolean

When true, the loading icon will be displayed.

autofocus false | true | "true" | "false"
disabledboolean
name string
label string
size'md' "xl" | "md" | "xs" | "sm" | "lg" | "xss"
roundedfalseboolean

Rounds the corners of the button

blockfalseboolean

Render the button full width

normalCasetrueboolean

Disable uppercase label

useWaitfalseboolean

Shows LoaderWaitIcon in loading mode

useClockfalseboolean

Shows LoaderClockIcon icon in loading mode

useDropdownfalseboolean

Shows a dropdown chevron on the right side, from the dictionary's chevronDown role, so an app.config override reaches it.

modelValueundefinedboolean | null

The controlled pressed state of the toggle. Can be bind as v-model.

defaultValueboolean

The pressed state of the toggle when it is initially rendered. Use when you do not need to control its open state.

requiredboolean

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

b24ui { base?: SlotClass; baseLoading?: SlotClass; baseLoadingWaitIcon?: SlotClass; baseLoadingClockIcon?: SlotClass; baseLoadingSpinnerIcon?: SlotClass; baseLine?: SlotClass; label?: SlotClass; labelInner?: SlotClass; leadingIcon?: SlotClass; leadingAvatar?: SlotClass; leadingAvatarSize?: SlotClass; trailingIcon?: SlotClass; safeList?: SlotClass; }

Слоты

Slot Type
leading{ b24ui: object; }
default{ b24ui: object; }
trailing{ b24ui: object; }

События

Event Type
change[event: Event]
update:modelValue[value: boolean]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/toggle.ts
export default {
  base: ''
}