-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated conversationStarter dom to support icons
- Loading branch information
1 parent
377c2be
commit f41b37f
Showing
1 changed file
with
34 additions
and
14 deletions.
There are no files selected for viewing
48 changes: 34 additions & 14 deletions
48
...ges/js/core/src/sections/chat/conversationStarters/utils/createConversationStartersDom.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
import {ConversationStarter} from '../../../../types/conversationStarter'; | ||
import { ConversationStarter } from "../../../../types/conversationStarter"; | ||
|
||
export const createConversationStartersDom = (conversationStarters: ConversationStarter[]): HTMLElement => { | ||
const conversationStartersContainer = document.createElement('div'); | ||
conversationStartersContainer.classList.add('nlux-comp-conversationStarters'); | ||
export const createConversationStartersDom = ( | ||
conversationStarters: ConversationStarter[] | ||
): HTMLElement => { | ||
const conversationStartersContainer = document.createElement("div"); | ||
conversationStartersContainer.classList.add("nlux-comp-conversationStarters"); | ||
|
||
conversationStarters.forEach((item, index) => { | ||
const conversationStarter = document.createElement('button'); | ||
conversationStarter.classList.add('nlux-comp-conversationStarter'); | ||
conversationStarters.forEach((item, index) => { | ||
const conversationStarter = document.createElement("button"); | ||
conversationStarter.classList.add("nlux-comp-conversationStarter"); | ||
|
||
const conversationStarterText = document.createElement('span'); | ||
conversationStarterText.classList.add('nlux-comp-conversationStarter-prompt'); | ||
conversationStarterText.textContent = item.prompt; | ||
// start with empty html tag | ||
let conversationStarterIcon: HTMLElement = document.createElement("div"); | ||
if (item.icon) { | ||
// if icon is specified | ||
// check if it is a string | ||
if (typeof item.icon === "string") { | ||
conversationStarterIcon = document.createElement("img"); | ||
conversationStarterIcon.setAttribute("src", item.icon); | ||
conversationStarterIcon.setAttribute("width", "20px"); | ||
} else { | ||
// if not, icon must be a html element | ||
conversationStarterIcon = item.icon; | ||
} | ||
} | ||
|
||
conversationStarter.appendChild(conversationStarterText); | ||
conversationStartersContainer.appendChild(conversationStarter); | ||
}); | ||
const conversationStarterText = document.createElement("span"); | ||
conversationStarterText.classList.add( | ||
"nlux-comp-conversationStarter-prompt" | ||
); | ||
conversationStarterText.textContent = item.prompt; | ||
|
||
return conversationStartersContainer; | ||
conversationStarter.appendChild(conversationStarterIcon); | ||
conversationStarter.appendChild(conversationStarterText); | ||
conversationStartersContainer.appendChild(conversationStarter); | ||
}); | ||
|
||
return conversationStartersContainer; | ||
}; |