fix(striker-ui): add colour presets in ContainedButton

main
Tsu-ba-me 1 year ago
parent f064623dd3
commit e2c264a40f
  1. 27
      striker-ui/components/ConfirmDialog.tsx
  2. 74
      striker-ui/components/ContainedButton.tsx
  3. 9
      striker-ui/types/ContainedButton.d.ts

@ -10,22 +10,12 @@ import {
useState, useState,
} from 'react'; } from 'react';
import { BLUE, RED, TEXT } from '../lib/consts/DEFAULT_THEME';
import ContainedButton from './ContainedButton'; import ContainedButton from './ContainedButton';
import FlexBox from './FlexBox'; import FlexBox from './FlexBox';
import { Panel, PanelHeader } from './Panels'; import { Panel, PanelHeader } from './Panels';
import Spinner from './Spinner'; import Spinner from './Spinner';
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
@ -53,7 +43,7 @@ const ConfirmDialog = forwardRef<
openInitially = false, openInitially = false,
preActionArea, preActionArea,
proceedButtonProps = {}, proceedButtonProps = {},
proceedColour: proceedColourKey = 'blue', proceedColour = 'blue',
scrollContent: isScrollContent = false, scrollContent: isScrollContent = false,
scrollBoxProps: { sx: scrollBoxSx, ...restScrollBoxProps } = {}, scrollBoxProps: { sx: scrollBoxSx, ...restScrollBoxProps } = {},
titleText, titleText,
@ -63,7 +53,6 @@ const ConfirmDialog = forwardRef<
const { sx: paperSx, ...restPaperProps } = paperProps; const { sx: paperSx, ...restPaperProps } = paperProps;
const { const {
disabled: proceedButtonDisabled = isDisableProceed, disabled: proceedButtonDisabled = isDisableProceed,
sx: proceedButtonSx,
...restProceedButtonProps ...restProceedButtonProps
} = proceedButtonProps; } = proceedButtonProps;
@ -75,10 +64,6 @@ const ConfirmDialog = forwardRef<
() => (ref ? isOpen : baseOpen), () => (ref ? isOpen : baseOpen),
[baseOpen, isOpen, ref], [baseOpen, isOpen, ref],
); );
const proceedColour = useMemo(
() => MAP_TO_COLOUR[proceedColourKey],
[proceedColourKey],
);
const { const {
contentContainerComponent, contentContainerComponent,
contentContainerSubmitEventHandler, contentContainerSubmitEventHandler,
@ -146,18 +131,11 @@ const ConfirmDialog = forwardRef<
const proceedButtonElement = useMemo( const proceedButtonElement = useMemo(
() => ( () => (
<ContainedButton <ContainedButton
background={proceedColour}
disabled={proceedButtonDisabled} disabled={proceedButtonDisabled}
onClick={proceedButtonClickEventHandler} onClick={proceedButtonClickEventHandler}
type={proceedButtonType} type={proceedButtonType}
{...restProceedButtonProps} {...restProceedButtonProps}
sx={{
backgroundColor: proceedColour,
color: TEXT,
'&:hover': { backgroundColor: `${proceedColour}F0` },
...proceedButtonSx,
}}
> >
{actionProceedText} {actionProceedText}
</ContainedButton> </ContainedButton>
@ -166,7 +144,6 @@ const ConfirmDialog = forwardRef<
actionProceedText, actionProceedText,
proceedButtonClickEventHandler, proceedButtonClickEventHandler,
proceedButtonDisabled, proceedButtonDisabled,
proceedButtonSx,
proceedButtonType, proceedButtonType,
proceedColour, proceedColour,
restProceedButtonProps, restProceedButtonProps,

@ -1,34 +1,62 @@
import { import {
Button as MUIButton, Button as MuiButton,
buttonClasses as muiButtonClasses, buttonClasses as muiButtonClasses,
SxProps, styled,
Theme,
} from '@mui/material'; } from '@mui/material';
import { FC, useMemo } from 'react'; import { FC } from 'react';
import { BLACK, DISABLED, GREY } from '../lib/consts/DEFAULT_THEME'; import {
BLACK,
BLUE,
DISABLED,
GREY,
RED,
TEXT,
} from '../lib/consts/DEFAULT_THEME';
const MAP_TO_COLOUR: Record<ContainedButtonBackground, string> = {
blue: BLUE,
normal: GREY,
red: RED,
};
const ContainedButton: FC<ContainedButtonProps> = ({ sx, ...restProps }) => { const BaseStyle = styled(MuiButton)({
const combinedSx = useMemo<SxProps<Theme>>( backgroundColor: GREY,
() => ({ color: BLACK,
backgroundColor: GREY, textTransform: 'none',
color: BLACK,
textTransform: 'none',
'&:hover': { '&:hover': {
backgroundColor: `${GREY}F0`, backgroundColor: `${GREY}F0`,
}, },
[`&.${muiButtonClasses.disabled}`]: { [`&.${muiButtonClasses.disabled}`]: {
backgroundColor: DISABLED, backgroundColor: DISABLED,
}, },
});
...sx, const Base: FC<ContainedButtonProps> = (props) => (
}), <BaseStyle variant="contained" {...props} />
[sx], );
);
return <MUIButton variant="contained" {...restProps} sx={combinedSx} />; const ContainedButton = styled(Base)((props) => {
}; const { background = 'normal' } = props;
let bg: string | undefined;
let color: string | undefined;
if (background !== 'normal') {
bg = MAP_TO_COLOUR[background];
color = TEXT;
}
return {
backgroundColor: bg,
color,
'&:hover': {
backgroundColor: `${bg}F0`,
},
};
});
export default ContainedButton; export default ContainedButton;

@ -1 +1,8 @@
type ContainedButtonProps = import('@mui/material').ButtonProps; type ContainedButtonBackground = 'blue' | 'normal' | 'red';
type ContainedButtonOptionalProps = {
background?: ContainedButtonBackground;
};
type ContainedButtonProps = import('@mui/material').ButtonProps &
ContainedButtonOptionalProps;

Loading…
Cancel
Save