Download the PHP package hussainweb/taarikh-picker without Composer
On this page you can find all versions of the php package hussainweb/taarikh-picker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hussainweb/taarikh-picker
More information about hussainweb/taarikh-picker
Files in hussainweb/taarikh-picker
Package taarikh-picker
Short Description Lightweight, accessible Hijri calendar date picker
License MIT
Homepage https://github.com/hussainweb/taarikh-picker
Informations about the package taarikh-picker
@taarikh/picker
A lightweight, accessible Hijri calendar date picker with zero third-party dependencies, built with vanilla TypeScript and modern web standards.
Features
- Zero External Dependencies: Pure vanilla TypeScript compiled to ESM and IIFE bundles (< 13 KB gzipped including stylesheet). No jQuery, no third-party runtime dependencies.
- Modular Monorepo Architecture: Includes headless
@taarikh/pickerfor the accessible DOM UI. - Fatimid Astronomical Hijri Calendar: Accurate astronomical calculation based on the Fatimid tabular calendar, with decoupled Julian Day Number (JDN) conversions matching
hussainweb/date-converter. - WCAG 2.2 AA Accessible: Full compliance with the WAI-ARIA APG Date Picker Dialog pattern, native
<dialog>top-layer modality, rovingtabindex, and polite live-region announcements. 0 axe-core violations. - Bidirectional & RTL Layout: Automatic or manual direction detection (
ltr,rtl,auto). Mirrors layout via CSS logical properties, mirrors navigation glyphs (‹/›), and mirrors keyboard arrow keys. - Comprehensive Localization: Month names, weekday headers, button labels, and live-region announcements are fully customizable via options or auto-derived from
Intl. - Strict Separation of Value and Display: Submitted form inputs always receive standard, zero-padded ASCII
YYYY-MM-DDstrings (e.g.1446-09-01), while UI headers, dropdowns, and announcements use localized numerals and script separators. - Modern CSS Architecture: Isolated component selectors (
.tp-dialog .tp-*) that resist accidental host theme resets, paired with zero-specificity--tp-*design tokens, CSS Anchor Positioning (centered modal fallback), light/dark mode vialight-dark(), high-contrast (forced-colors), and mobile bottom-sheet styling. - Dual Distribution: Available as
@taarikh/pickeron npm andhussainweb/taarikh-pickeron Packagist for seamless integration into Drupal and modern web stacks.
Installation
Via npm (Date Picker UI)
Import JavaScript and CSS into your project:
Headless Usage via @taarikh/core
For server-side Node.js, CLI applications, or custom UI components needing only calendar arithmetic without DOM or CSS dependencies:
Via Composer (Drupal Library / Packagist)
For Drupal sites using Composer with composer/installers, install directly into libraries/taarikh-picker:
Via IIFE (Direct Script Tag)
Compiled standalone assets are provided in dist/:
Quick Start
Given an HTML <input> element:
Initialize the picker:
With the IIFE global:
API Reference
createPicker(input, options?)
Factory function that creates and returns a TaarikhPicker instance.
TaarikhPickerOptions
| Option | Type | Default | Description |
|---|---|---|---|
engine |
CalendarEngine |
fatimidAstronomicalCalendar |
Pluggable calendar engine implementing Julian Day conversion. |
dir |
"ltr" \| "rtl" \| "auto" |
"auto" |
Text direction. "auto" detects from input.closest('[dir]'), computed style, or document.dir. |
locale |
string |
undefined (browser default) |
BCP 47 locale tag (e.g. 'ar', 'ar-EG', 'fa', 'ur', 'en') used for weekday resolution and numeral formatting. |
firstDayOfWeek |
number (0–6) |
Derived from Intl.Locale |
First day of week, where 0 = Sunday, 1 = Monday, ..., 6 = Saturday. |
initialDate |
PlainDate |
undefined (today) |
Date to focus and display on first open when the input is empty. |
selectedDate |
PlainDate |
Parsed from input value | Initially selected date. |
minDate |
PlainDate |
undefined |
Earliest selectable date. Earlier dates and previous months/years are disabled. |
maxDate |
PlainDate |
undefined |
Latest selectable date. Later dates and next months/years are disabled. |
valueFormat / valuePattern |
string |
"YYYY-MM-DD" |
Formatting pattern for submitted input value. |
labels |
PickerLabels |
DEFAULT_LABELS |
Custom string overrides for buttons, dialog, months, weekdays, and announcements. |
idPrefix |
string |
"tp" |
Prefix used for generated dialog element IDs. |
onSelect |
(date: PlainDate) => void |
undefined |
Callback fired when a date is selected. |
onOpen |
() => void |
undefined |
Callback fired when the dialog opens. |
onClose |
() => void |
undefined |
Callback fired when the dialog closes. |
onMonthChange |
(date: PlainDate) => void |
undefined |
Callback fired when visible month/year changes. |
onToday |
(todayDate: PlainDate) => void |
undefined |
Callback fired when the Today button is clicked. |
onClear |
() => void |
undefined |
Callback fired when the Clear button is clicked. |
PlainDate
PickerLabels
All strings are optional and fall back to localized English/Fatimid defaults:
Instance Methods
A TaarikhPicker instance returned by createPicker() exposes:
Explicit Resource Management (using)
In TypeScript / JavaScript environments supporting Symbol.dispose:
Events
Selecting a date, clicking Today, or clicking Clear dispatches:
- Standard native
inputevent (bubbles). - Standard native
changeevent (bubbles). - Custom
taarikh:changeevent (bubbles):
Styling & Design Tokens
The stylesheet is designed so that generic host theme rules (such as table, th, td, .form-item button, or .form-item select in CMS themes like Drupal Claro/Gin) cannot accidentally break the picker's layout, while intentional customization remains straightforward:
- CSS Custom Properties (
(0, 0, 0)specificity): Declared on:where(:root, :host), so setting--tp-*tokens on:root, a form wrapper, or.tp-dialogalways takes precedence regardless of stylesheet load order. - Flat Component Selectors (
(0, 2, 0)specificity): Internal elements use uniform.tp-dialog .tp-<element>selectors (and.tp-btn-trigger.tp-btn-triggerfor the trigger button). To override a rule directly, target.tp-dialog .tp-<element>in a stylesheet loaded after@taarikh/picker/style.css, or scope with a wrapper class (e.g.,.my-form .tp-dialog .tp-day-btn). - Optional Cascade Layering: If your application manages styles via CSS Cascade Layers, import the stylesheet into your desired layer:
CSS Custom Properties (--tp-*)
Override any of the design tokens on :root, a form container, or .tp-dialog:
Dark Mode & High Contrast
- Dark Mode: Uses modern
light-dark()color functions automatically adapting tocolor-schemeor@media (prefers-color-scheme: dark). - Forced Colors Mode: Fully supports Windows High Contrast and CSS
forced-colors: activeusing system canvas and highlight keywords (CanvasText,Highlight,ButtonText,GrayText). - Touch Devices: Automatically scales touch targets (
--tp-target-size, buttons, grid cells) to44pxon coarse pointer devices per WCAG 2.5.5. - Mobile Bottom Sheet: On viewports $\le 480\text{px}$, the dialog automatically anchors to the bottom of the screen as an accessible bottom sheet with smooth entry transitions.
Accessibility & Keyboard Navigation
The picker adheres strictly to the WAI-ARIA APG Date Picker Dialog specification:
- The calendar table has
role="grid"andaria-labelledbypointing to the dialog header. - Calendar cells use
role="gridcell", with selected states declared on the cell viaaria-selected="true". - Days outside
minDate/maxDatebounds havearia-disabled="true"andtabindex="-1". - Focus is trapped within the native
<dialog>modal while open and returned to the trigger button upon dismissal.
Keyboard Shortcuts
| Key | Action |
|---|---|
ArrowRight |
Move focus to the next day in LTR (previous day in RTL). |
ArrowLeft |
Move focus to the previous day in LTR (next day in RTL). |
ArrowDown |
Move focus to the same weekday in the next week (+7 days). |
ArrowUp |
Move focus to the same weekday in the previous week (-7 days). |
Home |
Move focus to the first day of the current week. |
End |
Move focus to the last day of the current week. |
PageDown |
Navigate to the same day in the next month. |
PageUp |
Navigate to the same day in the previous month. |
Shift + PageDown |
Navigate to the same day in the next year. |
Shift + PageUp |
Navigate to the same day in the previous year. |
Enter / Space |
Select the focused day, write to input, and close dialog. |
Escape |
Dismiss dialog without changing date; return focus to trigger button. |
Tab |
Cycle forward through interactive controls within dialog (Prev, Month, Year, Next, Grid, Today, Clear). |
Shift + Tab |
Cycle backward through interactive controls within dialog. |
Migration from kbwood/jquery.calendars
If you are migrating from Keith Wood's jquery.calendars.picker (commonly used in legacy Drupal modules):
kbwood/jquery.calendars |
@taarikh/picker |
Notes |
|---|---|---|
$(input).calendarsPicker({ calendar: $.calendars.instance('islamic') }) |
createPicker(input) |
Zero jQuery required; defaults to Fatimid astronomical engine. |
dateFormat: 'yyyy-mm-dd' |
valueFormat: 'YYYY-MM-DD' |
Defaults to ISO YYYY-MM-DD with zero-padded ASCII numerals. |
minDate: ... / maxDate: ... |
minDate: PlainDate / maxDate: PlainDate |
Typed { year, month, day } object instead of CDate or string. |
defaultDate: ... |
initialDate: PlainDate |
PlainDate object representing the opening month/day. |
firstDay: 6 |
firstDayOfWeek: 6 |
0 = Sunday, 6 = Saturday; defaults automatically from locale. |
isRTL: true |
dir: "rtl" or dir: "auto" |
Automatically detects RTL from ancestor attributes and styles. |
onSelect: function(dates) |
onSelect: (date) => void or taarikh:change event |
Emits typed { detail: { date, value } } event. |
showTrigger: '<button>...' |
Built-in accessible trigger | Created automatically as sibling <button type="button" class="tp-btn-trigger">. |
showOnFocus: false |
Default behavior | Never opens on input focus; requires deliberate trigger click or keyboard entry. |
commands: { today: ..., clear: ... } |
labels: { today: '...', clear: '...' } |
Configured directly in the labels dictionary. |
$(input).calendarsPicker('destroy') |
picker.destroy() |
Idempotent cleanup removing listeners and dialog DOM nodes. |
$(input).calendarsPicker('setDate', date) |
picker.setDate(date) |
Programmatic date setter. |
$(input).calendarsPicker('getDate') |
picker.getDate() |
Returns PlainDate \| null. |
Browser Support
- Chrome / Edge $\ge$ 114 (native
<dialog>and CSS Anchor Positioning) - Firefox $\ge$ 115 (native
<dialog>; centered modal positioning fallback) - Safari $\ge$ 16.4 (native
<dialog>; centered modal positioning fallback) - Mobile Safari & Chrome for Android
License
MIT © Hussain Abbas