New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

input-dt

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

input-dt

input-dt is a JavaScript library for entering datetime.

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

input-dt

input-dt is a library for datetime input. You can use it without JavaScript. Easy to use with PHP.

  • A custom element
  • Framework independent
  • Automatically localized
  • Dark mode support
  • Date periods support
  • Customizable
スクリーンショット 2024-04-07 205616 スクリーンショット 2024-04-07 2056582

Basic usage

Import js and css files beforehand. This is an example of importing from a CDN.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/input-dt@0.1.0/input-dt-min.css">
<script type="module" src="https://cdn.jsdelivr.net/npm/input-dt@0.1.0/input-dt-min.js"></script>

To start, write an input[type="text"] tag and enclose it in an input-dt tag. You can optionally add attributes to the input-dt tag.

Next, add the input-dt attribute to the input[type="text"].

The picker is added as the last element of the input-dt.

<label for="calender">Datetime:</label>
<input-dt
  value="2024-03-10"
  min="2024-01-01"
  max="2026-12-31"
  disable="2024-08-31,2024-12-31"
  hours="0,3,6,9,12,15,18,21"
  minutes="0,10,20,30,40,50"
  seconds="0,10,20,30,40,50"
  unit="seconds"
  locales="ja"
  first-day="0"
  background="true"
  auto-close="true"
>
  <input type="text" name="calender" input-dt>
</input-dt>

More examples

See the examples directory for examples in HTML only, Bootstrap, Vue.js, React, Jito, and PHP.

Import for Node.js

npm i input-dt

Import js and css at entry point.

import 'input-dt'
import 'input-dt/input-dt.css'

Attributes for child elements

AttributeDescription
input-dtThis attribute can be attached to input[type="text"] or input[type="datetime-local"], which opens the picker when the focus is set. It will also fire an input event whenever any datetime is selected. Optionally supports formatting. The supported formats are described below.
input-dt-openIf this attribute is specified, the picker will be opened when the element is clicked.
input-dt-clearIf this attribute is specified, clicking on the element will clear the date/time value.
input-dt-displayIf this attribute is specified, each time a datetime is selected, the element's children are overwritten with text nodes representing the datetime. Optionally supports formatting. The supported formats are described below.
input-dt-valueWhen associated with an element, it updates the value of the element when a date/time is selected. Optionally supports formatting. The supported formats are described below.

Attributes for the input-dt element

The input-dt element provides several attributes. These are default values and also detect dynamic changes.

AttributeDescription
valueValue selected by input-dt.
minMinimum number of selectable dates. By default, New Year's Day 120 years ago.
A comma-separated list of dates in the format YYYY-MM-DD and a selector string identifying other dt-picker elements. If multiple dates are given, the most recent date is used.
maxMaximum selectable dates. By default, the last day of the year after 10 years.
A comma-separated list of dates in the format YYYY-MM-DD and a selector string identifying other dt-picker elements. If multiple dates are given, the earliest date is used.
disableList of dates that cannot be selected.
A comma-separated list of dates in the format YYYY-MM-DD and a selector string identifying other dt-picker elements.
hoursOptions for the hour.
minutesOptions for the minute.
secondsOptions for the second.
unitMinimum unit of datetime. day - date picker only, or hour, minute, second(default).
localesA locale identifier used for all parts of the modal. By default, it will be the default locale of the web browser.
first-dayFirst day of the week. An integer, between 0 and 6. By default, this is the default locale of the web browser. However, FireFox is not supported, so the value is 0.
backgroundNormally, a modal is closed by clicking somewhere other than the modal. This is done by receiving the click event of the document. Therefore, if there is an element that stops the propagation of events, the modal will not close.
If the background attribute is set to true, a filter that closes the modal on click will cover the entire screen.
autocloseIf set to true, the modal will only close when a date is selected in the date picker only.

All supported formats

input-dt, input-dt-display and input-dt-value support formatting as attribute values. See the following table. If you do not specify a format, it defaults to the localized format.

