[feature-136] can now search models from the download modal

This commit is contained in:
MathieuG-P
2023-05-16 00:50:47 +02:00
parent eb9775c89f
commit 645f18002a
22 changed files with 336 additions and 109 deletions
@@ -1,31 +1,30 @@
import { ChangeEvent, CSSProperties } from "react"
import { ComponentProps } from "react"
import { useTranslation } from "renderer/hooks/use-translation.hook"
type Props = {
className?: string,
style?: CSSProperties,
options?: BsmSelectOption[],
onChange?: (value: string) => void
type Props<T> = Omit<ComponentProps<"select">, "onChange"> & {
options?: BsmSelectOption<T>[],
onChange?: (value: T) => void,
}
export function BsmSelect({className, style, options, onChange}: Props) {
export function BsmSelect<T = unknown>({className, style, options, onChange}: Props<T>) {
const t = useTranslation();
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => {
onChange?.(event.target.value);
const handleChange: ComponentProps<"select">["onChange"] = (e) => {
e.preventDefault();
onChange?.(options?.[parseInt(e.target.value)]?.value);
}
return (
<select className={className} style={style} onChange={handleChange}>
{options && options.map(option => (
<option key={option.value} value={option.value}>{t(option.text)}</option>
{options && options.map((option, index) => (
<option key={index} value={index}>{t(option.text)}</option>
))}
</select>
)
}
export interface BsmSelectOption{
export interface BsmSelectOption<T>{
text: string,
value: string
value: T
}