2022-03-06 13:43:32 +01:00
|
|
|
import { useState } from "react";
|
|
|
|
import { MWMediaType, MWQuery } from "providers";
|
2022-02-25 21:23:16 +01:00
|
|
|
import { DropdownButton } from "./buttons/DropdownButton";
|
2022-02-10 23:45:17 +01:00
|
|
|
import { Icons } from "./Icon";
|
2022-02-25 21:23:16 +01:00
|
|
|
import { TextInputControl } from "./text-inputs/TextInputControl";
|
2022-02-07 23:22:35 +01:00
|
|
|
|
2022-02-13 19:29:25 +01:00
|
|
|
export interface SearchBarProps {
|
2022-02-07 23:22:35 +01:00
|
|
|
buttonText?: string;
|
2022-02-10 23:45:17 +01:00
|
|
|
placeholder?: string;
|
2022-02-13 19:29:25 +01:00
|
|
|
onChange: (value: MWQuery) => void;
|
|
|
|
value: MWQuery;
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function SearchBarInput(props: SearchBarProps) {
|
2022-02-13 18:49:03 +01:00
|
|
|
const [dropdownOpen, setDropdownOpen] = useState(false);
|
2022-02-13 19:29:25 +01:00
|
|
|
function setSearch(value: string) {
|
|
|
|
props.onChange({
|
|
|
|
...props.value,
|
|
|
|
searchQuery: value,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function setType(type: string) {
|
|
|
|
props.onChange({
|
|
|
|
...props.value,
|
|
|
|
type: type as MWMediaType,
|
|
|
|
});
|
|
|
|
}
|
2022-02-13 18:49:03 +01:00
|
|
|
|
2022-02-07 23:22:35 +01:00
|
|
|
return (
|
2022-02-13 19:29:25 +01:00
|
|
|
<div className="bg-denim-300 hover:bg-denim-400 focus-within:bg-denim-400 flex flex-col items-center gap-4 rounded-[28px] px-4 py-4 transition-colors sm:flex-row sm:py-2 sm:pl-8 sm:pr-2">
|
2022-02-10 23:45:17 +01:00
|
|
|
<TextInputControl
|
2022-03-06 14:41:51 +01:00
|
|
|
onChange={(val) => setSearch(val)}
|
2022-02-13 19:29:25 +01:00
|
|
|
value={props.value.searchQuery}
|
|
|
|
className="placeholder-denim-700 w-full flex-1 bg-transparent text-white focus:outline-none"
|
2022-02-10 23:45:17 +01:00
|
|
|
placeholder={props.placeholder}
|
|
|
|
/>
|
2022-02-13 18:49:03 +01:00
|
|
|
|
|
|
|
<DropdownButton
|
|
|
|
icon={Icons.SEARCH}
|
|
|
|
open={dropdownOpen}
|
2022-03-06 14:41:51 +01:00
|
|
|
setOpen={(val) => setDropdownOpen(val)}
|
2022-02-13 19:29:25 +01:00
|
|
|
selectedItem={props.value.type}
|
2022-03-06 14:41:51 +01:00
|
|
|
setSelectedItem={(val) => setType(val)}
|
2022-02-13 18:49:03 +01:00
|
|
|
options={[
|
|
|
|
{
|
2022-02-13 19:29:25 +01:00
|
|
|
id: MWMediaType.MOVIE,
|
2022-02-13 18:49:03 +01:00
|
|
|
name: "Movie",
|
|
|
|
icon: Icons.FILM,
|
|
|
|
},
|
|
|
|
{
|
2022-02-13 19:29:25 +01:00
|
|
|
id: MWMediaType.SERIES,
|
2022-02-13 18:49:03 +01:00
|
|
|
name: "Series",
|
|
|
|
icon: Icons.CLAPPER_BOARD,
|
|
|
|
},
|
|
|
|
{
|
2022-02-13 19:29:25 +01:00
|
|
|
id: MWMediaType.ANIME,
|
2022-02-13 18:49:03 +01:00
|
|
|
name: "Anime",
|
|
|
|
icon: Icons.DRAGON,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
onClick={() => setDropdownOpen((old) => !old)}
|
|
|
|
>
|
2022-02-10 23:45:17 +01:00
|
|
|
{props.buttonText || "Search"}
|
2022-02-13 18:49:03 +01:00
|
|
|
</DropdownButton>
|
2022-02-07 23:22:35 +01:00
|
|
|
</div>
|
2022-02-10 23:45:17 +01:00
|
|
|
);
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|