v2.15.0

Range

Элемент управления для выбора числового значения в заданном диапазоне.

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

Директива v-model управляет значением Range.

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

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

const value = ref(50)
</script>

<template>
  <B24Range v-model="value" />
</template>

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

<template>
  <B24Range :default-value="50" />
</template>
Чтобы назвать Range с одним бегунком, используйте aria-label или aria-labelledby: они передаются бегунку — элементу с ролью slider.У Range с несколькими бегунками бегунки получают названия по положению, чтобы их можно было различать: Minimum / Maximum для двух и Value n of m для трёх и более. Эти названия сохраняются, а aria-label называет Range целиком через роль group на корне и не повторяется на каждом бегунке.

Минимум и максимум

Пропсы min и max задают минимальное и максимальное значения Range. По умолчанию 0 и 100.

<template>
  <B24Range :min="0" :max="50" :default-value="50" />
</template>

Шаг

Пропс step задаёт шаг изменения значения Range. По умолчанию 1.

<template>
  <B24Range :step="10" :default-value="50" />
</template>

Несколько бегунков

Директива v-model или пропс default-value с массивом значений создают Range-диапазон.

<script setup lang="ts">
const value = ref([
  25,
  75
])
</script>

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

const value = ref([
  25,
  75
])
</script>

<template>
  <B24Range v-model="value" />
</template>

Пропс min-steps-between-thumbs ограничивает минимальное расстояние между бегунками.

<script setup lang="ts">
const value = ref([
  25,
  50,
  75
])
</script>

<template>
  <B24Range v-model="value" :min-steps-between-thumbs="10" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const value = ref([
  25,
  50,
  75
])
</script>

<template>
  <B24Range v-model="value" :min-steps-between-thumbs="10" />
</template>

Ориентация

Пропс orientation меняет ориентацию Range. По умолчанию horizontal.

<template>
  <B24Range orientation="vertical" :default-value="50" class="h-48" />
</template>

Цвет

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

<template>
  <B24Range color="air-primary-copilot" :default-value="50" />
</template>

Размер

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

<template>
  <B24Range size="lg" :default-value="50" />
</template>

Подсказка

Пропс tooltip показывает вокруг бегунков Range Tooltip с текущим значением. Значение true включает поведение по умолчанию, а объект настраивает подсказку любыми свойствами компонента Tooltip.

<template>
  <B24Range :default-value="50" tooltip />
</template>

Отключение

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

<template>
  <B24Range disabled :default-value="50" />
</template>

Инверсия

Пропс inverted визуально инвертирует Range.

<template>
  <B24Range inverted :default-value="25" />
</template>

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

size'md' "xs" | "sm" | "md" | "lg"
color'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot"
orientation'horizontal' "horizontal" | "vertical"

The orientation of the range.

tooltipfalseboolean | TooltipProps

Display a tooltip around the range thumbs with the current value. { disableClosingTrigger: true }

defaultValue number | number[]

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

name string

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

disabledboolean

When true, prevents the user from interacting with the slider.

invertedboolean

Whether the slider is visually inverted.

min0 number

The minimum value for the range.

max100 number

The maximum value for the range.

step1 number

The stepping interval.

minStepsBetweenThumbs number

The minimum permitted steps between multiple thumbs.

modelValue T
b24ui { root?: SlotClass; track?: SlotClass; range?: SlotClass; thumb?: SlotClass; }

События

Event Type
change[event: Event]
update:modelValue[value: T | undefined]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/range.ts
export default {
  slots: {
    root: 'relative flex items-center select-none touch-none',
    track: 'relative rounded-(--ui-border-radius-pill) bg-(--ui-color-base-5) grow overflow-hidden',
    range: 'absolute rounded-(--ui-border-radius-pill) bg-(--b24ui-background)',
    thumb: 'rounded-(--ui-border-radius-pill) bg-(--ui-color-base-white-fixed) ring-2 outline-transparent focus-visible:outline-2 focus-visible:outline-offset-2 ring-(--b24ui-background) focus-visible:outline-(--b24ui-background-hover)'
  },
  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'
      }
    },
    size: {
      xs: {
        thumb: 'size-[12px]'
      },
      sm: {
        thumb: 'size-[14px]'
      },
      md: {
        thumb: 'size-[16px]'
      },
      lg: {
        thumb: 'size-[20px]'
      }
    },
    orientation: {
      horizontal: {
        root: 'w-full',
        range: 'h-full'
      },
      vertical: {
        root: 'flex-col h-full',
        range: 'w-full'
      }
    },
    disabled: {
      true: {
        root: 'opacity-30 cursor-not-allowed'
      }
    }
  },
  compoundVariants: [
    {
      orientation: 'horizontal',
      size: 'xs',
      class: {
        track: 'h-[6px]'
      }
    },
    {
      orientation: 'horizontal',
      size: 'sm',
      class: {
        track: 'h-[7px]'
      }
    },
    {
      orientation: 'horizontal',
      size: 'md',
      class: {
        track: 'h-2'
      }
    },
    {
      orientation: 'horizontal',
      size: 'lg',
      class: {
        track: 'h-[9px]'
      }
    },
    {
      orientation: 'horizontal',
      size: 'xl',
      class: {
        track: 'h-[10px]'
      }
    },
    {
      orientation: 'vertical',
      size: 'xs',
      class: {
        track: 'w-[6px]'
      }
    },
    {
      orientation: 'vertical',
      size: 'sm',
      class: {
        track: 'w-[7px]'
      }
    },
    {
      orientation: 'vertical',
      size: 'md',
      class: {
        track: 'w-2'
      }
    },
    {
      orientation: 'vertical',
      size: 'lg',
      class: {
        track: 'w-[9px]'
      }
    },
    {
      orientation: 'vertical',
      size: 'xl',
      class: {
        track: 'w-[10px]'
      }
    }
  ],
  defaultVariants: {
    color: 'air-primary',
    size: 'md'
  }
}