---
title: "Stepper"
description: "Компонент пошагового мастера, который показывает прогресс в многошаговом процессе."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/stepper"
---
# Stepper

> Компонент пошагового мастера, который показывает прогресс в многошаговом процессе.

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

Stepper показывает список элементов в виде пошагового мастера.

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper :items="items" />
</template>
```

### Элементы

Пропс `items` — массив объектов со свойствами:

- `title?: string`
- `description?: string`
- `content?: string`
- [`icon?: IconComponent`](#with-controls)
- `value?: string | number`
- `disabled?: boolean`
- [`slot?: string`](#with-custom-slot)
- `class?: any`
- `b24ui?: { item?: ClassNameValue, container?: ClassNameValue, trigger?: ClassNameValue, indicator?: ClassNameValue, icon?: ClassNameValue, separator?: ClassNameValue, wrapper?: ClassNameValue, title?: ClassNameValue, description?: ClassNameValue }`

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper :items="items" class="w-full" />
</template>
```

> [!NOTE]
> Щёлкайте по элементам, чтобы переходить между шагами.

### Цвет

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

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper color="air-primary-alert" :items="items" class="w-full" />
</template>
```

### Размер

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

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper size="xl" :items="items" class="w-full" />
</template>
```

### Ориентация

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

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper orientation="vertical" :items="items" class="w-full" />
</template>
```

### Отключение

Пропс `disabled` отключает переходы между шагами.

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

const items = ref<StepperItem[]>([
  {
    title: 'Адрес',
    description: 'Укажите здесь свой адрес'
  },
  {
    title: 'Доставка',
    description: 'Выберите способ доставки'
  },
  {
    title: 'Оформление',
    description: 'Подтвердите заказ'
  }
])
</script>

<template>
  <B24Stepper disabled :items="items" />
</template>
```

> [!NOTE]
> See: #with-controls
> Это удобно, когда переходить между шагами нужно только с помощью кнопок управления.

## Примеры

### С кнопками управления

Кнопки добавляют Stepper дополнительное управление.

```vue [StepperWithControlsExample.vue]
<script setup lang="ts">
import type { StepperItem } from '@bxshefby/b24ui-nuxt'
import ArrowLeftLIcon from '@bitrix24/b24icons-vue/outline/ArrowLeftLIcon'
import ArrowRightLIcon from '@bitrix24/b24icons-vue/outline/ArrowRightLIcon'
import LocationIcon from '@bitrix24/b24icons-vue/outline/LocationIcon'
import DeliveryIcon from '@bitrix24/b24icons-vue/outline/DeliveryIcon'

const items: StepperItem[] = [
  {
    title: 'Адрес',
    description: 'Укажите свой адрес',
    icon: LocationIcon
  }, {
    title: 'Доставка',
    description: 'Выберите предпочтительный способ доставки',
    icon: DeliveryIcon
  }, {
    title: 'Оформление заказа',
    description: 'Подтвердите заказ'
  }
]

const stepper = useTemplateRef('stepper')
</script>

<template>
  <div class="w-full">
    <B24Stepper ref="stepper" :items="items">
      <template #content="{ item }">
        <Placeholder class="h-[200px]">
          {{ item.title }}
        </Placeholder>
      </template>
    </B24Stepper>

    <div class="flex gap-2 justify-between mt-4">
      <B24Button
        :disabled="!stepper?.hasPrev"
        label="Назад"
        @click="stepper?.prev()"
      >
        <template #leading>
          <ArrowLeftLIcon class="text-(--ui-btn-color) size-(--ui-btn-icon-size)" />
        </template>
      </B24Button>

      <B24Button
        :disabled="!stepper?.hasNext"
        label="Далее"
        @click="stepper?.next()"
      >
        <template #trailing>
          <ArrowRightLIcon class="text-(--ui-btn-color) size-(--ui-btn-icon-size)" />
        </template>
      </B24Button>
    </div>
  </div>
</template>
```

### Управление активным элементом

Активным элементом управляют пропс `default-value` или директива `v-model` со значением `value` элемента. Если `value` не задан, берётся индекс.

```vue [StepperModelValueExample.vue]
<script setup lang="ts">
import type { StepperItem } from '@bxshefby/b24ui-nuxt'
import { onMounted, ref } from 'vue'
import LocationIcon from '@bitrix24/b24icons-vue/outline/LocationIcon'
import DeliveryIcon from '@bitrix24/b24icons-vue/outline/DeliveryIcon'

const items: StepperItem[] = [
  {
    title: 'Адрес',
    description: 'Укажите свой адрес',
    icon: LocationIcon
  }, {
    title: 'Доставка',
    description: 'Выберите предпочтительный способ доставки',
    icon: DeliveryIcon
  }, {
    title: 'Оформление заказа',
    description: 'Подтвердите заказ'
  }
]

const active = ref(0)

// Примечание: только для демонстрации, в реальном проекте так делать не стоит.
onMounted(() => {
  setInterval(() => {
    active.value = (active.value + 1) % items.length
  }, 2000)
})
</script>

<template>
  <B24Stepper v-model="active" :items="items" class="w-full">
    <template #content="{ item }">
      <Placeholder class="h-[200px]">
        Это шаг «{{ item?.title }}».
      </Placeholder>
    </template>
  </B24Stepper>
</template>
```

