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

adding top and middle nav #41

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions blocks/header/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,83 @@ header .lang-picker > a::after {
vertical-align: bottom;
}

/* stylelint-disable-next-line no-descending-specificity */
header .website-picker > a::after {

Choose a reason for hiding this comment

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

The styles look very similar to lang picker. Can we just reuse the same styles? The name can be generalised.

content: "";
height: 1rem;
width: 0.75rem;
margin-left: 0.25rem;
display: inline-flex;
background-image: url("../../icons/arrow-down.svg");
background-size: contain;
background-position: center;
background-repeat: no-repeat;
border: none;
vertical-align: bottom;
}

/* stylelint-disable-next-line no-descending-specificity */
header .website-picker > ul {
display: none;
color: var(--link-color);
position: absolute;
margin: 0;
background: var(--secondary);
border-radius: 0;
padding: 0;
width: calc(100% - 3rem);
box-shadow: 0 2px 8px 0 var(--transparent-grey-color);
right: 0;
left: auto;
top: var(--nav-top-height);
z-index: 100;
font-size: 1rem;
text-align: left;
list-style: none;
border: 1px solid #00000026;
float: left;
min-width: 12.5rem;
}

header .website-picker:hover > ul {
display: block;
}

/* stylelint-disable-next-line no-descending-specificity */
header .website-picker-item > a {
font-size: var(--body-font-size-s);
font-weight: var(--font-weight-medium);
color: var(--white);
padding: 11px 0 11px 32px;

Choose a reason for hiding this comment

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

Nit: Please prefer rem units.

display: block;
}

/* stylelint-disable-next-line no-descending-specificity */
header .website-picker-item > a:hover {
background: var(--primary);
}

/* stylelint-disable-next-line no-descending-specificity */
header .website-picker-item > a::after {
content: "";
display: inline-block;
height: 18px;
width: 18px;
margin-left: 2px;
margin-top: 0;
position: relative;
top: 4px;
background-image: url("../../icons/link-white.svg");
background-repeat: no-repeat;
background-position: center;
background-size: contain
}

header .website-picker {
position: relative;
padding: 1rem 0;
}

/* stylelint-disable-next-line no-descending-specificity */
header .lang-picker > ul {
display: none;
Expand Down Expand Up @@ -556,6 +633,7 @@ header .nav-bottom .other-items .mobile-lang-picker .mobile-lang-picker-item a {
header .lang-picker {
position: relative;
padding: 1rem 0;
padding-left: 34px;
}

@media (min-width: 77rem) {
Expand Down
41 changes: 19 additions & 22 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import
decorateAnchors,
} from '../../scripts/scripts.js';

function decorateSocial(social) {
social.classList.add('social');
social.innerHTML = social.innerHTML.replace(/\[social\]/, '');
social.querySelectorAll(':scope>ul>li').forEach((li) => {
const a = li.querySelector('a');
a.setAttribute('target', '_blank');
if (a.innerHTML.includes('linkedin')) {
a.setAttribute('aria-label', 'LinkedIn');
} else if (a.innerHTML.includes('twitter')) {
a.setAttribute('aria-label', 'Twitter');
} else if (a.innerHTML.includes('facebook')) {
a.setAttribute('aria-label', 'Facebook');
} else if (a.innerHTML.includes('youtube')) {
a.setAttribute('aria-label', 'YouTube');
}
async function decorateWebsitePicker(websitePicker) {
websitePicker.classList.add('website-picker');
websitePicker.innerHTML = websitePicker.innerHTML.replace(/\[websites\]/, '');
const title = 'Sunstar Websites';
websitePicker.querySelectorAll(':scope>ul>li').forEach((li) => {
li.classList.add('website-picker-item');
});

const a = document.createElement('a');
hparwani2 marked this conversation as resolved.
Show resolved Hide resolved
a.setAttribute('href', '#');
a.textContent = title;
websitePicker.prepend(a);

if (websitePicker.querySelectorAll(':scope>ul>li').length === 0 && websitePicker.querySelector('ul')) {
websitePicker.querySelector('ul').remove();
}
}

async function decorateLangPicker(langPicker) {
Expand Down Expand Up @@ -177,10 +177,10 @@ function buildDropDownMenu(l1menuItem, placeholders) {

function decorateTopNav(nav) {
nav.querySelectorAll(':scope>ul>li').forEach((li) => {
if (li.textContent.trim() === '[social]') {
decorateSocial(li);
} else if (li.textContent.includes('[languages]')) {
if (li.textContent.includes('[languages]')) {
decorateLangPicker(li);
} else if (li.textContent.includes('[websites]')) {
decorateWebsitePicker(li);
}
});
}
Expand Down Expand Up @@ -212,9 +212,6 @@ function decorateOtherItems(otherItemsEl) {
});

otherItemsEl.querySelector('.lang-picker').replaceWith(langPicker);

/* Move the social icons to the bottom */
otherItemsEl.appendChild(otherItemsEl.querySelector('.social'));
}

function decorateBottomNav(nav, placeholders) {
Expand Down Expand Up @@ -280,7 +277,7 @@ const navDecorators = { 'nav-top': decorateTopNav, 'nav-middle': decorateMiddleN
export default async function decorate(block) {
// fetch nav content
const navMeta = getMetadata('nav');
const navPath = navMeta || (getLanguage() === 'en' ? '/nav' : `/${getLanguage()}/nav`);
const navPath = navMeta || (getLanguage() === 'en' ? '/_drafts/himanshu/nav' : `/${getLanguage()}/nav`);

Choose a reason for hiding this comment

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

Change this before merging

const resp = await fetch(`${navPath}.plain.html`);

if (resp.ok) {
Expand Down