Datepicker And Color picker with dropdown
Deploy Docs to Synology / deploy (push) Successful in 4s

This commit is contained in:
2026-04-27 16:55:32 +02:00
parent 19279524d7
commit 495362c11c
9 changed files with 95 additions and 89 deletions
-9
View File
@@ -2658,9 +2658,6 @@
} }
} }
} }
.inset-0 {
inset: calc(var(--spacing) * 0);
}
.chat-end { .chat-end {
@layer daisyui.l1.l2 { @layer daisyui.l1.l2 {
place-items: end; place-items: end;
@@ -2972,12 +2969,6 @@
.z-50 { .z-50 {
z-index: 50; z-index: 50;
} }
.z-\[90\] {
z-index: 90;
}
.z-\[100\] {
z-index: 100;
}
.z-\[9999\] { .z-\[9999\] {
z-index: 9999; z-index: 9999;
} }
+26 -24
View File
@@ -724,13 +724,11 @@ var Calendar = (p2) => {
} }
]), ]),
p2.hour ? O("div", { class: "mt-3 pt-2 border-t border-base-300" }, rangeMode() ? O("div", { class: "flex gap-4" }, [HourSlider({ value: startHour, onChange: (h) => startHour(h) }), HourSlider({ value: endHour, onChange: (h) => endHour(h) })]) : HourSlider({ value: startHour, onChange: (h) => startHour(h) })) : null, p2.hour ? O("div", { class: "mt-3 pt-2 border-t border-base-300" }, rangeMode() ? O("div", { class: "flex gap-4" }, [HourSlider({ value: startHour, onChange: (h) => startHour(h) }), HourSlider({ value: endHour, onChange: (h) => endHour(h) })]) : HourSlider({ value: startHour, onChange: (h) => startHour(h) })) : null,
O("div", { class: cls("flex gap-2 mt-3 pt-2", !p2.hour && "border-t border-base-300") }, [
O("button", { O("button", {
type: "button", type: "button",
class: "btn btn-xs flex-1", class: "btn btn-xs w-full",
onclick: () => close() onclick: () => close()
}, Icon("icon-[lucide--x]")) }, Icon("icon-[lucide--x]"))
])
]); ]);
}; };
var Card = (p2, c) => O("div", { ...p2, class: cls("card", p2.class) }, c); var Card = (p2, c) => O("div", { ...p2, class: cls("card", p2.class) }, c);
@@ -754,7 +752,6 @@ var Colorpicker = (p2) => {
]), ]),
DropdownContent({ class: "p-3 bg-base-100 rounded-box shadow-xl w-64" }, ColorPalette({ value: p2.value, onchange: (c) => { DropdownContent({ class: "p-3 bg-base-100 rounded-box shadow-xl w-64" }, ColorPalette({ value: p2.value, onchange: (c) => {
isFn(p2.value) ? p2.value(c) : p2.onchange?.(c); isFn(p2.value) ? p2.value(c) : p2.onchange?.(c);
close();
} })) } }))
]); ]);
}; };
@@ -845,7 +842,6 @@ var ColorPalette = (p2) => {
]; ];
}; };
var Datepicker = (p2) => { var Datepicker = (p2) => {
const isOpen = S(false);
const displayValue = S(""); const displayValue = S("");
const rangeMode = () => get(p2.range) === true; const rangeMode = () => get(p2.range) === true;
R(() => { R(() => {
@@ -871,27 +867,33 @@ var Datepicker = (p2) => {
else else
p2.onChange?.(val); p2.onChange?.(val);
if (!rangeMode() || val?.end != null) if (!rangeMode() || val?.end != null)
isOpen(false); close();
}; };
return O("div", { class: cls("relative w-full", p2.class) }, [ return Dropdown({ class: cls("w-full", p2.class) }, [
O("label", { class: "input input-bordered w-full", onclick: (e) => { O("label", {
e.stopPropagation(); tabindex: "0",
isOpen(!isOpen()); role: "button",
} }, [ class: "input input-bordered w-full flex items-center gap-2 cursor-pointer"
O("span", { class: "icon-[lucide--calendar]" }), }, [
O("input", { O("span", { class: "icon-[lucide--calendar] shrink-0" }),
...p2, O("span", {
type: "text", class: () => `grow text-left truncate ${!displayValue() ? "opacity-50" : ""}`
class: "grow", }, () => displayValue() || p2.placeholder || (rangeMode() ? "Seleccionar rango..." : "Seleccionar fecha..."))
value: displayValue,
readonly: true,
placeholder: p2.placeholder || (rangeMode() ? "Seleccionar rango..." : "Seleccionar fecha...")
})
]), ]),
z(isOpen, () => [ DropdownContent({ class: "p-0 bg-base-100 rounded-box shadow-xl" }, Calendar({
O("div", { class: "fixed inset-0 z-[90]", onclick: () => isOpen(false) }), value: p2.value,
O("div", { class: "absolute left-0 mt-2 z-[100]", onclick: (e) => e.stopPropagation() }, Calendar({ value: p2.value, range: rangeMode(), hour: p2.hour, onChange: handleChange })) range: rangeMode(),
]) hour: p2.hour,
onChange: handleChange,
onAccept: () => {
p2.onAccept?.();
close();
},
onCancel: () => {
p2.onCancel?.();
close();
}
}))
]); ]);
}; };
var Drawer = (p2, c) => div({ ...p2, class: cls("drawer", p2.class) }, c); var Drawer = (p2, c) => div({ ...p2, class: cls("drawer", p2.class) }, c);
+1 -1
View File
File diff suppressed because one or more lines are too long
+26 -24
View File
@@ -755,13 +755,11 @@
} }
]), ]),
p2.hour ? O("div", { class: "mt-3 pt-2 border-t border-base-300" }, rangeMode() ? O("div", { class: "flex gap-4" }, [HourSlider({ value: startHour, onChange: (h) => startHour(h) }), HourSlider({ value: endHour, onChange: (h) => endHour(h) })]) : HourSlider({ value: startHour, onChange: (h) => startHour(h) })) : null, p2.hour ? O("div", { class: "mt-3 pt-2 border-t border-base-300" }, rangeMode() ? O("div", { class: "flex gap-4" }, [HourSlider({ value: startHour, onChange: (h) => startHour(h) }), HourSlider({ value: endHour, onChange: (h) => endHour(h) })]) : HourSlider({ value: startHour, onChange: (h) => startHour(h) })) : null,
O("div", { class: cls("flex gap-2 mt-3 pt-2", !p2.hour && "border-t border-base-300") }, [
O("button", { O("button", {
type: "button", type: "button",
class: "btn btn-xs flex-1", class: "btn btn-xs w-full",
onclick: () => close() onclick: () => close()
}, Icon("icon-[lucide--x]")) }, Icon("icon-[lucide--x]"))
])
]); ]);
}; };
var Card = (p2, c) => O("div", { ...p2, class: cls("card", p2.class) }, c); var Card = (p2, c) => O("div", { ...p2, class: cls("card", p2.class) }, c);
@@ -785,7 +783,6 @@
]), ]),
DropdownContent({ class: "p-3 bg-base-100 rounded-box shadow-xl w-64" }, ColorPalette({ value: p2.value, onchange: (c) => { DropdownContent({ class: "p-3 bg-base-100 rounded-box shadow-xl w-64" }, ColorPalette({ value: p2.value, onchange: (c) => {
isFn(p2.value) ? p2.value(c) : p2.onchange?.(c); isFn(p2.value) ? p2.value(c) : p2.onchange?.(c);
close();
} })) } }))
]); ]);
}; };
@@ -876,7 +873,6 @@
]; ];
}; };
var Datepicker = (p2) => { var Datepicker = (p2) => {
const isOpen = S(false);
const displayValue = S(""); const displayValue = S("");
const rangeMode = () => get(p2.range) === true; const rangeMode = () => get(p2.range) === true;
R(() => { R(() => {
@@ -902,27 +898,33 @@
else else
p2.onChange?.(val); p2.onChange?.(val);
if (!rangeMode() || val?.end != null) if (!rangeMode() || val?.end != null)
isOpen(false); close();
}; };
return O("div", { class: cls("relative w-full", p2.class) }, [ return Dropdown({ class: cls("w-full", p2.class) }, [
O("label", { class: "input input-bordered w-full", onclick: (e) => { O("label", {
e.stopPropagation(); tabindex: "0",
isOpen(!isOpen()); role: "button",
} }, [ class: "input input-bordered w-full flex items-center gap-2 cursor-pointer"
O("span", { class: "icon-[lucide--calendar]" }), }, [
O("input", { O("span", { class: "icon-[lucide--calendar] shrink-0" }),
...p2, O("span", {
type: "text", class: () => `grow text-left truncate ${!displayValue() ? "opacity-50" : ""}`
class: "grow", }, () => displayValue() || p2.placeholder || (rangeMode() ? "Seleccionar rango..." : "Seleccionar fecha..."))
value: displayValue,
readonly: true,
placeholder: p2.placeholder || (rangeMode() ? "Seleccionar rango..." : "Seleccionar fecha...")
})
]), ]),
z(isOpen, () => [ DropdownContent({ class: "p-0 bg-base-100 rounded-box shadow-xl" }, Calendar({
O("div", { class: "fixed inset-0 z-[90]", onclick: () => isOpen(false) }), value: p2.value,
O("div", { class: "absolute left-0 mt-2 z-[100]", onclick: (e) => e.stopPropagation() }, Calendar({ value: p2.value, range: rangeMode(), hour: p2.hour, onChange: handleChange })) range: rangeMode(),
]) hour: p2.hour,
onChange: handleChange,
onAccept: () => {
p2.onAccept?.();
close();
},
onCancel: () => {
p2.onCancel?.();
close();
}
}))
]); ]);
}; };
var Drawer = (p2, c) => div({ ...p2, class: cls("drawer", p2.class) }, c); var Drawer = (p2, c) => div({ ...p2, class: cls("drawer", p2.class) }, c);
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+29 -18
View File
@@ -218,9 +218,9 @@ export const ColorPalette = (p) => {
}, Icon('icon-[lucide--x]'))] }, Icon('icon-[lucide--x]'))]
} }
export const Datepicker = (p) => { export const Datepicker = (p) => {
const isOpen = $(false)
const displayValue = $("") const displayValue = $("")
const rangeMode = () => get(p.range) === true const rangeMode = () => get(p.range) === true
watch(() => { watch(() => {
const v = get(p.value) const v = get(p.value)
if (!v) return displayValue("") if (!v) return displayValue("")
@@ -237,30 +237,41 @@ export const Datepicker = (p) => {
} }
displayValue(text) displayValue(text)
}) })
const handleChange = (val) => { const handleChange = (val) => {
if (isFn(p.value)) p.value(val) if (isFn(p.value)) p.value(val)
else p.onChange?.(val) else p.onChange?.(val)
if (!rangeMode() || val?.end != null) isOpen(false) if (!rangeMode() || val?.end != null) close()
} }
return h('div', { class: cls('relative w-full', p.class) }, [
h('label', { class: 'input input-bordered w-full', onclick: (e) => { e.stopPropagation(); isOpen(!isOpen()) } }, [ return Dropdown({ class: cls('w-full', p.class) }, [
h('span', { class: 'icon-[lucide--calendar]' }), h('label', {
h('input', { tabindex: '0', // ← Necesario para que funcione el dropdown
...p, role: 'button', // ← Necesario para que funcione el dropdown
type: 'text', class: 'input input-bordered w-full flex items-center gap-2 cursor-pointer'
class: 'grow', }, [
value: displayValue, h('span', { class: 'icon-[lucide--calendar] shrink-0' }),
readonly: true, h('span', {
placeholder: p.placeholder || (rangeMode() ? 'Seleccionar rango...' : 'Seleccionar fecha...') class: () => `grow text-left truncate ${!displayValue() ? 'opacity-50' : ''}`,
}) }, () => displayValue() || p.placeholder || (rangeMode() ? 'Seleccionar rango...' : 'Seleccionar fecha...'))
]), ]),
when(isOpen, () => [ DropdownContent({ class: 'p-0 bg-base-100 rounded-box shadow-xl' },
h('div', { class: 'fixed inset-0 z-[90]', onclick: () => isOpen(false) }), Calendar({
h('div', { class: 'absolute left-0 mt-2 z-[100]', onclick: (e) => e.stopPropagation() }, value: p.value,
Calendar({ value: p.value, range: rangeMode(), hour: p.hour, onChange: handleChange }) range: rangeMode(),
hour: p.hour,
onChange: handleChange,
onAccept: () => {
p.onAccept?.()
close()
},
onCancel: () => {
p.onCancel?.()
close()
}
})
) )
]) ])
])
} }
export const Drawer = (p, c) => div({ ...p, class: cls('drawer', p.class) }, c) export const Drawer = (p, c) => div({ ...p, class: cls('drawer', p.class) }, c)
export const DrawerToggle = (p) => input({ ...p, type: 'checkbox', class: 'drawer-toggle', checked: () => get(p.checked), onchange: (e) => isFn(p.checked) && p.checked(e.target.checked) }) export const DrawerToggle = (p) => input({ ...p, type: 'checkbox', class: 'drawer-toggle', checked: () => get(p.checked), onchange: (e) => isFn(p.checked) && p.checked(e.target.checked) })