Skip to content

Commit 84cdaa7

Browse files
feat: Add responsive height and overflow scrolling to order modal for smaller screens.
1 parent 311cefb commit 84cdaa7

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/features/OrderButton/ui/MakeOrderModal/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22
import React from 'react';
33
import { ModalComponent } from '@/shared/ui/Modal';
4-
import { useWindowWidth } from '@/shared/hooks';
4+
import { useWindowHeight, useWindowWidth } from '@/shared/hooks';
55

66
type ModalComponentProps = {
77
open: boolean;
@@ -15,13 +15,16 @@ export const MakeOrderModal: React.FC<ModalComponentProps> = ({
1515
children,
1616
}) => {
1717
const windowWidth = useWindowWidth();
18-
const width = windowWidth >= 820 ? 800 : '90%';
18+
const windowHeight = useWindowHeight();
19+
const width = windowWidth >= 820 ? 800 : '85%';
20+
const height = windowHeight >= 700 ? 645 : '90%';
21+
1922
return (
2023
<ModalComponent
2124
open={open}
2225
onClose={onClose}
2326
withControl={false}
24-
style={{ height: 645, width, border: 'none' }}
27+
style={{ height, width, border: 'none' }}
2528
>
2629
{children}
2730
</ModalComponent>

src/shared/hooks/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ export function useWindowWidth() {
1616

1717
return width;
1818
}
19+
20+
export function useWindowHeight() {
21+
const [height, setHeight] = useState(
22+
typeof window !== 'undefined' ? window.innerHeight : 0,
23+
);
24+
25+
useEffect(() => {
26+
const onResize = () => setHeight(window.innerHeight);
27+
window.addEventListener('resize', onResize);
28+
29+
return () => {
30+
window.removeEventListener('resize', onResize);
31+
};
32+
}, []);
33+
34+
return height;
35+
}

src/shared/ui/OrderForm/style.module.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ $WIDTH: 800px;
4242
position: relative;
4343
background-color: #0a0a0a;
4444

45+
@media (max-width: 820px) and (max-height: 900px) {
46+
overflow-y: scroll;
47+
max-height: 100%;
48+
}
4549
@media (max-width: 820px) {
4650
width: 100%;
4751
padding: 20px;
@@ -59,7 +63,11 @@ $WIDTH: 800px;
5963
justify-content: center;
6064
align-items: center;
6165
@media (max-width: 820px) {
62-
width: 90%;
66+
width: 100%;
67+
}
68+
69+
@media (max-width: 820px) and (max-height: 900px) {
70+
max-height: 100%;
6371
}
6472
}
6573
&HeaderLabel {

0 commit comments

Comments
 (0)