Skip to content

Commit 19e684f

Browse files
authored
Merge pull request #377 from primer/underline-nav
Refactor underline nav
2 parents 324c230 + 0ffc472 commit 19e684f

File tree

4 files changed

+202
-11
lines changed

4 files changed

+202
-11
lines changed

modules/primer-navigation/README.md

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Primer comes with several navigation components. Some were designed with singula
4848

4949
The menu is a vertical list of navigational links. **A menu's width and placement must be set by you.** If you like, just use our grid columns as a parent. Otherwise, apply a custom `width`.
5050

51-
```html
51+
```html title="Menu"
5252
<nav class="menu" aria-label="Person settings">
5353
<a class="menu-item selected" href="#url" aria-current="page">Account</a>
5454
<a class="menu-item" href="#url">Profile</a>
@@ -59,7 +59,7 @@ The menu is a vertical list of navigational links. **A menu's width and placemen
5959

6060
There are a few subcomponents and add-ons that work well with the menu, including avatars, counters, and Octicons.
6161

62-
```html
62+
```html title="Menu with octicons, avatars and counters"
6363
<nav class="menu" aria-label="Person settings">
6464
<a class="menu-item selected" href="#url" aria-current="page">
6565
<%= octicon "tools" %>
@@ -83,7 +83,7 @@ There are a few subcomponents and add-ons that work well with the menu, includin
8383

8484
You can also add optional headings to a menu. Feel free to use nearly any semantic element with the `.menu-heading` class, including inline elements, headings, and more.
8585

