feat: embedded emoji
This commit is contained in:
parent
c40609c8ac
commit
319ae5a0ba
10 changed files with 93 additions and 14 deletions
29
src/components/Emoji/index.tsx
Normal file
29
src/components/Emoji/index.tsx
Normal 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)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue