"use client"; import type { ComponentRenderProps } from "./types"; import { baseClass, getCustomClass, getOpenSelect, setOpenSelectValue, getSelectValue, setSelectValueForKey, } from "./utils"; export function Select({ element }: ComponentRenderProps) { const { props, key } = element; const customClass = getCustomClass(props); const options = (props.options as string[]) || []; const selectedValue = getSelectValue(key); const isOpen = getOpenSelect() === key; return (
{props.label ? ( ) : null}
setOpenSelectValue(isOpen ? null : key)} className="h-7 w-full bg-background border border-border rounded px-2 text-xs flex items-center justify-between cursor-pointer hover:border-foreground/30 transition-colors" > {selectedValue || (props.placeholder as string) || "Select..."}
{isOpen && options.length > 0 && (
{options.map((opt, i) => (
{ setSelectValueForKey(key, opt); setOpenSelectValue(null); }} className={`px-2 py-1.5 text-xs text-left cursor-pointer hover:bg-muted transition-colors ${selectedValue === opt ? "bg-muted" : ""}`} > {opt}
))}
)}
); }