본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

ion-datetime-button

원문 보기 위키 갱신

Datetime Button은 Datetime 컴포넌트와 연결되어 포맷된 날짜와 시간을 표시하는 버튼이에요. 모달, 팝오버 등에서 datetime을 열어 보여주기 위한 버튼도 함께 제공합니다.

출처: 문서

본문

Datetime Button은 공간이 제한될 때 사용하면 좋아요. 이 컴포넌트는 현재 날짜와 시간 값을 보여주는 버튼을 표시하며, 버튼을 탭하면 날짜나 시간 선택기가 오버레이에서 열립니다.

Angular, React, Vue 같은 JavaScript 프레임워크에서 Datetime Button을 사용할 때는 반드시 ion-modal의 keepContentsMounted property나 ion-popover의 keepContentsMounted property를 사용해야 해요. 그래야 오버레이가 아직 표시되지 않았더라도 연결된 datetime 인스턴스가 마운트된 상태를 유지합니다.

기본 사용법 (Basic Usage)

JavaScript

<ion-datetime-button datetime="datetime"></ion-datetime-button>

<ion-modal>
  <ion-datetime id="datetime"></ion-datetime>
</ion-modal>

Angular

src/app/example.component.html

<ion-datetime-button datetime="datetime"></ion-datetime-button>

<ion-modal [keepContentsMounted]="true">
  <ng-template>
    <ion-datetime id="datetime"></ion-datetime>
  </ng-template>
</ion-modal>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonDatetime, IonDatetimeButton, IonModal],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/react';
function Example() {
  return (
    <>
      <IonDatetimeButton datetime="datetime"></IonDatetimeButton>

      <IonModal keepContentsMounted={true}>
        <IonDatetime id="datetime"></IonDatetime>
      </IonModal>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-datetime-button datetime="datetime"></ion-datetime-button>

  <ion-modal :keep-contents-mounted="true">
    <ion-datetime id="datetime"></ion-datetime>
  </ion-modal>
</template>

<script setup lang="ts">
  import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/vue';
</script>

지역화 (Localization)

ion-datetime-button에 표시되는 지역화 텍스트는 연결된 ion-datetime 인스턴스의 locale 프로퍼티에 의해 결정됩니다. 자세한 내용은 Datetime Localization 문서를 참고하세요.

포맷 옵션 (Format Options)

연결된 Datetime 인스턴스에 formatOptions를 제공하면 Datetime Button에서 표시되는 날짜와 시간의 포맷을 커스터마이즈할 수 있어요. 자세한 내용은 Datetime Format Options 문서를 참고하세요.

JavaScript

<ion-datetime-button datetime="datetime"></ion-datetime-button>

<ion-modal keep-contents-mounted="true">
  <ion-datetime id="datetime" presentation="date-time" value="2023-11-02T01:22:00"></ion-datetime>
</ion-modal>

<script>
  const datetime = document.querySelector('ion-datetime');
  datetime.formatOptions = {
    date: {
      weekday: 'short',
      month: 'long',
      day: '2-digit',
    },
    time: {
      hour: '2-digit',
      minute: '2-digit',
    },
  };
</script>

Angular

src/app/example.component.html

<ion-datetime-button datetime="datetime"></ion-datetime-button>

<ion-modal [keepContentsMounted]="true">
  <ng-template>
    <ion-datetime
      id="datetime"
      presentation="date-time"
      value="2023-11-02T01:22:00"
      [formatOptions]="{
        date: {
          weekday: 'short',
          month: 'long',
          day: '2-digit',
        },
        time: {
          hour: '2-digit',
          minute: '2-digit',
        },
      }"
    ></ion-datetime>
  </ng-template>
</ion-modal>

src/app/example.component.ts

import { Component } from '@angular/core';
import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonDatetime, IonDatetimeButton, IonModal],
})
export class ExampleComponent {}

React

import React from 'react';
import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/react';

function Example() {
  return (
    <>
      <IonDatetimeButton datetime="datetime"></IonDatetimeButton>

      <IonModal keepContentsMounted={true}>
        <IonDatetime
          id="datetime"
          presentation="date-time"
          value="2023-11-02T01:22:00"
          formatOptions={{
            date: {
              weekday: 'short',
              month: 'long',
              day: '2-digit',
            },
            time: {
              hour: '2-digit',
              minute: '2-digit',
            },
          }}
        ></IonDatetime>
      </IonModal>
    </>
  );
}
export default Example;

Vue

<template>
  <ion-datetime-button datetime="datetime"></ion-datetime-button>

  <ion-modal :keep-contents-mounted="true">
    <ion-datetime
      id="datetime"
      presentation="date-time"
      value="2023-11-02T01:22:00"
      :format-options="formatOptions"
    ></ion-datetime>
  </ion-modal>
</template>

<script setup lang="ts">
  import { IonDatetime, IonDatetimeButton, IonModal } from '@ionic/vue';

  const formatOptions = {
    date: {
      weekday: 'short',
      month: 'long',
      day: '2-digit',
    },
    time: {
      hour: '2-digit',
      minute: '2-digit',
    },
  };
</script>

모달 및 팝오버와 함께 사용하기 (Usage with Modals and Popovers)

ion-datetime-button은 마운트된 ion-datetime 인스턴스와 연결되어 있어야 해요. 따라서 keepContentsMounted 프로퍼티가 true로 설정된 Inline Modals와 Inline Popovers를 반드시 사용해야 합니다.

Properties

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

datetime

설명: datetime 버튼과 연결된 ion-datetime 인스턴스의 ID입니다.

속성(Attribute): datetime

타입(Type): string | undefined

기본값(Default): undefined

disabled

설명: true로 설정하면 사용자가 버튼과 상호작용할 수 없습니다.

속성(Attribute): disabled

타입(Type): boolean

기본값(Default): false

mode

설명: mode는 어떤 플랫폼 스타일을 사용할지 결정합니다. 이는 virtual property로, 초기화 시 한 번 설정되며 첫 렌더링 후 값을 변경해도 업데이트되지 않습니다.

속성(Attribute): mode

타입(Type): "ios" | "md"

기본값(Default): undefined

Events

이 컴포넌트에서 사용할 수 있는 이벤트가 없습니다.

Methods

이 컴포넌트에서 사용할 수 있는 공개 메서드가 없습니다.

CSS Shadow Parts

이름(Name) 설명(Description)
native 슬롯된 텍스트를 감싸는 네이티브 HTML 버튼입니다.

CSS Custom Properties

이 컴포넌트에서 사용할 수 있는 CSS 커스텀 프로퍼티가 없습니다.

Slots

이름(Name) 설명(Description)
date-target 날짜 버튼 안에 표시되는 콘텐츠입니다.
time-target 시간 버튼 안에 표시되는 콘텐츠입니다.

더 알아보기 (Learn more)

ion-datetime-button은 화면 공간이 부족할 때 ion-datetime을 모달이나 팝오버로 띄우기 위한 진입점 역할을 해요. 실제 날짜·시간 선택 로직은 전부 연결된 ion-datetime이 담당하므로, ion-datetime 문서에서 presentation, formatOptions, locale 등 옵션을 더 자세히 살펴보면 좋습니다.