Skip to content

Commit

Permalink
Decouple onClick and onActionClick
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaas committed May 2, 2024
1 parent f61c082 commit 71c0032
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
13 changes: 10 additions & 3 deletions sparkle/src/components/AssistantPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type GalleryVariantAssistantPreviewProps = BaseAssistantPreviewProps & {
type MinimalGalleryVariantAssistantPreviewProps = BaseAssistantPreviewProps & {
variant: "minimalGallery";
actions?: React.ReactNode;
onClick?: () => void;
onActionClick?: () => void;
};

type AssistantPreviewProps =
Expand Down Expand Up @@ -237,10 +239,12 @@ const MinimalGalleryVariantContent = ({
title,
pictureUrl,
subtitle,
onClick,
onActionClick,
}: MinimalGalleryVariantAssistantPreviewProps) => {
return (
<>
<div id="assistant-container" className="s-flex s-gap-2 s-grow s-flex-row s-justify-between s-py-1">
<>
<div id="assistant-container" className="s-flex s-gap-2 s-grow s-flex-row s-justify-between s-py-1" onClick={onClick}>
<div id="preview" className="s-flex s-gap-2 s-w-fit s-flex-row s-items-center">
<div id="avatar-column" className="s-w-fit">
<Avatar name={`Avatar of ${title}`} visual={pictureUrl} size="md" />
Expand All @@ -264,7 +268,10 @@ const MinimalGalleryVariantContent = ({
</div>
</div>
</div>
<div id="actions-column">
<div id="actions-column" onClick={(e) => {
e.stopPropagation();
onActionClick?.();
}}>
{actions}
</div>
</div>
Expand Down
14 changes: 7 additions & 7 deletions sparkle/src/stories/AssistantPreview.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,19 @@ export const AssistantPreviewExample = () => (
subtitle={"Dust"}
description=""
variant="minimalGallery"
onClick={() => console.log("AssistantPreview clicked")}
onActionClick={() => console.log("Action clicked")}
actions={
<div className="s-flex s-justify-end s-pt-1">
<Button
label=""
icon={MoreIcon}
variant="tertiary"
size="sm"
onClick={() => console.log("clicked")}
labelVisible={false}
/>
</div>
}
onClick={() => console.log("clicked")}
/>
</div>
<div className="s-border s-border-structure-100 s-rounded-xl">
Expand All @@ -234,19 +234,19 @@ export const AssistantPreviewExample = () => (
subtitle={"Dust"}
description=""
variant="minimalGallery"
onClick={() => console.log("AssistantPreview clicked")}
onActionClick={() => console.log("Action clicked")}
actions={
<div className="s-flex s-justify-end s-align-middle">
<div className="s-flex s-justify-end s-pt-1">
<Button
label=""
icon={MoreIcon}
variant="tertiary"
size="sm"
onClick={() => console.log("clicked")}
labelVisible={false}
/>
</div>
}
onClick={() => console.log("clicked")}
/>
</div>
<div className="s-border s-border-structure-100 s-rounded-xl">
Expand All @@ -256,19 +256,19 @@ export const AssistantPreviewExample = () => (
subtitle={"Dust"}
description=""
variant="minimalGallery"
onClick={() => console.log("AssistantPreview clicked")}
onActionClick={() => console.log("Action clicked")}
actions={
<div className="s-flex s-justify-end s-pt-1">
<Button
label=""
icon={MoreIcon}
variant="tertiary"
size="sm"
onClick={() => console.log("clicked")}
labelVisible={false}
/>
</div>
}
onClick={() => console.log("clicked")}
/>
</div>
</div>
Expand Down

0 comments on commit 71c0032

Please sign in to comment.