feat: embedded emoji

This commit is contained in:
codytseng 2025-04-17 17:09:22 +08:00
parent c40609c8ac
commit 319ae5a0ba
10 changed files with 93 additions and 14 deletions

View file

@ -0,0 +1,29 @@
import { cn } from '@/lib/utils'
import { TEmoji } from '@/types'
import { HTMLAttributes, useState } from 'react'
export default function Emoji({
emoji,
className = ''
}: HTMLAttributes<HTMLDivElement> & {
className?: string
emoji: TEmoji
}) {
const [hasError, setHasError] = useState(false)
if (hasError) return `:${emoji.shortcode}:`
return (
<img
src={emoji.url}
alt={emoji.shortcode}
className={cn('inline-block size-4', className)}
onLoad={() => {
setHasError(false)
}}
onError={() => {
setHasError(true)
}}
/>
)
}