Skip to content

Commit

Permalink
feat: add share and subscribe buttons to header
Browse files Browse the repository at this point in the history
  • Loading branch information
limulus authored Nov 20, 2024
1 parent d77179f commit d26fffd
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 31 deletions.
86 changes: 86 additions & 0 deletions www/_includes/components/ldn-header.webc
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>
30 changes: 30 additions & 0 deletions www/_includes/components/pill-button.webc
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>
37 changes: 6 additions & 31 deletions www/_includes/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ header nav {
}

:root {
--background-color: #f3f3f3;
--body-padding: 2rem;
--body-max-width: 55rem;
--card-background-color: #f6f6f6;
Expand All @@ -72,12 +73,13 @@ header nav {
--card-box-shadow: 0 0 0.2rem var(--card-box-shadow-color);
--card-box-shadow-color: rgba(0, 0, 0, 0.2);
--card-padding: 0.75rem 1rem;
--color: #333;
--hairline-pixels: 1px;
}

html {
background-color: #f3f3f3;
color: #333;
background-color: var(--background-color);
color: var(--color);
font-size: 18px;
line-height: 1.6;
overflow-y: scroll;
Expand Down Expand Up @@ -116,30 +118,6 @@ h1:first-of-type {
margin-top: 0;
}

body > header {
/* padding: 0 0 1rem 0; */
font-size: 1rem;
--var-font-wght: 700;
font-synthesis: none;
}

body > header nav {
display: flex;
}
body > header nav li {
display: inline-block;
text-wrap: nowrap;
}
body > header nav li::after {
content: '/';
margin: 0 0.5em;
}
body > header nav ul {
display: flex;
flex-wrap: wrap;
padding: 0;
}

code {
font-family: 'Monaspace Neon', monospace;
/**
Expand Down Expand Up @@ -188,14 +166,11 @@ sphere-shadow::part(hud-value) {

@media (prefers-color-scheme: dark) {
:root {
--background-color: rgb(13, 17, 23);
--card-background-color: #20212c;
--card-border-color: #444;
--card-box-shadow-color: rgba(0, 0, 0, 0.7);
}

html {
background-color: rgb(13, 17, 23);
color: rgb(201, 209, 217);
--color: rgb(201, 209, 217);
}

a {
Expand Down
2 changes: 2 additions & 0 deletions www/lib/common/index.ts
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')
}
23 changes: 23 additions & 0 deletions www/lib/share-button/index.ts
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)
}

0 comments on commit d26fffd

Please sign in to comment.