Skip to content

The only tool you need to know what is happening and how to fix it.

feat: better/more uniform date/time pickers

narrow-adventuredea3954b9fa9
diff --git a/frontend/src/lib/components/ui/date-picker/date-picker.svelte b/frontend/src/lib/components/ui/date-picker/date-picker.svelte
new file mode 100644
index 00000000..0a8678e6
--- /dev/null
+++ b/frontend/src/lib/components/ui/date-picker/date-picker.svelte
@@ -0,0 +1,72 @@
+<script lang="ts">
+ import * as Popover from '$lib/components/ui/popover';
+ import { Calendar } from '$lib/components/ui/calendar';
+ import { cn } from '$lib/utils';
+ import { Calendar as CalendarIcon } from '@lucide/svelte';
+ import { getLocalTimeZone, parseDate, type DateValue } from '@internationalized/date';
+
+ interface Props {
+ // Same wire format as <input type="date">: yyyy-MM-dd
+ value?: string;
+ onValueChange?: (value: string) => void;
+ disabled?: boolean;
+ id?: string;
+ class?: string;
+ placeholder?: string;
+ }
+
+ let {
+ value = $bindable(''),
+ onValueChange,
+ disabled = false,
+ id,
+ class: className,
+ placeholder = 'Pick a date'
+ }: Props = $props();
+
+ let open = $state(false);
+
+ const parsed = $derived.by(() => {
+ if (!value) return undefined;
+ try {
+ return parseDate(value);
+ } catch {
+ return undefined;
+ }
+ });
+
+ const label = $derived(
+ parsed
+ ? parsed.toDate(getLocalTimeZone()).toLocaleDateString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric'
+ })
+ : placeholder
+ );
+
+ function handleSelect(date: DateValue | undefined) {
+ if (!date) return;
+ const pad = (n: number) => String(n).padStart(2, '0');
+ value = `${date.year}-${pad(date.month)}-${pad(date.day)}`;
+ onValueChange?.(value);
+ open = false;
+ }
+</script>
+
+<Popover.Root bind:open>
+ <Popover.Trigger
+ {id}
+ {disabled}
+ class={cn(
+ 'flex h-9 w-full items-center gap-2 rounded-md border border-input bg-background px-3 text-left text-sm shadow-xs transition-[color,box-shadow] outline-none hover:bg-muted/50 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=open]:border-ring data-[state=open]:ring-[3px] data-[state=open]:ring-ring/50 dark:bg-input/30',
+ className
+ )}
+ >
+ <CalendarIcon class="h-4 w-4 shrink-0 text-muted-foreground" />
+ <span class={cn('truncate tabular-nums', !parsed && 'text-muted-foreground')}>{label}</span>
+ </Popover.Trigger>
+ <Popover.Content class="w-auto p-0" align="start">
+ <Calendar type="single" value={parsed} onValueChange={handleSelect} />
+ </Popover.Content>
+</Popover.Root>
diff --git a/frontend/src/lib/components/ui/date-picker/index.ts b/frontend/src/lib/components/ui/date-picker/index.ts
new file mode 100644
index 00000000..a66fcf52
--- /dev/null
+++ b/frontend/src/lib/components/ui/date-picker/index.ts
@@ -0,0 +1,3 @@
+import DatePicker from './date-picker.svelte';
+
+export { DatePicker };
diff --git a/frontend/src/lib/components/ui/datetime-picker/datetime-calendar.svelte b/frontend/src/lib/components/ui/datetime-picker/datetime-calendar.svelte
new file mode 100644
index 00000000..ee345b39
--- /dev/null
+++ b/frontend/src/lib/components/ui/datetime-picker/datetime-calendar.svelte
@@ -0,0 +1,252 @@
+<script lang="ts">
+ import { Calendar } from '$lib/components/ui/calendar';
+ import * as Select from '$lib/components/ui/select';
+ import { cn } from '$lib/utils';
+ import {
+ CalendarDate,
+ CalendarDateTime,
+ getLocalTimeZone,
+ today,
+ type DateValue
+ } from '@internationalized/date';
+
+ type Period = 'AM' | 'PM';
+
+ interface Props {
+ value?: CalendarDateTime | CalendarDate;
+ onValueChange?: (value: CalendarDateTime) => void;
+ class?: string;
+ }
+
+ let { value = $bindable(), onValueChange, class: className }: Props = $props();
+
+ // Time state (12-hour format for display)
+ let hours = $state(12);
+ let minutes = $state(0);
+ let seconds = $state(0);
+ let period = $state<Period>('AM');
+
+ // Initialize from value
+ $effect(() => {
+ if (value && 'hour' in value) {
+ const hour24 = value.hour;
+ period = hour24 >= 12 ? 'PM' : 'AM';
+ hours = hour24 % 12 || 12;
+ minutes = value.minute;
+ seconds = value.second;
+ }
+ });
+
+ // Derived 24-hour value
+ const hour24 = $derived(() => {
+ if (period === 'AM') {
+ return hours === 12 ? 0 : hours;
+ } else {
+ return hours === 12 ? 12 : hours + 12;
+ }
+ });
+
+ // Handle calendar date change
+ function handleDateChange(newDate: DateValue | undefined) {
+ if (!newDate) return;
+
+ const dateTime = new CalendarDateTime(
+ newDate.year,
+ newDate.month,
+ newDate.day,
+ hour24(),
+ minutes,
+ seconds
+ );
+
+ value = dateTime;
+ onValueChange?.(dateTime);
+ }
+
+ // Handle time changes
+ function updateDateTime() {
+ if (!value) {
+ const now = today(getLocalTimeZone());
+ value = new CalendarDateTime(now.year, now.month, now.day, hour24(), minutes, seconds);
+ } else {
+ const dateTime = new CalendarDateTime(
+ value.year,
+ value.month,
+ value.day,
+ hour24(),
+ minutes,
+ seconds
+ );
+ value = dateTime;
+ onValueChange?.(dateTime);
+ }
+ }
+
+ // Input handlers with validation
+ function handleHoursInput(e: Event) {
+ const input = e.target as HTMLInputElement;
+ let val = parseInt(input.value) || 0;
+ if (val < 1) val = 1;
+ if (val > 12) val = 12;
+ hours = val;
+ input.value = String(val).padStart(2, '0');
+ updateDateTime();
+ }
+
+ function handleMinutesInput(e: Event) {
+ const input = e.target as HTMLInputElement;
+ let val = parseInt(input.value) || 0;
+ if (val < 0) val = 0;
+ if (val > 59) val = 59;
+ minutes = val;
+ input.value = String(val).padStart(2, '0');
+ updateDateTime();
+ }
+
+ function handlePeriodChange(newPeriod: string | undefined) {
+ if (newPeriod === 'AM' || newPeriod === 'PM') {
+ period = newPeriod;
+ updateDateTime();
+ }
+ }
+
+ // Increment/decrement helpers
+ function incrementHours() {
+ hours = hours >= 12 ? 1 : hours + 1;
+ updateDateTime();
+ }
+
+ function decrementHours() {
+ hours = hours <= 1 ? 12 : hours - 1;
+ updateDateTime();
+ }
+
+ function incrementMinutes() {
+ if (minutes >= 59) {
+ minutes = 0;
+ incrementHours();
+ } else {
+ minutes++;
+ }
+ updateDateTime();
+ }
+
+ function decrementMinutes() {
+ if (minutes <= 0) {
+ minutes = 59;
+ decrementHours();
+ } else {
+ minutes--;
+ }
+ updateDateTime();
+ }
+
+ function incrementSeconds() {
+ if (seconds >= 59) {
+ seconds = 0;
+ incrementMinutes();
+ } else {
+ seconds++;
+ }
+ updateDateTime();
+ }
+
+ function decrementSeconds() {
+ if (seconds <= 0) {
+ seconds = 59;
+ decrementMinutes();
+ } else {
+ seconds--;
+ }
+ updateDateTime();
+ }
+
+ // Handle keyboard navigation
+ function handleKeyDown(e: KeyboardEvent, field: 'hours' | 'minutes' | 'seconds') {
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ if (field === 'hours') incrementHours();
+ else if (field === 'minutes') incrementMinutes();
+ else incrementSeconds();
+ } else if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ if (field === 'hours') decrementHours();
+ else if (field === 'minutes') decrementMinutes();
+ else decrementSeconds();
+ }
+ }
+
+ // Get calendar-compatible date value
+ const calendarValue = $derived(() => {
+ if (!value) return undefined;
+ return new CalendarDate(value.year, value.month, value.day);
+ });
+</script>
+
+<div class={cn('flex flex-col', className)}>
+ <!-- Calendar -->
+ <Calendar type="single" value={calendarValue()} onValueChange={handleDateChange} />
+
+ <!-- Time Picker -->
+ <div class="border-t px-3 py-3">
+ <div class="flex items-end gap-2">
+ <!-- Hours -->
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Hours</span>
+ <input
+ type="text"
+ inputmode="numeric"
+ class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
+ value={String(hours).padStart(2, '0')}
+ onchange={handleHoursInput}
+ onkeydown={(e) => handleKeyDown(e, 'hours')}
+ maxlength={2}
+ />
+ </div>
+
+ <span class="pb-1 text-sm font-medium text-muted-foreground">:</span>
+
+ <!-- Minutes -->
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Minutes</span>
+ <input
+ type="text"
+ inputmode="numeric"
+ class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
+ value={String(minutes).padStart(2, '0')}
+ onchange={handleMinutesInput}
+ onkeydown={(e) => handleKeyDown(e, 'minutes')}
+ maxlength={2}
+ />
+ </div>
+
+ <span class="pb-1 text-sm font-medium text-muted-foreground">:</span>
+
+ <!-- Seconds (disabled - not passed between pages) -->
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Seconds</span>
+ <input
+ type="text"
+ inputmode="numeric"
+ class="h-9 w-10 cursor-not-allowed rounded-md border bg-muted text-center text-sm text-muted-foreground tabular-nums"
+ value={String(seconds).padStart(2, '0')}
+ disabled
+ />
+ </div>
+
+ <!-- Period (AM/PM) -->
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Period</span>
+ <Select.Root type="single" value={period} onValueChange={handlePeriodChange}>
+ <Select.Trigger class="h-9 w-[60px] text-sm">
+ {period}
+ </Select.Trigger>
+ <Select.Content>
+ <Select.Item value="AM" label="AM">AM</Select.Item>
+ <Select.Item value="PM" label="PM">PM</Select.Item>
+ </Select.Content>
+ </Select.Root>
+ </div>
+ </div>
+ </div>
+</div>
diff --git a/frontend/src/lib/components/ui/datetime-picker/datetime-picker.svelte b/frontend/src/lib/components/ui/datetime-picker/datetime-picker.svelte
index ee345b39..89733805 100644
--- a/frontend/src/lib/components/ui/datetime-picker/datetime-picker.svelte
+++ b/frontend/src/lib/components/ui/datetime-picker/datetime-picker.svelte
@@ -1,252 +1,72 @@
<script lang="ts">
- import { Calendar } from '$lib/components/ui/calendar';
- import * as Select from '$lib/components/ui/select';
+ import * as Popover from '$lib/components/ui/popover';
+ import DateTimeCalendar from './datetime-calendar.svelte';
import { cn } from '$lib/utils';
- import {
- CalendarDate,
- CalendarDateTime,
- getLocalTimeZone,
- today,
- type DateValue
- } from '@internationalized/date';
-
- type Period = 'AM' | 'PM';
+ import { Calendar as CalendarIcon } from '@lucide/svelte';
+ import { CalendarDateTime, getLocalTimeZone, parseDateTime } from '@internationalized/date';
interface Props {
- value?: CalendarDateTime | CalendarDate;
- onValueChange?: (value: CalendarDateTime) => void;
+ // Same wire format as <input type="datetime-local">: yyyy-MM-ddTHH:mm
+ value?: string;
+ onValueChange?: (value: string) => void;
+ disabled?: boolean;
+ id?: string;
class?: string;
+ placeholder?: string;
}
- let { value = $bindable(), onValueChange, class: className }: Props = $props();
-
- // Time state (12-hour format for display)
- let hours = $state(12);
- let minutes = $state(0);
- let seconds = $state(0);
- let period = $state<Period>('AM');
+ let {
+ value = $bindable(''),
+ onValueChange,
+ disabled = false,
+ id,
+ class: className,
+ placeholder = 'Pick a date & time'
+ }: Props = $props();
- // Initialize from value
- $effect(() => {
- if (value && 'hour' in value) {
- const hour24 = value.hour;
- period = hour24 >= 12 ? 'PM' : 'AM';
- hours = hour24 % 12 || 12;
- minutes = value.minute;
- seconds = value.second;
- }
- });
+ let open = $state(false);
- // Derived 24-hour value
- const hour24 = $derived(() => {
- if (period === 'AM') {
- return hours === 12 ? 0 : hours;
- } else {
- return hours === 12 ? 12 : hours + 12;
+ const parsed = $derived.by(() => {
+ if (!value) return undefined;
+ try {
+ return parseDateTime(value);
+ } catch {
+ return undefined;
}
});
- // Handle calendar date change
- function handleDateChange(newDate: DateValue | undefined) {
- if (!newDate) return;
-
- const dateTime = new CalendarDateTime(
- newDate.year,
- newDate.month,
- newDate.day,
- hour24(),
- minutes,
- seconds
- );
-
- value = dateTime;
- onValueChange?.(dateTime);
- }
-
- // Handle time changes
- function updateDateTime() {
- if (!value) {
- const now = today(getLocalTimeZone());
- value = new CalendarDateTime(now.year, now.month, now.day, hour24(), minutes, seconds);
- } else {
- const dateTime = new CalendarDateTime(
- value.year,
- value.month,
- value.day,
- hour24(),
- minutes,
- seconds
- );
- value = dateTime;
- onValueChange?.(dateTime);
- }
- }
-
- // Input handlers with validation
- function handleHoursInput(e: Event) {
- const input = e.target as HTMLInputElement;
- let val = parseInt(input.value) || 0;
- if (val < 1) val = 1;
- if (val > 12) val = 12;
- hours = val;
- input.value = String(val).padStart(2, '0');
- updateDateTime();
+ const label = $derived(
+ parsed
+ ? parsed.toDate(getLocalTimeZone()).toLocaleString('en-US', {
+ month: 'short',
+ day: 'numeric',
+ year: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit'
+ })
+ : placeholder
+ );
+
+ function handleChange(dt: CalendarDateTime) {
+ const pad = (n: number) => String(n).padStart(2, '0');
+ value = `${dt.year}-${pad(dt.month)}-${pad(dt.day)}T${pad(dt.hour)}:${pad(dt.minute)}`;
+ onValueChange?.(value);
}
-
- function handleMinutesInput(e: Event) {
- const input = e.target as HTMLInputElement;
- let val = parseInt(input.value) || 0;
- if (val < 0) val = 0;
- if (val > 59) val = 59;
- minutes = val;
- input.value = String(val).padStart(2, '0');
- updateDateTime();
- }
-
- function handlePeriodChange(newPeriod: string | undefined) {
- if (newPeriod === 'AM' || newPeriod === 'PM') {
- period = newPeriod;
- updateDateTime();
- }
- }
-
- // Increment/decrement helpers
- function incrementHours() {
- hours = hours >= 12 ? 1 : hours + 1;
- updateDateTime();
- }
-
- function decrementHours() {
- hours = hours <= 1 ? 12 : hours - 1;
- updateDateTime();
- }
-
- function incrementMinutes() {
- if (minutes >= 59) {
- minutes = 0;
- incrementHours();
- } else {
- minutes++;
- }
- updateDateTime();
- }
-
- function decrementMinutes() {
- if (minutes <= 0) {
- minutes = 59;
- decrementHours();
- } else {
- minutes--;
- }
- updateDateTime();
- }
-
- function incrementSeconds() {
- if (seconds >= 59) {
- seconds = 0;
- incrementMinutes();
- } else {
- seconds++;
- }
- updateDateTime();
- }
-
- function decrementSeconds() {
- if (seconds <= 0) {
- seconds = 59;
- decrementMinutes();
- } else {
- seconds--;
- }
- updateDateTime();
- }
-
- // Handle keyboard navigation
- function handleKeyDown(e: KeyboardEvent, field: 'hours' | 'minutes' | 'seconds') {
- if (e.key === 'ArrowUp') {
- e.preventDefault();
- if (field === 'hours') incrementHours();
- else if (field === 'minutes') incrementMinutes();
- else incrementSeconds();
- } else if (e.key === 'ArrowDown') {
- e.preventDefault();
- if (field === 'hours') decrementHours();
- else if (field === 'minutes') decrementMinutes();
- else decrementSeconds();
- }
- }
-
- // Get calendar-compatible date value
- const calendarValue = $derived(() => {
- if (!value) return undefined;
- return new CalendarDate(value.year, value.month, value.day);
- });
</script>
-<div class={cn('flex flex-col', className)}>
- <!-- Calendar -->
- <Calendar type="single" value={calendarValue()} onValueChange={handleDateChange} />
-
- <!-- Time Picker -->
- <div class="border-t px-3 py-3">
- <div class="flex items-end gap-2">
- <!-- Hours -->
- <div class="flex flex-col items-center gap-1">
- <span class="text-xs text-muted-foreground">Hours</span>
- <input
- type="text"
- inputmode="numeric"
- class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
- value={String(hours).padStart(2, '0')}
- onchange={handleHoursInput}
- onkeydown={(e) => handleKeyDown(e, 'hours')}
- maxlength={2}
- />
- </div>
-
- <span class="pb-1 text-sm font-medium text-muted-foreground">:</span>
-
- <!-- Minutes -->
- <div class="flex flex-col items-center gap-1">
- <span class="text-xs text-muted-foreground">Minutes</span>
- <input
- type="text"
- inputmode="numeric"
- class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
- value={String(minutes).padStart(2, '0')}
- onchange={handleMinutesInput}
- onkeydown={(e) => handleKeyDown(e, 'minutes')}
- maxlength={2}
- />
- </div>
-
- <span class="pb-1 text-sm font-medium text-muted-foreground">:</span>
-
- <!-- Seconds (disabled - not passed between pages) -->
- <div class="flex flex-col items-center gap-1">
- <span class="text-xs text-muted-foreground">Seconds</span>
- <input
- type="text"
- inputmode="numeric"
- class="h-9 w-10 cursor-not-allowed rounded-md border bg-muted text-center text-sm text-muted-foreground tabular-nums"
- value={String(seconds).padStart(2, '0')}
- disabled
- />
- </div>
-
- <!-- Period (AM/PM) -->
- <div class="flex flex-col items-center gap-1">
- <span class="text-xs text-muted-foreground">Period</span>
- <Select.Root type="single" value={period} onValueChange={handlePeriodChange}>
- <Select.Trigger class="h-9 w-[60px] text-sm">
- {period}
- </Select.Trigger>
- <Select.Content>
- <Select.Item value="AM" label="AM">AM</Select.Item>
- <Select.Item value="PM" label="PM">PM</Select.Item>
- </Select.Content>
- </Select.Root>
- </div>
- </div>
- </div>
-</div>
+<Popover.Root bind:open>
+ <Popover.Trigger
+ {id}
+ {disabled}
+ class={cn(
+ 'flex h-9 w-full items-center gap-2 rounded-md border border-input bg-background px-3 text-left text-sm shadow-xs transition-[color,box-shadow] outline-none hover:bg-muted/50 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=open]:border-ring data-[state=open]:ring-[3px] data-[state=open]:ring-ring/50 dark:bg-input/30',
+ className
+ )}
+ >
+ <CalendarIcon class="h-4 w-4 shrink-0 text-muted-foreground" />
+ <span class={cn('truncate tabular-nums', !parsed && 'text-muted-foreground')}>{label}</span>
+ </Popover.Trigger>
+ <Popover.Content class="w-auto p-0" align="start">
+ <DateTimeCalendar value={parsed} onValueChange={handleChange} />
+ </Popover.Content>
+</Popover.Root>
diff --git a/frontend/src/lib/components/ui/datetime-picker/index.ts b/frontend/src/lib/components/ui/datetime-picker/index.ts
index 21e50b67..bb9640bf 100644
--- a/frontend/src/lib/components/ui/datetime-picker/index.ts
+++ b/frontend/src/lib/components/ui/datetime-picker/index.ts
@@ -1,3 +1,4 @@
+import DateTimeCalendar from './datetime-calendar.svelte';
import DateTimePicker from './datetime-picker.svelte';
-export { DateTimePicker };
+export { DateTimeCalendar, DateTimePicker };
diff --git a/frontend/src/lib/components/ui/time-picker/index.ts b/frontend/src/lib/components/ui/time-picker/index.ts
new file mode 100644
index 00000000..bed63028
--- /dev/null
+++ b/frontend/src/lib/components/ui/time-picker/index.ts
@@ -0,0 +1,3 @@
+import TimePicker from './time-picker.svelte';
+
+export { TimePicker };
diff --git a/frontend/src/lib/components/ui/time-picker/time-picker.svelte b/frontend/src/lib/components/ui/time-picker/time-picker.svelte
new file mode 100644
index 00000000..9ea30c8a
--- /dev/null
+++ b/frontend/src/lib/components/ui/time-picker/time-picker.svelte
@@ -0,0 +1,189 @@
+<script lang="ts">
+ import * as Popover from '$lib/components/ui/popover';
+ import * as Select from '$lib/components/ui/select';
+ import { cn } from '$lib/utils';
+ import { Clock } from '@lucide/svelte';
+
+ type Period = 'AM' | 'PM';
+
+ interface Props {
+ // Same wire format as <input type="time">: HH:mm (24-hour)
+ value?: string;
+ onValueChange?: (value: string) => void;
+ disabled?: boolean;
+ id?: string;
+ class?: string;
+ placeholder?: string;
+ }
+
+ let {
+ value = $bindable(''),
+ onValueChange,
+ disabled = false,
+ id,
+ class: className,
+ placeholder = 'Pick a time'
+ }: Props = $props();
+
+ let open = $state(false);
+
+ let hours = $state(9);
+ let minutes = $state(0);
+ let period = $state<Period>('AM');
+
+ const parsed = $derived.by(() => {
+ const match = /^(\d{1,2}):(\d{2})$/.exec(value ?? '');
+ if (!match) return null;
+ const hour = Number(match[1]);
+ const minute = Number(match[2]);
+ if (hour > 23 || minute > 59) return null;
+ return { hour, minute };
+ });
+
+ $effect(() => {
+ if (parsed) {
+ period = parsed.hour >= 12 ? 'PM' : 'AM';
+ hours = parsed.hour % 12 || 12;
+ minutes = parsed.minute;
+ }
+ });
+
+ const label = $derived(
+ parsed
+ ? `${parsed.hour % 12 || 12}:${String(parsed.minute).padStart(2, '0')} ${parsed.hour >= 12 ? 'PM' : 'AM'}`
+ : placeholder
+ );
+
+ function commit() {
+ const hour24 = period === 'AM' ? (hours === 12 ? 0 : hours) : hours === 12 ? 12 : hours + 12;
+ value = `${String(hour24).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
+ onValueChange?.(value);
+ }
+
+ function handleHoursInput(e: Event) {
+ const input = e.target as HTMLInputElement;
+ let val = parseInt(input.value) || 0;
+ if (val < 1) val = 1;
+ if (val > 12) val = 12;
+ hours = val;
+ input.value = String(val).padStart(2, '0');
+ commit();
+ }
+
+ function handleMinutesInput(e: Event) {
+ const input = e.target as HTMLInputElement;
+ let val = parseInt(input.value) || 0;
+ if (val < 0) val = 0;
+ if (val > 59) val = 59;
+ minutes = val;
+ input.value = String(val).padStart(2, '0');
+ commit();
+ }
+
+ function handlePeriodChange(newPeriod: string | undefined) {
+ if (newPeriod === 'AM' || newPeriod === 'PM') {
+ period = newPeriod;
+ commit();
+ }
+ }
+
+ function incrementHours() {
+ hours = hours >= 12 ? 1 : hours + 1;
+ commit();
+ }
+
+ function decrementHours() {
+ hours = hours <= 1 ? 12 : hours - 1;
+ commit();
+ }
+
+ function incrementMinutes() {
+ if (minutes >= 59) {
+ minutes = 0;
+ incrementHours();
+ } else {
+ minutes++;
+ commit();
+ }
+ }
+
+ function decrementMinutes() {
+ if (minutes <= 0) {
+ minutes = 59;
+ decrementHours();
+ } else {
+ minutes--;
+ commit();
+ }
+ }
+
+ function handleKeyDown(e: KeyboardEvent, field: 'hours' | 'minutes') {
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ if (field === 'hours') incrementHours();
+ else incrementMinutes();
+ } else if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ if (field === 'hours') decrementHours();
+ else decrementMinutes();
+ }
+ }
+</script>
+
+<Popover.Root bind:open>
+ <Popover.Trigger
+ {id}
+ {disabled}
+ class={cn(
+ 'flex h-9 w-full items-center gap-2 rounded-md border border-input bg-background px-3 text-left text-sm shadow-xs transition-[color,box-shadow] outline-none hover:bg-muted/50 focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 data-[state=open]:border-ring data-[state=open]:ring-[3px] data-[state=open]:ring-ring/50 dark:bg-input/30',
+ className
+ )}
+ >
+ <Clock class="h-4 w-4 shrink-0 text-muted-foreground" />
+ <span class={cn('truncate tabular-nums', !parsed && 'text-muted-foreground')}>{label}</span>
+ </Popover.Trigger>
+ <Popover.Content class="w-auto p-3" align="start">
+ <div class="flex items-end gap-2">
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Hours</span>
+ <input
+ type="text"
+ inputmode="numeric"
+ class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
+ value={String(hours).padStart(2, '0')}
+ onchange={handleHoursInput}
+ onkeydown={(e) => handleKeyDown(e, 'hours')}
+ maxlength={2}
+ />
+ </div>
+
+ <span class="pb-1 text-sm font-medium text-muted-foreground">:</span>
+
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Minutes</span>
+ <input
+ type="text"
+ inputmode="numeric"
+ class="h-9 w-10 rounded-md border bg-background text-center text-sm tabular-nums focus:ring-2 focus:ring-ring focus:outline-none"
+ value={String(minutes).padStart(2, '0')}
+ onchange={handleMinutesInput}
+ onkeydown={(e) => handleKeyDown(e, 'minutes')}
+ maxlength={2}
+ />
+ </div>
+
+ <div class="flex flex-col items-center gap-1">
+ <span class="text-xs text-muted-foreground">Period</span>
+ <Select.Root type="single" value={period} onValueChange={handlePeriodChange}>
+ <Select.Trigger class="h-9 w-[60px] text-sm">
+ {period}
+ </Select.Trigger>
+ <Select.Content>
+ <Select.Item value="AM" label="AM">AM</Select.Item>
+ <Select.Item value="PM" label="PM">PM</Select.Item>
+ </Select.Content>
+ </Select.Root>
+ </div>
+ </div>
+ </Popover.Content>
+</Popover.Root>
diff --git a/frontend/src/lib/components/ui/time-range-picker/time-range-picker.svelte b/frontend/src/lib/components/ui/time-range-picker/time-range-picker.svelte
index b7d474ca..627a9de5 100644
--- a/frontend/src/lib/components/ui/time-range-picker/time-range-picker.svelte
+++ b/frontend/src/lib/components/ui/time-range-picker/time-range-picker.svelte
@@ -1,6 +1,6 @@
<script lang="ts">
import { Button } from '$lib/components/ui/button';
- import { DateTimePicker } from '$lib/components/ui/datetime-picker';
+ import { DateTimeCalendar } from '$lib/components/ui/datetime-picker';
import * as Popover from '$lib/components/ui/popover';
import { Clock, ChevronDown, ChevronRight, Check } from '@lucide/svelte';
import { CalendarDate, CalendarDateTime, getLocalTimeZone, today } from '@internationalized/date';
@@ -471,7 +471,7 @@
</button>
</Popover.Trigger>
<Popover.Content class="w-auto p-0" align="start">
- <DateTimePicker value={tempFromDateTime} onValueChange={handleFromDateTimeChange} />
+ <DateTimeCalendar value={tempFromDateTime} onValueChange={handleFromDateTimeChange} />
</Popover.Content>
</Popover.Root>
@@ -492,7 +492,7 @@
</button>
</Popover.Trigger>
<Popover.Content class="w-auto p-0" align="start">
- <DateTimePicker value={tempToDateTime} onValueChange={handleToDateTimeChange} />
+ <DateTimeCalendar value={tempToDateTime} onValueChange={handleToDateTimeChange} />
</Popover.Content>
</Popover.Root>
</div>
diff --git a/frontend/src/routes/monitors/record-incident-dialog.svelte b/frontend/src/routes/monitors/record-incident-dialog.svelte
index 0f1a3904..c9705304 100644
--- a/frontend/src/routes/monitors/record-incident-dialog.svelte
+++ b/frontend/src/routes/monitors/record-incident-dialog.svelte
@@ -3,6 +3,7 @@
import { Button } from '$lib/components/ui/button';
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
+ import { DateTimePicker } from '$lib/components/ui/datetime-picker';
import { Checkbox } from '$lib/components/ui/checkbox';
import { ErrorAlert } from '$lib/components/ui/error-alert';
import { Plus } from '@lucide/svelte';
@@ -107,20 +108,14 @@
<div class="grid gap-4 sm:grid-cols-2">
<div class="space-y-2">
<Label for="incident-started">Started at</Label>
- <Input
- id="incident-started"
- type="datetime-local"
- bind:value={startedAt}
- disabled={saving}
- />
+ <DateTimePicker id="incident-started" bind:value={startedAt} disabled={saving} />
</div>
<div class="space-y-2">
<Label for="incident-resolved" class={alreadyResolved ? '' : 'text-muted-foreground'}>
Resolved at
</Label>
- <Input
+ <DateTimePicker
id="incident-resolved"
- type="datetime-local"
bind:value={resolvedAt}
disabled={saving || !alreadyResolved}
/>
diff --git a/frontend/src/routes/on-call/layer-editor.svelte b/frontend/src/routes/on-call/layer-editor.svelte
index 99370c54..fe1f93c7 100644
--- a/frontend/src/routes/on-call/layer-editor.svelte
+++ b/frontend/src/routes/on-call/layer-editor.svelte
@@ -4,6 +4,8 @@
import { Button } from '$lib/components/ui/button';
import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
+ import { DatePicker } from '$lib/components/ui/date-picker';
+ import { TimePicker } from '$lib/components/ui/time-picker';
import * as Select from '$lib/components/ui/select';
import { ErrorAlert } from '$lib/components/ui/error-alert';
import { Plus, Check, Trash2, ChevronUp, ChevronDown, X } from '@lucide/svelte';
@@ -233,7 +235,7 @@
</div>
<div class="space-y-1">
<Label class="text-xs">Handoff time</Label>
- <Input type="time" bind:value={layer.handoffTime} />
+ <TimePicker bind:value={layer.handoffTime} />
</div>
{#if layer.rotationType === 'weekly'}
<div class="space-y-1">
@@ -261,7 +263,7 @@
{/if}
<div class="space-y-1">
<Label class="text-xs">Rotation start</Label>
- <Input type="date" bind:value={layer.rotationStart} />
+ <DatePicker bind:value={layer.rotationStart} />
</div>
</div>
@@ -358,7 +360,7 @@
</Select.Content>
</Select.Root>
{/if}
- <Input type="time" bind:value={restriction.startTime} class="w-32" />
+ <TimePicker bind:value={restriction.startTime} class="w-32" />
<span class="text-xs text-muted-foreground">to</span>
{#if restriction.type === 'weekly'}
<Select.Root
@@ -376,7 +378,7 @@
</Select.Content>
</Select.Root>
{/if}
- <Input type="time" bind:value={restriction.endTime} class="w-32" />
+ <TimePicker bind:value={restriction.endTime} class="w-32" />
<Button
variant="ghost"
size="icon"
diff --git a/frontend/src/routes/on-call/override-dialog.svelte b/frontend/src/routes/on-call/override-dialog.svelte
index 4bf46704..90bca1db 100644
--- a/frontend/src/routes/on-call/override-dialog.svelte
+++ b/frontend/src/routes/on-call/override-dialog.svelte
@@ -1,8 +1,8 @@
<script lang="ts">
import * as AlertDialog from '$lib/components/ui/alert-dialog';
import { Button } from '$lib/components/ui/button';
- import { Input } from '$lib/components/ui/input';
import { Label } from '$lib/components/ui/label';
+ import { DateTimePicker } from '$lib/components/ui/datetime-picker';
import * as Select from '$lib/components/ui/select';
import { ErrorAlert } from '$lib/components/ui/error-alert';
import { Plus } from '@lucide/svelte';
@@ -110,12 +110,12 @@
<div class="space-y-2">
<Label for="override-start">Start</Label>
- <Input id="override-start" type="datetime-local" bind:value={startAt} />
+ <DateTimePicker id="override-start" bind:value={startAt} />
</div>
<div class="space-y-2">
<Label for="override-end">End</Label>
- <Input id="override-end" type="datetime-local" bind:value={endAt} />
+ <DateTimePicker id="override-end" bind:value={endAt} />
</div>
<p class="text-xs text-muted-foreground">