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

Vue Chip 컴포넌트

원문 보기 위키 갱신

Chip은 아이콘, 라벨, 이미지로 개체(entity)를 표현하는 컴포넌트예요. 태그, 연락처, 필터 조각 같은 작은 항목을 표시하고 제거할 수 있게 해 줘요.

출처: 문서

본문

Vue Chip Component

Chip represents entities using icons, labels and images.

Import

import Chip from 'primevue/chip';

Accessibility

Screen Reader Chip은 label 프로퍼티를 기본 aria-label로 사용하고, 모든 속성이 루트 요소로 전달되기 때문에 aria-labelledby나 aria-label로 기본 동작을 덮어쓸 수 있어요. 제거 가능한(removable) chip은 tabindex를 가지며 Tab 키로 포커스할 수 있어요. Keyboard Support Key Function backspace removable을 숨겨요. enter removable을 숨겨요.

Basic

텍스트가 있는 기본 chip은 label 프로퍼티로 만들어요. 또한 removable을 추가하면 chip을 제거하는 삭제 아이콘이 표시돼요.

<Chip label="Action" />
<Chip label="Comedy" />
<Chip label="Mystery" />
<Chip label="Thriller" removable />

Icon

icon 프로퍼티로 라벨 옆에 폰트 아이콘을 표시할 수 있어요.

<Chip label="Apple" icon="pi pi-apple" />
<Chip label="Facebook" icon="pi pi-facebook" />
<Chip label="Google" icon="pi pi-google" />
<Chip label="Microsoft" icon="pi pi-microsoft" removable />
<Chip label="GitHub" icon="pi pi-github" removable>
    <template #removeicon="{ removeCallback, keydownCallback }">
        <i class="pi pi-minus-circle" @click="removeCallback" @keydown="keydownCallback" />
    </template>
</Chip>
Composition API Example
<template>
    <div class="card flex flex-wrap gap-2">
        <Chip label="Apple" icon="pi pi-apple" />
        <Chip label="Facebook" icon="pi pi-facebook" />
        <Chip label="Google" icon="pi pi-google" />
        <Chip label="Microsoft" icon="pi pi-microsoft" removable />
        <Chip label="GitHub" icon="pi pi-github" removable>
            <template #removeicon="{ removeCallback, keydownCallback }">
                <i class="pi pi-minus-circle" @click="removeCallback" @keydown="keydownCallback" />
            </template>
        </Chip>
    </div>
</template>
<script setup>

<\/script>

Image

image 프로퍼티는 아바타 같은 이미지를 표시할 때 사용해요.

<Chip label="Amy Elsner" image="/images/avatar/amyelsner.png" />
<Chip label="Asiya Javayant" image="/images/avatar/asiyajavayant.png" />
<Chip label="Onyama Limba" image="/images/avatar/onyamalimba.png" />
<Chip label="Xuxue Feng" image="/images/avatar/xuxuefeng.png" removable />
Composition API Example
<template>
    <div class="card flex flex-wrap gap-2">
        <Chip label="Amy Elsner" image="https://primefaces.org/cdn/primevue/images/avatar/amyelsner.png" />
        <Chip label="Asiya Javayant" image=https://primefaces.org/cdn/primevue"/images/avatar/asiyajavayant.png" />
        <Chip label="Onyama Limba" image="https://primefaces.org/cdn/primevue/images/avatar/onyamalimba.png" />
        <Chip label="Xuxue Feng" image="https://primefaces.org/cdn/primevue/images/avatar/xuxuefeng.png" removable />
    </div>
</template>

<script setup>

<\/script>

StyleDoc

styled 모드에서 사용되는 클래스 이름 목록이에요.

TemplateDoc

default 슬롯은 chip 안에 커스텀 콘텐츠를 표시할 수 있게 해 줘요.

<Chip class="py-0 pl-0 pr-4">
    <span class="bg-primary text-primary-contrast rounded-full w-8 h-8 flex items-center justify-center">P</span>
    <span class="ml-2 font-medium">PRIME</span>
</Chip>
Composition API Example
<template>
    <div class="card">
        <Chip class="py-0 pl-0 pr-4">
            <span class="bg-primary text-primary-contrast rounded-full w-8 h-8 flex items-center justify-center">P</span>
            <span class="ml-2 font-medium">PRIME</span>
        </Chip>
    </div>
</template>

<script setup>

<\/script>

Chip

Props

Name Type Default Description
label string | number - Defines the text to display.
icon string - Defines the icon to display.
image string - Defines the image to display.
removable boolean false Whether to display a remove icon.
removeIcon string - Icon of the remove element.
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough<ChipPassThroughOptions> - 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 ChipPassThroughOptionType Used to pass attributes to the root's DOM element.
image ChipPassThroughOptionType Used to pass attributes to the image's DOM element.
icon ChipPassThroughOptionType Used to pass attributes to the icon's DOM element.
label ChipPassThroughOptionType Used to pass attributes to the label' DOM element.
removeIcon ChipPassThroughOptionType Used to pass attributes to the removeIcon's DOM element.
hooks any Used to manage all lifecycle hooks.

Theming

CSS Classes

Class Description
p-chip Class name of the root element
p-chip-image Class name of the image element
p-chip-icon Class name of the icon element
p-chip-label Class name of the label element
p-chip-remove-icon Class name of the remove icon element

Design Tokens

Token CSS Variable Description
chip.border.radius --p-chip-border-radius Border radius of root
chip.padding.x --p-chip-padding-x Padding x of root
chip.padding.y --p-chip-padding-y Padding y of root
chip.gap --p-chip-gap Gap of root
chip.transition.duration --p-chip-transition-duration Transition duration of root
chip.background --p-chip-background Background of root
chip.color --p-chip-color Color of root
chip.image.width --p-chip-image-width Width of image
chip.image.height --p-chip-image-height Height of image
chip.icon.size --p-chip-icon-size Size of icon
chip.icon.color --p-chip-icon-color Color of icon
chip.remove.icon.size --p-chip-remove-icon-size Size of remove icon
chip.remove.icon.focus.ring.width --p-chip-remove-icon-focus-ring-width Focus ring width of remove icon
chip.remove.icon.focus.ring.style --p-chip-remove-icon-focus-ring-style Focus ring style of remove icon
chip.remove.icon.focus.ring.color --p-chip-remove-icon-focus-ring-color Focus ring color of remove icon
chip.remove.icon.focus.ring.offset --p-chip-remove-icon-focus-ring-offset Focus ring offset of remove icon
chip.remove.icon.focus.ring.shadow --p-chip-remove-icon-focus-ring-shadow Focus ring shadow of remove icon
chip.remove.icon.color --p-chip-remove-icon-color Color of remove icon

더 알아보기 (Learn more)