86-
```html
86+
```html title="Menu with heading"
8787
<nav class="menu" aria-labelledby="menu-heading">
8888
<span class="menu-heading" id="menu-heading">Menu heading</span>
8989
<a class="menu-item selected" href="#url" aria-current="page">Account</a>
@@ -93,12 +93,118 @@ You can also add optional headings to a menu. Feel free to use nearly any semant
9393
</nav>
9494
```
9595

96+
## Underline nav
97+
98+
Use `.UnderlineNav` to style navigation with a minimal underlined selected state, typically used for navigation placed at the top of the page. This component comes with variations to accommodate icons, containers and other content.
99+
100+
```html title="UnderlineNav"
101+
<nav class="UnderlineNav">
102+
<div class="UnderlineNav-body">
103+
<a href="#url" role="tab" title="Item 1" class="UnderlineNav-item selected">Item 1</a>
104+
<a href="#url" role="tab" title="Item 2" class="UnderlineNav-item">Item 2</a>
105+
<a href="#url" role="tab" title="Item 3" class="UnderlineNav-item">Item 3</a>
106+
<a href="#url" role="tab" title="Item 4" class="UnderlineNav-item">Item 4</a>
107+
</div>
108+
</nav>
109+
```
110+
111+
Use `.UnderlineNav-actions` to place another element, such as a button, to the opposite side of the navigation items.
112+
113+
```html title="UnderlineNav-actions"
114+
<nav class="UnderlineNav" aria-label="Foo bar">
115+
<div class="UnderlineNav-body">
116+
<a href="#url" class="UnderlineNav-item selected">Item 1</a>
117+
<a href="#url" class="UnderlineNav-item">Item 2</a>
118+
<a href="#url" class="UnderlineNav-item">Item 3</a>
119+
<a href="#url" class="UnderlineNav-item">Item 4</a>
120+
</div>
121+
<div class="UnderlineNav-actions">
122+
<a class="btn">Button</a>
123+
</div>
124+
</nav>
125+
```
126+
127+
Use `.UnderlineNav--right` to right align the navigation.
128+
129+
```html title="UnderlineNav--right"
130+
<nav class="UnderlineNav UnderlineNav--right">
131+
<div class="UnderlineNav-body">
132+
<a href="#url" role="tab" title="Item 1" class="UnderlineNav-item selected">Item 1</a>
133+
<a href="#url" role="tab" title="Item 2" class="UnderlineNav-item">Item 2</a>
134+
<a href="#url" role="tab" title="Item 3" class="UnderlineNav-item">Item 3</a>
135+
<a href="#url" role="tab" title="Item 4" class="UnderlineNav-item">Item 4</a>
136+
</div>
137+
</nav>
138+
```
139+
140+
`.UnderlineNav--right` also works with when used with `.UnderlineNav-actions`.
141+
142+
```html title="UnderlineNav--right with actions"
143+
<nav class="UnderlineNav UnderlineNav--right" aria-label="Foo bar">
144+
<div class="UnderlineNav-actions">
145+
<a class="btn">Button</a>
146+
</div>
147+
<div class="UnderlineNav-body">
148+
<a href="#url" class="UnderlineNav-item selected">Item 1</a>
149+
<a href="#url" class="UnderlineNav-item">Item 2</a>
150+
<a href="#url" class="UnderlineNav-item">Item 3</a>
151+
<a href="#url" class="UnderlineNav-item">Item 4</a>
152+
</div>
153+
</nav>
154+
```
155+
156+
<!-- Update wording here -->
157+
`.Counters` and `.octicons` can be used with navigation items. Use `.UnderlineNav-octicon` to add color and hover styles.
158+
159+
```html title="UnderlineNav with Counter"
160+
<nav class="UnderlineNav" aria-label="Foo bar">
161+
<div class="UnderlineNav-body">
162+
<a href="#url" class="UnderlineNav-item selected">
163+
<%= octicon "tools", :class => "UnderlineNav-octicon" %>
164+
Item 1
165+
</a>
166+
<a href="#url" class="UnderlineNav-item">
167+
<%= octicon "tools", :class => "UnderlineNav-octicon" %>
168+
Item 2
169+
<span class="Counter">10</span>
170+
</a>
171+
<a href="#url" class="UnderlineNav-item">
172+
<%= octicon "tools", :class => "UnderlineNav-octicon" %>
173+
Item 3
174+
</a>
175+
<a href="#url" class="UnderlineNav-item">
176+
<%= octicon "tools", :class => "UnderlineNav-octicon" %>
177+
Item 4
178+
</a>
179+
</div>
180+
</nav>
181+
```
182+
183+
Use `.UnderlineNav--full` in combination with container styles and `.UnderlineNav-container` to make navigation fill the width of the container.
184+
185+
```html title="UnderlineNav--full"
186+
<nav class="UnderlineNav UnderlineNav--full" aria-label="Foo bar">
187+
<div class="container-lg UnderlineNav-container">
188+
<div class="UnderlineNav-body">
189+
<a href="#url" class="UnderlineNav-item selected">Item 1</a>
190+
<a href="#url" class="UnderlineNav-item">Item 2
191+
<span class="Counter">10</span>
192+
</a>
193+
<a href="#url" class="UnderlineNav-item">Item 3</a>
194+
<a href="#url" class="UnderlineNav-item">Item 4</a>
195+
</div>
196+
<div class="UnderlineNav-actions">
197+
<a class="btn">Button</a>
198+
</div>
199+
</div>
200+
</nav>
201+
```
96202

97203
## Tabnav
98204

99205
When you need to toggle between different views, consider using a tabnav. It'll given you a left-aligned horizontal row of... tabs!
100206

101-
```html
207+
```html title="tabnav"
102208
<div class="tabnav">
103209
<nav class="tabnav-tabs" aria-label="Foo bar">
104210
<a href="#url" class="tabnav-tab selected" aria-current="page">Foo tab</a>
@@ -109,7 +215,7 @@ When you need to toggle between different views, consider using a tabnav. It'll
109215

110216
Use `.float-right` to align additional elements in the `.tabnav`:
111217

112-
```html
218+
```html title="tabnav with buttons"
113219
<div class="tabnav">
114220
<a class="btn btn-sm float-right" href="#url" role="button">Button</a>
115221
<nav class="tabnav-tabs" aria-label="Foo bar">
@@ -121,7 +227,7 @@ Use `.float-right` to align additional elements in the `.tabnav`:
121227

122228
Additional bits of text and links can be styled for optimal placement with `.tabnav-extra`:
123229

124-
```html
230+
```html title="tabnav-extra"
125231
<div class="tabnav">
126232
<div class="tabnav-extra float-right">
127233
Tabnav widget text here.
@@ -133,7 +239,7 @@ Additional bits of text and links can be styled for optimal placement with `.tab
133239
</div>
134240
```
135241

136-
```html
242+
```html title="tabnav with everything"
137243
<div class="tabnav">
138244
<div class="float-right">
139245
<a class="tabnav-extra" href="#url">
@@ -154,7 +260,7 @@ Additional bits of text and links can be styled for optimal placement with `.tab
154260

