Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 99d9f55

Browse files
feat: added event listener for window resize for dynamic bar heights
1 parent 474504c commit 99d9f55

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

‎src/components/Home/Bar.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { BarStatus } from '@/utils'
55
interface IProps {
66
value: number
77
status: BarStatus
8+
isMobileScreen: boolean
89
}
910

10-
const Bar: FC<IProps> = ({ value, status }: IProps) => {
11+
const Bar: FC<IProps> = ({ value, status, isMobileScreen }: IProps) => {
1112
const barStyle = {
12-
height: value * 2,
13+
height: value * (isMobileScreen ? 1.5 : 2),
1314
backgroundColor: `var(--${status})`
1415
}
1516
return <div className='bar' style={barStyle} />

‎src/components/Home/BarContainer.tsx‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react'
1+
import { FC,useEffect,useState } from 'react'
22

33
import { Bar } from '@/utils'
44

@@ -8,10 +8,30 @@ interface IProps {
88
}
99

1010
const BarContainer: FC<IProps> = ({ step }: IProps) => {
11+
const [isMobileScreen, setIsMobileScreen] = useState<boolean>(true)
12+
13+
useEffect(() => {
14+
const resizeCallback = () => {
15+
const isMobile = window.innerWidth < 768
16+
setIsMobileScreen(isMobile)
17+
}
18+
19+
resizeCallback()
20+
window.addEventListener('resize', resizeCallback)
21+
return () => {
22+
window.removeEventListener('resize', resizeCallback)
23+
}
24+
}, [])
25+
1126
return (
1227
<div className='barContainer'>
1328
{step.map(a => (
14-
<BarComponent key={a.value} value={a.value} status={a.status} />
29+
<BarComponent
30+
key={a.value}
31+
value={a.value}
32+
status={a.status}
33+
isMobileScreen={isMobileScreen}
34+
/>
1535
))}
1636
</div>
1737
)

‎src/hooks/useSort.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux'
33

44
import { Bar } from '@/utils/Bar'
55
import { RootState } from '@/store'
6-
import sorting,{
6+
import {
77
goToNextStep,
88
goToPreviousStep,
99
resetSorting,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /