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
PageContent loading state #96
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both work, not sure if one is better than the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, turns out if I use
display: flex
thenjustify-self
doesn't work on the box below.Per MDN: