forked from w3f/polkadot-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageBox.jsx
32 lines (27 loc) · 816 Bytes
/
MessageBox.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React, { useState } from 'react';
const MessageBox = ({ message }) => {
const [isOpen, setIsOpen] = useState(true);
const handleClose = () => {
setIsOpen(false);
};
// Function to convert markdown links to HTML links
const renderMarkdownLinks = (text) => {
return text.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2">$1</a>');
};
return (
<>
{isOpen && (
<div className="message-box">
<button className="close-button" onClick={handleClose}>
✖ {/* Unicode character for "x" */}
</button>
<div
className="message-content"
dangerouslySetInnerHTML={{ __html: renderMarkdownLinks(message) }} // Render HTML content
></div>
</div>
)}
</>
);
};
export default MessageBox;