React Dialog (ダイアログ) の概要
Ignite UI for React Dialog コンポーネントは、情報を表示したり、ユーザーにアクションや確認を促すために使用されます。これはモーダル ウィンドウに表示されます。つまり、ダイアログを閉じる特定のアクションが実行されるまで、ユーザーはメイン アプリを操作できません。
Ignite UI for React Dialog の例
このサンプルでは、React で Dialog コンポーネントを作成する方法を示します。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrButton, IgrDialog } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
export default class DialogOverview extends React.Component<any, any> {
public dialogRef: IgrDialog;
constructor(props: any) {
super(props);
this.onDialogRef = this.onDialogRef.bind(this);
this.onDialogShow = this.onDialogShow.bind(this);
this.onDialogHide = this.onDialogHide.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<IgrButton variant="contained" onClick={this.onDialogShow}>
<span>Show Dialog</span>
</IgrButton>
<IgrDialog title="Confirmation" ref={this.onDialogRef}>
<p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p>
<div slot="footer">
<IgrButton onClick={this.onDialogHide} variant="flat"><span>Cancel</span></IgrButton>
<IgrButton onClick={this.onDialogHide} variant="flat"><span>OK</span></IgrButton>
</div>
</IgrDialog>
</div>
);
}
public onDialogRef(dialog: IgrDialog){
if (!dialog) { return; }
this.dialogRef = dialog;
}
public onDialogShow() {
if(this.dialogRef){
this.dialogRef.show();
}
}
public onDialogHide() {
if(this.dialogRef){
this.dialogRef.hide();
}
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DialogOverview/>);
tsx
このサンプルが気に入りましたか? 完全な Ignite UI for Reactツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
使用方法
まず、次のコマンドを実行して、対応する Ignite UI for React npm パッケージをインストールする必要があります:
npm install igniteui-react
cmd
次に、以下のように、React IgrDialog
と必要な CSS をインポートする必要があります:
import { IgrDialog } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';
tsx
Ignite UI for React の完全な概要については、作業の開始トピックを参照してください。
Dialog コンポーネントを表示する最も簡単な方法は、show
メソッドを使用して、ボタン クリックで呼び出すことです。
<IgrButton variant="contained" clicked={this.onDialogShow}>
<span>Show Dialog</span>
</IgrButton>
<IgrDialog ref={this.onDialogRef}>
<span>Dialog Message</span>
</IgrDialog>
public onDialogRef(dialog: IgrDialog) {
if (!dialog) { return; }
this.dialogRef = dialog;
}
public onDialogShow() {
if (this.dialogRef) {
this.dialogRef.show();
}
}
tsx
Dialog コンポーネントは open
プロパティを提供します。これにより、アプリケーション シナリオに従ってその状態を構成できます。
Dialog のタイトルを設定するには、title
プロパティを使用します。ただし、title
スロットにコンテンツが指定されている場合は、プロパティよりも優先されます。
アクション ボタンまたは追加情報は、footer
スロットを介してダイアログの下部に配置できます。そこにコンテンツが追加されていない場合、デフォルトの OK
ボタンが表示され、クリックするとダイアログが閉じます。このボタンを表示したくない場合は、hideDefaultAction
プロパティを true に設定できます。デフォルト値は false です。
閉じる (Closing)
デフォルトでは、ユーザーが ESC
キーを押すと、ダイアログは自動的に閉じられます。keepOpenOnEscape
プロパティを使用して、この動作を防ぐことができます。デフォルト値は false です。ダイアログに開いているドロップダウン (または ESC
を内部で処理する必要があるその他の要素) がある場合、ESC
を 1 回押すとドロップダウンが閉じ、もう一度押すとダイアログが閉じます。
closeOnOutsideClick
プロパティを使用して、ダイアログの外側をクリックしたときにダイアログを閉じるかどうかを構成します。デフォルト値は false です。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrButton, IgrDialog, IgrSwitch } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
export default class DialogClosingVariations extends React.Component<any, any> {
public dialogRef: IgrDialog;
constructor(props: any) {
super(props);
this.onDialogRef = this.onDialogRef.bind(this);
this.onDialogShow = this.onDialogShow.bind(this);
this.onDialogHide = this.onDialogHide.bind(this);
this.onSwitchChangeEscape = this.onSwitchChangeEscape.bind(this);
this.onSwitchChangeClick = this.onSwitchChangeClick.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample">
<IgrSwitch labelPosition="before" onChange={this.onSwitchChangeEscape}><span>keepOpenOnEscape</span></IgrSwitch>
<IgrSwitch labelPosition="before" onChange={this.onSwitchChangeClick}><span>closeOnOutsideClick</span></IgrSwitch>
<IgrButton variant="contained" onClick={this.onDialogShow}>
<span>Show Dialog</span>
</IgrButton>
<IgrDialog title="Confirmation" ref={this.onDialogRef}>
<p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p>
<div slot="footer">
<IgrButton onClick={this.onDialogHide} variant="flat"><span>Cancel</span></IgrButton>
<IgrButton onClick={this.onDialogHide} variant="flat"><span>OK</span></IgrButton>
</div>
</IgrDialog>
</div>
);
}
public onDialogRef(dialog: IgrDialog){
if (!dialog) { return; }
this.dialogRef = dialog;
}
public onDialogShow() {
if(this.dialogRef){
this.dialogRef.show();
}
}
public onDialogHide() {
if(this.dialogRef){
this.dialogRef.hide();
}
}
public onSwitchChangeEscape(e: any) {
this.dialogRef.keepOpenOnEscape = e.detail.checked;
}
public onSwitchChangeClick(e: any) {
this.dialogRef.closeOnOutsideClick = e.detail.checked;
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DialogClosingVariations/>);
tsx
(フォーム)
属性 method="dialog"
がある場合、フォーム要素はダイアログを閉じることができます。フォームを送信すると、ダイアログが閉じられます。
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrButton, IgrDialog, IgrInput, IgrIcon,registerIconFromText } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
const usernameIconText = '<svg width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M15.71,12.71a6,6,0,1,0-7.42,0,10,10,0,0,0-6.22,8.18,1,1,0,0,0,2,.22,8,8,0,0,1,15.9,0,1,1,0,0,0,1,.89h.11a1,1,0,0,0,.88-1.1A10,10,0,0,0,15.71,12.71ZM12,12a4,4,0,1,1,4-4A4,4,0,0,1,12,12Z"/></svg>';
const passwordIconText = '<svg width="24px" height="24px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M13.0151 13.6556C14.8093 14.3587 16.9279 13.9853 18.3777 12.5355C20.3304 10.5829 20.3304 7.41709 18.3777 5.46447C16.4251 3.51184 13.2593 3.51184 11.3067 5.46447C9.85687 6.91426 9.48353 9.03288 10.1866 10.8271M12.9964 13.6742L6.82843 19.8422L4.2357 19.6065L4 17.0138L10.168 10.8458M15.5493 8.31568V8.29289" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
export default class DialogForm extends React.Component<any, any> {
public dialogRef: IgrDialog;
public passwordIcon: IgrIcon;
public usernameIcon: IgrIcon;
constructor(props: any) {
super(props);
this.onDialogRef = this.onDialogRef.bind(this);
this.onDialogShow = this.onDialogShow.bind(this);
registerIconFromText("username", usernameIconText, "material");
registerIconFromText("password", passwordIconText, "material");
}
public render(): JSX.Element {
return (
<div className="container sample center">
<IgrButton variant="contained" onClick={this.onDialogShow}>
<span>Show Dialog</span>
</IgrButton>
<IgrDialog title="Login" ref={this.onDialogRef}>
<form>
<IgrInput label="Username">
<span slot="prefix">
<IgrIcon name="username" collection="material"/>
</span>
</IgrInput>
<br />
<IgrInput type="password" label="Password">
<span slot="prefix">
<IgrIcon name="password" collection="material"/>
</span>
</IgrInput>
<br />
<div style={{display: "flex", justifyContent: "flex-end"}}>
<IgrButton type="reset" variant="flat"><span>Reset</span></IgrButton>
<IgrButton type="submit" variant="flat"><span>Submit</span></IgrButton>
</div>
</form>
<div slot="footer">
<IgrButton><span>Create an account</span></IgrButton>
</div>
</IgrDialog>
</div>
);
}
public onDialogRef(dialog: IgrDialog){
if (!dialog) { return; }
this.dialogRef = dialog;
}
public onDialogShow() {
if(this.dialogRef){
this.dialogRef.show();
}
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DialogForm/>);
tsx
スタイル設定
IgrDialog
コンポーネントはいくつかの CSS パーツを公開し、スタイルを完全に制御できるようにします。
名前 |
説明 |
base |
ダイアログの基本ラッパー。 |
title |
タイトルのコンテナー。 |
footer |
フッターのコンテナー。 |
content |
コンテンツのコンテナー。 |
igc-dialog::part(content) {
background: var(--ig-secondary-800);
color: var(--ig-secondary-800-contrast);
}
igc-dialog::part(title),
igc-dialog::part(footer) {
background: var(--ig-secondary-800);
color: var(--ig-warn-500);
}
css
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { IgrButton, IgrDialog } from "@infragistics/igniteui-react";
import 'igniteui-webcomponents/themes/light/bootstrap.css';
export default class DialogStyling extends React.Component<any, any> {
public dialogRef: IgrDialog;
constructor(props: any) {
super(props);
this.onDialogRef = this.onDialogRef.bind(this);
this.onDialogShow = this.onDialogShow.bind(this);
this.onDialogHide = this.onDialogHide.bind(this);
}
public render(): JSX.Element {
return (
<div className="container sample center">
<IgrButton variant="contained" onClick={this.onDialogShow}>
<span>Show Dialog</span>
</IgrButton>
<IgrDialog title="Confirmation" ref={this.onDialogRef}>
<h1 slot="title">Styled Title</h1>
<p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p>
<div slot="footer">
<IgrButton onClick={this.onDialogHide} variant="flat"><span>Cancel</span></IgrButton>
<IgrButton onClick={this.onDialogHide} variant="flat"><span>OK</span></IgrButton>
</div>
</IgrDialog>
</div>
);
}
public onDialogRef(dialog: IgrDialog){
if (!dialog) { return; }
this.dialogRef = dialog;
}
public onDialogShow() {
if(this.dialogRef){
this.dialogRef.show();
}
}
public onDialogHide() {
if(this.dialogRef){
this.dialogRef.hide();
}
}
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<DialogStyling/>);
tsx
igc-dialog::part(content) {
background: #011627;
color: white;
}
igc-dialog::part(title),
igc-dialog::part(footer) {
background: #011627;
color: #ECAA53;
}
css

API リファレンス
その他のリソース