Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/funny-moose-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Update the `CalloutCard` `title` prop to accept a ReactNode type
21 changes: 20 additions & 1 deletion polaris-react/src/components/CalloutCard/CalloutCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import type {ComponentMeta} from '@storybook/react';
import {CalloutCard} from '@shopify/polaris';
import {Badge, CalloutCard} from '@shopify/polaris';

export default {
component: CalloutCard,
Expand Down Expand Up @@ -46,3 +46,22 @@ export function Dismissable() {
</CalloutCard>
);
}

export function WithCustomTitle() {
const customTitle = (
<>
<span>Customize the style of your checkout </span>
<Badge status="info">New</Badge>
</>
);

return (
<CalloutCard
title={customTitle}
illustration="https://cdn.shopify.com/s/assets/admin/checkout/settings-customizecart-705f57c725ac05be5a34ec20c05b94298cb8afd10aac7bd9c7ad02030f48cfa0.svg"
primaryAction={{content: 'Customize checkout'}}
>
<p>Upload your store’s logo, change colors and fonts, and more.</p>
</CalloutCard>
);
}
2 changes: 1 addition & 1 deletion polaris-react/src/components/CalloutCard/CalloutCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface CalloutCardProps {
/** The content to display inside the callout card. */
children?: React.ReactNode;
/** The title of the card */
title: string;
title: React.ReactNode;
/** URL to the card illustration */
illustration: string;
/** Primary action for the card */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import {mountWithApp} from 'tests/utilities';

import {Badge} from '../../Badge';
import {Button} from '../../Button';
import {ButtonGroup} from '../../ButtonGroup';
import {CalloutCard} from '../CalloutCard';
Expand Down Expand Up @@ -32,11 +33,38 @@ describe('<CalloutCard />', () => {
expect(calloutCard.find('p')).toContainReactText('Content');
});

it('renders the title as an h2 element', () => {
it('renders plain string title as an h2 element', () => {
const calloutCard = calloutCardMock();
expect(calloutCard.find('h2')).toContainReactText('Title');
});

it('renders any valid react element as title', () => {
const titleContent = 'Checkout Settings';
const badgeContent = 'Badge';
const titleMarkup = (
<>
{titleContent}
<Badge>{badgeContent}</Badge>
</>
);

const calloutCard = mountWithApp(
<CalloutCard
title={titleMarkup}
illustration={illustration}
primaryAction={{
content: 'Customize checkout',
url: 'https://www.shopify.com',
}}
/>,
);

expect(calloutCard).toContainReactText(titleContent);
expect(calloutCard).toContainReactComponent(Badge, {
children: badgeContent,
});
});

it('renders the illustration', () => {
const calloutCard = calloutCardMock();
expect(calloutCard).toContainReactComponent('img', {
Expand Down