Skip to content

Commit 27657ac

Browse files
authored
Merge pull request #109 from dev-five-git/fix-overflow
Fix overflow
2 parents c8d5868 + 9d62ac6 commit 27657ac

3 files changed

Lines changed: 42 additions & 49 deletions

File tree

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client'
22

33
import { Box } from '@devup-ui/react'
4-
import { useState } from 'react'
54

65
import Tooltip from './Tooltip'
76

@@ -12,8 +11,6 @@ export default function TestCaseCircle({
1211
children: React.ReactNode
1312
isSuccess: boolean
1413
}) {
15-
const [isHover, setIsHover] = useState(false)
16-
1714
return (
1815
<Box role="group">
1916
<Box
@@ -22,10 +19,8 @@ export default function TestCaseCircle({
2219
borderRadius="100px"
2320
boxSize="16px"
2421
cursor="pointer"
25-
onMouseEnter={() => setIsHover(true)}
26-
onMouseLeave={() => setIsHover(false)}
2722
/>
28-
<Tooltip isOpen={isHover}>{children}</Tooltip>
23+
<Tooltip>{children}</Tooltip>
2924
</Box>
3025
)
3126
}

‎apps/landing/src/components/test-case/Tooltip.tsx‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@ import { VStack } from '@devup-ui/react'
44
import { useRef, useState } from 'react'
55
import { useEffect } from 'react'
66

7-
export default function Tooltip({
8-
children,
9-
isOpen,
10-
}: {
11-
children: React.ReactNode
12-
isOpen: boolean
13-
}) {
7+
export default function Tooltip({ children }: { children: React.ReactNode }) {
148
const [viewportWidth, setViewportWidth] = useState(0)
15-
const [tooltipRect, setTooltipRect] = useState<DOMRect | null>(null)
169
const ref = useRef<HTMLDivElement>(null)
1710
useEffect(() => {
1811
if (typeof window === 'undefined') return
@@ -30,22 +23,36 @@ export default function Tooltip({
3023
}
3124
}, [])
3225

33-
useEffect(() => {
34-
if (ref.current) {
35-
setTooltipRect(ref.current.getBoundingClientRect())
36-
}
37-
}, [isOpen])
38-
3926
return (
4027
<VStack
41-
ref={ref}
28+
ref={(el) => {
29+
if (!el) return
30+
31+
ref.current = el
32+
33+
const mo = new ResizeObserver((entries) => {
34+
entries.forEach((entry) => {
35+
const target = entry.target as HTMLDivElement
36+
const x = target.offsetLeft
37+
const width = target.offsetWidth
38+
if (x + width > viewportWidth) {
39+
target.style.right = '16px'
40+
}
41+
})
42+
})
43+
44+
mo.observe(el)
45+
46+
return () => mo.disconnect()
47+
}}
4248
_groupHover={{
43-
display: isOpen ? 'flex' : 'none',
49+
display: 'flex',
4450
}}
4551
bg="rgba(0, 0, 0, 0.75)"
4652
borderRadius="4px"
4753
display="none"
4854
justifyContent="center"
55+
maxW="calc(100vw - 32px)"
4956
onMouseEnter={(e) => {
5057
e.stopPropagation()
5158
}}
@@ -55,12 +62,6 @@ export default function Tooltip({
5562
pos="absolute"
5663
px="10px"
5764
py="8px"
58-
style={{
59-
right:
60-
tooltipRect && tooltipRect.x + tooltipRect.width > viewportWidth
61-
? '16px'
62-
: 'unset',
63-
}}
6465
transform="translateY(10px)"
6566
transition="all 0.3s ease-in-out"
6667
>

‎apps/landing/src/components/test-case/list/TestCaseList.tsx‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Grid, Text } from '@devup-ui/react'
1+
import { Box, Grid, Text } from '@devup-ui/react'
22
import Latex from 'react-syntax-highlighter/dist/cjs/languages/hljs/latex'
33

44
import { TestStatus } from '@/types'
@@ -19,26 +19,23 @@ export function TestCaseList({ results }: { results: TestStatus[2] }) {
1919
value={Number(!isSuccess)}
2020
>
2121
<TestCaseCircle key={text + idx} isSuccess={isSuccess}>
22-
<Text
23-
color="#FFF"
24-
typography="body"
25-
whiteSpace="nowrap"
26-
wordBreak="keep-all"
27-
>
28-
{textParts.map((part, partIdx) =>
29-
part.type === 'latex' ? (
30-
<Latex key={partIdx}>${part.content}$</Latex>
31-
) : (
32-
<span key={partIdx}>{part.content}</span>
33-
),
34-
)}
35-
<br />
36-
정답 : {expected}
37-
<br />
38-
결과 : {actual}
39-
<br />
40-
{isSuccess ? '✅ 테스트 성공' : '❌ 테스트 실패'}
41-
</Text>
22+
<Box minW="50vw" w="100%" whiteSpace="pre-wrap">
23+
<Text color="#FFF" typography="body">
24+
{textParts.map((part, partIdx) =>
25+
part.type === 'latex' ? (
26+
<Latex key={partIdx}>${part.content}$</Latex>
27+
) : (
28+
<span key={partIdx}>{part.content}</span>
29+
),
30+
)}
31+
<br />
32+
정답 : <Text wordBreak="break-all">{expected}</Text>
33+
<br />
34+
결과 : <Text wordBreak="break-all">{actual}</Text>
35+
<br />
36+
{isSuccess ? '✅ 테스트 성공' : '❌ 테스트 실패'}
37+
</Text>
38+
</Box>
4239
</TestCaseCircle>
4340
</TestCaseDisplayBoundary>
4441
)

0 commit comments

Comments
 (0)