import "@potzblitz/styles/lib/components/Select.scss"; import React, { useState } from "react"; import { api } from "@potzblitz/components"; export function Select(props: api.SelectProps) { const [idStr, _id] = api.uniqueName(props.label); const [vO, setVO] = useState(props.value); const [showOptions, setShowOptions] = useState(false); const handleSelect = (option: T) => { const idx = props.options.indexOf(option); props.onSelect && props.onSelect(option, idx); setVO(idx); setShowOptions(false); }; return (
{props.label && }
setShowOptions(!showOptions)}> {props.displayFn ? props.displayFn(props.options[vO]) : props.options[vO]}
{props.options .filter((o) => o !== props.options[vO]) .map((option: T) => { return (
handleSelect(option)} > {props.displayFn ? props.displayFn(option) : option}
); })}
); }