Skip to content

Commit a17ecc9

Browse files
authored
Merge pull request #51 from kodingwarrior/codex/implement-responsive-navigation-bar
Make navbar responsive with icon-based active tabs
2 parents 95d761b + fe62331 commit a17ecc9

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

frontend/styles/index.css

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,59 @@ body > header img {
9393
max-width: 100%;
9494
}
9595

96-
body > nav ul {
96+
.primary-nav {
9797
margin: 2rem 0;
98+
}
99+
100+
.primary-nav ul {
101+
margin: 0;
98102
padding: 0;
99103
list-style-type: none;
100104
display: flex;
105+
flex-wrap: wrap;
101106
justify-content: center;
102-
gap: 1.5rem;
103-
font-size: 1.3rem;
104-
font-weight: bold;
107+
gap: 0.75rem;
108+
font-size: 1.25rem;
109+
font-weight: 600;
105110
}
106111

107-
body > nav a {
112+
.primary-nav li {
113+
display: flex;
114+
}
115+
116+
.primary-nav a {
117+
display: inline-flex;
118+
align-items: center;
119+
gap: 0.5rem;
120+
padding: 0.6rem 0.9rem;
121+
border-radius: 9999px;
108122
text-decoration: none;
123+
color: inherit;
124+
transition: background-color 0.2s ease, color 0.2s ease;
125+
}
126+
127+
.primary-nav a:hover,
128+
.primary-nav a:focus {
129+
background-color: rgba(214, 64, 69, 0.12);
130+
outline: none;
131+
}
132+
133+
.primary-nav i {
134+
font-size: 1.35rem;
135+
}
136+
137+
.primary-nav .nav-label {
138+
display: none;
139+
}
140+
141+
.primary-nav li.is-active a {
142+
background-color: var(--action-color);
143+
color: #fff;
144+
box-shadow: 0 0.25rem 0.5rem rgba(214, 64, 69, 0.25);
145+
}
146+
147+
.primary-nav li.is-active .nav-label {
148+
display: inline;
109149
}
110150

111151
main {

src/_partials/_navbar.erb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1-
2-
<nav>
1+
<nav class="primary-nav">
2+
<% current_path = resource.respond_to?(:relative_url) ? resource.relative_url : resource.relative_permalink %>
3+
<% current_path = current_path.sub(%r{/+$}, '') if current_path %>
4+
<% current_path = '/' if current_path.nil? || current_path.empty? %>
5+
<% nav_items = [
6+
{ path: '/', label: 'Home', icon: 'bi-house' },
7+
{ path: '/about/', label: 'About', icon: 'bi-person' },
8+
{ path: '/posts/', label: 'Posts', icon: 'bi-pencil-square' },
9+
{ path: '/wiki/', label: 'Wiki', icon: 'bi-book' },
10+
{ path: "/hackerspub/", label: "Hackers' Pub", icon: 'bi-globe2' }
11+
] %>
312
<ul>
4-
<li><a href="/">/home</a></li>
5-
<li><a href="/about">/about</a></li>
6-
<li><a href="/posts">/posts</a></li>
7-
<li><a href="/wiki">/wiki</a></li>
8-
<li><a href="/hackerspub">/hackerspub</a></li>
13+
<% nav_items.each do |item| %>
14+
<% item_path = item[:path].sub(%r{/+$}, '') %>
15+
<% item_path = '/' if item_path.empty? %>
16+
<% active = current_path == item_path %>
17+
<li class="<%= 'is-active' if active %>">
18+
<a href="<%= item[:path] %>" aria-label="<%= item[:label] %>" <%= 'aria-current="page"' if active %>>
19+
<i class="bi <%= item[:icon] %>" aria-hidden="true"></i>
20+
<span class="nav-label"><%= item[:label] %></span>
21+
</a>
22+
</li>
23+
<% end %>
924
</ul>
1025
</nav>

0 commit comments

Comments
 (0)