1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-24 12:34:20 +00:00
bluelib/src/components/inputs/Select.tsx

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-08-19 17:54:58 +00:00
import * as React from "react"
import * as ReactDOM from "react-dom"
import * as Types from "../../types"
import {BaseElement} from "../BaseElement"
import mergeClassNames from "classnames"
import {Option} from "./Option"
import {OptionGroup} from "./OptionGroup"
2021-08-19 17:54:58 +00:00
export interface SelectProps extends Types.BluelibHTMLProps<HTMLSelectElement> {
onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void,
onSimpleChange?: (value: string) => void,
value?: string,
2021-08-19 17:54:58 +00:00
}
export function Select({onChange, onSimpleChange, ...props}: SelectProps): JSX.Element {
2021-08-19 17:54:58 +00:00
props.bluelibClassNames = mergeClassNames(props.bluelibClassNames, "input", "input-select")
const onChangeWrapped = React.useCallback(
event => {
if(onChange) onChange(event)
if(onSimpleChange) onSimpleChange(event.target.value)
2021-08-19 17:54:58 +00:00
},
[onChange, onSimpleChange]
2021-08-19 17:54:58 +00:00
)
return (
<BaseElement kind={"select"} multiple={false} required={true} onChange={onChangeWrapped} {...props}/>
2021-08-19 17:54:58 +00:00
)
}
Select.Option = Option
Select.Group = OptionGroup