Web Components 목록 개요
The Ignite UI for Web Components List element is extremely useful when presenting a group of items. You can create a simple list of textual items, or a more complex one, containing an array of different layout elements. The IgcListComponent component displays rows of items and supports one or more headers as well. Each list item is completely templatable and will support any valid HTML or other components.
Web Components List Example
The following example represents a list populated with contacts with a name and a phone number properties. The IgcListComponent component demonstrated below uses the IgcAvatarComponent and IgcButtonComponent elements to enrich the user experience and expose the capabilities of setting avatar picture and buttons for text and call actions.
Usage
기본적으로 목록 웹 구성 요소를 사용하면 항목의 수직 목록을 쉽게 표시할 수 있습니다.
먼저 다음 명령을 실행하여 Ignite UI for Web Components 설치해야 합니다.
npm install igniteui-webcomponents
import { defineComponents, IgcListComponent } from 'igniteui-webcomponents';
defineComponents(IgcListComponent);
Ignite UI for Web Components에 대한 완전한 소개는 '시작 주제'를 읽어보세요.
Add List Items
이제 다음 코드를 추가하여 간단한 항목 목록을 얻을 수 있습니다.
<igc-list>
<igc-list-header>Header</igc-list-header>
<igc-list-item>
<h2 slot="title">Item 1</h2>
</igc-list-item>
<igc-list-item>
<h2 slot="title">Item 2</h2>
</igc-list-item>
<igc-list-item>
<h2 slot="title">Item 3</h2>
</igc-list-item>
</igc-list>
모든 것이 순조롭게 진행되면 브라우저에 다음이 표시됩니다.
게임을 조금 강화하고 목록 항목을 향상시켜 보겠습니다. 이름 아래에 이름과 전화번호가 표시되는 연락처 목록을 만들고 싶다고 가정해 보겠습니다. 이를 달성하기 위해 다음 예에서 설명한 대로 목록 항목과 함께 제공되는 일부 슬롯을 사용할 수 있습니다.
<igc-list>
<igc-list-header>
<h1>Contacts</h1>
</igc-list-header>
<igc-list-item>
<h2 slot="title">Terrance Orta</h2>
<span slot="subtitle">770-504-2217</span>
</igc-list-item>
<igc-list-item>
<h2 slot="title">Richard Mahoney</h2>
<span slot="subtitle">423-676-2869</span>
</igc-list-item>
<igc-list-item>
<h2 slot="title">Donna Price</h2>
<span slot="subtitle">859-496-2817</span>
</igc-list-item>
</igc-list>
위의 코드를 구현한 후 목록 구성 요소는 이제 다음과 같아야 합니다.
Adding Avatar and Buttons
We can use some of our other components in conjunction with the IgcListComponent component to enrich the experience and add some functionality. We can have a nice picture avatar to the left of the name and phone values. Additionally, we can add some buttons to the right of them to allow the user to text and call contacts, so let's update our contacts list component to show the avatar and the buttons. We can do that by using some of the list item's slots.
<igc-list>
<igc-list-header>
<h1>Job Positions</h1>
</igc-list-header>
<igc-list-item>
<igc-avatar slot="start" src="https://randomuser.me/api/portraits/men/27.jpg" shape="circle">
AA
</igc-avatar>
<h2 slot="title">Terrance Orta</h2>
<span slot="subtitle">770-504-2217</span>
<igc-button slot="end" variant="outlined">
Text
</igc-button>
<igc-button slot="end" variant="outlined">
Call
</igc-button>
</igc-list-item>
<igc-list-item>
<igc-avatar slot="start" src="https://randomuser.me/api/portraits/men/1.jpg" shape="circle">
AA
</igc-avatar>
<h2 slot="title">Richard Mahoney</h2>
<span slot="subtitle">423-676-2869</span>
<igc-button slot="end" variant="outlined">
Text
</igc-button>
<igc-button slot="end" variant="outlined">
Call
</igc-button>
</igc-list-item>
<igc-list-item>
<igc-avatar slot="start" src="https://randomuser.me/api/portraits/women/50.jpg" shape="circle">
AA
</igc-avatar>
<h2 slot="title">Donna Price</h2>
<span slot="subtitle">859-496-2817</span>
<igc-button slot="end" variant="outlined">
Text
</igc-button>
<igc-button slot="end" variant="outlined">
Call
</igc-button>
</igc-list-item>
</igc-list>
The start slot is meant to be used for adding some kind of media before all other content of our list items. The target element, in our case the IgcAvatarComponent component, will also be provided with a default position and spacing.
The end slot is meant to be used for list items that have some kind of action or metadata, represented, for example, by a switch, a button, a checkbox, etc. We will use IgcButtonComponent components.
Let's also allow the user to change the size of the list using the --ig-size CSS variable. We will add some radio buttons to display all size values. This way whenever one gets selected, we will change the size of the list.
<igc-radio-group id="radio-group" alignment="horizontal">
<igc-radio name="size" value="small" label-position="after">Small</igc-radio>
<igc-radio name="size" value="medium" label-position="after">Medium</igc-radio>
<igc-radio name="size" value="large" label-position="after" checked>Large</igc-radio>
</igc-radio-group>
this.list = document.getElementById('list') as IgcListComponent;
this.radioGroup = document.getElementById('radio-group') as IgcRadioGroupComponent;
this.radioGroup.addEventListener('click', (radio: any) => {
this.list.style.setProperty('--ig-size', `var(--ig-size-${radio.target.value})`);
});
위 코드를 구현한 결과는 다음과 같아야 합니다.
Styling
The IgcListComponent exposes several CSS parts, giving you full control over its style:
| 이름 | 설명 |
|---|---|
start |
시작 컨테이너입니다. |
end |
끝 컨테이너입니다. |
content |
헤더 및 사용자 지정 콘텐츠 컨테이너입니다. |
header |
제목 및 부제목 컨테이너입니다. |
title |
제목 컨테이너입니다. |
subtitle |
자막 컨테이너입니다. |
igc-list-header {
font-size: 20px;
font-weight: 700;
color: var(--ig-primary-700);
}
igc-list-item::part(title) {
font-size: 18px;
color: var(--ig-primary-600);
}
igc-list-item::part(subtitle) {
color: var(--ig-primary-300);
}
In this article we covered a lot of ground with the IgcListComponent component. First, we created a simple list with text items. Then, we created a list of contact items and added functionality to them by using some additional Ignite UI for Web Components components, like the IgcAvatarComponent and IgcButtonComponent. Finally, we changed the component's appearance through the exposed CSS parts.
API References
IgcAvatarComponentIgcButtonComponentIgcRadioGroupComponentIgcRadioComponentIgcListHeaderComponentIgcListItemComponentIgcListComponentStyling & Themes