v2.15.0

Pagination

Навигационный компонент с кнопками или ссылками для постраничного вывода.

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

Пропс default-page или директива v-model:page управляет текущей страницей.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>
Pagination использует Button для отображения страниц; пропсы color и size задают их стиль.

Всего

Пропс total задаёт общее число элементов в списке.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>

Элементов на странице

Пропс items-per-page задаёт число элементов на странице. По умолчанию 10.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :items-per-page="20" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :items-per-page="20" :total="100" />
</template>

Число соседних страниц

Пропс sibling-count задаёт, сколько соседних страниц показывать. По умолчанию 2.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :sibling-count="1" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :sibling-count="1" :total="100" />
</template>

Крайние страницы

Пропс show-edges всегда показывает многоточие, первую и последнюю страницы. По умолчанию false.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>

Кнопки управления

Пропс show-controls показывает кнопки «первая», «предыдущая», «следующая» и «последняя». По умолчанию true.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>

Цвет

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

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" color="air-tertiary-no-accent" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" color="air-tertiary-no-accent" :total="100" />
</template>

Цвет активной страницы

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

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" active-color="air-primary-copilot" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" active-color="air-primary-copilot" :total="100" />
</template>

Размер

Пропс size задаёт размер элементов управления. По умолчанию md.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" size="xl" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" size="xl" :total="100" />
</template>

Отключение

Пропс disabled отключает элементы управления пагинацией.

<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" disabled />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" disabled />
</template>

Примеры

Пропс to превращает кнопки в ссылки. Передайте функцию, которая принимает номер страницы и возвращает маршрут.

<script setup lang="ts">
const page = ref(5)

function to(page: number) {
  return {
    query: {
      page
    },
    hash: '#with-links'
  }
}
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" :to="to" :sibling-count="1" show-edges />
</template>
<script setup lang="ts">
import { ref } from 'vue'

const page = ref(5)

function to(page: number) {
  return {
    query: {
      page
    },
    hash: '#with-links'
  }
}
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" :to="to" :sibling-count="1" show-edges />
</template>
В этом примере к адресу добавлен хеш #with-links, чтобы страница не прокручивалась вверх.

API

Пропсы

Prop Default Type
as'div'any

The element or component this component should render as.

firstIconicons.chevronDoubleLeftIconComponent

The icon to use for the first page control.

prevIconicons.chevronLeftIconComponent

The icon to use for the previous page control.

nextIconicons.chevronRightIconComponent

The icon to use for the next page control.

lastIconicons.chevronDoubleRightIconComponent

The icon to use for the last page control.

ellipsisIconicons.ellipsisIconComponent

The icon to use for the ellipsis control.

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 pagination controls.

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 active pagination control.

showControlstrueboolean

Whether to show the first, previous, next, and last controls.

size "xs" | "md" | "xss" | "sm" | "lg" | "xl"
to (page: number): string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric

A function to render page controls as links.

defaultPage number

The value of the page that should be active when initially rendered.

Use when you do not need to control the value state.

disabledboolean

When true, prevents the user from interacting with item

itemsPerPage10 number

Number of items per page

page number

The controlled value of the current page. Can be binded as v-model:page.

showEdgesfalseboolean

When true, always show first page, last page, and ellipsis

siblingCount2 number

Number of sibling should be shown around the current page

total0 number

Number of items in your list

b24ui { root?: SlotClass; list?: SlotClass; ellipsis?: SlotClass; label?: SlotClass; first?: SlotClass; prev?: SlotClass; item?: SlotClass; next?: SlotClass; last?: SlotClass; }

Слоты

Slot Type
first{}
prev{}
next{}
last{}
ellipsis{ b24ui: object; }
item{ page: number; pageCount: number; item: { type: "ellipsis"; } | { type: "page"; value: number; }; index: number; }

События

Event Type
update:page[value: number]

Тема

https://github.com/bx-shef/b24-ui/tree/main/src/theme/pagination.ts
export default {
  slots: {
    root: '',
    list: 'flex items-center gap-1',
    ellipsis: 'pointer-events-none',
    label: 'text-center',
    first: '',
    prev: '',
    item: '',
    next: '',
    last: ''
  }
}