Перейти к содержанию

ContentNavigation

Навигация по страницам в виде аккордеона: разделы документации и вложенные ссылки.
Компонент доступен, только если установлен модуль @nuxt/content.

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

Пропс navigation принимает navigation — то, что возвращает запрос навигации приложения.

<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'
import { withTrailingSlash } from 'ufo'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// The docs site serves every page with a trailing slash (`useNavigation` adds it in place,
// on the client only); copying the tree with the slash keeps SSR and hydration in step.
const withSlash = (items: ContentNavigationItem[] = []): ContentNavigationItem[] => items.map(item => ({
  ...item,
  path: withTrailingSlash(item.path),
  children: item.children && withSlash(item.children)
}))

const links = computed(() => withSlash(navigation?.value))
</script>

<template>
  <B24ContentNavigation :navigation="links" highlight />
</template>
<script setup lang="ts">
import { computed, inject } from 'vue'
import type { ContentNavigationItem } from '@nuxt/content'
import { withTrailingSlash } from 'ufo'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// The docs site serves every page with a trailing slash (`useNavigation` adds it in place,
// on the client only); copying the tree with the slash keeps SSR and hydration in step.
const withSlash = (items: ContentNavigationItem[] = []): ContentNavigationItem[] => items.map(item => ({
  ...item,
  path: withTrailingSlash(item.path),
  children: item.children && withSlash(item.children)
}))

const links = computed(() => withSlash(navigation?.value))
</script>

<template>
  <B24ContentNavigation :navigation="links" highlight />
</template>

Тип

Пропс type со значением single оставляет открытым только один раздел. По умолчанию — multiple.

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

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation type="single" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation type="single" />
</template>

Цвет

Пропс color задаёт цвет активной ссылки.

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

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation color="air-primary-success" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation color="air-primary-success" />
</template>

Вариант

Пропс variant меняет вид ссылок: pill — активная ссылка на подложке, link — без подложки.

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

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation variant="link" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation variant="link" />
</template>

Подсветка

Пропс highlight рисует линию рядом с активной ссылкой.

Пропс highlight-color задаёт цвет линии. По умолчанию он равен color.

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

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation
    highlight
    highlight-color="air-primary"
    color="air-primary"
    variant="pill"
  />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation
    highlight
    highlight-color="air-primary"
    color="air-primary"
    variant="pill"
  />
</template>

Значок раскрытия

Пропс trailing-icon задаёт иконку у разделов с вложенными ссылками. По умолчанию — i-bx24-outline-chevron-down-l.

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

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation trailing-icon="i-bx24-actions-arrow-to-the-top" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
import type { ContentNavigationLink } from '@bxshefby/b24ui-nuxt'

const navigation = ref<ContentNavigationLink[]>([
  {
    title: 'Руководство',
    icon: 'i-bx24-crm-book-open',
    path: '#getting-started',
    children: [
      {
        title: 'Введение',
        path: '#introduction',
        active: true
      },
      {
        title: 'Установка',
        path: '#installation'
      }
    ]
  },
  {
    title: 'Композаблы',
    icon: 'i-bx24-outline-database',
    path: '#composables',
    children: [
      {
        title: 'defineShortcuts',
        path: '#defineshortcuts'
      },
      {
        title: 'useOverlay',
        path: '#useoverlay'
      }
    ]
  }
])
</script>

<template>
  <B24ContentNavigation trailing-icon="i-bx24-actions-arrow-to-the-top" />
</template>
Значок по умолчанию — ключ chevronDown набора иконок.

Примеры

В макете

Компонент ставится в PageAside макета и показывает навигацию по страницам:

layouts/docs.vue
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>

<template>
  <B24Page>
    <template #left>
      <B24PageAside>
        <B24ContentNavigation :navigation="navigation" highlight />
      </B24PageAside>
    </template>

    <slot />
  </B24Page>
</template>

В шапке

В слоте body компонента Header навигация видна на телефоне:

components/Header.vue
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
</script>

<template>
  <B24Header>
    <template #body>
      <B24ContentNavigation :navigation="navigation" highlight />
    </template>
  </B24Header>
</template>

API

Пропсы

Пропс По умолчанию Тип
as'nav'any

The element or component this component should render as.

defaultOpenundefinedboolean

When true, the tree will be opened based on the current route. When false, the tree will be closed. When undefined (default), the first item will be opened with type="single" and the first level will be opened with type="multiple".

trailingIconicons.chevronDown IconProp

The icon displayed to toggle the accordion.

color'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-primary-no-accent"
variant'pill' "pill" | "link"
highlightfalseboolean

Display a line next to the active link.

highlightColor'air-primary'"air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-primary-no-accent"
collapsibletrueboolean

When type is "single", prevents closing the open item when clicking its trigger. When type is "multiple", disables the collapsible behavior.

level0 number
navigation T[]
disabledfalseboolean

When true, prevents the user from interacting with the accordion and all its items

type'multiple' "single" | "multiple"

Determines whether a "single" or "multiple" items can be selected at a time.

This prop will overwrite the inferred type from modelValue and defaultValue.

unmountOnHidetrueboolean

When true, the element will be unmounted on closed state.

b24ui { root?: SlotClass; content?: SlotClass; list?: SlotClass; item?: SlotClass; listWithChildren?: SlotClass; itemWithChildren?: SlotClass; trigger?: SlotClass; link?: SlotClass; linkLeadingIcon?: SlotClass; linkTrailing?: SlotClass; linkTrailingBadge?: SlotClass; linkTrailingBadgeSize?: SlotClass; linkTrailingIcon?: SlotClass; linkTitle?: SlotClass; linkTitleExternalIcon?: SlotClass; }

Слоты

Слот Тип
link{ link: T; active: boolean; b24ui: object; }
link-leading{ link: T; active: boolean; b24ui: object; }
link-title{ link: T; active: boolean; b24ui: object; }
link-trailing{ link: T; active: boolean; b24ui: object; }

События

Событие Тип
update:modelValue[value: string | string[] | undefined]

Тема

Была ли страница полезна?