@keenmate/web-daterangepicker 1.0.0-rc01 → 1.0.0-rc03

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/README.md CHANGED
@@ -11,6 +11,9 @@ A lightweight, accessible date picker web component with excellent keyboard navi
11
11
  - 🎨 **Themeable** - All styles use CSS custom properties (`--drp-*`)
12
12
  - 🖱️ **Drag-to-Adjust** - Drag range endpoints to adjust selection (range mode)
13
13
  - 🌐 **Multiple Formats** - YYYY-MM-DD, DD.MM.YYYY, MM/DD/YYYY, etc.
14
+ - 🌍 **Locale-Aware** - Auto-detect week start day from user's locale
15
+ - 🚫 **Date Restrictions** - Min/max dates, disabled days/dates, custom disable logic
16
+ - 🎉 **Special Dates** - Highlight holidays, events with custom labels and styling
14
17
  - ✨ **Modern** - Web Component with Shadow DOM, TypeScript, bundled with Vite
15
18
 
16
19
  ## Installation
@@ -78,6 +81,12 @@ picker.setValue('2025-11-15'); // Set value
78
81
  | `value` | `string` | - | Current value |
79
82
  | `placeholder` | `string` | - | Input placeholder text |
80
83
  | `disabled` | `boolean` | `false` | Disable the picker |
