@spaethtech/svelte-ui 0.15.1-dev.67.fbf3875 → 0.15.1-dev.71.e357f8b

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.
@@ -1,157 +0,0 @@
1
- <!--
2
- /**
3
- * DateRangePicker — a start–end range picker with a presets rail. Composes the existing `Calendar`
4
- * (mode="range") inside an `Input`-framed trigger + `Popup`, exposing ergonomic bind:start / bind:end
5
- * (ISO). See DateRangePicker.spec.md.
6
- */
7
- -->
8
- <script lang="ts" module>
9
- export type RangePreset = { label: string; start: string; end: string };
10
- </script>
11
-
12
- <script lang="ts">
13
- import type { Snippet } from "svelte";
14
- import Input from "../Input.svelte";
15
- import Popup from "../Popup.svelte";
16
- import Button from "../Button.svelte";
17
- import Calendar from "../Calendar.svelte";
18
- import IconCalendar from "~icons/mdi/calendar-outline";
19
- import type { Variant } from "../../types/variants.js";
20
- import type { Size } from "../../types/sizes.js";
21
- import type { Responsive } from "../../types/responsive.js";
22
-
23
- // Local ISO (avoids the UTC shift of toISOString near midnight).
24
- const iso = (d: Date) =>
25
- `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
26
- function defaultPresets(): RangePreset[] {
27
- const t = new Date();
28
- t.setHours(0, 0, 0, 0);
29
- const shift = (n: number) => {
30
- const d = new Date(t);
31
- d.setDate(d.getDate() + n);
32
- return iso(d);
33
- };
34
- const today = iso(t);
35
- const monthStart = iso(new Date(t.getFullYear(), t.getMonth(), 1));
36
- return [
37
- { label: "Today", start: today, end: today },
38
- { label: "Yesterday", start: shift(-1), end: shift(-1) },
39
- { label: "Last 7 days", start: shift(-6), end: today },
40
- { label: "Last 30 days", start: shift(-29), end: today },
41
- { label: "This month", start: monthStart, end: today },
42
- ];
43
- }
44
-
45
- let {
46
- start = $bindable(""),
47
- end = $bindable(""),
48
- min,
49
- max,
50
- presets,
51
- variant = "secondary",
52
- size = "md",
53
- disabled = false,
54
- placeholder = "Select dates",
55
- format,
56
- label = null,
57
- aside,
58
- error = null,
59
- description = null,
60
- id,
61
- required = false,
62
- class: cls = "",
63
- }: {
64
- start?: string;
65
- end?: string;
66
- min?: string;
67
- max?: string;
68
- presets?: RangePreset[];
69
- variant?: Variant;
70
- size?: Responsive<Size>;
71
- disabled?: boolean;
72
- placeholder?: string;
73
- format?: (iso: string) => string;
74
- label?: string | null;
75
- aside?: Snippet;
76
- error?: string | Snippet | null;
77
- description?: string | Snippet | null;
78
- id?: string;
79
- required?: boolean;
80
- class?: string;
81
- } = $props();
82
-
83
- const rail = $derived(presets ?? defaultPresets());
84
- let open = $state(false);
85
- let fieldEl = $state<HTMLDivElement>();
86
-
87
- const fmt = (i: string): string => {
88
- if (format) return format(i);
89
- const [y, m, d] = i.split("-").map(Number);
90
- return new Date(y, m - 1, d).toLocaleDateString(undefined, {
91
- month: "short",
92
- day: "numeric",
93
- year: "numeric",
94
- });
95
- };
96
- const display = $derived(
97
- start && end
98
- ? `${fmt(start)} – ${fmt(end)}`
99
- : start
100
- ? `${fmt(start)} – …`
101
- : "",
102
- );
103
-
104
- function applyPreset(p: RangePreset) {
105
- start = p.start;
106
- end = p.end;
107
- open = false;
108
- }
109
- </script>
110
-
111
- <Input
112
- value={display}
113
- readonly
114
- {variant}
115
- {size}
116
- {disabled}
117
- {placeholder}
118
- {label}
119
- {aside}
120
- {error}
121
- {description}
122
- {id}
123
- {required}
124
- class={cls}
125
- icon={calIcon}
126
- bind:fieldElement={fieldEl}
127
- onclick={() => (disabled ? null : (open = !open))}
128
- />
129
-
130
- {#snippet calIcon()}<IconCalendar />{/snippet}
131
-
132
- <Popup anchor={fieldEl} bind:open side="bottom" align="start" lightDismiss>
133
- <div
134
- class="flex overflow-hidden rounded-md border shadow-lg [background-color:var(--ui-color-background)] [border-color:var(--ui-border-color)]"
135
- >
136
- {#if rail.length}
137
- <div class="flex flex-col gap-0.5 border-r p-2 [border-color:var(--ui-border-color)]">
138
- {#each rail as p (p.label)}
139
- <Button text={p.label} variant="ghost" size="sm" onclick={() => applyPreset(p)} />
140
- {/each}
141
- </div>
142
- {/if}
143
- <div class="p-2">
144
- <Calendar
145
- mode="range"
146
- bind:start
147
- bind:end
148
- {min}
149
- {max}
150
- {variant}
151
- onrange={(r) => {
152
- if (r.start && r.end) open = false;
153
- }}
154
- />
155
- </div>
156
- </div>
157
- </Popup>
@@ -1,31 +0,0 @@
1
- export type RangePreset = {
2
- label: string;
3
- start: string;
4
- end: string;
5
- };
6
- import type { Snippet } from "svelte";
7
- import type { Variant } from "../../types/variants.js";
8
- import type { Size } from "../../types/sizes.js";
9
- import type { Responsive } from "../../types/responsive.js";
10
- type $$ComponentProps = {
11
- start?: string;
12
- end?: string;
13
- min?: string;
14
- max?: string;
15
- presets?: RangePreset[];
16
- variant?: Variant;
17
- size?: Responsive<Size>;
18
- disabled?: boolean;
19
- placeholder?: string;
20
- format?: (iso: string) => string;
21
- label?: string | null;
22
- aside?: Snippet;
23
- error?: string | Snippet | null;
24
- description?: string | Snippet | null;
25
- id?: string;
26
- required?: boolean;
27
- class?: string;
28
- };
29
- declare const DateRangePicker: import("svelte").Component<$$ComponentProps, {}, "start" | "end">;
30
- type DateRangePicker = ReturnType<typeof DateRangePicker>;
31
- export default DateRangePicker;
@@ -1,2 +0,0 @@
1
- export { default as DateRangePicker } from "./DateRangePicker.svelte";
2
- export type { RangePreset } from "./DateRangePicker.svelte";
@@ -1 +0,0 @@
1
- export { default as DateRangePicker } from "./DateRangePicker.svelte";