Skip to content

Commit f0cb681

Browse files
author
Carlos Lancha
committed
fix: set stickerProps default value and use that instead make it nullable so stickerProps={undefined} can be passed to render no sticker
1 parent 90ebd60 commit f0cb681

File tree

3 files changed

+51
-30
lines changed

3 files changed

+51
-30
lines changed

packages/clay-card/src/CardWithInfo.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,9 @@ interface IProps extends React.BaseHTMLAttributes<HTMLDivElement> {
9393
/**
9494
* Values used in displaying bottom-left icon
9595
*/
96-
stickerProps?:
97-
| (IClayStickerProps & {
98-
content?: React.ReactNode;
99-
})
100-
| null;
96+
stickerProps?: IClayStickerProps & {
97+
content?: React.ReactNode;
98+
};
10199

102100
/**
103101
* Name of icon
@@ -125,7 +123,7 @@ export const ClayCardWithInfo: React.FunctionComponent<IProps> = ({
125123
onSelectChange,
126124
selected = false,
127125
spritemap,
128-
stickerProps,
126+
stickerProps = {},
129127
symbol,
130128
title,
131129
...otherProps
@@ -171,22 +169,20 @@ export const ClayCardWithInfo: React.FunctionComponent<IProps> = ({
171169
/>
172170
)}
173171

174-
{stickerProps !== null && (
172+
{stickerProps && (
175173
<ClaySticker
176174
displayType={
177-
stickerProps && stickerProps.displayType
175+
stickerProps.displayType
178176
? stickerProps.displayType
179177
: 'primary'
180178
}
181179
position="bottom-left"
182180
{...stickerProps}
183181
>
184-
{stickerProps ? (
185-
stickerProps.children ? (
186-
stickerProps.children
187-
) : (
188-
stickerProps.content
189-
)
182+
{stickerProps.children ? (
183+
stickerProps.children
184+
) : stickerProps.content ? (
185+
stickerProps.content
190186
) : (
191187
<ClayIcon
192188
spritemap={spritemap}

packages/clay-card/src/__tests__/__snapshots__/index.tsx.snap

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,16 @@ exports[`ClayCardWithInfo renders with custom sticker 1`] = `
23212321
>
23222322
<span
23232323
class="sticker-overlay"
2324-
/>
2324+
>
2325+
<svg
2326+
class="lexicon-icon lexicon-icon-document-default"
2327+
role="presentation"
2328+
>
2329+
<use
2330+
xlink:href="/some/spritemap#document-default"
2331+
/>
2332+
</svg>
2333+
</span>
23252334
</span>
23262335
</div>
23272336
<div
@@ -2582,6 +2591,22 @@ exports[`ClayCardWithInfo renders with no sticker 1`] = `
25822591
/>
25832592
</svg>
25842593
</div>
2594+
<span
2595+
class="sticker sticker-primary sticker-bottom-left"
2596+
>
2597+
<span
2598+
class="sticker-overlay"
2599+
>
2600+
<svg
2601+
class="lexicon-icon lexicon-icon-document-default"
2602+
role="presentation"
2603+
>
2604+
<use
2605+
xlink:href="/path/to/some/resource.svg#document-default"
2606+
/>
2607+
</svg>
2608+
</span>
2609+
</span>
25852610
</div>
25862611
</label>
25872612
</div>

packages/clay-card/src/__tests__/index.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -850,21 +850,6 @@ describe('ClayCardWithInfo', () => {
850850
expect(container).toMatchSnapshot();
851851
});
852852

853-
it('renders with no sticker', () => {
854-
const {container} = render(
855-
<ClayCardWithInfo
856-
href="#"
857-
onSelectChange={jest.fn()}
858-
selected={false}
859-
spritemap="/path/to/some/resource.svg"
860-
stickerProps={null}
861-
title="Foo Bar"
862-
/>
863-
);
864-
865-
expect(container).toMatchSnapshot();
866-
});
867-
868853
it('renders as file card specifying the displayType', () => {
869854
const {container} = render(
870855
<ClayCardWithInfo
@@ -1020,6 +1005,21 @@ describe('ClayCardWithInfo', () => {
10201005
expect(container).toMatchSnapshot();
10211006
});
10221007

1008+
it('renders with no sticker', () => {
1009+
const {container} = render(
1010+
<ClayCardWithInfo
1011+
href="#"
1012+
onSelectChange={jest.fn()}
1013+
selected={false}
1014+
spritemap="/path/to/some/resource.svg"
1015+
stickerProps={undefined}
1016+
title="Foo Bar"
1017+
/>
1018+
);
1019+
1020+
expect(container).toMatchSnapshot();
1021+
});
1022+
10231023
it('clicking dropdown item calls callback and not call onSelectChange', () => {
10241024
const onDropDownItemClick = jest.fn();
10251025
const onSelectChangeFn = jest.fn();

0 commit comments

Comments
 (0)