Web Components コンボボックスのテンプレート
Ignite UI for Web Components コンボボックス コンポーネントを使用すると、項目、グループ ヘッダー、空のリスト、アイコンなど、さまざまな領域のカスタム テンプレートを定義できます。
コンボボックス テンプレートの例
import { defineComponents, registerIconFromText, IgcComboComponent, ComboItemTemplate } from "igniteui-webcomponents" ;
import { html } from "lit-html" ;
import "igniteui-webcomponents/themes/light/bootstrap.css" ;
import "./index.css" ;
interface City {
id : string ;
name: string ;
country: string ;
}
const cities: City[] = [
{ name : "London" , id : "UK01" , country : "UK" },
{ name : "Manchester" , id : "UK02" , country : "UK" },
{ name : "Birmingham" , id : "UK03" , country : "UK" },
{ name : "Glasgow" , id : "UK04" , country : "UK" },
{ name : "Liverpool" , id : "UK05" , country : "UK" },
{ name : "New York" , id : "US01" , country : "USA" },
{ name : "Miami" , id : "US02" , country : "USA" },
{ name : "Philadelphia" , id : "US03" , country : "USA" },
{ name : "Chicago" , id : "US04" , country : "USA" },
{ name : "Springfield" , id : "US05" , country : "USA" },
{ name : "Los Angeles" , id : "US06" , country : "USA" },
{ name : "Houston" , id : "US07" , country : "USA" },
{ name : "Phoenix" , id : "US08" , country : "USA" },
{ name : "San Diego" , id : "US09" , country : "USA" },
{ name : "Dallas" , id : "US010" , country : "USA" },
{ name : "Sofia" , id : "BG01" , country : "Bulgaria" },
{ name : "Plovdiv" , id : "BG02" , country : "Bulgaria" },
{ name : "Varna" , id : "BG03" , country : "Bulgaria" },
{ name : "Burgas" , id : "BG04" , country : "Bulgaria" },
{ name : "Rome" , id : "IT01" , country : "Italy" },
{ name : "Milan" , id : "IT02" , country : "Italy" },
{ name : "Naples" , id : "IT03" , country : "Italy" },
{ name : "Turin" , id : "IT04" , country : "Italy" },
{ name : "Palermo" , id : "IT05" , country : "Italy" },
{ name : "Florence" , id : "IT06" , country : "Italy" }
];
const toggleIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>' ;
const clearIcon = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>' ;
defineComponents(IgcComboComponent);
export class ComboTemplates {
private combo: IgcComboComponent<City>;
protected itemTemplate: ComboItemTemplate<City> = ({ item } ) => {
return html` <span > <b > ${item.name} </b > [${item.id} ]</span > ` ;
};
protected groupHeaderTemplate: ComboItemTemplate<City> = ({ item } ) => {
return html`<span > Country of ${item.country} </span > ` ;
};
constructor ( ) {
registerIconFromText("clear" , clearIcon);
registerIconFromText("down" , toggleIcon);
this .combo = document .getElementById("combo" ) as IgcComboComponent<City>;
this .combo.data = cities;
this .combo.itemTemplate = this .itemTemplate;
this .combo.groupHeaderTemplate = this .groupHeaderTemplate;
}
}
new ComboTemplates();
ts コピー <!DOCTYPE html >
<html >
<head >
<title > Combo Templates</title >
<meta charset ="UTF-8" />
<link rel ="stylesheet" href ="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" type ="text/css" />
<link href ="https://static.infragistics.com/xplatform/css/samples/custom-legend.css" rel ="stylesheet" type ="text/css" />
</head >
<body >
<div id ="root" >
<div class ="container sample center" >
<igc-combo
id ="combo"
value-key ="id"
display-key ="name"
group-key ="country"
>
<header slot ="header" >
Header content goes here
</header >
<igc-icon name ="clear" slot ="clear-icon" > </igc-icon >
<igc-icon name ="down" slot ="toggle-icon" > </igc-icon >
<span slot ="empty" > ¯\_(ツ)_/¯</span >
<footer slot ="footer" >
Footer content goes here
</footer >
</igc-combo >
</div >
</div >
<% if (false) { %><script src ="src/index.ts" > </script > <% } %>
</body >
</html >
html コピー
igc-combo::part (header ),
igc-combo::part (footer ) {
padding : 12px 8px ;
text-align : center;
}
igc-combo::part (empty) {
font-size : 16px ;
}
css コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Web Componentsツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
テンプレート タイプ
Item Template (項目テンプレート)
itemTemplate
はカスタム テンプレートであり、定義されている場合は、オプションのリスト内の項目を描画するときに使用する必要があります。
import { ComboItemTemplate } from 'igniteui-webcomponents' ;
const itemTemplate: ComboItemTemplate<City> = ({ item } ) => {
return html`
<span > <b > ${item.name} </b > [${item.id} ]</span >
` ;
};
combo.itemTempate = itemTemplate;
ts
groupHeaderTemplate
はカスタム テンプレートであり、定義されている場合は、オプションのリストでグループ ヘッダーを描画するときに使用する必要があります。
import { ComboItemTemplate } from 'igniteui-webcomponents' ;
const groupHeaderTemplate: ComboItemTemplate<City> = ({ item } ) => {
return html`<div > Country of ${item.country} </div > ` ;
};
combo.groupHeaderTemplate = groupHeaderTemplate;
ts
スロット
カスタム テンプレート以外に、Ignite UI for Web Components コンボボックス コンポーネントは、ユーザーがカスタム コンテンツをさまざまなコンボ パーツに渡すことを可能にするいくつかのスロットを公開します。
ヘッダー スロット
オプションのリストの上にカスタム ヘッダーをレンダリングするには、コンテンツを header
スロットに渡します。
<igc-combo >
<div slot ="header" > Custom header content</div >
</igc-combo >
html
フッター スロット
オプションのリストの下にカスタム フッターをレンダリングするには、コンテンツを footer
スロットに渡します。
<igc-combo >
<div slot ="footer" > Custom footer content</div >
</igc-combo >
html
空のリスト スロット
フィルタリング操作で結果が返されない場合にカスタム コンテンツをレンダリングするには、empty
スロットを使用します。
<igc-combo >
<div slot ="empty" > ¯\_(ツ)_/¯</div >
</igc-combo >
html
トグル アイコン スロット
コンボ入力のトグル アイコンは、toggle-icon
スロットを介して変更することもできます。
<igc-combo >
<igc-icon name ="down" slot ="toggle-icon" > </igc-icon >
</igc-combo >
html
クリア アイコン スロット
クリア アイコンは、clear-icon
スロットを介して変更できます。
<igc-combo >
<igc-icon name ="clear" slot ="clear-icon" > </igc-icon >
</igc-combo >
html
API リファレンス
その他のリソース