This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
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.
Add a page content level loading state
- Loading branch information
Showing
9 changed files
with
132 additions
and
8 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/components/page_template/__specs__/page_content.spec.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import i18n from "i18next"; | ||
import { initReactI18next } from "react-i18next"; | ||
import { render } from "@testing-library/react"; | ||
|
||
import { PageContent } from "../src/page_content"; | ||
|
||
describe("<PageContent />", () => { | ||
i18n.use(initReactI18next).init({ | ||
lng: "en", | ||
resources: { | ||
en: { | ||
translation: { | ||
loading: "Loading", | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
it("renders content", () => { | ||
const { getByText } = render(<PageContent>My Content</PageContent>); | ||
|
||
expect(getByText("My Content")).toBeInTheDocument(); | ||
}); | ||
|
||
context("loading", () => { | ||
it("does not render the content", () => { | ||
const { queryByText } = render( | ||
<PageContent loading>My Content</PageContent> | ||
); | ||
|
||
expect(queryByText("My Content")).not.toBeInTheDocument(); | ||
}); | ||
|
||
it("renders a loading message", () => { | ||
const { queryByText } = render( | ||
<PageContent loading>My Content</PageContent> | ||
); | ||
|
||
expect(queryByText("Loading")).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,3 @@ | ||
{ | ||
"extends": "../../../../tsconfig.spec.json" | ||
} |
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 @@ | ||
module.exports = { presets: ["@babel/preset-env"] }; |
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,3 @@ | ||
import BaseConfig from "../../../jest.config"; | ||
|
||
export default BaseConfig; |
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,2 @@ | ||
import "@testing-library/jest-dom"; | ||
import "jest-styled-components"; |
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
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,14 +1,44 @@ | ||
import { Box, BoxProps } from "@buoysoftware/anchor-layout"; | ||
import { Box, BoxProps, Flex } from "@buoysoftware/anchor-layout"; | ||
import { LoadingIndicator } from "@buoysoftware/anchor-loading-indicator"; | ||
import { Body } from "@buoysoftware/anchor-typography"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
type PageContentProps = Omit<BoxProps, "gridArea">; | ||
interface OwnProps { | ||
loading?: boolean; | ||
} | ||
|
||
type PageContentProps = OwnProps & Omit<BoxProps, "gridArea">; | ||
|
||
export const PageContent: React.FC<PageContentProps> = ({ | ||
children, | ||
loading, | ||
...props | ||
}): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Box gridArea="content" mt="40px" px="page.gutterX" {...props}> | ||
{children} | ||
<Box | ||
gridArea="content" | ||
display={loading ? "grid" : "block"} | ||
mt="40px" | ||
px="page.gutterX" | ||
{...props} | ||
> | ||
{loading ? ( | ||
<Flex | ||
flexDirection="column" | ||
alignItems="center" | ||
justifySelf="center" | ||
alignSelf="center" | ||
> | ||
<LoadingIndicator strokeSize={2} size={40} color="grey70" /> | ||
<Body color="text.secondary" mt="s" size="m"> | ||
{t("loading")} | ||
</Body> | ||
</Flex> | ||
) : ( | ||
children | ||
)} | ||
</Box> | ||
); | ||
}; |
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
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