-
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
1 parent
ef57bfd
commit b063d9f
Showing
28 changed files
with
235 additions
and
200 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
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
import { modalStore } from "./store.js"; | ||
|
||
export default function openModal(component, layer = "alert") { | ||
modalStore.changeModal(component, layer); | ||
return new Promise( (resolve)=>{ | ||
function observe() | ||
{ | ||
if(modalStore.getSnapshot(layer) !== component) { | ||
modalStore.changeModal(component, layer); | ||
return new Promise((resolve) => { | ||
function observe() { | ||
if (modalStore.getSnapshot(layer) !== component) { | ||
resolve(); | ||
clear(); | ||
} | ||
} | ||
const clear = modalStore.subscribe( observe ); | ||
} ); | ||
const clear = modalStore.subscribe(observe); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,67 +1,64 @@ | ||
import { useEffect, useRef } from "react"; | ||
|
||
function getEndPointChild(element) | ||
{ | ||
const focusableElements = [...element.querySelectorAll( | ||
"a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]" | ||
)].filter( elem=>elem.tabIndex >= 0 ); | ||
if(focusableElements.length === 0) return [null, null]; | ||
return [focusableElements[0], focusableElements[focusableElements.length - 1]]; | ||
function getEndPointChild(element) { | ||
const focusableElements = [ | ||
...element.querySelectorAll( | ||
"a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]", | ||
), | ||
].filter((elem) => elem.tabIndex >= 0); | ||
if (focusableElements.length === 0) return [null, null]; | ||
return [focusableElements[0], focusableElements[focusableElements.length - 1]]; | ||
} | ||
|
||
function useFocusTrap(active) | ||
{ | ||
const prevRef = useRef(null); | ||
const ref = useRef(null); | ||
const endPointChild = useRef([null, null]); | ||
useEffect( ()=>{ | ||
if(!active || ref.current === null) return; | ||
function useFocusTrap(active) { | ||
const prevRef = useRef(null); | ||
const ref = useRef(null); | ||
const endPointChild = useRef([null, null]); | ||
useEffect(() => { | ||
if (!active || ref.current === null) return; | ||
|
||
function renewEndPointChild() | ||
{ | ||
if(ref.current === null) return; | ||
endPointChild.current = getEndPointChild(ref.current); | ||
} | ||
function renewEndPointChild() { | ||
if (ref.current === null) return; | ||
endPointChild.current = getEndPointChild(ref.current); | ||
} | ||
|
||
function handleTabKey(e) { | ||
if(e.key !== "Tab") return; | ||
function handleTabKey(e) { | ||
if (e.key !== "Tab") return; | ||
|
||
const [first, last] = endPointChild.current; | ||
const [first, last] = endPointChild.current; | ||
|
||
if(document.activeElement === prevRef.current) { | ||
if(e.shiftKey) last?.focus(); | ||
else first?.focus(); | ||
e.preventDefault(); | ||
return; | ||
} | ||
if (document.activeElement === prevRef.current) { | ||
if (e.shiftKey) last?.focus(); | ||
else first?.focus(); | ||
e.preventDefault(); | ||
return; | ||
} | ||
|
||
if(first === null || last === null) return; | ||
if(document.activeElement === last && !e.shiftKey) { | ||
first.focus(); | ||
e.preventDefault(); | ||
} | ||
else if(document.activeElement === first && e.shiftKey) { | ||
last.focus(); | ||
e.preventDefault(); | ||
} | ||
} | ||
if (first === null || last === null) return; | ||
if (document.activeElement === last && !e.shiftKey) { | ||
first.focus(); | ||
e.preventDefault(); | ||
} else if (document.activeElement === first && e.shiftKey) { | ||
last.focus(); | ||
e.preventDefault(); | ||
} | ||
} | ||
|
||
renewEndPointChild(); | ||
prevRef.current = document.activeElement; | ||
document.addEventListener("keydown", handleTabKey); | ||
const config = { subtree: true, childList: true, attributeFilter: ["disabled", "tabindex"] }; | ||
const observer = new MutationObserver( renewEndPointChild ); | ||
observer.observe(ref.current, config); | ||
renewEndPointChild(); | ||
prevRef.current = document.activeElement; | ||
document.addEventListener("keydown", handleTabKey); | ||
const config = { subtree: true, childList: true, attributeFilter: ["disabled", "tabindex"] }; | ||
const observer = new MutationObserver(renewEndPointChild); | ||
observer.observe(ref.current, config); | ||
|
||
return ()=>{ | ||
document.removeEventListener("keydown", handleTabKey); | ||
observer.disconnect(); | ||
prevRef.current.focus(); | ||
} | ||
return () => { | ||
document.removeEventListener("keydown", handleTabKey); | ||
observer.disconnect(); | ||
prevRef.current.focus(); | ||
}; | ||
}, [active]); | ||
|
||
}, [active] ); | ||
|
||
return ref; | ||
return ref; | ||
} | ||
|
||
export default useFocusTrap; | ||
export default useFocusTrap; |
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
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 |
---|---|---|
|
@@ -17,13 +17,15 @@ function CommentNoUserModal() { | |
<AlertModalContainer | ||
title="아직 기대평을 작성할 수 없습니다." | ||
description="오늘의 추첨 이벤트에 참여하고 기대평을 작성하세요" | ||
image={<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="추첨 이벤트 참여 바랍니다" | ||
width="208" | ||
height="40" | ||
/>} | ||
image={ | ||
<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="추첨 이벤트 참여 바랍니다" | ||
width="208" | ||
height="40" | ||
/> | ||
} | ||
> | ||
<div className="w-full flex flex-wrap justify-center gap-5"> | ||
<Button styleType="filled" onClick={toMoveInteraction}> | ||
|
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 |
---|---|---|
|
@@ -9,13 +9,15 @@ function CommentSuccessModal() { | |
return ( | ||
<AlertModalContainer | ||
title="기대평이 등록되었습니다!" | ||
image={<img | ||
image={ | ||
<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="기대평 등록 완료" | ||
width="173" | ||
height="182" | ||
/>} | ||
/> | ||
} | ||
> | ||
<Button styleType="ghost" onClick={close}> | ||
확인 | ||
|
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
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 |
---|---|---|
|
@@ -19,13 +19,15 @@ function FcfsLoseModal() { | |
<AlertModalContainer | ||
title="이번 이벤트에 당첨되지 않았어요!" | ||
description=" 다음 이벤트 일정을 확인하세요!" | ||
image={<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="선착순 이벤트 당첨 실패" | ||
width="144" | ||
height="146" | ||
/>} | ||
image={ | ||
<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="선착순 이벤트 당첨 실패" | ||
width="144" | ||
height="146" | ||
/> | ||
} | ||
> | ||
<div className="w-full flex flex-wrap justify-center gap-5"> | ||
<Button styleType="filled" hidden={!shouldInteraction} onClick={toMoveInteraction}> | ||
|
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 |
---|---|---|
|
@@ -10,13 +10,15 @@ function FcfsWinModal() { | |
<AlertModalContainer | ||
title="선착순 이벤트에 당첨되었어요!" | ||
description="경품 수령은 입력하신 연락처로 개별 안내됩니다" | ||
image={<img | ||
image={ | ||
<img | ||
src="/icons/[email protected]" | ||
srcSet="/icons/[email protected] 1x, /icons/[email protected] 2x" | ||
alt="선착순 이벤트 당첨" | ||
width="320" | ||
height="320" | ||
/>} | ||
/> | ||
} | ||
> | ||
<Button styleType="filled" onClick={close}> | ||
확인 | ||
|
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.