datex-ui 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 DateX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,300 @@
1
+ # DateX UI - Modern Date Range Picker
2
+
3
+ A modern, lightweight, and customizable date range picker for TypeScript/JavaScript applications. Built with native JavaScript, no external dependencies.
4
+
5
+ <!-- Add your demo GIF here -->
6
+
7
+ ![DateX Demo](./assets/images/demo.gif)
8
+
9
+ ## Features
10
+
11
+ - 📅 **Date Range Selection** - Select start and end dates with intuitive interface
12
+ - � **\*Single Date Mode** - Use as a single date picker
13
+ - ⏰ **Time Picker** - Optional time selection with 12/24 hour formats
14
+ - 🎨 **Customizable Themes** - Built-in themes (Default, Bootstrap, Material) or create your own
15
+ - � **Inteernationalization** - Built-in Spanish locale with easy customization
16
+ - 📱 **Responsive Design** - Works on desktop and mobile devices
17
+ - 🚀 **Zero Dependencies** - Pure JavaScript/TypeScript implementation
18
+ - 🎛️ **Predefined Ranges** - Quick selection with common date ranges
19
+ - ♿ **Accessible** - Keyboard navigation and screen reader support
20
+
21
+ <!-- Basic image here -->
22
+
23
+ ![Basic Date Range](./assets/images/screenshots/basic-date-range.png)
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ npm install datex-ui
29
+ # or
30
+ pnpm add datex-ui
31
+ # or
32
+ yarn add datex-ui
33
+ ```
34
+
35
+ ## Quick Start
36
+
37
+ ```typescript
38
+ import { Datex, SPANISH_LOCALE, DEFAULT_THEME } from "datex-ui";
39
+
40
+ // Basic usage with CSS selector
41
+ const picker = new Datex(
42
+ "#date-input", // CSS selector or DOM element
43
+ {
44
+ locale: SPANISH_LOCALE,
45
+ theme: DEFAULT_THEME,
46
+ },
47
+ (startDate, endDate, label) => {
48
+ console.log("Selected:", { startDate, endDate, label });
49
+ }
50
+ );
51
+
52
+ // Also works with class selectors and DOM elements
53
+ const picker2 = new Datex(".date-range-picker");
54
+ const picker3 = new Datex(document.getElementById("my-input"));
55
+ ```
56
+
57
+ ## Usage Examples
58
+
59
+ ### Basic Date Range Picker
60
+
61
+ ```typescript
62
+ import { Datex, SPANISH_LOCALE } from "datex-ui";
63
+
64
+ // Using CSS selectors
65
+ const picker = new Datex(
66
+ "#date-input", // ID selector
67
+ {
68
+ locale: SPANISH_LOCALE,
69
+ autoUpdateInput: true,
70
+ },
71
+ (startDate, endDate) => {
72
+ console.log(`Selected: ${startDate} to ${endDate}`);
73
+ }
74
+ );
75
+
76
+ // Also works with class selectors
77
+ const picker2 = new Datex(".date-range-picker");
78
+
79
+ // Or complex CSS selectors
80
+ const picker3 = new Datex("[data-datex='range']");
81
+
82
+ // Or DOM elements directly
83
+ const picker4 = new Datex(document.getElementById("my-input"));
84
+ ```
85
+
86
+ ### Single Date Picker
87
+
88
+ ```typescript
89
+ const singlePicker = new Datex("#single-date", {
90
+ singleDatePicker: true,
91
+ locale: SPANISH_LOCALE,
92
+ });
93
+ ```
94
+
95
+ ### With Predefined Ranges
96
+
97
+ ```typescript
98
+ import { getSpanishRanges } from "datex-ui";
99
+
100
+ const picker = new Datex("#range-input", {
101
+ ranges: getSpanishRanges(), // Built-in Spanish ranges
102
+ locale: SPANISH_LOCALE,
103
+ autoApply: true,
104
+ });
105
+
106
+ // Or create custom ranges
107
+ const customRanges = {
108
+ Hoy: [new Date(), new Date()],
109
+ Ayer: [
110
+ new Date(Date.now() - 24 * 60 * 60 * 1000),
111
+ new Date(Date.now() - 24 * 60 * 60 * 1000),
112
+ ],
113
+ "Últimos 7 días": [
114
+ new Date(Date.now() - 6 * 24 * 60 * 60 * 1000),
115
+ new Date(),
116
+ ],
117
+ };
118
+
119
+ const picker2 = new Datex("#custom-ranges", {
120
+ ranges: customRanges,
121
+ locale: SPANISH_LOCALE,
122
+ });
123
+ ```
124
+
125
+ ### With Time Picker
126
+
127
+ ```typescript
128
+ import { SPANISH_LOCALE_WITH_TIME } from "datex-ui";
129
+
130
+ const timePicker = new Datex("#datetime-input", {
131
+ timePicker: true,
132
+ timePicker24Hour: true,
133
+ timePickerIncrement: 15,
134
+ locale: SPANISH_LOCALE_WITH_TIME,
135
+ });
136
+ ```
137
+
138
+ <!-- Add time picker screenshot here -->
139
+
140
+ ![Time Picker](./assets/images/screenshots/time-picker.png)
141
+
142
+ ### Custom Theme
143
+
144
+ ```typescript
145
+ import { Datex } from "datex-ui";
146
+
147
+ const customTheme = {
148
+ primaryColor: "#ff6b6b",
149
+ backgroundColor: "#ffffff",
150
+ borderColor: "#e1e5e9",
151
+ textColor: "#495057",
152
+ selectedColor: "#ff6b6b",
153
+ rangeColor: "#ffe0e0",
154
+ };
155
+
156
+ const picker = new Datex("#themed-input", {
157
+ theme: customTheme,
158
+ });
159
+ ```
160
+
161
+ ### Mobile Responsive
162
+
163
+ <!-- Add mobile screenshot here -->
164
+
165
+ <!-- ![Mobile View](./assets/images/screenshots/mobile-view.png)-->
166
+
167
+ ## Configuration Options
168
+
169
+ ```typescript
170
+ interface DatexOptions {
171
+ startDate?: Date; // Initial start date
172
+ endDate?: Date; // Initial end date
173
+ minDate?: Date | null; // Minimum selectable date
174
+ maxDate?: Date | null; // Maximum selectable date
175
+ minYear?: number; // Minimum year in dropdowns
176
+ maxYear?: number; // Maximum year in dropdowns
177
+ maxSpan?: { days?: number }; // Maximum range span
178
+ autoApply?: boolean; // Auto-apply selection
179
+ singleDatePicker?: boolean; // Single date mode
180
+ showDropdowns?: boolean; // Show month/year dropdowns
181
+ linkedCalendars?: boolean; // Link calendar navigation
182
+ autoUpdateInput?: boolean; // Auto-update input value
183
+ alwaysShowCalendars?: boolean; // Always show calendars
184
+ showCustomRangeLabel?: boolean; // Show "Custom Range" option
185
+ timePicker?: boolean; // Enable time picker
186
+ timePicker24Hour?: boolean; // 24-hour format
187
+ timePickerIncrement?: number; // Minute increment
188
+ timePickerSeconds?: boolean; // Show seconds
189
+ ranges?: Record<string, [Date, Date]>; // Predefined ranges
190
+ opens?: "left" | "right" | "center"; // Picker position
191
+ drops?: "up" | "down" | "auto"; // Picker direction
192
+ locale?: DatexLocale; // Localization
193
+ theme?: DatexTheme; // Theme configuration
194
+ }
195
+ ```
196
+
197
+ ## Built-in Themes
198
+
199
+ - `DEFAULT_THEME` - Clean, modern default theme
200
+ - `BOOTSTRAP_THEME` - Bootstrap-compatible styling
201
+ - `MATERIAL_THEME` - Material Design inspired theme
202
+
203
+ ## Built-in Locales
204
+
205
+ - `SPANISH_LOCALE` - Spanish localization for dates
206
+ - `SPANISH_LOCALE_WITH_TIME` - Spanish localization with time format
207
+
208
+ ## API Methods
209
+
210
+ ```typescript
211
+ // Show/hide picker
212
+ picker.show();
213
+ picker.hide();
214
+ picker.toggle();
215
+
216
+ // Get/set dates
217
+ const startDate = picker.getStartDate();
218
+ const endDate = picker.getEndDate();
219
+ picker.setStartDate(new Date());
220
+ picker.setEndDate(new Date());
221
+
222
+ // Theme management
223
+ picker.setTheme(newTheme);
224
+ picker.refreshTheme();
225
+
226
+ // Update ranges
227
+ picker.updateRanges(newRanges);
228
+
229
+ // Cleanup
230
+ picker.remove();
231
+ ```
232
+
233
+ ## Events
234
+
235
+ The picker dispatches custom events:
236
+
237
+ ```typescript
238
+ element.addEventListener("show.daterangepicker", (e) => {
239
+ console.log("Picker shown");
240
+ });
241
+
242
+ element.addEventListener("hide.daterangepicker", (e) => {
243
+ console.log("Picker hidden");
244
+ });
245
+
246
+ element.addEventListener("apply.daterangepicker", (e) => {
247
+ console.log("Selection applied");
248
+ });
249
+
250
+ element.addEventListener("cancel.daterangepicker", (e) => {
251
+ console.log("Selection cancelled");
252
+ });
253
+ ```
254
+
255
+ ## Legacy Support
256
+
257
+ For backward compatibility, you can still use the old names:
258
+
259
+ ```typescript
260
+ import { DateRangePicker } from "datex-ui"; // Same as Datex
261
+ // All DateRangePickerOptions, DateRangePickerTheme, etc. are available
262
+ ```
263
+
264
+ ## Browser Support
265
+
266
+ - Chrome 60+
267
+ - Firefox 60+
268
+ - Safari 12+
269
+ - Edge 79+
270
+
271
+ ## Development
272
+
273
+ ```bash
274
+ # Install dependencies
275
+ pnpm install
276
+
277
+ # Start development server
278
+ pnpm run dev
279
+
280
+ # Build library
281
+ pnpm run build
282
+
283
+ # Run tests
284
+ pnpm test
285
+
286
+ # Type checking
287
+ pnpm run type-check
288
+ ```
289
+
290
+ ## Testing
291
+
292
+ Open `test.html` in your browser to see the library in action with various configurations.
293
+
294
+ ## License
295
+
296
+ MIT License - see LICENSE file for details.
297
+
298
+ ## Contributing
299
+
300
+ Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Binary file
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Predefined locales for DateX
3
+ */
4
+ import type { DateRangePickerLocale } from "../types";
5
+ export declare const ENGLISH_LOCALE: DateRangePickerLocale;
6
+ export declare const SPANISH_LOCALE: DateRangePickerLocale;
7
+ export declare const SPANISH_LOCALE_WITH_TIME: DateRangePickerLocale;
8
+ export declare const FRENCH_LOCALE: DateRangePickerLocale;
9
+ export declare const GERMAN_LOCALE: DateRangePickerLocale;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Predefined themes for DateX
3
+ */
4
+ import type { DateRangePickerTheme } from "../types";
5
+ export declare const DEFAULT_THEME: DateRangePickerTheme;
6
+ export declare const BOOTSTRAP_THEME: DateRangePickerTheme;
7
+ export declare const MATERIAL_THEME: DateRangePickerTheme;
8
+ export declare const DARK_THEME: DateRangePickerTheme;
@@ -0,0 +1,136 @@
1
+ export interface DatexTheme {
2
+ primaryColor?: string;
3
+ secondaryColor?: string;
4
+ backgroundColor?: string;
5
+ borderColor?: string;
6
+ textColor?: string;
7
+ hoverColor?: string;
8
+ selectedColor?: string;
9
+ rangeColor?: string;
10
+ todayColor?: string;
11
+ disabledColor?: string;
12
+ applyButtonColor?: string;
13
+ cancelButtonColor?: string;
14
+ borderRadius?: string;
15
+ fontSize?: string;
16
+ fontFamily?: string;
17
+ }
18
+ export declare const DEFAULT_THEME: DatexTheme;
19
+ export declare const BOOTSTRAP_THEME: DatexTheme;
20
+ export declare const MATERIAL_THEME: DatexTheme;
21
+ export interface DatexOptions {
22
+ startDate?: Date;
23
+ endDate?: Date;
24
+ minDate?: Date | null;
25
+ maxDate?: Date | null;
26
+ minYear?: number;
27
+ maxYear?: number;
28
+ maxSpan?: {
29
+ days?: number;
30
+ } | null;
31
+ autoApply?: boolean;
32
+ singleDatePicker?: boolean;
33
+ showDropdowns?: boolean;
34
+ linkedCalendars?: boolean;
35
+ autoUpdateInput?: boolean;
36
+ alwaysShowCalendars?: boolean;
37
+ showCustomRangeLabel?: boolean;
38
+ timePicker?: boolean;
39
+ timePicker24Hour?: boolean;
40
+ timePickerIncrement?: number;
41
+ timePickerSeconds?: boolean;
42
+ ranges?: Record<string, [Date, Date]>;
43
+ opens?: "left" | "right" | "center";
44
+ drops?: "up" | "down" | "auto";
45
+ locale?: DatexLocale;
46
+ buttonClasses?: string;
47
+ applyButtonClasses?: string;
48
+ cancelButtonClasses?: string;
49
+ theme?: DatexTheme;
50
+ }
51
+ export interface DatexLocale {
52
+ format: string;
53
+ separator: string;
54
+ applyLabel: string;
55
+ cancelLabel: string;
56
+ customRangeLabel: string;
57
+ daysOfWeek: string[];
58
+ monthNames: string[];
59
+ firstDay: number;
60
+ }
61
+ export declare const SPANISH_LOCALE: DatexLocale;
62
+ export declare const SPANISH_LOCALE_WITH_TIME: DatexLocale;
63
+ export type DatexCallback = (startDate: Date, endDate: Date, label?: string) => void;
64
+ export declare class Datex {
65
+ private element;
66
+ private container;
67
+ private options;
68
+ private locale;
69
+ private theme;
70
+ private callback;
71
+ private state;
72
+ private boundHandlers;
73
+ private resizeHandler?;
74
+ private scrollHandler?;
75
+ private documentClickHandler?;
76
+ private documentFocusHandler?;
77
+ constructor(element: HTMLElement | string, options?: DatexOptions, callback?: DatexCallback);
78
+ private applyTheme;
79
+ private generateThemeCSS;
80
+ setTheme(theme: DatexTheme): void;
81
+ refreshTheme(): void;
82
+ getCurrentTheme(): DatexTheme;
83
+ testDropdowns(): void;
84
+ private mergeOptions;
85
+ private createContainer;
86
+ private renderRanges;
87
+ private setupEventListeners;
88
+ private addEventHandler;
89
+ private containerChange;
90
+ private containerMouseOver;
91
+ private containerMouseLeave;
92
+ private containerClick;
93
+ private preventBlur;
94
+ show(): void;
95
+ hide(): void;
96
+ private removeDocumentListeners;
97
+ private outsideClick;
98
+ private outsideFocus;
99
+ toggle(): void;
100
+ private updateView;
101
+ private updateMonthsInView;
102
+ private getStartOfMonth;
103
+ private getEndOfMonth;
104
+ private getStartOfWeek;
105
+ private updateCalendars;
106
+ private renderCalendar;
107
+ private renderDropdowns;
108
+ private getDayClasses;
109
+ private updateFormInputs;
110
+ private updateSelectedDisplay;
111
+ private renderTimePicker;
112
+ private timeChanged;
113
+ private updateElement;
114
+ private move;
115
+ private clickRange;
116
+ private clickPrev;
117
+ private clickNext;
118
+ private clickDate;
119
+ private hoverDate;
120
+ private updateDateClasses;
121
+ private clickApply;
122
+ private clickCancel;
123
+ private monthOrYearChanged;
124
+ private elementChanged;
125
+ private keydown;
126
+ private showCalendars;
127
+ private hideCalendars;
128
+ private calculateChosenLabel;
129
+ setStartDate(date: Date): void;
130
+ setEndDate(date: Date): void;
131
+ getStartDate(): Date;
132
+ getEndDate(): Date | null;
133
+ remove(): void;
134
+ updateRanges(newRanges: Record<string, [Date, Date]>): void;
135
+ private dispatchEvent;
136
+ }
@@ -0,0 +1,5 @@
1
+ import "./datex.scss";
2
+ export { Datex } from "./datex";
3
+ export type { DatexOptions, DatexTheme, DatexLocale, DatexCallback, } from "./datex";
4
+ export { DEFAULT_THEME, BOOTSTRAP_THEME, MATERIAL_THEME } from "./datex";
5
+ export { SPANISH_LOCALE, SPANISH_LOCALE_WITH_TIME } from "./datex";