From f5f02aa4b36ba85c0287324e1654bccaf19cfd5f Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 5 Mar 2025 17:50:20 +0000 Subject: Add dark mode option to in-app embed snippet dialog (#7377) * add color theme selection * change chevron direction * change chevron direction again * rm unused ref --- src/components/dialogs/Embed.tsx | 184 ++++++++++++++++++++++++++------------- 1 file changed, 125 insertions(+), 59 deletions(-) (limited to 'src/components/dialogs/Embed.tsx') diff --git a/src/components/dialogs/Embed.tsx b/src/components/dialogs/Embed.tsx index ca75b0139..23d050488 100644 --- a/src/components/dialogs/Embed.tsx +++ b/src/components/dialogs/Embed.tsx @@ -1,5 +1,5 @@ -import React, {memo, useRef, useState} from 'react' -import {TextInput, View} from 'react-native' +import {memo, useEffect, useMemo, useState} from 'react' +import {View} from 'react-native' import {AppBskyActorDefs, AppBskyFeedPost, AtUri} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' @@ -8,12 +8,19 @@ import {EMBED_SCRIPT} from '#/lib/constants' import {niceDate} from '#/lib/strings/time' import {toShareUrl} from '#/lib/strings/url-helpers' import {atoms as a, useTheme} from '#/alf' +import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import * as TextField from '#/components/forms/TextField' -import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check' -import {CodeBrackets_Stroke2_Corner0_Rounded as CodeBrackets} from '#/components/icons/CodeBrackets' +import * as ToggleButton from '#/components/forms/ToggleButton' +import {Check_Stroke2_Corner0_Rounded as CheckIcon} from '#/components/icons/Check' +import { + ChevronBottom_Stroke2_Corner0_Rounded as ChevronBottomIcon, + ChevronRight_Stroke2_Corner0_Rounded as ChevronRightIcon, +} from '#/components/icons/Chevron' +import {CodeBrackets_Stroke2_Corner0_Rounded as CodeBracketsIcon} from '#/components/icons/CodeBrackets' import {Text} from '#/components/Typography' -import {Button, ButtonIcon, ButtonText} from '../Button' + +export type ColorModeValues = 'system' | 'light' | 'dark' type EmbedDialogProps = { control: Dialog.DialogControlProps @@ -44,11 +51,12 @@ function EmbedDialogInner({ }: Omit) { const t = useTheme() const {_, i18n} = useLingui() - const ref = useRef(null) const [copied, setCopied] = useState(false) + const [showCustomisation, setShowCustomisation] = useState(false) + const [colorMode, setColorMode] = useState('system') // reset copied state after 2 seconds - React.useEffect(() => { + useEffect(() => { if (copied) { const timeout = setTimeout(() => { setCopied(false) @@ -57,7 +65,7 @@ function EmbedDialogInner({ } }, [copied]) - const snippet = React.useMemo(() => { + const snippet = useMemo(() => { function toEmbedUrl(href: string) { return toShareUrl(href) + '?ref_src=embed' } @@ -75,9 +83,11 @@ function EmbedDialogInner({ // x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x return `

${escapeHtml(record.text)}${ + )}" data-bluesky-cid="${escapeHtml( + postCid, + )}" data-bluesky-embed-color-mode="${escapeHtml( + colorMode, + )}">

${escapeHtml(record.text)}${ record.embed ? `

[image or embed]` : '' @@ -88,60 +98,116 @@ function EmbedDialogInner({ )}) ${escapeHtml( niceDate(i18n, timestamp), )}

` - }, [i18n, postUri, postCid, record, timestamp, postAuthor]) + }, [i18n, postUri, postCid, record, timestamp, postAuthor, colorMode]) return ( - - - - Embed post - - - - Embed this post in your website. Simply copy the following snippet - and paste it into the HTML code of your website. - - - - - - - - - - + + + + + Embed post + + + + Embed this post in your website. Simply copy the following snippet + and paste it into the HTML code of your website. + + - + + {showCustomisation && ( + + + Color theme + + setColorMode(value as ColorModeValues)}> + + + System + + + + + Light + + + + + Dark + + + + )} - + + + + + + + + + + -- cgit 1.4.1