FormatOutputNote
yy26The 2-digit year
yyyy2026The 4-digit year
YYYY2026The full year
M1 to 12The numeric month
MM01 to 12The 2-digit month
D1 to 31The numeric day of month
DD01 to 31The 2-digit day of month
H0 to 23The numeric hour
HH00 to 23The 2-digit hour
m0 to 59The numeric minute
mm00 to 59The 2-digit minute
s0 to 59The numeric second
ss00 to 59The 2-digit second

Customize Style

You can easily change the style.

Simple Customize

You can customise colours using CSS custom properties.

.input-dt {
  --input-dt-color: #FFF;
  --input-dt-background: #323232;
  --input-dt-highlight: rgb(136, 214, 83);
  --input-dt-disable: #777;
  --input-dt-outside: #BBB;
  --input-dt-outside-visibility: visible;
  --input-dt-font-family: serif;
}
image

CSS overwrite

You can use the developer tool or other tools to find out the used class name and override it.

image

Setting Properties

When the input-dt element is accessed via JavaScript, several properties are available.

PropertyTypeDescription
valueDate | nullValue selected by input-dt.
minDate | nullMinimum selectable dates. By default, New Year's Day 120 years ago. If a null value is assigned, it is initialized to the default value.
maxDate | nullMaximum selectable dates. By default, the last day of the year after 10 years. If a null value is assigned, it is initialized to the default value.
disableDate[]List of dates that cannot be selected.
hoursnumber[] | nullOptions for the hour.
minutesnumber[] | nullOptions for the minute.
secondsnumber[] | nullOptions for the second.
unitstringMinimum unit of datetime. day - date picker only, or hour, minute, second(default).
localesstring | nullA locale identifier used for all parts of the modal. By default, it will be the default locale of the web browser.
firstDaynumber | nullFirst day of week. By default, it will be the default locale of the web browser.
backgroundbooleanSee the background attribute.
autoclosebooleanSee the autoclose attribute.
modalElementRead-only. A property for direct access to the elements of a modal.
format(date: Date) => stringWrite-only. It is possible to change the display of input-dt or input-dt-display. If used, the format attribute becomes invalid.
formatYear(date: number) => stringWrite-only. It is possible to change the text portion displaying the year and the year options.
formatMonth(date: number) => stringWrite-only. It is possible to change the text portion displaying the month and the month options.
formatWeek(value: number) => stringWrite-only. The display text of week headings in the calendar can be changed.
formatDay(date: Date) => stringWrite-only. The text of each day of the calendar can be changed.
formatHour(value: number) => stringWrite-only. The text of the hour options can be changed.
formatMinute(value: number) => stringWrite-only. The text of the minute options can be changed.
formatSecond(value: number) => stringWrite-only. The text of the second options can be changed.
renderYear(value: number, flags: Flags) => ElementWrite-only. The entire element of the year option can be replaced.
renderMonth(value: number, flags: Flags) => ElementWrite-only. The entire element of the month option can be replaced.
renderWeek(value: number) => ElementWrite-only. It is possible to change the elements of the calendar week headings in their entirety.
renderDate(date: Date, flags: Flags) => ElementWrite-only. It is possible to change the elements of each day of the calendar in its entirety.
renderHour(value: number, flags: Flags) => ElementWrite-only. The entire element of the hour option can be replaced.
renderMinute(value: number, flags: Flags) => ElementWrite-only. The entire element of the minute option can be replaced.
renderSecond(value: number, flags: Flags) => ElementWrite-only. The entire element of the second option can be replaced.

The Flags type has the following properties

  • isSelected - This value is the currently selected.
  • isWeekend - renderDate only. It is the weekend as determined by the current locale.
  • isInside - renderDate only. This date is inside the currently selected years and months.
  • isOutside - renderDate only. This date is outside the currently selected years and months.
  • isDisabled - renderDate only. This date has been disabled.

These properties can be used to create a new custom element as follows.

import { InputDt } from 'input-dt'

export class InputDtJa extends InputDt {
  constructor() {
    super()
    this.locales = 'ja'
  }
}

window.customElements.define('input-dt-ja', InputDtJa)

Events

The input-dt element receives an input event each time a date/time is selected.

At the same time, input-dt also sends an input event to input elements with input-dt.

Keywords

FAQs

Package last updated on 13 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc