@insymetri/styleguide 0.1.45 → 0.1.46
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.
|
@@ -41,14 +41,40 @@
|
|
|
41
41
|
const showError = $derived(error || !!errorMessage)
|
|
42
42
|
|
|
43
43
|
let placeholder = $state<DateValue>(today(getLocalTimeZone()))
|
|
44
|
+
let inputEl = $state<HTMLElement | null>(null)
|
|
45
|
+
let internalValue = $state<DateValue | undefined>(value)
|
|
46
|
+
|
|
47
|
+
// Sync external value changes into internal state
|
|
48
|
+
$effect(() => {
|
|
49
|
+
internalValue = value
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
function allSegmentsEmpty() {
|
|
53
|
+
if (!inputEl) return true
|
|
54
|
+
const segments = inputEl.querySelectorAll('[data-segment]:not([data-segment="trigger"]):not([data-segment="literal"])')
|
|
55
|
+
return Array.from(segments).every(s => s.hasAttribute('data-placeholder'))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function handleValueChange(newValue: DateValue | undefined) {
|
|
59
|
+
if (newValue === undefined && !allSegmentsEmpty()) {
|
|
60
|
+
// A segment was partially cleared — restore the internal value
|
|
61
|
+
// to prevent bits-ui from wiping the date
|
|
62
|
+
internalValue = value
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
internalValue = newValue
|
|
66
|
+
value = newValue
|
|
67
|
+
onValueChange?.(newValue)
|
|
68
|
+
}
|
|
44
69
|
</script>
|
|
45
70
|
|
|
46
71
|
<div class={cn('flex flex-col gap-4', className)}>
|
|
47
|
-
<DatePicker.Root
|
|
72
|
+
<DatePicker.Root value={internalValue} bind:placeholder onValueChange={handleValueChange} {disabled}>
|
|
48
73
|
{#if label}
|
|
49
74
|
<DatePicker.Label class="text-small-emphasis text-secondary">{label}</DatePicker.Label>
|
|
50
75
|
{/if}
|
|
51
76
|
<DatePicker.Input
|
|
77
|
+
bind:ref={inputEl}
|
|
52
78
|
class={cn(
|
|
53
79
|
'flex items-center gap-4 px-12 border bg-input-bg border-input-border transition-all duration-fast hover:border-input-border-hover [&:has(:focus)]:border-accent [&:has(:focus)]:ring-3 [&:has(:focus)]:ring-primary motion-reduce:transition-none',
|
|
54
80
|
densityClasses[density.value],
|