Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: [M3-6321] – MUI v5 Migration - Components > DismissibleBanner #8998

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import Close from '@mui/icons-material/Close';
import * as React from 'react';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
import { styled } from '@mui/material/styles';
import Grid from '@mui/material/Unstable_Grid2';
import Notice, { NoticeProps } from 'src/components/Notice';
import { SxProps } from '@mui/system';
import * as React from 'react';
import Notice, { NoticeProps } from 'src/components/Notice';
import useDismissibleNotifications, {
DismissibleNotificationOptions,
} from 'src/hooks/useDismissibleNotifications';

const useStyles = makeStyles()((theme: Theme) => ({
root: {
display: 'flex',
alignItems: 'center',
flexFlow: 'row nowrap',
justifyContent: 'space-between',
borderRadius: 1,
marginBottom: theme.spacing(),
padding: theme.spacing(2),
background: theme.bg.bgPaper,
},
closeIcon: {
...theme.applyLinkStyles,
display: 'flex',
color: theme.textColors.tableStatic,
marginLeft: 20,
},
}));

interface Props {
preferenceKey: string;
children: JSX.Element;
Expand All @@ -40,7 +20,6 @@ type CombinedProps = Props & Partial<NoticeProps>;

export const DismissibleBanner = (props: CombinedProps) => {
const { className, preferenceKey, options, children, ...rest } = props;
const { classes, cx } = useStyles();

const { hasDismissedBanner, handleDismiss } = useDismissibleBanner(
preferenceKey,
Expand All @@ -53,25 +32,24 @@ export const DismissibleBanner = (props: CombinedProps) => {

const dismissibleButton = (
<Grid>
<button
className={classes.closeIcon}
<StyledButton
aria-label={`Dismiss ${preferenceKey} banner`}
onClick={handleDismiss}
data-testid="notice-dismiss"
>
<Close />
</button>
</StyledButton>
</Grid>
);

return (
<Notice
className={cx(classes.root, className)}
<StyledNotice
className={className}
dismissibleButton={dismissibleButton}
{...rest}
>
{children}
</Notice>
</StyledNotice>
);
};

Expand All @@ -96,3 +74,21 @@ export const useDismissibleBanner = (

return { hasDismissedBanner, handleDismiss };
};

const StyledNotice = styled(Notice)(({ theme }) => ({
display: 'flex',
alignItems: 'center',
flexFlow: 'row nowrap',
justifyContent: 'space-between',
borderRadius: 1,
marginBottom: theme.spacing(),
padding: theme.spacing(2),
background: theme.bg.bgPaper,
}));

const StyledButton = styled('button')(({ theme }) => ({
...theme.applyLinkStyles,
display: 'flex',
color: theme.textColors.tableStatic,
marginLeft: 20,
}));