Files
rowy/src/components/Modal/ScrollableDialogContent.tsx

61 lines
1.6 KiB
TypeScript
Raw Permalink Normal View History

import { memo } from "react";
import useScrollInfo from "react-element-scroll-hook";
import {
Divider,
DividerProps,
DialogContent,
DialogContentProps,
} from "@mui/material";
2022-06-07 12:00:58 +10:00
import { spreadSx } from "@src/utils/ui";
2021-09-13 21:58:03 +10:00
const MemoizedDialogContent = memo(function MemoizedDialogContent_({
setRef,
...props
}: DialogContentProps & { setRef: any }) {
return <DialogContent {...props} ref={setRef} />;
});
export interface IScrollableDialogContentProps extends DialogContentProps {
disableTopDivider?: boolean;
disableBottomDivider?: boolean;
dividerSx?: DividerProps["sx"];
topDividerSx?: DividerProps["sx"];
bottomDividerSx?: DividerProps["sx"];
}
export default function ScrollableDialogContent({
disableTopDivider = false,
disableBottomDivider = false,
2021-11-30 12:27:28 +11:00
dividerSx = [],
topDividerSx = [],
bottomDividerSx = [],
...props
}: IScrollableDialogContentProps) {
const [scrollInfo, setRef] = useScrollInfo();
return (
<>
2021-09-15 18:57:08 +10:00
{!disableTopDivider && scrollInfo.y.percentage !== null && (
<Divider
style={{
visibility: scrollInfo.y.percentage > 0 ? "visible" : "hidden",
}}
2022-06-07 12:00:58 +10:00
sx={[...spreadSx(dividerSx), ...spreadSx(topDividerSx)]}
2021-09-15 18:57:08 +10:00
/>
)}
<MemoizedDialogContent {...props} setRef={setRef} />
2021-09-15 18:57:08 +10:00
{!disableBottomDivider && scrollInfo.y.percentage !== null && (
<Divider
style={{
visibility: scrollInfo.y.percentage < 1 ? "visible" : "hidden",
}}
2022-06-07 12:00:58 +10:00
sx={[...spreadSx(dividerSx), ...spreadSx(bottomDividerSx)]}
2021-09-15 18:57:08 +10:00
/>
)}
</>
);
}