-
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.
Loading status checks…
Merge pull request #164 from oaknational/feat/styled-ordered-list
feat: order list nav with tertiary styling
- v1.75.0
- v1.74.0
- v1.73.2
- v1.73.1
- v1.73.0
- v1.72.0
- v1.71.0
- v1.70.0
- v1.69.0
- v1.68.1
- v1.68.0
- v1.67.1
- v1.67.0
- v1.66.0
- v1.65.1
- v1.65.0
- v1.64.1
- v1.64.0
- v1.63.0
- v1.62.0
- v1.61.1
- v1.61.0
- v1.60.0
- v1.59.0
- v1.58.0
- v1.57.0
- v1.56.0
- v1.55.0
- v1.54.0
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.0
- v1.49.0
- v1.48.0
- v1.47.0
- v1.46.0
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.3
- v1.42.2
- v1.42.1
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.0
- v1.38.2
- v1.38.1
- v1.38.0
- v1.37.0
- v1.36.0
- v1.35.0
- v1.34.1
- v1.34.0
- v1.33.0
- v1.32.0
- v1.31.0
- v1.30.1
- v1.30.0
- v1.29.0
- v1.28.3
- v1.28.2
- v1.28.1
- v1.28.0
- v1.27.0
- v1.26.0
- v1.25.0
- v1.24.1
- v1.24.0
- v1.23.1
- v1.23.0
- v1.22.1
- v1.22.0
- v1.21.0
- v1.20.1
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.2
- v1.16.1
- v1.16.0
- v1.15.0
- v1.14.0
- v1.13.0
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.2
- v1.7.1
- v1.7.0
- v1.6.0
- v1.5.1
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.42.1
- v0.42.0
- v0.41.1
- v0.41.0
- v0.40.0
- v0.39.1
- v0.39.0
- v0.38.0
- v0.37.2
- v0.37.1
- v0.37.0
- v0.36.1
- v0.36.0
- v0.35.1
- v0.35.0
- v0.34.0
- v0.33.1
- v0.33.0
- v0.32.4
- v0.32.3
- v0.32.2
- v0.32.1
- v0.32.0
- v0.31.1
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.0
Showing
7 changed files
with
415 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
src/components/organisms/teacher/OakTertiaryOLNav/OakTertiaryOLNav.stories.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,41 @@ | ||
import React from "react"; | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { OakTertiaryOLNav, OakTertiaryOLNavProps } from "./OakTertiaryOLNav"; | ||
|
||
const items: OakTertiaryOLNavProps = { | ||
items: [ | ||
{ | ||
title: "Creating solid explanations and good modelling", | ||
href: "#solid-explanations", | ||
}, | ||
{ | ||
title: "Short item", | ||
href: "#short-item", | ||
}, | ||
{ | ||
title: "What is a lesson plan", | ||
href: "#lesson-plan", | ||
}, | ||
], | ||
ariaLabel: "navigation", | ||
title: "contents", | ||
}; | ||
/** | ||
* | ||
* OakTertiaryOLNav is a styled ol list nav. | ||
* | ||
*/ | ||
const meta: Meta<typeof OakTertiaryOLNav> = { | ||
component: OakTertiaryOLNav, | ||
tags: ["autodocs"], | ||
title: "components/organisms/teacher/OakTertiaryOLNav", | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof OakTertiaryOLNav>; | ||
|
||
export const Default: Story = { | ||
render: (args) => <OakTertiaryOLNav {...args} />, | ||
args: items, | ||
}; |
59 changes: 59 additions & 0 deletions
59
src/components/organisms/teacher/OakTertiaryOLNav/OakTertiaryOLNav.test.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,59 @@ | ||
import React from "react"; | ||
import "@testing-library/jest-dom"; | ||
import { create } from "react-test-renderer"; | ||
|
||
import { OakTertiaryOLNav, OakTertiaryOLNavProps } from "./OakTertiaryOLNav"; | ||
|
||
import renderWithTheme from "@/test-helpers/renderWithTheme"; | ||
import { OakThemeProvider } from "@/components/atoms"; | ||
import { oakDefaultTheme } from "@/styles"; | ||
|
||
const baseProps: OakTertiaryOLNavProps = { | ||
items: [ | ||
{ title: "Item 1", href: "#item1" }, | ||
{ title: "Item 2", href: "#item2" }, | ||
], | ||
ariaLabel: "navigation", | ||
}; | ||
|
||
describe("Component OakTertiaryOLNav", () => { | ||
it("renders", () => { | ||
const { getByTestId } = renderWithTheme( | ||
<OakTertiaryOLNav {...baseProps} data-testid="test" />, | ||
); | ||
expect(getByTestId("test")).toBeInTheDocument(); | ||
}); | ||
it("conditionally renders the title", () => { | ||
const { queryByText } = renderWithTheme( | ||
<OakTertiaryOLNav {...baseProps} title="Contents" />, | ||
); | ||
expect(queryByText("Contents")).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders items with correct title and href", () => { | ||
const { getByText } = renderWithTheme(<OakTertiaryOLNav {...baseProps} />); | ||
const link1 = getByText("Item 1"); | ||
const link2 = getByText("Item 2"); | ||
expect(link1.closest("a")).toHaveAttribute("href", "#item1"); | ||
expect(link2.closest("a")).toHaveAttribute("href", "#item2"); | ||
}); | ||
it("renders anchor target if passed as prop", () => { | ||
const { getByTestId } = renderWithTheme( | ||
<OakTertiaryOLNav | ||
{...baseProps} | ||
anchorTarget="target" | ||
data-testid="test" | ||
/>, | ||
); | ||
expect(getByTestId("test").querySelector("#target")).toBeInTheDocument(); | ||
}); | ||
|
||
it("matches snapshot", () => { | ||
const tree = create( | ||
<OakThemeProvider theme={oakDefaultTheme}> | ||
<OakTertiaryOLNav {...baseProps} />, | ||
</OakThemeProvider>, | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
116 changes: 116 additions & 0 deletions
116
src/components/organisms/teacher/OakTertiaryOLNav/OakTertiaryOLNav.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,116 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { InternalLink } from "@/components/molecules/InternalLink"; | ||
import { parseColor } from "@/styles/helpers/parseColor"; | ||
import { parseDropShadow } from "@/styles/helpers/parseDropShadow"; | ||
import { OakLI } from "@/components/atoms/OakLI"; | ||
import { parseSpacing } from "@/styles/helpers/parseSpacing"; | ||
import { OakAnchorTarget, OakBox, OakSpan } from "@/components/atoms"; | ||
|
||
const StyledNav = styled.nav` | ||
outline: none; | ||
`; | ||
const StyledOakLink = styled(InternalLink)` | ||
text-decoration: none; | ||
color: inherit; | ||
width: 100%; | ||
display: Flex; | ||
width: 100%; | ||
&:focus { | ||
box-shadow: none; | ||
} | ||
&::before { | ||
content: counter(list-counter); | ||
min-width: 32px; | ||
height: 32px; | ||
border-radius: 50%; | ||
background-color: ${parseColor("black")}; | ||
color: ${parseColor("white")}; | ||
text-align: center; | ||
line-height: 32px; | ||
margin-right: ${parseSpacing("space-between-xs")}; | ||
text-decoration: none; | ||
} | ||
&:hover::before { | ||
background-color: ${parseColor("bg-btn-primary-hover")}; | ||
box-shadow: ${parseDropShadow("drop-shadow-lemon")}; | ||
text-decoration: none; | ||
} | ||
&:focus-within::before { | ||
box-shadow: ${parseDropShadow("drop-shadow-centered-lemon")}, | ||
${parseDropShadow("drop-shadow-centered-grey")}; | ||
text-decoration: none; | ||
} | ||
&:active { | ||
color: ${parseColor("black")}; | ||
} | ||
&:active::before { | ||
box-shadow: ${parseDropShadow("drop-shadow-lemon")}, | ||
${parseDropShadow("drop-shadow-grey")}; | ||
background-color: ${parseColor("black")}; | ||
} | ||
`; | ||
|
||
const StyledOL = styled.ol` | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
text-decoration: none; | ||
`; | ||
|
||
const StyledOLItem = styled(OakLI)` | ||
position: relative; | ||
counter-increment: list-counter; | ||
display: flex; | ||
align-items: center; | ||
margin-bottom: ${parseSpacing("space-between-xs")}; | ||
min-height: 40px; | ||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
&:hover { | ||
text-decoration: underline; | ||
color: ${parseColor("bg-btn-primary-hover")}; | ||
} | ||
`; | ||
|
||
export type OakTertiaryOLNavProps = { | ||
title?: string; | ||
items: { title: string; href: string }[]; | ||
ariaLabel?: string; | ||
anchorTarget?: string; | ||
}; | ||
|
||
export const OakTertiaryOLNav = ({ | ||
items, | ||
ariaLabel, | ||
title, | ||
anchorTarget, | ||
...rest | ||
}: OakTertiaryOLNavProps) => { | ||
return ( | ||
<StyledNav tabIndex={0} aria-label={ariaLabel} {...rest}> | ||
{anchorTarget && <OakAnchorTarget id={anchorTarget} />} | ||
{title && ( | ||
<OakBox $mb={"space-between-m"}> | ||
<OakSpan $font={"heading-light-7"}>{"Contents"}</OakSpan> | ||
</OakBox> | ||
)} | ||
<StyledOL role="list"> | ||
{items.map((item, index) => ( | ||
<StyledOLItem | ||
aria-label={`list item ${index + 1}`} | ||
$font={"heading-7"} | ||
key={index} | ||
> | ||
<StyledOakLink href={item.href}>{item.title}</StyledOakLink> | ||
</StyledOLItem> | ||
))} | ||
</StyledOL> | ||
</StyledNav> | ||
); | ||
}; |
Oops, something went wrong.