Skip to content

Commit

Permalink
Sync hover of logo and em link hovers with CSS only (#157)
Browse files Browse the repository at this point in the history
* ♻️ Reuse same logic for listeners

* Sync hover of logo and em link hovers without js

* Correct type for `a` tag

* Rename `.is-em` to BEM variant

* Use `.is-em` again with class combination
  • Loading branch information
baileys-li authored Aug 8, 2024
1 parent 09508ec commit 4386766
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 43 deletions.
23 changes: 9 additions & 14 deletions view/main/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,17 @@ body {
color: inherit;
text-decoration: none;

&:hover,
&.is-hover {
color: var(--accent);
text-decoration: underline;
}

&:focus {
text-decoration: none;
border-radius: 2px;
outline-offset: 2px;
}
}

.main_logo-path {
fill: var(--surface-ui-regular);
.main:has(.main_logo:hover) .main_link.is-em,
.main_link:hover {
color: var(--accent);
text-decoration: underline;
}

.main_logo-icon {
Expand All @@ -109,14 +105,13 @@ body {
width: 96px;
height: 38px;
padding-top: 10px;
color: var(--surface-ui-regular);
transform: translateX(-50%);
}

&:hover,
&.is-hover {
.main_logo-path {
fill: var(--accent);
}
}
.main:has(.main_link.is-em:is(:hover, :focus)) .main_logo,
.main_logo:hover {
color: var(--accent);
}

.main_logo::before,
Expand Down
29 changes: 1 addition & 28 deletions view/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { trackEvent } from '../analytics/index.js'

let expand = document.querySelector<HTMLButtonElement>('.main_expand')!

let emText = document.querySelector<HTMLLinkElement>('.main_link.is-em')!
let emLogo = document.querySelector<HTMLLinkElement>('.main_logo')!

let links = document.querySelectorAll<HTMLLinkElement>('.main a')
let links = document.querySelectorAll<HTMLAnchorElement>('.main a')

function onScroll(): void {
document.body.classList.add('is-main-collapsed')
Expand All @@ -29,30 +26,6 @@ expand.addEventListener('click', () => {
document.body.classList.toggle('is-main-collapsed')
})

emText.addEventListener('mouseenter', () => {
emLogo.classList.add('is-hover')
})

emText.addEventListener('mouseleave', () => {
emLogo.classList.remove('is-hover')
})

emText.addEventListener('focus', () => {
emLogo.classList.add('is-hover')
})

emText.addEventListener('blur', () => {
emLogo.classList.remove('is-hover')
})

emLogo.addEventListener('mouseenter', () => {
emText.classList.add('is-hover')
})

emLogo.addEventListener('mouseleave', () => {
emText.classList.remove('is-hover')
})

for (let link of links) {
let event = 'Open Evil Martians'
if (link.href.includes('sitnik')) event = 'Open Sitnik page'
Expand Down
2 changes: 1 addition & 1 deletion view/main/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4386766

Please sign in to comment.