Files
scrm.antd/src/pages/ChatLogs/components/EmojiFormat.tsx

33 lines
761 B
TypeScript
Raw Normal View History

import { emoji } from '@/services/config';
import React from 'react';
type IProps = {
content: string;
};
export const EmojiFormat: React.FC<IProps> = (props) => {
const format = () => {
let txt = props.content;
if (txt.includes('[') && txt.includes(']')) {
emoji.forEach((item) => {
const reg = new RegExp(`\\[${item}\\]`, 'g');
txt = txt.replace(
reg,
`<img style="width: 24px;height:24px;vertical-align: bottom;" src="/api/assets/wechat/emoji/${item}.png" alt="" />`,
);
});
}
return txt;
};
return (
<>
{typeof props.content === 'string' ? (
2023-04-24 13:43:36 +08:00
<div dangerouslySetInnerHTML={{ __html: format() }} />
) : (
props.content
)}
</>
);
};