@comicrelief/component-library 8.47.4 → 8.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +3 -0
- package/dist/components/Molecules/CTAMultiCard/ArrowIcon.js +29 -0
- package/dist/components/Molecules/CTAMultiCard/CTAMultiCard.js +54 -0
- package/dist/components/Molecules/CTAMultiCard/CTAMultiCard.md +104 -0
- package/dist/components/Molecules/CTAMultiCard/CTAMultiCard.style.js +156 -0
- package/dist/components/Molecules/CTAMultiCard/CTAMultiCard.test.js +70 -0
- package/dist/components/Molecules/CTAMultiCard/SingleCard.js +56 -0
- package/dist/components/Molecules/CTAMultiCard/__snapshots__/CTAMultiCard.test.js.snap +2292 -0
- package/dist/components/Molecules/CTAMultiCard/example_data.json +107 -0
- package/dist/components/Molecules/CardDs/CardDs.md +1 -1
- package/dist/components/Molecules/HeroBanner/HeroBanner.js +1 -1
- package/dist/index.js +7 -0
- package/dist/styleguide/assets/challenge-1.jpg +0 -0
- package/dist/{components/Molecules/HeroBanner → theme/shared}/assets/alt_cta_underline.svg +1 -0
- package/package.json +1 -1
- package/src/components/Molecules/CTAMultiCard/ArrowIcon.js +22 -0
- package/src/components/Molecules/CTAMultiCard/CTAMultiCard.js +94 -0
- package/src/components/Molecules/CTAMultiCard/CTAMultiCard.md +104 -0
- package/src/components/Molecules/CTAMultiCard/CTAMultiCard.style.js +251 -0
- package/src/components/Molecules/CTAMultiCard/CTAMultiCard.test.js +86 -0
- package/src/components/Molecules/CTAMultiCard/SingleCard.js +100 -0
- package/src/components/Molecules/CTAMultiCard/__snapshots__/CTAMultiCard.test.js.snap +2292 -0
- package/src/components/Molecules/CTAMultiCard/example_data.json +107 -0
- package/src/components/Molecules/CardDs/CardDs.md +1 -1
- package/src/components/Molecules/HeroBanner/HeroBanner.js +1 -1
- package/src/index.js +1 -0
- package/src/styleguide/assets/challenge-1.jpg +0 -0
- package/src/{components/Molecules/HeroBanner → theme/shared}/assets/alt_cta_underline.svg +1 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import 'jest-styled-components';
|
|
3
|
+
import renderWithTheme from '../../../../tests/hoc/shallowWithTheme';
|
|
4
|
+
import CTAMultiCard from './CTAMultiCard';
|
|
5
|
+
import exampleData from './example_data.json';
|
|
6
|
+
import Text from '../../Atoms/Text/Text';
|
|
7
|
+
|
|
8
|
+
// Map example data cards to include pre-rendered body content
|
|
9
|
+
const cardsWithRenderedBody = exampleData.cards.map(card => ({
|
|
10
|
+
...card,
|
|
11
|
+
body: (
|
|
12
|
+
<Text tag="p">
|
|
13
|
+
<strong>Load</strong> of text here
|
|
14
|
+
</Text>
|
|
15
|
+
)
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const mockData = {
|
|
19
|
+
...exampleData,
|
|
20
|
+
cards: [
|
|
21
|
+
...cardsWithRenderedBody,
|
|
22
|
+
// Add a card without image for testing edge cases. This should not ever really happen in real life, but just in case...
|
|
23
|
+
{
|
|
24
|
+
id: '6bc887c7-f939-5654-a0c5-1b2caf91de6c',
|
|
25
|
+
title: 'Card no pic',
|
|
26
|
+
backgroundColour: 'Blue Light',
|
|
27
|
+
link: '/test-no-image',
|
|
28
|
+
linkLabel: 'View card',
|
|
29
|
+
body: (
|
|
30
|
+
<Text tag="p">
|
|
31
|
+
Load of text here
|
|
32
|
+
</Text>
|
|
33
|
+
),
|
|
34
|
+
image: null
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
it('renders correctly with data prop', () => {
|
|
40
|
+
const tree = renderWithTheme(
|
|
41
|
+
<CTAMultiCard data={mockData} />
|
|
42
|
+
).toJSON();
|
|
43
|
+
|
|
44
|
+
expect(tree).toMatchSnapshot();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('renders carousel mode correctly', () => {
|
|
48
|
+
const carouselData = {
|
|
49
|
+
...mockData,
|
|
50
|
+
carouselOfCards: true
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const tree = renderWithTheme(
|
|
54
|
+
<CTAMultiCard data={carouselData} />
|
|
55
|
+
).toJSON();
|
|
56
|
+
|
|
57
|
+
expect(tree).toMatchSnapshot();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('renders 2 columns layout correctly', () => {
|
|
61
|
+
const twoColumnData = {
|
|
62
|
+
...mockData,
|
|
63
|
+
layout: '2 columns'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const tree = renderWithTheme(
|
|
67
|
+
<CTAMultiCard data={twoColumnData} />
|
|
68
|
+
).toJSON();
|
|
69
|
+
|
|
70
|
+
expect(tree).toMatchSnapshot();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('handles data structure correctly', () => {
|
|
74
|
+
const testData = {
|
|
75
|
+
cards: mockData.cards,
|
|
76
|
+
backgroundColour: 'White',
|
|
77
|
+
layout: '3 columns',
|
|
78
|
+
carouselOfCards: false
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const tree = renderWithTheme(
|
|
82
|
+
<CTAMultiCard data={testData} />
|
|
83
|
+
).toJSON();
|
|
84
|
+
|
|
85
|
+
expect(tree).toMatchSnapshot();
|
|
86
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Picture from '../../Atoms/Picture/Picture';
|
|
4
|
+
import ArrowIcon from './ArrowIcon';
|
|
5
|
+
import altCtaUnderline from '../../../theme/shared/assets/alt_cta_underline.svg';
|
|
6
|
+
import {
|
|
7
|
+
CardLink,
|
|
8
|
+
ImageWrapper,
|
|
9
|
+
CopyAndLinkSection,
|
|
10
|
+
Copy,
|
|
11
|
+
CTA,
|
|
12
|
+
CTAText,
|
|
13
|
+
CTATextUnderline,
|
|
14
|
+
ArrowIconWrapper,
|
|
15
|
+
CardWrapper
|
|
16
|
+
} from './CTAMultiCard.style';
|
|
17
|
+
|
|
18
|
+
const SingleCard = ({
|
|
19
|
+
card,
|
|
20
|
+
isCarousel
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
body,
|
|
25
|
+
link,
|
|
26
|
+
linkLabel,
|
|
27
|
+
fallback,
|
|
28
|
+
imageLow,
|
|
29
|
+
images,
|
|
30
|
+
bgColour,
|
|
31
|
+
description,
|
|
32
|
+
target,
|
|
33
|
+
external
|
|
34
|
+
} = card;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<CardWrapper key={id} isCarousel={isCarousel}>
|
|
38
|
+
<CardLink
|
|
39
|
+
href={link}
|
|
40
|
+
target={target}
|
|
41
|
+
rel={external}
|
|
42
|
+
isCarousel={isCarousel}
|
|
43
|
+
backgroundColor={bgColour}
|
|
44
|
+
>
|
|
45
|
+
{imageLow && (
|
|
46
|
+
<ImageWrapper>
|
|
47
|
+
<Picture
|
|
48
|
+
alt={description}
|
|
49
|
+
imageLow={imageLow}
|
|
50
|
+
images={images}
|
|
51
|
+
image={fallback}
|
|
52
|
+
objectFit="cover"
|
|
53
|
+
width="100%"
|
|
54
|
+
height="100%"
|
|
55
|
+
/>
|
|
56
|
+
</ImageWrapper>
|
|
57
|
+
)}
|
|
58
|
+
<CopyAndLinkSection backgroundColor={bgColour}>
|
|
59
|
+
<Copy>
|
|
60
|
+
{body}
|
|
61
|
+
</Copy>
|
|
62
|
+
{linkLabel && (
|
|
63
|
+
<CTA>
|
|
64
|
+
<CTAText>
|
|
65
|
+
{linkLabel}
|
|
66
|
+
<CTATextUnderline
|
|
67
|
+
src={altCtaUnderline}
|
|
68
|
+
alt=""
|
|
69
|
+
aria-hidden="true"
|
|
70
|
+
/>
|
|
71
|
+
</CTAText>
|
|
72
|
+
<ArrowIconWrapper>
|
|
73
|
+
<ArrowIcon />
|
|
74
|
+
</ArrowIconWrapper>
|
|
75
|
+
</CTA>
|
|
76
|
+
)}
|
|
77
|
+
</CopyAndLinkSection>
|
|
78
|
+
</CardLink>
|
|
79
|
+
</CardWrapper>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
SingleCard.propTypes = {
|
|
84
|
+
card: PropTypes.shape({
|
|
85
|
+
id: PropTypes.string.isRequired,
|
|
86
|
+
body: PropTypes.node,
|
|
87
|
+
link: PropTypes.string.isRequired,
|
|
88
|
+
linkLabel: PropTypes.string,
|
|
89
|
+
fallback: PropTypes.string,
|
|
90
|
+
imageLow: PropTypes.string,
|
|
91
|
+
images: PropTypes.string,
|
|
92
|
+
bgColour: PropTypes.string.isRequired,
|
|
93
|
+
description: PropTypes.string,
|
|
94
|
+
target: PropTypes.string.isRequired,
|
|
95
|
+
external: PropTypes.string
|
|
96
|
+
}).isRequired,
|
|
97
|
+
isCarousel: PropTypes.bool
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default SingleCard;
|