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