-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Replaced react-autocomplete with custom based on Bootstrap dropdo…
…wn (#362)
- Loading branch information
Showing
11 changed files
with
148 additions
and
381 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
|
||
export default function Autocomplete({ | ||
items, | ||
getItemValue, | ||
renderItem, | ||
value, | ||
onChange, | ||
children, | ||
prependChildren, | ||
...inputProps | ||
}) { | ||
const itemValue = getItemValue || ((item) => item); | ||
const ItemComponent = renderItem || (({ item }) => itemValue(item)); | ||
const menuStyle = items.length === 0 ? { display: "none" } : {}; | ||
|
||
return ( | ||
<div className="dropdown input-group"> | ||
{prependChildren ? children : []} | ||
<input | ||
value={value} | ||
onChange={(ev) => onChange(ev.target.value)} | ||
{...(inputProps || {})} | ||
data-toggle="dropdown" | ||
/> | ||
<div className="dropdown-menu" role="menu" style={menuStyle}> | ||
{items.map((item) => ( | ||
<button | ||
key={itemValue(item)} | ||
className="dropdown-item" | ||
onClick={(ev) => { | ||
ev.preventDefault(); | ||
onChange(itemValue(item)); | ||
}} | ||
> | ||
<ItemComponent item={item} /> | ||
</button> | ||
))} | ||
</div> | ||
{prependChildren ? [] : children} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.