@financial-times/cp-content-pipeline-ui 6.6.2 → 6.7.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/CHANGELOG.md +32 -0
- package/lib/components/Clip/client/index.d.ts +2 -0
- package/lib/components/Clip/client/index.js +27 -1
- package/lib/components/Clip/client/index.js.map +1 -1
- package/lib/components/Clip/components/Container.js +2 -2
- package/lib/components/Clip/components/Container.js.map +1 -1
- package/lib/components/Clip/components/VideoDescription.js +2 -2
- package/lib/components/Clip/components/VideoDescription.js.map +1 -1
- package/lib/components/Clip/components/VideoInfoBox.js +2 -2
- package/lib/components/Clip/components/VideoInfoBox.js.map +1 -1
- package/lib/components/Clip/template/index.js +0 -1
- package/lib/components/Clip/template/index.js.map +1 -1
- package/lib/components/Clip/test/index.spec.js +30 -0
- package/lib/components/Clip/test/index.spec.js.map +1 -1
- package/lib/components/Expander/client/index.d.ts +49 -0
- package/lib/components/Expander/client/index.js +124 -0
- package/lib/components/Expander/client/index.js.map +1 -0
- package/lib/components/Expander/index.d.ts +15 -0
- package/lib/components/Expander/index.js +27 -0
- package/lib/components/Expander/index.js.map +1 -0
- package/lib/components/Expander/test/client/index.spec.d.ts +1 -0
- package/lib/components/Expander/test/client/index.spec.js +103 -0
- package/lib/components/Expander/test/client/index.spec.js.map +1 -0
- package/lib/components/Expander/test/index.spec.d.ts +1 -0
- package/lib/components/Expander/test/index.spec.js +57 -0
- package/lib/components/Expander/test/index.spec.js.map +1 -0
- package/lib/components/Expander/test/snapshot.spec.d.ts +1 -0
- package/lib/components/Expander/test/snapshot.spec.js +63 -0
- package/lib/components/Expander/test/snapshot.spec.js.map +1 -0
- package/lib/components/ImageSet/index.js +1 -1
- package/lib/components/ImageSet/index.js.map +1 -1
- package/lib/components/LiveBlogPost/client/index.d.ts +5 -0
- package/lib/components/LiveBlogPost/client/index.js +12 -0
- package/lib/components/LiveBlogPost/client/index.js.map +1 -0
- package/lib/components/LiveBlogPost/index.js +9 -21
- package/lib/components/LiveBlogPost/index.js.map +1 -1
- package/lib/components/LiveBlogWrapper/index.js +1 -1
- package/lib/components/LiveBlogWrapper/index.js.map +1 -1
- package/lib/components/Recommended/index.js +1 -1
- package/lib/components/Recommended/index.js.map +1 -1
- package/lib/components/RichText/index.d.ts +1 -1
- package/lib/components/Table/index.js +1 -1
- package/lib/components/Table/index.js.map +1 -1
- package/lib/components/Video/index.js +1 -1
- package/lib/components/Video/index.js.map +1 -1
- package/lib/components/YoutubeVideo/index.js +1 -1
- package/lib/components/YoutubeVideo/index.js.map +1 -1
- package/lib/stories/Clip.stories.d.ts +2 -1
- package/lib/stories/Clip.stories.js +5 -5
- package/lib/stories/Clip.stories.js.map +1 -1
- package/lib/stories/Expander.stories.d.ts +54 -0
- package/lib/stories/Expander.stories.js +142 -0
- package/lib/stories/Expander.stories.js.map +1 -0
- package/package.json +3 -5
- package/src/components/Clip/client/index.ts +39 -1
- package/src/components/Clip/client/main.scss +28 -0
- package/src/components/Clip/components/Container.tsx +10 -3
- package/src/components/Clip/components/VideoDescription.tsx +5 -3
- package/src/components/Clip/components/VideoInfoBox.tsx +3 -3
- package/src/components/Clip/components/_video-info-box.scss +0 -4
- package/src/components/Clip/template/index.ts +0 -1
- package/src/components/Clip/test/__snapshots__/snapshot.spec.tsx.snap +57 -47
- package/src/components/Clip/test/index.spec.ts +45 -0
- package/src/components/Expander/client/index.ts +197 -0
- package/src/components/Expander/client/main.scss +162 -0
- package/src/components/Expander/index.tsx +74 -0
- package/src/components/Expander/test/__snapshots__/snapshot.spec.tsx.snap +225 -0
- package/src/components/Expander/test/client/index.spec.tsx +129 -0
- package/src/components/Expander/test/index.spec.tsx +77 -0
- package/src/components/Expander/test/snapshot.spec.tsx +73 -0
- package/src/components/ImageSet/index.tsx +1 -0
- package/src/components/LiveBlogPost/client/index.ts +9 -0
- package/src/components/LiveBlogPost/index.tsx +29 -42
- package/src/components/LiveBlogWrapper/index.tsx +1 -0
- package/src/components/Recommended/index.tsx +1 -0
- package/src/components/Table/index.tsx +1 -0
- package/src/components/Video/index.tsx +4 -1
- package/src/components/YoutubeVideo/index.tsx +4 -1
- package/src/stories/Clip.stories.tsx +3 -2
- package/src/stories/Expander.stories.scss +3 -0
- package/src/stories/Expander.stories.tsx +159 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
@import '@financial-times/o-icons/main';
|
|
2
|
+
@import '@financial-times/o-colors/main';
|
|
3
|
+
@import '@financial-times/o-grid/main';
|
|
4
|
+
@import '@financial-times/o-spacing/main';
|
|
5
|
+
|
|
6
|
+
$numberIntroductoryElements: 1;
|
|
7
|
+
$dataComponentVisibleElements: (
|
|
8
|
+
'clip-set',
|
|
9
|
+
'recommended',
|
|
10
|
+
'flourish',
|
|
11
|
+
'image-set',
|
|
12
|
+
'video',
|
|
13
|
+
'youtube-video',
|
|
14
|
+
'table'
|
|
15
|
+
);
|
|
16
|
+
$alwaysVisibleComponentSelectors: ();
|
|
17
|
+
|
|
18
|
+
@each $component-name in $dataComponentVisibleElements {
|
|
19
|
+
$alwaysVisibleComponentSelectors: append(
|
|
20
|
+
$alwaysVisibleComponentSelectors,
|
|
21
|
+
'[data-component="#{$component-name}"]'
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
@mixin AlwaysVisibleElements {
|
|
25
|
+
@each $component in $alwaysVisibleComponentSelectors {
|
|
26
|
+
#{$component} {
|
|
27
|
+
display: block;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
@mixin IntroductoryElements {
|
|
32
|
+
& > :nth-child(-n + #{$numberIntroductoryElements + 1}):not(.cp-expander__expand) {
|
|
33
|
+
display: block;
|
|
34
|
+
order:1
|
|
35
|
+
}
|
|
36
|
+
& > :nth-child(n + #{$numberIntroductoryElements + 1}) {
|
|
37
|
+
order:3
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
@mixin expandeAndCollapse {
|
|
41
|
+
&[data-state='expanded'] {
|
|
42
|
+
.cp-expander-content {
|
|
43
|
+
// Show all the hidden children...
|
|
44
|
+
& > * {
|
|
45
|
+
display: block;
|
|
46
|
+
}
|
|
47
|
+
> .cp-expander__expand {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
&[data-state='collapsed'] {
|
|
56
|
+
.cp-expander-content {
|
|
57
|
+
// Hide everything that comes after the expander...
|
|
58
|
+
// ... except the always visible children
|
|
59
|
+
& > * {
|
|
60
|
+
display: none;
|
|
61
|
+
}
|
|
62
|
+
&:target > * {
|
|
63
|
+
display: block;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
> .cp-expander__expand {
|
|
67
|
+
display: block;
|
|
68
|
+
order: 2;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
> .cp-expander__collapse {
|
|
72
|
+
display: none;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@include AlwaysVisibleElements;
|
|
76
|
+
|
|
77
|
+
@include IntroductoryElements;
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@mixin InnerStyles {
|
|
85
|
+
|
|
86
|
+
&.cp-expander--not-initialised {
|
|
87
|
+
|
|
88
|
+
.cp-expander__expand,
|
|
89
|
+
.cp-expander__collapse {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.cp-expander-content {
|
|
94
|
+
// Target is used for the Core experience.
|
|
95
|
+
// It permits us to hide elements server-side via CSS preventing Cumulative Shift but it is also a fully functional solution without Javascript
|
|
96
|
+
&:target{
|
|
97
|
+
.cp-expander__collapse{
|
|
98
|
+
display: block;
|
|
99
|
+
}
|
|
100
|
+
.cp-expander__expand{
|
|
101
|
+
display: none;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
.cp-expander__expand,
|
|
107
|
+
.cp-expander__collapse {
|
|
108
|
+
display: block;
|
|
109
|
+
padding-bottom: oSpacingByName('s6');
|
|
110
|
+
> a {
|
|
111
|
+
$icon-color: oColorsByName('ft-grey');
|
|
112
|
+
--_o-typography-body-color: $icon-color;
|
|
113
|
+
font-feature-settings: 'clig' off, 'liga' off;
|
|
114
|
+
|
|
115
|
+
@include oTypographyBody();
|
|
116
|
+
font-weight: 400;
|
|
117
|
+
text-decoration: none;
|
|
118
|
+
font-size: 20px;
|
|
119
|
+
&:hover {
|
|
120
|
+
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
&:after {
|
|
125
|
+
content: '';
|
|
126
|
+
@include oIconsContent('arrow-down', $icon-color, $size: 20);
|
|
127
|
+
padding: 0 4px;
|
|
128
|
+
vertical-align: middle;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.cp-expander__collapse a:after {
|
|
134
|
+
transform: rotate(180deg);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.cp-expander-content {
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@include expandeAndCollapse;
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.cp-expander{
|
|
148
|
+
&.cp-expander--mobile-only {
|
|
149
|
+
.cp-expander__expand,
|
|
150
|
+
.cp-expander__collapse {
|
|
151
|
+
display: none;
|
|
152
|
+
}
|
|
153
|
+
@include oGridRespondTo($until: S) {
|
|
154
|
+
@include InnerStyles;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
&.cp-expander--all-resolutions {
|
|
159
|
+
@include InnerStyles;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import classnames from 'classnames'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
export interface ExpanderProps extends React.PropsWithChildren {
|
|
5
|
+
/** The initial state of the expander */
|
|
6
|
+
state?: 'expanded' | 'collapsed'
|
|
7
|
+
/** The label for the Expand CTA */
|
|
8
|
+
expandLabel?: string
|
|
9
|
+
/** The label for the collapse CTA */
|
|
10
|
+
collapseLabel?: string
|
|
11
|
+
/** Show the expander only on mobile resolutions */
|
|
12
|
+
onlyMobile?: boolean
|
|
13
|
+
/** Id of the component */
|
|
14
|
+
id: string
|
|
15
|
+
}
|
|
16
|
+
// React functional component with children
|
|
17
|
+
export const ExpanderServer: React.FC<ExpanderProps> = ({
|
|
18
|
+
state = 'collapsed', // default value for "state
|
|
19
|
+
children,
|
|
20
|
+
id,
|
|
21
|
+
expandLabel = 'Expand',
|
|
22
|
+
collapseLabel = 'Collapse',
|
|
23
|
+
onlyMobile = false,
|
|
24
|
+
}) => {
|
|
25
|
+
return (
|
|
26
|
+
<div
|
|
27
|
+
className={classnames({
|
|
28
|
+
'cp-expander': true,
|
|
29
|
+
'cp-expander--mobile-only': onlyMobile,
|
|
30
|
+
'cp-expander--all-resolutions': !onlyMobile,
|
|
31
|
+
'cp-expander--not-initialised': true,
|
|
32
|
+
})}
|
|
33
|
+
data-component="expander"
|
|
34
|
+
data-state={state}
|
|
35
|
+
id={`${id}__container`}
|
|
36
|
+
>
|
|
37
|
+
<div id={id} className="cp-expander-content" aria-describedby={id}>
|
|
38
|
+
<div className="cp-expander__expand">
|
|
39
|
+
<a
|
|
40
|
+
data-trackable="truncated-post"
|
|
41
|
+
data-trackable-context-truncated-post="expand"
|
|
42
|
+
data-trackable-context-truncated-id={id}
|
|
43
|
+
className="cp-expander__link"
|
|
44
|
+
href={`#${id}`}
|
|
45
|
+
aria-expanded={state === 'expanded' ? true : false}
|
|
46
|
+
aria-controls={id}
|
|
47
|
+
aria-hidden={state === 'expanded' ? true : false}
|
|
48
|
+
data-action="expand"
|
|
49
|
+
>
|
|
50
|
+
{expandLabel}
|
|
51
|
+
</a>
|
|
52
|
+
</div>
|
|
53
|
+
{children}
|
|
54
|
+
<div className="cp-expander__collapse">
|
|
55
|
+
<a
|
|
56
|
+
data-trackable="truncated-post"
|
|
57
|
+
data-trackable-context-truncated-post="collapse"
|
|
58
|
+
data-trackable-context-truncated-id={id}
|
|
59
|
+
href={`#${id}__container`}
|
|
60
|
+
className="cp-expander__link"
|
|
61
|
+
aria-expanded={state === 'expanded' ? true : false}
|
|
62
|
+
aria-controls={id}
|
|
63
|
+
aria-hidden={state === 'expanded' ? false : true}
|
|
64
|
+
data-action="collapse"
|
|
65
|
+
>
|
|
66
|
+
{collapseLabel}
|
|
67
|
+
</a>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default ExpanderServer
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Expander Snapshot component rendered on server default render 1`] = `
|
|
4
|
+
<div
|
|
5
|
+
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
6
|
+
data-component="expander"
|
|
7
|
+
data-state="collapsed"
|
|
8
|
+
id="test-id__container"
|
|
9
|
+
>
|
|
10
|
+
<div
|
|
11
|
+
aria-describedby="test-id"
|
|
12
|
+
className="cp-expander-content"
|
|
13
|
+
id="test-id"
|
|
14
|
+
>
|
|
15
|
+
<div
|
|
16
|
+
className="cp-expander__expand"
|
|
17
|
+
>
|
|
18
|
+
<a
|
|
19
|
+
aria-controls="test-id"
|
|
20
|
+
aria-expanded={false}
|
|
21
|
+
aria-hidden={false}
|
|
22
|
+
className="cp-expander__link"
|
|
23
|
+
data-action="expand"
|
|
24
|
+
data-trackable="truncated-post"
|
|
25
|
+
data-trackable-context-truncated-id="test-id"
|
|
26
|
+
data-trackable-context-truncated-post="expand"
|
|
27
|
+
href="#test-id"
|
|
28
|
+
>
|
|
29
|
+
Expand
|
|
30
|
+
</a>
|
|
31
|
+
</div>
|
|
32
|
+
<div>
|
|
33
|
+
Children 1
|
|
34
|
+
</div>
|
|
35
|
+
<div>
|
|
36
|
+
Children 2
|
|
37
|
+
</div>
|
|
38
|
+
<div
|
|
39
|
+
className="cp-expander__collapse"
|
|
40
|
+
>
|
|
41
|
+
<a
|
|
42
|
+
aria-controls="test-id"
|
|
43
|
+
aria-expanded={false}
|
|
44
|
+
aria-hidden={true}
|
|
45
|
+
className="cp-expander__link"
|
|
46
|
+
data-action="collapse"
|
|
47
|
+
data-trackable="truncated-post"
|
|
48
|
+
data-trackable-context-truncated-id="test-id"
|
|
49
|
+
data-trackable-context-truncated-post="collapse"
|
|
50
|
+
href="#test-id__container"
|
|
51
|
+
>
|
|
52
|
+
Collapse
|
|
53
|
+
</a>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</div>
|
|
57
|
+
`;
|
|
58
|
+
|
|
59
|
+
exports[`Expander Snapshot component rendered on server only on mobile 1`] = `
|
|
60
|
+
<div
|
|
61
|
+
className="cp-expander cp-expander--mobile-only cp-expander--not-initialised"
|
|
62
|
+
data-component="expander"
|
|
63
|
+
data-state="collapsed"
|
|
64
|
+
id="test-id__container"
|
|
65
|
+
>
|
|
66
|
+
<div
|
|
67
|
+
aria-describedby="test-id"
|
|
68
|
+
className="cp-expander-content"
|
|
69
|
+
id="test-id"
|
|
70
|
+
>
|
|
71
|
+
<div
|
|
72
|
+
className="cp-expander__expand"
|
|
73
|
+
>
|
|
74
|
+
<a
|
|
75
|
+
aria-controls="test-id"
|
|
76
|
+
aria-expanded={false}
|
|
77
|
+
aria-hidden={false}
|
|
78
|
+
className="cp-expander__link"
|
|
79
|
+
data-action="expand"
|
|
80
|
+
data-trackable="truncated-post"
|
|
81
|
+
data-trackable-context-truncated-id="test-id"
|
|
82
|
+
data-trackable-context-truncated-post="expand"
|
|
83
|
+
href="#test-id"
|
|
84
|
+
>
|
|
85
|
+
Expand
|
|
86
|
+
</a>
|
|
87
|
+
</div>
|
|
88
|
+
<div>
|
|
89
|
+
Children 1
|
|
90
|
+
</div>
|
|
91
|
+
<div>
|
|
92
|
+
Children 2
|
|
93
|
+
</div>
|
|
94
|
+
<div
|
|
95
|
+
className="cp-expander__collapse"
|
|
96
|
+
>
|
|
97
|
+
<a
|
|
98
|
+
aria-controls="test-id"
|
|
99
|
+
aria-expanded={false}
|
|
100
|
+
aria-hidden={true}
|
|
101
|
+
className="cp-expander__link"
|
|
102
|
+
data-action="collapse"
|
|
103
|
+
data-trackable="truncated-post"
|
|
104
|
+
data-trackable-context-truncated-id="test-id"
|
|
105
|
+
data-trackable-context-truncated-post="collapse"
|
|
106
|
+
href="#test-id__container"
|
|
107
|
+
>
|
|
108
|
+
Collapse
|
|
109
|
+
</a>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
exports[`Expander Snapshot component rendered on server with different labels 1`] = `
|
|
116
|
+
<div
|
|
117
|
+
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
118
|
+
data-component="expander"
|
|
119
|
+
data-state="collapsed"
|
|
120
|
+
id="test-id__container"
|
|
121
|
+
>
|
|
122
|
+
<div
|
|
123
|
+
aria-describedby="test-id"
|
|
124
|
+
className="cp-expander-content"
|
|
125
|
+
id="test-id"
|
|
126
|
+
>
|
|
127
|
+
<div
|
|
128
|
+
className="cp-expander__expand"
|
|
129
|
+
>
|
|
130
|
+
<a
|
|
131
|
+
aria-controls="test-id"
|
|
132
|
+
aria-expanded={false}
|
|
133
|
+
aria-hidden={false}
|
|
134
|
+
className="cp-expander__link"
|
|
135
|
+
data-action="expand"
|
|
136
|
+
data-trackable="truncated-post"
|
|
137
|
+
data-trackable-context-truncated-id="test-id"
|
|
138
|
+
data-trackable-context-truncated-post="expand"
|
|
139
|
+
href="#test-id"
|
|
140
|
+
>
|
|
141
|
+
Open
|
|
142
|
+
</a>
|
|
143
|
+
</div>
|
|
144
|
+
<div>
|
|
145
|
+
Children 1
|
|
146
|
+
</div>
|
|
147
|
+
<div>
|
|
148
|
+
Children 2
|
|
149
|
+
</div>
|
|
150
|
+
<div
|
|
151
|
+
className="cp-expander__collapse"
|
|
152
|
+
>
|
|
153
|
+
<a
|
|
154
|
+
aria-controls="test-id"
|
|
155
|
+
aria-expanded={false}
|
|
156
|
+
aria-hidden={true}
|
|
157
|
+
className="cp-expander__link"
|
|
158
|
+
data-action="collapse"
|
|
159
|
+
data-trackable="truncated-post"
|
|
160
|
+
data-trackable-context-truncated-id="test-id"
|
|
161
|
+
data-trackable-context-truncated-post="collapse"
|
|
162
|
+
href="#test-id__container"
|
|
163
|
+
>
|
|
164
|
+
Close
|
|
165
|
+
</a>
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
</div>
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
exports[`Expander Snapshot component rendered on server with different state 1`] = `
|
|
172
|
+
<div
|
|
173
|
+
className="cp-expander cp-expander--all-resolutions cp-expander--not-initialised"
|
|
174
|
+
data-component="expander"
|
|
175
|
+
data-state="expanded"
|
|
176
|
+
id="test-id__container"
|
|
177
|
+
>
|
|
178
|
+
<div
|
|
179
|
+
aria-describedby="test-id"
|
|
180
|
+
className="cp-expander-content"
|
|
181
|
+
id="test-id"
|
|
182
|
+
>
|
|
183
|
+
<div
|
|
184
|
+
className="cp-expander__expand"
|
|
185
|
+
>
|
|
186
|
+
<a
|
|
187
|
+
aria-controls="test-id"
|
|
188
|
+
aria-expanded={true}
|
|
189
|
+
aria-hidden={true}
|
|
190
|
+
className="cp-expander__link"
|
|
191
|
+
data-action="expand"
|
|
192
|
+
data-trackable="truncated-post"
|
|
193
|
+
data-trackable-context-truncated-id="test-id"
|
|
194
|
+
data-trackable-context-truncated-post="expand"
|
|
195
|
+
href="#test-id"
|
|
196
|
+
>
|
|
197
|
+
Expand
|
|
198
|
+
</a>
|
|
199
|
+
</div>
|
|
200
|
+
<div>
|
|
201
|
+
Children 1
|
|
202
|
+
</div>
|
|
203
|
+
<div>
|
|
204
|
+
Children 2
|
|
205
|
+
</div>
|
|
206
|
+
<div
|
|
207
|
+
className="cp-expander__collapse"
|
|
208
|
+
>
|
|
209
|
+
<a
|
|
210
|
+
aria-controls="test-id"
|
|
211
|
+
aria-expanded={true}
|
|
212
|
+
aria-hidden={false}
|
|
213
|
+
className="cp-expander__link"
|
|
214
|
+
data-action="collapse"
|
|
215
|
+
data-trackable="truncated-post"
|
|
216
|
+
data-trackable-context-truncated-id="test-id"
|
|
217
|
+
data-trackable-context-truncated-post="collapse"
|
|
218
|
+
href="#test-id__container"
|
|
219
|
+
>
|
|
220
|
+
Collapse
|
|
221
|
+
</a>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
`;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import Expander, { ExpanderProps } from '../../index'
|
|
6
|
+
import { ExpanderClient } from '../../client'
|
|
7
|
+
import { render, screen } from '@testing-library/react'
|
|
8
|
+
|
|
9
|
+
//mock IntersectionObserver
|
|
10
|
+
class IntersectionObserver {
|
|
11
|
+
//mock constructor
|
|
12
|
+
constructor(callback) {
|
|
13
|
+
this.callback = callback
|
|
14
|
+
}
|
|
15
|
+
observe() {
|
|
16
|
+
this.active = true
|
|
17
|
+
}
|
|
18
|
+
disconnect() {
|
|
19
|
+
this.active = false
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
intersects() {
|
|
23
|
+
if (this.active) {
|
|
24
|
+
this.callback([{ isIntersecting: true }])
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//mock scrollIntoView
|
|
30
|
+
window.HTMLElement.prototype.scrollIntoView = jest.fn()
|
|
31
|
+
|
|
32
|
+
describe('Expander client test', () => {
|
|
33
|
+
beforeEach(() => {
|
|
34
|
+
window.IntersectionObserver = IntersectionObserver
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('find expanders markup and initialises it', () => {
|
|
38
|
+
const props: ExpanderProps = {
|
|
39
|
+
id: 'test-id',
|
|
40
|
+
}
|
|
41
|
+
render(
|
|
42
|
+
<Expander {...props}>
|
|
43
|
+
<div>Children 1</div>
|
|
44
|
+
</Expander>
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const expanders = ExpanderClient.init()
|
|
48
|
+
expect(expanders.length).toBe(1)
|
|
49
|
+
expect(
|
|
50
|
+
document.querySelectorAll("[data-component='expander']").length
|
|
51
|
+
).toBe(1)
|
|
52
|
+
expect(expanders[0].container.id).toBe('test-id__container')
|
|
53
|
+
expect(
|
|
54
|
+
expanders[0].container.classList.contains('cp-expander--initialised')
|
|
55
|
+
).toBe(true)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('do not initialised twice expanders', () => {
|
|
59
|
+
const props: ExpanderProps = {
|
|
60
|
+
id: 'test-id',
|
|
61
|
+
}
|
|
62
|
+
render(
|
|
63
|
+
<Expander {...props}>
|
|
64
|
+
<div>Children 1</div>
|
|
65
|
+
</Expander>
|
|
66
|
+
)
|
|
67
|
+
ExpanderClient.init()
|
|
68
|
+
const expanders = ExpanderClient.init()
|
|
69
|
+
|
|
70
|
+
expect(expanders.length).toBe(0)
|
|
71
|
+
expect(
|
|
72
|
+
document.querySelectorAll("[data-component='expander']").length
|
|
73
|
+
).toBe(1)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('expands and collapse', async () => {
|
|
77
|
+
const props: ExpanderProps = {
|
|
78
|
+
id: 'test-id',
|
|
79
|
+
}
|
|
80
|
+
render(
|
|
81
|
+
<Expander {...props}>
|
|
82
|
+
<div>Children 1</div>
|
|
83
|
+
</Expander>
|
|
84
|
+
)
|
|
85
|
+
const expanders = ExpanderClient.init()
|
|
86
|
+
const expanderButton = screen.getByText('Expand')
|
|
87
|
+
const collapserButton = screen.getByText('Collapse')
|
|
88
|
+
expect(expanderButton.getAttribute('aria-expanded')).toBe('false')
|
|
89
|
+
expect(expanderButton.getAttribute('aria-hidden')).toBe('false')
|
|
90
|
+
expect(collapserButton.getAttribute('aria-expanded')).toBe('false')
|
|
91
|
+
expect(collapserButton.getAttribute('aria-hidden')).toBe('true')
|
|
92
|
+
|
|
93
|
+
await expanderButton.click()
|
|
94
|
+
expect(expanderButton.getAttribute('aria-expanded')).toBe('true')
|
|
95
|
+
expect(expanders[0].container?.getAttribute('data-state')).toBe('expanded')
|
|
96
|
+
expect(expanderButton.getAttribute('aria-expanded')).toBe('true')
|
|
97
|
+
expect(expanderButton.getAttribute('aria-hidden')).toBe('true')
|
|
98
|
+
expect(collapserButton.getAttribute('aria-expanded')).toBe('true')
|
|
99
|
+
expect(collapserButton.getAttribute('aria-hidden')).toBe('false')
|
|
100
|
+
|
|
101
|
+
await collapserButton.click()
|
|
102
|
+
expect(expanders[0].container?.getAttribute('data-state')).toBe('collapsed')
|
|
103
|
+
expect(expanderButton.getAttribute('aria-expanded')).toBe('false')
|
|
104
|
+
expect(expanderButton.getAttribute('aria-hidden')).toBe('false')
|
|
105
|
+
expect(collapserButton.getAttribute('aria-expanded')).toBe('false')
|
|
106
|
+
expect(collapserButton.getAttribute('aria-hidden')).toBe('true')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('track entire read only once', () => {
|
|
110
|
+
const props: ExpanderProps = {
|
|
111
|
+
id: 'test-id',
|
|
112
|
+
}
|
|
113
|
+
render(
|
|
114
|
+
<Expander {...props}>
|
|
115
|
+
<div>Children 1</div>
|
|
116
|
+
</Expander>
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const expanders = ExpanderClient.init()
|
|
120
|
+
const spy = jest.spyOn(document.body, 'dispatchEvent')
|
|
121
|
+
spy.mockImplementation((event) => {
|
|
122
|
+
expect(event.detail.action).toBe('entire_read')
|
|
123
|
+
})
|
|
124
|
+
expanders[0].trackingEntireRead.observer.intersects()
|
|
125
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
126
|
+
expanders[0].trackingEntireRead.observer.intersects()
|
|
127
|
+
expect(spy).toHaveBeenCalledTimes(1)
|
|
128
|
+
})
|
|
129
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
import Expander, { ExpanderProps } from '../index'
|
|
6
|
+
import { render, screen } from '@testing-library/react'
|
|
7
|
+
|
|
8
|
+
describe('Expander template', () => {
|
|
9
|
+
it('renders', () => {
|
|
10
|
+
const props: ExpanderProps = {
|
|
11
|
+
id: 'test-id',
|
|
12
|
+
}
|
|
13
|
+
const tree = render(
|
|
14
|
+
<Expander {...props}>
|
|
15
|
+
<div>Children 1</div>
|
|
16
|
+
<div>Children 2</div>
|
|
17
|
+
</Expander>
|
|
18
|
+
)
|
|
19
|
+
expect(
|
|
20
|
+
tree.container.querySelector('[data-component="expander"]')
|
|
21
|
+
).toBeTruthy()
|
|
22
|
+
expect(
|
|
23
|
+
tree.container.querySelector('[data-state="collapsed"]')
|
|
24
|
+
).toBeTruthy()
|
|
25
|
+
expect(
|
|
26
|
+
tree.container.querySelector('.cp-expander--not-initialised')
|
|
27
|
+
).toBeTruthy()
|
|
28
|
+
expect(screen.getByText('Expand')).toBeTruthy()
|
|
29
|
+
expect(screen.getByText('Collapse')).toBeTruthy()
|
|
30
|
+
expect(screen.getByText('Children 1')).toBeTruthy()
|
|
31
|
+
expect(screen.getByText('Children 2')).toBeTruthy()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('with different labels', () => {
|
|
35
|
+
const props: ExpanderProps = {
|
|
36
|
+
id: 'test-id',
|
|
37
|
+
collapseLabel: 'Close',
|
|
38
|
+
expandLabel: 'Open',
|
|
39
|
+
}
|
|
40
|
+
render(
|
|
41
|
+
<Expander {...props}>
|
|
42
|
+
<div>Children</div>
|
|
43
|
+
</Expander>
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
expect(screen.getByText('Open')).toBeTruthy()
|
|
47
|
+
expect(screen.getByText('Close')).toBeTruthy()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('with different state', () => {
|
|
51
|
+
const props: ExpanderProps = {
|
|
52
|
+
id: 'test-id',
|
|
53
|
+
state: 'expanded',
|
|
54
|
+
}
|
|
55
|
+
const tree = render(
|
|
56
|
+
<Expander {...props}>
|
|
57
|
+
<div>Children</div>
|
|
58
|
+
</Expander>
|
|
59
|
+
)
|
|
60
|
+
expect(tree.container.querySelector('[data-state="expanded"]')).toBeTruthy()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('add class for only mobile', () => {
|
|
64
|
+
const props: ExpanderProps = {
|
|
65
|
+
id: 'test-id',
|
|
66
|
+
onlyMobile: true,
|
|
67
|
+
}
|
|
68
|
+
const tree = render(
|
|
69
|
+
<Expander {...props}>
|
|
70
|
+
<div>Children</div>
|
|
71
|
+
</Expander>
|
|
72
|
+
)
|
|
73
|
+
expect(
|
|
74
|
+
tree.container.querySelector('.cp-expander--mobile-only')
|
|
75
|
+
).toBeTruthy()
|
|
76
|
+
})
|
|
77
|
+
})
|