-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from softeerbootcamp4th/CC-85
[Feat] 공통 컴포넌트인 Overlay구현
- Loading branch information
Showing
11 changed files
with
208 additions
and
53 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
Empty file.
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,54 @@ | ||
import { createState } from "../../Shared/Hyundux/State"; | ||
import { makePayLoad } from "../../Shared/Hyundux/Util/StoreUtil"; | ||
import Reducer from "../../Shared/Hyundux/Reducer"; | ||
import Action from "../../Shared/Hyundux/Actions"; | ||
|
||
const WORK_NAME = "Overlay"; | ||
|
||
// state type | ||
interface OverlayPayLoad { | ||
isShowing: boolean; | ||
index: number; | ||
isOnButton: boolean; | ||
} | ||
|
||
const initOverlayState = createState<OverlayPayLoad>(WORK_NAME, { | ||
isShowing: false, | ||
index: 0, | ||
isOnButton: false, | ||
}); | ||
|
||
// define reducer | ||
const overlayReducer: Reducer<OverlayPayLoad> = { | ||
type: WORK_NAME, | ||
reducer: async function reducer(state, action) { | ||
const payLoad = state.payload; | ||
switch (action.actionName) { | ||
case "toggleOverlay": { | ||
return makePayLoad(state, { isShowing: !payLoad.isShowing }); | ||
} | ||
case "nextPage": { | ||
return makePayLoad(state, { index: payLoad.index + 1 }); | ||
} | ||
default: | ||
return state; | ||
} | ||
}, | ||
}; | ||
// actions | ||
const action = { | ||
toggleOverlay: (): Action => { | ||
return { | ||
type: WORK_NAME, | ||
actionName: "toggleOverlay", | ||
}; | ||
}, | ||
nextPage: (): Action => { | ||
return { | ||
type: WORK_NAME, | ||
actionName: "nextPage", | ||
}; | ||
}, | ||
}; | ||
|
||
export { action, initOverlayState, overlayReducer }; |
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 was deleted.
Oops, something went wrong.
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,18 @@ | ||
import { useState } from "react"; | ||
import HState from "../State"; | ||
import store from "../Store"; | ||
import Reducer from "../Reducer"; | ||
|
||
function useWork<PayLoad>( | ||
initialState: HState<PayLoad>, | ||
reducer: Reducer<PayLoad> | ||
): PayLoad { | ||
const [state, setState] = useState<HState<PayLoad>>(initialState); | ||
store.subscribe(state, reducer, (newState) => { | ||
setState(newState); | ||
}); | ||
|
||
return state.payload; | ||
} | ||
|
||
export default useWork; |
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,22 @@ | ||
import React, { isValidElement, ReactElement, ReactNode } from "react"; | ||
|
||
const findChildrenElement = ( | ||
elements: ReactNode, | ||
checkFn: (element: ReactElement) => boolean | ||
): ReactElement | null => { | ||
let returnElement: ReactElement | null = null; | ||
React.Children.forEach(elements, (element) => { | ||
if (!isValidElement(element)) { | ||
return; | ||
} | ||
if (element.type === React.Fragment) { | ||
return; | ||
} | ||
if (checkFn(element)) { | ||
returnElement = element.props.element; | ||
} | ||
}); | ||
return returnElement; | ||
}; | ||
|
||
export default findChildrenElement; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,46 @@ | ||
import React, { ReactNode } from "react"; | ||
import useWork from "../../../Shared/Hyundux/Hooks/useWork"; | ||
import { | ||
initOverlayState, | ||
overlayReducer, | ||
action, | ||
} from "../../../Job/Overlay/OverlayWork"; | ||
import store from "../../../Shared/Hyundux/Store"; | ||
import findChildrenElement from "../../../Shared/Util/FindChildrenElement"; | ||
|
||
interface OverLayProps { | ||
children: ReactNode; | ||
} | ||
|
||
const OverLay: React.FC<OverLayProps> = ({ children }) => { | ||
const state = useWork(initOverlayState, overlayReducer); | ||
const content = findChildrenElement( | ||
children, | ||
(element) => | ||
element.props.index !== undefined && element.props.index == state.index | ||
); | ||
|
||
if (state.isShowing) { | ||
return ( | ||
<div className="absolute inset-0 bg-black opacity-50 flex flex-col items-center justify-center"> | ||
<div | ||
className="relative bg-white shadow-lg z-10" | ||
style={{ width: "62%", height: "71%" }} | ||
> | ||
<img | ||
src="/src/Shared/assets/xButton.svg" | ||
className="absolute right-10 top-10" | ||
onClick={() => { | ||
store.dispatch(action.toggleOverlay()); | ||
}} | ||
/> | ||
{content} | ||
</div> | ||
</div> | ||
); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
export default OverLay; |
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 React, { ReactElement } from "react"; | ||
|
||
interface OverLayContentProps { | ||
index: number; | ||
element: ReactElement; | ||
} | ||
|
||
const OverLayContent: React.FC<OverLayContentProps> = () => { | ||
return null; | ||
}; | ||
|
||
export default OverLayContent; |