The Open Standard for Generative UI
Thread styling changes (#36)
abhithesys60b9934191d0
diff --git a/js/packages/react-ui/src/components/Shell/Container.tsx b/js/packages/react-ui/src/components/Shell/Container.tsxindex 639ce7370..6c22f1d3f 100644--- a/js/packages/react-ui/src/components/Shell/Container.tsx+++ b/js/packages/react-ui/src/components/Shell/Container.tsx@@ -8,9 +8,10 @@ interface ContainerProps {children?: React.ReactNode;logoUrl: string;agentName: string;+ className?: string;}-export const Container = ({ children, logoUrl, agentName }: ContainerProps) => {+export const Container = ({ children, logoUrl, agentName, className }: ContainerProps) => {const ref = useRef<HTMLDivElement>(null);const { width } = useElementSize({ ref }) || {};// TODO: revisit this logic@@ -22,7 +23,13 @@ export const Container = ({ children, logoUrl, agentName }: ContainerProps) => {<ShellStoreProvider logoUrl={logoUrl} agentName={agentName}><LayoutContextProvider layout={layout}><div- className={clsx("crayon-shell-container", { "crayon-shell-container--mobile": isMobile })}+ className={clsx(+ "crayon-shell-container",+ {+ "crayon-shell-container--mobile": isMobile,+ },+ className,+ )}ref={ref}>{children}diff --git a/js/packages/react-ui/src/components/Shell/Thread.tsx b/js/packages/react-ui/src/components/Shell/Thread.tsxindex b99d4c762..c1e8e06ca 100644--- a/js/packages/react-ui/src/components/Shell/Thread.tsx+++ b/js/packages/react-ui/src/components/Shell/Thread.tsx@@ -6,7 +6,7 @@ import {} from "@crayonai/react-core";import clsx from "clsx";import { ArrowRight, Square } from "lucide-react";-import React, { useRef } from "react";+import React, { useLayoutEffect, useRef } from "react";import { useComposerState } from "../../hooks/useComposerState";import { useScrollToBottom } from "../../hooks/useScrollToBottom";import { IconButton } from "../IconButton";@@ -25,13 +25,29 @@ export const ThreadContainer = ({export const ScrollArea = ({children,className,+ scrollVariant = "always",+ userMessageSelector,}: {children?: React.ReactNode;className?: string;+ /**+ * Scroll to bottom once the last message is added+ */+ scrollVariant?: "always" | "once" | "user-message-anchor";+ /**+ * Selector for the user message+ */+ userMessageSelector?: string;}) => {const ref = useRef<HTMLDivElement>(null);const { messages } = useThreadState();- useScrollToBottom(ref, JSON.stringify(messages[messages.length - 1]));++ useScrollToBottom({+ ref,+ lastMessage: messages[messages.length - 1] || { id: "" },+ scrollVariant,+ userMessageSelector,+ });return (<div ref={ref} className={clsx("crayon-shell-thread-scroll-area", className)}>@@ -128,6 +144,7 @@ export const Composer = ({ className }: { className?: string }) => {const { textContent, setTextContent } = useComposerState();const { processMessage, onCancel } = useThreadActions();const { isRunning } = useThreadState();+ const inputRef = useRef<HTMLTextAreaElement>(null);const handleSubmit = () => {if (!textContent.trim() || isRunning) {@@ -142,10 +159,21 @@ export const Composer = ({ className }: { className?: string }) => {setTextContent("");};+ useLayoutEffect(() => {+ const input = inputRef.current;+ if (!input) {+ return;+ }++ input.style.height = "0px";+ input.style.height = `${input.scrollHeight}px`;+ }, [textContent]);+return (<div className={clsx("crayon-shell-thread-composer", className)}><div className="crayon-shell-thread-composer__input-wrapper"><textarea+ ref={inputRef}value={textContent}onChange={(e) => setTextContent(e.target.value)}className="crayon-shell-thread-composer__input"diff --git a/js/packages/react-ui/src/components/Shell/sidebar.scss b/js/packages/react-ui/src/components/Shell/sidebar.scssindex 976b4d466..6d92de0a7 100644--- a/js/packages/react-ui/src/components/Shell/sidebar.scss+++ b/js/packages/react-ui/src/components/Shell/sidebar.scss@@ -7,8 +7,8 @@ $sidebar-mobile-width: 294px;$sidebar-mobile-padding: map.get(cssUtils.$spacing, "l");.crayon-shell-sidebar-container {- //todo: fills elevated container- background: rgba(255, 255, 255, 0.6);+ background: map.get(cssUtils.$colors, fills, "background");+ border: 1px solid map.get(cssUtils.$colors, strokes, "default");height: 100%;width: $sidebar-width;border-radius: 12px;@@ -55,7 +55,7 @@ $sidebar-mobile-padding: map.get(cssUtils.$spacing, "l");&__agent-name {@include cssUtils.typography(primary, default);flex-grow: 1;- color: map.get(cssUtils.$colors, "primary");+ color: map.get(cssUtils.$colors, text, "primary");.crayon-shell-sidebar-container--collapsed & {display: none;diff --git a/js/packages/react-ui/src/components/Shell/thread.scss b/js/packages/react-ui/src/components/Shell/thread.scssindex e2bf2e0fa..4d1b3db28 100644--- a/js/packages/react-ui/src/components/Shell/thread.scss+++ b/js/packages/react-ui/src/components/Shell/thread.scss@@ -76,7 +76,7 @@ $center-align-spacing: calc(32px + map.get(cssUtils.$spacing, "s"));@include cssUtils.typography(primary, default);padding: map.get(cssUtils.$spacing, "m") map.get(cssUtils.$spacing, "l");background-color: map.get(cssUtils.$colors, "fills", "brand-el");- color: #fff;+ color: map.get(cssUtils.$colors, "text", "primary");border-radius: map.get(cssUtils.$radius, "2xl");overflow-wrap: break-word;max-width: 100%;@@ -99,7 +99,7 @@ $center-align-spacing: calc(32px + map.get(cssUtils.$spacing, "s"));border: 1.256px solid map.get(cssUtils.$colors, strokes, default);border-radius: map.get(cssUtils.$radius, "xl");display: flex;- align-items: center;+ align-items: flex-end;gap: map.get(cssUtils.$spacing, "s");padding: map.get(cssUtils.$spacing, "m");}@@ -108,11 +108,16 @@ $center-align-spacing: calc(32px + map.get(cssUtils.$spacing, "s"));flex-grow: 1;padding: 0;resize: none;- height: 1.5em;+ margin: auto 0px;+ max-height: 154px;outline: none;border: none;background: transparent;overflow: hidden;@include cssUtils.typography(primary, default);+ color: map.get(cssUtils.$colors, text, "primary");+ &::placeholder {+ color: map.get(cssUtils.$colors, text, "disabled");+ }}}diff --git a/js/packages/react-ui/src/components/Shell/threadlist.scss b/js/packages/react-ui/src/components/Shell/threadlist.scssindex bdb816a38..20310a0cb 100644--- a/js/packages/react-ui/src/components/Shell/threadlist.scss+++ b/js/packages/react-ui/src/components/Shell/threadlist.scss@@ -17,13 +17,18 @@.crayon-shell-thread-button {width: 100%;+ flex-shrink: 0;@include cssUtils.button-reset;@include cssUtils.typography(primary, default);+ color: map.get(cssUtils.$colors, text, "primary");padding: map.get(cssUtils.$spacing, "2xs") map.get(cssUtils.$spacing, "xs");border-radius: map.get(cssUtils.$radius, "s");border: 1px solid transparent;text-align: left;cursor: pointer;+ white-space: nowrap;+ text-overflow: ellipsis;+ overflow: hidden;&--selected {background-color: map.get(cssUtils.$colors, "fills", "sunk");diff --git a/js/packages/react-ui/src/hooks/useScrollToBottom.ts b/js/packages/react-ui/src/hooks/useScrollToBottom.tsindex 1028cd94a..2e9b794f5 100644--- a/js/packages/react-ui/src/hooks/useScrollToBottom.ts+++ b/js/packages/react-ui/src/hooks/useScrollToBottom.ts@@ -1,19 +1,62 @@-import { RefObject, useEffect } from "react";+import { RefObject, useEffect, useRef } from "react";-export const useScrollToBottom = <T extends HTMLElement | null>(- ref: RefObject<T>,+export const useScrollToBottom = <T extends HTMLElement | null, L extends { id: string }>({+ ref,+ lastMessage,+ scrollVariant,+ userMessageSelector = ".crayon-shell-thread-message-user",+}: {+ ref: RefObject<T>;// scroll to bottom when this value changes- triggerScroll: any,-) => {+ lastMessage: L;+ scrollVariant: "always" | "once" | "user-message-anchor";+ userMessageSelector?: string;+}) => {+ const previousLastMessage = useRef<L | null>(null);+ const lastUserMessage = useRef<HTMLElement | null>(null);+useEffect(() => {const element = ref.current;- if (!element || !triggerScroll) {+ if (!element) {return;}- element.scrollTo({- top: element.scrollHeight,- behavior: "smooth",- });- }, [ref, triggerScroll]);+ if (scrollVariant === "always") {+ if (previousLastMessage.current !== lastMessage) {+ element.scrollTo({+ top: element.scrollHeight,+ behavior: "smooth",+ });+ }+ } else if (scrollVariant === "once") {+ if (previousLastMessage.current?.id !== lastMessage.id) {+ element.scrollTo({+ top: element.scrollHeight,+ behavior: "smooth",+ });+ }+ } else {+ const lastUserMessageDiv = Array.from(element.querySelectorAll(userMessageSelector)).pop() as+ | HTMLElement+ | undefined;+ const lastUserMessageNextSibling = lastUserMessageDiv?.nextElementSibling;++ if (+ lastUserMessageDiv &&+ !lastUserMessageNextSibling?.nextElementSibling &&+ previousLastMessage.current?.id !== lastMessage.id+ ) {+ // scroll to last user message till there is only 1 more message+ const scrollPosition =+ lastUserMessageDiv.getBoundingClientRect().top -+ element.getBoundingClientRect().top ++ element.scrollTop;++ element.scrollTo({ top: scrollPosition, behavior: "smooth" });+ lastUserMessage.current = lastUserMessageDiv;+ }+ }++ previousLastMessage.current = lastMessage;+ }, [ref, lastMessage, scrollVariant, userMessageSelector]);};