Angular Calendar (カレンダー) コンポーネントの概要
Angular Calendar は、アプリで日付と曜日を表示するために使用される UI コンポーネントです。さまざまな機能をサポートしているため、ユーザーは簡単にカレンダー機能を管理したり、カレンダーにイベントをドラッグして作成したり、希望の日付に移動したり、Angular カレンダーの月表示、週表示、または日表示でイベントをシングル クリックで表示したりできます。
Ignite UI for Angular Calendar コンポーネントは、ネイティブ Angular コンポーネント (英語) であり、日付情報の表示、日付の有効化、または Angular カレンダー無効日付モードの適用を簡単かつ直感的に行う方法を提供します。ユーザーは、単一選択、複数選択、または範囲選択の 3 つの選択モードから選択できます。
Angular Calendar の例
Ignite UI for Angular Calendar パッケージを使用して、次の Angular Calendar の例を作成しました。基本的なカレンダーがどのように見えるか、ユーザーが 1 つの日付を選択して強調表示する方法、特定の日付に前後に移動する方法を簡単に示します。
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 {
IgxCalendarModule,
IgxDialogModule
} from "igniteui-angular" ;
import { CalendarSample5Component } from "./calendar-sample-5/calendar-sample-5.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample5Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxDialogModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-5.component.scss' ],
templateUrl : './calendar-sample-5.component.html'
})
export class CalendarSample5Component { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar > </igx-calendar >
</article >
html コピー @use '../../variables' as *;
$border-color : color($color : gray, $variant : 300 );
.calendar-wrapper {
max-width : 500px ;
min-width : 200px ;
border : 1px solid $border-color ;
border-radius : 6px ;
margin : 8px ;
}
.igx-calendar {
border-radius : 4px ;
}
scss コピー
このサンプルが気に入りましたか? 完全な Ignite UI for Angularツールキットにアクセスして、すばやく独自のアプリの作成を開始します。無料でダウンロードできます。
Ignite UI for Angular Calendar を使用した作業の開始
Ignite UI for Angular Calendar コンポーネントを使用した作業を開始するには、Ignite UI for Angular をインストールする必要があります。既存の Angular アプリケーションで、以下のコマンドを入力します。
ng add igniteui-angular
cmd
Ignite UI for Angular については、「はじめに 」トピックをご覧ください。
次に、app.module.ts ファイルに IgxCalendarModule
をインポートします。
...
import { HammerModule } from '@angular/platform-browser' ;
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
import { IgxCalendarModule } from 'igniteui-angular' ;
@NgModule ({
...
imports : [..., BrowserAnimationsModule, HammerModule, IgxCalendarModule],
...
})
export class AppModule {}
typescript
あるいは、16.0.0
以降、IgxCalendarComponent
をスタンドアロンの依存関係としてインポートすることも、IGX_CALENDAR_DIRECTIVES
トークンを使用してコンポーネントとそのすべてのサポート コンポーネントおよびディレクティブをインポートすることもできます。
import { HammerModule } from '@angular/platform-browser' ;
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ;
import { IGX_CALENDAR_DIRECTIVES } from 'igniteui-angular' ;
@Component ({
selector : 'app-home' ,
template : '<igx-calendar></igx-calendar>' ,
styleUrls : ['home.component.scss' ],
standalone : true ,
imports : [BrowserAnimationsModule, HammerModule, IGX_CALENDAR_DIRECTIVES]
})
export class HomeComponent {}
typescript
Ignite UI for Angular Calendar モジュールまたはディレクティブをインポートしたので、igx-calendar
コンポーネントの使用を開始できます。
Angular Calendar の使用
Angular 単一選択カレンダー
IgxCalendarComponent
をインスタンス化するには、セレクター要素をテンプレートに追加します。単一選択カレンダー モードで現在の月を表示します。
<igx-calendar > </igx-calendar >
html
Angular 複数選択カレンダー
selection
プロパティを使用してデフォルトのモードを簡単に変更できます。
<igx-calendar selection ="multi" [showWeekNumbers ]="true" > </igx-calendar >
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 { IgxCalendarModule } from "igniteui-angular" ;
import { CalendarSample1Component } from "./calendar-sample-1/calendar-sample-1.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample1Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-1.component.scss' ],
templateUrl : './calendar-sample-1.component.html'
})
export class CalendarSample1Component { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar selection ="multi" [showWeekNumbers ]="true" > </igx-calendar >
</article >
html コピー .calendar-wrapper {
max-width : 400px ;
min-width : 200px ;
margin : 8px ;
}
.igx-calendar {
box-shadow : 0 1px 3px 0 rgba(0 ,0 ,0 ,.26 ),
0 1px 1px 0 rgba(0 ,0 ,0 ,.12 ),
0 2px 1px -1px rgba(0 ,0 ,0 ,.08 );
}
scss コピー
Angular Calendar 範囲ピッカー
同じ方法に従って、範囲選択モードに切り替えることができます。
<igx-calendar selection ="range" > </igx-calendar >
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 {
IgxCalendarModule,
IgxSnackbarModule
} from "igniteui-angular" ;
import { CalendarSample8Component } from "./calendar-sample-8/calendar-sample-8.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample8Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxSnackbarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-8.component.scss' ],
templateUrl : './calendar-sample-8.component.html'
})
export class CalendarSample8Component { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar selection ="range" > </igx-calendar >
</article >
html コピー .calendar-wrapper {
max-width : 400px ;
min-width : 200px ;
margin : 8px ;
}
.igx-calendar {
box-shadow : 0 1px 3px 0 rgba(0 ,0 ,0 ,.26 ),
0 1px 1px 0 rgba(0 ,0 ,0 ,.12 ),
0 2px 1px -1px rgba(0 ,0 ,0 ,.08 );
}
scss コピー
選択が multi
または range
の場合、カレンダー ヘッダーは描画されません。
ローカライズおよび書式設定
カレンダーにおいてローカライズおよび書式設定はとても重要な要素です。IgxCalendarComponent
でこれらは以下のプロパティによって制御およびカスタマイズします - locale
、formatOptions
、formatViews
、weekStart
。
これらの設定に加え、IgxCalendarComponent API
のその他のカスタマイズ機能も使用できます。最初に週の開始日を制御する weekStart
を設定します。デフォルト値が 0 (日曜日) であるため、値を 1 (月曜日) に設定します。以下のマークアップで表示書式設定をカスタマイズするために、formatOptions
および formatViews
プロパティもバインドしています。最後に、locale
プロパティをユーザーの選択した場所に基づいて値にバインドします。
<igx-select #select [(ngModel )]="locale" >
<igx-select-item *ngFor ="let locale of locales" [value ]="locale" >
{{ locale }}
</igx-select-item >
</igx-select >
<igx-calendar #calendar
[weekStart ]="1"
[locale ]="locale"
[formatOptions ]="formatOptions"
[formatViews ]="formatViews" >
</igx-calendar >
html
すべてのプロパティ値が AppCоmponent ファイルに設定されます。
@ViewChild ('calendar' , { read : IgxCalendarComponent }) public calendar: IgxCalendarComponent;
public formatOptions: any ;
public formatViews: any ;
public locales = ['EN' , 'DE' , 'FR' , 'AR' , 'ZH' ];
public locale = 'EN' ;
public ngOnInit ( ) {
this .formatOptions = { day : '2-digit' , month : 'long' , weekday : 'long' , year : 'numeric' };
this .formatViews = { day : true , month : true , year : true };
}
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 {
IgxCalendarModule,
IgxPrefixModule,
IgxSelectModule
} from "igniteui-angular" ;
import { CalendarSample2Component } from "./calendar-sample-2/calendar-sample-2.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample2Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxPrefixModule,
IgxSelectModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
import { registerLocaleData } from '@angular/common' ;
import localeDE from '@angular/common/locales/de' ;
import localeFR from '@angular/common/locales/fr' ;
import localeAR from '@angular/common/locales/ar' ;
import localeZH from '@angular/common/locales/zh' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-2.component.scss' ],
templateUrl : './calendar-sample-2.component.html'
})
export class CalendarSample2Component implements OnInit {
@ViewChild ('calendar' , { read : IgxCalendarComponent }) public calendar: IgxCalendarComponent;
public formatOptions: any ;
public formatViews: any ;
public locales = ['EN' , 'DE' , 'FR' , 'AR' , 'ZH' ];
public locale = 'EN' ;
public ngOnInit ( ) {
this .formatOptions = { day : '2-digit' , month : 'long' , weekday : 'long' , year : 'numeric' };
this .formatViews = { day : true , month : true , year : true };
registerLocaleData(localeDE);
registerLocaleData(localeFR);
registerLocaleData(localeAR);
registerLocaleData(localeZH);
}
}
ts コピー <article class ="sample-column location-wrapper" >
<igx-select #select [(ngModel )]="locale" >
<igx-prefix > Location: </igx-prefix >
<igx-select-item *ngFor ="let locale of locales" [value ]="locale" >
{{ locale }}
</igx-select-item >
</igx-select >
</article >
<article class ="sample-column calendar-wrapper" >
<igx-calendar
#calendar
[locale ]="locale"
[weekStart ]="1"
[formatOptions ]="formatOptions"
[formatViews ]="formatViews"
>
</igx-calendar >
</article >
html コピー @use '../../variables' as *;
.calendar-wrapper {
max-width : 650px ;
min-width : 300px ;
margin : 8px ;
border : 1px solid color($color : 'gray' , $variant : 300 );
border-radius : 6px ;
}
.location-wrapper {
min-width : 200px ;
max-width : 640px ;
margin-bottom : 32px ;
}
scss コピー
Angular Calendar で日付を無効にする方法
このセクションは、disabledDates
機能の使用について説明します。これには、異なる単一の日付または範囲を配列に追加し、disabledDates
記述子に渡すことができます。
DateRangeType
は無効にする範囲を指定するために使用します。
現在の月の 3 日から 8 日の日付を無効にするサンプルを作成します。
export class CalendarSample6Component {
@ViewChild ('calendar' ) public calendar: IgxCalendarComponent;
public today = new Date (Date .now());
public range = [
new Date (this .today.getFullYear(), this .today.getMonth(), 3 ),
new Date (this .today.getFullYear(), this .today.getMonth(), 8 )
];
public ngOnInit ( ) {
this .calendar.disabledDates = [{ type : DateRangeType.Between, dateRange : this .range }];
}
}
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 { IgxCalendarModule } from "igniteui-angular" ;
import { CalendarSample6Component } from "./calendar-sample-6/calendar-sample-6.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample6Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, OnInit, ViewChild } from '@angular/core' ;
import { DateRangeType, IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-6.component.scss' ],
templateUrl : './calendar-sample-6.component.html'
})
export class CalendarSample6Component implements OnInit {
@ViewChild ('calendar' , { static : true }) public calendar: IgxCalendarComponent;
public today = new Date (Date .now());
public range = [
new Date (this .today.getFullYear(), this .today.getMonth(), 3 ),
new Date (this .today.getFullYear(), this .today.getMonth(), 8 )
];
public ngOnInit ( ) {
this .calendar.disabledDates = [{ type : DateRangeType.Between, dateRange : this .range }];
}
}
ts コピー <article class ="sample-column calendar-wrapper" >
<div class ="info" >
<span > Disabled dates range from <b > {{ range[0] | date }}</b > to <b > {{ range[1] | date }}</b > </span >
</div >
<igx-calendar #calendar weekstart ="1" [selection ]="'multi'" >
</igx-calendar >
</article >
html コピー .calendar-wrapper {
max-width : 700px ;
min-width : 200px ;
margin : 8px ;
box-shadow : 0 1px 3px 0 rgba(0 ,0 ,0 ,.26 ),
0 1px 1px 0 rgba(0 ,0 ,0 ,.12 ),
0 2px 1px -1px rgba(0 ,0 ,0 ,.08 );
}
.info {
display : flex;
justify-content : center;
background : hsla(var(--ig-surface-500 ));
}
.info > span {
color : var(--ig-secondary-400 );
font-weight : 600 ;
font-size : 0.875rem ;
letter-spacing : 0.046875rem ;
text-transform : uppercase;
line-height : 1rem ;
margin : 16px ;
}
scss コピー
特別な日付
specialDates
機能は、disabledDates
とほとんど同じ構成を使用します。disabled
と異なる点は specialDates
を選択してフォーカスする機能です。
igxCalendar
に specialDates
を追加します。これを行うには、DateRangeType.Specific
タイプの DateRangeDescriptor
項目を作成し、日付の配列を dateRange
として渡します。
export class CalendarSample7Component {
@ViewChild ('calendar' , { static : true })
public calendar: IgxCalendarComponent;
@ViewChild ('alert' , { static : true })
public dialog: IgxDialogComponent;
public range = [];
public selectPTOdays (dates: Date [] ) {
this .range = dates;
}
public submitPTOdays (eventArgs ) {
this .calendar.specialDates =
[{ type : DateRangeType.Specific, dateRange : this .range }];
this .range.forEach((item ) => {
this .calendar.selectDate(item);
});
...
}
}
typescript
<igx-calendar #calendar weekStart ="1"
selection ="multi"
(selected )="selectPTOdays($event)" >
</igx-calendar >
<igx-dialog #alert title ="Request Time Off"
leftButtonLabel ="OK"
(leftButtonSelect )="alert.close()" >
</igx-dialog >
<button igxButton ="contained" (click )="submitPTOdays($event)" > Submit Request</button >
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 {
IgxButtonModule,
IgxCalendarModule,
IgxDialogModule
} from "igniteui-angular" ;
import { CalendarSample7Component } from "./calendar-sample-7/calendar-sample-7.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample7Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxCalendarModule,
IgxDialogModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, ViewChild } from '@angular/core' ;
import { DateRangeType, IgxCalendarComponent, IgxDialogComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-7.component.scss' ],
templateUrl : './calendar-sample-7.component.html'
})
export class CalendarSample7Component {
@ViewChild ('calendar' , { static : true }) public calendar: IgxCalendarComponent;
@ViewChild ('alert' , { static : true }) public dialog: IgxDialogComponent;
public range = [];
public selectPTOdays (dates: Date | Date [] ) {
this .range = dates as Date [];
}
public submitPTOdays ( ) {
this .calendar.specialDates =
[{ type : DateRangeType.Specific, dateRange : this .range }];
this .range.forEach((item ) => {
this .calendar.selectDate(item);
});
if (this .range.length === 0 ) {
this .dialog.message = 'Select dates from the Calendar first.' ;
} else {
this .dialog.message = 'PTO days submitted.' ;
}
this .dialog.open();
}
}
ts コピー <article class ="sample-column calendar-wrapper" >
<igx-calendar #calendar [weekStart ]="1" selection ="multi" (selected )="selectPTOdays($event)" >
</igx-calendar >
<igx-dialog #alert title ="Request Time Off" leftButtonLabel ="OK" (leftButtonSelect )="alert.close()" >
</igx-dialog >
<button igxButton ="raised" (click )="submitPTOdays()" > Submit Request</button >
</article >
html コピー .calendar-wrapper {
max-width : 700px ;
min-width : 200px ;
margin : 8px ;
box-shadow : 0 1px 3px 0 rgba(0 , 0 , 0 , 0.26 ),
0 1px 1px 0 rgba(0 , 0 , 0 , 0.12 ),
0 2px 1px -1px rgba(0 , 0 , 0 , 0.08 );
}
.igx-calendar {
border-radius : 0 ;
}
.igx-button--raised {
border-radius : 0 ;
}
scss コピー
週番号
showWeekNumbers
入力を使用して、Calendar コンポーネント と DatePicker コンポーネントの両方の週番号を表示できるようになりました。
<igx-calendar selection ="multi" [showWeekNumbers ]="true" > </igx-calendar >
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 { IgxCalendarModule } from "igniteui-angular" ;
import { CalendarSample1Component } from "./calendar-sample-1/calendar-sample-1.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample1Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-1.component.scss' ],
templateUrl : './calendar-sample-1.component.html'
})
export class CalendarSample1Component { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar selection ="multi" [showWeekNumbers ]="true" > </igx-calendar >
</article >
html コピー .calendar-wrapper {
max-width : 400px ;
min-width : 200px ;
margin : 8px ;
}
.igx-calendar {
box-shadow : 0 1px 3px 0 rgba(0 ,0 ,0 ,.26 ),
0 1px 1px 0 rgba(0 ,0 ,0 ,.12 ),
0 2px 1px -1px rgba(0 ,0 ,0 ,.08 );
}
scss コピー
カレンダー イベント
カレンダーが発するイベントを見てみましょう:
<igx-calendar #calendar
(selected )="onSelection($event)"
(viewDateChanged )="viewDateChanged($event)"
(activeViewChanged )="activeViewChanged($event)" >
</igx-calendar >
html
selected
イベントは、入力検証ロジックを構築するのに適しています。以下のコードを使用して、選択が 5 日を超えた場合にユーザーに警告し、選択をリセットします。
...
public onSelection (dates: Date [] ) {
if (dates.length > 5 ) {
this .calendar.selectedDates = [];
}
}
public viewDateChanged (event: IViewDateChangeEventArgs ) {
}
public activeViewChanged (event: CalendarView ) {
}
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 {
IgxCalendarModule,
IgxDialogModule
} from "igniteui-angular" ;
import { CalendarSample3Component } from "./calendar-sample-3/calendar-sample-3.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarSample3Component
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxDialogModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent, IgxDialogComponent, IgxCalendarView } from 'igniteui-angular' ;
import { IViewDateChangeEventArgs } from 'igniteui-angular/lib/calendar/calendar-base' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-3.component.scss' ],
templateUrl : './calendar-sample-3.component.html'
})
export class CalendarSample3Component {
@ViewChild ('calendar' , { static : true }) public calendar: IgxCalendarComponent;
@ViewChild ('alert' , { static : true }) public dialog: IgxDialogComponent;
public loggerHeader = `Interact with the calendar to see the events logged here in sequence:` ;
public onSelection (dates: Date | Date [] ) {
const logger: HTMLElement = document .querySelector('.logger' );
dates = dates as Date [];
logger.innerHTML = `<span> => 'onSelectionChanged': ${dates.length} dates selected.<br>${logger.innerHTML} ` ;
}
public viewDateChanged (event: IViewDateChangeEventArgs ) {
const logger: HTMLElement = document .querySelector('.logger' );
const eventArgs = `event.previousValue: ${this .parseDate(event.previousValue)} | event.currentValue: ${this .parseDate(event.currentValue)} ` ;
logger.innerHTML = `<span> => 'viewDateChanged': ${eventArgs} </span><br>${logger.innerHTML} ` ;
}
public activeViewChanged (event: IgxCalendarView ) {
const logger: HTMLElement = document .querySelector('.logger' );
logger.innerHTML = `<span> => 'activeViewChanged':. Active view is: ${IgxCalendarView[event]} </span><br>${logger.innerHTML} ` ;
}
private parseDate (date: Date ) {
const monthFormatter = new Intl .DateTimeFormat('en' , { month : 'long' });
return `${monthFormatter.format(date)} ${date.getFullYear()} ` ;
}
}
ts コピー <div class ="calendar-section" >
<article class ="calendar-wrapper" >
<igx-calendar #calendar selection ="multi" (selected )="onSelection($event)" (viewDateChanged )="viewDateChanged($event)" (activeViewChanged )="activeViewChanged($event)" > </igx-calendar >
</article >
</div >
<div class ="calendar-section" style ="width: calc(100% - 324px)" >
<div class ="selected-data-area" >
<div class ="logContainer" >
<div class ="highlight" >
<span > {{loggerHeader}}</span >
</div >
<div class ="logger" > </div >
</div >
</div >
</div >
html コピー .igx-calendar {
box-shadow : 0 1px 3px 0 rgba(0 ,0 ,0 ,.26 ),
0 1px 1px 0 rgba(0 ,0 ,0 ,.12 ),
0 2px 1px -1px rgba(0 ,0 ,0 ,.08 );
}
:host {
display : flex;
width : 100% ;
flex-flow : row wrap;
}
button {
margin : 8px 0px ;
}
.calendar-wrapper {
width : 300px ;
margin : 8px ;
}
.calendar-section {
height : 383px ;
}
.selected-data-area {
overflow-y : auto;
max-height : 500px ;
width : 100% ;
height : 100% ;
box-shadow : 0 1px 3px 0 rgba(0 , 0 , 0 , 0.2 ), 0 1px 1px 0 rgba(0 , 0 , 0 , 0.14 ), 0 2px 1px -1px rgba(0 , 0 , 0 , 0.12 );
margin-top : 8px ;
}
.logContainer {
padding : 0.2rem 0.4rem ;
}
.highlight {
background-color : rgba(0 ,153 ,255 , 0.1 );
margin-bottom : 0.4rem ;
}
scss コピー
Angular Calendar ビュー
IgxCalendarModule
によって提供される個別のビューがあり、別々に使用できます。
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 {
IgxCalendarModule,
IgxCardModule
} from "igniteui-angular" ;
import { CalendarDaysViewComponent } from "./calendar-days-view/calendar-days-view.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarDaysViewComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxCardModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-days-view.component.scss' ],
templateUrl : './calendar-days-view.component.html'
})
export class CalendarDaysViewComponent { }
ts コピー <igx-card >
<igx-card-header >
<h5 class ="igx-card-header__title" > Days View</h5 >
</igx-card-header >
<igx-card-content >
<igx-days-view [selection ]="'single'" > </igx-days-view >
</igx-card-content >
</igx-card >
html コピー .igx-card {
max-width : 500px ;
min-width : 200px ;
margin : 8px ;
}
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 {
IgxCalendarModule,
IgxCardModule
} from "igniteui-angular" ;
import { CalendarMonthsViewComponent } from "./calendar-months-view/calendar-months-view.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarMonthsViewComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxCardModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-months-view.component.scss' ],
templateUrl : './calendar-months-view.component.html'
})
export class CalendarMonthsViewComponent { }
ts コピー <igx-card >
<igx-card-header >
<h5 class ="igx-card-header__title" > Months View</h5 >
</igx-card-header >
<igx-card-content >
<igx-months-view > </igx-months-view >
</igx-card-content >
</igx-card >
html コピー .igx-card {
max-width : 500px ;
min-width : 200px ;
margin : 8px ;
}
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 {
IgxCalendarModule,
IgxCardModule
} from "igniteui-angular" ;
import { CalendarYearsViewComponent } from "./calendar-years-view/calendar-years-view.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarYearsViewComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule,
IgxCardModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-years-view.component.scss' ],
templateUrl : './calendar-years-view.component.html'
})
export class CalendarYearsViewComponent { }
ts コピー <igx-card >
<igx-card-header >
<h5 class ="igx-card-header__title" > Years View</h5 >
</igx-card-header >
<igx-card-content >
<igx-years-view > </igx-years-view >
</igx-card-content >
</igx-card >
html コピー .igx-card {
max-width : 500px ;
min-width : 200px ;
margin : 8px ;
}
scss コピー
キーボード ナビゲーション
Tab キーを使用してページを移動する場合、igxCalendarComponent が W3 アクセシビリティ推奨事項 に基づいて以下のタブストップを導入することに注意してください。
[前月] ボタン
[月の選択] ボタン
[年の選択] ボタン
[翌月] ボタン
日ビューの選択した日付、現在の日付、最初のフォーカス可能な (無効ではない) 日付
複数の選択された日付を含む Angular Calendar では、最初の日付のみがタブ位置として導入されます。たとえば、Angular Calendar の複数選択が有効で、日付を選択した場合: 2020 年 10 月 13 日 、2020 年 10 月 17 日 および 2020 年 10 月 21 日 のみは、タブ ナビゲーション中にアクセスできます。Angular Calendar 範囲ピッカーでは、選択した範囲の最初の日付のみがページ タブ シーケンスの一部になります。
V10.2.0 からの動作変更- 日ビューの Tab キー ナビゲーションは使用できなくなりました。日付ビューの日付間を移動するには、矢印キーを使用します。
igxCalendar
コンポーネントにフォーカスがある場合、以下を使用してナビゲーションできます。
PageUp キーは前の月に移動します。
PageDown キーは次の月に移動します。
Shift + PageUp キーは前の年に移動します。
Shift + PageDown > キーは次の年に移動します。
Home キーは現在の年の最初の月をフォーカスします。
End キーは現在の月の最後の日または最後の月をフォーカスします。
前
または次
の月のボタン(サブヘッダー内)にフォーカスがある場合、以下を使用します。
Space または Enter キーは次の月または前の月のビューへスクロールします。
サブヘッダーの月
ボタンのフォーカス時:
Space または Enter キーは月ビューを開きます。
サブヘッダーの年
ボタンのフォーカス時:
Space または Enter キーは10 年ビューを開きます。
現在月の日
がフォーカスされる場合:
矢印キーで日を移動します。注: 無効な日付はスキップされます。
フォーカスはビューの現在の月に保持され、ナビゲーションは月の最終日 / 初日 から / まで になります。
キーボード ナビゲーションは連続です。つまり、矢印でナビゲーションしている間、すべての月を移動します。
Enter キー を使用して、現在フォーカスされている日を選択します。
月ビュー内の月
のフォーカス時:
矢印キーで月を移動します。
Home キーは月ビューの最初の月にフォーカスします。
End キーは月ビューの最後の月にフォーカスします。
Enter キーは、現在フォーカスされている月を選択してビューと閉じます。
10 年ビュー内の年
のフォーカス時:
上矢印 キーと 下矢印 キーで年を移動します。
Enter キーは、現在フォーカスされている年を選択してビューと閉じます。
バージョン 8.2.0 に続いて、キーボード ナビゲーションは現在の月以外の日をフォーカスせず、ビューの月を変更します。
マルチビュー カレンダー
マルチ ビューカレンダーは、3 種類すべての選択をサポートしています。monthsViewNumber
入力を使用して、表示される月の数を設定します。これは、フレックス コンテナーに水平に表示されます。設定される最大値に制限はありません。マルチ ビューカレンダーを使用する場合、現在の月に属さない日を非表示にできます。非表示にするには、hideOutsideDays
プ ロパティを使用します。キーボード ナビゲーションは、表示されている次/前の月へ移動します。
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,
IgxCalendarModule,
IgxDialogModule
} from "igniteui-angular" ;
import { CalendarMultiViewComponent } from "./multiview/multiview.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarMultiViewComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxButtonModule,
IgxCalendarModule,
IgxDialogModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent, IgxDialogComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./multiview.component.scss' ],
templateUrl : './multiview.component.html'
})
export class CalendarMultiViewComponent {
@ViewChild ('calendar' , { static : true }) public calendar: IgxCalendarComponent;
@ViewChild ('alert' , { static : true }) public dialog: IgxDialogComponent;
public range = [];
public selectDates (dates: Date | Date [] ) {
this .range = dates as Date [];
}
public submitDates ( ) {
if (this .range.length < 2 ) {
this .dialog.message = 'Select dates from the Calendar first.' ;
} else {
this .dialog.message = 'Request for your stay has been submitted !' ;
}
this .dialog.open();
}
public formatDate(date: Date ): string {
return this .getDatePart(date, this .calendar, 'weekday' ) + ' ' +
this .getDatePart(date, this .calendar, 'day' ) + ' ' +
this .getDatePart(date, this .calendar, 'month' );
}
public getDatePart (val: any , component: any , datePart: string ) {
const date = val as Date ;
const locale = component.locale;
const formatOptions: Intl .DateTimeFormatOptions = {};
formatOptions[datePart] = component.formatOptions[datePart];
return date.toLocaleString(locale, formatOptions);
}
get action () {
return this .range.length < 1 ? 'CHECK-IN' : 'CHECK-OUT' ;
}
get checkin () {
const checkin = this .range[0 ];
return this .formatDate(checkin);
}
get checkout () {
const checkin = this .range[this .range.length - 1 ];
return this .formatDate(checkin);
}
}
ts コピー <article class ="sample-column calendar-wrapper" >
<div class ="stay__info" >
<span *ngIf ="range.length <= 1" > {{ action }}</span >
<span *ngIf ="range.length > 1" > {{ checkin }} - {{ checkout }} ({{ this.range.length - 1 }} nights stay)</span >
</div >
<igx-calendar #calendar selection ="range" [monthsViewNumber ]="2" [hideOutsideDays ]="true"
(selected )="selectDates($event)" >
</igx-calendar >
<igx-dialog #alert title ="Availability" leftButtonLabel ="OK" (leftButtonSelect )="alert.close()" >
</igx-dialog >
<button igxButton ="raised" (click )="submitDates()" > Check Availability</button >
</article >
html コピー .calendar-wrapper {
max-width : 900px ;
min-width : 200px ;
margin : 8px ;
box-shadow : 0 1px 3px 0 rgba(0 , 0 , 0 , 0.26 ),
0 1px 1px 0 rgba(0 , 0 , 0 , 0.12 ),
0 2px 1px -1px rgba(0 , 0 , 0 , 0.08 );
}
.igx-calendar {
border-radius : 0 ;
}
.igx-button--raised {
border-radius : 0 ;
}
.stay__info {
display : flex;
justify-content : center;
background : hsla(var(--ig-surface-500 ));
}
.stay__info > span {
color : var(--ig-secondary-400 );
font-weight : 600 ;
font-size : 0.875rem ;
letter-spacing : 0.046875rem ;
text-transform : uppercase;
line-height : 1rem ;
margin : 16px ;
}
scss コピー
カレンダーの方向
方向の設定により、ユーザーはカレンダーのヘッダーとビューの表示方法を選択できます。
ヘッダーの方向オプション
ヘッダーの方向を変更して、カレンダーのヘッダーを水平 (カレンダー ビューの上) または垂直 (カレンダー ビューの横) に配置できます。
これを行うには、[headerOrientation]
プロパティを使用し、それぞれ horizontal
または vertical
に設定します。
ビューの方向オプション
ビューの方向を設定して、カレンダー内の月を水平 (並べて) または垂直 (上下に) に配置できます。
これを行うには、[orientation]
プロパティを使用して、それぞれ horizontal
または vertical
に設定します。
そのプロパティが機能していることを確認するには、少なくとも 2 か月分のビュー カレンダーが必要です。
<igx-calendar [monthsViewNumber ]="2" [headerOrientation ]="headerOrientation" [orientation ]="orientation" > </igx-calendar >
html
const orientations = ["horizontal" , "vertical" ] as const ;
type Orientation = (typeof orientations)[number ];
export class CalendarSample9Component {
protected orientations = Array .from(orientations, (o ) => o);
protected headerOrientation: Orientation = "horizontal" ;
protected orientation: Orientation = "horizontal" ;
protected setHeaderOrientation (orientation: Orientation ) {
this .headerOrientation = orientation;
}
protected setOrientation (orientation: Orientation ) {
this .orientation = orientation;
}
}
typescript
スタイル設定
カレンダーのスタイル設定を開始するには、すべてのテーマ関数とコンポーネント ミックスインが存在する index
ファイルをインポートする必要があります。
@use "igniteui-angular/theming" as *;
scss
最も簡単な方法は、calendar-theme
を拡張する新しいテーマを作成し、デフォルト テーマのいくつかのパラメーターを受け取る方法です。
$custom-calendar-theme : calendar-theme(
$header-background : #345779 ,
$content-background : #fdfdfd ,
$header-foreground : #ffffff ,
$date-current-foreground : #2dabe8 ,
$navigation-color : #2dabe8 ,
$date-selected-foreground : #fdfdfd ,
$date-current-background : #fdfdfd ,
$navigation-hover-color : #345779 ,
$ym-current-foreground : #2dabe8 ,
$ym-hover-foreground : #2dabe8 ,
$picker-foreground : #2dabe8 ,
$picker-hover-foreground : #345779 ,
);
scss
最後に calendar のカスタム テーマを設定します。
@include css-vars($custom-calendar-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 { IgxCalendarModule } from "igniteui-angular" ;
import { CalendarStylingSampleComponent } from "./calendar-styling-sample/calendar-styling-sample.component" ;
@NgModule ({
bootstrap : [AppComponent],
declarations : [
AppComponent,
CalendarStylingSampleComponent
],
imports : [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
IgxCalendarModule
],
providers : [],
entryComponents : [],
schemas : []
})
export class AppModule {}
ts コピー import { Component } from '@angular/core' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-styling-sample.component.scss' ],
templateUrl : './calendar-styling-sample.component.html'
})
export class CalendarStylingSampleComponent { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar [weekStart ]="1" > </igx-calendar >
</article >
html コピー @use '../../variables' as *;
.calendar-wrapper {
max-width : 600px ;
min-width : 200px ;
margin : 8px ;
}
.igx-calendar {
box-shadow : elevation(4 );
}
$custom-calendar-theme : calendar-theme(
$header-background : #345779 ,
$content-background : #fdfdfd ,
$header-text-color : #ffffff ,
$date-current-text-color : #2dabe8 ,
$picker-arrow-color : #2dabe8 ,
$date-selected-text-color : #fdfdfd ,
$date-current-bg-color : #fdfdfd ,
$picker-arrow-hover-color : #345779 ,
$year-current-text-color : #2dabe8 ,
$year-hover-text-color : #2dabe8 ,
$month-current-text-color : #2dabe8 ,
$month-hover-text-color : #2dabe8 ,
$picker-text-color : #2dabe8 ,
$picker-text-hover-color : #345779 ,
);
:host {
@include css-vars($custom-calendar-theme );
}
scss コピー
API リファレンス
その他のリソース
コミュニティに参加して新しいアイデアをご提案ください。