SuperDate
Lightweight TypeScript enhancer for native date, time, and datetime-local inputs.
SuperDate replaces the native browser date/time picker chrome with a fully custom, format-aware overlay — while still delegating the actual popup calendar or clock to the OS. You never re-implement a calendar widget.
The underlying input.value always stays in standard ISO format, so it drops in alongside any existing form logic without changes.
Install & Build
Copy the dist/ folder into your project, or build from source:
npm install
npm run build
| File | Format | Use when |
|---|---|---|
| super-date.umd.js | UMD | Plain <script> tag, exposes global SuperDate |
| super-date.min.js | UMD minified | Production <script> tag |
| super-date.esm.js | ES Module | import in bundler or modern browser |
| super-date.esm.min.js | ESM minified | Production ESM |
CDN (jsDelivr)
No installation needed — load SuperDate directly via jsDelivr. Use the @latest tag to always receive the newest version automatically:
Always use the latest version ✦ recommended
<!-- CSS -->
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@maihcx/super-date@latest/dist/super-date.min.css" />
<!-- JS (UMD — exposes global SuperDate) -->
<script src="https://cdn.jsdelivr.net/npm/@maihcx/super-date@latest/dist/super-date.min.js"></script>
Pin a specific version
If you need stricter stability guarantees for production, replace @latest with an exact version number:
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@maihcx/super-date@1.0.0/dist/super-date.min.css" />
<script src="https://cdn.jsdelivr.net/npm/@maihcx/super-date@1.0.0/dist/super-date.min.js"></script>
ESM via jsDelivr
<script type="module">
import SuperDate from 'https://cdn.jsdelivr.net/npm/@maihcx/super-date@latest/dist/super-date.esm.min.js';
SuperDate.bind('.sd', { format: 'dd/MM/yyyy' });
</script>
Usage
Via <script> tag
<link rel="stylesheet" href="dist/super-date.min.css" />
<script src="dist/super-date.umd.js"></script>
<script>
SuperDate.bind('.sd', { format: 'dd/MM/yyyy' });
</script>
ES Module
import SuperDate from './dist/super-date.esm.js';
SuperDate.bind('.sd', { format: 'dd/MM/yyyy' });
TypeScript / bundler
import SuperDate from 'superdate';
SuperDate.bind('.sd');
SuperDate.bind()
Enhances all current and future matching inputs. Uses a MutationObserver to catch inputs added to the DOM after the call.
SuperDate.bind(selector: string, options?: SuperDateOptions): this
Supports input[type="date"], input[type="time"], and input[type="datetime-local"] within the same selector. Returns this for chaining.
// all three types under one selector
SuperDate.bind('.sd', {
format: 'dd/MM/yyyy',
timeFormat: 'HH:mm',
dateTimeDelimiter: ' ',
});
// chaining
SuperDate
.bind('.date-field', { format: 'yyyy/MM/dd' })
.bind('.time-field', { timeFormat: 'HH:mm:ss' });
SuperDate.init()
Manually enhance a single element. Returns the SuperDateInstance. Safe to call on an already-enhanced element — returns the existing instance.
SuperDate.init(el: HTMLInputElement, options?: SuperDateOptions): SuperDateInstance
const el = document.querySelector('#my-dt') as HTMLInputElement;
SuperDate.init(el, {
format: 'dd/MM/yyyy',
timeFormat: 'HH:mm:ss',
dateTimeDelimiter: ' | ',
});
SuperDate.destroy()
Removes the overlay, detaches all listeners, and restores the original native input. The element is marked so the MutationObserver won't re-bind it automatically. Call bind() or init() again to re-enable.
SuperDate.destroy(el: HTMLInputElement): void
Options
| Option | Type | Default | Description |
|---|---|---|---|
| format | string | 'dd/MM/yyyy' | Display format for date inputs, and the date part of datetime-local |
| timeFormat | string | 'HH:mm' | Display format for time inputs, and the time part of datetime-local |
| dateTimeDelimiter | string | ' ' | String inserted between date and time parts in datetime-local overlays |
| locale | string | navigator.language | Locale — reserved for future i18n features |
Format tokens
Date tokens
| Token | Description | Example |
|---|---|---|
| yyyy | 4-digit year | 2025 |
| yy | 2-digit year | 25 |
| MM | Month, zero-padded | 03 |
| M | Month, no padding | 3 |
| dd | Day, zero-padded | 07 |
| d | Day, no padding | 7 |
Time tokens
| Token | Description | Range | Example |
|---|---|---|---|
| HH | Hours, 24h, zero-padded | 00–23 | 09, 23 |
| H | Hours, 24h, no padding | 0–23 | 9, 23 |
| hh | Hours, 12h, zero-padded | 01–12 | 09, 12 |
| h | Hours, 12h, no padding | 1–12 | 9, 12 |
| mm | Minutes, zero-padded | 00–59 | 05 |
| ss | Seconds, zero-padded | 00–59 | 30 |
MM (uppercase) = months, mm (lowercase) = minutes. The token regex is case-sensitive.Data attributes
Per-element attributes always override the global bind() options.
| Attribute | Applies to | Example value |
|---|---|---|
| data-date-format | date, datetime-local | "yyyy/MM/dd" |
| data-time-format | time, datetime-local | "HH:mm:ss" |
| data-date-time-delimiter | datetime-local | " | " |
<input type="date" data-date-format="yyyy/MM/dd" />
<input type="time" data-time-format="HH:mm:ss" />
<input type="datetime-local"
data-date-format="dd/MM/yyyy"
data-time-format="HH:mm:ss"
data-date-time-delimiter=" | " />
CSS variables
Scope overrides to .superdate-overlay on a wrapper or globally:
| Variable | Default | Controls |
|---|---|---|
| --superdate-active-bg | #2563eb | Active segment background |
| --superdate-active-color | #fff | Active segment text |
| --superdate-placeholder-color | #9ca3af | Empty segment placeholder text |
| --superdate-sep-color | inherit | Separator / literal character color |
/* Override globally */
.superdate-overlay {
--superdate-active-bg: #0ea5e9;
--superdate-active-color: #fff;
--superdate-placeholder-color: #475569;
--superdate-sep-color: #64748b;
}
/* Or scope to one wrapper */
#my-form .superdate-overlay {
--superdate-active-bg: #7c3aed;
}
Keyboard shortcuts
| Key | Action |
|---|---|
| 0–9 | Type digit into active segment; auto-advances when segment is full |
| ↑ / ↓ | Increment / decrement the active segment value (wraps around) |
| ← / → | Move to previous / next token segment |
| Tab / Shift+Tab | Move to next / previous segment; Tab out when at last/first |
| Backspace | Erase last digit in the typing buffer |
| Delete | Same as Backspace; on a selection — clears all selected tokens |
| Escape | Clear selection, or deactivate overlay |
| Ctrl+A | Select all segments |
| Ctrl+C | Copy selected segments as formatted string |
| Click & drag | Multi-segment selection |
| Double-click | Select all segments |
Input value
SuperDate only changes the visual overlay. The underlying input.value always stays in standard ISO format:
| Input type | input.value format | Example |
|---|---|---|
| date | yyyy-MM-dd | 2025-03-07 |
| time | HH:mm:ss | 09:30:00 |
| datetime-local | yyyy-MM-ddTHH:mm:ss | 2025-03-07T09:30:00 |
input.value is unchanged, SuperDate is fully compatible with any existing form serialisation, validation library, or framework two-way binding.