File tree Expand file tree Collapse file tree 6 files changed +44
-4
lines changed
Expand file tree Collapse file tree 6 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ Try it in the [Svelte REPL](https://svelte.dev/repl/cae0ce6e92634878b6e1a587146d
8383### Events
8484| Prop | Description | Default |
8585| :----------------- | :------------------------------------------------------------------------------------ | :-------------------------- |
86+ | onDateChange | Callback function to handle date change events. | ` function `
8687| onDayClick | Callback function to handle day click events. | ` function `
8788| onNavigationChange | Callback function to handle the navigation click event for months and years | ` function `
8889
@@ -162,6 +163,7 @@ DatePicker CSS variables:
162163 --datepicker-container-font-family: var(--datepicker-font-family);
163164 --datepicker-container-left: 0;
164165 --datepicker-container-position: absolute;
166+ --datepicker-container-top: 105%;
165167 --datepicker-container-width: fit-content ;
166168 --datepicker-container-zindex: 99;
167169
Original file line number Diff line number Diff line change 300300 <th >Description</th >
301301 <th >Default</th >
302302 </tr >
303+ <tr >
304+ <td >onDateChange</td >
305+ <td ><code >function</code ></td >
306+ <td >Callback function to handle when date changes.</td >
307+ <td ><code >None</code ></td >
308+ </tr >
303309 <tr >
304310 <td >onDayClick</td >
305311 <td ><code >function</code ></td >
Original file line number Diff line number Diff line change 3131 console .log (e, ' onNavigationChange' );
3232 };
3333
34+ const onDateChange = (args ) => {
35+ console .log (args, ' onDateChange' );
36+ };
37+
3438 const toggleDatePicker = () => (isOpen = ! isOpen);
3539 const formatDate = (dateString ) => dateString && format (new Date (dateString), dateFormat) || ' ' ;
3640
4448 bind:startDate
4549 bind:endDate
4650 {onNavigationChange }
51+ {onDateChange }
4752 isRange
4853 {isMultipane }
4954 {showPresets }
Original file line number Diff line number Diff line change 2929 console .log (e, ' onNavigationChange' );
3030 };
3131
32+ const onDateChange = (args ) => {
33+ console .log (args, ' onDateChange' );
34+ };
35+
3236 $: formattedStartDate = formatDate (startDate);
3337 </script >
3438
35- <DatePicker bind:isOpen bind:startDate {...$$props } {onNavigationChange }>
39+ <DatePicker bind:isOpen bind:startDate {...$$props } {onNavigationChange } { onDateChange } >
3640 <input type ="text" bind:value ={formattedStartDate } on:change ={onChange } on:click ={toggleDatePicker } />
3741</DatePicker >
3842
Original file line number Diff line number Diff line change 209209 --datepicker-presets-button-color : #fff ;
210210 --datepicker-presets-button-color-active : #fff ;
211211 --datepicker-presets-button-color-hover : #333 ;
212- --datepicker-presets-button-color-focus : #333
212+ --datepicker-presets-button-color-focus : #333 ;
213+ --datepicker-spacing : 90px ;
214+
213215 }
214216 </style >
Original file line number Diff line number Diff line change 9393 */
9494 export let enabledDates = [];
9595
96+ /**
97+ * Callback function triggered when a date or date range changes.
98+ * @type {function}
99+ * @default () => {}
100+ */
101+ export let onDateChange = () => {};
102+
96103 /**
97104 * Callback function to handle day click events.
98105 * @type {(event: Object) => void}
483490 *
484491 * @param {number} startDate - The timestamp of the start date.
485492 * @param {number} endDate - The timestamp of the end date.
486- * @param {string[]} disabled - An array of disabled dates.
487493 * @returns {string[]} - An array of dates within the specified range.
488494 */
489495 const getDatesInRange = (startDate , endDate ) => {
495501 const formattedDate = ` ${
496502 dateRangeStart .getMonth () + 1
497503 } /${ dateRangeStart .getDate ()} /${ dateRangeStart .getFullYear ()} ` ;
504+
498505 if (
499506 (! enabled && ! disabled) ||
500507 (enabled .length && enabled .includes (formattedDate)) ||
501- ( disabled . length && ! disabled .includes (formattedDate) )
508+ ! disabled .includes (formattedDate)
502509 ) {
503510 datesInRange .push (formattedDate);
504511 }
545552 };
546553
547554 onDayClick (event );
555+
556+ if ((isRange && startDate && endDate) || (! isRange && startDate)) {
557+ onDateChange (event );
558+ }
548559 };
549560
550561 /**
772783 startDate = start;
773784 endDate = end;
774785
786+ if (isRange && startDate && endDate) {
787+ onDateChange ({
788+ startDate,
789+ startDateTime,
790+ endDate,
791+ endDateTime,
792+ rangeDates: getDatesInRange (startDate, endDate)
793+ });
794+ }
795+
775796 if (! alwaysShow) {
776797 isOpen = false ;
777798 }
You can’t perform that action at this time.
0 commit comments