mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature-136] can now search models from the download modal
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user