fix(striker-ui): add simple colour control to proceed button in ConfirmDialog

main
Tsu-ba-me 2 years ago
parent f4c4e30610
commit 21329e7c47
  1. 19
      striker-ui/components/ConfirmDialog.tsx
  2. 3
      striker-ui/types/ConfirmDialog.d.ts

@ -1,12 +1,20 @@
import { Box, Dialog } from '@mui/material'; import { Box, Dialog } from '@mui/material';
import { forwardRef, useImperativeHandle, useMemo, useState } from 'react'; import { forwardRef, useImperativeHandle, useMemo, useState } from 'react';
import { BLUE, TEXT } from '../lib/consts/DEFAULT_THEME'; import { BLUE, RED, TEXT } from '../lib/consts/DEFAULT_THEME';
import ContainedButton from './ContainedButton'; import ContainedButton from './ContainedButton';
import { Panel, PanelHeader } from './Panels'; import { Panel, PanelHeader } from './Panels';
import { BodyText, HeaderText } from './Text'; import { BodyText, HeaderText } from './Text';
const MAP_TO_COLOUR: Record<
Exclude<ConfirmDialogProps['proceedColour'], undefined>,
string
> = {
blue: BLUE,
red: RED,
};
const ConfirmDialog = forwardRef< const ConfirmDialog = forwardRef<
ConfirmDialogForwardedRefContent, ConfirmDialogForwardedRefContent,
ConfirmDialogProps ConfirmDialogProps
@ -21,6 +29,7 @@ const ConfirmDialog = forwardRef<
onProceedAppend, onProceedAppend,
openInitially = false, openInitially = false,
proceedButtonProps = {}, proceedButtonProps = {},
proceedColour: proceedColourKey = 'blue',
titleText, titleText,
}, },
ref, ref,
@ -35,6 +44,10 @@ const ConfirmDialog = forwardRef<
() => (ref ? isOpen : baseOpen), () => (ref ? isOpen : baseOpen),
[baseOpen, isOpen, ref], [baseOpen, isOpen, ref],
); );
const proceedColour = useMemo(
() => MAP_TO_COLOUR[proceedColourKey],
[proceedColourKey],
);
useImperativeHandle( useImperativeHandle(
ref, ref,
@ -80,10 +93,10 @@ const ConfirmDialog = forwardRef<
</ContainedButton> </ContainedButton>
<ContainedButton <ContainedButton
sx={{ sx={{
backgroundColor: BLUE, backgroundColor: proceedColour,
color: TEXT, color: TEXT,
'&:hover': { backgroundColor: `${BLUE}F0` }, '&:hover': { backgroundColor: `${proceedColour}F0` },
...proceedButtonSx, ...proceedButtonSx,
}} }}

@ -1,15 +1,16 @@
type ConfirmDialogOptionalProps = { type ConfirmDialogOptionalProps = {
actionCancelText?: string; actionCancelText?: string;
dialogProps?: import('@mui/material').DialogProps; dialogProps?: import('@mui/material').DialogProps;
onProceedAppend?: ContainedButtonProps['onClick'];
onCancelAppend?: ContainedButtonProps['onClick']; onCancelAppend?: ContainedButtonProps['onClick'];
openInitially?: boolean; openInitially?: boolean;
proceedButtonProps?: ContainedButtonProps; proceedButtonProps?: ContainedButtonProps;
proceedColour?: 'blue' | 'red';
}; };
type ConfirmDialogProps = ConfirmDialogOptionalProps & { type ConfirmDialogProps = ConfirmDialogOptionalProps & {
actionProceedText: string; actionProceedText: string;
content: import('@mui/material').ReactNode; content: import('@mui/material').ReactNode;
onProceedAppend: Exclude<ContainedButtonProps['onClick'], undefined>;
titleText: string; titleText: string;
}; };

Loading…
Cancel
Save