-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CentralChart폴더의 차트 구현 컴포넌트를 header에 import 기존 SearchBar의 CSS 디자인을 입혔습니다. Issues #15
- Loading branch information
김병현
authored and
김병현
committed
Sep 11, 2023
1 parent
58173c6
commit ca81a75
Showing
3 changed files
with
100 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React, { useState } from 'react'; | ||
import { useDispatch } from "react-redux"; | ||
import styled from "styled-components"; | ||
import { changeCompanyId } from "../../reducer/CompanyId-Reducer"; | ||
import useGetCompanyList from "../../hooks/useGetCompanyList"; | ||
|
||
interface CompanyProps { | ||
companyId: number; | ||
code: string; | ||
korName: string; | ||
stockAsBiResponseDto: null; | ||
stockInfResponseDto: null; | ||
} | ||
|
||
const StockSearchComponent: React.FC = () => { | ||
const dispatch = useDispatch(); | ||
const { companyList } = useGetCompanyList(); | ||
const [searchWord, setSearchWord] = useState(""); | ||
|
||
const handleChangeSearchWord = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setSearchWord(e.target.value); | ||
}; | ||
|
||
const handleSearchCompany = () => { | ||
let searchResult: string = "noExistCompany"; | ||
|
||
companyList.forEach((company: CompanyProps) => { | ||
if (company.korName === searchWord) { | ||
searchResult = "ExistCompany"; | ||
dispatch(changeCompanyId(company.companyId)); | ||
} | ||
}); | ||
|
||
if (searchResult === "noExistCompany") { | ||
dispatch(changeCompanyId(-1)); | ||
} | ||
}; | ||
|
||
const handlePressEnterToSearch = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.code === "Enter" && e.nativeEvent.isComposing === false) { | ||
handleSearchCompany(); | ||
setSearchWord(""); | ||
} | ||
}; | ||
|
||
return ( | ||
<SearchContainer> | ||
<StyledSearchInput | ||
value={searchWord} | ||
onChange={handleChangeSearchWord} | ||
onKeyDown={handlePressEnterToSearch} | ||
placeholder="종목 검색" | ||
/> | ||
<StyledSearchButton onClick={handleSearchCompany}>검색</StyledSearchButton> | ||
</SearchContainer> | ||
); | ||
}; | ||
|
||
export default StockSearchComponent; | ||
|
||
// 스타일 정의 | ||
|
||
const SearchContainer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
flex-grow: 0.7; // 여기에 추가 | ||
`; | ||
|
||
const StyledSearchInput = styled.input.attrs({ | ||
type: "text", | ||
placeholder: "검색...", | ||
})` | ||
width: 100%; | ||
padding: 0.5rem; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
flex: 1; | ||
`; | ||
|
||
const StyledSearchButton = styled.button` | ||
background-color: #fff; | ||
color: #2f4f4f; | ||
border: 1px solid #2f4f4f; | ||
padding: 0.5rem 1rem; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
transition: background-color 0.3s; | ||
&:hover { | ||
background-color: #f2f2f2; | ||
} | ||
margin-left: 0.5rem; | ||
`; |