Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions src/backend/overlay-widgets/builtin-types/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type ChatWidgetSettings = {
messageExitAnimation?: Animation;
messageStyle: "compact" | "modern";
chatOrder: "normal" | "reversed";
/** The type of the chat (vertical or horizontal, undefined = vertical) */
chatType: "vertical" | "horizontal" | undefined;
actionDisplayFormat: "modern" | "classic";
highlightStyle: "normal" | "highlighted";
highlightColor?: string;
Expand Down Expand Up @@ -215,17 +217,32 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
{
value: "normal",
label: "Normal",
description: "New messages will appear at the bottom of the chat feed",
description: "New messages will appear at the end of the chat feed (bottom for vertical, right for horizontal)",
iconClass: "fa-sort-amount-down-alt"
},
{
value: "reversed",
label: "Reversed",
description: "New messages will appear at the top of the chat feed",
description: "New messages will appear at the start of the chat feed (top for vertical, left for horizontal)",
iconClass: "fa-sort-amount-up"
}
]
},
{
name: "chatType",
title: "Chat Type",
description: "The type of chat widget",
type: "radio-cards",
default: "vertical",
options: [{
value: "vertical", label: "Vertical", iconClass: "fa-arrows-alt-v"
}, {
value: "horizontal", label: "Horizontal", iconClass: "fa-arrows-alt-h"
}],
settings: {
gridColumns: 2
}
},
{
name: "actionDisplayFormat",
title: "Action Display Format",
Expand Down Expand Up @@ -331,6 +348,12 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
}],
settings: {
gridColumns: 2
},
showIf: {
chatType: [
"vertical",
undefined
]
}
},
{
Expand Down Expand Up @@ -894,6 +917,9 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
default:
switch (config.settings.verticalAlignment) {
case "bottom":
if (config.settings.chatType === "horizontal") {
anchorToBottom = true;
}
height = "100%";
maxHeight = "100%";
justifyContent = "end";
Expand All @@ -907,16 +933,26 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
break;
}

let flexDirection = config.settings.chatType === "horizontal" ? "row" : "column";
flexDirection = config.settings.chatOrder === "reversed" ? `${flexDirection}-reverse` : flexDirection;

const horizontalAlignment = config.settings.chatType === "horizontal" ? "left" : config.settings.horizontalAlignment;

const chatContainerStyles: Record<string, string> = {
"display": "flex",
"flex-direction": config.settings.chatOrder === "reversed" ? "column-reverse" : "column",
"align-items": config.settings.horizontalAlignment === "right" ? "end" : "start",
"flex-direction": flexDirection,
"align-items": horizontalAlignment === "right" ? "end" : "start",
"justify-content": justifyContent,
"height": height,
"width": "100%",
"text-align": config.settings.horizontalAlignment
"text-align": horizontalAlignment
};

if (config.settings.chatType === "horizontal") {
chatContainerStyles["text-wrap"] = "nowrap";
chatContainerStyles["align-items"] = "end";
}

if (!!maxHeight?.length) {
chatContainerStyles["max-height"] = maxHeight;
}
Expand All @@ -929,7 +965,7 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
const messageRootContainerStyles: Record<string, string> = {
"display": "flex",
"gap": "10px",
"flex-direction": config.settings.horizontalAlignment === "right"
"flex-direction": horizontalAlignment === "right"
? "row-reverse"
: "row"
};
Expand Down Expand Up @@ -1006,6 +1042,10 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
"font-style": config.settings?.actionDisplayFormat === "classic" ? "normal" : "italic"
};

const chatMargin = config.settings.chatType === "horizontal" ?
config.settings.chatOrder === "reversed" ? "right" : "left" :
config.settings.chatOrder === "reversed" ? "bottom" : "top";

const styleMarkup = `
<style>
.chat-${config.id} {
Expand All @@ -1017,7 +1057,7 @@ export const chat: OverlayWidgetType<ChatWidgetSettings, ChatWidgetState> = {
}

.chat-${config.id} > div + div {
${config.settings.chatOrder === "reversed" ? "margin-bottom" : "margin-top"}: ${config.settings.spaceBetweenMessages ?? 5}px;
margin-${chatMargin}: ${config.settings.spaceBetweenMessages ?? 5}px;
}

.chat-message-root-container-${config.id} {
Expand Down