diff --git a/example/components/chakra-markdown.tsx b/example/components/chakra-markdown.tsx index ce31ab3..33b2e90 100644 --- a/example/components/chakra-markdown.tsx +++ b/example/components/chakra-markdown.tsx @@ -13,17 +13,21 @@ function calculateChildrenHeight(parentDiv) { return childrenHeight; } -const ChakraMarkdown = React.memo(({ content }) => { +interface ChakraMarkdownProps { + content: string; +} + +const ChakraMarkdown = React.memo(({ content }) => { const renderers = { - h1: ({ children }) => {children}, - h2: ({ children }) => {children}, - h3: ({ children }) => {children}, - a: ({ href, children }) => ( - + h1: ({ children }: any) => {children}, + h2: ({ children }: any) => {children}, + h3: ({ children }: any) => {children}, + a: ({ href, children, ...props }: any) => ( + {children} ), - code: ({ inline, children, className }) => { + code: ({ inline, children, className }: any) => { const { colorMode } = useColorMode(); const monacoTheme = colorMode === 'dark' ? 'vs-dark' : 'vs-light'; diff --git a/example/components/chat-with-markdown.tsx b/example/components/chat-with-markdown.tsx index c928262..c2e0abd 100644 --- a/example/components/chat-with-markdown.tsx +++ b/example/components/chat-with-markdown.tsx @@ -1,11 +1,11 @@ -import React, { useState, useRef, useEffect } from 'react'; -import { ChakraProvider, Box, Textarea, Button, VStack, HStack, Avatar, Text, useColorModeValue } from '@chakra-ui/react'; +import React, { useState } from 'react'; +import { ChakraProvider, Box, Button, VStack, HStack, Avatar, Text, useColorModeValue } from '@chakra-ui/react'; import ChakraMarkdown from './chakra-markdown'; // Import the renamed component +import MonacoMarkdownEditor from './monaco-markdown-editor'; function ChatApp() { const [messages, setMessages] = useState([]); const [input, setInput] = useState(""); - const textareaRef = useRef(null); const bgColor = useColorModeValue("gray.100", "gray.900"); const chatBgColor = useColorModeValue("white", "gray.800"); @@ -21,26 +21,9 @@ function ChatApp() { }; setMessages([...messages, newMessage]); setInput(""); - if (textareaRef.current) { - textareaRef.current.style.height = "auto"; // Reset textarea height after sending - } } }; - // Function to adjust the height of the textarea - const autoResizeTextarea = () => { - const maxTextareaHeight = window.innerHeight * 0.3; // 30% of screen height - if (textareaRef.current) { - textareaRef.current.style.height = "auto"; // Reset the height - textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, maxTextareaHeight)}px`; // Adjust the height, limiting to 30% - } - }; - - useEffect(() => { - // Run the resize function when the input value changes - autoResizeTextarea(); - }, [input]); - return ( @@ -74,17 +57,13 @@ function ChatApp() { {/* Input Section */} -