1
1
import React , { useState } from 'react' ;
2
- import { ChakraProvider , Box , Textarea , Button , VStack , HStack , Avatar , Text , Link as ChakraLink , Heading , useColorMode , useColorModeValue } from '@chakra-ui/react' ;
3
- import ReactMarkdown from 'react-markdown' ;
4
- import MonacoEditor from '@monaco-editor/react' ; // Monaco Editor
2
+ import { ChakraProvider , Box , Textarea , Button , VStack , HStack , Avatar , Text , useColorModeValue } from '@chakra-ui/react' ;
3
+ import ChakraMarkdown from './chakra-markdown' ; // Import the renamed component
5
4
6
5
function ChatApp ( ) {
7
6
const [ messages , setMessages ] = useState ( [ ] ) ;
8
7
const [ input , setInput ] = useState ( "" ) ;
9
- const { colorMode, toggleColorMode } = useColorMode ( ) ; // Chakra color mode
10
8
11
9
const sendMessage = ( ) => {
12
10
if ( input . trim ( ) !== "" ) {
@@ -21,43 +19,6 @@ function ChatApp() {
21
19
}
22
20
} ;
23
21
24
- // Dynamic theme for Monaco Editor based on Chakra UI color mode
25
- const monacoTheme = colorMode === 'dark' ? 'vs-dark' : 'vs-light' ;
26
-
27
- // Custom renderers for Markdown components using Chakra UI and Monaco Editor for code blocks
28
- const renderers = {
29
- h1 : ( { children } ) => < Heading as = "h1" size = "xl" mb = { 2 } > { children } </ Heading > ,
30
- h2 : ( { children } ) => < Heading as = "h2" size = "lg" mb = { 2 } > { children } </ Heading > ,
31
- h3 : ( { children } ) => < Heading as = "h3" size = "md" mb = { 2 } > { children } </ Heading > ,
32
- a : ( { href, children } ) => (
33
- < ChakraLink href = { href } color = "blue.500" isExternal >
34
- { children }
35
- </ ChakraLink >
36
- ) ,
37
- code : ( { inline, children, className } ) => {
38
- const language = className ? className . replace ( 'language-' , '' ) : 'plaintext' ;
39
- if ( inline ) {
40
- return < Text as = "code" bg = { useColorModeValue ( "gray.100" , "gray.700" ) } p = "1" borderRadius = "md" > { children } </ Text > ;
41
- }
42
- return (
43
- < Box border = "1px solid" borderColor = { useColorModeValue ( "gray.200" , "gray.600" ) } borderRadius = "md" overflow = "hidden" my = { 2 } >
44
- < MonacoEditor
45
- height = "200px"
46
- language = { language }
47
- theme = { monacoTheme }
48
- value = { String ( children ) . trim ( ) }
49
- options = { {
50
- readOnly : true ,
51
- minimap : { enabled : false } ,
52
- scrollBeyondLastLine : false ,
53
- lineNumbers : "off" ,
54
- } }
55
- />
56
- </ Box >
57
- ) ;
58
- } ,
59
- } ;
60
-
61
22
return (
62
23
< ChakraProvider >
63
24
< Box bg = { useColorModeValue ( "gray.100" , "gray.900" ) } h = "100vh" p = { 4 } display = "flex" flexDirection = "column" >
@@ -79,7 +40,8 @@ function ChatApp() {
79
40
< Text fontSize = "sm" fontWeight = "bold" >
80
41
{ message . sender }
81
42
</ Text >
82
- < ReactMarkdown components = { renderers } children = { message . text } />
43
+ { /* Rendering the message text with markdown support */ }
44
+ < ChakraMarkdown content = { message . text } />
83
45
< Text fontSize = "xs" color = "gray.500" >
84
46
{ message . timestamp }
85
47
</ Text >
0 commit comments