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

Vue Badge 컴포넌트

원문 보기 위키 갱신

Badge는 다른 요소를 위한 작은 상태 인디케이터예요. 알림 개수처럼 요소에 붙여 짧은 숫자나 텍스트를 강조할 때 사용해요.

출처: 문서

본문

Vue Badge Component

Badge is a small status indicator for another element.

Import

// import as component
import Badge from 'primevue/badge';
import OverlayBadge from 'primevue/overlaybadge';

Accessibility

Screen Reader Badge는 기본적으로 어떤 role이나 속성도 포함하지 않지만, 모든 속성이 루트 요소로 전달되기 때문에 필요하다면 aria role과 속성을 추가할 수 있어요. 배지가 동적이라면 aria-live도 활용할 수 있어요. 배지를 탭 이동 가능하게 하려면 tabindex를 추가해 커스텀 키 핸들러를 구현하면 돼요. Keyboard Support 이 컴포넌트에는 인터랙티브 요소가 없어요.

Basic

표시할 콘텐츠는 value 프로퍼티나 default 슬롯으로 정의해요.

<Badge value="2"></Badge>
<Badge>10</Badge>

Button

버튼은 배지를 인라인으로 표시하는 내장 지원을 갖고 있어요.

<Button type="button" label="Notifications" icon="pi pi-bell" badge="2" />
<Button type="button" label="Inbox" icon="pi pi-inbox" badge="2" badgeSeverity="contrast" variant="outlined" />
Composition API Example
<template>
    <div class="card flex justify-center flex-wrap gap-4">
        <Button type="button" label="Notifications" icon="pi pi-bell" badge="2" />
        <Button type="button" label="Inbox" icon="pi pi-inbox" badge="2" badgeSeverity="contrast" variant="outlined" />
    </div>
</template>

<script setup>
<\/script>

Overlay

콘텐츠를 OverlayBadge 컴포넌트로 감싸면 어떤 요소에든 배지를 붙일 수 있어요.

<OverlayBadge value="2">
    <i class="pi pi-bell" style="font-size: 2rem" />
</OverlayBadge>
<OverlayBadge value="4" severity="danger">
    <i class="pi pi-calendar" style="font-size: 2rem" />
</OverlayBadge>
<OverlayBadge severity="danger">
    <i class="pi pi-envelope" style="font-size: 2rem" />
</OverlayBadge>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-6">
        <OverlayBadge value="2">
            <i class="pi pi-bell" style="font-size: 2rem" />
        </OverlayBadge>
        <OverlayBadge value="4" severity="danger">
            <i class="pi pi-calendar" style="font-size: 2rem" />
        </OverlayBadge>
        <OverlayBadge severity="danger">
            <i class="pi pi-envelope" style="font-size: 2rem" />
        </OverlayBadge>
    </div>
</template>

<script setup>

<\/script>

Severity

Severity는 배지의 변형(variant)을 정의해요.

<Badge value="2"></Badge>
<Badge value="6" severity="secondary"></Badge>
<Badge value="8" severity="success"></Badge>
<Badge value="4" severity="info"></Badge>
<Badge value="9" severity="warn"></Badge>
<Badge value="3" severity="danger"></Badge>
<Badge value="5" severity="contrast"></Badge>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center gap-2">
        <Badge value="2"></Badge>
        <Badge value="6" severity="secondary"></Badge>
        <Badge value="8" severity="success"></Badge>
        <Badge value="4" severity="info"></Badge>
        <Badge value="9" severity="warn"></Badge>
        <Badge value="3" severity="danger"></Badge>
        <Badge value="5" severity="contrast"></Badge>
    </div>
</template>

<script setup>
<\/script>

Size

size 프로퍼티로 Badge의 크기를 조절하세요.

<Badge value="8" size="xlarge" severity="success"></Badge>
<Badge value="6" size="large" severity="warn"></Badge>
<Badge value="4" severity="info"></Badge>
<Badge value="2" size="small"></Badge>
Composition API Example
<template>
    <div class="card flex flex-wrap justify-center items-end gap-2">
        <Badge value="8" size="xlarge" severity="success"></Badge>
        <Badge value="6" size="large" severity="warn"></Badge>
        <Badge value="4" severity="info"></Badge>
        <Badge value="2" size="small"></Badge>
    </div>
</template>

<script setup>

<\/script>

Badge

Props

Name Type Default Description
value string | number - Value to display inside the badge.
severity null | HintedString<"secondary" | "info" | "success" | "warn" | "danger" | "contrast"> - Severity type of the badge.
size null | HintedString<"small" | "large" | "xlarge"> - Size of the badge, valid options are 'small', 'large', and 'xlarge'.
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough<BadgePassThroughOptions> - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.

Pass Through Options

Name Type Description
root BadgePassThroughOptionType Used to pass attributes to the root's DOM element.
hooks any Used to manage all lifecycle hooks.

Theming

CSS Classes

Class Description
p-badge Class name of the root element

Design Tokens

Token CSS Variable Description
badge.border.radius --p-badge-border-radius Border radius of root
badge.padding --p-badge-padding Padding of root
badge.font.size --p-badge-font-size Font size of root
badge.font.weight --p-badge-font-weight Font weight of root
badge.min.width --p-badge-min-width Min width of root
badge.height --p-badge-height Height of root
badge.dot.size --p-badge-dot-size Size of dot
badge.sm.font.size --p-badge-sm-font-size Font size of sm
badge.sm.min.width --p-badge-sm-min-width Min width of sm
badge.sm.height --p-badge-sm-height Height of sm
badge.lg.font.size --p-badge-lg-font-size Font size of lg
badge.lg.min.width --p-badge-lg-min-width Min width of lg
badge.lg.height --p-badge-lg-height Height of lg
badge.xl.font.size --p-badge-xl-font-size Font size of xl
badge.xl.min.width --p-badge-xl-min-width Min width of xl
badge.xl.height --p-badge-xl-height Height of xl
badge.primary.background --p-badge-primary-background Background of primary
badge.primary.color --p-badge-primary-color Color of primary
badge.secondary.background --p-badge-secondary-background Background of secondary
badge.secondary.color --p-badge-secondary-color Color of secondary
badge.success.background --p-badge-success-background Background of success
badge.success.color --p-badge-success-color Color of success
badge.info.background --p-badge-info-background Background of info
badge.info.color --p-badge-info-color Color of info
badge.warn.background --p-badge-warn-background Background of warn
badge.warn.color --p-badge-warn-color Color of warn
badge.danger.background --p-badge-danger-background Background of danger
badge.danger.color --p-badge-danger-color Color of danger
badge.contrast.background --p-badge-contrast-background Background of contrast
badge.contrast.color --p-badge-contrast-color Color of contrast

더 알아보기 (Learn more)