2025-08-06 11:39:31 +03:00
|
|
|
import { ComponentChildren } from "preact";
|
|
|
|
|
import Icon from "./Icon";
|
2025-08-10 15:21:49 +03:00
|
|
|
import type { CSSProperties } from "preact/compat";
|
2025-08-06 11:39:31 +03:00
|
|
|
|
|
|
|
|
interface FormListOpts {
|
|
|
|
|
children: ComponentChildren;
|
|
|
|
|
onSelect?: (value: string) => void;
|
2025-08-06 16:16:30 +03:00
|
|
|
style?: CSSProperties;
|
2025-08-06 11:39:31 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-06 16:16:30 +03:00
|
|
|
export default function FormList({ children, onSelect, style }: FormListOpts) {
|
2025-08-06 11:39:31 +03:00
|
|
|
return (
|
|
|
|
|
<div class="dropdown-menu static show" style={{
|
2025-08-06 16:16:30 +03:00
|
|
|
...style ?? {},
|
|
|
|
|
position: "relative",
|
2025-08-06 11:39:31 +03:00
|
|
|
}} onClick={(e) => {
|
|
|
|
|
const value = (e.target as HTMLElement)?.dataset?.value;
|
|
|
|
|
if (value && onSelect) {
|
|
|
|
|
onSelect(value);
|
|
|
|
|
}
|
|
|
|
|
}}>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface FormListItemOpts {
|
2025-08-06 12:12:37 +03:00
|
|
|
children: ComponentChildren;
|
2025-08-06 11:39:31 +03:00
|
|
|
icon?: string;
|
|
|
|
|
value?: string;
|
2025-08-06 16:16:30 +03:00
|
|
|
title?: string;
|
2025-08-10 17:53:45 +03:00
|
|
|
active?: boolean;
|
2025-08-06 11:39:31 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-10 17:53:45 +03:00
|
|
|
export function FormListItem({ children, icon, value, title, active }: FormListItemOpts) {
|
2025-08-06 11:39:31 +03:00
|
|
|
return (
|
2025-08-10 17:53:45 +03:00
|
|
|
<a class={`dropdown-item ${active ? "active" : ""}`} data-value={value} title={title}>
|
2025-08-06 11:39:31 +03:00
|
|
|
<Icon icon={icon} />
|
2025-08-06 12:12:37 +03:00
|
|
|
{children}
|
2025-08-06 11:39:31 +03:00
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface FormListHeaderOpts {
|
|
|
|
|
text: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function FormListHeader({ text }: FormListHeaderOpts) {
|
|
|
|
|
return (
|
|
|
|
|
<li>
|
|
|
|
|
<h6 className="dropdown-header">{text}</h6>
|
|
|
|
|
</li>
|
|
|
|
|
)
|
|
|
|
|
}
|