-
Notifications
You must be signed in to change notification settings - Fork 0
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
67 changed files
with
269 additions
and
124 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/components/common/Dropdown/Dropdown.tsx → src/components/Dropdown/Dropdown.tsx
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
2 changes: 1 addition & 1 deletion
2
...nents/common/Dropdown/DropdownContent.tsx → src/components/Dropdown/DropdownContent.tsx
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
2 changes: 1 addition & 1 deletion
2
...onents/common/Dropdown/DropdownToggle.tsx → src/components/Dropdown/DropdownToggle.tsx
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...components/common/HoverCard/HoverCard.tsx → src/components/HoverCard/HoverCard.tsx
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
2 changes: 1 addition & 1 deletion
2
...nts/common/HoverCard/HoverCardContent.tsx → ...components/HoverCard/HoverCardContent.tsx
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ents/common/HoverCard/HoverCardToggle.tsx → src/components/HoverCard/HoverCardToggle.tsx
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...nents/common/HoverCard/useHoverWaiting.ts → src/components/HoverCard/useHoverWaiting.ts
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,79 @@ | ||
import { keyframes } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
import React from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
import { usePortal } from '@/components/Portal/usePortal'; | ||
import useContext from '@/hooks/useContext'; | ||
import { composeRefs } from '@/libs/ref'; | ||
import { PositionType } from '@/types/position'; | ||
|
||
import { PortalContext } from './PortalContext'; | ||
|
||
interface ModalContentProps extends React.ComponentProps<'div'> { | ||
ref: React.ForwardedRef<HTMLDivElement>; | ||
width?: React.CSSProperties['width']; | ||
disabledBG?: boolean; | ||
} | ||
|
||
export const PortalContent = ({ children, ref, width, disabledBG = false, ...props }: ModalContentProps) => { | ||
const { showModal, setShowModal, toggleElement } = useContext(PortalContext)!; | ||
const modalRef = React.useRef<HTMLDivElement>(null); | ||
const { reorgPos } = usePortal({ modalRef }); | ||
|
||
const close = () => { | ||
setShowModal(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
{showModal && | ||
createPortal( | ||
<> | ||
{!disabledBG && <ModalBG onClick={close} id="bmates-portal-bg" className="bmates-portal-bg" />} | ||
<Modal | ||
ref={composeRefs(modalRef, ref)} | ||
width={width || toggleElement?.getBoundingClientRect().width} | ||
position={reorgPos} | ||
{...props} | ||
> | ||
{children} | ||
</Modal> | ||
</>, | ||
document.body, | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const enter = keyframes` | ||
0% { opacity: 0; } | ||
100% { opacity: 1; } | ||
`; | ||
|
||
const ModalBG = styled.div` | ||
position: fixed; | ||
background-color: transparent; | ||
pointer-events: auto; | ||
z-index: 50; | ||
inset: 0; | ||
`; | ||
|
||
const Modal = styled.div<{ width?: React.CSSProperties['width']; position: PositionType }>` | ||
display: grid; | ||
min-width: max-content; | ||
${({ width }) => width && `width: ${typeof width === 'string' ? width : `${width}px`};`} | ||
padding: 0.25rem; | ||
border-radius: 0.25rem; | ||
position: fixed; | ||
top: 0px; | ||
left: 0px; | ||
transform: ${({ position }) => `translate(${position.x}px, ${position.y}px)`}; | ||
background-color: white; | ||
pointer-events: auto; | ||
z-index: 50; | ||
animation-name: ${enter}; | ||
animation-duration: 0.15s; | ||
border: 1px solid ${({ theme }) => theme.colors.gray['300']}; | ||
box-shadow: 0px 2px 2px 0px ${({ theme }) => theme.colors.gray['300']}; | ||
`; |
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,29 @@ | ||
import React from 'react'; | ||
|
||
import { AlignType } from '@/types/align'; | ||
|
||
export interface PortalContextType { | ||
/* | ||
* Modal | ||
*/ | ||
showModal: boolean; | ||
setShowModal: (value: boolean) => void; | ||
|
||
/* | ||
* Toggle Rect | ||
* - to calcurate element size | ||
*/ | ||
toggleElement: HTMLElement | undefined; | ||
setToggleElment: (value: HTMLElement) => void; | ||
|
||
/* | ||
* Align | ||
*/ | ||
align: AlignType; | ||
|
||
/* | ||
* Space Size | ||
*/ | ||
space?: number; | ||
} | ||
export const PortalContext = React.createContext<PortalContextType | null>(null); |
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,30 @@ | ||
import React from 'react'; | ||
|
||
import useModal from '@/hooks/useModal'; | ||
|
||
import { PortalContext } from './PortalContext'; | ||
import { PortalType } from './type'; | ||
|
||
export interface PortalProviderProps extends React.PropsWithChildren, PortalType { | ||
enableScroll?: boolean; | ||
} | ||
|
||
export const PortalProvider = ({ align, space, enableScroll, children }: PortalProviderProps) => { | ||
const [showModal, setShowModal] = useModal(enableScroll); | ||
const [toggleElement, setToggleElment] = React.useState<HTMLElement>(); | ||
|
||
return ( | ||
<PortalContext.Provider | ||
value={{ | ||
showModal, | ||
setShowModal, | ||
toggleElement, | ||
setToggleElment, | ||
align, | ||
space, | ||
}} | ||
> | ||
{children} | ||
</PortalContext.Provider> | ||
); | ||
}; |
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,3 @@ | ||
export * from './PortalContent'; | ||
export * from './PortalProvider'; | ||
export * from './usePortal'; |
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,6 @@ | ||
import { AlignType } from '@/types/align'; | ||
|
||
export interface PortalType { | ||
align: AlignType; | ||
space: number; | ||
} |
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,60 @@ | ||
import React from 'react'; | ||
|
||
import { PortalContext } from '@/components/Portal/PortalContext'; | ||
import { PositionType } from '@/types/position'; | ||
|
||
export const usePortal = ({ modalRef }: { modalRef: React.RefObject<HTMLDivElement> }) => { | ||
const { | ||
showModal, | ||
align, | ||
space = 0, | ||
toggleElement, | ||
setShowModal, | ||
setToggleElment, | ||
} = React.useContext(PortalContext)!; | ||
const [reorgPos, setReorgPos] = React.useState<PositionType>({ x: 0, y: 0 }); | ||
|
||
React.useEffect(() => { | ||
const adjustmentPos = () => { | ||
if (modalRef.current && toggleElement && showModal) { | ||
const rect = modalRef.current; | ||
const toggleRect = toggleElement.getBoundingClientRect(); | ||
|
||
const isOverflowing = rect.offsetHeight + toggleRect.bottom + space >= window.innerHeight; | ||
const reorgPos = { x: 0, y: 0 }; | ||
|
||
switch (align) { | ||
case 'center': | ||
reorgPos.x = toggleRect.x + toggleRect.width / 2 - rect.clientWidth / 2; | ||
break; | ||
case 'start': | ||
reorgPos.x = toggleRect.x; | ||
break; | ||
case 'end': | ||
reorgPos.x = toggleRect.x + toggleRect.width - rect.clientWidth; | ||
break; | ||
} | ||
|
||
if (isOverflowing) { | ||
reorgPos.y = toggleRect.y - rect.offsetHeight - space; | ||
} else { | ||
reorgPos.y = toggleRect.y + toggleRect.height + space; | ||
} | ||
|
||
if (reorgPos.x <= 0) reorgPos.x = space; | ||
else if (reorgPos.x + rect.offsetWidth >= window.innerWidth) | ||
reorgPos.x = window.innerWidth - rect.offsetWidth - space; | ||
|
||
setReorgPos(reorgPos); | ||
} | ||
}; | ||
adjustmentPos(); | ||
|
||
window.addEventListener('resize', adjustmentPos); | ||
return () => { | ||
window.removeEventListener('resize', adjustmentPos); | ||
}; | ||
}, [align, showModal, toggleElement, modalRef, space]); | ||
|
||
return { showModal, align, toggleElement, setShowModal, setToggleElment, reorgPos }; | ||
}; |
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,14 @@ | ||
import GlobalStyle from '@/styles/GlobalStyle.tsx'; | ||
import theme from '@/styles/theme.ts'; | ||
import { ThemeProvider } from '@emotion/react'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
const StyledProvider = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalStyle /> | ||
{children} | ||
</ThemeProvider> | ||
); | ||
}; | ||
export default StyledProvider; |
2 changes: 1 addition & 1 deletion
2
src/components/common/Select/Select.tsx → src/components/Select/Select.tsx
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
2 changes: 1 addition & 1 deletion
2
...omponents/common/Select/SelectContent.tsx → src/components/Select/SelectContent.tsx
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
File renamed without changes.
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
...components/common/Select/SelectToggle.tsx → src/components/Select/SelectToggle.tsx
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.