From 65d78ca21580681b93847044a5d8a2292a0bdf9d Mon Sep 17 00:00:00 2001 From: natxocc Date: Tue, 21 Apr 2026 18:00:39 +0200 Subject: [PATCH] remode vilterlist --- components/FilterList.js | 55 ---------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 components/FilterList.js diff --git a/components/FilterList.js b/components/FilterList.js deleted file mode 100644 index 97f67a9..0000000 --- a/components/FilterList.js +++ /dev/null @@ -1,55 +0,0 @@ -// components/FilterList.js -import { $, Tag, For, Watch } from "sigpro"; - -export const FilterList = (props) => { - const { items, filterKeys = ["label"], placeholder = "Filtrar...", renderItem, onSelect, class: className } = props; - - const filterText = $(""); - const filteredItems = $([]); - - const updateFiltered = () => { - const q = String(filterText()).toLowerCase(); - // items puede ser función, señal o array plano - const allItems = typeof items === "function" ? items() : items || []; - if (!q) { - filteredItems([...allItems]); - return; - } - const filtered = allItems.filter(item => - filterKeys.some(key => { - const val = typeof item === "string" ? item : item[key]; - return String(val || "").toLowerCase().includes(q); - }) - ); - filteredItems(filtered); - }; - - // Ejecutar inmediatamente al montar y luego reactivamente cuando cambie items o filterText - updateFiltered(); - Watch(() => { - // Dependencias: items (evaluado) y filterText - const it = typeof items === "function" ? items() : items; - return { it, ft: filterText() }; - }, () => updateFiltered()); - - return Tag("div", { class: `filter-list flex flex-col ${className ?? ''}` }, [ - Tag("div", { class: "p-2 border-b border-base-300" }, [ - Tag("label", { class: "input input-sm input-bordered flex items-center gap-2 w-full" }, [ - Tag("span", { class: "icon-[lucide--search] opacity-50" }), - Tag("input", { - type: "text", - class: "grow", - placeholder, - value: filterText, - oninput: (e) => filterText(e.target.value), - ref: (el) => { if (el && props.autoFocus) el.focus(); } - }) - ]) - ]), - Tag("div", { class: "max-h-60 overflow-y-auto" }, [ - For(filteredItems, (item, idx) => - renderItem(item, idx, () => onSelect?.(item)) - ) - ]) - ]); -}; \ No newline at end of file