@makolabs/ripple 1.1.0 → 1.1.1
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/dist/forms/DateRange.svelte +14 -6
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { cn } from '../helper/cls.js';
|
|
3
3
|
import type { DateRangeProps } from '../index.js';
|
|
4
|
+
import Portal from '../utils/Portal.svelte';
|
|
4
5
|
|
|
5
6
|
let {
|
|
6
7
|
startDate = $bindable(),
|
|
@@ -21,13 +22,17 @@
|
|
|
21
22
|
let isOpen = $state(false);
|
|
22
23
|
let hoveredDate = $state<Date | null>(null);
|
|
23
24
|
let datePickerRef = $state<HTMLDivElement | null>(null);
|
|
25
|
+
let calendarRef = $state<HTMLDivElement | null>(null);
|
|
24
26
|
|
|
25
27
|
let viewMode = $state<'days' | 'months' | 'years'>('days');
|
|
26
28
|
let viewDate = $state(new Date());
|
|
27
29
|
|
|
28
30
|
const handleOutsideClick = (event: MouseEvent) => {
|
|
29
|
-
if (isOpen && datePickerRef &&
|
|
30
|
-
|
|
31
|
+
if (isOpen && datePickerRef && calendarRef) {
|
|
32
|
+
const target = event.target as Node;
|
|
33
|
+
if (!datePickerRef.contains(target) && !calendarRef.contains(target)) {
|
|
34
|
+
isOpen = false;
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
38
|
|
|
@@ -290,9 +295,11 @@
|
|
|
290
295
|
</div>
|
|
291
296
|
|
|
292
297
|
{#if isOpen}
|
|
293
|
-
<
|
|
294
|
-
|
|
295
|
-
|
|
298
|
+
<Portal target={datePickerRef}>
|
|
299
|
+
<div
|
|
300
|
+
bind:this={calendarRef}
|
|
301
|
+
class="ring-opacity-5 absolute z-10 mt-1 w-full origin-top-left rounded-md bg-white p-4 shadow-lg ring-1 ring-default-300 focus:outline-none"
|
|
302
|
+
>
|
|
296
303
|
<div class="mb-2 flex items-center justify-between">
|
|
297
304
|
{#if viewMode === 'days'}
|
|
298
305
|
<button
|
|
@@ -490,6 +497,7 @@
|
|
|
490
497
|
</div>
|
|
491
498
|
</div>
|
|
492
499
|
{/if}
|
|
493
|
-
|
|
500
|
+
</div>
|
|
501
|
+
</Portal>
|
|
494
502
|
{/if}
|
|
495
503
|
</div>
|