-
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.
- Loading branch information
Showing
5 changed files
with
77 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { filterAtom } from '@recoil/map'; | ||
import { useEffect, useRef } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
function FilterMenu() { | ||
const [filterState, setFilterState] = useRecoilState(filterAtom); | ||
const filterRef = useRef<HTMLDivElement>(null); | ||
|
||
const closeFilter = (e: MouseEvent) => { | ||
if (!filterRef.current) return; | ||
if (filterState.isOpen && !filterRef.current.contains(e.target as HTMLElement)) { | ||
setFilterState({ ...filterState, isOpen: false }); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
document.addEventListener('click', closeFilter); | ||
return () => document.removeEventListener('click', closeFilter); | ||
}, [filterState.isOpen]); | ||
return <Wrapper {...filterState} ref={filterRef}></Wrapper>; | ||
} | ||
|
||
export default FilterMenu; | ||
|
||
const Wrapper = styled.div<{ isOpen: boolean }>` | ||
position: fixed; | ||
bottom: 0; | ||
width: 100%; | ||
height: 80vh; | ||
background-color: #fff; | ||
z-index: 500; | ||
transition: 0.5s; | ||
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.15); | ||
border-radius: 16px 16px 0px 0px; | ||
${({ isOpen }) => { | ||
if (isOpen) { | ||
return css` | ||
bottom: 0; | ||
`; | ||
} else { | ||
return css` | ||
bottom: -100%; | ||
`; | ||
} | ||
}} | ||
`; |
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,12 @@ | ||
import { atom } from 'recoil'; | ||
|
||
const filterAtom = atom({ | ||
key: 'filterAtom', | ||
default: { | ||
isOpen: false, | ||
moodTag: null, | ||
drinkTag: null, | ||
}, | ||
}); | ||
|
||
export default filterAtom; |
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 @@ | ||
export { default as filterAtom } from './filterAtom'; |