Skip to content

Commit

Permalink
Adding avatar and onClose() on <Citation/> (#2562)
Browse files Browse the repository at this point in the history
* Adding action and avatars on the Citation component (for file attachement v1).

* Fix lint error

* Bumping Sparkle to 0.2.41

* Remove and action and add onClose()
  • Loading branch information
lasryaric authored Nov 16, 2023
1 parent cb73699 commit 2331a63
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
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.41",
"version": "0.2.42",
"scripts": {
"build": "rm -rf dist && rollup -c",
"build:with-tw-base": "rollup -c --environment INCLUDE_TW_BASE:true",
Expand Down
28 changes: 26 additions & 2 deletions sparkle/src/components/Citation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { DocumentText } from "@sparkle/icons/stroke";
import { classNames } from "@sparkle/lib/utils";
import { Drive, Github, Notion, Slack } from "@sparkle/logo/platforms";

import { ExternalLinkIcon, Icon, IconButton, Tooltip } from "..";
import {
Avatar,
ExternalLinkIcon,
Icon,
IconButton,
Tooltip,
XCircleIcon,
} from "..";

interface CitationProps {
type?: "slack" | "google_drive" | "github" | "notion" | "document";
Expand All @@ -13,6 +20,8 @@ interface CitationProps {
index?: ReactNode;
isBlinking?: boolean;
href?: string;
onClose?: () => void;
avatarUrl?: string;
}

const typeIcons = {
Expand All @@ -29,7 +38,9 @@ export function Citation({
type = "document",
description,
href,
onClose,
isBlinking = false,
avatarUrl,
}: CitationProps) {
return (
<div
Expand All @@ -39,18 +50,31 @@ export function Citation({
)}
>
<div className="s-flex s-items-center s-gap-2">
{avatarUrl && <Avatar visual={avatarUrl} size="xs" />}
{index && (
<div className="s-flex s-h-5 s-w-5 s-items-center s-justify-center s-rounded-full s-border s-border-violet-200 s-bg-violet-100 s-text-xs s-font-semibold s-text-element-800">
{index}
</div>
)}
<Icon visual={typeIcons[type]} size="sm" />
<Icon
visual={typeIcons[type]}
size="sm"
className="s-text-element-700"
/>
<div className="s-flex-grow s-text-xs" />
{href && (
<a target="_blank" rel="noopener noreferrer" href={href}>
<IconButton icon={ExternalLinkIcon} size="sm" variant="secondary" />
</a>
)}
{onClose && (
<IconButton
icon={XCircleIcon}
size="sm"
variant="tertiary"
onClick={onClose}
/>
)}
</div>
<Tooltip label={title} position="above">
<div className="s-line-clamp-1 s-text-sm s-font-bold s-text-element-900">
Expand Down
19 changes: 19 additions & 0 deletions sparkle/src/stories/Citation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@ export const CitationsExample = () => (
type="slack"
href="https://www.google.com"
/>
<div className="s-flex s-gap-2">
<Citation
title="With close action"
type="document"
index="3"
onClose={() => alert("Close action clicked")}
description="Write a 120 character description of the citation here to be displayed in the citation list."
isBlinking={true}
/>

<Citation
title="With avatarUrl"
type="document"
onClose={() => alert("Close action clicked")}
description="Write a 120 character description of the citation here to be displayed in the citation list."
isBlinking={true}
avatarUrl="https://cdn.discordapp.com/attachments/995248824375316560/1143857310142316685/duncid_friendly_Scandinavian_droid_designed_by_Wes_Anderson_and_29eec588-b898-4e4a-9776-10c27790cbf9.png"
/>
</div>
<div className="s-flex s-gap-2">
<Citation
title="Source: Thread on #general message from @ed"
Expand Down

0 comments on commit 2331a63

Please sign in to comment.