Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NavList component (part 1) #2058

Merged
merged 14 commits into from
May 10, 2022
5 changes: 5 additions & 0 deletions .changeset/breezy-cooks-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Add draft of `NavList` component
234 changes: 40 additions & 194 deletions docs/content/NavList.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,30 @@
title: NavList
status: Draft
description: Use nav list to render a vertical list of navigation links.
source: https://github.com/primer/react/tree/main/src/NavList
---

<Note variant="warning">Not implemented yet</Note>

To render a horizontal list of navigation links, consider using [UnderlineNav](/UnderlineNav).
```js
import {NavList} from '@primer/react/drafts'
```

## Examples

### Simple

```jsx
```jsx live drafts
<NavList>
<NavList.Item href="/" aria-current="page">
Dashboard
Home
</NavList.Item>
<NavList.Item href="/pulls">Pull requests</NavList.Item>
<NavList.Item href="/issues">Issues</NavList.Item>
<NavList.Item href="/about">About</NavList.Item>
<NavList.Item href="/contact">Contact</NavList.Item>
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li><a href="/" aria-current="page">Dashboard</a></li>
<li><a href="/about">Pull requests</a></li>
<li><a href="/contact">Issues</a></li>
</ul>
</nav>
```

</details>

### With leading icons

```jsx
```jsx live drafts
<NavList>
<NavList.Item href="/" aria-current="page">
<NavList.LeadingVisual>
Expand All @@ -62,88 +48,34 @@ To render a horizontal list of navigation links, consider using [UnderlineNav](/
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li>
<a href="/" aria-current="page">
<span><svg aria-hidden="true">...</svg></span>
<span>Dashboard</span>
</a>
</li>
<li>
<a href="/pulls">
<span><svg aria-hidden="true">...</svg></span>
<span>Pull requests</span>
</a>
</li>
<li>
<a href="/issues">
<span><svg aria-hidden="true">...</svg></span>
<span>Issues</span>
</a>
</li>
</ul>
</nav>
```

</details>

### With other leading visuals

```jsx
```jsx live drafts
<NavList>
<NavList.Item href="/general" aria-current="page">
<NavList.LeadingVisual>#️⃣</NavList.LeadingVisual>
<NavList.LeadingVisual>
<span aria-hidden>#️⃣</span>
</NavList.LeadingVisual>
General
</NavList.Item>
<NavList.Item href="/q-a">
<NavList.LeadingVisual>🙏</NavList.LeadingVisual>
<NavList.LeadingVisual>
<span aria-hidden>🙏</span>
</NavList.LeadingVisual>
Q&A
</NavList.Item>
<NavList.Item href="/show-and-tell">
<NavList.LeadingVisual>🙌</NavList.LeadingVisual>
<NavList.LeadingVisual>
<span aria-hidden>🙌</span>
</NavList.LeadingVisual>
Show and tell
</NavList.Item>
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li>
<a href="/" aria-current="page">
<span>#️⃣</span>
<span>General</span>
</a>
</li>
<li>
<a href="/pulls">
<span>🙏</span>
<span>Q&A</span>
</a>
</li>
<li>
<a href="/issues">
<span>🙌</span>
<span>Show and tell</span>
</a>
</li>
</ul>
</nav>
```

</details>

### With trailing visuals

```jsx
```jsx live drafts
<NavList>
<NavList.Item href="/inbox" aria-current="page">
Inbox
Expand All @@ -154,31 +86,13 @@ To render a horizontal list of navigation links, consider using [UnderlineNav](/
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li>
<a href="/inbox" aria-current="page">
<span>Inbox</span>
<span>1,234</span>
</a>
</li>
<li><a href="/saved">Saved</a></li>
<li><a href="/done">Done</a></li>
</ul>
</nav>
```

</details>

### With a heading

```jsx
```jsx live drafts
<>
<h3 id="workflows-heading">Workflows</h3>
<Heading as="h3" id="workflows-heading" sx={{fontSize: 2}}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good example!

