2023-08-20 17:59:46 +02:00
|
|
|
import c from "classnames";
|
|
|
|
import { useState } from "react";
|
|
|
|
|
2023-06-30 12:20:01 +02:00
|
|
|
import { MWQuery } from "@/backend/metadata/types/mw";
|
2023-08-20 17:59:46 +02:00
|
|
|
import { Flare } from "@/components/utils/Flare";
|
2023-04-24 17:41:54 +02:00
|
|
|
|
2023-01-07 21:36:18 +01:00
|
|
|
import { Icon, 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-10 23:45:17 +01:00
|
|
|
placeholder?: string;
|
2022-05-03 20:58:34 +02:00
|
|
|
onChange: (value: MWQuery, force: boolean) => void;
|
|
|
|
onUnFocus: () => void;
|
2022-02-13 19:29:25 +01:00
|
|
|
value: MWQuery;
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function SearchBarInput(props: SearchBarProps) {
|
2023-08-20 17:59:46 +02:00
|
|
|
const [focused, setFocused] = useState(false);
|
|
|
|
|
2022-02-13 19:29:25 +01:00
|
|
|
function setSearch(value: string) {
|
2022-05-03 20:58:34 +02:00
|
|
|
props.onChange(
|
|
|
|
{
|
|
|
|
...props.value,
|
|
|
|
searchQuery: value,
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2022-02-13 19:29:25 +01:00
|
|
|
}
|
2022-02-13 18:49:03 +01:00
|
|
|
|
2022-02-07 23:22:35 +01:00
|
|
|
return (
|
2023-08-20 17:59:46 +02:00
|
|
|
<Flare.Base
|
|
|
|
className={c({
|
|
|
|
"hover:flare-enabled group relative flex flex-col rounded-[28px] transition-colors sm:flex-row sm:items-center":
|
|
|
|
true,
|
|
|
|
"bg-search-background": !focused,
|
|
|
|
"bg-search-focused": focused,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<Flare.Light
|
|
|
|
flareSize={400}
|
|
|
|
enabled={focused}
|
|
|
|
className="rounded-[28px]"
|
|
|
|
backgroundClass={c({
|
|
|
|
"transition-colors": true,
|
|
|
|
"bg-search-background": !focused,
|
|
|
|
"bg-search-focused": focused,
|
|
|
|
})}
|
2022-02-10 23:45:17 +01:00
|
|
|
/>
|
2023-08-20 17:59:46 +02:00
|
|
|
|
|
|
|
<Flare.Child className="flex flex-1 flex-col">
|
|
|
|
<div className="pointer-events-none absolute bottom-0 left-5 top-0 flex max-h-14 items-center text-search-icon">
|
|
|
|
<Icon icon={Icons.SEARCH} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<TextInputControl
|
|
|
|
onUnFocus={() => {
|
|
|
|
setFocused(false);
|
|
|
|
props.onUnFocus();
|
|
|
|
}}
|
|
|
|
onFocus={() => setFocused(true)}
|
|
|
|
onChange={(val) => setSearch(val)}
|
|
|
|
value={props.value.searchQuery}
|
|
|
|
className="text-search-text w-full flex-1 bg-transparent px-4 py-4 pl-12 placeholder-search-placeholder focus:outline-none sm:py-4 sm:pr-2"
|
|
|
|
placeholder={props.placeholder}
|
|
|
|
/>
|
|
|
|
</Flare.Child>
|
|
|
|
</Flare.Base>
|
2022-02-10 23:45:17 +01:00
|
|
|
);
|
2022-02-07 23:22:35 +01:00
|
|
|
}
|