11import 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
54
65function ChatApp ( ) {
76 const [ messages , setMessages ] = useState ( [ ] ) ;
87 const [ input , setInput ] = useState ( "" ) ;
9- const { colorMode, toggleColorMode } = useColorMode ( ) ; // Chakra color mode
108
119 const sendMessage = ( ) => {
1210 if ( input . trim ( ) !== "" ) {
@@ -21,43 +19,6 @@ function ChatApp() {
2119 }
2220 } ;
2321
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-
6122 return (
6223 < ChakraProvider >
6324 < Box bg = { useColorModeValue ( "gray.100" , "gray.900" ) } h = "100vh" p = { 4 } display = "flex" flexDirection = "column" >
@@ -79,7 +40,8 @@ function ChatApp() {
7940 < Text fontSize = "sm" fontWeight = "bold" >
8041 { message . sender }
8142 </ Text >
82- < ReactMarkdown components = { renderers } children = { message . text } />
43+ { /* Rendering the message text with markdown support */ }
44+ < ChakraMarkdown content = { message . text } />
8345 < Text fontSize = "xs" color = "gray.500" >
8446 { message . timestamp }
8547 </ Text >
0 commit comments