Skip to content

Commit f0a2aae

Browse files
committed
chore: Add OverflowY component
1 parent cb60409 commit f0a2aae

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { type ReactNode } from "react";
2+
import { type SystemStyleObject } from "@mui/system";
3+
import Box from "@mui/system/Box";
4+
5+
type Props = {
6+
children: ReactNode;
7+
height?: number;
8+
maxHeight?: number;
9+
sx?: SystemStyleObject;
10+
};
11+
12+
export function OverflowY({ children, height, maxHeight, sx }: Props) {
13+
const computedHeight = height === undefined ? "100%" : `${height}px`;
14+
15+
// Doing Math.max check to catch cases where height is accidentally larger
16+
// than maxHeight
17+
const computedMaxHeight =
18+
maxHeight === undefined
19+
? computedHeight
20+
: `${Math.max(height ?? 0, maxHeight)}px`;
21+
22+
return (
23+
<Box
24+
sx={{
25+
width: "100%",
26+
height: computedHeight,
27+
maxHeight: computedMaxHeight,
28+
overflowY: "auto",
29+
...sx,
30+
}}
31+
>
32+
{children}
33+
</Box>
34+
);
35+
}

0 commit comments

Comments
 (0)