Skip to content

Commit 5f0a5a3

Browse files
authored
Merge pull request #322 from boostcampwm-2022/fix/#321-K
Fix/#321-K: λΈ”λŸ­ νƒ€μž… 선택 λͺ¨λ‹¬ λ‹«λŠ” κΈ°λŠ₯에 dimmer ν™œμš©
2 parents ac2cf50 + d70d24e commit 5f0a5a3

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

β€Žclient/src/components/Block/TextBlock.tsxβ€Ž

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ function TextBlock({
3030
registerRef,
3131
}: BlockProps) {
3232
const { momSocket: socket } = useSocketContext();
33-
const [isOpen, setIsOpen] = useState<boolean>(false);
3433

3534
const {
3635
syncCRDT,
@@ -46,6 +45,9 @@ function TextBlock({
4645
const { offsetRef, setOffset, clearOffset, onArrowKeyDown, offsetHandlers } =
4746
useOffset(blockRef);
4847

48+
const [isOpen, setIsOpen] = useState<boolean>(false);
49+
const onClose = () => setIsOpen(false);
50+
4951
// 리λͺ¨νŠΈ μ—°μ‚° μˆ˜ν–‰κ²°κ³Όλ‘œ innerText λ³€κ²½ μ‹œ μ»€μ„œμ˜ μœ„μΉ˜ μ‘°μ •
5052
const updateCaretPosition = (updateOffset = 0) => {
5153
if (!blockRef.current || offsetRef.current === null) return;
@@ -212,18 +214,12 @@ function TextBlock({
212214
onHandleBlock(e);
213215
};
214216

215-
const onBlur = () => {
216-
clearOffset();
217-
setIsOpen(false);
218-
};
219-
220217
const commonHandlers = {
221218
onInput,
222219
onCompositionEnd,
223220
...offsetHandlers,
224221
onKeyDown,
225222
onPaste,
226-
onBlur,
227223
};
228224

229225
const BLOCK_TYPES = Object.values(BlockType)
@@ -249,7 +245,7 @@ function TextBlock({
249245
},
250246
readCRDT(),
251247
)}
252-
{isOpen && <BlockSelector onSelect={onSelect} />}
248+
{isOpen && <BlockSelector onClose={onClose} onSelect={onSelect} />}
253249
</>
254250
);
255251
}

β€Žclient/src/components/BlockSelector/index.tsxβ€Ž

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@ import BlockItem from './BlockItem';
55
import style from './style.module.scss';
66

77
interface BlockSelectorProps {
8+
onClose: () => void;
89
onSelect: (arg: BlockType) => void;
910
}
1011

11-
function BlockSelector({ onSelect }: BlockSelectorProps) {
12+
function BlockSelector({ onClose, onSelect }: BlockSelectorProps) {
1213
return (
13-
<div className={style['block-selector']}>
14-
<div className={style['block-displayed']}>
15-
<strong>블둝</strong>
14+
<>
15+
<div className={style['block-selector']}>
16+
<div className={style['block-displayed']}>
17+
<strong>블둝</strong>
1618

17-
<ul className={style['block-list']}>
18-
{BLOCKS_TYPE.map(({ id, name, desc, thumbnail }) => (
19-
<BlockItem key={id} {...{ id, name, desc, thumbnail, onSelect }} />
20-
))}
21-
</ul>
19+
<ul className={style['block-list']}>
20+
{BLOCKS_TYPE.map(({ id, name, desc, thumbnail }) => (
21+
<BlockItem
22+
key={id}
23+
{...{ id, name, desc, thumbnail, onSelect }}
24+
/>
25+
))}
26+
</ul>
27+
</div>
2228
</div>
23-
</div>
29+
<div className={style['dimmer']} onClick={onClose}></div>
30+
</>
2431
);
2532
}
2633

β€Žclient/src/components/BlockSelector/style.module.scssβ€Ž

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.block-selector {
44
position: absolute;
55
z-index: 99;
6-
height: 100%;
6+
height: 280px;
77
overflow: hidden;
88

99
.block-displayed {
@@ -27,3 +27,11 @@
2727
}
2828
}
2929
}
30+
31+
.dimmer {
32+
position: fixed;
33+
top: 0;
34+
left: 0;
35+
width: 100vw;
36+
height: 100vh;
37+
}

β€Žclient/src/hooks/useOffset.tsxβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export function useOffset(blockRef: React.RefObject<HTMLParagraphElement>) {
5454
};
5555

5656
const offsetHandlers = {
57-
onClick:
58-
setOffset as unknown as React.MouseEventHandler<HTMLParagraphElement>,
57+
onClick: setOffset,
58+
onBlur: clearOffset,
5959
onKeyUp: onArrowKeyup,
6060
};
6161

0 commit comments

Comments
Β (0)