icns-frontend/components/search-input/index.tsx

101 lines
1.9 KiB
TypeScript
Raw Normal View History

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;
const [isFocused, setIsFocused] = useState(false);
2022-12-13 13:10:31 +00:00
return (
<SearchContainer>
<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);
}}
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
padding: 0.6rem 1.4rem;
2022-12-13 13:10:31 +00:00
border-radius: 3rem;
background-color: ${color.grey["700"]};
`;
const SearchIconContainer = styled.div<{
focused: boolean;
}>`
2022-12-13 13:10:31 +00:00
position: relative;
width: ${({ focused }) => (focused ? 0 : "1.3rem")};
2022-12-13 13:10:31 +00:00
height: 1.3rem;
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;
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;
width: 10rem;
::placeholder,
::-webkit-input-placeholder {
color: ${color.grey["600"]};
}
2022-12-13 13:10:31 +00:00
}
`;