feature: Problem sorting, solution view raw toggle button
parent
dcaa052f30
commit
28a1a85531
@ -1,23 +1,31 @@
|
||||
import { StateUpdater } from 'preact/hooks'
|
||||
import { JSX } from 'preact/jsx-runtime'
|
||||
|
||||
type Props = {
|
||||
options: Record<string, string>
|
||||
value: string
|
||||
setValue?: StateUpdater<string>
|
||||
type Props<K extends string, T extends K> = {
|
||||
options: Record<K, string | JSX.Element>
|
||||
value: T
|
||||
setValue?: StateUpdater<K>
|
||||
}
|
||||
|
||||
export const Select = ({ options, value, setValue }: Props) => (
|
||||
<div class="input-select">
|
||||
<select
|
||||
onInput={e => setValue?.(e.target instanceof HTMLSelectElement ? e.target.value : '')}
|
||||
>
|
||||
{Object.entries(options).map(([k, v]) => (
|
||||
<option value={k} selected={value === k}>
|
||||
{v}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span class="material-symbols-outlined">expand_more</span>
|
||||
</div>
|
||||
)
|
||||
export const Select = <K extends string, T extends K>({ options, value, setValue }: Props<K, T>) => {
|
||||
const optionValues = new Set(Object.keys(options))
|
||||
|
||||
return (
|
||||
<div class="input-select">
|
||||
<select
|
||||
onInput={e => {
|
||||
if (e.target instanceof HTMLSelectElement && optionValues.has(e.target.value)) {
|
||||
setValue?.(e.target.value as K)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{Object.entries<string | JSX.Element>(options).map(([k, v]) => (
|
||||
<option value={k} selected={value === k}>
|
||||
{v}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span class="material-symbols-outlined">expand_more</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue