Skip to content

Commit

Permalink
feat(MainToggle.js) : InputDate header prop edit
Browse files Browse the repository at this point in the history
  • Loading branch information
jiHeeFlee committed Nov 6, 2024
1 parent ec79739 commit 1d706ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/MainPage/MainToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,16 @@ const CropButton=styled.div`

function MainToggle({onToggle=()=>{},onClick=()=>{},header,elements=[],icon,toggleHeader}){
const [isToggled, setIsToggled] = useState(false);
const [selectedCrop,setSelectedCrop] = useState(null);
const [selectedButton,setSelectedButton] = useState(null);

const handleToggle=()=>{
setIsToggled((prevState)=>!prevState)
onToggle(!isToggled); // 토글 상태에 따라 Maindp dkffla
}

const handleCrop=(crop)=>{
setSelectedCrop(crop);
onClick(crop); // 작물 선택 시 부모 컴포넌트에 알림
const handleButton=(elem)=>{
setSelectedButton(elem);
onClick(elem); // 작물 선택 시 부모 컴포넌트에 알림
}

return(
Expand All @@ -181,8 +181,8 @@ function MainToggle({onToggle=()=>{},onClick=()=>{},header,elements=[],icon,togg
{elements.map((elem) => (
<CropButton
key={elem}
onClick={() => handleCrop(elem)}
className={selectedCrop === elem ? "active" : ""}
onClick={() => handleButton(elem)}
className={selectedButton === elem ? "active" : ""}
>
{elem}
</CropButton>
Expand Down
1 change: 1 addition & 0 deletions src/pages/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const Main = () => {
value={inputData.date}
onChange={handleDateButton}
onToggle={handleToggle} // onToggle 함수 추가
header={inputData.date || '날짜 선택'}
/>
</ComponentsContainer>
</Components>
Expand Down

0 comments on commit 1d706ef

Please sign in to comment.