Angular List View (リスト ビュー) コンポーネントの概要
Ignite UI for Angular List コンポーネントは項目の行を表示し、ヘッダー項目を 1 つ以上、さらにリスト項目の検索およびフィルタリングをサポートします。各リスト項目はすべての有効な HTML または Angular コンポーネント をサポートするテンプレートに設定できます。リスト コンポーネントは、組み込みのパンニング機能、空および読み込み状態のテンプレートも提供し、IgxForOf
ディレクティブを使用した大きなリストの仮想化をサポートします。
Angular List の例
次の例は、name プロパティと phone number プロパティを持つ連絡先が入力されたリストを表しています。IgxList
コンポーネントは、IgxAvatar
と IgxIcon
を使用して、ユーザー エクスペリエンスを向上させ、連絡先をお気に入りに追加 にアバター写真とさまざまなアイコンを設定する機能を公開します。さらに、リスト ビューは、フィルタリング パイプを使用して実現されたソート機能を公開します。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule,
IgxButtonGroupModule,
IgxRippleModule
} from "igniteui-angular" ;
import { ListSample4Component } from "./list-sample-4/list-sample-4.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample4Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule,
IgxButtonGroupModule,
IgxRippleModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit } from '@angular/core' ;
import { DisplayDensity, IgxFilterOptions } from 'igniteui-angular' ;
@Component ({
selector : 'app-contact-list2' ,
styleUrls : ['./list-sample-4.component.scss' ],
templateUrl : './list-sample-4.component.html'
})
export class ListSample4Component implements OnInit {
public searchContact: string ;
public contacts = [
{
isFavorite : false ,
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/27.jpg'
},
{
isFavorite : true ,
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/1.jpg'
},
{
isFavorite : false ,
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/50.jpg'
},
{
isFavorite : false ,
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/3.jpg'
},
{
isFavorite : true ,
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/67.jpg'
}
];
public density: DisplayDensity = 'comfortable' ;
public displayDensities;
constructor ( ) { }
public ngOnInit ( ) {
this .displayDensities = [
{ label : 'comfortable' , selected : this .density === 'comfortable' , togglable : true },
{ label : 'cosy' , selected : this .density === 'cosy' , togglable : true },
{ label : 'compact' , selected : this .density === 'compact' , togglable : true }
];
}
public selectDensity (event ) {
this .density = this .displayDensities[event.index].label;
}
public toggleFavorite (contact: any ) {
contact.isFavorite = !contact.isFavorite;
}
get filterContacts () {
const fo = new IgxFilterOptions();
fo.key = 'name' ;
fo.inputValue = this .searchContact;
return fo;
}
}
ts コピー <div class ="density-chooser" >
<igx-buttongroup [values ]="displayDensities" (selected )="selectDensity($event)" > </igx-buttongroup >
</div >
<igx-input-group type ="search" class ="search" >
<igx-prefix >
<igx-icon > search</igx-icon >
</igx-prefix >
<input #search igxInput placeholder ="Search Contacts" [(ngModel )]="searchContact" >
<igx-suffix *ngIf ="search.value.length > 0" (click )="searchContact = null" >
<igx-icon > clear</igx-icon >
</igx-suffix >
</igx-input-group >
<div class ="list-sample" >
<igx-list [displayDensity ]="density" >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
<igx-list-item igxRipple igxRippleTarget =".igx-list__item-content" #item *ngFor ="let contact of contacts | igxFilter: filterContacts;" >
<igx-avatar igxListThumbnail [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(contact)" > star</igx-icon >
</igx-list-item >
</igx-list >
</div >
html コピー :host {
display : block;
padding : 16px ;
}
.list-sample {
box-shadow : 0px 1px 3px 0px rgba(0 , 0 , 0 , 0.2 ),
0px 1px 1px 0px rgba(0 , 0 , 0 , 0.14 ),
0px 2px 1px -1px rgba(0 , 0 , 0 , 0.12 );
}
.density-chooser {
margin-bottom : 16px ;
}
igx-icon {
cursor : pointer;
}
.search {
margin-bottom : 16px ;
}
scss コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Ignite UI for Angular List を使用した作業の開始
Ignite UI for Angular List View コンポーネントを使用した作業を開始するには、Ignite UI for Angular をインストールする必要があります。既存の Angular アプリケーションで、以下のコマンドを入力します。
ng add igniteui-angular
cmd
Ignite UI for Angular については、「はじめに 」トピックをご覧ください。
次に、app.module.ts ファイルに IgxListModule
をインポートします。
このコンポーネントは、オプションで HammerModule
を利用できます。タッチ操作が正しく動作するために、アプリケーションのルート モジュールにインポートできます。
import { HammerModule } from '@angular/platform-browser' ;
import { IgxListModule } from 'igniteui-angular' ;
@NgModule ({
...
imports : [..., IgxListModule, HammerModule],
...
})
export class AppModule {}
typescript
あるいは、16.0.0
以降、IgxListComponent
をスタンドアロンの依存関係としてインポートすることも、IGX_LIST_DIRECTIVES
トークンを使用してコンポーネントとそのすべてのサポート コンポーネントおよびディレクティブをインポートすることもできます。
import { HammerModule } from '@angular/platform-browser' ;
import { IGX_LIST_DIRECTIVES } from 'igniteui-angular' ;
@Component ({
selector : 'app-home' ,
template : `
<igx-list>
<igx-list-item isHeader="true">Header</igx-list-item>
<igx-list-item>Item 1</igx-list-item>
<igx-list-item>Item 2</igx-list-item>
<igx-list-item>Item 3</igx-list-item>
</igx-list>
` ,
styleUrls : ['home.component.scss' ],
standalone : true ,
imports : [IGX_LIST_DIRECTIVES, HammerModule]
})
export class HomeComponent {}
typescript
Ignite UI for Angular List モジュールまたはディレクティブをインポートしたので、igx-list
コンポーネントの使用を開始できます。
Angular List の使用
連絡先コンポーネントのテンプレートでリストを作成できます。
項目がない場合は、空のリストのデフォルト テンプレートを使用できます。
igxEmptyList
ディレクティブを使用して空のリストの外観をカスタマイズするためにカスタム テンプレートを設定できます。この場合、デフォルト テンプレートは使用されません。
<igx-list >
<ng-template igxEmptyList >
<p class ="empty" > No contacts! :(</p >
</ng-template >
</igx-list >
html
空のテンプレートのスタイル:
.empty {
color : rgba (0 , 153 , 255 , 1 );
font-size : 25px ;
font-weight : 600 ;
text-shadow : 2px 1px 2px rgba (150 , 150 , 150 , 1 );
}
css
空のリストは以下のようになります:
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxListModule } from "igniteui-angular" ;
import { ListSample5Component } from "./list-sample-5/list-sample-5.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample5Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxListModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-list-sample-5' ,
styleUrls : ['./list-sample-5.component.scss' ],
templateUrl : './list-sample-5.component.html'
})
export class ListSample5Component {
constructor ( ) { }
}
ts コピー <igx-list >
<ng-template igxEmptyList >
<p class ="empty" > No contacts! :(</p >
</ng-template >
</igx-list >
html コピー .empty {
color : rgba(0 , 153 , 255 , 1 );
font-size : 25px ;
font-weight : 600 ;
text-shadow : 2px 1px 2px rgba(150 , 150 , 150 , 1 );
}
scss コピー
データの読み込みで遅延が発生した場合、リストの isLoading
プロパティを true
に設定し、デフォルト テンプレートで処理中のデータ読み込み処理についてユーザーに通知できます。igxDataLoading
ディレクティブを使用してカスタムの読み込みテンプレートを提供できます。
<igx-list >
<ng-template igxDataLoading >
<p class ="loading" > Patience, we are currently loading your data...</p >
</ng-template >
</igx-list >
html
.loading {
color : rgba (255 , 153 , 0 , 1 );
font-size : 25px ;
font-weight : 600 ;
text-shadow : 2px 1px 2px rgba (150 , 150 , 150 , 1 );
}
css
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxButtonModule,
IgxListModule,
IgxRippleModule
} from "igniteui-angular" ;
import { ListSample6Component } from "./list-sample-6/list-sample-6.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample6Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxListModule,
IgxRippleModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, ViewChild } from '@angular/core' ;
import { IgxListComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-list-sample-6' ,
styleUrls : ['./list-sample-6.component.scss' ],
templateUrl : './list-sample-6.component.html'
})
export class ListSample6Component {
@ViewChild ('fruitList' , { static : true })
public fruitList: IgxListComponent;
public fruitsData: string [] = [];
constructor ( ) { }
public loadFruits ( ) {
this .fruitList.isLoading = true ;
setTimeout (() => {
const availableFruits: string [] = ['banana' , 'orange' , 'apple' , 'strawberry' , 'pear' ];
availableFruits.forEach((fruit ) => { this .fruitsData.push(fruit); });
this .fruitList.isLoading = false ;
}, 1000 );
}
}
ts コピー <igx-list #fruitList >
<igx-list-item *ngFor ="let fruit of fruitsData" igxRipple igxRippleTarget =".igx-list__item-content" >
{{ fruit }}
</igx-list-item >
<ng-template igxEmptyList >
<div class ="center" > <button type ="button" igxButton ="raised" (click )="loadFruits()" > Load data</button > </div >
</ng-template >
<ng-template igxDataLoading >
<div class ="center" > <span > Patience, we are currently loading your data...</span > </div >
</ng-template >
</igx-list >
html コピー .center {
display : flex;
align-items : center;
justify-content : center;
color : #999 ;
font-size : 24px ;
height : 100% ;
}
scss コピー
リスト項目の追加
リストが空の場合にテンプレートは便利ですが、次は項目を追加します。以下のコードを追加すると項目の簡易なリストを作成できます。
<igx-list >
<igx-list-item isHeader ="true" > Header</igx-list-item >
<igx-list-item > Item 1</igx-list-item >
<igx-list-item > Item 2</igx-list-item >
<igx-list-item > Item 3</igx-list-item >
</igx-list >
html
以下は結果です:
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import { IgxListModule } from "igniteui-angular" ;
import { ListSample2Component } from "./list-sample-2/list-sample-2.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample2Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxListModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-igx-list-simple' ,
styleUrls : ['./list-sample-2.component.scss' ],
templateUrl : './list-sample-2.component.html'
})
export class ListSample2Component {
constructor ( ) {}
}
ts コピー <igx-list >
<igx-list-item [isHeader ]="true" > Header</igx-list-item >
<igx-list-item > Item 1</igx-list-item >
<igx-list-item > Item 2</igx-list-item >
<igx-list-item > Item 3</igx-list-item >
</igx-list >
html コピー
リスト項目にカスタム マークアップおよびスタイルを適用します。たとえば、名前の下に電話番号が表示される連絡先の Angular リストを作成する場合、コンポーネントの typescript ファイルで連絡先のリストを定義します。
...
public contacts = [{
name : "Terrance Orta" ,
phone : "770-504-2217"
}, {
name : "Richard Mahoney" ,
phone : "423-676-2869"
}, {
name : "Donna Price" ,
phone : "859-496-2817"
}, {
name : "Lisa Landers" ,
phone : "901-747-3428"
}, {
name : "Dorothy H. Spencer" ,
phone : "573-394-9254"
}];
typescript
データを描画するマークアップを作成します。
すぐにスタイル設定したい場合は、リスト項目に付属するディレクティブを使用できます。
以下の例では、それらを使用する方法を示します。
<igx-list >
<igx-list-item isHeader ="true" >
Contacts
</igx-list-item >
<igx-list-item *ngFor ="let contact of contacts" >
<h4 igxListLineTitle > {{ contact.name }}</h4 >
<p igxListLineSubTitle > {{ contact.phone }}</p >
</igx-list-item >
</igx-list >
html
igxListLineTitle
と igxListLineSubTitle
ディレクティブは両方とも、リスト項目にデフォルトの外観を指定します。
結果は以下のようになります。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxListModule,
IgxRippleModule
} from "igniteui-angular" ;
import { ListSample3Component } from "./list-sample-3/list-sample-3.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample3Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxListModule,
IgxRippleModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-contact-list' ,
styleUrls : ['./list-sample-3.component.scss' ],
templateUrl : './list-sample-3.component.html'
})
export class ListSample3Component {
public contacts = [
{
name : 'Terrance Orta' ,
phone : '770-504-2217'
},
{
name : 'Richard Mahoney' ,
phone : '423-676-2869'
},
{
name : 'Donna Price' ,
phone : '859-496-2817'
},
{
name : 'Lisa Landers' ,
phone : '901-747-3428'
},
{
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254'
}
];
constructor ( ) { }
}
ts コピー <igx-list >
<igx-list-item [isHeader ]="true" >
Contacts
</igx-list-item >
<igx-list-item *ngFor ="let contact of contacts" igxRipple igxRippleTarget =".igx-list__item-content" >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{contact.phone}}</span >
</igx-list-item >
</igx-list >
html コピー
アバターおよびアイコンの追加
その他のコンポーネントを IgxList
と共に使用してエクスペリエンスの向上や機能拡張が可能です。名前や電話番号の値の左に画像のアバターを表示できます。また、連絡先をお気に入りに追加するための星アイコンを右側に追加できます。要素を追加するには、IgxAvatar および IgxIcon モジュールを app.module.ts ファイルにインポートします。
...
import {
IgxListModule,
IgxAvatarModule,
IgxIconModule
} from 'igniteui-angular' ;
@NgModule ({
...
imports : [..., IgxAvatarModule, IgxIconModule],
})
export class AppModule {}
typescript
連絡先オブジェクトにアバターの photo
ソースおよび連絡先のお気に入り状態を示す isFavorite
プロパティを追加します。
public contacts = [{
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://randomuser.me/api/portraits/men/27.jpg' ,
isFavorite : false
}, {
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://randomuser.me/api/portraits/men/1.jpg' ,
isFavorite : true
}, {
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://randomuser.me/api/portraits/women/50.jpg' ,
isFavorite : false
}, {
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://randomuser.me/api/portraits/women/3.jpg' ,
isFavorite : false
}, {
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://randomuser.me/api/portraits/women/67.jpg' ,
isFavorite : true
}];
typescript
連絡先リストのテンプレートをアバターおよびアイコンを表示するために更新します。リスト ディレクティブを使用してテンプレートを更新できます。
<igx-list >
<igx-list-item isHeader ="true" >
Contacts
</igx-list-item >
<igx-list-item #item *ngFor ="let contact of contacts;" >
<igx-avatar igxListThumbnail [src ]="contact.photo" shape ="circle" > </igx-avatar >
<h4 igxListLineTitle > {{ contact.name }}</h4 >
<p igxListLineSubTitle class ="phone" > {{ contact.phone }}</p >
<span igxListLine > Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dicta, laborum.</span >
<igx-icon igxListAction [color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(item)" > star</igx-icon >
</igx-list-item >
</igx-list >
html
igxListThumbnail
は、リスト項目の開始に何らかのメディアを追加する必要がある場合に使用します。このディレクティブは、ターゲット要素 (この場合は igx-avatar) を、デフォルトの位置と間隔を提供するコンテナーにラップします。
igxListAction
は、スイッチ、ラジオ ボタン、チェックボックスなど、アクションまたはメタデータを持つリスト項目に使用します。この場合、アクションは igx-icon
で表示されます。ディレクティブは、正しい位置と間隔のコンテナーでターゲット要素をラップします。
igxListLine
は、igxListThumbnail
と igxListAction
の間にテキストが必要な場合に使用します。このディレクティブは、テキストの位置、間隔、配置が残りのディレクティブと外観がよくなるようにします。
次に、連絡先オブジェクトの isFavorite プロパティを切り替えるために IgxIcon コンポーネントでクリック イベントをリッスンします。
...
toggleFavorite (item: IgxListItem ) {
const contact = this .contacts[item.index - 1 ];
contact.isFavorite = !contact.isFavorite;
}
typescript
また、--ig-size
カスタム CSS プロパティを使用して、ユーザーがリストのサイズを選択できるようにすることができます。これには、IgxButtonGroupModule
をインポートし、IgxButtonGroup を使用してすべてのサイズ値を表示します。このようにして、選択されるたびに、リストのサイズ が更新されます。
...
import { IgxButtonGroupModule } from 'igniteui-angular' ;
@NgModule ({
imports : [..., IgxButtonGroupModule]
})
typescript
<igx-buttongroup [values ]="sizes" (selected )="selectSize($event)" > </igx-buttongroup >
...
<igx-list >
...
</igx-list >
html
public size = 'large' ;
public sizes;
public ngOnInit ( ) {
this .sizes = [
{ label : 'large' , selected : this .size === 'large' , togglable : true },
{ label : 'medium' , selected : this .size === 'medium' , togglable : true },
{ label : 'small' , selected : this .size === 'small' , togglable : true }
];
}
public selectSize (event: any ) {
this .size = this .sizes[event.index].label;
}
@HostBinding ('style.--ig-size' )
protected get sizeStyle () {
return `var(--ig-size-${this .size} )` ;
}
typescript
結果は以下のようになります。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule,
IgxButtonGroupModule,
IgxRippleModule
} from "igniteui-angular" ;
import { ListSample4Component } from "./list-sample-4/list-sample-4.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample4Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule,
IgxButtonGroupModule,
IgxRippleModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit } from '@angular/core' ;
import { DisplayDensity, IgxFilterOptions } from 'igniteui-angular' ;
@Component ({
selector : 'app-contact-list2' ,
styleUrls : ['./list-sample-4.component.scss' ],
templateUrl : './list-sample-4.component.html'
})
export class ListSample4Component implements OnInit {
public searchContact: string ;
public contacts = [
{
isFavorite : false ,
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/27.jpg'
},
{
isFavorite : true ,
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/1.jpg'
},
{
isFavorite : false ,
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/50.jpg'
},
{
isFavorite : false ,
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/3.jpg'
},
{
isFavorite : true ,
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/67.jpg'
}
];
public density: DisplayDensity = 'comfortable' ;
public displayDensities;
constructor ( ) { }
public ngOnInit ( ) {
this .displayDensities = [
{ label : 'comfortable' , selected : this .density === 'comfortable' , togglable : true },
{ label : 'cosy' , selected : this .density === 'cosy' , togglable : true },
{ label : 'compact' , selected : this .density === 'compact' , togglable : true }
];
}
public selectDensity (event ) {
this .density = this .displayDensities[event.index].label;
}
public toggleFavorite (contact: any ) {
contact.isFavorite = !contact.isFavorite;
}
get filterContacts () {
const fo = new IgxFilterOptions();
fo.key = 'name' ;
fo.inputValue = this .searchContact;
return fo;
}
}
ts コピー <div class ="density-chooser" >
<igx-buttongroup [values ]="displayDensities" (selected )="selectDensity($event)" > </igx-buttongroup >
</div >
<igx-input-group type ="search" class ="search" >
<igx-prefix >
<igx-icon > search</igx-icon >
</igx-prefix >
<input #search igxInput placeholder ="Search Contacts" [(ngModel )]="searchContact" >
<igx-suffix *ngIf ="search.value.length > 0" (click )="searchContact = null" >
<igx-icon > clear</igx-icon >
</igx-suffix >
</igx-input-group >
<div class ="list-sample" >
<igx-list [displayDensity ]="density" >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
<igx-list-item igxRipple igxRippleTarget =".igx-list__item-content" #item *ngFor ="let contact of contacts | igxFilter: filterContacts;" >
<igx-avatar igxListThumbnail [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(contact)" > star</igx-icon >
</igx-list-item >
</igx-list >
</div >
html コピー :host {
display : block;
padding : 16px ;
}
.list-sample {
box-shadow : 0px 1px 3px 0px rgba(0 , 0 , 0 , 0.2 ),
0px 1px 1px 0px rgba(0 , 0 , 0 , 0.14 ),
0px 2px 1px -1px rgba(0 , 0 , 0 , 0.12 );
}
.density-chooser {
margin-bottom : 16px ;
}
igx-icon {
cursor : pointer;
}
.search {
margin-bottom : 16px ;
}
scss コピー
リスト項目パンニング
連絡先や電話番号の Angular リストなどを作成しましたが、次に連絡先に電話を掛ける機能を追加します。
IgxList
はリスト項目パンニングに最適です。
以下の手順に沿って作成します。
以下は、右と左両方のパンニングを処理する方法の例です。右パンニングのイベント ハンドラーは、トースト メッセージを表示します。左パンニングのイベント ハンドラーは、IgxList
から項目を削除します。
リスト項目の削除はアプリケーション タスクであることに注意してください。IgxList
にデータソース参照がないため、IgxList
は項目をデータソースから削除できません。
以下は HTML コードです。
<igx-list [allowLeftPanning ]="true" [allowRightPanning ]="true"
(leftPan )="leftPanPerformed($event)" (rightPan )="rightPanPerformed($event)" >
<ng-template igxListItemLeftPanning >
<div class ="listItemLeftPanningStyle" >
<igx-icon [color ]="white" style ="margin-left:10px" > delete</igx-icon >Delete
</div >
</ng-template >
<ng-template igxListItemRightPanning >
<div class ="listItemRightPanningStyle" >
<igx-icon [color ]="white" style ="margin-right:10px" > call</igx-icon >Dial
</div >
</ng-template >
<igx-list-item isHeader ="true" > Contacts</igx-list-item >
<igx-list-item #item *ngFor ="let contact of contacts" >
<igx-avatar igxListThumbnail [src ]="contact.photo" shape ="circle" > </igx-avatar >
<h4 igxListLineTitle > {{ contact.name }}</h4 >
<p igxListLineSubTitle class ="phone" > {{ contact.phone }}</p >
<igx-icon igxListAction [color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(item)" > star</igx-icon >
</igx-list-item >
</igx-list >
<igx-toast #toast > </igx-toast >
html
上記の例は、CSS スタイルを使用します。
igx-icon {
cursor : pointer;
user-select: none;
}
.listItemLeftPanningStyle {
display : flex;
flex-direction : row-reverse;
background-color :orange;
color : white;
width : 100% ;
padding-right : 10px ;
align-items : center;
}
.listItemRightPanningStyle {
display : flex;
flex-direction : row;
background-color :limegreen;
color : white;
width : 100% ;
padding-left : 10px ;
align-items : center;
}
css
最後にパンニング イベントを処理するタイプスクリプト コードを使用します。
...
@ViewChild ('toast' )
public toast: IgxToastComponent;
public rightPanPerformed (args ) {
args.keepItem = true ;
this .toast.message = 'Dialing ' + this .contacts[args.item.index - 1 ].name;
this .toast.open();
}
public leftPanPerformed (args ) {
args.keepItem = false ;
setTimeout ((idx = args.item.index - 1 ) => {
this .toast.message = 'Contact ' + this .contacts[idx].name + ' removed.' ;
this .toast.open();
this .contacts.splice(idx, 1 );
}, 500 );
}
...
typescript
次にリスト項目をパンニングします。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxAvatarModule,
IgxIconModule,
IgxListModule,
IgxRippleModule,
IgxSliderModule,
IgxToastModule,
IgxButtonModule
} from "igniteui-angular" ;
import { ListSample7Component } from "./list-sample-7/list-sample-7.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample7Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxAvatarModule,
IgxIconModule,
IgxListModule,
IgxRippleModule,
IgxSliderModule,
IgxToastModule,
IgxButtonModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxListComponent, IgxToastComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-contact-list2' ,
styleUrls : ['./list-sample-7.component.scss' ],
templateUrl : './list-sample-7.component.html'
})
export class ListSample7Component implements OnInit {
@ViewChild ('toast' , { static : true })
public toast: IgxToastComponent;
@ViewChild ('mainIgxList' , { static : true })
public list: IgxListComponent;
public contacts;
private dataSource = [{
isFavorite : false ,
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/27.jpg'
}, {
isFavorite : true ,
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/1.jpg'
}, {
isFavorite : false ,
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/50.jpg'
}, {
isFavorite : false ,
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/3.jpg'
}, {
isFavorite : true ,
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/67.jpg'
}
];
constructor ( ) {
}
public ngOnInit ( ) {
this .contacts = Object .assign([], this .dataSource);
}
public toggleFavorite (contact: any ) {
contact.isFavorite = !contact.isFavorite;
}
public rightPanPerformed (args ) {
args.keepItem = true ;
this .toast.open('Dialing ' + this .contacts[args.item.index - 1 ].name);
}
public leftPanPerformed (args ) {
args.keepItem = false ;
setTimeout ((idx = args.item.index - 1 ) => {
this .toast.open('Contact ' + this .contacts[idx].name + ' removed.' );
this .contacts.splice(idx, 1 );
}, 500 );
}
public repopulateHandler ( ) {
this .contacts = Object .assign([], this .dataSource);
}
public get panThreshold () {
const result = this .list.panEndTriggeringThreshold;
return Math .round(result * 100 ) + '%' ;
}
}
ts コピー <div style ="width:300px; margin-bottom:20px" >
<igx-slider id ="slider" [minValue ]="0.1" [maxValue ]="0.9" [step ]="0.1" [continuous ]="true" [(ngModel )]="mainIgxList.panEndTriggeringThreshold" > </igx-slider >
<label > Threshold: {{panThreshold}}</label >
</div >
<div class ="list-sample" >
<igx-list [allowLeftPanning ]="true" [allowRightPanning ]="true" #mainIgxList (leftPan )="leftPanPerformed($event)"
(rightPan )="rightPanPerformed($event)" >
<ng-template igxListItemLeftPanning >
<div class ="listItemLeftPanningStyle" >
<igx-icon > delete</igx-icon >Delete
</div >
</ng-template >
<ng-template igxListItemRightPanning >
<div class ="listItemRightPanningStyle" >
<igx-icon > call</igx-icon >Dial
</div >
</ng-template >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
<igx-list-item #item *ngFor ="let contact of contacts" igxRipple ="pink" igxRippleTarget =".igx-list__item-content" >
<igx-avatar igxListThumbnail [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(contact)" > star</igx-icon >
</igx-list-item >
</igx-list >
<igx-toast #toast > </igx-toast >
</div >
<button igxButton ="raised" (click )="repopulateHandler()" style ="margin-top:20px" > Repopulate IgxList</button >
html コピー :host {
display : block;
padding : 16px ;
}
.list-sample {
box-shadow : 0px 1px 3px 0px rgba(0 , 0 , 0 , 0.2 ),
0px 1px 1px 0px rgba(0 , 0 , 0 , 0.14 ),
0px 2px 1px -1px rgba(0 , 0 , 0 , 0.12 );
}
igx-icon {
cursor : pointer;
}
.listItemLeftPanningStyle {
display : flex;
flex-direction : row-reverse;
background-color :orange;
color : white;
width : 100% ;
padding-right : 10px ;
align-items : center;
}
.listItemRightPanningStyle {
display : flex;
flex-direction : row;
background-color :limegreen;
color : white;
width : 100% ;
padding-left : 10px ;
align-items : center;
}
scss コピー
Angular フィルター リスト
リストで連絡先を名前によって検索する機能を追加します。これはフィルタリング パイプを使用して実装できます。
Angular コンポーネント テンプレートの上側に入力フィールドを追加し、コンポーネントの searchContact プロパティにバインドします:
<igx-input-group type ="search" class ="search" >
<igx-prefix >
<igx-icon > search</igx-icon >
</igx-prefix >
<input #search igxInput placeholder ="Search Contacts" [(ngModel )]="searchContact" >
<igx-suffix *ngIf ="search.value.length > 0" (click )="searchContact = null" >
<igx-icon > clear</igx-icon >
</igx-suffix >
</igx-input-group >
html
IgxFilterModule
および IgxInputGroupModule
を app.module.ts ファイルにインポートし、IgxFilterOptions
を連絡先コンポーネントにインポートします。
...
import { IgxFilterModule, IgxInputGroupModule } from 'igniteui-angular' ;
@NgModule ({
imports : [..., IgxFilterModule, IgxInputGroupModule]
})
...
import { IgxFilterOptions } from 'igniteui-angular' ;
@Component ({...})
export class ContactListComponent {
public searchContact: string ;
...
get filterContacts (): IgxFilterOptions {
const fo = new IgxFilterOptions();
fo.key = 'name' ;
fo.inputValue = this .searchContact;
return fo;
}
}
typescript
IgxFilterOptions
をインポートした後、searchContact
プロパティの更新でパイプによって使用されるフィルタリング オプションを返すゲッター メソッドを登録します。フィルターが機能するために連絡先オブジェクトのフィルター key
を登録します。この場合、各連絡先の name
です。IgxFilterOptions
オブジェクトで登録する 2 番目のプロパティは連絡先の名前を比較する値です。連絡先リストの上の入力フィールドにバインドした searchContact
プロパティです。
フィルタリング パイプを連絡先のデータに適用します。テンプレートで以下のコードを追加します:
<igx-list-item *ngFor ="let contact of contacts | igxFilter: filterContacts; let i = index" >
...
</igx-list-item >
html
リスト項目の選択
リスト項目には、どの項目が「選択」されているかを追跡するのに役立つ selected
プロパティがあります。このプロパティを使用すると、各項目の選択状態を識別および管理できます。
以下の例は、selected
プロパティを使用したときに項目の視覚スタイルがどのように変化するかを示しています。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule
} from "igniteui-angular" ;
import { ListItemSelectionComponent } from "./list-item-selection/list-item-selection.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListItemSelectionComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxAvatarModule,
IgxFilterModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
import { IgxFilterOptions } from 'igniteui-angular' ;
@Component ({
selector : 'app-list-item-selection' ,
templateUrl : './list-item-selection.component.html' ,
styleUrls : ['./list-item-selection.component.scss' ]
})
export class ListItemSelectionComponent {
public searchContact: string ;
public contacts = [
{
isFavorite : false ,
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/27.jpg' ,
selected : false
},
{
isFavorite : true ,
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/1.jpg' ,
selected : false
},
{
isFavorite : false ,
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/50.jpg' ,
selected : false
},
{
isFavorite : false ,
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/3.jpg' ,
selected : false
},
{
isFavorite : true ,
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/67.jpg' ,
selected : false
}
];
public toggleFavorite (contact: any , event: Event ) {
event.stopPropagation();
contact.isFavorite = !contact.isFavorite;
}
public selectItem (item ) {
if (!item.selected) {
this .contacts.forEach(c => c.selected = false );
item.selected = true ;
}
}
get filterContacts () {
const fo = new IgxFilterOptions();
fo.key = 'name' ;
fo.inputValue = this .searchContact;
return fo;
}
}
ts コピー <igx-input-group type ="search" class ="search" >
<igx-prefix >
<igx-icon > search</igx-icon >
</igx-prefix >
<input #search igxInput placeholder ="Search Contacts" [(ngModel )]="searchContact" >
<igx-suffix *ngIf ="search.value.length > 0" (click )="searchContact = null" >
<igx-icon > clear</igx-icon >
</igx-suffix >
</igx-input-group >
<div class ="list-sample" >
<igx-list >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
<igx-list-item [ngClass ]="contact.selected ? 'selected' : ''"
(click )="selectItem(contact)"
*ngFor ="let contact of contacts | igxFilter: filterContacts;" >
<igx-avatar igxListThumbnail [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(contact, $event)" > star</igx-icon >
</igx-list-item >
</igx-list >
</div >
html コピー :host {
display : block;
padding : 16px ;
.selected {
background-color : hsla(var(--ig-secondary-500 ))
}
.list-sample {
box-shadow: 0px 1px 3px 0px rgba(0 , 0 , 0 , 0.2 ),
0px 1px 1px 0px rgba(0 , 0 , 0 , 0.14 ),
0px 2px 1px -1px rgba(0 , 0 , 0 , 0.12 );
}
igx-icon {
cursor : pointer;
}
.search {
margin-bottom : 16px ;
}
}
scss コピー
デフォルトで、selected
プロパティは false
に設定されています。各リスト項目の (click)
イベントにバインドされたインライン式を使用して値を切り替えることができ、クリックされるたびに項目の視覚的な状態を効果的に切り替えることができます。
<igx-list >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
@for (contact of contacts | igxFilter: filterContacts; track contact) {
<igx-list-item [selected ]="contact.selected" (click )="contact.selected = !contact.selected" >
<igx-avatar igxListThumbnail [src ]="contact.photo" shape ="circle" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" igxRipple ="pink"
[igxRippleCentered ]="true" (click )="toggleFavorite(contact, $event)"
(mousedown )="mousedown($event)" > star</igx-icon >
</igx-list-item >
}
</igx-list >
html
リスト項目には、選択した要素のさまざまな部分のスタイルを設定するために使用できるいくつかの CSS 変数も公開されています。
--item-background-selected
--item-text-color-selected
--item-title-color-selected
--item-action-color-selected
--item-subtitle-color-selected
--item-thumbnail-color-selected
igx-list-item {
--item-background -selected: var(--ig-secondary-500 );
--item-title-color -selected: var(--ig-secondary-500 -contrast);
--item-subtitle-color -selected: var(--ig-info-100 );
}
scss
リストのテーマ変数を使用する場合は、リスト項目の選択状態のスタイルを設定できるパラメーターが用意されています。これらのパラメーターの詳細については、list-theme
を参照してください。
Chat コンポーネント
以下のサンプルは、IgxList を使用して作成したシンプルなチャットです。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxAvatarModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule
} from "igniteui-angular" ;
import { ListChatSampleComponent } from "./list-chat-sample/list-chat-sample.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListChatSampleComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxAvatarModule,
IgxIconModule,
IgxListModule,
IgxInputGroupModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { DOCUMENT } from '@angular/common' ;
import { Component, Inject, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core' ;
import { ContactsService } from './services/contacts.service' ;
import { IMessage, MessagesService } from './services/messages.service' ;
@Component ({
encapsulation : ViewEncapsulation.None,
selector : 'app-list-chat-sample' ,
styleUrls : ['./list-chat-sample.component.scss' ],
templateUrl : './list-chat-sample.component.html'
})
export class ListChatSampleComponent {
@ViewChild ('myMessage' , { static : true })
public myMessageTemplate: TemplateRef<any >;
@ViewChild ('othersMessage' , { static : true })
public othersMessageTemplate: TemplateRef<any >;
public message: string ;
private myId = 4 ;
constructor (public messagesService: MessagesService, public contactsService: ContactsService,
@Inject (DOCUMENT) private document : any ) { }
public getMessageTemplate(message: IMessage): TemplateRef<any > {
if (message.authorId === this .myId) {
return this .myMessageTemplate;
}
return this .othersMessageTemplate;
}
public isFirstMessage(messageIndex: number ): boolean {
if (messageIndex === 0 ) {
return true ;
}
const messages = this .messagesService.getMessages();
if (messageIndex >= messages.length) {
return false ;
}
const currentMessage = messages[messageIndex];
const previousMessage = messages[messageIndex - 1 ];
return currentMessage.authorId !== previousMessage.authorId;
}
public onMessageKeypress (event ) {
if (event.key === 'Enter' ) {
this .sendMessage();
}
}
public onSendButtonClick ( ) {
this .sendMessage();
}
private sendMessage ( ) {
this .addMessage(this .message);
this .message = null ;
this .scrollToBottom();
}
private addMessage (message: string ) {
if (message) {
const messageInstance: IMessage = {
authorId : this .myId,
message,
timestamp : new Date (Date .now())
};
this .messagesService.addMessage(messageInstance);
}
}
private scrollToBottom(): void {
try {
const listElement = this .document.querySelector('igx-list' );
if (listElement) {
listElement.scrollTop = listElement.scrollHeight;
}
} catch (err) { }
}
}
ts コピー <div class ="chat-sample-wrapper" >
<form class ="chat-sample__form" >
<igx-list #list >
<ng-template #othersMessage let-message ="message" let-contact ="contact" let-messageIndex ="index" >
<igx-list-item class ="contact" *ngIf ="isFirstMessage(messageIndex)" >
<div class ="contact__panel" >
<igx-avatar [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span class ="message__info" >
{{ contact.name }}, {{ message.timestamp | date: 'shortTime'}}
</span >
</div >
</igx-list-item >
<igx-list-item [ngClass ]="{
'others-message': true,
'others-message--first': isFirstMessage(messageIndex)}" >
<span >
{{ message.message }}
</span >
</igx-list-item >
</ng-template >
<ng-template #myMessage let-message ="message" let-messageIndex ="index" >
<igx-list-item class ="contact" *ngIf ="isFirstMessage(messageIndex)" >
<span class ="my-message__info" >
{{ message.timestamp | date: 'shortTime'}}
</span >
</igx-list-item >
<igx-list-item class ="my-message" [ngClass ]="{
'my-message': true,
'my-message--first': isFirstMessage(messageIndex)}" >
<span >
{{ message.message }}
</span >
</igx-list-item >
</ng-template >
<ng-container *ngFor ="let message of messagesService.getMessages(); index as i" >
<ng-container *ngTemplateOutlet ="getMessageTemplate(message); context: {message: message, contact: contactsService.getContact(message.authorId), index: i}" >
</ng-container >
</ng-container >
</igx-list >
<div class ="chat-massage-field" >
<igx-input-group class ="chat-input-group" type ="box" >
<input class ="input-round-box" placeholder ="Send message" autocomplete ="off" igxInput #newMessage name ="newMessage"
[(ngModel )]="message" (keypress )="onMessageKeypress($event)" />
</igx-input-group >
<button class ="send-message-button" igxButton ="icon" igxButtonColor ="#09f" igxButtonBackground ="#fff"
igxRipple ="#09f" [igxRippleCentered ]="true" (click )="onSendButtonClick()" >
<igx-icon family ="material" > send</igx-icon >
</button >
</div >
</form >
</div >
html コピー .chat-sample-wrapper {
margin : 0 auto;
height : 100% ;
padding-bottom : 50px ;
}
.chat-sample__form {
display : flex;
flex-direction : column;
width : 100% ;
height : 100% ;
position : relative;
}
igx-icon {
cursor : pointer;
user-select: none;
}
.igx-input-group--border .igx-input-group__bundle ,
.igx-input-group--border .igx-input-group__bundle :hover ,
.igx-input-group--border .igx-input-group__bundle :focus ,
.igx-input-group--focused .igx-input-group--border .igx-input-group__bundle ,
.igx-input-group--focused ,
.igx-input-group__bundle :focus ,
.igx-input-group__bundle ,
.igx-input-group :focus
{
box-shadow : none;
outline : none;
}
.igx-input-group--border .igx-input-group__bundle {
padding : 4px 0 ;
}
.igx-list {
position : relative;
display : flex;
flex-flow : column nowrap;
background-color : #fff ;
height : 100% ;
overflow : auto;
z-index : 0 ;
flex : 1 0 0% ;
padding-bottom : 10px ;
}
.chat-massage-field {
display : flex;
align-items : center;
position : fixed;
left : 0 ;
right : 0 ;
bottom : 0 ;
width : 100% ;
padding : 0 8px ;
height : 50px ;
margin : 0 auto;
border-top : 1px solid #ddd ;
background : #fff ;
}
.chat-sample-wrapper {
.input-round-box {
transform : translateY(0 );
font-size : 14px ;
}
.igx-input-group__bundle-main {
padding : 0 ;
}
.chat-input-group {
flex : 1 0 0% ;
height : 40px ;
display : flex;
align-items : center;
}
.igx-input-group__wrapper {
flex : 1 ;
}
.igx-input-group--box .igx-input-group__bundle {
padding : 0 8px ;
}
}
.send-message-button {
margin-left : 8px ;
}
.igx-list__item-base :active ,
.igx-list__item-base {
padding : 0 ;
min-height : 36px ;
user-select: auto!important ;
}
.others-message ,
.my-message {
.igx-list__item-content {
font-weight : 600 ;
min-height : 16px ;
border-radius : 4px ;
margin : 0 0 4px 16px ;
padding : 4px 8px ;
font-size : 12px ;
font-weight : 300 ;
}
}
.igx-list__item-content {
padding : .5rem 0 ;
}
.others-message--first {
.igx-list__item-content {
border-top-left-radius : 0 ;
}
}
.my-message--first {
.igx-list__item-content {
border-top-right-radius : 0 ;
}
}
.others-message :active ,
.others-message {
.igx-list__item-content {
align-self : flex-start;
background-color : #09f ;
color : white;
}
}
.my-message :active ,
.my-message {
.igx-list__item-content {
align-self : flex-end;
background-color : rgb(240 , 240 , 240 );
}
}
.my-message {
.igx-list__item-content {
margin-right : 16px ;
}
}
.message__info {
margin-left : 10px ;
font-weight : 400 ;
}
.my-message__info {
margin-top : 20px ;
font-weight : 400 ;
text-align : right;
}
.contact :active {
background : transparent;
}
.contact {
margin : 20px 16px 5px 16px ;
}
.contact__panel {
display : flex;
align-items : center;
padding : 0 ;
}
@media only screen and (min-width : 960px ) {
.chat-sample-wrapper {
max-width : 400px ;
max-height : 600px ;
margin : 20px auto;
padding : 0 ;
border : 1px solid #ddd ;
box-shadow : 0 0 10px #999 ;
}
.chat-massage-field {
max-width : 400px ;
position : static;
padding-bottom : 0 ;
}
}
scss コピー
List コンポーネントにテーマの適用
以下は、リストの背景を変更する方法を説明します。まず、index.scss をコンポーネントの .scss ファイルにインポートします。
@use "igniteui-angular/theming" as *;
scss
最も簡単な方法は、list-theme
を拡張し、$background
パラメーターを受け入れる新しいテーマを作成する方法です。
$my-list-theme : list-theme(
$background : #0568ab
);
scss
リストのスタイル設定に使用できるパラメーターの完全なリストについては、list-theme
セクションを参照してください。
最後にコンポーネントのテーマを含めます 。
@include css-vars($my-list-theme );
scss
以下は上記コードの結果です。
import { NgModule } from "@angular/core" ;
import { FormsModule } from "@angular/forms" ;
import { BrowserModule } from "@angular/platform-browser" ;
import { BrowserAnimationsModule } from "@angular/platform-browser/animations" ;
import { AppComponent } from "./app.component" ;
import {
IgxToastModule,
IgxListModule,
IgxIconModule,
IgxAvatarModule
} from "igniteui-angular" ;
import { ListSample8Component } from "./list-sample-8/list-sample-8.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
ListSample8Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxToastModule,
IgxListModule,
IgxIconModule,
IgxAvatarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxListComponent, IgxToastComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-list-8' ,
styleUrls : ['./list-sample-8.component.scss' ],
templateUrl : './list-sample-8.component.html'
})
export class ListSample8Component implements OnInit {
@ViewChild ('toast' , { static : true })
public toast: IgxToastComponent;
@ViewChild ('mainIgxList' , { static : true })
public list: IgxListComponent;
public contacts;
private dataSource = [{
isFavorite : false ,
name : 'Terrance Orta' ,
phone : '770-504-2217' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/27.jpg'
}, {
isFavorite : true ,
name : 'Richard Mahoney' ,
phone : '423-676-2869' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/men/1.jpg'
}, {
isFavorite : false ,
name : 'Donna Price' ,
phone : '859-496-2817' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/50.jpg'
}, {
isFavorite : false ,
name : 'Lisa Landers' ,
phone : '901-747-3428' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/3.jpg'
}, {
isFavorite : true ,
name : 'Dorothy H. Spencer' ,
phone : '573-394-9254' ,
photo : 'https://www.infragistics.com/angular-demos-lob/assets/images/women/67.jpg'
}
];
constructor ( ) {
}
public ngOnInit ( ) {
this .contacts = Object .assign([], this .dataSource);
}
public toggleFavorite (contact: any ) {
contact.isFavorite = !contact.isFavorite;
}
}
ts コピー <div class ="list-sample" >
<igx-list >
<igx-list-item [isHeader ]="true" > Contacts</igx-list-item >
<igx-list-item #item *ngFor ="let contact of contacts" >
<igx-avatar igxListThumbnail [src ]="contact.photo" [roundShape ]="true" > </igx-avatar >
<span igxListLineTitle > {{ contact.name }}</span >
<span igxListLineSubTitle > {{ contact.phone }}</span >
<igx-icon igxListAction [style.color ]="contact.isFavorite ? 'orange' : 'lightgray'" (click )="toggleFavorite(contact)" > star</igx-icon >
</igx-list-item >
</igx-list >
</div >
html コピー @use '../../variables' as *;
:host ::ng-deep {
$my-list-theme : list-theme(
$background : #0568ab
);
@include css-vars($my-list-theme );
}
:host {
display : block;
padding : 16px ;
}
.list-sample {
box-shadow : elevation(2 );
}
igx-icon {
cursor : pointer;
}
scss コピー
リスト コンポーネントに変更できるパラメーターの完全なリストについては、IgxListComponent スタイル を参照してください。
API リファレンス
この記事では Angular List コンポーネントについて説明しました。アバターおよびアイコンの Ignite UI for Angular コンポーネントを使用して連絡先項目のリストを作成し、カスタム項目レイアウトを作成してスタイル設定、更にリスト フィルタリングを追加しました。以下は、List コンポーネントのその他の API です。
使用したその他の Angular コンポーネント:
テーマの依存関係
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。