@skyscanner/backpack-web 9.2.0 → 9.3.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/bpk-component-content-cards/README.md +43 -0
- package/bpk-component-content-cards/index.ts +21 -0
- package/bpk-component-content-cards/package.json +23 -0
- package/bpk-component-content-cards/src/BpkContentCard/BpkContentCard-test.tsx +88 -0
- package/bpk-component-content-cards/src/BpkContentCard/BpkContentCard.module.scss +87 -0
- package/bpk-component-content-cards/src/BpkContentCard/BpkContentCard.tsx +84 -0
- package/bpk-component-content-cards/src/BpkContentCard/index.ts +19 -0
- package/bpk-component-content-cards/src/BpkContentCards-test.tsx +126 -0
- package/bpk-component-content-cards/src/BpkContentCards.module.css +18 -0
- package/bpk-component-content-cards/src/BpkContentCards.module.scss +51 -0
- package/bpk-component-content-cards/src/BpkContentCards.tsx +72 -0
- package/bpk-component-content-cards/src/accessibility-test.tsx +64 -0
- package/package.json +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# BpkContentCards
|
|
2
|
+
|
|
3
|
+
> Backpack example component.
|
|
4
|
+
|
|
5
|
+
- [Storybook link](https://backpack.github.io/storybook)
|
|
6
|
+
- [Content Cards Docs](backpack.github.io/components/content-cards)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install bpk-component-content-cards --save-dev
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import React from 'react';
|
|
18
|
+
import BpkContentCards from '@skyscanner/backpack-web/bpk-component-content-cards';
|
|
19
|
+
|
|
20
|
+
<BpkContentCards
|
|
21
|
+
heading='Heading'
|
|
22
|
+
cards=[
|
|
23
|
+
{
|
|
24
|
+
image: {
|
|
25
|
+
url: 'http://skyscanner.net/card-1-image-link.jpg',
|
|
26
|
+
alt: 'People surfing in the ocean',
|
|
27
|
+
},
|
|
28
|
+
headline: 'Card headline',
|
|
29
|
+
description: 'Card description',
|
|
30
|
+
href: 'http://skyscanner.net/card-1-cta-link.html',
|
|
31
|
+
},
|
|
32
|
+
]
|
|
33
|
+
/>
|
|
34
|
+
|
|
35
|
+
export default () => <BpkContentCards />;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Props
|
|
39
|
+
|
|
40
|
+
| Property | PropType | Required | Default Value |
|
|
41
|
+
| ---------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | ------------- |
|
|
42
|
+
| heading | string | true | |
|
|
43
|
+
| cards <ul><li>image</li><ul><li>url</li><li>alt</li></ul><li>headline</li><li>description</li><li>href</li></ul> | Array <ul><li>Object</li><ul><li>string</li><li>string</li></ul><li>string</li><li>string</li><li>string</li></ul> | true <ul><li>true</li><ul><li>true</li><li>false</li></ul><li>true</li><li>true</li><li>true</li></ul> | "" |
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import BpkContentCards from './src/BpkContentCards';
|
|
20
|
+
|
|
21
|
+
export default BpkContentCards;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "bpk-component-content-cards",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Backpack content-cards component.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git@github.com:Skyscanner/backpack.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Backpack Design System <backpack@skyscanner.net>",
|
|
11
|
+
"main": "index.ts",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"registry": "https://registry.npmjs.org/"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"bpk-component-text": "^8.0.2",
|
|
17
|
+
"bpk-mixins": "^31.1.6",
|
|
18
|
+
"bpk-react-utils": "^7.0.0"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": "^17.0.2"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import { render, screen } from '@testing-library/react';
|
|
21
|
+
import '@testing-library/jest-dom';
|
|
22
|
+
|
|
23
|
+
import BpkContentCard from './BpkContentCard';
|
|
24
|
+
|
|
25
|
+
describe('Content Card widget', () => {
|
|
26
|
+
const horizontalCardTestProps: React.ComponentProps<typeof BpkContentCard> = {
|
|
27
|
+
card: {
|
|
28
|
+
image: {
|
|
29
|
+
url: 'http://skyscanner.net/card-1-image-link.jpg',
|
|
30
|
+
alt: 'People surfing in the ocean',
|
|
31
|
+
},
|
|
32
|
+
headline: 'Card 1 headline',
|
|
33
|
+
description: 'Card 1 description',
|
|
34
|
+
href: 'http://skyscanner.net/card-1-cta-link.html',
|
|
35
|
+
},
|
|
36
|
+
layout: 'HORIZONTAL',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const verticalCardTestProps: React.ComponentProps<typeof BpkContentCard> = {
|
|
40
|
+
card: {
|
|
41
|
+
image: {
|
|
42
|
+
url: 'http://skyscanner.net/card-1-image-link.jpg',
|
|
43
|
+
alt: 'People surfing in the ocean',
|
|
44
|
+
},
|
|
45
|
+
headline: 'Card 1 headline',
|
|
46
|
+
description: 'Card 1 description',
|
|
47
|
+
href: 'http://skyscanner.net/card-1-cta-link.html',
|
|
48
|
+
},
|
|
49
|
+
layout: 'VERTICAL',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
it('renders horizontal card correctly', async () => {
|
|
53
|
+
const { asFragment } = render(
|
|
54
|
+
<BpkContentCard
|
|
55
|
+
card={horizontalCardTestProps.card}
|
|
56
|
+
layout={horizontalCardTestProps.layout}
|
|
57
|
+
/>,
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect(asFragment()).toMatchSnapshot();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('renders vertical card correctly', async () => {
|
|
64
|
+
const { asFragment } = render(
|
|
65
|
+
<BpkContentCard
|
|
66
|
+
card={verticalCardTestProps.card}
|
|
67
|
+
layout={verticalCardTestProps.layout}
|
|
68
|
+
/>,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(asFragment()).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('renders the headline and the description for the card', async () => {
|
|
75
|
+
render(
|
|
76
|
+
<BpkContentCard
|
|
77
|
+
card={horizontalCardTestProps.card}
|
|
78
|
+
layout={horizontalCardTestProps.layout}
|
|
79
|
+
/>,
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const expectedElements = ['Card 1 headline', 'Card 1 description'];
|
|
83
|
+
|
|
84
|
+
expectedElements.forEach((element) =>
|
|
85
|
+
expect(screen.getByText(element)).toBeVisible(),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
@import '~bpk-mixins/index';
|
|
19
|
+
|
|
20
|
+
$bpk-spacing-v2: true;
|
|
21
|
+
|
|
22
|
+
.bpk-content-card {
|
|
23
|
+
&--link {
|
|
24
|
+
color: inherit;
|
|
25
|
+
font: inherit;
|
|
26
|
+
text-decoration: inherit;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&--horizontal {
|
|
30
|
+
display: grid;
|
|
31
|
+
column-gap: bpk-spacing-xxl();
|
|
32
|
+
grid-template-columns: minmax(min(10%, 50%), $bpk-one-pixel-rem * 620) 40%;
|
|
33
|
+
align-items: center;
|
|
34
|
+
|
|
35
|
+
@include bpk-breakpoint-mobile {
|
|
36
|
+
grid-template-columns: 1fr;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&--horizontal &--image-container {
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: $bpk-one-pixel-rem * 420;
|
|
43
|
+
|
|
44
|
+
@include bpk-breakpoint-mobile {
|
|
45
|
+
max-height: $bpk-one-pixel-rem * 180;
|
|
46
|
+
margin-bottom: bpk-spacing-base();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@include bpk-breakpoint-tablet {
|
|
50
|
+
height: 100%;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&--vertical &--image {
|
|
55
|
+
height: $bpk-one-pixel-rem * 460;
|
|
56
|
+
margin-bottom: bpk-spacing-base();
|
|
57
|
+
|
|
58
|
+
@include bpk-breakpoint-small-tablet {
|
|
59
|
+
width: 100%;
|
|
60
|
+
height: auto;
|
|
61
|
+
max-height: $bpk-one-pixel-rem * 260;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@include bpk-breakpoint-mobile {
|
|
65
|
+
max-height: $bpk-one-pixel-rem * 180;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&--headline {
|
|
70
|
+
margin-bottom: $bpk-heading-margin-bottom;
|
|
71
|
+
|
|
72
|
+
@include bpk-heading-4;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&--description {
|
|
76
|
+
color: $bpk-color-sky-gray-tint-02;
|
|
77
|
+
|
|
78
|
+
@include bpk-body-default;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&--image {
|
|
82
|
+
width: 100%;
|
|
83
|
+
height: 100%;
|
|
84
|
+
border-radius: $bpk-border-radius-md;
|
|
85
|
+
object-fit: cover;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
|
|
21
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
22
|
+
import BpkText from '../../../bpk-component-text';
|
|
23
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
24
|
+
import { cssModules } from '../../../bpk-react-utils';
|
|
25
|
+
|
|
26
|
+
import STYLES from './BpkContentCard.module.scss';
|
|
27
|
+
|
|
28
|
+
const getClassName = cssModules(STYLES);
|
|
29
|
+
|
|
30
|
+
type CardLayout = 'HORIZONTAL' | 'VERTICAL';
|
|
31
|
+
|
|
32
|
+
type Props = {
|
|
33
|
+
card: {
|
|
34
|
+
image: {
|
|
35
|
+
url: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
};
|
|
38
|
+
headline: string;
|
|
39
|
+
description: string;
|
|
40
|
+
href: string;
|
|
41
|
+
};
|
|
42
|
+
layout: CardLayout;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const BpkContentCard = ({ card, layout }: Props) => (
|
|
46
|
+
<a
|
|
47
|
+
className={getClassName(
|
|
48
|
+
'bpk-content-card--link',
|
|
49
|
+
layout === 'HORIZONTAL'
|
|
50
|
+
? 'bpk-content-card--horizontal'
|
|
51
|
+
: 'bpk-content-card--vertical',
|
|
52
|
+
)}
|
|
53
|
+
href={card.href}
|
|
54
|
+
target="_blank"
|
|
55
|
+
rel="noreferrer"
|
|
56
|
+
>
|
|
57
|
+
<div className={getClassName('bpk-content-card--image-container')}>
|
|
58
|
+
{/* eslint-disable-next-line jsx-a11y/img-redundant-alt */}
|
|
59
|
+
<img
|
|
60
|
+
className={getClassName('bpk-content-card--image')}
|
|
61
|
+
alt={card.image.alt || ''}
|
|
62
|
+
src={card.image.url}
|
|
63
|
+
loading="lazy"
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<div>
|
|
68
|
+
<BpkText
|
|
69
|
+
className={getClassName('bpk-content-card--headline')}
|
|
70
|
+
tagName="h3"
|
|
71
|
+
>
|
|
72
|
+
{card.headline}
|
|
73
|
+
</BpkText>
|
|
74
|
+
<BpkText
|
|
75
|
+
className={getClassName('bpk-content-card--description')}
|
|
76
|
+
tagName="p"
|
|
77
|
+
>
|
|
78
|
+
{card.description}
|
|
79
|
+
</BpkText>
|
|
80
|
+
</div>
|
|
81
|
+
</a>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export default BpkContentCard;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export { default } from './BpkContentCard';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import { render, screen } from '@testing-library/react';
|
|
21
|
+
|
|
22
|
+
import BpkContentCards from './BpkContentCards';
|
|
23
|
+
|
|
24
|
+
describe('Content Card widget', () => {
|
|
25
|
+
const contentContainerTestProps: React.ComponentProps<
|
|
26
|
+
typeof BpkContentCards
|
|
27
|
+
> = {
|
|
28
|
+
heading: 'Header for the component',
|
|
29
|
+
cards: [
|
|
30
|
+
{
|
|
31
|
+
image: {
|
|
32
|
+
url: 'http://skyscanner.net/card-1-image-link.jpg',
|
|
33
|
+
alt: 'People surfing in the ocean',
|
|
34
|
+
},
|
|
35
|
+
headline: 'Card 1 headline',
|
|
36
|
+
description: 'Card 1 description',
|
|
37
|
+
href: 'http://skyscanner.net/card-1-cta-link.html',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
image: {
|
|
41
|
+
url: 'http://skyscanner.net/card-2-image-link.jpg',
|
|
42
|
+
alt: 'Man on boat in a fjord',
|
|
43
|
+
},
|
|
44
|
+
headline: 'Card 2 headline',
|
|
45
|
+
description: 'Card 2 description',
|
|
46
|
+
href: 'http://skyscanner.net/card-2-cta-link.html',
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
image: {
|
|
50
|
+
url: 'http://skyscanner.net/card-3-image-link.jpg',
|
|
51
|
+
alt: 'Airplane flying over mountains',
|
|
52
|
+
},
|
|
53
|
+
headline: 'Card 3 headline',
|
|
54
|
+
description: 'Card 3 description',
|
|
55
|
+
href: 'http://skyscanner.net/card-3-cta-link.html',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
it('renders correctly with 1 card', async () => {
|
|
61
|
+
const { asFragment } = render(
|
|
62
|
+
<BpkContentCards
|
|
63
|
+
heading={contentContainerTestProps.heading}
|
|
64
|
+
cards={contentContainerTestProps.cards.slice(0, 1)}
|
|
65
|
+
/>,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(asFragment()).toMatchSnapshot();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('renders correctly with 2 cards', async () => {
|
|
72
|
+
const { asFragment } = render(
|
|
73
|
+
<BpkContentCards
|
|
74
|
+
heading={contentContainerTestProps.heading}
|
|
75
|
+
cards={contentContainerTestProps.cards.slice(0, 2)}
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(asFragment()).toMatchSnapshot();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('renders correctly with 3 cards', async () => {
|
|
83
|
+
const { asFragment } = render(
|
|
84
|
+
<BpkContentCards
|
|
85
|
+
heading={contentContainerTestProps.heading}
|
|
86
|
+
cards={contentContainerTestProps.cards}
|
|
87
|
+
/>,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect(asFragment()).toMatchSnapshot();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('renders the title, the headline and the description for each card', async () => {
|
|
94
|
+
render(
|
|
95
|
+
<BpkContentCards
|
|
96
|
+
heading={contentContainerTestProps.heading}
|
|
97
|
+
cards={contentContainerTestProps.cards}
|
|
98
|
+
/>,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const expectedElements = [
|
|
102
|
+
'Header for the component',
|
|
103
|
+
'Card 1 headline',
|
|
104
|
+
'Card 1 description',
|
|
105
|
+
'Card 2 headline',
|
|
106
|
+
'Card 2 description',
|
|
107
|
+
'Card 3 headline',
|
|
108
|
+
'Card 3 description',
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
expectedElements.forEach((element) =>
|
|
112
|
+
expect(screen.getByText(element)).toBeTruthy(),
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('does not render anything if the cards are not defined', () => {
|
|
117
|
+
const { container } = render(
|
|
118
|
+
<BpkContentCards
|
|
119
|
+
heading={contentContainerTestProps.heading}
|
|
120
|
+
cards={[]}
|
|
121
|
+
/>,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
expect(container.firstChild).toBe(null);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
@keyframes bpk-keyframe-spin{100%{transform:rotate(1turn)}}.bpk-content-cards{display:flex}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* stylelint-disable selector-class-pattern */
|
|
20
|
+
/* stylelint-disable selector-max-compound-selectors */
|
|
21
|
+
@import '~bpk-mixins/index';
|
|
22
|
+
|
|
23
|
+
$bpk-spacing-v2: true;
|
|
24
|
+
|
|
25
|
+
.bpk-content-cards {
|
|
26
|
+
&--header-text {
|
|
27
|
+
margin-bottom: bpk-spacing-base();
|
|
28
|
+
|
|
29
|
+
@include bpk-heading-2;
|
|
30
|
+
|
|
31
|
+
@include bpk-breakpoint-mobile {
|
|
32
|
+
@include bpk-heading-3;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&--layout {
|
|
37
|
+
display: grid;
|
|
38
|
+
grid-template-columns: repeat(
|
|
39
|
+
auto-fit,
|
|
40
|
+
minmax($bpk-one-pixel-rem * 50, 1fr)
|
|
41
|
+
);
|
|
42
|
+
grid-auto-flow: column;
|
|
43
|
+
gap: bpk-spacing-base();
|
|
44
|
+
|
|
45
|
+
@include bpk-breakpoint-small-tablet {
|
|
46
|
+
grid-template-columns: 1fr;
|
|
47
|
+
grid-auto-flow: row;
|
|
48
|
+
gap: bpk-spacing-lg();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
|
|
21
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
22
|
+
import BpkText from '../../bpk-component-text';
|
|
23
|
+
// @ts-expect-error Untyped import. See `decisions/imports-ts-suppressions.md`.
|
|
24
|
+
import { cssModules } from '../../bpk-react-utils';
|
|
25
|
+
|
|
26
|
+
import BpkContentCard from './BpkContentCard';
|
|
27
|
+
import STYLES from './BpkContentCards.module.scss';
|
|
28
|
+
|
|
29
|
+
const getClassName = cssModules(STYLES);
|
|
30
|
+
|
|
31
|
+
type Props = {
|
|
32
|
+
heading: string;
|
|
33
|
+
cards: Array<{
|
|
34
|
+
image: {
|
|
35
|
+
url: string;
|
|
36
|
+
alt?: string;
|
|
37
|
+
};
|
|
38
|
+
headline: string;
|
|
39
|
+
description: string;
|
|
40
|
+
href: string;
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const BpkContentCards = ({ cards, heading }: Props) => {
|
|
45
|
+
if (cards.length === 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div>
|
|
51
|
+
<BpkText
|
|
52
|
+
tagName="h2"
|
|
53
|
+
className={getClassName('bpk-content-cards--header-text')}
|
|
54
|
+
>
|
|
55
|
+
{heading}
|
|
56
|
+
</BpkText>
|
|
57
|
+
<div role="list" className={getClassName('bpk-content-cards--layout')}>
|
|
58
|
+
{cards.map((card) => (
|
|
59
|
+
<div role="listitem">
|
|
60
|
+
<BpkContentCard
|
|
61
|
+
key={card.image.url}
|
|
62
|
+
card={card}
|
|
63
|
+
layout={cards.length === 1 ? 'HORIZONTAL' : 'VERTICAL'}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default BpkContentCards;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Backpack - Skyscanner's Design System
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2016 Skyscanner Ltd
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import React from 'react';
|
|
20
|
+
import { render } from '@testing-library/react';
|
|
21
|
+
import { axe } from 'jest-axe';
|
|
22
|
+
|
|
23
|
+
import BpkContentCards from './BpkContentCards';
|
|
24
|
+
|
|
25
|
+
const heading = 'Header for the component';
|
|
26
|
+
const cards = [
|
|
27
|
+
{
|
|
28
|
+
image: {
|
|
29
|
+
url: 'http://skyscanner.net/card-1-image-link.jpg',
|
|
30
|
+
alt: '',
|
|
31
|
+
},
|
|
32
|
+
headline: 'Card 1 headline',
|
|
33
|
+
description: 'Card 1 description',
|
|
34
|
+
href: 'http://skyscanner.net/card-1-cta-link.html',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
image: {
|
|
38
|
+
url: 'http://skyscanner.net/card-2-image-link.jpg',
|
|
39
|
+
alt: '',
|
|
40
|
+
},
|
|
41
|
+
headline: 'Card 2 headline',
|
|
42
|
+
description: 'Card 2 description',
|
|
43
|
+
href: 'http://skyscanner.net/card-2-cta-link.html',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
image: {
|
|
47
|
+
url: 'http://skyscanner.net/card-3-image-link.jpg',
|
|
48
|
+
alt: '',
|
|
49
|
+
},
|
|
50
|
+
headline: 'Card 3 headline',
|
|
51
|
+
description: 'Card 3 description',
|
|
52
|
+
href: 'http://skyscanner.net/card-3-cta-link.html',
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
describe('BpkContentCards accessibility tests', () => {
|
|
57
|
+
it('should not have programmatically-detectable accessibility issues', async () => {
|
|
58
|
+
const { container } = render(
|
|
59
|
+
<BpkContentCards heading={heading} cards={cards} />,
|
|
60
|
+
);
|
|
61
|
+
const results = await axe(container);
|
|
62
|
+
expect(results).toHaveNoViolations();
|
|
63
|
+
});
|
|
64
|
+
});
|