You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
globus/src/components/RepositorySearchInput.tsx

32 lines
890 B
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import React, { useContext } from 'react'
import { RepositorySearchContext } from '../context/RepositorySearchContext'
export default function RepositorySearchInput () {
const context = useContext(RepositorySearchContext)
return (
<div>
<label htmlFor="keyword-input">
<input type="text" id="keyword-input"
value={context.keyword}
onChange={({ target }) => {
context.setKeyword(target.value)
}}
onKeyDown={evt => {
const value = (evt.target as HTMLInputElement).value
if (evt.key.toLocaleLowerCase() === 'enter') {
context.setKeyword(value)
context.search(value, 1)
}
}}
/>
</label>
<button onClick={() => {
context.search(context.keyword, 1)
}} disabled={context.loading}></button>
</div>
)
}