155261
A vertical list of filters. Grey text on white background. Selecting a filter from the list will fill its background with blue and make the text white.
156262

157-
```html
263+
```html title="filter-list"
158264
<ul class="filter-list">
159265
<li>
160266
<a href="#url" class="filter-item selected" aria-current="page">
@@ -180,7 +286,7 @@ A vertical list of filters. Grey text on white background. Selecting a filter fr
180286

181287
`.subnav` is navigation that is typically used when on a dashboard type interface with another set of navigation above it. This helps distinguish navigation hierarchy.
182288

183-
```html
289+
```html title="subnav"
184290
<nav class="subnav" aria-label="Respository">
185291
<a href="#url" class="subnav-item selected" aria-current="page">Item 1</a>
186292
<a href="#url" class="subnav-item">Item 2</a>
@@ -190,7 +296,7 @@ A vertical list of filters. Grey text on white background. Selecting a filter fr
190296

191297
You can have `subnav-search` in the subnav bar.
192298

193-
```html
299+
```html title="subnav-search"
194300
<div class="subnav">
195301
<nav class="subnav-links" aria-label="Repository">
196302
<a href="#url" class="subnav-item selected" aria-current="page">Item 1</a>
@@ -207,7 +313,7 @@ You can have `subnav-search` in the subnav bar.
207313

208314
You can also use a `subnav-search-context` to display search help in a select menu.
209315

210-
```html
316+
```html title="subnav-search-context"
211317
<div class="subnav">
212318
<nav class="subnav-links">
213319
<a href="#url" class="subnav-item selected">Item 1</a>
@@ -244,6 +350,8 @@ You can also use a `subnav-search-context` to display search help in a select me
244350
</div>
245351
</div>
246352
```
353+
354+
247355
<!-- %enddocs -->
248356

249357
## License

modules/primer-navigation/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
@import "./lib/tabnav.scss";
55
@import "./lib/filter-list.scss";
66
@import "./lib/subnav.scss";
7+
@import "./lib/underline-nav.scss";
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.UnderlineNav {
2+
display: flex;
3+
justify-content: space-between;
4+
border-bottom: 1px solid $gray-200;
5+
}
6+
7+
.UnderlineNav-body {
8+
display: flex;
9+
margin-bottom: -1px;
10+
}
11+
12+
.UnderlineNav-item {
13+
padding: $spacer-3 $spacer-2;
14+
margin-right: $spacer-3;
15+
font-size: $body-font-size;
16+
line-height: $lh-default;
17+
color: $text-gray;
18+
text-align: center;
19+
border-bottom: 2px solid transparent;
20+
21+
&:hover,
22+
&:focus {
23+
color: $text-gray-dark;
24+
text-decoration: none;
25+
border-bottom-color: $gray-300;
26+
transition: 0.2s ease;
27+
28+
.UnderlineNav-octicon {
29+
color: $gray-500;
30+
}
31+
}
32+
33+
&.selected {
34+
font-weight: $font-weight-bold;
35+
color: $text-gray-dark;
36+
border-bottom-color: $orange-600;
37+
38+
.UnderlineNav-octicon {
39+
color: $gray-500;
40+
}
41+
}
42+
}
43+
44+
.UnderlineNav--right {
45+
justify-content: flex-end;
46+
47+
.UnderlineNav-item {
48+
margin-right: 0;
49+
margin-left: $spacer-3;
50+
}
51+
52+
.UnderlineNav-actions {
53+
flex: 1 1 auto;
54+
}
55+
}
56+
57+
.UnderlineNav-actions {
58+
align-self: center;
59+
}
60+
61+
.UnderlineNav--full {
62+
display: block;
63+
}
64+
65+
.UnderlineNav-octicon {
66+
color: $gray-400;
67+
}
68+
69+
.UnderlineNav-container {
70+
display: flex;
71+
justify-content: space-between;
72+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
import storiesFromMarkdown from '../../.storybook/lib/storiesFromMarkdown'
4+
5+
const stories = storiesOf('Navigation', module)
6+
7+
storiesFromMarkdown(require.context('.', true, /\.md$/))
8+
.forEach(({title, story}) => {
9+
stories.add(title, story)
10+
})

0 commit comments

Comments
 (0)