mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-24 07:28:11 +02:00
Add a component to display emojis correctly in previews
Create a new React component that parses and renders text with emojis as Twemoji images, ensuring consistency between preview and final output. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: e41fe0af-9a57-474c-998a-d509286b7711 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/JcM96XE
This commit is contained in:
1 parent
e596fa298d
commit
86ac089fb2
1 file changed
+42
@@ -0,0 +1,42 @@
|
|||||||
|
import { useMemo } from 'react';
|
||||||
|
import { parseTextWithEmojis } from '@/lib/emojiUtils';
|
||||||
|
|
||||||
|
interface EmojiTextProps {
|
||||||
|
text: string;
|
||||||
|
className?: string;
|
||||||
|
emojiSize?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component that renders text with emojis as Twemoji images
|
||||||
|
* Matches the backend Twemoji rendering for consistent preview
|
||||||
|
*/
|
||||||
|
export function EmojiText({ text, className = '', emojiSize = 20 }: EmojiTextProps) {
|
||||||
|
const segments = useMemo(() => parseTextWithEmojis(text), [text]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span className={className}>
|
||||||
|
{segments.map((segment, idx) => {
|
||||||
|
if (segment.type === 'text') {
|
||||||
|
return <span key={idx}>{segment.content}</span>;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
key={idx}
|
||||||
|
src={segment.url}
|
||||||
|
alt={segment.content}
|
||||||
|
className="inline-block align-middle"
|
||||||
|
style={{
|
||||||
|
width: `${emojiSize}px`,
|
||||||
|
height: `${emojiSize}px`,
|
||||||
|
marginLeft: '2px',
|
||||||
|
marginRight: '2px'
|
||||||
|
}}
|
||||||
|
draggable={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user