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

43 lines
995 B
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"
2021-08-19 21:01:11 +00:00
import {SelectContext} from "./SelectContext";
2021-08-19 17:54:58 +00:00
interface SelectProps {
disabled?: boolean,
onChange?: (contents: string) => boolean,
children: React.ReactNode,
[props: string]: any,
}
2021-08-19 21:01:11 +00:00
export function Select({onChange, ...props}: SelectProps): JSX.Element {
2021-08-19 17:54:58 +00:00
props.bluelibClassNames = mergeClassNames(props.bluelibClassNames, "input", "input-select")
const onChangeWrapper = React.useCallback(
2021-08-20 03:03:18 +00:00
(event: React.ChangeEvent<HTMLSelectElement>): boolean => {
2021-08-19 17:54:58 +00:00
const contents = event.target.value
if(onChange) {
return onChange(contents)
}
return false
},
[onChange]
)
return (
2021-08-19 21:01:11 +00:00
<BaseElement kind={"select"} multiple={false} onChange={onChangeWrapper} {...props}/>
2021-08-19 17:54:58 +00:00
)
}