From 4cebf280a47e4c0d07570eb4f1cbace9f53c6324 Mon Sep 17 00:00:00 2001 From: somebodyawesome-dev Date: Tue, 18 Jun 2024 23:08:35 +0100 Subject: [PATCH 1/2] added icon component to ConversationStarters component --- .../components/ConversationStarters.css | 5 ++ .../ConversationStarters.tsx | 46 ++++++++++++------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/packages/css/themes/src/common/components/ConversationStarters.css b/packages/css/themes/src/common/components/ConversationStarters.css index c5e5b8a5..f04f8c6b 100644 --- a/packages/css/themes/src/common/components/ConversationStarters.css +++ b/packages/css/themes/src/common/components/ConversationStarters.css @@ -14,6 +14,11 @@ > .nlux-comp-conversationStarter { font-family: var(--nlux-chtr--fnFm), sans-serif; + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 0.75rem; + width: 150px; height: 100px; overflow: hidden; diff --git a/packages/react/core/src/components/ConversationStarters/ConversationStarters.tsx b/packages/react/core/src/components/ConversationStarters/ConversationStarters.tsx index cad1b0a9..da06963d 100644 --- a/packages/react/core/src/components/ConversationStarters/ConversationStarters.tsx +++ b/packages/react/core/src/components/ConversationStarters/ConversationStarters.tsx @@ -1,20 +1,32 @@ -import {ConversationStartersProps} from './props'; +import { ConversationStarter } from "../../types/conversationStarter"; +import { ConversationStartersProps } from "./props"; export const ConversationStarters = (props: ConversationStartersProps) => { - const {onConversationStarterSelected} = props; - return ( -
- {props.items.map((conversationStarter, index) => ( - - ))} -
- ); + const { onConversationStarterSelected } = props; + return ( +
+ {props.items.map((conversationStarter, index) => ( + + ))} +
+ ); +}; + +const ConversationStarterIcon = ({ + icon, +}: { + icon: ConversationStarter["icon"]; +}) => { + if (!icon) return null; + if (typeof icon === "string") return ; + return icon; }; From effb02c145710e6f7c29e191efa7ec9fcc2d3eef Mon Sep 17 00:00:00 2001 From: somebodyawesome-dev Date: Tue, 18 Jun 2024 23:58:52 +0100 Subject: [PATCH 2/2] updated conversationStarter dom to support icons --- .../utils/createConversationStartersDom.ts | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/js/core/src/sections/chat/conversationStarters/utils/createConversationStartersDom.ts b/packages/js/core/src/sections/chat/conversationStarters/utils/createConversationStartersDom.ts index 8f53386b..a17680b2 100644 --- a/packages/js/core/src/sections/chat/conversationStarters/utils/createConversationStartersDom.ts +++ b/packages/js/core/src/sections/chat/conversationStarters/utils/createConversationStartersDom.ts @@ -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; };