Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 221118a

Browse files
feat(select): select component use generics (#492)
Co-authored-by: Jack Meyer <jackcmeyer@gmail.com>
1 parent 7af484a commit 221118a

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/components/Select/Select.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ import React from 'react'
22
import { Typeahead } from 'react-bootstrap-typeahead'
33
import 'react-bootstrap-typeahead/css/Typeahead.css'
44

5-
type SelectOption = { label: string; value: any }
5+
interface SelectOption<T> {
6+
label: string
7+
value: T
8+
}
69

7-
interface Props {
10+
interface Props<T> {
811
id: string
9-
options: SelectOption[]
10-
defaultSelected?: SelectOption[]
11-
onChange?: (values: string[]) => void
12+
options: SelectOption<T>[]
13+
defaultSelected?: SelectOption<T>[]
14+
onChange?: (values: T[]) => void
1215
placeholder?: string
1316
multiple?: boolean
1417
disabled?: boolean
1518
isInvalid?: boolean
1619
}
1720

18-
const Select = (props: Props) => {
21+
function Select<T>(props: Props<T>) {
1922
const {
2023
id,
2124
options,
@@ -28,11 +31,11 @@ const Select = (props: Props) => {
2831
} = props
2932

3033
return (
31-
<Typeahead<SelectOption>
34+
<Typeahead<SelectOption<T>>
3235
id={id}
3336
options={options as any}
3437
selected={defaultSelected}
35-
onChange={(selected: SelectOption[]) => {
38+
onChange={(selected: SelectOption<T>[]) => {
3639
if (onChange !== undefined) {
3740
onChange(selected.map((option) => option.value))
3841
}

0 commit comments

Comments
 (0)