Updateing Docs
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
// components/Autocomplete.js
|
||||
import { $, $html, $for } from "sigpro";
|
||||
import { val } from "../core/utils.js";
|
||||
import { tt } from "../core/i18n.js";
|
||||
import { Input } from "./Input.js"; // Importamos el componente hermano
|
||||
import { Input } from "./Input.js";
|
||||
|
||||
/** AUTOCOMPLETE */
|
||||
/**
|
||||
* Autocomplete component
|
||||
*
|
||||
* daisyUI classes used:
|
||||
* - input, input-bordered, input-primary, input-secondary
|
||||
* - menu, menu-dropdown, menu-dropdown-show
|
||||
* - bg-base-100, rounded-box, shadow-xl, border, border-base-300
|
||||
* - absolute, left-0, w-full, mt-1, p-2, max-h-60, overflow-y-auto
|
||||
* - z-50, active, bg-primary, text-primary-content
|
||||
*/
|
||||
export const Autocomplete = (props) => {
|
||||
const { options = [], value, onSelect, label, placeholder, ...rest } = props;
|
||||
const { class: className, items = [], value, onSelect, label, placeholder, ...rest } = props;
|
||||
|
||||
const query = $(val(value) || "");
|
||||
const isOpen = $(false);
|
||||
@@ -13,7 +23,7 @@ export const Autocomplete = (props) => {
|
||||
|
||||
const list = $(() => {
|
||||
const q = query().toLowerCase();
|
||||
const data = val(options) || [];
|
||||
const data = val(items) || [];
|
||||
return q
|
||||
? data.filter((o) => (typeof o === "string" ? o : o.label).toLowerCase().includes(q))
|
||||
: data;
|
||||
@@ -48,9 +58,10 @@ export const Autocomplete = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
return $html("div", { class: "relative w-full" }, [
|
||||
return $html("div", { class: 'relative w-full' }, [
|
||||
Input({
|
||||
label,
|
||||
class: className,
|
||||
placeholder: placeholder || tt("search")(),
|
||||
value: query,
|
||||
onfocus: () => isOpen(true),
|
||||
@@ -88,8 +99,8 @@ export const Autocomplete = (props) => {
|
||||
]),
|
||||
(opt, i) => (typeof opt === "string" ? opt : opt.value) + i,
|
||||
),
|
||||
() => (list().length ? null : $html("li", { class: "p-2 text-center opacity-50" }, "No results")),
|
||||
() => (list().length ? null : $html("li", { class: "p-2 text-center opacity-50" }, tt("nodata")())),
|
||||
],
|
||||
),
|
||||
]);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user