> [!TIP]
> Пропс `value-key` меняет ключ, по которому элементы сопоставляются с `v-model` или `default-value`.
> Значение сопоставляется с `value-key` каждого элемента независимо от его типа. Число сохраняет позиционный смысл, если у элемента на этой позиции нет `value-key` (поэтому обычные массивы по-прежнему работают по индексу), и превращается в позицию, если ни один элемент не совпал. Числа вне диапазона не выбирают ничего.

### Со слотом content

Слот `#content` настраивает содержимое каждого элемента.

```vue [StepperContentSlotExample.vue]
<script setup lang="ts">
import type { StepperItem } from '@bxshefby/b24ui-nuxt'
import LocationIcon from '@bitrix24/b24icons-vue/outline/LocationIcon'
import DeliveryIcon from '@bitrix24/b24icons-vue/outline/DeliveryIcon'

const items: StepperItem[] = [
  {
    title: 'Адрес',
    description: 'Укажите свой адрес',
    icon: LocationIcon
  }, {
    title: 'Доставка',
    description: 'Выберите предпочтительный способ доставки',
    icon: DeliveryIcon
  }, {
    title: 'Оформление заказа',
    description: 'Подтвердите заказ'
  }
]
</script>

<template>
  <B24Stepper ref="stepper" :items="items" class="w-full">
    <template #content="{ item }">
      <Placeholder class="h-[200px]">
        Это шаг «{{ item?.title }}».
      </Placeholder>
    </template>
  </B24Stepper>
</template>
```

### С собственным слотом

Свойство `slot` настраивает отдельный элемент.

Вам будут доступны слоты:

- `#{{ item.slot }}`

```vue [StepperCustomSlotExample.vue]
<script setup lang="ts">
import type { StepperItem } from '@bxshefby/b24ui-nuxt'
import LocationIcon from '@bitrix24/b24icons-vue/outline/LocationIcon'
import DeliveryIcon from '@bitrix24/b24icons-vue/outline/DeliveryIcon'

const items: StepperItem[] = [
  {
    title: 'Адрес',
    description: 'Укажите свой адрес',
    icon: LocationIcon,
    slot: 'address'
  }, {
    title: 'Доставка',
    description: 'Выберите предпочтительный способ доставки',
    icon: DeliveryIcon,
    slot: 'shipping'
  }, {
    title: 'Оформление заказа',
    description: 'Подтвердите заказ',
    slot: 'checkout'
  }
]
</script>

<template>
  <B24Stepper :items="items" class="w-full">
    <template #address>
      <Placeholder class="h-[200px]">
        Адрес
      </Placeholder>
    </template>

    <template #shipping>
      <Placeholder class="h-[200px]">
        Доставка
      </Placeholder>
    </template>

    <template #checkout>
      <Placeholder class="h-[200px]">
        Оформление заказа
      </Placeholder>
    </template>
  </B24Stepper>
</template>
```

## API

### Пропсы

```ts
/**
 * Props for the Stepper component
 */
interface StepperProps {
  items: T[];
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * @default 'md'
   */
  size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
  /**
   * @default 'air-primary'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot";
  /**
   * The orientation of the stepper.
   * @default 'horizontal'
   */
  orientation?: "horizontal" | "vertical" | undefined;
  /**
   * The key used to get the value from the item.
   * @default 'value'
   */
  valueKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
  /**
   * The value of the step that should be active when initially rendered. Use when you do not need to control the state of the steps.
   */
  defaultValue?: string | number | undefined;
  disabled?: boolean | undefined;
  b24ui?: { root?: SlotClass; header?: SlotClass; item?: SlotClass; container?: SlotClass; trigger?: SlotClass; indicator?: SlotClass; icon?: SlotClass; separator?: SlotClass; wrapper?: SlotClass; title?: SlotClass; description?: SlotClass; content?: SlotClass; } | undefined;
  /**
   * Whether or not the steps must be completed in order.
   * @default true
   */
  linear?: boolean | undefined;
  modelValue?: string | number | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Stepper component
 */
interface StepperSlots {
  indicator(): any;
  wrapper(): any;
  title(): any;
  description(): any;
  content(): any;
}
```

### События

```ts
/**
 * Emitted events for the Stepper component
 */
interface StepperEmits {
  next: (payload: [value: T]) => void;
  prev: (payload: [value: T]) => void;
  update:modelValue: (payload: [value: string | number | undefined]) => void;
}
```

### Доступ через ref

