Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/unity-react-core/src/components/Card/Card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ const CardContent = ({
</div>
) : (
<>
{(!title && !body && !showEventInfo) && <br/>}
{buttons && (
<div className="card-buttons">
{buttons.map(button => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,39 @@ const imageCards = [
},
];

const imageButtonCards = [
{
type: "default",
image: img1,
alt: "Image button card 1",
title: "Example",
body: "This is the body content for the first card.",
buttons: [
{
color: "gold",
size: "default",
label: "Explore",
ariaLabel: "Explore",
href: "#",
},
],
},
{
type: "default",
image: img1,
alt: "Image button card 2",
buttons: [
{
color: "gold",
size: "default",
label: "Explore",
ariaLabel: "Explore",
href: "#",
}
]
},
];

const Template = args => (
<div className="container">
<CardArrangement {...args} />
Expand Down Expand Up @@ -641,3 +674,27 @@ Example with image cards that display a visual representation along with heading
},
},
};

export const ImageButtonCards = Template.bind({});
ImageButtonCards.args = {
cards: imageButtonCards,
cardType: "default",
columns: 2,
};
ImageButtonCards.storyName = "Cards with image and buttons";
ImageButtonCards.parameters = {
docs: {
description: {
story: `
Example with cards that display a visual representation along with a button.

\`\`\`jsx
<CardArrangement
cards={imageButtonCards}
cardType="image"
/>
\`\`\`
`,
},
},
};
69 changes: 51 additions & 18 deletions packages/unity-react-core/src/components/Image/Image.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { spreadClasses, sanitizeDangerousMarkup } from "@asu/shared";
import classNames from "classnames";
import PropTypes from "prop-types";
import React from "react";
import { Button } from "../Button/Button";

// @ts-ignore

Expand Down Expand Up @@ -32,6 +33,7 @@ export const Image = ({
title,
caption,
captionTitle,
buttons,
border,
dropShadow,
}) => {
Expand Down Expand Up @@ -67,26 +69,57 @@ export const Image = ({
);
};

const renderFigure = () => (
<div className={borderAndDropShadowClasses}>
<figure className="figure uds-figure">
{renderImage()}
{caption && (
<figcaption className="figure-caption uds-figure-caption">
{captionTitle && <h3>{captionTitle}</h3>}
<span
className="uds-caption-text"
dangerouslySetInnerHTML={sanitizeDangerousMarkup(caption)}
/>
</figcaption>
const renderButtons = () => {
return (
<>
{buttons && (
<div className="card-buttons" style={{marginTop: caption?20:0}}>
{buttons.map(button => (
<div
className="card-button"
data-testid="card-button"
key={`${button.label}-${button.href}`}
>
<Button
ariaLabel={button.ariaLabel}
color={button.color}
icon={button.icon}
href={button.href}
label={button.label}
onClick={button.onClick}
size={button.size}
target={button.target}
cardTitle={title}
/>
</div>
))}
</div>
)}
</figure>
</div>
);
</>
);
};

const renderFigure = () => {
return (
<div className={borderAndDropShadowClasses}>
<figure className="figure uds-figure">
{renderImage()}
<figcaption className="figure-caption uds-figure-caption">
{captionTitle && <h3>{captionTitle}</h3>}
{caption &&
<span
className="uds-caption-text"
dangerouslySetInnerHTML={sanitizeDangerousMarkup(caption)}
/>}
{renderButtons()}
</figcaption>
</figure>
</div>
);
};

return buttons || caption ? renderFigure() : renderImage(borderAndDropShadowClasses);

return (
<>{caption ? renderFigure() : renderImage(borderAndDropShadowClasses)}</>
);
};

Image.propTypes = {
Expand Down
5 changes: 5 additions & 0 deletions packages/unity-react-core/src/core/types/image-types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// @ts-check

/**
* @typedef {import('./shared-types').ButtonProps} ButtonProps
*/

/**
* @typedef {Object} ImageComponentProps
* @property {string} src
Expand All @@ -15,6 +19,7 @@
* @property {string} [title]
* @property {string} [caption]
* @property {string} [captionTitle]
* @property {ButtonProps[]} [buttons]
* @property {boolean} [border]
* @property {boolean} [dropShadow]
*/
Expand Down