Skip to content

Commit

Permalink
X2-6577 Add ability to specify the caption for the button
Browse files Browse the repository at this point in the history
  • Loading branch information
rushi committed Sep 28, 2023
1 parent 54ba5cf commit 65a1f0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/ImageUpload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ImageUpload = ({
maxSize = 5,
hasDelete = true,
requirements = null,
caption = null,
csvAcceptFormats = "image/png,image/jpeg",
onChange,
onDelete,
Expand Down Expand Up @@ -41,6 +42,7 @@ export const ImageUpload = ({
};

const hasRequirements = requirements?.trim().length > 0;
const hasCaption = caption?.trim().length > 0;

return (
<div className={clsx("flex items-center rounded bg-gray-lighter p-4", hasDelete ? "space-x-2" : "space-x-3")}>
Expand Down Expand Up @@ -73,12 +75,12 @@ export const ImageUpload = ({
Delete
</Button>
<SubmitButton disabled={isLoading} isLoading={isLoading} onClick={handleUploadClick}>
Upload New Picture
{hasCaption ? caption.trim() : "Upload New Photo"}
</SubmitButton>
</>
) : (
<SubmitButton disabled={isLoading} isLoading={isLoading} onClick={handleUploadClick}>
{src ? "Replace Photo" : "Upload New Photo"}
{hasCaption ? caption.trim() : src ? "Replace Photo" : "Upload New Photo"}
</SubmitButton>
)}
</div>
Expand Down
11 changes: 11 additions & 0 deletions src/stories/Media/ImageUpload.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ImageUploadStories = {
size: "medium",
maxSize: 5,
hasDelete: true,
caption: "",
requirements: "",
},
argTypes: {
Expand All @@ -43,6 +44,14 @@ const ImageUploadStories = {
defaultValue: { summary: "medium" },
},
},
csvAcceptFormats: {
description: "The caption to show on the upload button",
control: { type: "text" },
table: {
type: { summary: null },
defaultValue: { summary: "Upload New Photo" },
},
},
isLoading: {
control: { type: "boolean" },
table: {
Expand Down Expand Up @@ -82,6 +91,7 @@ export const Default = ({
src: source,
size = "small",
maxSize,
caption,
csvAcceptFormats,
hasDelete,
requirements,
Expand Down Expand Up @@ -112,6 +122,7 @@ export const Default = ({
size={size}
isLoading={isLoading}
maxSize={maxSize}
caption={caption}
hasDelete={hasDelete}
requirements={requirements}
onChange={onChange}
Expand Down

0 comments on commit 65a1f0f

Please sign in to comment.