-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add share and subscribe buttons to header
- Loading branch information
Showing
5 changed files
with
147 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<header webc:root="override"> | ||
<nav> | ||
<h2 class="visually-hidden">Top level navigation menu</h2> | ||
<ul> | ||
<li><a href="/">limulus.net</a></li> | ||
<script webc:type="js"> | ||
let path = '/' | ||
page.url | ||
.split('/') | ||
.filter((dir) => dir !== '') | ||
.map((dir) => { | ||
path = `${path}${dir}/` | ||
return `<li><a href="${path}">${dir}</a></li>\n` | ||
}) | ||
.join('') | ||
</script> | ||
</ul> | ||
</nav> | ||
|
||
<section class="engagement"> | ||
<h2 class="visually-hidden">Please Engage</h2> | ||
<ul> | ||
<li> | ||
<share-button> | ||
<pill-button @icon="arrow-up-from-bracket-solid" :href="page.url" | ||
>Share</pill-button | ||
> | ||
</share-button> | ||
</li> | ||
<li><pill-button @icon="bell-solid" href="/feed.xml">Subscribe</pill-button></li> | ||
</ul> | ||
</section> | ||
</header> | ||
|
||
<style webc:scoped> | ||
:host { | ||
display: flex; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 1rem; | ||
margin: 2rem 0; | ||
font-size: 1.2rem; | ||
--var-font-wght: 700; | ||
font-synthesis: none; | ||
} | ||
|
||
:host ul { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
:host nav ul { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
|
||
:host li { | ||
display: block; | ||
text-wrap: nowrap; | ||
white-space: nowrap; | ||
} | ||
|
||
:host nav, | ||
:host section { | ||
display: flex; | ||
} | ||
|
||
:host nav li::after { | ||
content: '/'; | ||
margin: 0 0.5em; | ||
} | ||
|
||
:host section.engagement { | ||
margin-left: auto; | ||
} | ||
|
||
:host section.engagement li + li { | ||
margin-left: 0.5em; | ||
} | ||
|
||
:host section.engagement ul { | ||
display: flex; | ||
flex-wrap: nowrap; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<a :href="href" @attributes> | ||
<script webc:if="icon" webc:type="js"> | ||
this.svg(icon) | ||
</script> | ||
|
||
<span class="visually-hidden"> | ||
<slot></slot> | ||
</span> | ||
</a> | ||
|
||
<style webc:scoped> | ||
:host a { | ||
display: flex; | ||
border: none; | ||
align-items: center; | ||
justify-content: center; | ||
width: 1.5em; | ||
height: 1.5em; | ||
border-radius: 1.5em; | ||
background-color: var(--color); | ||
fill: var(--background-color); | ||
cursor: pointer; | ||
overflow: hidden; | ||
} | ||
|
||
:host svg { | ||
display: block; | ||
width: 50%; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import '../share-button/index.js' | ||
|
||
if (window.location.hostname.endsWith('limulus.net')) { | ||
import('../rum/index.js') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
export class ShareButton extends HTMLElement { | ||
connectedCallback() { | ||
this.addEventListener('click', this.#onClick) | ||
} | ||
|
||
async #onClick(e: Event) { | ||
e.preventDefault() | ||
if (navigator.share) { | ||
const title = | ||
document.querySelector('meta[property="og:title"]')?.getAttribute('content') ?? '' | ||
await navigator.share({ | ||
title, | ||
url: location.href, | ||
}) | ||
} | ||
} | ||
|
||
// TODO: Fallback to copying the URL to the clipboard | ||
} | ||
|
||
if (!customElements.get('share-button')) { | ||
customElements.define('share-button', ShareButton) | ||
} |