fix(striker-ui): add scroll box in ConfirmDialog

main
Tsu-ba-me 2 years ago committed by digimer
parent c7203b8e0a
commit 1a3a0f549b
  1. 20
      striker-ui/components/ConfirmDialog.tsx
  2. 2
      striker-ui/types/ConfirmDialog.d.ts

@ -1,4 +1,4 @@
import { Dialog as MUIDialog } from '@mui/material'; import { Box, Dialog as MUIDialog, SxProps, Theme } from '@mui/material';
import { import {
ButtonHTMLAttributes, ButtonHTMLAttributes,
ElementType, ElementType,
@ -51,6 +51,8 @@ const ConfirmDialog = forwardRef<
openInitially = false, openInitially = false,
proceedButtonProps = {}, proceedButtonProps = {},
proceedColour: proceedColourKey = 'blue', proceedColour: proceedColourKey = 'blue',
scrollContent: isScrollContent = false,
scrollBoxProps: { sx: scrollBoxSx, ...restScrollBoxProps } = {},
titleText, titleText,
}, },
ref, ref,
@ -183,6 +185,18 @@ const ConfirmDialog = forwardRef<
typeof content === 'string' ? <BodyText text={content} /> : content, typeof content === 'string' ? <BodyText text={content} /> : content,
[content], [content],
); );
const combinedScrollBoxSx = useMemo<SxProps<Theme> | undefined>(
() =>
isScrollContent
? {
maxHeight: '60vh',
overflowY: 'scroll',
padding: '.2em .4em',
...scrollBoxSx,
}
: undefined,
[isScrollContent, scrollBoxSx],
);
useImperativeHandle( useImperativeHandle(
ref, ref,
@ -210,7 +224,9 @@ const ConfirmDialog = forwardRef<
onSubmit={contentContainerSubmitEventHandler} onSubmit={contentContainerSubmitEventHandler}
{...contentContainerProps} {...contentContainerProps}
> >
{contentElement} <Box {...restScrollBoxProps} sx={combinedScrollBoxSx}>
{contentElement}
</Box>
{actionAreaElement} {actionAreaElement}
</FlexBox> </FlexBox>
</MUIDialog> </MUIDialog>

@ -12,6 +12,8 @@ type ConfirmDialogOptionalProps = {
openInitially?: boolean; openInitially?: boolean;
proceedButtonProps?: ContainedButtonProps; proceedButtonProps?: ContainedButtonProps;
proceedColour?: 'blue' | 'red'; proceedColour?: 'blue' | 'red';
scrollContent?: boolean;
scrollBoxProps?: import('@mui/material').BoxProps;
}; };
type ConfirmDialogProps = ConfirmDialogOptionalProps & { type ConfirmDialogProps = ConfirmDialogOptionalProps & {

Loading…
Cancel
Save