From 6574157c66a80332802efd138e9127d663c34e9b Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 29 Aug 2024 13:00:43 -0500 Subject: [PATCH] Handle emoji-only --- bskyogcard/src/components/RichText.tsx | 39 +++++++++++--------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/bskyogcard/src/components/RichText.tsx b/bskyogcard/src/components/RichText.tsx index cc445d5d31..2225f4ffa1 100644 --- a/bskyogcard/src/components/RichText.tsx +++ b/bskyogcard/src/components/RichText.tsx @@ -8,41 +8,27 @@ import {Text} from './Text.js' export function RichText({ value, disableLinks, - cx, + cx = [], }: { value: RichTextApi disableLinks?: boolean cx?: Record[] }) { - const {facets} = value - const baseStyles = [ - a.leading_snug, - { - // whiteSpace: 'wrap', - }, - cx ? s(cx) : {}, - ] + const {text, facets} = value + const baseStyles = [a.leading_snug, ...cx] const linkStyles = [ { color: t.palette.primary_500, }, ] + const fontSize: number = s(baseStyles).fontSize || a.text_sm.fontSize if (!facets?.length) { - // if (isOnlyEmoji(text)) { - // const fontSize = - // (flattenedStyle.fontSize ?? a.text_sm.fontSize) * emojiMultiplier - // return ( - // - // {text} - // - // ) - // } + if (isOnlyEmoji(text)) { + return ( + {text} + ) + } } const els = [] @@ -89,3 +75,10 @@ export function RichText({ return {els} } + +export function isOnlyEmoji(text: string) { + return ( + text.length <= 15 && + /^[\p{Emoji_Presentation}\p{Extended_Pictographic}]+$/u.test(text) + ) +}