search_awesome/components/SearchBar.tsx

31 lines
981 B
TypeScript
Raw Permalink Normal View History

2022-11-29 01:52:44 +09:00
import { useState } from "preact/hooks";
export interface SearchBarProps {
value: string;
onChange: (value: string) => void;
2022-12-01 19:40:03 +09:00
onSubmit: () => void;
2022-11-29 01:52:44 +09:00
}
export function SearchBar(props: SearchBarProps) {
2022-12-01 19:40:03 +09:00
const { value, onChange, onSubmit } = props;
2022-11-29 01:52:44 +09:00
return (
<div class="flex items-center justify-center w-full p-4">
<input class="w-full flex-auto p-2 border border-gray-200 rounded
focus:outline-none focus:border-gray-600"
2022-12-01 19:40:03 +09:00
type="text" placeholder="Search..." value={value}
2022-11-29 01:52:44 +09:00
onInput={e=>{
if(e.currentTarget){
onChange(e.currentTarget.value);
}
2022-12-01 19:40:03 +09:00
}}
onKeyUp={e=>{
if(e.key === "Enter"){
onSubmit();
}
}}/>
2022-11-29 01:52:44 +09:00
<button class="flex-grow-0 p-2 ml-2 text-white bg-blue-500 rounded hover:bg-blue-600"
2022-12-01 19:40:03 +09:00
type="submit" onClick={onSubmit}>Submit</button>
2022-11-29 01:52:44 +09:00
</div>
);
}