-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature-view_product' into viewProduct/#112
- Loading branch information
Showing
12 changed files
with
296 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import styled from '@emotion/styled'; | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
import { | ||
checkedItemsState, | ||
filterListState, | ||
filterTagState, | ||
} from '../../core/atom'; | ||
import { IcDeleteTag } from '../../public/assets/icons'; | ||
import { FilterTagProps } from '../../types/viewProduct'; | ||
|
||
export default function FilterTag(props: FilterTagProps) { | ||
const { categoryIdx, elementIdx, categoryKey, tagText } = props; | ||
const [checkedItems, setCheckedItems] = useRecoilState(checkedItemsState); | ||
const [filterTagList, setFilterTagList] = | ||
useRecoilState<FilterTagProps[]>(filterTagState); | ||
const filterTagValues = Object.values(filterTagList); | ||
const handleFilterTag = ( | ||
categoryIdx: number, | ||
elementIdx: number, | ||
tagText: string, | ||
) => { | ||
const tag: FilterTagProps = { | ||
categoryIdx: categoryIdx, | ||
elementIdx: elementIdx, | ||
categoryKey: categoryKey, | ||
tagText: tagText, | ||
}; | ||
if (checkedItems[categoryIdx].has(elementIdx)) { | ||
checkedItems[categoryIdx].delete(elementIdx); | ||
const deleteidx = filterTagList.findIndex((item) => { | ||
return ( | ||
item.categoryIdx === categoryIdx && item.elementIdx === elementIdx | ||
); | ||
}); | ||
|
||
let copyFilterTagList = [...filterTagList]; | ||
copyFilterTagList.splice(deleteidx, 1); | ||
setFilterTagList(copyFilterTagList); | ||
} else { | ||
checkedItems[categoryIdx].add(elementIdx); | ||
setFilterTagList([...filterTagList, tag]); | ||
console.log(filterTagList); | ||
} | ||
|
||
setCheckedItems({ | ||
...checkedItems, | ||
[categoryIdx]: checkedItems[categoryIdx], | ||
}); | ||
}; | ||
return ( | ||
<StFilterTag> | ||
<h2>{tagText === '기타' ? `${tagText} (${categoryKey})` : tagText}</h2> | ||
<StDeleteBtn | ||
onClick={() => handleFilterTag(categoryIdx, elementIdx, tagText)} | ||
/> | ||
</StFilterTag> | ||
); | ||
} | ||
const StFilterTag = styled.div` | ||
display: flex; | ||
align-items: center; | ||
width: fit-content; | ||
padding: 0.6rem 0.8rem 0.6rem 1rem; | ||
margin: 0.5rem; | ||
border-radius: 0.6rem; | ||
background-color: ${({ theme }) => theme.colors.gray002}; | ||
color: ${({ theme }) => theme.colors.gray009}; | ||
${({ theme }) => theme.fonts.b5_14_medium_140}; | ||
`; | ||
const StDeleteBtn = styled(IcDeleteTag)` | ||
margin-left: 0.713rem; | ||
cursor: pointer; | ||
`; |
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,65 @@ | ||
import styled from '@emotion/styled'; | ||
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { filterListState, filterTagState } from '../../core/atom'; | ||
import { IcUndoBtn } from '../../public/assets/icons'; | ||
import { FilterTagProps } from '../../types/viewProduct'; | ||
import FilterTag from './FilterTag'; | ||
|
||
export default function TagSection() { | ||
const filterTagList = useRecoilValue<FilterTagProps[]>(filterTagState); | ||
|
||
return ( | ||
<StTagSection> | ||
<StTagWrapper> | ||
{filterTagList.map( | ||
({ categoryIdx, elementIdx, categoryKey, tagText }) => { | ||
return ( | ||
<FilterTag | ||
key={`${categoryKey}${tagText}`} | ||
categoryIdx={categoryIdx} | ||
elementIdx={elementIdx} | ||
categoryKey={categoryKey} | ||
tagText={tagText} | ||
/> | ||
); | ||
}, | ||
)} | ||
</StTagWrapper> | ||
<StUndoAllTagBtn> | ||
<h2>모두 해제</h2> | ||
<IcUndoBtn /> | ||
</StUndoAllTagBtn> | ||
</StTagSection> | ||
); | ||
} | ||
|
||
const StTagWrapper = styled.article` | ||
display: flex; | ||
justify-content: flex-start; | ||
flex-flow: row wrap; | ||
width: 77.6rem; | ||
height: fit-content; | ||
`; | ||
const StTagSection = styled.div` | ||
display: flex; | ||
align-items: flex-start; | ||
justify-content: space-between; | ||
padding: 1.5rem 0; | ||
margin-left: 2.4rem; | ||
border-bottom: 0.1rem solid ${({ theme }) => theme.colors.gray002}; | ||
`; | ||
const StUndoAllTagBtn = styled.button` | ||
display: flex; | ||
align-items: center; | ||
padding: 0 0 0 1rem; | ||
margin-top: 0.5rem; | ||
background-color: ${({ theme }) => theme.colors.white}; | ||
border-radius: 0.6rem; | ||
border: 0.1rem solid ${({ theme }) => theme.colors.gray004}; | ||
color: ${({ theme }) => theme.colors.gray007}; | ||
${({ theme }) => theme.fonts.b5_14_medium_140}; | ||
`; |
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
Oops, something went wrong.