Angular Calendar 구성 요소 개요
Angular Calendar는 앱에서 날짜와 요일을 표시하는 데 사용되는 UI 구성 요소입니다. 다양한 기능을 지원하여 사용자가 캘린더 기능을 쉽게 관리하고, 캘린더에서 이벤트를 끌어서 만들고, 캘린더에서 원하는 날짜로 이동하고, 한 번의 클릭으로 Angular 캘린더 월별 보기, 주별 보기 또는 일별 보기에서 이벤트를 표시할 수 있습니다.
기본 Angular 구성 요소 로 개발된 Ignite UI for Angular Calendar 구성 요소는 날짜 정보를 표시하거나, 날짜를 활성화하거나, 달력 비활성화 날짜 모드를 적용 Angular 쉽고 직관적인 방법을 제공합니다. 사용자는 단일 선택, 다중 선택 또는 범위 선택의 세 가지 선택 모드 중에서 선택할 수 있습니다.
Angular 달력 예
Ignite UI for Angular Calendar 패키지를 사용하여 다음 Angular Calendar 예제를 만들었습니다. 기본 달력이 어떻게 보이고 느껴지는지, 사용자가 단일 날짜를 선택하고 강조 표시하는 방법, 특정 날짜로 앞뒤로 이동하는 방법을 빠르게 보여줍니다.
import { Component } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-5.component.scss' ],
templateUrl : './calendar-sample-5.component.html' ,
imports : [IgxCalendarComponent]
})
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 {
--ig-size: 2 ;
border-radius : 4px ;
}
scss コピー
이 샘플이 마음에 드시나요? 전체 Ignite UI for Angular 툴킷에 액세스하고 몇 분 안에 나만의 앱을 구축해 보세요. 무료로 다운로드하세요.
Ignite UI for Angular 캘린더 시작하기
Ignite UI for Angular Calendar 구성 요소를 시작하려면 먼저 Ignite UI for Angular 설치해야 합니다. 기존 Angular 애플리케이션에서 다음 명령을 입력합니다.
ng add igniteui-angular
cmd
Ignite UI for Angular에 대한 전체 소개는 시작 항목을 참조하십시오.
다음 단계는 IgxCalendarModule
당신의 app.module.ts 파일.
...
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 { Component } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-1.component.scss' ],
templateUrl : './calendar-sample-1.component.html' ,
imports : [IgxCalendarComponent]
})
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 {
--ig-size: 2 ;
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 달력 범위 선택기
동일한 접근 방식에 따라 범위 선택 모드로 전환할 수 있습니다.
<igx-calendar selection ="range" > </igx-calendar >
html
import { Component } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-8.component.scss' ],
templateUrl : './calendar-sample-8.component.html' ,
imports : [IgxCalendarComponent]
})
export class CalendarSample8Component { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar selection ="range" > </igx-calendar >
</article >
html コピー .calendar-wrapper {
--ig-size: 2 ;
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
모든 속성 값은 AppComponent 파일에서 설정되어야 합니다.
@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 { Component, OnInit, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent, IgxSelectComponent, IgxPrefixDirective, IgxSelectItemComponent } 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' ;
import { FormsModule } from '@angular/forms' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-2.component.scss' ],
templateUrl : './calendar-sample-2.component.html' ,
imports : [IgxSelectComponent, FormsModule, IgxPrefixDirective, IgxSelectItemComponent, IgxCalendarComponent]
})
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 >
@for (locale of locales; track locale) {
<igx-select-item [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 ;
}
.igx-calendar {
--ig-size: 2 ;
}
.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 { Component, OnInit, ViewChild } from '@angular/core' ;
import { DateRangeType, IgxCalendarComponent } from 'igniteui-angular' ;
import { DatePipe } from '@angular/common' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-6.component.scss' ],
templateUrl : './calendar-sample-6.component.html' ,
imports : [IgxCalendarComponent, DatePipe]
})
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 );
}
.igx-calendar {
--ig-size: 2 ;
}
.info {
display : flex;
justify-content : center;
background : 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
와 거의 동일한 구성 원칙을 사용합니다. specialDates
선택하고 집중하는 기능은 disabled
기능과 다릅니다.
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 { Component, ViewChild } from '@angular/core' ;
import { DateRangeType, IgxCalendarComponent, IgxDialogComponent, IgxButtonDirective } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-7.component.scss' ],
templateUrl : './calendar-sample-7.component.html' ,
imports : [IgxCalendarComponent, IgxDialogComponent, IgxButtonDirective]
})
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 ="contained" (click )="submitPTOdays()" > Submit Request</button >
</article >
html コピー .calendar-wrapper {
--ig-size: 2 ;
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--contained {
border-radius : 0 ;
}
scss コピー
주 번호
이제 showWeekNumbers
입력을 사용하여 Calendar 및 DatePicker 구성 요소 모두의 주 번호를 표시할 수 있습니다.
<igx-calendar selection ="multi" [showWeekNumbers ]="true" > </igx-calendar >
html
다음 데모에서는 주 번호가 활성화된 달력을 보여줍니다.
import { Component } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-1.component.scss' ],
templateUrl : './calendar-sample-1.component.html' ,
imports : [IgxCalendarComponent]
})
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 {
--ig-size: 2 ;
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 { DOCUMENT } from '@angular/common' ;
import { Component, Inject, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent, IgxDialogComponent, IgxCalendarView, IViewDateChangeEventArgs } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-3.component.scss' ],
templateUrl : './calendar-sample-3.component.html' ,
imports : [IgxCalendarComponent]
})
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:` ;
constructor (@Inject (DOCUMENT) private document : Document ) { }
public onSelection (dates: Date | Date [] ) {
const logger: HTMLElement = this .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 = this .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 = this .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" >
<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 {
--ig-size: 2 ;
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% ;
gap: 16px ;
flex-flow : row wrap;
}
button {
margin : 8px 0 ;
}
.calendar-wrapper {
width : 300px ;
margin : 8px ;
}
.calendar-section {
height : 336px ;
}
.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 달력 뷰
독립적으로 사용할 수 있는 IgxCalendarModule
에서 제공하는 별도의 뷰가 있습니다.
import { Component } from '@angular/core' ;
import { IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxDaysViewComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-days-view.component.scss' ],
templateUrl : './calendar-days-view.component.html' ,
imports : [IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxDaysViewComponent]
})
export class CalendarDaysViewComponent { }
ts コピー <igx-card elevated >
<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 ;
}
.igx-calendar {
--ig-size: 2 ;
}
scss コピー
import { Component } from '@angular/core' ;
import { IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxMonthsViewComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-months-view.component.scss' ],
templateUrl : './calendar-months-view.component.html' ,
imports : [IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxMonthsViewComponent]
})
export class CalendarMonthsViewComponent { }
ts コピー <igx-card elevated >
<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 ;
}
.igx-calendar {
--ig-size: 2 ;
}
scss コピー
import { Component } from '@angular/core' ;
import { IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxYearsViewComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar-views' ,
styleUrls : ['./calendar-years-view.component.scss' ],
templateUrl : './calendar-years-view.component.html' ,
imports : [IgxCardComponent, IgxCardHeaderComponent, IgxCardContentDirective, IgxYearsViewComponent]
})
export class CalendarYearsViewComponent { }
ts コピー <igx-card elevated >
<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 ;
}
:host {
igx-years-view {
--ig-size: 2 ;
}
}
scss コピー
키보드 탐색
Tab 키를 사용하여 페이지를 트래버스하는 경우 W3 접근성 권장 사항에 따라 igxCalendarComponent 에 다음과 같은 탭 정지가 도입된다는 점을 명심해야 합니다.
지난달 버튼
월 선택 버튼
연도 선택 버튼
다음 달 버튼
선택한 날짜, 현재 날짜, 일별 보기에서 첫 번째 포커스 가능(비활성화 아님) 날짜
선택한 날짜가 두 개 이상 포함된 Angular 캘린더에서는 첫 번째 날짜만 탭 정지로 도입됩니다. 예를 들어 Angular 캘린더 다중 선택이 활성화되어 있고 날짜를 선택한 경우: 13/10/2020,17 /10/2020 및 21/10/2020 탭 탐색 중에는 13/10/2020 에만 액세스할 수 있습니다. Angular 달력 범위 선택기에서는 선택한 범위의 첫 번째 날짜만 페이지 탭 시퀀스 의 일부가 됩니다.
v10.2.0 의 동작 변경 -일 보기 의 탭 키 탐색을 더 이상 사용할 수 없습니다. 날짜 보기 에서 날짜 사이를 이동하려면 화살표 키를 사용해야 합니다.
igxCalendar
구성요소에 초점이 맞춰지면 다음을 사용하세요.
이전 달로 이동하는 PageUp 키,
PageDown 키를 누르면 다음 달로 이동하고,
이전 연도로 이동하려면 Shift + PageUp 키,
다음 연도로 이동하려면 Shift + PageDown 키를 사용하고,
현재 달의 첫날 또는 보기의 첫 번째 달에 초점을 맞추는 홈 키
현재 달의 마지막 날 또는 지난 달의 보기에 초점을 맞추는 종료 키
하위 헤더에 있는 prev
또는 next
달 버튼에 초점이 맞춰지면 다음을 사용하세요.
다음 달 또는 이전 달 보기로 스크롤하려면 스페이스바 또는 Enter 키를 누르세요.
하위 헤더에 있는 months
버튼에 초점이 맞춰지면 다음을 사용하세요.
월별 보기를 열려면 Space 또는 Enter 키를 누르세요.
year
버튼(하위 헤더에 있음)에 초점이 맞춰지면 다음을 사용하세요.
10년 보기를 열려면 Space 또는 Enter 키를 누르세요.
당월 내의 day
에 초점이 맞춰진 경우:
날짜를 탐색하려면 화살표 키를 사용하세요. 참고: 비활성화된 날짜는 건너뜁니다.
포커스는 뷰에 있는 이번 달에 유지되며, 해당 달의 마지막 날 / 1일 부터 /까지 탐색됩니다.
kb 탐색은 연속적입니다. 즉, 화살표를 사용하여 탐색하는 동안 모든 달을 통과하게 됩니다.
현재 집중하고 있는 날짜를 선택하려면 Enter 키를 사용하세요.
월 보기 내의 한 month
에 초점이 맞춰지면 다음을 사용하세요.
월을 탐색하려면 화살표 키를 사용하세요.
월 보기 내에서 첫 번째 달에 초점을 맞추는 홈 키입니다.
월 보기 내에서 마지막 달에 초점을 맞추는 종료 키입니다.
현재 초점이 맞춰진 월을 선택하고 보기를 닫으려면 키를 입력하세요 .
10년 보기 내의 year
에 초점을 맞추면 다음을 사용합니다.
위쪽 화살표 및 아래쪽 화살표 키를 사용하여 연도를 탐색할 수 있습니다.
현재 초점을 맞춘 연도를 선택하고 보기를 닫으려면 키를 입력하세요 .
버전 8.2.0 이후 키보드 탐색에서는 이번 달이 아닌 날짜에 초점을 맞추지 않고 표시된 달을 변경합니다.
멀티뷰 캘린더
다중 보기 달력은 세 가지 유형의 선택을 모두 지원합니다. 입력을 monthsViewNumber
사용하여 표시되는 개월 수를 설정하면 플렉스 컨테이너에 가로로 표시됩니다. 설정된 최대값에는 제한이 없습니다. 다중 보기 달력을 사용하는 동안 현재 달에 속하지 않는 날짜를 숨길 수 있습니다. 당신은 재산으로 hideOutsideDays
그것을 할 수 있습니다. 키보드 탐색은 다음/이전 달이 표시되면 해당 달로 이동합니다.
import { Component, ViewChild } from '@angular/core' ;
import { IgxCalendarComponent, IgxDialogComponent, IgxButtonDirective } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./multiview.component.scss' ],
templateUrl : './multiview.component.html' ,
imports : [IgxCalendarComponent, IgxDialogComponent, IgxButtonDirective]
})
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" >
@if (range.length <= 1) {
<span > {{ action }}</span >
}
@if (range.length > 1) {
<span > {{ 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 ="contained" (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 {
--ig-size: 2 ;
border-radius : 0 ;
}
.igx-button--contained {
border-radius : 0 ;
}
.stay__info {
display : flex;
justify-content : center;
background : 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]
하려면 속성을 사용하여 각각 or vertical
로 horizontal
설정합니다.
해당 속성이 작동하는지 확인하려면 최소 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
import { Component, ViewChild } from '@angular/core' ;
import { IgxButtonGroupComponent, IgxCalendarComponent, IgxButtonDirective }
from 'igniteui-angular' ;
const orientations = ["horizontal" , "vertical" ] as const ;
type Orientation = (typeof orientations)[number ];
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-sample-9.component.scss' ],
templateUrl : './calendar-sample-9.component.html' ,
imports : [IgxCalendarComponent, IgxButtonGroupComponent, IgxButtonDirective]
})
export class CalendarSample9Component {
@ViewChild (IgxButtonGroupComponent, { static : true }) public buttonGroup: IgxButtonGroupComponent;
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;
}
}
ts コピー <div class ="preview__sample" >
<article class ="calendar-wrapper" >
<igx-calendar [monthsViewNumber ]="2" [headerOrientation ]="headerOrientation" [orientation ]="orientation" > </igx-calendar >
</article >
<div class ="preview__settings" >
<small > Header orientation</small >
<igx-buttongroup selectionMode ="singleRequired" >
@for (ho of orientations; track ho) {
<button
igxButton
(click )="setHeaderOrientation(ho)"
[selected ]="ho === headerOrientation"
>
{{ ho }}
</button >
}
</igx-buttongroup >
<small > View orientation</small >
<igx-buttongroup selectionMode ="singleRequired" >
@for (vo of orientations; track vo) {
<button
igxButton
(click )="setOrientation(vo)"
[selected ]="vo === orientation"
>
{{ vo }}
</button >
}
</igx-buttongroup >
</div >
</div >
html コピー $padding : 2rem ;
:host {
display : flex;
flex-direction : column;
height : calc(100vh - 90px );
overflow : hidden;
}
small {
&:not (:first-child) {
margin -block-start: 1rem ;
}
}
.calendar-wrapper {
flex-basis : 100px ;
display : flex;
flex-direction : column;
flex-grow : 1 ;
margin : 20px ;
}
.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 );
}
.preview {
display : flex;
overflow : hidden;
height : 100% ;
&__sample {
display : flex;
flex-wrap : wrap;
overflow : auto;
flex : 1 ;
}
&__settings {
display : flex;
flex-direction : column;
gap: 8px ;
background : hsla(var(--ig-gray-50 ));
border-left : 1px solid var(--ig-gray-300 );
padding : $padding ;
overflow-x : auto;
}
}
scss コピー
스타일링
달력 스타일 지정을 시작하려면 모든 테마 기능과 구성 요소 믹스인이 있는 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
마지막 단계는 사용자 정의 캘린더 테마를 전달하는 것입니다.
@include css-vars($custom-calendar-theme );
scss
import { Component } from '@angular/core' ;
import { IgxCalendarComponent } from 'igniteui-angular' ;
@Component ({
selector : 'app-calendar' ,
styleUrls : ['./calendar-styling-sample.component.scss' ],
templateUrl : './calendar-styling-sample.component.html' ,
imports : [IgxCalendarComponent]
})
export class CalendarStylingSampleComponent { }
ts コピー <article class ="calendar-wrapper" >
<igx-calendar [weekStart ]="1" > </igx-calendar >
</article >
html コピー @use "layout.scss" ;
@use "igniteui-angular/theming" as *;
$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 ,
);
@include css-vars($custom-calendar-theme );
scss コピー
API 참조
추가 리소스
우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.