From df7cbc59da437e4f780a4504f8cbb3d418f7af56 Mon Sep 17 00:00:00 2001 From: Chris Kent <8364109+thechriskent@users.noreply.github.com> Date: Sun, 28 Jan 2024 01:42:57 -0500 Subject: [PATCH] Style Updates Moved inline styles to SCSS module Added support for theme colors (fixes issues with display in dark themes) Simplified Stack logic --- .../components/AssistantResponse.tsx | 47 ++-------- .../components/ChatStreaming.module.scss | 92 ++++++++++++++----- .../components/ChatStreaming.tsx | 13 +-- .../chatStreaming/components/MessagesList.tsx | 5 +- .../chatStreaming/components/UserMessage.tsx | 9 +- .../chatStreaming/components/UserQuestion.tsx | 47 ++-------- 6 files changed, 98 insertions(+), 115 deletions(-) diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/AssistantResponse.tsx b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/AssistantResponse.tsx index 19a74d74d..a4d3607f7 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/AssistantResponse.tsx +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/AssistantResponse.tsx @@ -1,6 +1,7 @@ import { Stack } from "@fluentui/react"; import { Icon } from '@fluentui/react'; import * as React from "react"; +import styles from "./ChatStreaming.module.scss"; export interface IAssistantResponseProps { message: string; @@ -12,46 +13,12 @@ export default class AssistantResponse extends React.Component< > { public render(): React.ReactElement { return ( - - - - - -
-

{this.props.message}

- -
-
- + + +
+

{this.props.message}

+
+
); } diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.module.scss b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.module.scss index 1aae964bd..57619fcca 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.module.scss +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.module.scss @@ -4,30 +4,80 @@ overflow: hidden; color: "[theme:bodyText, default: #323130]"; color: var(--bodyText); + min-height: 100%; + gap: 20px; + &.teams { font-family: $ms-font-family-fallbacks; } -} -.welcome { - text-align: left; -} - -.welcomeImage { - width: 100%; - max-width: 420px; -} - -.links { - a { - text-decoration: none; - color: "[theme:link, default:#03787c]"; - color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only - - &:hover { - text-decoration: underline; - color: "[theme:linkHovered, default: #014446]"; - color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only - } + .messagesContainer { + min-height: 200px; + height: 100%; + position: relative; } +} + +.messagesList { + background-color: "[theme:neutralLighter, default: #f3f2f1]"; + min-height: 200px; + + .scrollablePane { + padding: 20px; + } +} + +.userQuestion { + padding: 5px; + gap: 30px; + + .beak { + right: -10px; + border-left: 10px solid "[theme:white, default: #ffffff]"; + } +} + +.assistantResponse { + padding: 10px; + gap: 30px; + + i { + font-size: 22px; + } + + .beak { + left: -10px; + border-right: 10px solid "[theme:white, default: #ffffff]"; + } +} + +.messageBox { + position: relative; + border-radius: 5px; + padding: 5px; + background-color: "[theme:white, default: #ffffff]"; + font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; + font-size: 14px; + font-weight: 400; + box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); + max-width: 85%; + min-width: 350px; + + .message { + min-width: 100px; + } + + .beak { + content: ""; + position: absolute; + top: 10px; + width: 0; + height: 0; + border-top: 10px solid transparent; + border-bottom: 10px solid transparent; + } +} + +.userMessage { + gap: 5px; } \ No newline at end of file diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.tsx b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.tsx index f445ad44d..4a2400520 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.tsx +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/ChatStreaming.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; -//import styles from './ChatStreaming.module.scss'; +import styles from './ChatStreaming.module.scss'; import type { IChatStreamingProps } from './IChatStreamingProps'; import { IChatStreamingState } from './IChatStreamingState'; import { cloneDeep } from '@microsoft/sp-lodash-subset'; import { fetchEventSource } from '@microsoft/fetch-event-source'; import CompletionsRequestBuilder from '../models/CompletionsRequestBuilder'; -import { Spinner, SpinnerSize, Stack } from '@fluentui/react'; +import { Spinner, SpinnerSize, Stack, css } from '@fluentui/react'; import MessagesList from './MessagesList'; import UserMessage from './UserMessage'; import { IChatMessage } from '../models/IChatMessage'; @@ -32,13 +32,8 @@ export default class ChatStreaming extends React.Component { const content = this._validateWebPartProperties() ? ( - - + + {this.state.thinking && ( diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/MessagesList.tsx b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/MessagesList.tsx index 791f1c4f1..e1e1fd0cd 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/MessagesList.tsx +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/MessagesList.tsx @@ -2,6 +2,7 @@ import * as React from "react"; import UserQuestion from "./UserQuestion"; import AssistantResponse from "./AssistantResponse"; import { IChatMessage } from "../models/IChatMessage"; +import styles from "./ChatStreaming.module.scss"; import { ScrollablePane, ScrollbarVisibility } from '@fluentui/react'; @@ -30,8 +31,8 @@ export default class MessagesList extends React.Component - +
+ {output}
diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserMessage.tsx b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserMessage.tsx index a62409fce..28e4c1c30 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserMessage.tsx +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserMessage.tsx @@ -1,5 +1,6 @@ import { IconButton, Stack, TextField } from '@fluentui/react'; import * as React from 'react'; +import styles from './ChatStreaming.module.scss'; export interface IUserMessageProps { onMessageChange: (query: string) => void; @@ -31,8 +32,8 @@ export default class UserMessage extends React.Component public render(): React.ReactElement { return ( - - + + placeholder="Type user query here." /> - + ariaLabel="Stop" onClick={() => this.props.controller.abort()} /> - + ); } diff --git a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserQuestion.tsx b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserQuestion.tsx index 1bd3a9af8..ad7b0e5c1 100644 --- a/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserQuestion.tsx +++ b/samples/react-azure-openai-api-stream/src/webparts/chatStreaming/components/UserQuestion.tsx @@ -2,6 +2,7 @@ import { Stack } from "@fluentui/react"; import { Person } from "@microsoft/mgt-react/dist/es6/spfx"; import { ViewType } from "@microsoft/mgt-spfx"; import * as React from "react"; +import styles from "./ChatStreaming.module.scss"; export interface IUserQuestionProps { message: string; @@ -13,45 +14,13 @@ export default class UserQuestion extends React.Component< > { public render(): React.ReactElement { return ( - - -
-

{this.props.message}

-
-
- - - - + +
+

{this.props.message}

+
+
+ ); } -} +} \ No newline at end of file