-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subject listing page): merge changes
- Loading branch information
Showing
11 changed files
with
364 additions
and
4 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,93 @@ | ||
import { ComponentStory, ComponentMeta } from "@storybook/react"; | ||
|
||
import { UnitListProps } from "./UnitList"; | ||
|
||
import Component from "."; | ||
|
||
const currentPageItems: UnitListProps = { | ||
units: [ | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: false, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: false, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: true, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: false, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: false, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
], | ||
keyStageSlug: "4", | ||
subjectSlug: "computing", | ||
headingTag: "h1", | ||
paginationProps: { | ||
currentPage: 1, | ||
totalPages: 2, | ||
}, | ||
}; | ||
|
||
const tiers = [ | ||
{ title: "Foundation", slug: "foundation", unitCount: 14 }, | ||
{ title: "Core", slug: "core", unitCount: 14 }, | ||
{ title: "Higher", slug: "higher", unitCount: 14 }, | ||
]; | ||
|
||
export default { | ||
title: "Lists/Unit list", | ||
component: Component, | ||
} as ComponentMeta<typeof Component>; | ||
|
||
const Template: ComponentStory<typeof Component> = (args) => { | ||
return <Component {...args} />; | ||
}; | ||
|
||
export const UnitList = Template.bind({}); | ||
|
||
UnitList.args = currentPageItems; | ||
|
||
export const UnitListTiers = Template.bind({}); | ||
|
||
UnitListTiers.args = { | ||
...currentPageItems, | ||
tiers: tiers, | ||
}; |
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,33 @@ | ||
import renderWithProviders from "../../__tests__/__helpers__/renderWithProviders"; | ||
import { mockPaginationProps } from "../Pagination/Pagination.test"; | ||
|
||
import UnitList from "."; | ||
|
||
describe("components/UnitList", () => { | ||
test("renders the list items", () => { | ||
const { getByRole } = renderWithProviders( | ||
<UnitList | ||
paginationProps={mockPaginationProps} | ||
subjectSlug={"computing"} | ||
keyStageSlug={"2"} | ||
headingTag={"h1"} | ||
units={[ | ||
{ | ||
title: | ||
"1, To build knowledge of the historical context of the play ‘Macbeth’", | ||
slug: "To-build-knowledge", | ||
learningThemeTitle: "MacBeth", | ||
lessonCount: 4, | ||
hasUnitQuiz: false, | ||
subjectSlug: "english", | ||
keyStageSlug: "2", | ||
}, | ||
]} | ||
/> | ||
); | ||
|
||
const listHeading = getByRole("heading", { level: 1 }); | ||
|
||
expect(listHeading).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,89 @@ | ||
import { FC } from "react"; | ||
|
||
import Box from "../Box"; | ||
import Flex from "../Flex"; | ||
import Pagination, { PaginationProps } from "../Pagination"; | ||
import { Heading, LI, Span, UL } from "../Typography"; | ||
import { HeadingTag } from "../Typography/Heading"; | ||
import OakLink from "../OakLink"; | ||
|
||
import UnitListItem from "./UnitListItem"; | ||
import { UnitListItemProps } from "./UnitListItem/UnitListItem"; | ||
|
||
export type Tier = { | ||
title: string; | ||
slug: string; | ||
unitCount: number; | ||
}; | ||
|
||
export type UnitListProps = { | ||
units: UnitListItemProps[]; | ||
keyStageSlug: string; | ||
subjectSlug: string; | ||
paginationProps: PaginationProps; | ||
headingTag: HeadingTag; | ||
tiers?: Tier[]; | ||
}; | ||
/** | ||
* Contains a list of units | ||
* | ||
* ## Usage | ||
* Used on subject, unit and search results page | ||
*/ | ||
const UnitList: FC<UnitListProps> = (props) => { | ||
const { | ||
units, | ||
paginationProps, | ||
headingTag, | ||
tiers, | ||
keyStageSlug, | ||
subjectSlug, | ||
} = props; | ||
|
||
return ( | ||
<Flex $flexDirection="column"> | ||
<Flex $flexDirection={["column-reverse", "column"]}> | ||
<Heading $font={["heading-6", "heading-5"]} $mb={24} tag={headingTag}> | ||
Units | ||
</Heading> | ||
|
||
{tiers && ( | ||
<Flex $mb={[24, 32]}> | ||
{tiers.map(({ title, slug, unitCount }) => ( | ||
<OakLink | ||
keyStage={keyStageSlug} | ||
subject={subjectSlug} | ||
search={{ tier: slug }} | ||
page={"unit-index"} | ||
> | ||
<Span | ||
$font={"heading-7"} | ||
$mr={[12, 32]} | ||
>{`${title} (${unitCount})`}</Span> | ||
</OakLink> | ||
))} | ||
</Flex> | ||
)} | ||
</Flex> | ||
|
||
{units.length ? ( | ||
<> | ||
<UL $reset> | ||
{units.map((item) => ( | ||
<LI key={`UnitList-UnitListItem-${item.slug}`}> | ||
<UnitListItem {...item} /> | ||
</LI> | ||
))} | ||
</UL> | ||
</> | ||
) : null} | ||
{units.length > 20 && ( | ||
<Box $width="100%" $mt={[0, "auto"]} $pt={48}> | ||
<Pagination {...paginationProps} /> | ||
</Box> | ||
)} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default UnitList; |
Oops, something went wrong.