<!DOCTYPE html> <html> <head> <title>Chatbot</title> <style> body { font-family: Arial; margin-top: 0px; margin-bottom: 0px; } .send-button { background-color: rgb(25,135,84); color: white; padding: 12px 20px; margin-left: 10px; border: none; border-radius: 10px; font-size:15px; cursor : pointer; } .chat-input { padding : 12px 15px; border-radius : 10px; border-width : 1px; font-size:15px; flex-grow:1; } .chat-input-container{ display:flex; margin-bottom: 30px; } .app-container { max-width:600px; margin-left:auto; margin-right:auto; height: 100vh; display: flex; flex-direction: column; } .chat-message-user { display: flex; justify-content: end; align-items: start; } .chat-message-robot { display: flex; align-items: start; } .chat-message-text { background-color: rgb(238,238,238); padding : 15px 20px; border-radius : 10px; margin-right : 10px; margin-left : 10px; margin-bottom: 20px; max-width: 300px; } .chat-message-profile { width: 45px; } .chat-messages-container { flex-grow: 1; margin-top: 20px; overflow: scroll; scrollbar-width: none; } </style> </head> <body> <div class="js-container"></div> <script src="https://unpkg.com/supersimpledev/react.js"></script> <script src="https://unpkg.com/supersimpledev/react-dom.js"></script> <script src="https://unpkg.com/supersimpledev/chatbot.js"></script> <script src="https://unpkg.com/supersimpledev/babel.js"></script> <script type="text/babel"> function ChatInput({chatMessages, setChatMessages}){ const [inputText, setInputText] = React.useState(''); function saveInputText(event) { // console.log(event.target.value); setInputText(event.target.value); } function sendMessage() { // console.log(inputText); const newChatMessages = [ ...chatMessages, { message : inputText, sender : 'user', id : crypto.randomUUID() } ]; setChatMessages(newChatMessages); const response = Chatbot.getResponse(inputText); // console.log(response); /* in react we should not modify the data directly. We should create a copy of the data and modify the copy. */ setChatMessages([ ...newChatMessages, { message : response, sender : 'robot', id : crypto.randomUUID() } ]); setInputText(''); } return ( <div className="chat-input-container"> {/* using fragment to remove extra div elements */} <input placeholder="Send a message to chatbot" size="30" onChange={saveInputText} value={inputText} className="chat-input" /> <button onClick = {sendMessage} className="send-button" >Send</button> </div> ); } function ChatMessage({message, sender}){ return ( <div className={ sender === 'user' ? 'chat-message-user' : 'chat-message-robot' }> {/* use div element to put the ChatMessage on a new line */} {sender === 'robot' && <img src="robot.jpeg" className="chat-message-profile"/>} <div className="chat-message-text"> {message} </div> {sender === 'user' && <img src="human.jpeg" className="chat-message-profile"/>} </div> ) } function ChatMessages({chatMessages}) { const chatMessagesRef = React.useRef(null); React.useEffect (() => { console.log('updated'); console.log(chatMessagesRef.current); const containerElem=chatMessagesRef.current; if (containerElem) { containerElem.scrollTop = containerElem.scrollHeight; } }, [chatMessages]); return ( <div className="chat-messages-container" ref={chatMessagesRef}> {chatMessages.map((chatMessage) => { return ( <ChatMessage message={chatMessage.message} sender={chatMessage.sender} key={chatMessage.id} /> ); } )} </div> ); } function App (){ const array = React.useState([{ message: 'hello chatbot', sender: 'user', id : 'id1' }, { message: 'Hello! How can I help you?', sender: 'robot', id : 'id2' }, { message: 'Can you get me todays date?', sender: 'user', id : 'id3' }, { message: 'Today is September 26', sender: 'robot', id : 'id4' } ] ); const chatMessages = array[0]; const setChatMessages = array[1]; return (<div className="app-container"> <ChatMessages chatMessages={chatMessages} /> <ChatInput chatMessages={chatMessages} setChatMessages={setChatMessages} /> </div>); } //const app = ( App ); const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render(<App />); </script> </body> </html>
Navigation Bar
- Oracle Developer
- Date Functions
- Queries
- PL/SQL
- Oracle XML DB
- Oracle XML DB: An Example
- To Store and Select XML Data
- XMLDB : Examples of using getClobVal, getStringVal and getNumberVal
- XMLDB: Convert xml file into equivalent relational dataset
- XMLDB: XML to HTML with XSL stylesheet
- XMLDB : DBUriType
- XMLDB : XML Functions continued ...
- XMLElement, XMLAttributes, XMLAgg, XMLForest - Examples
- JSON in Oracle
- Working with JSONs in Oracle
- PL/SQL Object Types and Methods for JSON
- Oracle JSON : Select Level 1 and Level 2 data
- A JSON generator using SQL and PLSQL
- XML to JSON and JSON to XML
- Parsing a JSON object with Oracle PLSQL
- Parsing and updating a JSON object using PLSQL
- A generic JSON parser with update using Oracle PL/SQL
- A generic multi level JSON object parse and update script using PLSQL
- A generic JSON parser and JSON generator using a config table
- A generic JSON generator using a config table
- Common Oracle Errors
- Exception Handling
- Archiving
- Reclaim tablespace size after a large table delete
- Data Archiving in Oracle
- Archiving a generic solution - Part 1
- Archiving a generic solution - Part 2
- Archiving a generic solution - Part 3
- Archiving a generic solution - Part 4
- Archiving a generic solution - Part 5
- Archiving a generic solution - Part 6 - Deploy and Test
- Archiving - Case Study for optimizing disk space utilization with archiving
- Archiving : Changes for data replication
- Archiving : A case study for data replication
- Data Replication : Using Change Notification and DBMS_SCHEDULER as a LISTENER
- Oracle DBA
- Knowledge Base
- Linux
- Oracle Dewdrops
- Newsletters
- Java
Sunday, November 1, 2026
React - Using CSS stylesheet in chatbot - Full Code
A demo of the chatbot can be tried below
Chatbot
Chatbot project with CSS stylesheet code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment