Angular Month Picker 구성 요소 개요

    Ignite UI for Angular 월-년 달력 뷰를 사용하여 특정 월과 년을 선택하는 쉽고 직관적인 방법을 제공합니다. 이 구성 요소를 사용하면 값을 날짜 개체에 바인딩할 수 있으며 사용자는 월 선택기 구성 요소 UI를 통해 날짜 개체의 월 및 년 부분을 변경할 수 있습니다. 또한 현지화도 지원합니다.

    Angular Month Picker Example

    여기서 보이는 것은 기본 Angular Month Picker의 예이며, 사용자가 연도와 월을 선택할 수 있는 기본 뷰가 포함되어 있습니다.

    Getting Started with Ignite UI for Angular Month Picker

    Ignite UI for Angular Month Picker 구성 요소를 시작하려면 먼저 Ignite UI for Angular 설치해야 합니다. 기존 Angular 애플리케이션에서 다음 명령을 입력합니다.

    ng add igniteui-angular
    

    Ignite UI for Angular에 대한 전체 소개는 시작 항목을 참조하십시오.

    첫 번째 단계는 다음 파일을 가져오는 것입니다.IgxCalendarModule 우리 안에서 app.module.ts 파일.

    Note

    The IgxMonthPickerComponent also depends on the BrowserAnimationsModule and optionally the HammerModule for touch interactions, so they need to be added to the AppModule as well:

    // app.module.ts
    ...
    import { HammerModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { IgxCalendarModule } from 'igniteui-angular/calendar';
    // import { IgxCalendarModule } from '@infragistics/igniteui-angular'; for licensed package
    
    @NgModule({
        ...
        imports: [..., BrowserAnimationsModule, HammerModule, IgxCalendarModule],
        ...
    })
    export class AppModule {}
    

    또는16.0.0 독립 실행형 의존성으로 가져오IgxMonthPickerComponent 거나, 토큰을IGX_CALENDAR_DIRECTIVES 사용해 컴포넌트와 그 지원 컴포넌트, 명령어를 가져올 수도 있습니다.

    // home.component.ts
    
    import { HammerModule } from '@angular/platform-browser';
    import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
    import { IgxMonthPickerComponent } from 'igniteui-angular/calendar';
    // import { IgxMonthPickerComponent } from '@infragistics/igniteui-angular'; for licensed package
    
    @Component({
        selector: 'app-home',
        template: '<igx-month-picker></igx-month-picker>',
        styleUrls: ['home.component.scss'],
        standalone: true,
        imports: [BrowserAnimationsModule, HammerModule, IgxMonthPickerComponent]
        /* or imports: [BrowserAnimationsModule, HammerModule, IGX_CALENDAR_DIRECTIVES] */
    })
    export class HomeComponent {}
    

    Now that you have the Ignite UI for Angular Calendar module or Month Picker component imported, you can start using the igx-month-picker component.

    Note

    Note that the IgxMonthPickerComponent uses the Intl WebAPI for localization and formatting of dates. Consider using the appropriate polyfills if your target platform does not support them.

    Using the Angular Month Picker

    템플릿에 Angular Month Picker를 추가하려면 다음 코드를 사용하세요.

    <!-- month-picker-sample.component.html -->
    
    <igx-month-picker></igx-month-picker>
    

    Setting date

    Set a date to IgxMonthPickerComponent using the value input.

    // month-picker-sample.component.ts
    
    public date: Date = new Date();
    
    <!-- month-picker-sample.component.html -->
    
    <igx-month-picker [value]="date"></igx-date-picker>
    

    To create a two-way data-binding, set ngModel like this:

    <!-- month-picker-sample.component.html -->
    
    <igx-month-picker [(ngModel)]="date"></igx-date-picker>
    

    Formatting

    Change the month picker display format, using the formatOptions inputs.

    <!-- month-picker-sample.component.html -->
    
    <igx-month-picker [(ngModel)]="date" [formatOptions]="numericFormatOptions"></igx-month-picker>
    
    // month-picker-sample.component.ts
    
    public date: Date = new Date();
    public numericFormatOptions = {
        month: '2-digit'
    };
    

    Localization

    Use the locale input, to customize the Ignite UI for Angular Month Picker localization.

    <!-- month-picker-sample.component.html -->
    
    <igx-month-picker [(ngModel)]="date" [locale]="locale" [formatOptions]="formatOptions"></igx-month-picker>
    
    // month-picker-sample.component.ts
    
    public date: Date = new Date();
    public locale: 'fr';
    public formatOptions = {
        month: 'long'
    };
    

    다음은 월 선택기 구성 요소를 지역화하고 형식을 지정하는 예입니다.

    키보드 탐색

    • igxMonthPicker 구성 요소에 초점이 맞춰지면 다음을 사용하세요.

      • PageUp 키는 전년도로 이동하고,
      • PageDown 키를 누르면 다음 연도로 이동하고,
      • 올해의 첫 달을 포커스하는 키,
      • 해당 연도의 마지막 달에 초점을 맞추는 End 키,
      • 하위 헤더 버튼을 탐색하려면 Tab 키를 사용하세요.
    • When < (previous) or > (next) year button (in the sub-header) is focused, use

      • 다음 또는 이전 연도를 보려면 스크롤하려면 스페이스Enter 키를 누르세요.
    • 연도 버튼(하위 헤더에 있음)에 초점이 맞춰지면 다음을 사용하세요.

      • 연도 보기를 열려면 Space 또는 Enter 키를 누르세요.
      • 이전/다음 연도를 스크롤하여 보려면 오른쪽 또는 왼쪽 화살표 키를 사용하세요.
    • 월 보기 내 월에 초점이 맞춰지면 다음을 사용하세요.

      • 달을 탐색하려면 화살표 키를 사용하세요.
      • 월 보기 내에서 첫 번째 달에 초점을 맞추는 키,
      • 월 보기 내에서 지난 달에 초점을 맞추는 종료 키,
      • 현재 초점이 맞춰진 월을 선택하고 보기를 닫으려면 키를 입력하세요.
      • 월을 탐색하려면 Tab 키를 사용하세요.

    스타일링

    To get started with styling the month picker, we need to import the index file, where all the theme functions and component mixins live:

    @use "igniteui-angular/theming" as *;
    
    // IMPORTANT: Prior to Ignite UI for Angular version 13 use:
    // @import '~igniteui-angular/lib/core/styles/themes/index';
    

    The month picker uses the calendar's theme, so we have to create a new theme that extends the calendar-theme. To style the month picker's items, you can set the $content-background parameter. Optionally, you can also set $header-background if you want to override the rest of the properties. These two parameters act as the foundation for the theme and are used to automatically generate the appropriate background and foreground colors for all interaction states, such as hover, selected, and active.

    $my-calendar-theme: calendar-theme(
      $border-radius: 15px,
      $content-background: #57a5cd,
    );
    

    다음 단계는 애플리케이션에 구성 요소 테마를 포함하는 것입니다.

    @include css-vars($my-calendar-theme);
    

    모든 작업이 완료되면 구성 요소는 다음과 같아야 합니다.

    Demo

    Styling with Tailwind

    저희 맞춤형 Tailwind 유틸리티 클래스를 사용해 스타일month picker 링할 수 있습니다. 먼저 Tailwind를 꼭 설정 하세요.

    전역 스타일시트의 순풍 가져오기와 함께 다음과 같이 원하는 테마 유틸리티를 적용할 수 있습니다.

    @import "tailwindcss";
    ...
    @use 'igniteui-theming/tailwind/utilities/material.css';
    

    The utility file includes both light and dark theme variants. The month picker is styled through the calendar theme, so you have to use the calendar utility class

    • 라이트 테마에는 클래스를 사용light-* 하세요.
    • 어두운 테마에는 클래스를 사용dark-* 하세요.
    • 접두사 뒤에 컴포넌트 이름을 덧붙이세요,light-calendardark-calendar 예: .

    이 클래스들이 적용되면 동적 테마 계산이 가능합니다. 그 다음에는 생성된 CSS 변수를 무arbitrary properties 시할 수 있습니다. 콜론 다음에는 유효한 CSS 색상 형식(HEX, CSS 변수, RGB 등)을 입력하세요.

    전체 부동산 목록은 캘린더 테마에서 확인할 수 있습니다. 문법은 다음과 같습니다:

    <igx-month-picker
    class="!light-calendar
    ![--header-background:#4F6A5A]
    ![--content-background:#A3C7B2]">
    </igx-month-picker>
    
    Note

    느낌표(!)는 유틸리티 클래스가 우선순위가 되도록 보장하기 위해 필요합니다. Tailwind는 레이어에 스타일을 적용하는데, 이 스타일을 중요하게 표시하지 않으면 컴포넌트의 기본 테마에 의해 덮어쓰여집니다.

    마지막에 월 선택기는 다음과 같이 보여야 합니다:

    API References

    Theming Dependencies

    Additional Resources

    우리 커뮤니티는 활동적이며 항상 새로운 아이디어를 환영합니다.