fix(striker-ui): add optional close button to form dialog

main
Tsu-ba-me 1 year ago
parent ade881f0d3
commit 382640bad0
  1. 44
      striker-ui/components/FormDialog.tsx
  2. 1
      striker-ui/components/ManageFence/ManageFencePanel.tsx
  3. 3
      striker-ui/components/ManageManifest/ManageManifestPanel.tsx
  4. 1
      striker-ui/components/ManageUps/ManageUpsPanel.tsx

@ -1,18 +1,46 @@
import { forwardRef, useMemo } from 'react'; import { forwardRef, useMemo } from 'react';
import ConfirmDialog from './ConfirmDialog'; import ConfirmDialog from './ConfirmDialog';
import IconButton from './IconButton';
import { HeaderText } from './Text';
const FormDialog = forwardRef< const FormDialog = forwardRef<
ConfirmDialogForwardedRefContent, ConfirmDialogForwardedRefContent,
ConfirmDialogProps ConfirmDialogProps & { showClose?: boolean }
>((props, ref) => { >((props, ref) => {
const { scrollContent: isScrollContent } = props; const { scrollContent, showClose, titleText, ...restProps } = props;
const scrollBoxPaddingRight = useMemo( const scrollBoxPaddingRight = useMemo(
() => (isScrollContent ? '.5em' : undefined), () => (scrollContent ? '.5em' : undefined),
[isScrollContent], [scrollContent],
); );
const titleElement = useMemo(() => {
const title =
typeof titleText === 'string' ? (
<HeaderText>{titleText}</HeaderText>
) : (
titleText
);
return showClose ? (
<>
{title}
<IconButton
mapPreset="close"
onClick={() => {
if (ref && 'current' in ref) {
ref.current?.setOpen?.call(null, false);
}
}}
variant="redcontained"
/>
</>
) : (
title
);
}, [ref, showClose, titleText]);
return ( return (
<ConfirmDialog <ConfirmDialog
dialogProps={{ dialogProps={{
@ -23,12 +51,18 @@ const FormDialog = forwardRef<
paddingRight: scrollBoxPaddingRight, paddingRight: scrollBoxPaddingRight,
paddingTop: '.3em', paddingTop: '.3em',
}} }}
{...props} scrollContent={scrollContent}
titleText={titleElement}
{...restProps}
ref={ref} ref={ref}
/> />
); );
}); });
FormDialog.defaultProps = {
showClose: false,
};
FormDialog.displayName = 'FormDialog'; FormDialog.displayName = 'FormDialog';
export default FormDialog; export default FormDialog;

@ -421,6 +421,7 @@ const ManageFencePanel: FC = () => {
preActionArea={messageArea} preActionArea={messageArea}
ref={formDialogRef} ref={formDialogRef}
scrollContent scrollContent
showClose
/> />
<ConfirmDialog <ConfirmDialog
closeOnProceed closeOnProceed

@ -590,6 +590,7 @@ const ManageManifestPanel: FC = () => {
preActionArea={messageArea} preActionArea={messageArea}
ref={addManifestFormDialogRef} ref={addManifestFormDialogRef}
scrollContent scrollContent
showClose
/> />
<FormDialog <FormDialog
{...editManifestFormDialogProps} {...editManifestFormDialogProps}
@ -598,6 +599,7 @@ const ManageManifestPanel: FC = () => {
preActionArea={messageArea} preActionArea={messageArea}
ref={editManifestFormDialogRef} ref={editManifestFormDialogRef}
scrollContent scrollContent
showClose
/> />
<FormDialog <FormDialog
{...runManifestFormDialogProps} {...runManifestFormDialogProps}
@ -606,6 +608,7 @@ const ManageManifestPanel: FC = () => {
preActionArea={messageArea} preActionArea={messageArea}
ref={runManifestFormDialogRef} ref={runManifestFormDialogRef}
scrollContent scrollContent
showClose
/> />
<ConfirmDialog <ConfirmDialog
closeOnProceed closeOnProceed

@ -365,6 +365,7 @@ const ManageUpsPanel: FC = () => {
loadingAction={isFormSubmitting} loadingAction={isFormSubmitting}
preActionArea={messageArea} preActionArea={messageArea}
ref={formDialogRef} ref={formDialogRef}
showClose
/> />
<ConfirmDialog <ConfirmDialog
closeOnProceed closeOnProceed

Loading…
Cancel
Save