ion-datetime
Datetime은 캘린더 인터페이스와 시간 휠(wheel)을 제공해서 사용자가 날짜와 시간을 쉽게 선택할 수 있게 해 주는 컴포넌트예요. 네이티브 input 요소의 datetime-local과 비슷하지만, Ionic Framework의 Datetime 컴포넌트를 이용하면 날짜와 시간을 원하는 형식으로 쉽게 표시하고 datetime 값을 관리할 수 있습니다.
출처: 문서
본문
Datetime은 캘린더 인터페이스와 시간 휠을 제공해 사용자가 날짜와 시간을 손쉽게 고를 수 있게 해 줍니다. 네이티브 input의 datetime-local과 유사하지만, Ionic Framework의 Datetime 컴포넌트는 날짜와 시간을 선호하는 형식으로 표시하고 datetime 값을 관리하기 쉽게 만들어 줍니다.
ISO 8601 Datetime 형식: YYYY-MM-DDTHH:mmZ
Ionic Framework는 값에 ISO 8601 datetime 형식을 사용합니다. 값은 JavaScript의 Date 객체 대신 단순한 문자열이에요. ISO datetime 형식을 사용하면 JSON 객체와 데이터베이스 안에서 직렬화하고 파싱하기 쉽습니다.
ion-datetime과 함께 사용할 수 있는 ISO 8601 형식의 예시는 다음과 같습니다:
| 설명 | 형식 | Datetime 값 예시 |
|---|---|---|
| 연도 | YYYY |
1994 |
| 연도와 월 | YYYY-MM |
1994-12 |
| 완전한 날짜 | YYYY-MM-DD |
1994-12-15 |
| 날짜와 시간 | YYYY-MM-DDTHH:mm |
1994-12-15T13:47 |
| UTC 시간대 | YYYY-MM-DDTHH:mm:ssZ |
1994-12-15T13:47:20Z |
| 시간대 오프셋 | YYYY-MM-DDTHH:mm:ssTZD |
1994-12-15T13:47:20+05:00 |
| 시간과 분 | HH:mm |
13:47 |
연도는 항상 네 자리, 밀리초(추가되는 경우)는 항상 세 자리, 나머지는 모두 두 자리라는 점을 기억하세요. 그래서 1월을 나타내는 숫자는 항상 앞에 0이 붙어 01이 됩니다. 또한 시간은 항상 24시간 형식이라, 00은 12시간 시계의 12am, 13은 1pm, 23은 11pm을 의미합니다.
참고 (Note)
ISO 8601 datetime 형식으로 초, 밀리초, 시간대를 지정할 수는 있지만, ion-datetime은 초, 밀리초, 시간대 선택을 위한 인터페이스를 제공하지 않습니다. 제공된 초, 밀리초, 시간대 값은 모두 무시됩니다.
기본 사용법 (Basic Usage)
JavaScript
<ion-datetime></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
Datetime Button과 함께 사용하기
모달이나 팝오버 같은 오버레이에서 datetime을 표시해야 한다면 ion-datetime-button을 사용하는 것을 권장해요. ion-datetime-button은 공간이 제한될 때 사용해야 합니다. 이 컴포넌트는 현재 날짜와 시간 값을 보여주는 버튼을 표시하며, 버튼을 탭하면 오버레이에서 날짜 또는 시간 선택기가 열립니다.
값 비동기 설정 (Setting Values Asynchronously)
datetime이 이미 생성된 후에 value가 프로그래밍 방식으로 업데이트되면, datetime은 자동으로 새 날짜로 이동합니다. 하지만 사용자가 datetime과 상호작용할 수 있는 상태에서 이렇게 value를 업데이트하는 것은 권장하지 않아요. 현재 날짜를 선택하려는 사용자에게 혼란을 줄 수 있기 때문입니다. 예를 들어 datetime의 value가 비동기 프로세스로 로드된다면, 값 업데이트가 끝날 때까지 CSS로 datetime을 숨겨 두는 것이 좋습니다.
날짜 제약 (Date Constraints)
최대/최소 날짜 (Max and Min Dates)
최소/최대 datetime 값을 커스터마이즈하려면 min과 max 컴포넌트 프로퍼티를 제공하면 됩니다. 이는 앱의 사용 사례에 더 적합할 수 있어요. 위 표에 나온 것과 같은 ISO 8601 형식을 따르며, 각 컴포넌트는 사용자가 선택할 수 있는 날짜를 제한할 수 있습니다.
다음 예시는 2022년 3월부터 2022년 5월까지만 날짜 선택을 제한합니다.
JavaScript
<ion-datetime value="2022-04-21T00:00:00" min="2022-03-01T00:00:00" max="2022-05-31T23:59:59"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime value="2022-04-21T00:00:00" min="2022-03-01T00:00:00" max="2022-05-31T23:59:59"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime value="2022-04-21T00:00:00" min="2022-03-01T00:00:00" max="2022-05-31T23:59:59"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime value="2022-04-21T00:00:00" min="2022-03-01T00:00:00" max="2022-05-31T23:59:59"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
특정 값 선택 (Selecting Specific Values)
min과 max 프로퍼티가 날짜 선택을 일정 범위로 제한한다면, monthValues, dayValues, yearValues, hourValues, minuteValues 프로퍼티는 사용자가 선택할 수 있는 특정 일과 시간을 고르게 해 줍니다.
다음 예시는 분을 15 단위로, 날짜를 5 단위로 선택할 수 있게 합니다.
JavaScript
<ion-datetime minute-values="0,15,30,45" day-values="5,10,15,20,25,30"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime minuteValues="0,15,30,45" dayValues="5,10,15,20,25,30"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime minuteValues="0,15,30,45" dayValues="5,10,15,20,25,30"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime minute-values="0,15,30,45" day-values="5,10,15,20,25,30"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
고급 날짜 제약 (Advanced Date Constraints)
isDateEnabled 프로퍼티를 사용하면 개발자가 ISO 8601 날짜 문자열을 이용해 특정 요일, 날짜 범위, 주말 또는 어떤 커스텀 규칙이든 ion-datetime이 비활성화하도록 커스터마이즈할 수 있어요. isDateEnabled 프로퍼티는 날짜가 활성화되어 있는지 나타내는 불리언을 반환하는 함수를 받습니다. 이 함수는 렌더링되는 각 캘린더 일(이전, 현재, 다음 달)에 대해 호출됩니다. 커스텀 구현은 버벅임(jank)을 피하기 위해 성능을 최적화해야 합니다.
다음 예시는 모든 주말 날짜를 비활성화하는 방법을 보여줍니다. 더 고급스러운 날짜 조작을 위해서는 date-fns 같은 날짜 유틸리티를 사용하는 것을 권장해요.
JavaScript
<ion-datetime></ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.isDateEnabled = (dateString) => {
const date = new Date(dateString);
const utcDay = date.getUTCDay();
/**
* Date will be enabled if it is not
* Sunday or Saturday
*/
return utcDay !== 0 && utcDay !== 6;
};
</script>
Angular
src/app/example.component.html
<ion-datetime [isDateEnabled]="isWeekday"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {
isWeekday = (dateString: string) => {
const date = new Date(dateString);
const utcDay = date.getUTCDay();
/**
* Date will be enabled if it is not
* Sunday or Saturday
*/
return utcDay !== 0 && utcDay !== 6;
};
}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
const isWeekday = (dateString: string) => {
const date = new Date(dateString);
const utcDay = date.getUTCDay();
/**
* Date will be enabled if it is not
* Sunday or Saturday
*/
return utcDay !== 0 && utcDay !== 6;
};
return <IonDatetime isDateEnabled={isWeekday}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime :is-date-enabled="isWeekday"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
const isWeekday = (dateString: string) => {
const date = new Date(dateString);
const utcDay = date.getUTCDay();
/**
* Date will be enabled if it is not
* Sunday or Saturday
*/
return utcDay !== 0 && utcDay !== 6;
};
</script>
지역화 (Localization)
Ionic Framework는 Intl.DatetimeFormat Web API를 사용해 사용자 기기에 설정된 언어와 지역에 따라 월/일 이름을 자동으로 지역화합니다.
커스텀 로케일 (Custom Locale)
특정 로케일이 필요한 경우 locale 프로퍼티로 설정할 수 있어요. locale은 표시되는 언어와 날짜/시간 형식을 모두 제어합니다.
다음 예시는 로케일을 스페인(스페인)으로 설정하는 방법을 보여줍니다.
JavaScript
<ion-datetime locale="es-ES"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime locale="es-ES"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime locale="es-ES"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime locale="es-ES"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
참고 (Note)
시간 라벨은 자동으로 지역화되지 않습니다. 자세한 내용은 Time Label을 참고하세요.
시간 주기 (Hour Cycle)
ion-datetime은 기본적으로 locale 프로퍼티가 지정한 시간 주기를 사용합니다. 예를 들어 locale이 en-US로 설정되면 ion-datetime은 12시간 주기를 사용해요.
4가지 기본 시간 주기 유형이 있습니다:
| 시간 주기 유형 | 설명 |
|---|---|
'h12' |
1–12을 사용하는 시간 체계; 패턴에서 'h'에 해당. 자정이 12:00 am에서 시작하는 12시간 시계. |
'h23' |
0–23을 사용하는 시간 체계; 패턴에서 'H'에 해당. 자정이 0:00에서 시작하는 24시간 시계. |
'h11' |
0–11을 사용하는 시간 체계; 패턴에서 'K'에 해당. 자정이 0:00 am에서 시작하는 12시간 시계. |
'h24' |
1–24을 사용하는 시간 체계; 패턴에서 'k'에 해당. 자정이 24:00에서 시작하는 24시간 시계. |
참고 (Note)
사용할 시간 주기를 더 자세히 제어해야 하는 상황이 있을 수 있어요. 이때 hourCycle 프로퍼티가 도움이 됩니다.
다음 예시에서 locale이 en-GB(기본적으로 24시간 주기를 사용)여도 hourCycle 프로퍼티로 ion-datetime이 12시간 주기를 사용하도록 강제할 수 있습니다:
JavaScript
<ion-datetime locale="en-GB" hour-cycle="h12"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime locale="en-GB" hourCycle="h12"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime locale="en-GB" hourCycle="h12"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime locale="en-GB" hour-cycle="h12"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
주의 첫 번째 요일 (First Day of the Week)
ion-datetime의 기본 주의 첫 번째 요일은 일요일입니다. 2022년 기준으로 브라우저에서 기기의 로케일에 따라 주의 첫 번째 요일을 자동으로 결정하는 API는 없습니다. 다만 이에 대한 작업은 진행 중입니다(TC39 GitHub 참고).
JavaScript
<ion-datetime first-day-of-week="1"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime [firstDayOfWeek]="1"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime firstDayOfWeek={1}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime :first-day-of-week="1"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
시간 라벨 (Time Label)
시간 라벨은 자동으로 지역화되지 않아요. 다행히 Ionic은 time-label 슬롯으로 커스텀 지역화를 쉽게 제공할 수 있게 해 줍니다.
JavaScript
<ion-datetime locale="es-ES">
<span slot="time-label">Tiempo</span>
</ion-datetime>
Angular
src/app/example.component.html
<ion-datetime locale="es-ES">
<span slot="time-label">Tiempo</span>
</ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return (
<IonDatetime locale="es-ES">
<span slot="time-label">Tiempo</span>
</IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime locale="es-ES">
<span slot="time-label">Tiempo</span>
</ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
로케일 확장 태그 (Locale Extension Tags)
ion-datetime은 Intl.Locale API의 일부로 로케일 확장 태그(locale extension tags)도 지원합니다. 이러한 태그는 locale 문자열 자체에 locale에 대한 정보를 인코딩할 수 있게 해 줍니다. 앱에서 Intl.Locale API를 사용한다면 확장 태그 방식을 선호할 수 있어요.
예를 들어 en-GB locale에서 12시간 주기를 사용하려면 locale과 hourCycle 프로퍼티를 둘 다 사용하는 대신 확장 태그를 제공할 수 있습니다:
JavaScript
<ion-datetime locale="en-GB-u-hc-h12"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime locale="en-GB-u-hc-h12"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime locale="en-GB-u-hc-h12"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime locale="en-GB-u-hc-h12"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
참고 (Note)
앱에서 Intl.Locale을 사용하기 전에 브라우저 호환성 차트(Browser Compatibility Chart)를 꼭 확인하세요.
표시 형식 (Presentation)
기본적으로 ion-datetime은 사용자가 날짜와 시간을 모두 선택할 수 있게 해 줍니다. 또한 사용자는 특정 월, 연도, 시간, 분을 선택할 수 있습니다.
어떤 사용 사례는 날짜만 또는 시간만 선택해야 할 수도 있어요. presentation 프로퍼티로 어떤 선택기를 표시할지, 그리고 어떤 순서로 표시할지 지정할 수 있습니다. 예를 들어 date-time으로 설정하면 달력 선택기가 시간 선택기보다 먼저 나타납니다. time-date로 설정하면 달력 선택기가 시간 선택기보다 나중에 나타나요.
월과 연도 선택 (Month and Year Selection)
presentation 프로퍼티에 month-year, month 또는 year를 전달하면 월과 연도 선택이 가능합니다.
이 예시는 month-year 구성을 가진 datetime을 보여줍니다.
JavaScript
<ion-datetime presentation="month-year"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime presentation="month-year"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime presentation="month-year"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime presentation="month-year"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
시간 선택 (Time Selection)
presentation 프로퍼티에 date-time, time-date 또는 time을 전달하면 시간 선택이 가능합니다.
이 예시는 time 구성을 가진 datetime을 보여줍니다.
JavaScript
<ion-datetime presentation="time"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime presentation="time"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime presentation="time"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime presentation="time"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
날짜 선택 (Date Selection)
presentation 프로퍼티에 date-time, time-date 또는 date를 전달하면 날짜 선택이 가능합니다.
이 예시는 date 구성을 가진 datetime을 보여줍니다.
JavaScript
<ion-datetime presentation="date"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime presentation="date"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime presentation="date"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime presentation="date"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
휠 스타일 선택기 (Wheel Style Pickers)
기본적으로 Ionic은 presentation을 사용할 때 그리드 스타일 레이아웃을 선호합니다. 하지만 preferWheel 프로퍼티로 휠 스타일을 표시할 수 있어요. preferWheel이 true면 가능할 때 휠 스타일 레이아웃을 선호합니다.
특정 presentation 옵션은 그리드와 휠 스타일을 모두 가져 개발자가 preferWheel 프로퍼티로 선택할 수 있습니다. 다른 presentation 값은 휠 스타일만 있으며 그리드 스타일은 절대 표시하지 않습니다. 아래 표는 어떤 presentation 값이 그리드 또는 휠 스타일을 가지는지 보여줍니다.
presentation |
그리드 스타일 있음? | 휠 스타일 있음? |
|---|---|---|
date |
예 | 예 |
date-time |
예 | 예 |
month |
아니오 | 예 |
month-year |
아니오 | 예 |
time |
아니오 | 예 |
time-date |
예 | 예 |
year |
아니오 | 예 |
아래 예시는 presentation="date-time"을 사용한 휠 선택기를 보여줍니다.
JavaScript
<ion-datetime presentation="date-time" prefer-wheel="true"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime presentation="date-time" [preferWheel]="true"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime presentation="date-time" preferWheel={true}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime presentation="date-time" :prefer-wheel="true"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
인접한 날짜 표시 (Show Adjacent Days)
showAdjacentDays 프로퍼티를 true로 설정하면, 이전 달과 다음 달의 날짜가 캘린더 보기에 표시되어 달의 시작이나 끝의 빈 공간을 채웁니다. 사용자가 활성화된 인접한 날짜를 클릭하면 캘린더가 부드럽게 애니메이션되어 해당 달의 보기를 표시합니다.
showAdjacentDays가 활성화되면 캘린더 보기는 항상 6줄을 표시하므로, 그리드를 채우기 위해 필요에 따라 이전/다음 달의 날짜가 표시됩니다. 예를 들어 달이 주의 첫 번째 요일에 시작해 다섯 번째 줄 안에서 끝나더라도, 여섯 번째 줄을 완성하기 위해 다음 달의 날짜가 끝에 나타납니다.
참고 (Note)
이 프로퍼티는 presentation="date"와 preferWheel="false"를 사용할 때만 지원됩니다.
JavaScript
<ion-datetime show-adjacent-days="true"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime show-adjacent-days="true"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React, { useRef, useEffect } from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime showAdjacentDays={true}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime show-adjacent-days="true"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
다중 날짜 선택 (Multiple Date Selection)
multiple 프로퍼티를 true로 설정하면 달력 선택기에서 여러 날짜를 선택할 수 있습니다. 선택된 날짜를 클릭하면 선택이 해제됩니다.
참고 (Note)
이 프로퍼티는 presentation="date"와 preferWheel="false"를 사용할 때만 지원됩니다.
JavaScript
<ion-datetime presentation="date" multiple="true"></ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.value = ['2022-06-03', '2022-06-13', '2022-06-29'];
</script>
Angular
src/app/example.component.html
<ion-datetime presentation="date" [multiple]="true" [value]="['2022-06-03', '2022-06-13', '2022-06-29']"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React, { useRef, useEffect } from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
const datetime = useRef<null | HTMLIonDatetimeElement>(null);
useEffect(() => {
if (!datetime.current) return;
datetime.current.value = ['2022-06-03', '2022-06-13', '2022-06-29'];
}, []);
return <IonDatetime ref={datetime} presentation="date" multiple={true}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime presentation="date" :multiple="true" :value="['2022-06-03', '2022-06-13', '2022-06-29']"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
타이틀 (Titles)
기본적으로 ion-datetime은 컴포넌트와 관련된 헤더나 타이틀을 표시하지 않습니다. 개발자는 showDefaultTitle 프로퍼티로 기본 타이틀/헤더 구성을 표시할 수 있고, title 슬롯으로 헤더에 렌더링될 내용을 커스터마이즈할 수도 있어요.
기본 타이틀 표시 (Showing the Default Title)
JavaScript
<ion-datetime show-default-title="true"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime [showDefaultTitle]="true"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime showDefaultTitle={true}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime :show-default-title="true"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
타이틀 커스터마이즈 (Customizing the Title)
JavaScript
<ion-datetime>
<span slot="title">Select a Reservation Date</span>
</ion-datetime>
Angular
src/app/example.component.html
<ion-datetime>
<span slot="title">Select a Reservation Date</span>
</ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return (
<IonDatetime>
<span slot="title">Select a Reservation Date</span>
</IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime>
<span slot="title">Select a Reservation Date</span>
</ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
포맷 옵션 (Format Options)
Datetime 컴포넌트의 헤더 텍스트에 있는 날짜와 시간 버튼에 있는 시간의 포맷을 formatOptions를 제공해 커스터마이즈할 수 있어요. formatOptions 프로퍼티의 date와 time은 각각 Intl.DateTimeFormatOptions 객체여야 합니다. formatOptions가 제공되지 않으면 날짜와 시간에 기본 포맷이 사용됩니다.
Datetime은 시간대를 조작하거나 설정하지 않습니다. timeZone 또는 timeZoneName이 제공되면 무시되고 시간대는 UTC로 설정됩니다. 이는 표시된 값이 사용자의 현재 시간대로 변환되지 않고 선택된 값과 일치하도록 보장합니다.
제공하는 옵션이 선택한 presentation과 일치하지 않을 수 있으니 주의하세요. 예를 들어 month presentation에 minute: 'numeric'을 제공하면 시간만 예상되는 곳에 월이 표시되는 예상치 못한 동작이 발생할 수 있습니다.
JavaScript
<ion-datetime value="2023-11-02T01:22:00">
<span slot="title">Select Date</span>
</ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
datetime.formatOptions = {
time: { hour: '2-digit', minute: '2-digit' },
date: { day: '2-digit', month: 'long' },
};
</script>
Angular
src/app/example.component.html
<ion-datetime
value="2023-11-02T01:22:00"
[formatOptions]="{
time: { hour: '2-digit', minute: '2-digit' },
date: { day: '2-digit', month: 'long' },
}"
>
<span slot="title">Select Date</span>
</ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return (
<IonDatetime
value="2023-11-02T01:22:00"
formatOptions={{
time: { hour: '2-digit', minute: '2-digit' },
date: { day: '2-digit', month: 'long' },
}}
>
<span slot="title">Select Date</span>
</IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime value="2023-11-02T01:22:00" :format-options="formatOptions">
<span slot="title">Select Date</span>
</ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
const formatOptions = {
time: { hour: '2-digit', minute: '2-digit' },
date: { day: '2-digit', month: 'long' },
};
</script>
버튼 (Buttons)
기본적으로 새 날짜가 선택될 때마다 ionChange가 새 datetime 값과 함께 발생합니다. ionChange를 발생시키기 전에 사용자 확인을 요구하려면 showDefaultButtons 프로퍼티를 true로 설정하거나 buttons 슬롯으로 커스텀 확인 버튼을 전달할 수 있어요. 커스텀 버튼을 전달할 때 확인 버튼은 ionChange가 발생하도록 ion-datetime의 confirm 메서드를 호출해야 합니다.
확인 버튼 표시 (Showing Confirmation Buttons)
기본 Done(완료) 및 Cancel(취소) 버튼은 각각 confirm과 cancel 메서드를 호출하도록 이미 사전 구성되어 있습니다.
JavaScript
<ion-datetime show-default-buttons="true"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime [showDefaultButtons]="true"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime showDefaultButtons={true}></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime :show-default-buttons="true"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
버튼 텍스트 커스터마이즈 (Customizing Button Texts)
간단한 사용 사례에서는 doneText와 cancelText 프로퍼티를 통해 확인 및 취소 값에 커스텀 버튼 텍스트를 제공할 수 있어요. 버튼 텍스트만 바꾸면 되고 커스텀 동작이 필요하지 않을 때 이 방법을 권장합니다.
JavaScript
<ion-datetime show-default-buttons="true" done-text="All set" cancel-text="Never mind"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime [showDefaultButtons]="true" doneText="All set" cancelText="Never mind"> </ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
import React, { useRef } from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return <IonDatetime showDefaultButtons={true} doneText="All set" cancelText="Never mind"></IonDatetime>;
}
export default Example;
Vue
<template>
<ion-datetime :show-default-buttons="true" done-text="All set" cancel-text="Never mind"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
버튼 요소 커스터마이즈 (Customizing Button Elements)
개발자는 고급 커스텀 동작을 위해 자신만의 버튼을 제공할 수 있습니다.
ion-datetime에는 커스텀 버튼을 클릭할 때 호출할 수 있는 confirm, cancel, reset 메서드가 있어요. reset 메서드는 datetime을 리셋할 날짜를 제공할 수도 있습니다.
JavaScript
<ion-datetime>
<ion-buttons slot="buttons">
<ion-button color="danger" onclick="datetime.reset()">Reset</ion-button>
<ion-button color="primary" onclick="datetime.cancel()">Never mind</ion-button>
<ion-button color="primary" onclick="datetime.confirm()">All Set</ion-button>
</ion-buttons>
</ion-datetime>
<script>
var datetime = document.querySelector('ion-datetime');
</script>
Angular
src/app/example.component.html
<ion-datetime #datetime>
<ion-buttons slot="buttons">
<ion-button color="danger" (click)="datetime.reset()">Reset</ion-button>
<ion-button color="primary" (click)="datetime.cancel()">Never mind</ion-button>
<ion-button color="primary" (click)="datetime.confirm()">All Set</ion-button>
</ion-buttons>
</ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonButton, IonButtons, IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton, IonButtons, IonDatetime],
})
export class ExampleComponent {}
React
import React, { useRef } from 'react';
import { IonButtons, IonButton, IonDatetime } from '@ionic/react';
function Example() {
const datetime = useRef<null | HTMLIonDatetimeElement>(null);
const reset = () => {
datetime.current?.reset();
};
const cancel = () => {
datetime.current?.cancel();
};
const confirm = () => {
datetime.current?.confirm();
};
return (
<IonDatetime ref={datetime}>
<IonButtons slot="buttons">
<IonButton color="danger" onClick={reset}>
Reset
</IonButton>
<IonButton color="primary" onClick={cancel}>
Never mind
</IonButton>
<IonButton color="primary" onClick={confirm}>
All Set
</IonButton>
</IonButtons>
</IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime ref="datetime">
<ion-buttons slot="buttons">
<ion-button color="danger" @click="reset()">Reset</ion-button>
<ion-button color="primary" @click="cancel()">Never mind</ion-button>
<ion-button color="primary" @click="confirm()">All Set</ion-button>
</ion-buttons>
</ion-datetime>
</template>
<script setup lang="ts">
import { IonButtons, IonButton, IonDatetime } from '@ionic/vue';
import { ref } from 'vue';
const datetime = ref();
const reset = () => datetime.value.$el.reset();
const cancel = () => datetime.value.$el.cancel();
const confirm = () => datetime.value.$el.confirm();
</script>
특정 날짜 강조 (Highlighting Specific Dates)
highlightedDates 프로퍼티를 사용하면 특정 날짜에 커스텀 텍스트 또는 배경 색상을 입힐 수 있어요. 이 프로퍼티는 날짜와 색상의 배열, 또는 ISO 문자열을 받아 사용할 색상을 반환하는 콜백으로 정의할 수 있습니다.
색상을 지정할 때 유효한 CSS 색상 형식이면 무엇이든 사용할 수 있습니다. 여기에는 16진수 코드, rgba, 색상 변수(color variables) 등이 포함됩니다.
일관된 사용자 경험을 유지하기 위해 선택된 날짜의 스타일은 항상 커스텀 강조를 덮어씁니다.
참고 (Note)
이 프로퍼티는 preferWheel="false"이고 presentation이 "date", "date-time" 또는 "time-date" 중 하나일 때만 지원됩니다.
배열 사용 (Using Array)
강조가 마감일 같은 고정 날짜에 적용될 때는 배열이 더 좋습니다.
JavaScript
<ion-datetime presentation="date" value="2023-01-01"></ion-datetime>
<script>
var datetime = document.querySelector('ion-datetime');
datetime.highlightedDates = [
{
date: '2023-01-05',
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
},
{
date: '2023-01-10',
textColor: '#09721b',
backgroundColor: '#c8e5d0',
border: '1px solid #4caf50',
},
{
date: '2023-01-20',
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
},
{
date: '2023-01-23',
textColor: 'rgb(68, 10, 184)',
backgroundColor: 'rgb(211, 200, 229)',
border: '1px solid rgb(103, 58, 183)',
},
];
</script>
Angular
src/app/example.component.html
<ion-datetime presentation="date" value="2023-01-01" [highlightedDates]="highlightedDates"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {
highlightedDates = [
{
date: '2023-01-05',
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
},
{
date: '2023-01-10',
textColor: '#09721b',
backgroundColor: '#c8e5d0',
border: '1px solid #4caf50',
},
{
date: '2023-01-20',
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
},
{
date: '2023-01-23',
textColor: 'rgb(68, 10, 184)',
backgroundColor: 'rgb(211, 200, 229)',
border: '1px solid rgb(103, 58, 183)',
},
];
}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return (
<IonDatetime
presentation="date"
value="2023-01-01"
highlightedDates={[
{
date: '2023-01-05',
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
},
{
date: '2023-01-10',
textColor: '#09721b',
backgroundColor: '#c8e5d0',
border: '1px solid #4caf50',
},
{
date: '2023-01-20',
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
},
{
date: '2023-01-23',
textColor: 'rgb(68, 10, 184)',
backgroundColor: 'rgb(211, 200, 229)',
border: '1px solid rgb(103, 58, 183)',
},
]}
></IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime presentation="date" value="2023-01-01" :highlighted-dates="highlightedDates"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
const highlightedDates = [
{
date: '2023-01-05',
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
},
{
date: '2023-01-10',
textColor: '#09721b',
backgroundColor: '#c8e5d0',
border: '1px solid #4caf50',
},
{
date: '2023-01-20',
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
},
{
date: '2023-01-23',
textColor: 'rgb(68, 10, 184)',
backgroundColor: 'rgb(211, 200, 229)',
border: '1px solid rgb(103, 58, 183)',
},
];
</script>
콜백 사용 (Using Callback)
강조할 날짜가 생일이나 반복 회의처럼 반복될 때는 콜백이 더 좋습니다.
JavaScript
<ion-datetime presentation="date"></ion-datetime>
<script>
var datetime = document.querySelector('ion-datetime');
datetime.highlightedDates = (isoString) => {
const date = new Date(isoString);
const utcDay = date.getUTCDate();
if (utcDay % 5 === 0) {
return {
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
};
}
if (utcDay % 3 === 0) {
return {
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
};
}
return undefined;
};
</script>
Angular
src/app/example.component.html
<ion-datetime presentation="date" [highlightedDates]="highlightedDates"></ion-datetime>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {
highlightedDates = (isoString: string) => {
const date = new Date(isoString);
const utcDay = date.getUTCDate();
if (utcDay % 5 === 0) {
return {
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
};
}
if (utcDay % 3 === 0) {
return {
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
};
}
return undefined;
};
}
React
import React from 'react';
import { IonDatetime } from '@ionic/react';
function Example() {
return (
<IonDatetime
presentation="date"
highlightedDates={(isoString) => {
const date = new Date(isoString);
const utcDay = date.getUTCDate();
if (utcDay % 5 === 0) {
return {
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
};
}
if (utcDay % 3 === 0) {
return {
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
};
}
return undefined;
}}
></IonDatetime>
);
}
export default Example;
Vue
<template>
<ion-datetime presentation="date" :highlighted-dates="highlightedDates"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
const highlightedDates = (isoString) => {
const date = new Date(isoString);
const utcDay = date.getUTCDate();
if (utcDay % 5 === 0) {
return {
textColor: '#800080',
backgroundColor: '#ffc0cb',
border: '1px solid #e91e63',
};
}
if (utcDay % 3 === 0) {
return {
textColor: 'var(--ion-color-secondary)',
backgroundColor: 'rgb(var(--ion-color-secondary-rgb), 0.18)',
border: '1px solid var(--ion-color-secondary-shade)',
};
}
return undefined;
};
</script>
스타일링 (Styling)
전역 테마 (Global Theming)
Ionic의 강력한 테마 시스템을 사용하면 전체 앱을 특정 테마에 맞게 쉽게 바꿀 수 있어요. 이 예시에서는 Color Creator와 Stepped Color Generator를 사용해 ion-datetime에 사용할 로즈(rose) 색상 팔레트를 만들었습니다.
이 접근 방식의 장점은 ion-datetime뿐만 아니라 모든 컴포넌트가 자동으로 이 테마의 이점을 얻을 수 있다는 점입니다.
JavaScript
index.html
<ion-datetime color="rose"></ion-datetime>
<style>
ion-datetime {
--background: #fff1f2;
--background-rgb: 255, 241, 242;
border-radius: 16px;
box-shadow: rgba(var(--ion-color-rose-rgb), 0.3) 0px 10px 15px -3px;
}
</style>
theme/variables.css
/* Ionic Variables and Theming
* ---------------------------------------------------------------
* Any overrides to theme variables should be placed in this file.
* For more information, please see:
* http://ionicframework.com/docs/theming/
*/
/* This sets the CSS variables for the rose color */
:root {
--ion-color-rose: #831843;
--ion-color-rose-rgb: 131, 24, 67;
--ion-color-rose-contrast: #ffffff;
--ion-color-rose-contrast-rgb: 255, 255, 255;
--ion-color-rose-shade: #73153b;
--ion-color-rose-tint: #8f2f56;
}
/* This overrides the global CSS variables for both modes */
:root.ios,
:root.md {
--ion-background-color: #ffffff;
--ion-background-color-rgb: 255, 255, 255;
--ion-text-color: #881337;
--ion-text-color-rgb: 136, 19, 55;
--ion-text-color-step-50: #8e1e40;
--ion-text-color-step-100: #94294a;
--ion-text-color-step-150: #9a3453;
--ion-text-color-step-200: #a03f5c;
--ion-text-color-step-250: #a64b66;
--ion-text-color-step-300: #ac566f;
--ion-text-color-step-350: #b26178;
--ion-text-color-step-400: #b86c82;
--ion-text-color-step-450: #be778b;
--ion-text-color-step-500: #c48295;
--ion-text-color-step-550: #c98d9e;
--ion-text-color-step-600: #cf98a7;
--ion-text-color-step-650: #d5a3b1;
--ion-text-color-step-700: #dbaeba;
--ion-text-color-step-750: #e1bac3;
--ion-text-color-step-800: #e7c5cd;
--ion-text-color-step-850: #edd0d6;
--ion-text-color-step-900: #f3dbdf;
--ion-text-color-step-950: #f9e6e9;
--ion-background-color-step-50: #f9e6e9;
--ion-background-color-step-100: #f3dbdf;
--ion-background-color-step-150: #edd0d6;
--ion-background-color-step-200: #e7c5cd;
--ion-background-color-step-250: #e1bac3;
--ion-background-color-step-300: #dbaeba;
--ion-background-color-step-350: #d5a3b1;
--ion-background-color-step-400: #cf98a7;
--ion-background-color-step-450: #c98d9e;
--ion-background-color-step-500: #c48295;
--ion-background-color-step-550: #be778b;
--ion-background-color-step-600: #b86c82;
--ion-background-color-step-650: #b26178;
--ion-background-color-step-700: #ac566f;
--ion-background-color-step-750: #a64b66;
--ion-background-color-step-800: #a03f5c;
--ion-background-color-step-850: #9a3453;
--ion-background-color-step-900: #94294a;
--ion-background-color-step-950: #8e1e40;
}
/* This adds the rose color */
.ion-color-rose {
--ion-color-base: var(--ion-color-rose);
--ion-color-base-rgb: var(--ion-color-rose-rgb);
--ion-color-contrast: var(--ion-color-rose-contrast);
--ion-color-contrast-rgb: var(--ion-color-rose-contrast-rgb);
--ion-color-shade: var(--ion-color-rose-shade);
--ion-color-tint: var(--ion-color-rose-tint);
}
Angular
src/app/example.component.html
<ion-datetime color="rose"></ion-datetime>
src/app/example.component.css
ion-datetime {
--background: #fff1f2;
--background-rgb: 255, 241, 242;
border-radius: 16px;
box-shadow: rgba(var(--ion-color-rose-rgb), 0.3) 0px 10px 15px -3px;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
src/theme/variables.css
/* Ionic Variables and Theming
* ---------------------------------------------------------------
* Any overrides to theme variables should be placed in this file.
* For more information, please see:
* http://ionicframework.com/docs/theming/
*/
/* This sets the CSS variables for the rose color */
:root {
--ion-color-rose: #831843;
--ion-color-rose-rgb: 131, 24, 67;
--ion-color-rose-contrast: #ffffff;
--ion-color-rose-contrast-rgb: 255, 255, 255;
--ion-color-rose-shade: #73153b;
--ion-color-rose-tint: #8f2f56;
}
/* This overrides the global CSS variables for both modes */
:root.ios,
:root.md {
--ion-background-color: #ffffff;
--ion-background-color-rgb: 255, 255, 255;
--ion-text-color: #881337;
--ion-text-color-rgb: 136, 19, 55;
--ion-text-color-step-50: #8e1e40;
--ion-text-color-step-100: #94294a;
--ion-text-color-step-150: #9a3453;
--ion-text-color-step-200: #a03f5c;
--ion-text-color-step-250: #a64b66;
--ion-text-color-step-300: #ac566f;
--ion-text-color-step-350: #b26178;
--ion-text-color-step-400: #b86c82;
--ion-text-color-step-450: #be778b;
--ion-text-color-step-500: #c48295;
--ion-text-color-step-550: #c98d9e;
--ion-text-color-step-600: #cf98a7;
--ion-text-color-step-650: #d5a3b1;
--ion-text-color-step-700: #dbaeba;
--ion-text-color-step-750: #e1bac3;
--ion-text-color-step-800: #e7c5cd;
--ion-text-color-step-850: #edd0d6;
--ion-text-color-step-900: #f3dbdf;
--ion-text-color-step-950: #f9e6e9;
--ion-background-color-step-50: #f9e6e9;
--ion-background-color-step-100: #f3dbdf;
--ion-background-color-step-150: #edd0d6;
--ion-background-color-step-200: #e7c5cd;
--ion-background-color-step-250: #e1bac3;
--ion-background-color-step-300: #dbaeba;
--ion-background-color-step-350: #d5a3b1;
--ion-background-color-step-400: #cf98a7;
--ion-background-color-step-450: #c98d9e;
--ion-background-color-step-500: #c48295;
--ion-background-color-step-550: #be778b;
--ion-background-color-step-600: #b86c82;
--ion-background-color-step-650: #b26178;
--ion-background-color-step-700: #ac566f;
--ion-background-color-step-750: #a64b66;
--ion-background-color-step-800: #a03f5c;
--ion-background-color-step-850: #9a3453;
--ion-background-color-step-900: #94294a;
--ion-background-color-step-950: #8e1e40;
}
/* This adds the rose color */
.ion-color-rose {
--ion-color-base: var(--ion-color-rose);
--ion-color-base-rgb: var(--ion-color-rose-rgb);
--ion-color-contrast: var(--ion-color-rose-contrast);
--ion-color-contrast-rgb: var(--ion-color-rose-contrast-rgb);
--ion-color-shade: var(--ion-color-rose-shade);
--ion-color-tint: var(--ion-color-rose-tint);
}
React
src/main.tsx
import React from 'react';
import { IonDatetime } from '@ionic/react';
import './main.css';
function Example() {
return <IonDatetime color="rose"></IonDatetime>;
}
export default Example;
src/main.css
ion-datetime {
--background: #fff1f2;
--background-rgb: 255, 241, 242;
border-radius: 16px;
box-shadow: rgba(var(--ion-color-rose-rgb), 0.3) 0px 10px 15px -3px;
}
src/theme/variables.css
/* Ionic Variables and Theming
* ---------------------------------------------------------------
* Any overrides to theme variables should be placed in this file.
* For more information, please see:
* http://ionicframework.com/docs/theming/
*/
/* This sets the CSS variables for the rose color */
:root {
--ion-color-rose: #831843;
--ion-color-rose-rgb: 131, 24, 67;
--ion-color-rose-contrast: #ffffff;
--ion-color-rose-contrast-rgb: 255, 255, 255;
--ion-color-rose-shade: #73153b;
--ion-color-rose-tint: #8f2f56;
}
/* This overrides the global CSS variables for both modes */
:root.ios,
:root.md {
--ion-background-color: #ffffff;
--ion-background-color-rgb: 255, 255, 255;
--ion-text-color: #881337;
--ion-text-color-rgb: 136, 19, 55;
--ion-text-color-step-50: #8e1e40;
--ion-text-color-step-100: #94294a;
--ion-text-color-step-150: #9a3453;
--ion-text-color-step-200: #a03f5c;
--ion-text-color-step-250: #a64b66;
--ion-text-color-step-300: #ac566f;
--ion-text-color-step-350: #b26178;
--ion-text-color-step-400: #b86c82;
--ion-text-color-step-450: #be778b;
--ion-text-color-step-500: #c48295;
--ion-text-color-step-550: #c98d9e;
--ion-text-color-step-600: #cf98a7;
--ion-text-color-step-650: #d5a3b1;
--ion-text-color-step-700: #dbaeba;
--ion-text-color-step-750: #e1bac3;
--ion-text-color-step-800: #e7c5cd;
--ion-text-color-step-850: #edd0d6;
--ion-text-color-step-900: #f3dbdf;
--ion-text-color-step-950: #f9e6e9;
--ion-background-color-step-50: #f9e6e9;
--ion-background-color-step-100: #f3dbdf;
--ion-background-color-step-150: #edd0d6;
--ion-background-color-step-200: #e7c5cd;
--ion-background-color-step-250: #e1bac3;
--ion-background-color-step-300: #dbaeba;
--ion-background-color-step-350: #d5a3b1;
--ion-background-color-step-400: #cf98a7;
--ion-background-color-step-450: #c98d9e;
--ion-background-color-step-500: #c48295;
--ion-background-color-step-550: #be778b;
--ion-background-color-step-600: #b86c82;
--ion-background-color-step-650: #b26178;
--ion-background-color-step-700: #ac566f;
--ion-background-color-step-750: #a64b66;
--ion-background-color-step-800: #a03f5c;
--ion-background-color-step-850: #9a3453;
--ion-background-color-step-900: #94294a;
--ion-background-color-step-950: #8e1e40;
}
/* This adds the rose color */
.ion-color-rose {
--ion-color-base: var(--ion-color-rose);
--ion-color-base-rgb: var(--ion-color-rose-rgb);
--ion-color-contrast: var(--ion-color-rose-contrast);
--ion-color-contrast-rgb: var(--ion-color-rose-contrast-rgb);
--ion-color-shade: var(--ion-color-rose-shade);
--ion-color-tint: var(--ion-color-rose-tint);
}
Vue
src/components/Example.vue
<template>
<ion-datetime color="rose"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
<style>
ion-datetime {
--background: #fff1f2;
--background-rgb: 255, 241, 242;
border-radius: 16px;
box-shadow: rgba(var(--ion-color-rose-rgb), 0.3) 0px 10px 15px -3px;
}
</style>
src/theme/variables.css
/* Ionic Variables and Theming
* ---------------------------------------------------------------
* Any overrides to theme variables should be placed in this file.
* For more information, please see:
* http://ionicframework.com/docs/theming/
*/
/* This sets the CSS variables for the rose color */
:root {
--ion-color-rose: #831843;
--ion-color-rose-rgb: 131, 24, 67;
--ion-color-rose-contrast: #ffffff;
--ion-color-rose-contrast-rgb: 255, 255, 255;
--ion-color-rose-shade: #73153b;
--ion-color-rose-tint: #8f2f56;
}
/* This overrides the global CSS variables for both modes */
:root.ios,
:root.md {
--ion-background-color: #ffffff;
--ion-background-color-rgb: 255, 255, 255;
--ion-text-color: #881337;
--ion-text-color-rgb: 136, 19, 55;
--ion-text-color-step-50: #8e1e40;
--ion-text-color-step-100: #94294a;
--ion-text-color-step-150: #9a3453;
--ion-text-color-step-200: #a03f5c;
--ion-text-color-step-250: #a64b66;
--ion-text-color-step-300: #ac566f;
--ion-text-color-step-350: #b26178;
--ion-text-color-step-400: #b86c82;
--ion-text-color-step-450: #be778b;
--ion-text-color-step-500: #c48295;
--ion-text-color-step-550: #c98d9e;
--ion-text-color-step-600: #cf98a7;
--ion-text-color-step-650: #d5a3b1;
--ion-text-color-step-700: #dbaeba;
--ion-text-color-step-750: #e1bac3;
--ion-text-color-step-800: #e7c5cd;
--ion-text-color-step-850: #edd0d6;
--ion-text-color-step-900: #f3dbdf;
--ion-text-color-step-950: #f9e6e9;
--ion-background-color-step-50: #f9e6e9;
--ion-background-color-step-100: #f3dbdf;
--ion-background-color-step-150: #edd0d6;
--ion-background-color-step-200: #e7c5cd;
--ion-background-color-step-250: #e1bac3;
--ion-background-color-step-300: #dbaeba;
--ion-background-color-step-350: #d5a3b1;
--ion-background-color-step-400: #cf98a7;
--ion-background-color-step-450: #c98d9e;
--ion-background-color-step-500: #c48295;
--ion-background-color-step-550: #be778b;
--ion-background-color-step-600: #b86c82;
--ion-background-color-step-650: #b26178;
--ion-background-color-step-700: #ac566f;
--ion-background-color-step-750: #a64b66;
--ion-background-color-step-800: #a03f5c;
--ion-background-color-step-850: #9a3453;
--ion-background-color-step-900: #94294a;
--ion-background-color-step-950: #8e1e40;
}
/* This adds the rose color */
.ion-color-rose {
--ion-color-base: var(--ion-color-rose);
--ion-color-base-rgb: var(--ion-color-rose-rgb);
--ion-color-contrast: var(--ion-color-rose-contrast);
--ion-color-contrast-rgb: var(--ion-color-rose-contrast-rgb);
--ion-color-shade: var(--ion-color-rose-shade);
--ion-color-tint: var(--ion-color-rose-tint);
}
Datetime 헤더 (Datetime Header)
datetime 헤더는 title 슬롯의 콘텐츠와 선택된 날짜를 관리합니다.
참고 (Note)
preferWheel이 true로 설정되면 선택된 날짜가 렌더링되지 않습니다.
JavaScript
<ion-datetime presentation="date">
<span slot="title">Select Date</span>
</ion-datetime>
<style>
/*
* Custom Datetime Header Parts
* -------------------------------------------
*/
ion-datetime::part(datetime-header) {
background-color: orange;
}
ion-datetime::part(datetime-title) {
background-color: pink;
}
ion-datetime::part(datetime-selected-date) {
background-color: violet;
}
</style>
Angular
src/app/example.component.html
<ion-datetime presentation="date">
<span slot="title">Select Date</span>
</ion-datetime>
src/app/example.component.css
/*
* Custom Datetime Header Parts
* -------------------------------------------
*/
ion-datetime::part(datetime-header) {
background-color: orange;
}
ion-datetime::part(datetime-title) {
background-color: pink;
}
ion-datetime::part(datetime-selected-date) {
background-color: violet;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular/standalone';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['./example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
src/main.tsx
import React from 'react';
import { IonDatetime } from '@ionic/react';
import './main.css';
function Example() {
return (
<>
<IonDatetime presentation="date">
<span slot="title">Select Date</span>
</IonDatetime>
</>
);
}
export default Example;
src/main.css
/*
* Custom Datetime Header Parts
* -------------------------------------------
*/
ion-datetime::part(datetime-header) {
background-color: orange;
}
ion-datetime::part(datetime-title) {
background-color: pink;
}
ion-datetime::part(datetime-selected-date) {
background-color: violet;
}
Vue
<template>
<ion-datetime presentation="date">
<span slot="title">Select Date</span>
</ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
<style scoped>
/*
* Custom Datetime Header Parts
* -------------------------------------------
*/
ion-datetime::part(datetime-header) {
background-color: orange;
}
ion-datetime::part(datetime-title) {
background-color: pink;
}
ion-datetime::part(datetime-selected-date) {
background-color: violet;
}
</style>
캘린더 헤더 (Calendar Header)
캘린더 헤더는 날짜 탐색 컨트롤(월/연도 선택기와 이전/다음 버튼)과, 그리드 스타일 레이아웃을 사용할 때의 요일을 관리합니다.
헤더는 CSS shadow parts로 스타일링할 수 있습니다.
JavaScript
<ion-datetime presentation="date"></ion-datetime>
<style>
/*
* Custom Datetime Calendar Header Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-header) {
background-color: orange;
}
ion-datetime::part(month-year-button) {
background-color: lightblue;
}
ion-datetime::part(navigation-button) {
background-color: firebrick;
}
ion-datetime::part(previous-button) {
color: white;
}
ion-datetime::part(next-button) {
color: black;
}
ion-datetime::part(calendar-days-of-week) {
background-color: #9ad162;
color: white;
}
</style>
Angular
src/app/example.component.html
<ion-datetime presentation="date"></ion-datetime>
src/app/example.component.css
/*
* Custom Datetime Calendar Header Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-header) {
background-color: orange;
}
ion-datetime::part(month-year-button) {
background-color: lightblue;
}
ion-datetime::part(navigation-button) {
background-color: firebrick;
}
ion-datetime::part(previous-button) {
color: white;
}
ion-datetime::part(next-button) {
color: black;
}
ion-datetime::part(calendar-days-of-week) {
background-color: #9ad162;
color: white;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonDatetime } from '@ionic/angular/standalone';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['./example.component.css'],
imports: [IonDatetime],
})
export class ExampleComponent {}
React
src/main.tsx
import React from 'react';
import { IonDatetime } from '@ionic/react';
import './main.css';
function Example() {
return (
<>
<IonDatetime presentation="date"></IonDatetime>
</>
);
}
export default Example;
src/main.css
/*
* Custom Datetime Calendar Header Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-header) {
background-color: orange;
}
ion-datetime::part(month-year-button) {
background-color: lightblue;
}
ion-datetime::part(navigation-button) {
background-color: firebrick;
}
ion-datetime::part(previous-button) {
color: white;
}
ion-datetime::part(next-button) {
color: black;
}
ion-datetime::part(calendar-days-of-week) {
background-color: #9ad162;
color: white;
}
Vue
<template>
<ion-datetime presentation="date"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
<style scoped>
/*
* Custom Datetime Calendar Header Part
* -------------------------------------------
*/
ion-datetime::part(calendar-header) {
background-color: orange;
}
ion-datetime::part(month-year-button) {
background-color: lightblue;
}
ion-datetime::part(navigation-button) {
background-color: firebrick;
}
ion-datetime::part(previous-button) {
color: white;
}
ion-datetime::part(next-button) {
color: black;
}
ion-datetime::part(calendar-days-of-week) {
background-color: #9ad162;
color: white;
}
</style>
캘린더 일 (Calendar Days)
그리드 스타일 ion-datetime의 캘린더 날짜는 CSS shadow parts로 스타일링할 수 있습니다.
참고 (Note)
아래 예시는 2일 전의 날짜를 선택합니다. 단, 그 날짜가 지난 달이면 2일 뒤의 날짜를 선택합니다. 이는 모든 날짜, 현재 날짜, 선택된 날짜에 커스텀 스타일을 적용하는 방법을 보여주기 위한 데모용입니다.
JavaScript
<ion-datetime presentation="date"></ion-datetime>
<script>
const datetime = document.querySelector('ion-datetime');
const date = new Date();
// Set the value of the datetime to 2 days
// before the current day
let dayChange = -2;
// If the day we are going to set the value to
// is in the previous month then set the day 2 days
// later instead so it remains in the same month
if (date.getDate() + dayChange <= 0) {
dayChange = -dayChange;
}
// Set the value of the datetime to the day
// calculated above
date.setDate(date.getDate() + dayChange);
datetime.value = date.toISOString();
</script>
<style>
/*
* Custom Datetime Day Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-day) {
color: #da5296;
}
ion-datetime::part(calendar-day today) {
color: #8462d1;
}
ion-datetime::part(calendar-day):focus {
background-color: rgb(154 209 98 / 0.2);
box-shadow: 0px 0px 0px 4px rgb(154 209 98 / 0.2);
}
/*
* Custom Material Design Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.md::part(calendar-day active),
ion-datetime.md::part(calendar-day active):focus {
background-color: #9ad162;
border-color: #9ad162;
color: #fff;
}
ion-datetime.md::part(calendar-day today) {
border-color: #8462d1;
}
/*
* Custom iOS Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.ios::part(calendar-day active),
ion-datetime.ios::part(calendar-day active):focus {
background-color: rgb(154 209 98 / 0.2);
color: #9ad162;
}
</style>
Angular
src/app/example.component.html
<ion-datetime presentation="date" [(ngModel)]="datetime"></ion-datetime>
src/app/example.component.css
/*
* Custom Datetime Day Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-day) {
color: #da5296;
}
ion-datetime::part(calendar-day today) {
color: #8462d1;
}
ion-datetime::part(calendar-day):focus {
background-color: rgb(154 209 98 / 0.2);
box-shadow: 0px 0px 0px 4px rgb(154 209 98 / 0.2);
}
/*
* Custom Material Design Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.md::part(calendar-day active),
ion-datetime.md::part(calendar-day active):focus {
background-color: #9ad162;
border-color: #9ad162;
color: #fff;
}
ion-datetime.md::part(calendar-day today) {
border-color: #8462d1;
}
/*
* Custom iOS Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.ios::part(calendar-day active),
ion-datetime.ios::part(calendar-day active):focus {
background-color: rgb(154 209 98 / 0.2);
color: #9ad162;
}
src/app/example.component.ts
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
import { FormsModule } from '@angular/forms';
// ViewEncapsulation is turned off for this demo due to
// a lack of support for styling multiple css shadow parts
// See https://github.com/angular/angular/issues/22515
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
encapsulation: ViewEncapsulation.None,
imports: [IonDatetime, FormsModule],
})
export class ExampleComponent implements OnInit {
public datetime!: string;
ngOnInit() {
const date = new Date();
// Set the value of the datetime to 2 days
// before the current day
let dayChange = -2;
// If the day we are going to set the value to
// is in the previous month then set the day 2 days
// later instead so it remains in the same month
if (date.getDate() + dayChange <= 0) {
dayChange = -dayChange;
}
// Set the value of the datetime to the day
// calculated above
date.setDate(date.getDate() + dayChange);
this.datetime = date.toISOString();
}
}
React
src/main.tsx
import React, { useEffect, useState } from 'react';
import { IonDatetime } from '@ionic/react';
import './main.css';
function Example() {
const [datetime, setDatetime] = useState<string | null>(null);
useEffect(() => {
const date = new Date();
// Set the value of the datetime to 2 days
// before the current day
let dayChange = -2;
// If the day we are going to set the value to
// is in the previous month then set the day 2 days
// later instead so it remains in the same month
if (date.getDate() + dayChange <= 0) {
dayChange = -dayChange;
}
// Set the value of the datetime to the day
// calculated above
date.setDate(date.getDate() + dayChange);
setDatetime(date.toISOString());
}, []);
return <IonDatetime presentation="date" value={datetime}></IonDatetime>;
}
export default Example;
src/main.css
/*
* Custom Datetime Day Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-day) {
color: #da5296;
}
ion-datetime::part(calendar-day today) {
color: #8462d1;
}
ion-datetime::part(calendar-day):focus {
background-color: rgb(154 209 98 / 0.2);
box-shadow: 0px 0px 0px 4px rgb(154 209 98 / 0.2);
}
/*
* Custom Material Design Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.md::part(calendar-day active),
ion-datetime.md::part(calendar-day active):focus {
background-color: #9ad162;
border-color: #9ad162;
color: #fff;
}
ion-datetime.md::part(calendar-day today) {
border-color: #8462d1;
}
/*
* Custom iOS Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.ios::part(calendar-day active),
ion-datetime.ios::part(calendar-day active):focus {
background-color: rgb(154 209 98 / 0.2);
color: #9ad162;
}
Vue
<template>
<ion-datetime presentation="date" :value="datetime"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
import { ref } from 'vue';
let datetime = ref('');
const date = new Date();
// Set the value of the datetime to 2 days
// before the current day
let dayChange = -2;
// If the day we are going to set the value to
// is in the previous month then set the day 2 days
// later instead so it remains in the same month
if (date.getDate() + dayChange <= 0) {
dayChange = -dayChange;
}
// Set the value of the datetime to the day
// calculated above
date.setDate(date.getDate() + dayChange);
datetime = date.toISOString();
</script>
<style scoped>
/*
* Custom Datetime Day Parts
* -------------------------------------------
*/
ion-datetime::part(calendar-day) {
color: #da5296;
}
ion-datetime::part(calendar-day today) {
color: #8462d1;
}
ion-datetime::part(calendar-day):focus {
background-color: rgb(154 209 98 / 0.2);
box-shadow: 0px 0px 0px 4px rgb(154 209 98 / 0.2);
}
/*
* Custom Material Design Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.md::part(calendar-day active),
ion-datetime.md::part(calendar-day active):focus {
background-color: #9ad162;
border-color: #9ad162;
color: #fff;
}
ion-datetime.md::part(calendar-day today) {
border-color: #8462d1;
}
/*
* Custom iOS Datetime Day Parts
* -------------------------------------------
*/
ion-datetime.ios::part(calendar-day active),
ion-datetime.ios::part(calendar-day active):focus {
background-color: rgb(154 209 98 / 0.2);
color: #9ad162;
}
</style>
휠 선택기 (Wheel Pickers)
ion-datetime에 사용되는 휠은 shadow parts와 CSS 변수의 조합으로 스타일링할 수 있습니다. 이는 휠 스타일 datetime의 열과, 그리드 스타일 datetime의 월/연도 선택기에 모두 적용됩니다.
JavaScript
<style>
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-highlight-border-radius: 48px;
--wheel-fade-background-rgb: 245, 235, 247;
}
ion-datetime::part(wheel):focus {
background: rgb(109, 208, 164);
}
ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}
ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
</style>
<ion-datetime presentation="date" prefer-wheel="true"></ion-datetime>
Angular
src/app/example.component.html
<ion-datetime presentation="date" [preferWheel]="true"></ion-datetime>
src/app/example.component.css
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-highlight-border-radius: 48px;
--wheel-fade-background-rgb: 245, 235, 247;
}
ion-datetime::part(wheel):focus {
background: rgb(109, 208, 164);
}
ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}
ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
src/app/example.component.ts
import { Component, ViewEncapsulation } from '@angular/core';
import { IonDatetime } from '@ionic/angular';
// ViewEncapsulation is turned off for this demo due to
// a lack of support for styling multiple css shadow parts
// See https://github.com/angular/angular/issues/22515
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
encapsulation: ViewEncapsulation.None,
imports: [IonDatetime],
})
export class ExampleComponent {}
React
src/main.tsx
import React from 'react';
import { IonDatetime } from '@ionic/react';
import './main.css';
function Example() {
return <IonDatetime presentation="date" preferWheel={true}></IonDatetime>;
}
export default Example;
src/main.css
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-highlight-border-radius: 48px;
--wheel-fade-background-rgb: 245, 235, 247;
}
ion-datetime::part(wheel):focus {
background: rgb(109, 208, 164);
}
ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}
ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
Vue
<template>
<ion-datetime presentation="date" :prefer-wheel="true"></ion-datetime>
</template>
<script setup lang="ts">
import { IonDatetime } from '@ionic/vue';
</script>
<style scoped>
ion-datetime {
--background: rgb(245, 235, 247);
--background-rgb: 245, 235, 247;
--wheel-highlight-background: rgb(218, 216, 255);
--wheel-highlight-border-radius: 48px;
--wheel-fade-background-rgb: 245, 235, 247;
}
ion-datetime::part(wheel):focus {
background: rgb(109, 208, 164);
}
ion-datetime::part(wheel-item) {
color: rgb(255, 66, 97);
}
ion-datetime::part(wheel-item active) {
color: rgb(128, 30, 171);
}
</style>
시간대 (Time Zones)
Ionic의 ion-datetime은 datetime-local의 동작을 따라 datetime 컨트롤 안에서 시간대를 조작하거나 설정하지 않습니다. 다시 말해 "07:00"이라는 시간 값은 서로 다른 시간대에 따라 조정되지 않아요.
date-fns-tz 같은 라이브러리를 사용해 datetime 값을 원하는 시간대로 변환할 것을 권장합니다.
다음은 ISO-8601 문자열을 사용자 기기에 설정된 시간대로 표시하도록 포맷하는 예시입니다:
import { format, utcToZonedTime } from 'date-fns-tz';
// Get the time zone set on the user's device
const userTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
// Create a date object from a UTC date string
const date = new Date('2014-10-25T10:46:20Z');
// Use date-fns-tz to convert from UTC to a zoned time
const zonedTime = utcToZonedTime(date, userTimeZone);
// Create a formatted string from the zoned time
format(zonedTime, 'yyyy-MM-dd HH:mm:ssXXX', { timeZone: userTimeZone });
날짜 값 파싱 (Parsing Date Values)
ionChange 이벤트는 이벤트 페이로드에 날짜 값을 ISO-8601 문자열로 발생시킵니다. 이를 애플리케이션 요구 사항에 따라 포맷하는 것은 개발자의 책임이에요. 날짜 값을 포맷하려면 date-fns를 사용하는 것을 권장합니다.
다음은 ISO-8601 문자열을 월, 일, 연도로 표시하도록 포맷하는 예시입니다:
import { format, parseISO } from 'date-fns';
/**
* This is provided in the event
* payload from the `ionChange` event.
*
* The value is an ISO-8601 date string.
*/
const dateFromIonDatetime = '2021-06-04T14:23:00-04:00';
const formattedString = format(parseISO(dateFromIonDatetime), 'MMM d, yyyy');
console.log(formattedString); // Jun 4, 2021
유효한 포맷 토큰 전체 목록은 https://date-fns.org/docs/format을 참고하세요.
고급 Datetime 검증 및 조작
datetime 선택기는 정확한 형식을 선택하는 단순함을 제공하며, 표준화된 ISO 8601 datetime 형식을 사용해 datetime 값을 문자열로 유지합니다. 하지만 ion-datetime이 datetime 값을 검증하고 조작할 때 모든 상황을 해결하려 시도하지는 않는다는 점을 알아두세요. 특정 형식에서 datetime 값을 파싱하거나, 조작(날짜에 5일 더하기, 30분 빼기 등)하거나, 특정 로케일로 데이터를 포맷해야 한다면 JavaScript에서 날짜를 다루는 데 date-fns를 사용하는 것을 적극 권장합니다.
접근성 (Accessibility)
키보드 상호작용 (Keyboard Interactions)
ion-datetime은 컴포넌트 안의 포커스 가능한 요소 간을 탐색하기 위한 완전한 키보드 지원을 갖추고 있습니다. 다음 표는 각 키가 하는 일을 설명합니다:
| 키 | 설명 |
|---|---|
| Tab | 다음 포커스 가능한 요소로 포커스를 이동합니다. |
| Shift + Tab | 이전 포커스 가능한 요소로 포커스를 이동합니다. |
| Space 또는 Enter | 포커스 가능한 요소를 클릭합니다. |
날짜 그리드 (Date Grid)
| 키 | 설명 |
|---|---|
| ArrowUp | 이전 주의 같은 요일로 포커스를 이동합니다. |
| ArrowDown | 다음 주의 같은 요일로 포커스를 이동합니다. |
| ArrowRight | 다음 날로 포커스를 이동합니다. |
| ArrowLeft | 이전 날로 포커스를 이동합니다. |
| Home | 현재 주의 첫 번째 날로 포커스를 이동합니다. |
| End | 현재 주의 마지막 날로 포커스를 이동합니다. |
| PageUp | 날짜 그리드를 이전 달로 변경합니다. |
| PageDown | 날짜 그리드를 다음 달로 변경합니다. |
| Shift + PageUp | 날짜 그리드를 이전 해로 변경합니다. |
| Shift + PageDown | 날짜 그리드를 다음 해로 변경합니다. |
시간, 월, 연도 휠 (Time, Month, and Year Wheels)
Datetime의 휠 선택기는 내부적으로 Picker를 사용합니다. 휠 선택기의 접근성 기능에 대한 자세한 내용은 Picker Accessibility를 참고하세요.
Interfaces
DatetimeChangeEventDetail
interface DatetimeChangeEventDetail {
value?: string | null;
}
DatetimeCustomEvent
이 인터페이스는 필수는 아니지만, 이 컴포넌트에서 발생하는 Ionic 이벤트를 더 강력한 타입으로 다루기 위해 CustomEvent 인터페이스 대신 사용할 수 있어요.
interface DatetimeCustomEvent extends CustomEvent {
detail: DatetimeChangeEventDetail;
target: HTMLIonDatetimeElement;
}
Properties
cancelText
설명: 선택기의 취소(cancel) 버튼에 표시할 텍스트입니다.
속성(Attribute): cancel-text
타입(Type): string
기본값(Default): 'Cancel'
clearText
설명: 선택기의 "Clear"(지우기) 버튼에 표시할 텍스트입니다.
속성(Attribute): clear-text
타입(Type): string
기본값(Default): 'Clear'
color
설명: 애플리케이션의 색상 팔레트에서 사용할 색상을 지정합니다. 기본 옵션은 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", "dark"입니다. 색상에 대한 자세한 내용은 theming 문서를 참고하세요.
속성(Attribute): color
타입(Type): "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined
기본값(Default): undefined
dayValues
설명: 선택 가능한 날짜 목록을 만드는 데 사용되는 값입니다. 기본적으로 주어진 달의 모든 날이 표시됩니다. 하지만 달의 정확히 어떤 날짜를 표시할지 제어하려면 dayValues 입력에 숫자, 숫자 배열, 또는 쉼표로 구분된 숫자 문자열을 넣을 수 있습니다. 배열의 날짜에 선택된 달에 유효하지 않은 숫자(예: 2월의 31)가 있어도, 선택된 달에 유효하지 않은 날짜는 올바르게 표시되지 않는다는 점을 기억하세요.
속성(Attribute): day-values
타입(Type): number | number[] | string | undefined
기본값(Default): undefined
disabled
설명: true로 설정하면 사용자가 datetime과 상호작용할 수 없습니다.
속성(Attribute): disabled
타입(Type): boolean
기본값(Default): false
doneText
설명: 선택기의 "Done"(완료) 버튼에 표시할 텍스트입니다.
속성(Attribute): done-text
타입(Type): string
기본값(Default): 'Done'
firstDayOfWeek
설명: ion-datetime에 사용할 주의 첫 번째 요일입니다. 기본값은 0이며 일요일을 나타냅니다.
속성(Attribute): first-day-of-week
타입(Type): number
기본값(Default): 0
formatOptions
설명: 날짜와 시간을 위한 포맷 옵션입니다. 각각 Intl.DateTimeFormatOptions 타입의 'date' 및/또는 'time' 객체를 포함해야 합니다.
속성(Attribute): undefined
타입(Type): undefined | { date: DateTimeFormatOptions; time?: DateTimeFormatOptions | undefined; } | { date?: DateTimeFormatOptions | undefined; time: DateTimeFormatOptions; }
기본값(Default): undefined
highlightedDates
설명: 특정 날짜에 커스텀 텍스트와 배경 색상을 적용하는 데 사용됩니다. ISO 문자열과 색상을 포함하는 객체 배열이거나, ISO 문자열을 받아 색상을 반환하는 콜백일 수 있습니다. preferWheel="false" 상태의 date, date-time, time-date presentation에만 적용됩니다.
속성(Attribute): undefined
타입(Type): ((dateIsoString: string) => DatetimeHighlightStyle | undefined) | DatetimeHighlight[] | undefined
기본값(Default): undefined
hourCycle
설명: ion-datetime의 시간 주기입니다. 값이 설정되지 않으면 현재 로케일이 지정합니다.
속성(Attribute): hour-cycle
타입(Type): "h11" | "h12" | "h23" | "h24" | undefined
기본값(Default): undefined
hourValues
설명: 선택 가능한 시간 목록을 만드는 데 사용되는 값입니다. 기본적으로 24시간 체계에서는 023, 12시간 체계에서는 112 범위입니다. 하지만 정확히 어떤 시간을 표시할지 제어하려면 hourValues 입력에 숫자, 숫자 배열, 또는 쉼표로 구분된 숫자 문자열을 넣을 수 있습니다.
속성(Attribute): hour-values
타입(Type): number | number[] | string | undefined
기본값(Default): undefined
isDateEnabled
설명: 개별 날짜(캘린더 일)가 활성화되어 있는지 비활성화되어 있는지 반환합니다. true이면 그 날이 활성화/상호작용 가능해지고, false이면 비활성화/비상호작용이 됩니다. 이 함수는 특정 날의 ISO 8601 날짜 문자열을 받습니다. 기본적으로 모든 날이 활성화됩니다. 개발자는 이 함수로 특정 날을 비활성화하는 커스텀 로직을 작성할 수 있어요. 이 함수는 렌더링되는 각 캘린더 일(이전, 현재, 다음 달)에 대해 호출됩니다. 커스텀 구현은 버벅임(jank)을 피하기 위해 성능을 최적화해야 합니다.
속성(Attribute): undefined
타입(Type): ((dateIsoString: string) => boolean) | undefined
기본값(Default): undefined
locale
설명: ion-datetime에 사용할 로케일입니다. 이는 월과 일 이름 형식에 영향을 줍니다. "default" 값은 기기에 설정된 기본 로케일을 가리킵니다.
속성(Attribute): locale
타입(Type): string
기본값(Default): 'default'
max
설명: 허용되는 최대 datetime입니다. 값은 ISO 8601 datetime 형식 표준을 따르는 날짜 문자열이어야 합니다(예: 1996-12-19). 형식이 정확한 datetime에만 국한될 필요는 없어요. 예를 들어 최대값은 1994 같은 연도만 될 수도 있습니다. 기본값은 올해의 끝입니다.
속성(Attribute): max
타입(Type): string | undefined
기본값(Default): undefined
min
설명: 허용되는 최소 datetime입니다. 값은 ISO 8601 datetime 형식 표준을 따르는 날짜 문자열이어야 합니다(예: 1996-12-19). 형식이 정확한 datetime에만 국한될 필요는 없어요. 예를 들어 최소값은 1994 같은 연도만 될 수도 있습니다. 기본값은 오늘로부터 100년 전 연도의 시작입니다. 이는 virtual property로, 초기화 시 한 번 설정되며 첫 렌더링 후 값을 변경해도 업데이트되지 않습니다.
속성(Attribute): min
타입(Type): string | undefined
기본값(Default): undefined
minuteValues
설명: 선택 가능한 분 목록을 만드는 데 사용되는 값입니다. 기본적으로 분은 0~59 범위입니다. 하지만 정확히 어떤 분을 표시할지 제어하려면 minuteValues 입력에 숫자, 숫자 배열, 또는 쉼표로 구분된 숫자 문자열을 넣을 수 있습니다. 예를 들어 분 선택이 15분마다여야 한다면 이 입력 값은 minuteValues="0,15,30,45"가 됩니다.
속성(Attribute): minute-values
타입(Type): number | number[] | string | undefined
기본값(Default): undefined
mode
설명: mode는 어떤 플랫폼 스타일을 사용할지 결정합니다. 이는 virtual property로, 초기화 시 한 번 설정되며 첫 렌더링 후 값을 변경해도 업데이트되지 않습니다.
속성(Attribute): mode
타입(Type): "ios" | "md"
기본값(Default): undefined
monthValues
설명: 선택 가능한 월 목록을 만드는 데 사용되는 값입니다. 기본적으로 월 값은 1~12 범위입니다. 하지만 정확히 어떤 월을 표시할지 제어하려면 monthValues 입력에 숫자, 숫자 배열, 또는 쉼표로 구분된 숫자 문자열을 넣을 수 있습니다. 예를 들어 여름 달만 보여야 한다면 이 입력 값은 monthValues="6,7,8"이 됩니다. 월 번호는 0 기반 인덱스가 아닙니다. 즉 1월의 값은 1, 12월의 값은 12입니다.
속성(Attribute): month-values
타입(Type): number | number[] | string | undefined
기본값(Default): undefined
multiple
설명: true로 설정하면 여러 날짜를 한 번에 선택할 수 있습니다. presentation="date"와 preferWheel="false"에만 적용됩니다.
속성(Attribute): multiple
타입(Type): boolean
기본값(Default): false
name
설명: 폼 데이터와 함께 제출되는 컨트롤의 이름입니다.
속성(Attribute): name
타입(Type): string
기본값(Default): this.inputId
preferWheel
설명: true로 설정하면 가능한 경우 달력 그리드 대신 휠 선택기가 렌더링됩니다. false로 설정하면 가능한 경우 휠 선택기 대신 달력 그리드가 렌더링됩니다. presentation이 "date", "date-time", "time-date" 중 하나일 때 휠 선택기를 그리드 대신 렌더링할 수 있어요. presentation이 "time", "month", "month-year", "year" 중 하나일 때는 preferWheel 값과 무관하게 항상 휠 선택기가 렌더링됩니다.
속성(Attribute): prefer-wheel
타입(Type): boolean
기본값(Default): false
presentation
설명: 어떤 값을 선택할지 지정합니다. "date"는 월, 일, 연도를 선택하는 달력 선택기를 표시합니다. "time"은 시, 분, (선택적으로) AM/PM을 선택하는 시간 선택기를 표시합니다. "date-time"은 날짜 선택기를 먼저, 시간 선택기를 나중에 표시합니다. "time-date"는 시간 선택기를 먼저, 날짜 선택기를 나중에 표시합니다.
속성(Attribute): presentation
타입(Type): "date" | "date-time" | "month" | "month-year" | "time" | "time-date" | "year"
기본값(Default): 'date-time'
readonly
설명: true로 설정하면 datetime이 정상적으로 보이지만 선택된 날짜는 변경할 수 없습니다.
속성(Attribute): readonly
타입(Type): boolean
기본값(Default): false
showAdjacentDays
설명: true로 설정하면 datetime 캘린더가 그리드를 채우기 위해 이전/다음 달의 날짜를 포함한 6주(42일) 레이아웃을 표시합니다. 이러한 인접한 날짜는 비활성화되지 않는 한 선택할 수 있습니다.
속성(Attribute): show-adjacent-days
타입(Type): boolean
기본값(Default): false
showClearButton
설명: true로 설정하면 ion-datetime 컴포넌트 하단에 기본 "Cancel" 및 "OK" 버튼과 함께 "Clear"(지우기) 버튼이 렌더링됩니다. 개발자는 이러한 버튼을 커스터마이즈하려면 button 슬롯을 사용할 수도 있어요. button 슬롯에 커스텀 버튼이 설정되면 기본 버튼은 렌더링되지 않습니다.
속성(Attribute): show-clear-button
타입(Type): boolean
기본값(Default): false
showDefaultButtons
설명: true로 설정하면 ion-datetime 컴포넌트 하단에 기본 "Cancel" 및 "OK" 버튼이 렌더링됩니다. 개발자는 이러한 버튼을 커스터마이즈하려면 button 슬롯을 사용할 수도 있어요. button 슬롯에 커스텀 버튼이 설정되면 기본 버튼은 렌더링되지 않습니다.
속성(Attribute): show-default-buttons
타입(Type): boolean
기본값(Default): false
showDefaultTimeLabel
설명: true로 설정하면 ion-datetime 컴포넌트의 시간 선택기에 기본 "Time" 라벨이 렌더링됩니다. 개발자는 이 라벨을 커스터마이즈하려면 time-label 슬롯을 사용할 수도 있어요. time-label 슬롯에 커스텀 라벨이 설정되면 기본 라벨은 렌더링되지 않습니다.
속성(Attribute): show-default-time-label
타입(Type): boolean
기본값(Default): true
showDefaultTitle
설명: true로 설정하면 캘린더 선택기 위에 헤더가 표시됩니다. 여기에는 슬롯된 타이틀과 선택된 날짜가 모두 포함됩니다.
속성(Attribute): show-default-title
타입(Type): boolean
기본값(Default): false
size
설명: cover이면 ion-datetime이 컨테이너 전체 너비를 덮도록 확장됩니다. fixed이면 ion-datetime이 고정된 너비를 가집니다.
속성(Attribute): size
타입(Type): "cover" | "fixed"
기본값(Default): 'fixed'
titleSelectedDatesFormatter
설명: 선택된 날짜의 수를 보여주는 헤더 텍스트를 포맷하는 데 사용되는 콜백입니다. 선택된 날짜가 0개 또는 1개보다 많을 때만 사용됩니다(즉, 정확히 1개일 때는 사용되지 않음). 기본적으로 헤더 텍스트는 "numberOfDates days"로 설정됩니다. 콜백 내부에서 this에 접근해야 한다면 https://ionicframework.com/docs/troubleshooting/runtime#accessing-this를 참고하세요.
속성(Attribute): undefined
타입(Type): ((selectedDates: string[]) => string) | undefined
기본값(Default): undefined
value
설명: 유효한 ISO 8601 datetime 문자열로서의 datetime 값입니다. 이 값은 multiple="true"일 때만 문자열 배열이어야 합니다.
속성(Attribute): value
타입(Type): null | string | string[] | undefined
기본값(Default): undefined
yearValues
설명: 선택 가능한 연도 목록을 만드는 데 사용되는 값입니다. 기본적으로 연도 값은 min과 max datetime 입력 사이의 범위입니다. 하지만 정확히 어떤 연도를 표시할지 제어하려면 yearValues 입력에 숫자, 숫자 배열, 또는 쉼표로 구분된 숫자 문자열을 넣을 수 있습니다. 예를 들어 다가오고 지난 윤년을 표시하려면 이 입력 값은 yearValues="2008,2012,2016,2020,2024"가 됩니다.
속성(Attribute): year-values
타입(Type): number | number[] | string | undefined
기본값(Default): undefined
Events
| 이름(Name) | 설명(Description) | 버블링(Bubbles) |
|---|---|---|
ionBlur |
datetime이 포커스를 잃었을 때 발생합니다. | true |
ionCancel |
datetime 선택이 취소되었을 때 발생합니다. | true |
ionChange |
값(선택된 날짜)이 변경되었을 때 발생합니다. value 프로퍼티를 프로그래밍 방식으로 설정할 때는 이 이벤트가 발생하지 않습니다. |
true |
ionFocus |
datetime에 포커스가 있을 때 발생합니다. | true |
Methods
cancel
설명: ionCancel 이벤트를 발생시키고 선택적으로 datetime이 표시된 popover 또는 modal을 닫습니다.
시그니처(Signature): cancel(closeOverlay?: boolean) => Promise<void>
매개변수(Parameters): closeOverlay: true이면 부모 오버레이를 닫습니다. 기본값은 false입니다.
confirm
설명: 선택된 datetime 값을 확인하고 value 프로퍼티를 업데이트하며, 선택적으로 datetime이 표시된 popover 또는 modal을 닫습니다.
시그니처(Signature): confirm(closeOverlay?: boolean) => Promise<void>
매개변수(Parameters): closeOverlay: true이면 부모 오버레이를 닫습니다. 기본값은 false입니다.
reset
설명: datetime의 내부 상태를 리셋하지만 값은 업데이트하지 않습니다. 유효한 ISO-8601 문자열을 전달하면 컴포넌트의 상태를 제공된 날짜로 리셋합니다. 값이 제공되지 않으면 내부 상태가 min, max, today의 값 중 제한된(clamped) 값으로 리셋됩니다.
시그니처(Signature): reset(startDate?: string) => Promise<void>
매개변수(Parameters): startDate: datetime 상태를 리셋할 유효한 ISO-8601 문자열입니다.
CSS Shadow Parts
| 이름(Name) | 설명(Description) |
|---|---|
calendar-day |
datetime 캘린더 안에 날짜를 표시하는 개별 버튼입니다. |
calendar-day active |
현재 선택된 캘린더 날짜입니다. |
calendar-day disabled |
비활성화된 캘린더 날짜입니다. |
calendar-day today |
현재 날짜가 포함된 캘린더 날짜입니다. |
calendar-days-of-week |
그리드 스타일 레이아웃을 사용할 때 요일 헤더(평일과 주말 모두)의 컨테이너입니다. |
calendar-header |
캘린더 헤더는 날짜 탐색 컨트롤(월/연도 선택기와 이전/다음 버튼)과, 그리드 스타일 레이아웃을 사용할 때의 요일을 관리합니다. |
datetime-header |
datetime 헤더는 title 슬롯의 콘텐츠와 선택된 날짜를 포함합니다. |
datetime-selected-date |
선택된 날짜를 포함하는 요소입니다. |
datetime-title |
title 슬롯 콘텐츠를 포함하는 요소입니다. |
month-year-button |
그리드 스타일 레이아웃을 사용할 때 월/연도 선택기를 여는 버튼입니다. |
navigation-button |
그리드 스타일 레이아웃을 사용할 때 다음 또는 이전 달로 이동하는 데 사용되는 버튼입니다. |
next-button |
그리드 스타일 레이아웃을 사용할 때 다음 달로 이동하는 데 사용되는 버튼입니다. |
previous-button |
그리드 스타일 레이아웃을 사용할 때 이전 달로 이동하는 데 사용되는 버튼입니다. |
time-button |
presentation="date-time" 또는 "time-date"와 함께 그리드 스타일 레이아웃을 사용할 때 시간 선택기를 여는 버튼입니다. |
time-button active |
선택기가 열려 있을 때의 시간 선택기 버튼입니다. |
wheel |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 휠 컨테이너입니다. |
wheel-item |
휠 스타일 레이아웃에서의 개별 항목이거나, 그리드 스타일 레이아웃의 월/연도 선택기에서의 개별 항목입니다. |
wheel-item active |
현재 선택된 wheel-item입니다. |
CSS Custom Properties
iOS
| 이름(Name) | 설명(Description) |
|---|---|
--background |
datetime 컴포넌트의 기본 배경입니다. |
--background-rgb |
RGB 형식의 datetime 컴포넌트 기본 배경입니다. |
--title-color |
타이틀의 텍스트 색상입니다. |
--wheel-fade-background-rgb |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택되지 않은 항목을 덮는 그라데이션 색상입니다. RGB 형식이어야 합니다(예: 255, 255, 255). |
--wheel-highlight-background |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택된 항목 아래 하이라이트의 배경입니다. |
--wheel-highlight-border-radius |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택된 항목 아래 하이라이트의 테두리 모서리 반경입니다. |
MD
| 이름(Name) | 설명(Description) |
|---|---|
--background |
datetime 컴포넌트의 기본 배경입니다. |
--background-rgb |
RGB 형식의 datetime 컴포넌트 기본 배경입니다. |
--title-color |
타이틀의 텍스트 색상입니다. |
--wheel-fade-background-rgb |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택되지 않은 항목을 덮는 그라데이션 색상입니다. RGB 형식이어야 합니다(예: 255, 255, 255). |
--wheel-highlight-background |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택된 항목 아래 하이라이트의 배경입니다. |
--wheel-highlight-border-radius |
휠 스타일 레이아웃을 사용할 때, 또는 그리드 스타일 레이아웃의 월/연도 선택기에서 선택된 항목 아래 하이라이트의 테두리 모서리 반경입니다. |
Slots
| 이름(Name) | 설명(Description) |
|---|---|
buttons |
datetime의 버튼입니다. |
time-label |
datetime의 시간 선택기 라벨입니다. |
title |
datetime의 타이틀입니다. |
더 알아보기 (Learn more)
ion-datetime은 날짜와 시간 선택을 위한 가장 강력한 Ionic 컴포넌트 중 하나예요. ISO 8601 형식의 값, presentation으로 그리드/휠 선택기 전환, locale·hourCycle 지역화, min/max·isDateEnabled 날짜 제약, highlightedDates 날짜 강조 등 다양한 옵션을 제공합니다. 모달/팝오버에 넣을 땐 ion-datetime-button을 함께 사용하면 공간을 절약할 수 있어요.