본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

콘텐츠 서라운드

원문 보기 위키 갱신

콘텐츠 서라운드 (ContentSurround)

페이지 사이를 이동할 수 있는 이전(prev)과 다음(next) 링크 쌍을 만들어 주는 컴포넌트예요. 페이지의 surround 값을 가져와 surround prop으로 전달하면 됩니다. @nuxt/content 모듈이 설치된 경우에만 사용할 수 있어요.

출처: Nuxt UI

본문

[!WARNING] See: /docs/getting-started/integrations/content

This component is only available when the @nuxt/content module is installed.

[!WARNING]

이 컴포넌트는 @nuxt/content 모듈이 설치된 경우에만 사용할 수 있어요. 자세한 내용은 /docs/getting-started/integrations/content 문서를 참고해 주세요.

사용법 (Usage)

페이지 surround를 가져올 때 얻는 surround 값과 함께 surround prop을 사용해요.

<script setup lang="ts">
const route = useRoute()

const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
  return queryCollectionItemSurroundings('docs', route.path, {
    fields: ['description']
  })
})
</script>

<template>
  <UContentSurround :surround="(surround as any)" />
</template>

이전 / 다음 (Prev / Next)

prev-icon와 next-icon prop을 사용해 버튼의 Icon을 커스텀할 수 있어요.

<script setup lang="ts">
import type { ContentSurroundLink } from '@nuxt/ui'

const surround = ref<ContentSurroundLink[]>([
  {
    title: "ContentSearchButton",
    path: "/docs/components/content-search-button",
    stem: "docs/2.components/content-search-button",
    description: "A pre-styled Button to open the ContentSearch modal."
  },
  {
    title: "ContentToc",
    path: "/docs/components/content-toc",
    stem: "docs/2.components/content-toc",
    description: "A sticky Table of Contents with customizable slots."
  }
])
</script>

<template>
  <UContentSurround prev-icon="i-lucide-chevron-left" next-icon="i-lucide-chevron-right" :surround="surround" />
</template>

예시 (Examples)

페이지 안에서 사용하기 (Within a page)

ContentSurround 컴포넌트를 페이지 안에서 사용하면 이전·다음 링크를 표시할 수 있어요.

<script setup lang="ts">
const route = useRoute()

const { data: page } = await useAsyncData(route.path, () => queryCollection('docs').path(route.path).first())
if (!page.value) {
  throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}
</script>

<template>
  <UPage v-if="page">
    <UPageHeader :title="page.title" />

    <UPageBody>
      <ContentRenderer v-if="page.body" :value="page" />

      <USeparator v-if="surround?.filter(Boolean).length" />

      <UContentSurround :surround="(surround as any)" />
    </UPageBody>

    <template v-if="page?.body?.toc?.links?.length" #right>
      <UContentToc :links="page.body.toc.links" />
    </template>
  </UPage>
</template>

API

Props

/**
 * Props for the ContentSurround component
 */
interface ContentSurroundProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * The icon displayed in the prev link.
   * @default appConfig.ui.icons.arrowLeft
   */
  prevIcon?: any;
  /**
   * The icon displayed in the next link.
   * @default appConfig.ui.icons.arrowRight
   */
  nextIcon?: any;
  surround?: T[] | undefined;
  ui?: { root?: SlotClass; link?: SlotClass; linkLeading?: SlotClass; linkLeadingIcon?: SlotClass; linkTitle?: SlotClass; linkDescription?: SlotClass; } | undefined;
}

Slots

/**
 * Slots for the ContentSurround component
 */
interface ContentSurroundSlots {
  link(): any;
  link-leading(): any;
  link-title(): any;
  link-description(): any;
}

테마 (Theme)

export default defineAppConfig({
  ui: {
    contentSurround: {
      slots: {
        root: 'grid grid-cols-1 sm:grid-cols-2 gap-8',
        link: [
          'group block px-6 py-8 rounded-lg border border-default hover:bg-elevated/50 outline-primary/25 focus-visible:outline-3 focus-visible:border-primary',
          'transition-colors'
        ],
        linkLeading: [
          'inline-flex items-center rounded-full p-1.5 bg-elevated group-hover:bg-primary/10 ring ring-accented mb-4 group-hover:ring-primary/50',
          'transition'
        ],
        linkLeadingIcon: [
          'size-5 shrink-0 text-highlighted group-hover:text-primary',
          'transition-[color,translate] ease-out motion-reduce:transition-none'
        ],
        linkTitle: 'font-medium text-[15px] text-highlighted mb-1 truncate',
        linkDescription: 'text-sm text-muted line-clamp-2'
      },
      variants: {
        direction: {
          left: {
            linkLeadingIcon: 'group-active:-translate-x-0.5 rtl:group-active:translate-x-0.5'
          },
          right: {
            link: 'text-end',
            linkLeadingIcon: 'group-active:translate-x-0.5 rtl:group-active:-translate-x-0.5'
          }
        }
      }
    }
  }
})

변경 내역 (Changelog)

컴포넌트와 테마의 커밋 기록을 확인해 보세요.


사이트맵 (Sitemap)

전체 사이트맵에서 모든 페이지를 확인할 수 있어요.

더 알아보기 (Learn more)