Skip to content

Commit

Permalink
[sparkle] Use Citation component directly in messages (#8201)
Browse files Browse the repository at this point in the history
* Use Citation component directly in messages

* Add zoomable citation
  • Loading branch information
tdraier authored Oct 24, 2024
1 parent e4c6774 commit 48d5f66
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 72 deletions.
4 changes: 2 additions & 2 deletions sparkle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sparkle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dust-tt/sparkle",
"version": "0.2.273",
"version": "0.2.274",
"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",
Expand Down
43 changes: 0 additions & 43 deletions sparkle/src/components/ConversationCitationComponent.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions sparkle/src/components/ConversationMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ComponentType, MouseEventHandler } from "react";

import { ConversationCitationType } from "@sparkle/components/ConversationCitationComponent";
import {
ConversationMessageActions,
ConversationMessageEmojiSelectorProps,
Expand Down Expand Up @@ -32,7 +31,7 @@ type ConversationMessageProps = {
onClick: MouseEventHandler<HTMLButtonElement>;
}[];
children?: React.ReactNode;
citations?: ConversationCitationType[];
citations?: React.ReactElement[];
messageEmoji?: ConversationMessageEmojiSelectorProps;
name: string | null;
pictureUrl?: string | React.ReactNode | null;
Expand Down
10 changes: 2 additions & 8 deletions sparkle/src/components/ConversationMessageContent.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React from "react";

import {
ConversationCitationComponent,
ConversationCitationType,
} from "@sparkle/components/ConversationCitationComponent";
import { ConversationMessageSizeType } from "@sparkle/components/ConversationMessage";
import { cn } from "@sparkle/lib/utils";

interface ConversationMessageContentProps {
children: React.ReactNode;
citations?: ConversationCitationType[];
citations?: React.ReactElement[];
size: ConversationMessageSizeType;
}

Expand Down Expand Up @@ -40,9 +36,7 @@ export function ConversationMessageContent({
size === "compact" ? "s-grid-cols-2" : "s-grid-cols-4"
)}
>
{citations.map((c) => {
return <ConversationCitationComponent citation={c} key={c.id} />;
})}
{citations}
</div>
)}
</div>
Expand Down
2 changes: 0 additions & 2 deletions sparkle/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export { ColorPicker } from "./ColorPicker";
export { default as ConfettiBackground } from "./ConfettiBackground";
export { ContentMessage } from "./ContentMessage";
export { ContextItem } from "./ContextItem";
export type { ConversationCitationType } from "./ConversationCitationComponent";
export { ConversationCitationComponent as ConverationCitationComponent } from "./ConversationCitationComponent";
export type { ConversationMessageSizeType } from "./ConversationMessage";
export { ConversationMessage } from "./ConversationMessage";
export type { ConversationMessageEmojiSelectorProps } from "./ConversationMessageActions";
Expand Down
62 changes: 48 additions & 14 deletions sparkle/src/stories/ConversationMessage.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import type { Meta } from "@storybook/react";
import React from "react";

import {
Citation,
ConversationMessage,
MagnifyingGlassIcon,
ZoomableImageCitationWrapper,
} from "../index_with_tw_base";

const meta = {
Expand Down Expand Up @@ -40,13 +42,29 @@ export const ConversationExample = () => {
},
]}
citations={[
{
citationType: "slack",
id: "1",
isZoomable: false,
sourceUrl: "https://www.google.com",
title: "Source: Thread on #general message from @ed",
},
<Citation
title="Source: Thread on #general message from @ed"
size="xs"
sizing="fluid"
type="slack"
index="1"
href="https://www.google.com"
/>,
<Citation
title="Title"
type="github"
size="xs"
sizing="fluid"
index="2"
href="https://www.google.com"
/>,

<ZoomableImageCitationWrapper
size="xs"
title="Title"
imgSrc="https://dust.tt/static/droidavatar/Droid_Lime_1.jpg"
alt={"Image"}
/>,
]}
>
To conditionally render the citations only if a citations React node
Expand Down Expand Up @@ -92,13 +110,29 @@ export const ConversationExample = () => {
},
]}
citations={[
{
citationType: "slack",
id: "1",
isZoomable: false,
sourceUrl: "https://www.google.com",
title: "Source: Thread on #general message from @ed",
},
<Citation
title="Source: Thread on #general message from @ed"
size="xs"
sizing="fluid"
type="slack"
index="1"
href="https://www.google.com"
/>,
<Citation
title="Title"
type="github"
size="xs"
sizing="fluid"
index="2"
href="https://www.google.com"
/>,

<ZoomableImageCitationWrapper
size="xs"
title="Title"
imgSrc="https://dust.tt/static/droidavatar/Droid_Lime_1.jpg"
alt={"Image"}
/>,
]}
>
To conditionally render the citations only if a citations React node
Expand Down

0 comments on commit 48d5f66

Please sign in to comment.