Skip to content

Commit 68302cd

Browse files
Tabbed Navigation component (#1054)
* creating custom tab navigation * adding active class when tab is clicked * linting --------- Co-authored-by: Hector Correa <[email protected]>
1 parent d648d17 commit 68302cd

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

app/assets/stylesheets/_settings.scss

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
margin-top: 0.5em;
6161
}
6262
}
63-
63+
// TODO
64+
// Turn the tab nav css into a mixin component
6465
#welcome {
6566
.emulation {
6667
display: inline-flex;
@@ -74,7 +75,30 @@
7475
margin-top: 11px;
7576
margin-left: 22em;
7677
}
78+
.tab-nav {
79+
padding: 0;
80+
border: none;
81+
background: none;
82+
83+
display: inline-flex;
84+
flex-direction: column;
85+
align-items: center;
86+
87+
// Typography
88+
color: var(--Neutral-Black, #121212);
89+
/* Body S Bold */
90+
font-family: "Libre Franklin";
91+
font-size: 16px;
92+
font-style: normal;
93+
font-weight: 600;
94+
line-height: 24px; /* 150% */
95+
96+
// states
97+
button:active {
98+
color: var(--Primary-Blue, #0d6efd);
99+
}
77100

101+
}
78102
#emulation_bar {
79103
margin-left: 5px;
80104
}

app/javascript/entrypoints/application.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,39 @@ function showValidationError() {
240240
});
241241
}
242242

243+
function tabNav() {
244+
$('#tab-nav').on('mouseenter', (el) => {
245+
const element = el;
246+
element.preventDefault();
247+
const tab = document.getElementById('tab-nav');
248+
249+
if (!tab.classList.contains('active')) {
250+
tab.style.borderBottom = 'solid';
251+
tab.style.borderColor = '#121212';
252+
}
253+
});
254+
255+
$('#tab-nav').on('mouseleave', (el) => {
256+
const element = el;
257+
element.preventDefault();
258+
const tab = document.getElementById('tab-nav');
259+
260+
if (!tab.classList.contains('active')) {
261+
tab.style.border = 'none';
262+
}
263+
});
264+
265+
$('#tab-nav').on('click', (el) => {
266+
const element = el;
267+
element.preventDefault();
268+
const tab = document.getElementById('tab-nav');
269+
// change background color to red
270+
tab.style.borderBottom = 'solid';
271+
tab.style.borderColor = '#E77500';
272+
tab.classList.add('active');
273+
});
274+
}
275+
243276
function initPage() {
244277
$('#test-jquery').click((event) => {
245278
setTargetHtml(event, 'jQuery works!');
@@ -250,6 +283,7 @@ function initPage() {
250283
showMoreLessSysAdmin();
251284
emulate();
252285
showValidationError();
286+
tabNav();
253287
}
254288

255289
window.addEventListener('load', () => initPage());

app/views/welcome/styles_preview.html.erb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
<h1>Styles Preview</h1>
1+
<div id="welcome">
2+
<button id="tab-nav" class="tab-nav"> Activity</button>
3+
</div>
24

5+
6+
<h1>Styles Preview</h1>
37
<p>This page shows the styles that have been implemented for this site's look and feel.</p>
48

59
<h1>Heading Level 1</h1>
@@ -38,14 +42,3 @@
3842
<div class="status-warning">Status Warning</div>
3943
<div class="status-info">Status Info</div>
4044
</div>
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-

0 commit comments

Comments
 (0)