PricingPlans 가격 플랜
가격 플랜 목록을 반응형 그리드 레이아웃으로 표시하는 컴포넌트예요. 기본 슬롯 또는 plans prop으로 PricingPlan 컴포넌트 목록을 유연하게 배치할 수 있어요.
출처: Nuxt UI
본문
가격 플랜 목록을 반응형 그리드 레이아웃으로 표시해요.
사용법 (Usage)
PricingPlans 컴포넌트는 기본 슬롯이나 plans prop을 이용해 PricingPlan 컴포넌트 목록을 유연하게 배치할 수 있는 레이아웃을 제공해요.
<template>
<UPricingPlans>
<UPricingPlan
v-for="(plan, index) in plans"
:key="index"
v-bind="plan"
/>
</UPricingPlans>
</template>
[!TIP]
그리드 열 수는 플랜 개수에 따라 자동으로 계산돼요. 이는
plansprop과 기본 슬롯 모두에서 동작해요.
Plans
plans prop에 PricingPlan 컴포넌트의 속성들을 가진 객체 배열을 전달해요.
<script setup lang="ts">
import type { PricingPlanProps } from '@nuxt/ui'
const plans = ref<PricingPlanProps[]>([
{
title: "Solo",
description: "Tailored for indie hackers.",
price: "$249",
features: [
"One developer",
"Lifetime access"
],
button: {
label: "Buy now"
}
},
{
title: "Startup",
description: "Best suited for small teams.",
price: "$499",
features: [
"Up to 5 developers",
"Everything in Solo"
],
button: {
label: "Buy now"
}
},
{
title: "Organization",
description: "Ideal for larger teams and organizations.",
price: "$999",
features: [
"Up to 20 developers",
"Everything in Startup"
],
button: {
label: "Buy now"
}
}
])
</script>
<template>
<UPricingPlans :plans="plans" />
</template>
Orientation
orientation prop으로 PricingPlans의 방향을 바꿀 수 있어요. 기본값은 horizontal이에요.
<script setup lang="ts">
import type { PricingPlanProps } from '@nuxt/ui'
const plans = ref<PricingPlanProps[]>([
{
title: "Solo",
description: "Tailored for indie hackers.",
price: "$249",
features: [
"One developer",
"Lifetime access"
],
button: {
label: "Buy now"
}
},
{
title: "Startup",
description: "Best suited for small teams.",
price: "$499",
features: [
"Up to 5 developers",
"Everything in Solo"
],
button: {
label: "Buy now"
}
},
{
title: "Organization",
description: "Ideal for larger teams and organizations.",
price: "$999",
features: [
"Up to 20 developers",
"Everything in Startup"
],
button: {
label: "Buy now"
}
}
])
</script>
<template>
<UPricingPlans orientation="vertical" :plans="plans" />
</template>
[!TIP]
기본 슬롯 대신
plansprop을 사용하면 플랜의orientation이 자동으로 반전돼요.horizontal은vertical로,vertical은horizontal로 바뀌어요.
Compact
compact prop을 이용해 시각적 균형을 위해 하나의 플랜을 확대했을 때 플랜 사이의 패딩을 줄일 수 있어요.
<script setup lang="ts">
import type { PricingPlanProps } from '@nuxt/ui'
const plans = ref<PricingPlanProps[]>([
{
title: "Solo",
description: "Tailored for indie hackers.",
price: "$249",
features: [
"One developer",
"Lifetime access"
],
button: {
label: "Buy now"
}
},
{
title: "Startup",
description: "Best suited for small teams.",
price: "$499",
scale: true,
features: [
"Up to 5 developers",
"Everything in Solo"
],
button: {
label: "Buy now"
}
},
{
title: "Organization",
description: "Ideal for larger teams and organizations.",
price: "$999",
features: [
"Up to 20 developers",
"Everything in Startup"
],
button: {
label: "Buy now"
}
}
])
</script>
<template>
<UPricingPlans compact :plans="plans" />
</template>
Scale
scale prop을 이용해 시각적 균형을 위해 하나의 플랜을 확대했을 때 플랜 사이의 간격을 조절할 수 있어요.
<script setup lang="ts">
import type { PricingPlanProps } from '@nuxt/ui'
const plans = ref<PricingPlanProps[]>([
{
title: "Solo",
description: "Tailored for indie hackers.",
price: "$249",
features: [
"One developer",
"Lifetime access"
],
button: {
label: "Buy now"
}
},
{
title: "Startup",
description: "Best suited for small teams.",
price: "$499",
scale: true,
features: [
"Up to 5 developers",
"Everything in Solo"
],
button: {
label: "Buy now"
}
},
{
title: "Organization",
description: "Ideal for larger teams and organizations.",
price: "$999",
features: [
"Up to 20 developers",
"Everything in Startup"
],
button: {
label: "Buy now"
}
}
])
</script>
<template>
<UPricingPlans scale :plans="plans" />
</template>
예시 (Examples)
[!NOTE]
이 예시들은 Nuxt Content를 사용하지만, 컴포넌트는 어떤 콘텐츠 관리 시스템과도 통합할 수 있어요.
페이지 안에서 (Within a page)
페이지 안에 PricingPlans 컴포넌트를 사용해 가격 페이지를 만들 수 있어요.
<script setup lang="ts">
const { data: plans } = await useAsyncData('plans', () => queryCollection('plans').all())
</script>
<template>
<UPage>
<UPageHero title="Pricing" />
<UPageBody>
<UContainer>
<UPricingPlans :plans="plans" />
</UContainer>
</UPageBody>
</UPage>
</template>
[!NOTE]
이 예시에서
plans는@nuxt/content모듈의queryCollection을 이용해 가져와요.
API
Props
/**
* Props for the PricingPlans component
*/
interface PricingPlansProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
plans?: PricingPlanProps[] | undefined;
/**
* The orientation of the pricing plans.
* @default 'horizontal'
*/
orientation?: "horizontal" | "vertical" | undefined;
/**
* When `true`, the plans will be displayed without gap.
* @default false
*/
compact?: boolean | undefined;
/**
* When `true`, the plans will be displayed with a larger gap.
* Useful when one plan is scaled. Doesn't work with `compact`.
* @default false
*/
scale?: boolean | undefined;
ui?: { base?: any; } | undefined;
}
Slots
/**
* Slots for the PricingPlans component
*/
interface PricingPlansSlots {
badge(): any;
title(): any;
description(): any;
price(): any;
discount(): any;
billing(): any;
features(): any;
button(): any;
header(): any;
body(): any;
footer(): any;
tagline(): any;
terms(): any;
default(): any;
}
테마 (Theme)
export default defineAppConfig({
ui: {
pricingPlans: {
base: 'flex flex-col gap-y-8',
variants: {
orientation: {
horizontal: 'lg:grid lg:grid-cols-[repeat(var(--count),minmax(0,1fr))]',
vertical: ''
},
compact: {
false: 'gap-x-8'
},
scale: {
true: ''
}
},
compoundVariants: [
{
compact: false,
scale: true,
class: 'lg:gap-x-13'
}
]
}
}
})