logo dile-components dile-components

dile-datetimepicker

Extension of dile-datepicker that adds time selection to the date picker. Allows selecting both date and time in a single component.

The calendar also lets you choose the month and year with scrolling columns, and supports the minYear, maxYear, minDate, maxDate, disableDates, weekdayHeaderNotation, locale, validateDate and validationMessages properties, as described in the dile-datepicker month and year section.

How it works

Installation

npm i @dile/utils

Usage

Import the component:

import '@dile/utils/components/datepicker/datetimepicker.js';

Use the component:

<dile-datetimepicker label="Select date and time"></dile-datetimepicker>

Properties

This component inherits all properties from dile-datepicker. In addition, the selected value will have the format "YYYY-MM-DD HH:mm:ss".

Property Type Default Description
acceptLabel String 'Accept date and time' Accessible label (aria-label and title) for the confirmation button
showSeconds Boolean false Shows the seconds wheel and the seconds in the time button
minuteStep Number 1 Step between the values of the minutes wheel (1 to 59). A minute of the value out of the step is also listed
secondStep Number 1 Step between the values of the seconds wheel (1 to 59)
timeLabel String 'Time' Accessible label and title of the time button and the time layer
timeAcceptLabel String 'OK' Accessible label of the check button that closes the time layer

The wheels are labelled with the names of the hour, minute and second fields in the locale language (or the page language).

Methods

Inherits all methods from dile-datepicker. In addition:

Method Description
acceptTime() Writes the marked day (or the focused day) and the selected time in the field and closes the picker
openTimePicker() Shows the time wheels over the calendar
closeTimePicker() Hides the time wheels

The read-only selectedTime getter returns the selected time as "HH:mm:ss", and timePickerOpened says whether the time wheels are visible.

Events

Inherits all events from dile-datepicker.

CSS Custom Properties

In addition to all CSS Custom Properties from dile-datepicker, you can customize the following new aspects specific to dile-datetimepicker:

Custom property Description Default
--dile-datetimepicker-accept-icon-size Size of the accept icon 24px
--dile-datetimepicker-accept-icon-color Color of the accept icon var(--dile-on-primary-color, #888)
--dile-datetimepicker-accept-icon-background-color Background color of the rounded accept icon var(--dile-primary-color, #f4f4f4)
--dile-datetimepicker-accept-focus-ring-color Focus outline color for the accept button var(--dile-primary-color, #2563eb)
--dile-datetimepicker-time-color Text color of the time button var(--dile-calendar-day-text-color, #303030)
--dile-datetimepicker-time-font-size Font size of the time button 1.1rem
--dile-datetimepicker-wheel-width Width of each time wheel 4.5rem

The time wheels use the same --dile-calendar-wheel-* custom properties as the month and year columns of the calendar (see dile-datepicker).

Examples

Regular datetimepicker

<script type="module">
  import '@dile/utils/components/datepicker/datetimepicker.js';
</script>
<dile-datetimepicker 
  name="datetimepicker1" 
  id="datetimepicker1" 
  label="Date"
></dile-datetimepicker>

Styled datetimepicker appears at the bottom

Styled datetimepicker
<style>
  .styled {
    --dile-input-label-color: #6d3d6c;
    --dile-input-label-font-weight: bold;
    --dile-input-border-radius: 0;
    --dile-input-border-color: #6d3d6c;
    --dile-input-border-width: 2px;
    --dile-input-label-margin-bottom: 0.5rem;
    --dile-input-line-height: 2.5rem;
    --dile-input-background-color: #ffc;
    --dile-input-color: #963;
    --dile-menu-overlay-background-color: rgb(143, 143, 34);
    --dile-menu-overlay-color: #fff;
    --dile-datepicker-trigger-color: #6d3d6c; 
    --dile-calendar-day-background-color: rgb(130, 79, 12);
    --dile-calendar-today-background-color: rgb(233, 47, 223);
    --dile-calendar-day-text-color: #fff;
    --dile-calendar-day-border-radius: 7px;
    --dile-calendar-nav-buttons-color: #fff;
    --dile-datepicker-trigger-margin-bottom: 0.1em;
    --dile-datepicker-trigger-size: 50px;
  }
</style>
<dile-datetimepicker 
  name="datetimepicker2" 
  id="datetimepicker2" 
  class="styled" 
  label="Event date" 
  verticalAlign="bottom"
>Styled datetimepicker</dile-datetimepicker>

Datetimepicker with seconds and steps

<dile-datetimepicker 
  name="datetimepicker4" 
  label="Meeting"
  showSeconds
  minuteStep="15"
  secondStep="10"
></dile-datetimepicker>

Datetimepicker with Monday as first day of week

<dile-datetimepicker 
  firstDayOfWeek="1" 
  name="datetimepicker3" 
  id="datetimepicker3" 
  label="Event date"
></dile-datetimepicker>

Disabled datetimepicker

Disabled datetimepicker
<dile-datetimepicker 
  name="disabelddatetimepicker" 
  disabled 
  id="disabelddatetimepicker"
>Disabled datetimepicker</dile-datetimepicker>