Типизированный экземпляр компонента доступен через [`useTemplateRef`](https://vuejs.org/api/composition-api-helpers.html#usetemplateref).

```vue
<script setup lang="ts">
const stepper = useTemplateRef('stepper')
</script>

<template>
  <B24Stepper ref="stepper" />
</template>
```

Он даёт доступ к следующему:

| Имя | Тип |
| --- | --- |
| `next` | `() => void` |
| `prev` | `() => void` |
| `hasNext` | `Ref<boolean>` |
| `hasPrev` | `Ref<boolean>` |

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    stepper: {
      slots: {
        root: 'flex gap-4',
        header: 'flex',
        item: 'group text-center relative w-full',
        container: 'relative',
        trigger: 'cursor-pointer rounded-full font-(--ui-font-weight-medium) text-center align-middle flex items-center justify-center group-data-[state=completed]:text-(--b24ui-color) group-data-[state=active]:text-(--b24ui-color) text-description group-data-[state=completed]:bg-(--b24ui-background) group-data-[state=active]:bg-(--b24ui-background-active) focus-visible:outline-(--b24ui-background-active) bg-(--ui-color-base-8) ring ring-(--ui-color-base-7) focus-visible:outline-2 focus-visible:outline-offset-2',
        indicator: 'flex items-center justify-center size-full',
        icon: 'shrink-0',
        separator: 'absolute rounded-(--ui-border-radius-circle) group-data-[disabled]:opacity-75 group-data-[state=completed]:bg-(--b24ui-background-active) bg-(--ui-color-base-6)',
        wrapper: '',
        title: 'font-(--ui-font-weight-medium) text-legend',
        description: 'text-description text-wrap',
        content: 'size-full'
      },
      variants: {
        orientation: {
          horizontal: {
            root: 'flex-col',
            container: 'flex justify-center',
            separator: 'top-[calc(50%-2px)] h-0.5',
            wrapper: 'mt-1'
          },
          vertical: {
            header: 'flex-col gap-4',
            item: 'flex text-start',
            separator: 'start-[calc(50%-1px)] -bottom-[10px] w-0.5'
          }
        },
        size: {
          xs: {
            trigger: 'size-[28px] text-(length:--ui-font-size-sm)',
            icon: 'size-[26px]',
            title: 'text-(length:--ui-font-size-xs)',
            description: 'text-(length:--ui-font-size-xs)',
            wrapper: 'mt-[6px]'
          },
          sm: {
            trigger: 'size-[32px] text-(length:--ui-font-size-md)',
            icon: 'size-[28px]',
            title: 'text-(length:--ui-font-size-sm)',
            description: 'text-(length:--ui-font-size-sm)',
            wrapper: 'mt-2'
          },
          md: {
            trigger: 'size-[42px] text-(length:--ui-font-size-xl)',
            icon: 'size-[38px]',
            title: 'text-(length:--ui-font-size-md)',
            description: 'text-(length:--ui-font-size-md)',
            wrapper: 'mt-[10px]'
          },
          lg: {
            trigger: 'size-[48px] text-(length:--ui-font-size-2xl)',
            icon: 'size-[44px]',
            title: 'text-(length:--ui-font-size-xl)',
            description: 'text-(length:--ui-font-size-xl)',
            wrapper: 'mt-[12px]'
          },
          xl: {
            trigger: 'size-[60px] text-(length:--ui-font-size-3xl)',
            icon: 'size-[56px]',
            title: 'text-(length:--ui-font-size-2xl)',
            description: 'text-(length:--ui-font-size-2xl)',
            wrapper: 'mt-[14px]'
          }
        },
        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'
          }
        }
      },
      compoundVariants: [
        {
          orientation: 'horizontal',
          size: 'xs',
          class: {
            separator: 'start-[calc(50%+16px)] end-[calc(-50%+16px)]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'sm',
          class: {
            separator: 'start-[calc(50%+20px)] end-[calc(-50%+20px)]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'md',
          class: {
            separator: 'start-[calc(50%+28px)] end-[calc(-50%+28px)]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'lg',
          class: {
            separator: 'start-[calc(50%+32px)] end-[calc(-50%+32px)]'
          }
        },
        {
          orientation: 'horizontal',
          size: 'xl',
          class: {
            separator: 'start-[calc(50%+36px)] end-[calc(-50%+36px)]'
          }
        },
        {
          orientation: 'vertical',
          size: 'xs',
          class: {
            separator: 'top-[30px]',
            item: 'gap-1.5'
          }
        },
        {
          orientation: 'vertical',
          size: 'sm',
          class: {
            separator: 'top-[38px]',
            item: 'gap-2'
          }
        },
        {
          orientation: 'vertical',
          size: 'md',
          class: {
            separator: 'top-[46px]',
            item: 'gap-2.5'
          }
        },
        {
          orientation: 'vertical',
          size: 'lg',
          class: {
            separator: 'top-[54px]',
            item: 'gap-3'
          }
        },
        {
          orientation: 'vertical',
          size: 'xl',
          class: {
            separator: 'top-[62px]',
            item: 'gap-3.5'
          }
        }
      ],
      defaultVariants: {
        size: 'md',
        color: 'air-primary'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
