From 4639b4454c369ce23fc1407cdf9f0d33bdbfb13a Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Fri, 13 Dec 2024 00:12:16 +0100 Subject: [PATCH 1/9] [sparkle/src/components] - refactor: update Citation component structure and remove CitationNew - Refactored Citation component to be more modular, introducing subcomponents for better readability and maintenance - Removed the now redundant CitationNew component and related stories in favor of the updated Citation structure - Streamlined and condensed citation components into a more cohesive and manageable set of subcomponents - Simplified the usage of Citation components in stories by using the new subcomponent architecture - Updated class names and ordering for better consistency and to follow naming conventions [src/stories] - refactor: update stories to reflect changes in Citation components - Adapted Citation stories to utilize the new subcomponents introduced in the Citation refactor - Removed CitationNew stories as the component has been deprecated and merged with Citation [src/components/Sheet.tsx] - fix: adjust shadow-tale-white order for sheet header style - Modified the ordering of class names to adhere to styling conventions and ensure visual consistency [src/components] - cleanup: remove deprecated export of CitationNew component - Removed the export statement for the now-nonexistent CitationNew component after its deprecation and merge into Citation --- sparkle/src/components/Citation.tsx | 376 ++++++++++++-------- sparkle/src/components/CitationNew.tsx | 242 ------------- sparkle/src/components/Sheet.tsx | 2 +- sparkle/src/components/index.ts | 1 - sparkle/src/stories/Citation.stories.tsx | 331 ++++++++--------- sparkle/src/stories/CitationNew.stories.tsx | 161 --------- 6 files changed, 360 insertions(+), 753 deletions(-) delete mode 100644 sparkle/src/components/CitationNew.tsx delete mode 100644 sparkle/src/stories/CitationNew.stories.tsx diff --git a/sparkle/src/components/Citation.tsx b/sparkle/src/components/Citation.tsx index 680fb12f5b38..18bbdfed6747 100644 --- a/sparkle/src/components/Citation.tsx +++ b/sparkle/src/components/Citation.tsx @@ -1,180 +1,242 @@ import React, { ReactNode } from "react"; -import { Avatar } from "@sparkle/components/Avatar"; -import { CardButton } from "@sparkle/components/CardButton"; -import { Icon } from "@sparkle/components/Icon"; -import { IconButton } from "@sparkle/components/IconButton"; -import Spinner from "@sparkle/components/Spinner"; -import { Tooltip } from "@sparkle/components/Tooltip"; -import { XCircleIcon } from "@sparkle/icons"; -import { DocumentTextStrokeIcon, ImageStrokeIcon } from "@sparkle/icons/stroke"; -import { classNames } from "@sparkle/lib/utils"; import { - ConfluenceLogo, - DriveLogo, - GithubLogo, - IntercomLogo, - MicrosoftLogo, - NotionLogo, - SlackLogo, - SnowflakeLogo, - ZendeskLogo, -} from "@sparkle/logo/platforms"; - -export type CitationType = - | "confluence" - | "document" - | "github" - | "google_drive" - | "image" - | "intercom" - | "microsoft" - | "zendesk" - | "notion" - | "slack" - | "snowflake"; - -const typeIcons = { - confluence: ConfluenceLogo, - document: DocumentTextStrokeIcon, - github: GithubLogo, - google_drive: DriveLogo, - intercom: IntercomLogo, - microsoft: MicrosoftLogo, - zendesk: ZendeskLogo, - notion: NotionLogo, - slack: SlackLogo, - image: ImageStrokeIcon, - snowflake: SnowflakeLogo, -}; + Button, + CardButton, + CardButtonProps, + Spinner, + Tooltip, +} from "@sparkle/components/"; +import { XMarkIcon } from "@sparkle/icons"; +import { cn } from "@sparkle/lib/utils"; -const typeSizing = { - fixed: { xs: "s-w-48", sm: "s-w-64" }, - fluid: "s-w-full", +type CitationProps = CardButtonProps & { + children: React.ReactNode; + isLoading?: boolean; + tooltip?: string; }; -interface CitationProps { - avatarSrc?: string; - description?: string; - href?: string; - imgSrc?: string; - index?: ReactNode; - isBlinking?: boolean; - isLoading?: boolean; - onClose?: () => void; - size?: "xs" | "sm"; - sizing?: "fixed" | "fluid"; - title: string; - type?: CitationType; -} +const Citation = React.forwardRef( + ( + { children, variant = "primary", isLoading, className, tooltip, ...props }, + ref + ) => { + const cardButton = ( + + {children} + {isLoading && } + + ); -export function Citation({ - avatarSrc, - description, - href, - imgSrc, - index, - isBlinking = false, - isLoading, - onClose, - size = "sm", - sizing = "fixed", - title, - type = "document", -}: CitationProps) { - const cardContent = ( - <> - {type === "image" && imgSrc && ( -
+ if (tooltip) { + return ; + } + + return cardButton; + } +); + +Citation.displayName = "Citation"; + +const CitationIndex = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ children, className, ...props }, ref) => { + return ( +
- {avatarSrc && } - {index && ( -
- {index} -
- )} + {...props} + > + {children} +
+ ); +}); +CitationIndex.displayName = "CitationIndex"; - {!isLoading && ( - - )} -
- {onClose && ( -
- -
- )} +const CitationGrid = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes +>(({ children, className, ...props }, ref) => { + return ( +
+
+ {children}
+
+ ); +}); +CitationGrid.displayName = "CitationGrid"; + +interface CitationCloseProps + extends React.ButtonHTMLAttributes { + className?: string; + onClick?: (e: React.MouseEvent) => void; +} + +const CitationClose = React.forwardRef( + ({ className, onClick, ...props }, ref) => { + return ( +
+ Example of dynamic grid + + alert("Card clicked")}> + + 1 + + + Hello + + alert("Close action clicked")}> + + 2 + + + Hello + + alert("Close action clicked")}> + + 3 + + + Hello + + alert("Close action clicked")}> + + 4 + + + Hello + +
); diff --git a/sparkle/src/stories/CitationNew.stories.tsx b/sparkle/src/stories/CitationNew.stories.tsx deleted file mode 100644 index 7918ba627b62..000000000000 --- a/sparkle/src/stories/CitationNew.stories.tsx +++ /dev/null @@ -1,161 +0,0 @@ -import type { Meta } from "@storybook/react"; -import React from "react"; - -import { - Button, - CitationNew, - CitationNewClose, - CitationNewDescription, - CitationNewGrid, - CitationNewIcons, - CitationNewImage, - CitationNewIndex, - CitationNewTitle, - DocumentIcon, - ExternalLinkIcon, - GlobeAltIcon, - Icon, - ImageIcon, - NotionLogo, - Popover, - SlackLogo, - TableIcon, -} from "../index_with_tw_base"; - -const meta = { - title: "Components/CitationNew", - component: CitationNew, -} satisfies Meta; - -export default meta; - -export const CitationsExample = () => ( -
- Example of attachement -
- alert("Card clicked")} className="s-w-48"> - - - - Slack thread - - @ed at 16:32 This is the latest ve - - - alert("Card clicked")} className="s-w-48"> - - - - extract_financa.csv - - alert("Card clicked")} className="s-w-48"> - - - - Linkedin, Edouard Wautier - - - alert("Card clicked")} className="s-w-48"> - - - - - screenshot.png - - - - - - - screenshot.png - -
- Example of dissmissable attachements -
- alert("Card clicked")} className="s-w-48"> - - - - Slack thread - alert("Close clicked")} /> - - @ed at 16:32 This is the latest ve - - - alert("Card clicked")} className="s-w-48"> - - - - alert("Close clicked")} /> - extract_financa.csv - - alert("Card clicked")} className="s-w-48"> - - - - alert("Close clicked")} /> - Linkedin, Edouard Wautier - - - alert("Card clicked")} className="s-w-48"> - - - - - alert("Close clicked")} /> - screenshot.png - -
- Example of citations in markdown -
- 1} - content={ - <> - - 1 - - - Hello -
- Example of dynamic grid - - alert("Card clicked")}> - - 1 - - - Hello - - alert("Close action clicked")}> - - 2 - - - Hello - - alert("Close action clicked")}> - - 3 - - - Hello - - alert("Close action clicked")}> - - 4 - - - Hello - - -
-); From 64e8e850bb22c0e91d3682179675eb0045e76455 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Fri, 13 Dec 2024 00:19:35 +0100 Subject: [PATCH 2/9] [sparkle] - refactor: remove ZoomableImageCitationWrapper component - Deleted the ZoomableImageCitationWrapper to simplify the image citation features - Removed the component export from the main index to clean up unused code references --- .../ZoomableImageCitationWrapper.tsx | 61 ------------------- sparkle/src/components/index.ts | 1 - 2 files changed, 62 deletions(-) delete mode 100644 sparkle/src/components/ZoomableImageCitationWrapper.tsx diff --git a/sparkle/src/components/ZoomableImageCitationWrapper.tsx b/sparkle/src/components/ZoomableImageCitationWrapper.tsx deleted file mode 100644 index 96d9d8a0ca61..000000000000 --- a/sparkle/src/components/ZoomableImageCitationWrapper.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { Dialog } from "@headlessui/react"; -import React, { useState } from "react"; - -import { Citation } from "@sparkle/components/Citation"; -import { IconButton } from "@sparkle/components/IconButton"; -import { XCircleIcon } from "@sparkle/icons/solid"; - -interface ZoomableImageCitationWrapperProps { - alt: string; - imgSrc: string; - title: string; - size: "xs" | "sm"; -} - -export function ZoomableImageCitationWrapper({ - alt, - imgSrc, - title, - size = "sm", -}: ZoomableImageCitationWrapperProps) { - const [isZoomed, setIsZoomed] = useState(false); - - const handleZoomToggle = () => { - setIsZoomed(!isZoomed); - }; - - return ( - <> -
- -
- - -
- - -
- -
-
- {alt} -
-
-
- - ); -} diff --git a/sparkle/src/components/index.ts b/sparkle/src/components/index.ts index 80cb0d02f41d..17bacc9827a1 100644 --- a/sparkle/src/components/index.ts +++ b/sparkle/src/components/index.ts @@ -114,4 +114,3 @@ export { } from "./Tooltip"; export { Tree } from "./Tree"; export { TypingAnimation } from "./TypingAnimation"; -export { ZoomableImageCitationWrapper } from "./ZoomableImageCitationWrapper"; From c0ca5afb260deee43919a988c37535e6adf00e96 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Fri, 13 Dec 2024 00:23:14 +0100 Subject: [PATCH 3/9] [sparkle] - refactor: streamline ConversationMessage citations - Replace individual Citation components with a more flexible structure including CitationIcons and CitationTitle - Remove usage of ZoomableImageCitationWrapper in favor of a unified Citation component structure --- .../stories/ConversationMessage.stories.tsx | 98 +++++++------------ 1 file changed, 33 insertions(+), 65 deletions(-) diff --git a/sparkle/src/stories/ConversationMessage.stories.tsx b/sparkle/src/stories/ConversationMessage.stories.tsx index 90daa93c7560..5c63deda5312 100644 --- a/sparkle/src/stories/ConversationMessage.stories.tsx +++ b/sparkle/src/stories/ConversationMessage.stories.tsx @@ -4,9 +4,13 @@ import React from "react"; import { Button, Citation, + CitationIcons, + CitationTitle, ConversationMessage, + GithubIcon, + Icon, MagnifyingGlassIcon, - ZoomableImageCitationWrapper, + SlackLogo, } from "../index_with_tw_base"; const meta = { @@ -43,47 +47,20 @@ export const ConversationExample = () => { />, ]} citations={[ - , - , - - , - , - , - , + + + + + + Source: Thread on #general message from @ed + + , + + + + + Title + , ]} > To conditionally render the citations only if a citations React node @@ -129,29 +106,20 @@ export const ConversationExample = () => { />, ]} citations={[ - , - , - - , + + + + + + Source: Thread on #general message from @ed + + , + + + + + Title + , ]} > To conditionally render the citations only if a citations React node From f6a8afe3985db9a2a2e7837d5fa2a85418b08dd1 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Fri, 13 Dec 2024 00:33:40 +0100 Subject: [PATCH 4/9] [sparkle] - refactor: update citation components structure in PaginatedCitationsGrid - Remove the display name assignment for CitationImage component - Restructure Citation items to use composition rather than props in PaginatedCitationsGrid - Replace CitationType with icon JSX element for flexibility in citation rendering - Update storybook for PaginatedCitationsGrid with the new component design and DocumentIcon usage --- sparkle/src/components/Citation.tsx | 2 -- .../src/components/PaginatedCitationsGrid.tsx | 27 +++++++++++-------- .../PaginatedCitationsGrid.stories.tsx | 6 ++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/sparkle/src/components/Citation.tsx b/sparkle/src/components/Citation.tsx index 18bbdfed6747..fdc4e36bfc8c 100644 --- a/sparkle/src/components/Citation.tsx +++ b/sparkle/src/components/Citation.tsx @@ -159,8 +159,6 @@ const CitationIcons = React.forwardRef< }); CitationIcons.displayName = "CitationIcons"; -CitationImage.displayName = "CitationImage"; - const CitationLoading = React.forwardRef< HTMLDivElement, React.HTMLAttributes diff --git a/sparkle/src/components/PaginatedCitationsGrid.tsx b/sparkle/src/components/PaginatedCitationsGrid.tsx index 4c842305be56..ea0ebb67aff3 100644 --- a/sparkle/src/components/PaginatedCitationsGrid.tsx +++ b/sparkle/src/components/PaginatedCitationsGrid.tsx @@ -2,14 +2,20 @@ import { PaginationState } from "@tanstack/react-table"; import { useState } from "react"; import React from "react"; -import { Citation, CitationType } from "@sparkle/components/Citation"; +import { + Citation, + CitationDescription, + CitationIcons, + CitationIndex, + CitationTitle, +} from "@sparkle/components/Citation"; import { Pagination } from "@sparkle/components/Pagination"; import { classNames } from "@sparkle/lib/utils"; interface CitationItem { description?: string; title: string; - type: CitationType; + icon: React.JSX.Element; href?: string; } @@ -50,15 +56,14 @@ export function PaginatedCitationsGrid({ > {paginatedItems.map((d, idx) => { return ( - + + + {idx} + {d.icon} + + {d.title} + {d.description} + ); })} diff --git a/sparkle/src/stories/PaginatedCitationsGrid.stories.tsx b/sparkle/src/stories/PaginatedCitationsGrid.stories.tsx index 66e05f912daa..f06bd0e4c8c2 100644 --- a/sparkle/src/stories/PaginatedCitationsGrid.stories.tsx +++ b/sparkle/src/stories/PaginatedCitationsGrid.stories.tsx @@ -1,9 +1,7 @@ import type { Meta } from "@storybook/react"; import React from "react"; -import { CitationType } from "@sparkle/components/Citation"; - -import { PaginatedCitationsGrid } from "../index_with_tw_base"; +import { DocumentIcon, PaginatedCitationsGrid } from "../index_with_tw_base"; const meta = { title: "Modules/PaginatedCitationsGrid", @@ -16,7 +14,7 @@ function makeCitationItems(items: number) { return Array.from({ length: items }, (_, idx) => ({ title: `test ${idx + 1}`, href: "empty", - type: "document" as CitationType, + icon: , })); } From a09a3e0e95ffb74e0247a35159aff4c45f7b4c86 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Fri, 13 Dec 2024 16:33:29 +0100 Subject: [PATCH 5/9] [sparkle] - refactor: update CardButton component padding and alignment - Change padding specificity from general to horizontal for small, medium, and large sizes - Adjust the button alignment to center justify within its container --- sparkle/src/components/CardButton.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sparkle/src/components/CardButton.tsx b/sparkle/src/components/CardButton.tsx index 4f13b369da6f..30299db108d5 100644 --- a/sparkle/src/components/CardButton.tsx +++ b/sparkle/src/components/CardButton.tsx @@ -27,13 +27,13 @@ const CARD_BUTTON_SIZES = ["sm", "md", "lg"] as const; type CardButtonSizeType = (typeof CARD_BUTTON_SIZES)[number]; const sizeVariants: Record = { - sm: "s-p-3 s-rounded-xl", - md: "s-p-4 s-rounded-2xl", - lg: "s-p-5 s-rounded-3xl", + sm: "s-px-3 s-rounded-xl", + md: "s-px-4 s-rounded-2xl", + lg: "s-px-5 s-rounded-3xl", }; const cardButtonVariants = cva( - "s-flex s-text-left s-group s-border s-overflow-hidden s-text-foreground", + "s-flex s-text-left s-justify-center s-group s-border s-overflow-hidden s-text-foreground", { variants: { variant: variantClasses, From bb8ad1b424232d9e051db42d6173f3c7c90ca7a2 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Sat, 14 Dec 2024 11:36:34 +0100 Subject: [PATCH 6/9] [sparkle] - feature: add compact size option to ConversationMessage component - Introduced a 'compact' size property to reduce the visual space taken by agent messages in conversations --- sparkle/src/stories/ConversationMessage.stories.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/sparkle/src/stories/ConversationMessage.stories.tsx b/sparkle/src/stories/ConversationMessage.stories.tsx index 5c63deda5312..6d21beaec621 100644 --- a/sparkle/src/stories/ConversationMessage.stories.tsx +++ b/sparkle/src/stories/ConversationMessage.stories.tsx @@ -97,6 +97,7 @@ export const ConversationExample = () => { Date: Mon, 16 Dec 2024 10:48:58 +0100 Subject: [PATCH 7/9] [sparkle] - feature: bump package version to 0.2.341 - Update `package-lock.json` and `package.json` to reflect the new package version - Ensure dependencies are aligned with the upgraded version --- sparkle/package-lock.json | 4 ++-- sparkle/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sparkle/package-lock.json b/sparkle/package-lock.json index 99ada6ec1066..00f6d6379b9f 100644 --- a/sparkle/package-lock.json +++ b/sparkle/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dust-tt/sparkle", - "version": "0.2.340", + "version": "0.2.341", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dust-tt/sparkle", - "version": "0.2.340", + "version": "0.2.341", "license": "ISC", "dependencies": { "@emoji-mart/data": "^1.1.2", diff --git a/sparkle/package.json b/sparkle/package.json index 4e3d743bdf8f..6ae0c9cc44b3 100644 --- a/sparkle/package.json +++ b/sparkle/package.json @@ -1,6 +1,6 @@ { "name": "@dust-tt/sparkle", - "version": "0.2.340", + "version": "0.2.341", "scripts": { "build": "rm -rf dist && npm run tailwind && npm run build:esm && npm run build:cjs", "tailwind": "tailwindcss -i ./src/styles/tailwind.css -o dist/sparkle.css", From e125622da228a8e22056a79a567191685ca331cd Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Mon, 16 Dec 2024 15:32:03 +0100 Subject: [PATCH 8/9] [sparkle] - refactor: update responsive grid and container styles in ConversationMessageContent - Removed fixed grid column classes and added responsive grid classes to support various screen sizes - Included new container utility class to enhance structure in conversation message layouts --- sparkle/src/components/ConversationMessageContent.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sparkle/src/components/ConversationMessageContent.tsx b/sparkle/src/components/ConversationMessageContent.tsx index 5e2519afde53..006c521552eb 100644 --- a/sparkle/src/components/ConversationMessageContent.tsx +++ b/sparkle/src/components/ConversationMessageContent.tsx @@ -17,7 +17,7 @@ export function ConversationMessageContent({ return (
@@ -32,8 +32,10 @@ export function ConversationMessageContent({ {citations && (
{citations} From 45865521257edbe129b6df8ad7b50bd93bae7e73 Mon Sep 17 00:00:00 2001 From: JulesBelveze Date: Mon, 16 Dec 2024 16:22:15 +0100 Subject: [PATCH 9/9] [sparkle] - fix: adjust responsive grid columns for ConversationMessageContent - Change the grid column setup at 'xs' breakpoint to start with 2 columns instead of 1 --- sparkle/src/components/ConversationMessageContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparkle/src/components/ConversationMessageContent.tsx b/sparkle/src/components/ConversationMessageContent.tsx index 006c521552eb..32f75a91cc8f 100644 --- a/sparkle/src/components/ConversationMessageContent.tsx +++ b/sparkle/src/components/ConversationMessageContent.tsx @@ -35,7 +35,7 @@ export function ConversationMessageContent({ "s-grid s-grid-cols-2 s-gap-2", size === "compact" ? "" - : "@xs:s-grid-cols-1 @sm:s-grid-cols-3 @lg:s-grid-cols-4 @xl:s-grid-cols-5" + : "@xs:s-grid-cols-2 @sm:s-grid-cols-3 @lg:s-grid-cols-4 @xl:s-grid-cols-5" )} > {citations}