{error}
From de15f8e2d3264b9ffb18c3a089612ef604eb87b8 Mon Sep 17 00:00:00 2001 From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Thu, 12 Dec 2024 01:31:29 +0900 Subject: feat(embed): Add support for dark mode (#6912) * feat(embed): Support dark mode (wip) * finishing up the implementation * fix tailwind color selector * tweak design * refactor: unify types * fix * fix english grammar * refactor: unify types * tweak design * remove the customization part --- bskyembed/src/color-mode.ts | 17 +++++++++++++++++ bskyembed/src/components/container.tsx | 2 +- bskyembed/src/components/embed.tsx | 34 ++++++++++++++++++++-------------- bskyembed/src/components/post.tsx | 18 ++++++++++-------- bskyembed/src/index.css | 4 ++++ bskyembed/src/screens/landing.tsx | 31 ++++++++++++++++++------------- bskyembed/src/screens/post.tsx | 9 ++++++--- 7 files changed, 76 insertions(+), 39 deletions(-) create mode 100644 bskyembed/src/color-mode.ts (limited to 'bskyembed/src') diff --git a/bskyembed/src/color-mode.ts b/bskyembed/src/color-mode.ts new file mode 100644 index 000000000..2b392c617 --- /dev/null +++ b/bskyembed/src/color-mode.ts @@ -0,0 +1,17 @@ +export function applyTheme(theme: 'light' | 'dark') { + document.documentElement.classList.remove('light', 'dark') + document.documentElement.classList.add(theme) +} + +export function initColorMode() { + applyTheme( + window.matchMedia('(prefers-color-scheme: dark)').matches + ? 'dark' + : 'light', + ) + window + .matchMedia('(prefers-color-scheme: dark)') + .addEventListener('change', mql => { + applyTheme(mql.matches ? 'dark' : 'light') + }) +} diff --git a/bskyembed/src/components/container.tsx b/bskyembed/src/components/container.tsx index 5b1b2b7fb..8e142a25b 100644 --- a/bskyembed/src/components/container.tsx +++ b/bskyembed/src/components/container.tsx @@ -37,7 +37,7 @@ export function Container({ return (
{record.author.displayName} - + @{record.author.handle}
@@ -209,7 +209,7 @@ function Info({children}: {children: ComponentChildren}) { return ({children}
+{children}
+
{toNiceDomain(content.external.uri)}
{content.external.title}
-+
{content.external.description}
{title}
-{subtitle}
++ {subtitle} +
{description}
} + {description && ( ++ {description} +
+ )} ) } @@ -406,7 +412,7 @@ function StarterPackEmbed({ return ( + className="w-full rounded-lg overflow-hidden border dark:border-slate-600 flex flex-col items-stretch">{content.record.name}
-+
Starter pack by{' '} {content.creator.displayName || `@${content.creator.handle}`}
@@ -425,7 +431,7 @@ function StarterPackEmbed({{content.record.description}
)} {!!content.joinedAllTimeCount && content.joinedAllTimeCount > 50 && ( -+
{content.joinedAllTimeCount} users have joined!
)} diff --git a/bskyembed/src/components/post.tsx b/bskyembed/src/components/post.tsx index 4db5eeb45..26945eb69 100644 --- a/bskyembed/src/components/post.tsx +++ b/bskyembed/src/components/post.tsx @@ -38,7 +38,7 @@ export function Post({thread}: Props) {@{post.author.handle}
+
{prettyNumber(post.likeCount)}
+
{prettyNumber(post.repostCount)}
Reply
++ Reply +
+
{post.replyCount
? `Read ${prettyNumber(post.replyCount)} ${
post.replyCount > 1 ? 'replies' : 'reply'
diff --git a/bskyembed/src/index.css b/bskyembed/src/index.css
index 22b2b8be5..289e34cf0 100644
--- a/bskyembed/src/index.css
+++ b/bskyembed/src/index.css
@@ -5,3 +5,7 @@
.break-word {
word-break: break-word;
}
+
+:root {
+ color-scheme: light dark;
+}
diff --git a/bskyembed/src/screens/landing.tsx b/bskyembed/src/screens/landing.tsx
index a9e08cd3f..a3448e90a 100644
--- a/bskyembed/src/screens/landing.tsx
+++ b/bskyembed/src/screens/landing.tsx
@@ -6,6 +6,7 @@ import {useEffect, useMemo, useRef, useState} from 'preact/hooks'
import arrowBottom from '../../assets/arrowBottom_stroke2_corner0_rounded.svg'
import logo from '../../assets/logo.svg'
+import {initColorMode} from '../color-mode'
import {Container} from '../components/container'
import {Link} from '../components/link'
import {Post} from '../components/post'
@@ -21,6 +22,8 @@ export const EMBED_SCRIPT = `${EMBED_SERVICE}/static/embed.js`
const root = document.getElementById('app')
if (!root) throw new Error('No root element')
+initColorMode()
+
const agent = new BskyAgent({
service: 'https://public.api.bsky.app',
})
@@ -108,7 +111,7 @@ function LandingPage() {
}, [uri])
return (
- {error}
+
{loading ? (
-