-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Fran McDade <[email protected]>
- Loading branch information
Showing
10 changed files
with
91 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import styled from "@emotion/styled"; | ||
import { Alert } from "@mui/material"; | ||
import { mediaDesktopUp } from "../../../styles/common/mixins/breakpoints"; | ||
import { textBodySmall400 } from "../../../styles/common/mixins/fonts"; | ||
|
||
export const StyledAlert = styled(Alert)` | ||
justify-content: center; | ||
padding: 8px 12px; | ||
text-align: center; | ||
.MuiAlert-message { | ||
${textBodySmall400}; | ||
align-self: center; | ||
flex: 1; | ||
.MuiLink-root { | ||
color: inherit; | ||
} | ||
} | ||
.MuiAlert-action { | ||
margin: -8px; | ||
padding: 0; | ||
} | ||
${mediaDesktopUp} { | ||
padding: 8px 16px; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
import { Alert as MAlert, AlertProps as MAlertProps } from "@mui/material"; | ||
import React, { forwardRef, ReactNode } from "react"; | ||
import { AlertProps } from "@mui/material"; | ||
import React, { forwardRef } from "react"; | ||
import { BaseComponentProps } from "../../types"; | ||
import { StyledAlert } from "./banner.styles"; | ||
import { ALERT_PROPS } from "./constants"; | ||
|
||
export interface BannerProps extends MAlertProps { | ||
children: ReactNode; | ||
className?: string; | ||
} | ||
|
||
export const Banner = forwardRef<HTMLDivElement, BannerProps>(function Banner( | ||
{ | ||
children, | ||
className, | ||
...props /* Spread props to allow for Mui AlertProps specific prop overrides. */ | ||
}: BannerProps, | ||
export const Banner = forwardRef< | ||
HTMLDivElement, | ||
AlertProps & BaseComponentProps | ||
>(function Alert( | ||
{ ...props }: AlertProps & BaseComponentProps, | ||
ref | ||
): JSX.Element { | ||
return ( | ||
<MAlert className={className} ref={ref} {...props}> | ||
{children} | ||
</MAlert> | ||
); | ||
return <StyledAlert {...ALERT_PROPS} ref={ref} {...props} />; | ||
}); |
24 changes: 0 additions & 24 deletions
24
src/components/common/Banner/components/BannerPrimary/bannerPrimary.styles.ts
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
src/components/common/Banner/components/BannerPrimary/bannerPrimary.tsx
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
src/components/common/Banner/components/SessionTimeout/sessionTimeout.styles.ts
This file was deleted.
Oops, something went wrong.
29 changes: 12 additions & 17 deletions
29
src/components/common/Banner/components/SessionTimeout/sessionTimeout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
import { AlertProps as MAlertProps } from "@mui/material"; | ||
import React, { Fragment, ReactNode } from "react"; | ||
import { AlertProps, Fade } from "@mui/material"; | ||
import React from "react"; | ||
import { useSessionTimeout } from "../../../../../hooks/useSessionTimeout"; | ||
import { Banner } from "./sessionTimeout.styles"; | ||
|
||
export interface SessionTimeoutProps extends Omit<MAlertProps, "title"> { | ||
className?: string; | ||
title?: ReactNode; | ||
} | ||
import { BaseComponentProps, ContentProps } from "../../../../types"; | ||
import { Banner } from "../../banner"; | ||
|
||
export const SessionTimeout = ({ | ||
children, | ||
className, | ||
title = "For your security, you have been logged out due to 15 minutes of inactivity.", | ||
content, | ||
...props | ||
}: SessionTimeoutProps): JSX.Element => { | ||
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => { | ||
const { clearSessionTimeout, isSessionTimeout } = useSessionTimeout(); | ||
return ( | ||
<Fragment> | ||
{isSessionTimeout && ( | ||
<Banner className={className} onClose={clearSessionTimeout} {...props}> | ||
{title} | ||
</Banner> | ||
)} | ||
</Fragment> | ||
<Fade in={isSessionTimeout} unmountOnExit> | ||
<Banner className={className} onClose={clearSessionTimeout} {...props}> | ||
{content || children} | ||
</Banner> | ||
</Fade> | ||
); | ||
}; |
33 changes: 11 additions & 22 deletions
33
src/components/common/Banner/components/SystemIndexing/systemIndexing.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
import { AlertProps as MAlertProps } from "@mui/material"; | ||
import React, { Fragment, ReactNode } from "react"; | ||
import { AlertProps, Fade } from "@mui/material"; | ||
import React from "react"; | ||
import { useSystemStatus } from "../../../../../hooks/useSystemStatus"; | ||
import { BannerPrimary } from "../BannerPrimary/bannerPrimary"; | ||
|
||
export interface SystemIndexingProps extends Omit<MAlertProps, "title"> { | ||
children?: ReactNode; | ||
className?: string; | ||
title?: ReactNode; | ||
} | ||
import { BaseComponentProps, ContentProps } from "../../../../types"; | ||
import { Banner } from "../../banner"; | ||
|
||
export const SystemIndexing = ({ | ||
children, | ||
className, | ||
title = "Data indexing in progress. Downloads and exports are disabled as search results may be incomplete.", | ||
content, | ||
...props | ||
}: SystemIndexingProps): JSX.Element => { | ||
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => { | ||
const systemStatus = useSystemStatus(); | ||
const { indexing, loading, ok } = systemStatus; | ||
const showAlert = !loading && ok && indexing; | ||
return ( | ||
<Fragment> | ||
{showAlert && ( | ||
<BannerPrimary className={className} {...props}> | ||
<Fragment> | ||
{title} | ||
{children} | ||
</Fragment> | ||
</BannerPrimary> | ||
)} | ||
</Fragment> | ||
<Fade in={!loading && ok && indexing} unmountOnExit> | ||
<Banner className={className} {...props}> | ||
{content || children} | ||
</Banner> | ||
</Fade> | ||
); | ||
}; |
33 changes: 11 additions & 22 deletions
33
src/components/common/Banner/components/SystemStatus/systemStatus.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,22 @@ | ||
import { AlertProps as MAlertProps } from "@mui/material"; | ||
import React, { Fragment, ReactNode } from "react"; | ||
import { AlertProps, Fade } from "@mui/material"; | ||
import React from "react"; | ||
import { useSystemStatus } from "../../../../../hooks/useSystemStatus"; | ||
import { BannerPrimary } from "../BannerPrimary/bannerPrimary"; | ||
|
||
export interface SystemStatusProps extends Omit<MAlertProps, "title"> { | ||
children?: ReactNode; | ||
className?: string; | ||
title?: ReactNode; | ||
} | ||
import { BaseComponentProps, ContentProps } from "../../../../types"; | ||
import { Banner } from "../../banner"; | ||
|
||
export const SystemStatus = ({ | ||
children, | ||
className, | ||
title = "One or more of the system components are currently unavailable. Functionality may be degraded.", | ||
content, | ||
...props | ||
}: SystemStatusProps): JSX.Element => { | ||
}: AlertProps & BaseComponentProps & ContentProps): JSX.Element => { | ||
const systemStatus = useSystemStatus(); | ||
const { loading, ok } = systemStatus; | ||
const showAlert = !loading && !ok; | ||
return ( | ||
<Fragment> | ||
{showAlert && ( | ||
<BannerPrimary className={className} {...props}> | ||
<Fragment> | ||
{title} | ||
{children} | ||
</Fragment> | ||
</BannerPrimary> | ||
)} | ||
</Fragment> | ||
<Fade in={!loading && !ok} unmountOnExit> | ||
<Banner className={className} {...props}> | ||
{content || children} | ||
</Banner> | ||
</Fade> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { AlertProps } from "@mui/material"; | ||
import { COLOR, VARIANT } from "../../../styles/common/mui/alert"; | ||
import { FlatPaper } from "../Paper/paper.styles"; | ||
|
||
export const ALERT_PROPS: Partial<AlertProps> = { | ||
color: COLOR.PRIMARY, | ||
component: FlatPaper, | ||
elevation: 0, | ||
icon: false, | ||
variant: VARIANT.FILLED, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { ReactNode } from "react"; | ||
|
||
export interface BaseComponentProps { | ||
className?: string; | ||
} | ||
|
||
export interface ContentProps { | ||
content?: ReactNode; | ||
} | ||
|
||
export interface TestIdProps { | ||
testId?: string; | ||
} |