2022-12-20 08:13:36 +00:00
|
|
|
import { Dispatch, FunctionComponent, SetStateAction, useState } from "react";
|
2022-12-13 13:10:31 +00:00
|
|
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
import color from "../../styles/color";
|
|
|
|
|
|
|
|
import SearchIcon from "../../public/images/svg/search-icon.svg";
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
searchValue: string;
|
|
|
|
setSearchValue: Dispatch<SetStateAction<string>>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SearchInput: FunctionComponent<Props> = (props) => {
|
|
|
|
const { searchValue, setSearchValue } = props;
|
|
|
|
|
2022-12-20 08:13:36 +00:00
|
|
|
const [isFocused, setIsFocused] = useState(false);
|
|
|
|
|
2022-12-13 13:10:31 +00:00
|
|
|
return (
|
|
|
|
<SearchContainer>
|
2022-12-20 08:13:36 +00:00
|
|
|
<SearchIconContainer focused={isFocused}>
|
2022-12-19 08:30:00 +00:00
|
|
|
<SearchIcon />
|
2022-12-13 13:10:31 +00:00
|
|
|
</SearchIconContainer>
|
|
|
|
|
|
|
|
<SearchText
|
|
|
|
type="text"
|
|
|
|
placeholder="search"
|
|
|
|
value={searchValue}
|
|
|
|
onChange={(event) => {
|
|
|
|
setSearchValue(event.target.value);
|
|
|
|
}}
|
2022-12-20 08:13:36 +00:00
|
|
|
onFocus={() => {
|
|
|
|
setIsFocused(true);
|
|
|
|
}}
|
|
|
|
onBlur={() => {
|
|
|
|
setIsFocused(false);
|
|
|
|
}}
|
2022-12-13 13:10:31 +00:00
|
|
|
/>
|
|
|
|
</SearchContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const SearchContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 0.625rem;
|
|
|
|
|
2022-12-17 08:00:25 +00:00
|
|
|
height: 2.3rem;
|
2022-12-13 13:10:31 +00:00
|
|
|
|
2022-12-17 09:04:21 +00:00
|
|
|
padding: 0.6rem 1.4rem;
|
2022-12-13 13:10:31 +00:00
|
|
|
|
|
|
|
border-radius: 3rem;
|
|
|
|
background-color: ${color.grey["700"]};
|
|
|
|
`;
|
|
|
|
|
2022-12-20 08:13:36 +00:00
|
|
|
const SearchIconContainer = styled.div<{
|
|
|
|
focused: boolean;
|
|
|
|
}>`
|
2022-12-13 13:10:31 +00:00
|
|
|
position: relative;
|
|
|
|
|
2022-12-20 08:13:36 +00:00
|
|
|
width: ${({ focused }) => (focused ? 0 : "1.3rem")};
|
2022-12-13 13:10:31 +00:00
|
|
|
height: 1.3rem;
|
2022-12-20 08:13:36 +00:00
|
|
|
|
|
|
|
transition: width 0.2s ease-out;
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2022-12-13 13:10:31 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
const SearchText = styled.input`
|
|
|
|
border: none;
|
|
|
|
|
|
|
|
color: ${color.white};
|
|
|
|
background-color: ${color.grey["700"]};
|
|
|
|
|
|
|
|
font-family: "Inter", serif;
|
|
|
|
font-style: normal;
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 1rem;
|
|
|
|
line-height: 1.2rem;
|
|
|
|
|
2022-12-17 09:04:21 +00:00
|
|
|
width: 5.5rem;
|
|
|
|
transition: width 0.2s ease-out;
|
|
|
|
|
2022-12-13 13:10:31 +00:00
|
|
|
::placeholder,
|
|
|
|
::-webkit-input-placeholder {
|
|
|
|
color: ${color.grey["400"]};
|
|
|
|
}
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
2022-12-17 09:04:21 +00:00
|
|
|
|
|
|
|
width: 10rem;
|
2022-12-20 08:13:36 +00:00
|
|
|
|
|
|
|
::placeholder,
|
|
|
|
::-webkit-input-placeholder {
|
|
|
|
color: ${color.grey["600"]};
|
|
|
|
}
|
2022-12-13 13:10:31 +00:00
|
|
|
}
|
|
|
|
`;
|