블로그 포스트
블로그 포스트 (BlogPost)
블로그 페이지에 표시할 수 있는 커스터마이즈 가능한 기사 컴포넌트예요. 제목, 설명, 이미지, 작성자 등을 유연하게 표시하는 <article> 요소를 렌더링합니다.
출처: Nuxt UI
본문
BlogPost 컴포넌트는 제목, 설명, 이미지 등 커스터마이즈 가능한 콘텐츠를 담은 <article> 요소를 유연하게 표시해 주는 방법을 제공해요.
<template>
<u-blog-post :authors="[
{
name: 'Anthony Fu',
description: 'antfu7',
avatar: {
src: 'https://github.com/antfu.png',
loading: 'lazy'
},
to: 'https://github.com/antfu',
target: '_blank'
}
]" class="w-96" date="2024-11-25" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" target="_blank" title="Introducing Nuxt Icon v1" to="https://nuxt.com/blog/nuxt-icon-v1-0" />
</template>
[!TIP] See: /docs/components/blog-posts
여러 블로그 게시물을 반응형 그리드 레이아웃으로 표시하려면
BlogPosts컴포넌트를 사용해 주세요.
제목 (Title)
title prop을 사용해 BlogPost의 제목을 표시해요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" />
</template>
설명 (Description)
description prop을 사용해 BlogPost의 설명을 표시해요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." />
</template>
날짜 (Date)
date prop을 사용해 BlogPost의 날짜를 표시해요.
[!TIP]
날짜는 현재 로케일에 맞게 자동으로 포맷됩니다.
Date객체 또는 문자열을 전달할 수 있어요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." date="2024-11-25" />
</template>
배지 (Badge)
badge prop을 사용해 BlogPost에 Badge를 표시할 수 있어요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." badge="Release" />
</template>
Badge 컴포넌트의 어떤 속성이든 전달해 커스터마이즈할 수 있어요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." :badge="{
label: 'Release',
color: 'primary',
variant: 'solid'
}" />
</template>
이미지 (Image)
image prop을 사용해 BlogPost에 이미지를 표시해요.
[!NOTE]
@nuxt/image가 설치되어 있으면 네이티브img태그 대신<NuxtImg>컴포넌트가 사용됩니다.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" />
</template>
작성자 (Authors)
authors prop을 사용해 BlogPost에 User 목록을 아래 속성을 가진 객체 배열로 표시할 수 있어요:
name?: stringdescription?: stringavatar?: Omit<AvatarProps, 'size'>chip?: boolean | Omit<ChipProps, 'size' | 'inset'>size?: UserProps['size']orientation?: UserProps['orientation']
Link 컴포넌트의 to, target 등 어떤 속성이든 전달할 수 있어요.
<script setup lang="ts">
import type { UserProps } from '@nuxt/ui'
const authors = ref<UserProps[]>([
{
name: "Anthony Fu",
description: "antfu7",
avatar: {
src: "https://github.com/antfu.png",
loading: "lazy"
},
to: "https://github.com/antfu",
target: "_blank"
}
])
</script>
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" :authors="authors" />
</template>
authors prop에 항목이 두 개 이상 있으면 AvatarGroup 컴포넌트가 사용됩니다.
<script setup lang="ts">
import type { UserProps } from '@nuxt/ui'
const authors = ref<UserProps[]>([
{
name: "Anthony Fu",
description: "antfu7",
avatar: {
src: "https://github.com/antfu.png",
loading: "lazy"
},
to: "https://github.com/antfu",
target: "_blank"
},
{
name: "Benjamin Canac",
description: "benjamincanac",
avatar: {
src: "https://github.com/benjamincanac.png",
loading: "lazy"
},
to: "https://github.com/benjamincanac",
target: "_blank"
}
])
</script>
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" :authors="authors" />
</template>
링크 (Link)
<NuxtLink> 컴포넌트의 to, target, rel 등 어떤 속성이든 전달할 수 있어요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" to="https://nuxt.com/blog/nuxt-icon-v1-0" target="_blank" />
</template>
변형 (Variant)
variant prop을 사용해 BlogPost의 스타일을 바꿔요.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" to="https://nuxt.com/blog/nuxt-icon-v1-0" target="_blank" variant="naked" />
</template>
[!NOTE]
toprop을 제공하느냐image를 제공하느냐에 따라 스타일이 달라집니다.
방향 (Orientation)
orientation prop을 사용해 BlogPost의 방향을 바꿔요. 기본값은 vertical입니다.
<template>
<UBlogPost title="Introducing Nuxt Icon v1" description="Discover Nuxt Icon v1 - a modern, versatile, and customizable icon solution for your Nuxt projects." image="https://nuxt.com/assets/blog/nuxt-icon/cover.png" date="2024-11-25" to="https://nuxt.com/blog/nuxt-icon-v1-0" target="_blank" orientation="horizontal" variant="outline" />
</template>
API
Props
/**
* Props for the BlogPost component
*/
interface BlogPostProps {
/**
* The element or component this component should render as.
* @default 'article'
*/
as?: any;
title?: string | undefined;
description?: string | undefined;
/**
* The date of the blog post. Can be a string or a Date object.
*/
date?: string | Date | undefined;
/**
* Display a badge on the blog post.
* Can be a string or an object.
* `{ color: 'neutral', variant: 'subtle' }`{lang="ts-type"}
*/
badge?: string | BadgeProps | undefined;
/**
* The authors of the blog post.
*/
authors?: UserProps[] | undefined;
/**
* The image of the blog post. Can be a string or an object.
*/
image?: string | Partial<ImgHTMLAttributes> & { [key: string]: any; } | undefined;
/**
* The orientation of the blog post.
* @default 'vertical'
*/
orientation?: "vertical" | "horizontal" | undefined;
/**
* @default 'outline'
*/
variant?: "outline" | "soft" | "subtle" | "ghost" | "naked" | undefined;
to?: string | it | et | undefined;
target?: null | "_blank" | "_parent" | "_self" | "_top" | string & {} | undefined;
onClick?: (event: MouseEvent): void | undefined;
ui?: { root?: SlotClass; header?: SlotClass; body?: SlotClass; footer?: SlotClass; image?: SlotClass; title?: SlotClass; description?: SlotClass; authors?: SlotClass; avatar?: SlotClass; meta?: SlotClass; date?: SlotClass; badge?: SlotClass; } | undefined;
}
Slots
/**
* Slots for the BlogPost component
*/
interface BlogPostSlots {
date(): any;
badge(): any;
title(): any;
description(): any;
authors(): any;
header(): any;
body(): any;
footer(): any;
}
테마 (Theme)
export default defineAppConfig({
ui: {
blogPost: {
slots: {
root: 'relative group/blog-post flex flex-col rounded-lg overflow-hidden',
header: 'relative overflow-hidden aspect-[16/9] w-full pointer-events-none',
body: 'min-w-0 flex-1 flex flex-col',
footer: '',
image: 'object-cover object-top w-full h-full',
title: 'text-xl text-pretty font-semibold text-highlighted',
description: 'mt-1 text-base text-pretty',
authors: 'pt-4 mt-auto flex flex-wrap gap-x-3 gap-y-1.5',
avatar: '',
meta: 'flex items-center gap-2 mb-2',
date: 'text-sm',
badge: ''
},
variants: {
orientation: {
horizontal: {
root: 'lg:grid lg:grid-cols-2 lg:items-center gap-x-8',
body: 'justify-center p-4 sm:p-6 lg:px-0'
},
vertical: {
root: 'flex flex-col',
body: 'p-4 sm:p-6'
}
},
variant: {
outline: {
root: 'bg-default ring ring-default',
date: 'text-toned',
description: 'text-muted'
},
soft: {
root: 'bg-elevated/50',
date: 'text-muted',
description: 'text-toned'
},
subtle: {
root: 'bg-elevated/50 ring ring-default',
date: 'text-muted',
description: 'text-toned'
},
ghost: {
date: 'text-toned',
description: 'text-muted',
header: 'shadow-lg rounded-lg'
},
naked: {
root: 'p-0 sm:p-0',
date: 'text-toned',
description: 'text-muted',
header: 'shadow-lg rounded-lg'
}
},
to: {
true: {
root: [
'outline-primary/25 has-[>a:focus-visible]:outline-3',
'transition'
],
image: 'transform transition-transform ease-out motion-reduce:transition-none group-hover/blog-post:scale-110',
avatar: 'inline-flex transform transition-transform ease-out motion-reduce:transition-none hover:scale-115 rounded-full outline-primary/25 focus-visible:outline-3'
}
},
image: {
true: ''
}
},
compoundVariants: [
{
variant: 'outline',
to: true,
class: {
root: 'hover:bg-elevated/50'
}
},
{
variant: 'soft',
to: true,
class: {
root: 'hover:bg-elevated'
}
},
{
variant: 'subtle',
to: true,
class: {
root: 'hover:bg-elevated hover:ring-accented'
}
},
{
variant: [
'outline',
'subtle'
],
to: true,
class: {
root: 'has-[>a:focus-visible]:ring-primary'
}
},
{
variant: 'ghost',
to: true,
class: {
root: 'hover:bg-elevated/50',
header: [
'group-hover/blog-post:shadow-none',
'transition-[box-shadow,border-radius] ease-out'
]
}
},
{
variant: 'ghost',
to: true,
orientation: 'vertical',
class: {
header: 'group-hover/blog-post:rounded-b-none'
}
},
{
variant: 'ghost',
to: true,
orientation: 'horizontal',
class: {
header: 'group-hover/blog-post:rounded-e-none'
}
},
{
orientation: 'vertical',
image: false,
variant: 'naked',
class: {
body: 'p-0 sm:p-0'
}
}
],
defaultVariants: {
variant: 'outline'
}
}
}
})