Workflows
</Heading>
<NavList aria-labelledby="workflows-heading">
<NavList.Item href="/" aria-current="page">
All workflows
Expand All @@ -190,26 +104,9 @@ To render a horizontal list of navigation links, consider using [UnderlineNav](/
</>
```

<details>
<summary>Rendered HTML</summary>

```html
<h3 id="workflows-heading">Workflows</h3>
<nav aria-labelledby="workflows-heading">
<ul role="list">
<li><a href="/" aria-current="page">All workflows</a></li>
<li><a href="/ci">CI</a></li>
<li><a href="/deploy">Deploy</a></li>
<li><a href="/release">Release</a></li>
</ul>
</nav>
```

</details>

### With aria-label

```jsx
```jsx live drafts
<NavList aria-label="Security">
<NavList.Item href="/" aria-current="page">
Overview
Expand All @@ -219,24 +116,9 @@ To render a horizontal list of navigation links, consider using [UnderlineNav](/
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav aria-label="Security">
<ul role="list">
<li><a href="/" aria-current="page">Overview</a></li>
<li><a href="/policy">Security policy</a></li>
<li><a href="/advisories">Security advisories</a></li>
</ul>
</nav>
```

</details>

### With groups

```jsx
```jsx live drafts
<NavList>
<NavList.Group title="Overview">
<NavList.Item href="/getting-started" aria-current="page">
Expand All @@ -251,34 +133,10 @@ To render a horizontal list of navigation links, consider using [UnderlineNav](/
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li>
<div role="presentation" id="generated-id-1">Overview</div>
<ul role="list" aria-labelledby="generated-id-1">
<li><a href="/getting-started" aria-current="page">Getting started</a></li>
</ul>
</li>
<li>
<div role="presentation" id="generated-id-2">Components</div>
<ul role="list" aria-labelledby="generated-id-2">
<li><a href="/Avatar">Avatar</a></li>
<li><a href="/Button">Button</a></li>
<li><a href="/Label">Label</a></li>
</ul>
</li>
</ul>
</nav>
```

</details>

### With sub-items

<Note variant="danger">Not implemented yet</Note>

```jsx
<NavList>
<NavList.Item href="/branches">Branches</NavList.Item>
Expand Down Expand Up @@ -325,9 +183,11 @@ If a `NavList.Item` contains a `NavList.SubNav`, the `NavList.Item` will render

### With a divider

```jsx
```jsx live drafts
<NavList>
<NavList.Item href="/">Dashboard</NavList.Item>
<NavList.Item href="/" aria-current="page">
Dashboard
</NavList.Item>
<NavList.Item href="/pulls">Pull requests</NavList.Item>
<NavList.Item href="/issues">Issues</NavList.Item>
<NavList.Divider />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting 🤔

Would we also want to support <NavList showDivider={true} similar to Action list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think dividers in between individual items is part of the NavList design cc @vdepizzol

Expand All @@ -336,26 +196,10 @@ If a `NavList.Item` contains a `NavList.SubNav`, the `NavList.Item` will render
</NavList>
```

<details>
<summary>Rendered HTML</summary>

```html
<nav>
<ul role="list">
<li><a href="/">Dashboard</a></li>
<li><a href="/pulls">Pull requests</a></li>
<li><a href="/issues">Issues</a></li>
<div role="separator"></div>
<li><a href="/marketplace">Marketplace</a></li>
<li><a href="/explore">Explore</a></li>
</ul>
</nav>
```

</details>

### With React Router

<Note variant="danger">Not implemented yet</Note>

```jsx
import {Link, useMatch, useResolvedPath} from 'react-router-dom'
import {NavList} from '@primer/react'
Expand Down Expand Up @@ -383,6 +227,8 @@ function App() {

### With Next.js

<Note variant="danger">Not implemented yet</Note>

```jsx
import {useRouter} from 'next/router'
import Link from 'next/link'
Expand Down Expand Up @@ -506,10 +352,10 @@ function App() {
<ComponentChecklist
items={{
propsDocumented: true,
noUnnecessaryDeps: false,
adaptsToThemes: false,
adaptsToScreenSizes: false,
fullTestCoverage: false,
noUnnecessaryDeps: true,
adaptsToThemes: true,
adaptsToScreenSizes: true,
fullTestCoverage: true,
usedInProduction: false,
usageExamplesDocumented: true,
hasStorybookStories: false,
Expand Down
3 changes: 2 additions & 1 deletion src/ActionList/Visuals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export const TrailingVisual: React.FC<VisualProps> = ({sx = {}, ...props}) => {
height: '20px', // match height of text row
flexShrink: 0,
color: getVariantStyles(variant, disabled).annotationColor,
marginLeft: 2
marginLeft: 2,
fontWeight: 'initial'
},
sx as SxProp
)}
Expand Down
Loading