84
+ | `week-start-day` | `'auto' \| 0-6` | `'auto'` | First day of week (0=Sunday, 1=Monday, etc. 'auto'=detect from locale) |
85
+ | `min-date` | `string` | - | Minimum selectable date (YYYY-MM-DD) |
86
+ | `max-date` | `string` | - | Maximum selectable date (YYYY-MM-DD) |
87
+ | `disabled-days` | `string` | - | Comma-separated day numbers to disable (e.g., "0,6" for weekends) |
88
+ | `range-disabled-mode` | `'allow' \| 'block' \| 'split' \| 'individual'` | `'allow'` | How to handle range selections over disabled dates (see [Range Selection Modes](#range-selection-modes)) |
89
+ | `highlight-disabled-in-range` | `boolean` | `true` | Whether to visually highlight disabled dates within a selected range. Set to `false` to only highlight enabled dates. |
81
90
 
82
91
  ## Properties
83
92
 
@@ -122,6 +131,261 @@ picker.disabled = true;
122
131
  - **Tab / Shift+Tab** - Switch between month columns (multi-month mode)
123
132
  - **T** - Jump to today
124
133
 
134
+ ## Advanced Features
135
+
136
+ ### Week Start Day
137
+
138
+ Control which day the week starts on (auto-detected by default from user's locale):
139
+
140
+ ```html
141
+ <!-- Auto-detect from locale (default) -->
142
+ <date-range-picker week-start-day="auto"></date-range-picker>
143
+
144
+ <!-- Force Sunday start -->
145
+ <date-range-picker week-start-day="0"></date-range-picker>
146
+
147
+ <!-- Force Monday start (common in Europe) -->
148
+ <date-range-picker week-start-day="1"></date-range-picker>
149
+ ```
150
+
151
+ ### Disabled Dates & Date Restrictions
152
+
153
+ #### Simple Restrictions (Attributes)
154
+
155
+ ```html
156
+ <!-- Disable weekends -->
157
+ <date-range-picker disabled-days="0,6"></date-range-picker>
158
+
159
+ <!-- Date range restriction -->
160
+ <date-range-picker
161
+ min-date="2025-01-01"
162
+ max-date="2025-12-31">
163
+ </date-range-picker>
164
+ ```
165
+
166
+ #### Complex Restrictions (JavaScript)
167
+
168
+ ```javascript
169
+ const picker = document.querySelector('date-range-picker');
170
+
171
+ // Disable specific dates (e.g., public holidays)
172
+ picker.disabledDates = [
173
+ '2025-12-25', // Christmas
174
+ '2025-01-01', // New Year
175
+ new Date(2025, 6, 4) // July 4th
176
+ ];
177
+
178
+ // Custom disable logic (e.g., cottage booking)
179
+ picker.isDateDisabled = (date) => {
180
+ // Disable all dates that overlap with existing bookings
181
+ return bookedRanges.some(range =>
182
+ date >= range.start && date <= range.end
183
+ );
184
+ };
185
+ ```
186
+
187
+ ### Special Dates (Holidays, Events)
188
+
189
+ Add visual indicators and labels to specific dates:
190
+
191
+ ```javascript
192
+ const picker = document.querySelector('date-range-picker');
193
+
194
+ picker.specialDates = [
195
+ {
196
+ date: '2025-12-25',
197
+ class: 'holiday', // CSS class for styling
198
+ label: '🎄', // Emoji or short text overlay
199
+ tooltip: 'Christmas Day'
200
+ },
201
+ {
202
+ date: '2025-07-04',
203
+ class: 'holiday',
204
+ label: '🎆',
205
+ tooltip: 'Independence Day'
206
+ },
207
+ {
208
+ date: '2025-02-14',
209
+ class: 'event',
210
+ label: '❤️',
211
+ tooltip: 'Valentine\'s Day'
212
+ }
213
+ ];
214
+ ```
215
+
216
+ ### Advanced Styling & Info
217
+
218
+ For complete control, use the `getDateInfo` callback:
219
+
220
+ ```javascript
221
+ picker.getDateInfo = (date) => {
222
+ const dateStr = date.toISOString().split('T')[0];
223
+
224
+ // Check if it's a peak season date
225
+ if (isPeakSeason(date)) {
226
+ return {
227
+ class: 'peak-season',
228
+ label: '$$$',
229
+ tooltip: 'Peak season pricing'
230
+ };
231
+ }
232
+
233
+ // Check if it's a special offer date
234
+ if (specialOffers[dateStr]) {
235
+ return {
236
+ class: 'special-offer',
237
+ label: '%',
238
+ tooltip: `${specialOffers[dateStr]}% off!`
239
+ };
240
+ }
241
+
242
+ return null;
243
+ };
244
+ ```
245
+
246
+ ### CSS Styling for Special Dates
247
+
248
+ ```css
249
+ /* Holiday styling (predefined class) */
250
+ date-range-picker::part(calendar) .pa-date-picker__day.holiday {
251
+ background-color: rgba(239, 68, 68, 0.1);
252
+ }
253
+
254
+ /* Event styling (predefined class) */
255
+ date-range-picker::part(calendar) .pa-date-picker__day.event {
256
+ background-color: rgba(16, 185, 129, 0.1);
257
+ }
258
+
259
+ /* Custom class example */
260
+ date-range-picker::part(calendar) .pa-date-picker__day.peak-season {
261
+ background-color: rgba(251, 191, 36, 0.15);
262
+ font-weight: 600;
263
+ }
264
+ ```
265
+
266
+ ## Range Selection Modes
267
+
268
+ When selecting date ranges that include disabled dates (e.g., selecting a working week where weekends are disabled), you can control how the selection is handled using the `range-disabled-mode` attribute:
269
+
270
+ ### Mode: 'allow' (default)
271
+
272
+ Allows range selections over disabled dates. Returns both enabled and disabled date arrays:
273
+
274
+ ```html
275
+ <date-range-picker
276
+ mode="range"
277
+ disabled-days="0,6"
278
+ range-disabled-mode="allow">
279
+ </date-range-picker>
280
+
281
+ <script>
282
+ picker.addEventListener('date-select', (e) => {
283
+ console.log('Enabled dates:', e.detail.enabledDates);
284
+ console.log('Disabled dates:', e.detail.disabledDates);
285
+ console.log('Total days:', e.detail.getTotalDays());
286
+ console.log('Enabled count:', e.detail.getEnabledDateCount());
287
+ });
288
+ </script>
289
+ ```
290
+
291
+ **Use case:** Selecting working weeks where you need to know both working days and weekends (e.g., "Select 3 weeks of work" where weekends are included in the range but you get a separate array of working days).
292
+
293
+ ### Mode: 'block'
294
+
295
+ Prevents range selections from crossing disabled dates. Automatically snaps to the last enabled date before the gap:
296
+
297
+ ```html
298
+ <date-range-picker
299
+ mode="range"
300
+ range-disabled-mode="block">
301
+ </date-range-picker>
302
+ ```
303
+
304
+ When dragging from day 1 to day 7 with days 4-5 disabled, the selection will automatically snap to days 1-3.
305
+
306
+ **Use case:** Cottage booking where you can't book across existing reservations, or any scenario where gaps in the range are not allowed.
307
+
308
+ ### Mode: 'split'
309
+
310
+ Returns multiple date ranges separated by disabled dates:
311
+
312
+ ```html
313
+ <date-range-picker
314
+ mode="range"
315
+ disabled-days="0,6"
316
+ range-disabled-mode="split">
317
+ </date-range-picker>
318
+
319
+ <script>
320
+ picker.addEventListener('date-select', (e) => {
321
+ console.log('Ranges:', e.detail.dateRanges);
322
+ // e.g., [{start: Mon, end: Fri}, {start: Mon, end: Fri}, {start: Mon, end: Fri}]
323
+ console.log('Formatted:', e.detail.formattedValue);
324
+ // "2025-11-03 - 2025-11-07, 2025-11-10 - 2025-11-14, 2025-11-17 - 2025-11-21"
325
+ });
326
+ </script>
327
+ ```
328
+
329
+ **Use case:** Reporting or analytics where you need distinct time periods (e.g., "Generate report for these 3 work weeks").
330
+
331
+ ### Mode: 'individual'
332
+
333
+ Returns a flat array of individual enabled dates:
334
+
335
+ ```html
336
+ <date-range-picker
337
+ mode="range"
338
+ disabled-days="0,6"
339
+ range-disabled-mode="individual">
340
+ </date-range-picker>
341
+
342
+ <script>
343
+ picker.addEventListener('date-select', (e) => {
344
+ console.log('Individual dates:', e.detail.dates);
345
+ // [Date(Mon), Date(Tue), Date(Wed), Date(Thu), Date(Fri), Date(Mon), ...]
346
+ console.log('Formatted:', e.detail.formattedValue);
347
+ // "2025-11-03, 2025-11-04, 2025-11-05, 2025-11-06, 2025-11-07, ..."
348
+ });
349
+ </script>
350
+ ```
351
+
352
+ **Use case:** Scheduling or event planning where you need a list of specific dates (e.g., "Schedule training sessions on these dates").
353
+
354
+ ### Event Detail Structure by Mode
355
+
356
+ | Mode | Properties | Description |
357
+ |------|-----------|-------------|
358
+ | `allow` | `dateRange`, `enabledDates`, `disabledDates`, `getTotalDays()`, `getEnabledDateCount()` | Full range with helper methods |
359
+ | `block` | `dateRange`, `dates` | Single continuous range (no disabled dates) |
360
+ | `split` | `dateRanges`, `dates` | Multiple ranges split by disabled dates |
361
+ | `individual` | `dates` | Flat array of enabled dates |
362
+
363
+ ### Visual Highlighting Control
364
+
365
+ By default, when you select a range that includes disabled dates, all dates (both enabled and disabled) within the range are visually highlighted. You can change this behavior with the `highlight-disabled-in-range` attribute:
366
+
367
+ ```html
368
+ <!-- Default: highlights all dates in range, including disabled weekends -->
369
+ <date-range-picker
370
+ mode="range"
371
+ disabled-days="0,6"
372
+ range-disabled-mode="split">
373
+ </date-range-picker>
374
+
375
+ <!-- Only highlight enabled dates (Mon-Fri), skip weekends -->
376
+ <date-range-picker
377
+ mode="range"
378
+ disabled-days="0,6"
379
+ range-disabled-mode="split"
380
+ highlight-disabled-in-range="false">
381
+ </date-range-picker>
382
+ ```
383
+
384
+ **When to use `highlight-disabled-in-range="false"`:**
385
+ - Selecting working weeks where you only want to see Monday-Friday highlighted
386
+ - Visual clarity when disabled dates are not relevant to the selection
387
+ - Any scenario where showing gaps in the range is clearer than showing continuous highlighting
388
+
125
389
  ## Theming
126
390
 
127
391
  Customize the appearance using CSS custom properties: