Skip to content

Commit d9c87c7

Browse files
frano-mFran McDade
and
Fran McDade
authored
feat!: update banner components (#253) (#255)
Co-authored-by: Fran McDade <[email protected]>
1 parent 18f3e54 commit d9c87c7

File tree

10 files changed

+91
-152
lines changed

10 files changed

+91
-152
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import styled from "@emotion/styled";
2+
import { Alert } from "@mui/material";
3+
import { mediaDesktopUp } from "../../../styles/common/mixins/breakpoints";
4+
import { textBodySmall400 } from "../../../styles/common/mixins/fonts";
5+
6+
export const StyledAlert = styled(Alert)`
7+
justify-content: center;
8+
padding: 8px 12px;
9+
text-align: center;
10+
11+
.MuiAlert-message {
12+
${textBodySmall400};
13+
align-self: center;
14+
flex: 1;
15+
16+
.MuiLink-root {
17+
color: inherit;
18+
}
19+
}
20+
21+
.MuiAlert-action {
22+
margin: -8px;
23+
padding: 0;
24+
}
25+
26+
${mediaDesktopUp} {
27+
padding: 8px 16px;
28+
}
29+
`;
+11-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
import { Alert as MAlert, AlertProps as MAlertProps } from "@mui/material";
2-
import React, { forwardRef, ReactNode } from "react";
1+
import { AlertProps } from "@mui/material";
2+
import React, { forwardRef } from "react";
3+
import { BaseComponentProps } from "../../types";
4+
import { StyledAlert } from "./banner.styles";
5+
import { ALERT_PROPS } from "./constants";
36

4-
export interface BannerProps extends MAlertProps {
5-
children: ReactNode;
6-
className?: string;
7-
}
8-
9-
export const Banner = forwardRef<HTMLDivElement, BannerProps>(function Banner(
10-
{
11-
children,
12-
className,
13-
...props /* Spread props to allow for Mui AlertProps specific prop overrides. */
14-
}: BannerProps,
7+
export const Banner = forwardRef<
8+
HTMLDivElement,
9+
AlertProps & BaseComponentProps
10+
>(function Alert(
11+
{ ...props }: AlertProps & BaseComponentProps,
1512
ref
1613
): JSX.Element {
17-
return (
18-
<MAlert className={className} ref={ref} {...props}>
19-
{children}
20-
</MAlert>
21-
);
14+
return <StyledAlert {...ALERT_PROPS} ref={ref} {...props} />;
2215
});

src/components/common/Banner/components/BannerPrimary/bannerPrimary.styles.ts

-24
This file was deleted.

src/components/common/Banner/components/BannerPrimary/bannerPrimary.tsx

-27
This file was deleted.

src/components/common/Banner/components/SessionTimeout/sessionTimeout.styles.ts

-22
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
import { AlertProps as MAlertProps } from "@mui/material";
2-
import React, { Fragment, ReactNode } from "react";
1+
import { AlertProps, Fade } from "@mui/material";
2+
import React from "react";
33
import { useSessionTimeout } from "../../../../../hooks/useSessionTimeout";
4-
import { Banner } from "./sessionTimeout.styles";
5-
6-
export interface SessionTimeoutProps extends Omit<MAlertProps, "title"> {
7-
className?: string;
8-
title?: ReactNode;
9-
}
4+
import { BaseComponentProps, ContentProps } from "../../../../types";
5+
import { Banner } from "../../banner";
106

117
export const SessionTimeout = ({
8+
children,
129
className,
13-
title = "For your security, you have been logged out due to 15 minutes of inactivity.",
10+
content,
1411
...props
15-
}: SessionTimeoutProps): JSX.Element => {
12+
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => {
1613
const { clearSessionTimeout, isSessionTimeout } = useSessionTimeout();
1714
return (
18-
<Fragment>
19-
{isSessionTimeout && (
20-
<Banner className={className} onClose={clearSessionTimeout} {...props}>
21-
{title}
22-
</Banner>
23-
)}
24-
</Fragment>
15+
<Fade in={isSessionTimeout} unmountOnExit>
16+
<Banner className={className} onClose={clearSessionTimeout} {...props}>
17+
{content || children}
18+
</Banner>
19+
</Fade>
2520
);
2621
};
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
import { AlertProps as MAlertProps } from "@mui/material";
2-
import React, { Fragment, ReactNode } from "react";
1+
import { AlertProps, Fade } from "@mui/material";
2+
import React from "react";
33
import { useSystemStatus } from "../../../../../hooks/useSystemStatus";
4-
import { BannerPrimary } from "../BannerPrimary/bannerPrimary";
5-
6-
export interface SystemIndexingProps extends Omit<MAlertProps, "title"> {
7-
children?: ReactNode;
8-
className?: string;
9-
title?: ReactNode;
10-
}
4+
import { BaseComponentProps, ContentProps } from "../../../../types";
5+
import { Banner } from "../../banner";
116

127
export const SystemIndexing = ({
138
children,
149
className,
15-
title = "Data indexing in progress. Downloads and exports are disabled as search results may be incomplete.",
10+
content,
1611
...props
17-
}: SystemIndexingProps): JSX.Element => {
12+
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => {
1813
const systemStatus = useSystemStatus();
1914
const { indexing, loading, ok } = systemStatus;
20-
const showAlert = !loading && ok && indexing;
2115
return (
22-
<Fragment>
23-
{showAlert && (
24-
<BannerPrimary className={className} {...props}>
25-
<Fragment>
26-
{title}
27-
{children}
28-
</Fragment>
29-
</BannerPrimary>
30-
)}
31-
</Fragment>
16+
<Fade in={!loading && ok && indexing} unmountOnExit>
17+
<Banner className={className} {...props}>
18+
{content || children}
19+
</Banner>
20+
</Fade>
3221
);
3322
};
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
import { AlertProps as MAlertProps } from "@mui/material";
2-
import React, { Fragment, ReactNode } from "react";
1+
import { AlertProps, Fade } from "@mui/material";
2+
import React from "react";
33
import { useSystemStatus } from "../../../../../hooks/useSystemStatus";
4-
import { BannerPrimary } from "../BannerPrimary/bannerPrimary";
5-
6-
export interface SystemStatusProps extends Omit<MAlertProps, "title"> {
7-
children?: ReactNode;
8-
className?: string;
9-
title?: ReactNode;
10-
}
4+
import { BaseComponentProps, ContentProps } from "../../../../types";
5+
import { Banner } from "../../banner";
116

127
export const SystemStatus = ({
138
children,
149
className,
15-
title = "One or more of the system components are currently unavailable. Functionality may be degraded.",
10+
content,
1611
...props
17-
}: SystemStatusProps): JSX.Element => {
12+
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => {
1813
const systemStatus = useSystemStatus();
1914
const { loading, ok } = systemStatus;
20-
const showAlert = !loading && !ok;
2115
return (
22-
<Fragment>
23-
{showAlert && (
24-
<BannerPrimary className={className} {...props}>
25-
<Fragment>
26-
{title}
27-
{children}
28-
</Fragment>
29-
</BannerPrimary>
30-
)}
31-
</Fragment>
16+
<Fade in={!loading && !ok} unmountOnExit>
17+
<Banner className={className} {...props}>
18+
{content || children}
19+
</Banner>
20+
</Fade>
3221
);
3322
};
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { AlertProps } from "@mui/material";
2+
import { COLOR, VARIANT } from "../../../styles/common/mui/alert";
3+
import { FlatPaper } from "../Paper/paper.styles";
4+
5+
export const ALERT_PROPS: Partial<AlertProps> = {
6+
color: COLOR.PRIMARY,
7+
component: FlatPaper,
8+
elevation: 0,
9+
icon: false,
10+
variant: VARIANT.FILLED,
11+
};

src/components/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import { ReactNode } from "react";
2+
13
export interface BaseComponentProps {
24
className?: string;
35
}
46

7+
export interface ContentProps {
8+
content?: ReactNode;
9+
}
10+
511
export interface TestIdProps {
612
testId?: string;
713
}

0 commit comments

Comments
 (0)