movie-web/src/components/SearchBar.tsx

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2023-08-20 17:59:46 +02:00
import c from "classnames";
import { useState } from "react";
import { Flare } from "@/components/utils/Flare";
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
export interface SearchBarProps {
2022-02-10 23:45:17 +01:00
placeholder?: string;
2023-10-13 21:41:44 +02:00
onChange: (value: string, force: boolean) => void;
2022-05-03 20:58:34 +02:00
onUnFocus: () => void;
2023-10-13 21:41:44 +02:00
value: string;
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);
function setSearch(value: string) {
2023-10-13 21:41:44 +02:00
props.onChange(value, false);
}
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)}
2023-10-13 21:41:44 +02:00
value={props.value}
2023-08-20 20:04:06 +02:00
className="w-full flex-1 bg-transparent px-4 py-4 pl-12 text-search-text placeholder-search-placeholder focus:outline-none sm:py-4 sm:pr-2"
2023-08-20 17:59:46 +02:00
placeholder={props.placeholder}
/>
</Flare.Child>
</Flare.Base>
2022-02-10 23:45:17 +01:00
);
2022-02-07 23:22:35 +01:00
}