@financial-times/cp-content-pipeline-ui 6.6.3 → 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.
Files changed (75) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/components/Clip/client/index.d.ts +2 -0
  3. package/lib/components/Clip/client/index.js +25 -0
  4. package/lib/components/Clip/client/index.js.map +1 -1
  5. package/lib/components/Clip/components/Container.js +2 -2
  6. package/lib/components/Clip/components/Container.js.map +1 -1
  7. package/lib/components/Clip/template/index.js +0 -1
  8. package/lib/components/Clip/template/index.js.map +1 -1
  9. package/lib/components/Clip/test/index.spec.js +30 -0
  10. package/lib/components/Clip/test/index.spec.js.map +1 -1
  11. package/lib/components/Expander/client/index.d.ts +49 -0
  12. package/lib/components/Expander/client/index.js +124 -0
  13. package/lib/components/Expander/client/index.js.map +1 -0
  14. package/lib/components/Expander/index.d.ts +15 -0
  15. package/lib/components/Expander/index.js +27 -0
  16. package/lib/components/Expander/index.js.map +1 -0
  17. package/lib/components/Expander/test/client/index.spec.d.ts +1 -0
  18. package/lib/components/Expander/test/client/index.spec.js +103 -0
  19. package/lib/components/Expander/test/client/index.spec.js.map +1 -0
  20. package/lib/components/Expander/test/index.spec.d.ts +1 -0
  21. package/lib/components/Expander/test/index.spec.js +57 -0
  22. package/lib/components/Expander/test/index.spec.js.map +1 -0
  23. package/lib/components/Expander/test/snapshot.spec.d.ts +1 -0
  24. package/lib/components/Expander/test/snapshot.spec.js +63 -0
  25. package/lib/components/Expander/test/snapshot.spec.js.map +1 -0
  26. package/lib/components/ImageSet/index.js +1 -1
  27. package/lib/components/ImageSet/index.js.map +1 -1
  28. package/lib/components/LiveBlogPost/client/index.d.ts +5 -0
  29. package/lib/components/LiveBlogPost/client/index.js +12 -0
  30. package/lib/components/LiveBlogPost/client/index.js.map +1 -0
  31. package/lib/components/LiveBlogPost/index.js +9 -21
  32. package/lib/components/LiveBlogPost/index.js.map +1 -1
  33. package/lib/components/LiveBlogWrapper/index.js +1 -1
  34. package/lib/components/LiveBlogWrapper/index.js.map +1 -1
  35. package/lib/components/Recommended/index.js +1 -1
  36. package/lib/components/Recommended/index.js.map +1 -1
  37. package/lib/components/RichText/index.d.ts +1 -1
  38. package/lib/components/Table/index.js +1 -1
  39. package/lib/components/Table/index.js.map +1 -1
  40. package/lib/components/Video/index.js +1 -1
  41. package/lib/components/Video/index.js.map +1 -1
  42. package/lib/components/YoutubeVideo/index.js +1 -1
  43. package/lib/components/YoutubeVideo/index.js.map +1 -1
  44. package/lib/stories/Clip.stories.d.ts +2 -1
  45. package/lib/stories/Clip.stories.js +5 -5
  46. package/lib/stories/Clip.stories.js.map +1 -1
  47. package/lib/stories/Expander.stories.d.ts +54 -0
  48. package/lib/stories/Expander.stories.js +142 -0
  49. package/lib/stories/Expander.stories.js.map +1 -0
  50. package/package.json +3 -5
  51. package/src/components/Clip/client/index.ts +37 -0
  52. package/src/components/Clip/client/main.scss +28 -0
  53. package/src/components/Clip/components/Container.tsx +10 -3
  54. package/src/components/Clip/template/index.ts +0 -1
  55. package/src/components/Clip/test/__snapshots__/snapshot.spec.tsx.snap +8 -8
  56. package/src/components/Clip/test/index.spec.ts +45 -0
  57. package/src/components/Expander/client/index.ts +197 -0
  58. package/src/components/Expander/client/main.scss +162 -0
  59. package/src/components/Expander/index.tsx +74 -0
  60. package/src/components/Expander/test/__snapshots__/snapshot.spec.tsx.snap +225 -0
  61. package/src/components/Expander/test/client/index.spec.tsx +129 -0
  62. package/src/components/Expander/test/index.spec.tsx +77 -0
  63. package/src/components/Expander/test/snapshot.spec.tsx +73 -0
  64. package/src/components/ImageSet/index.tsx +1 -0
  65. package/src/components/LiveBlogPost/client/index.ts +9 -0
  66. package/src/components/LiveBlogPost/index.tsx +29 -42
  67. package/src/components/LiveBlogWrapper/index.tsx +1 -0
  68. package/src/components/Recommended/index.tsx +1 -0
  69. package/src/components/Table/index.tsx +1 -0
  70. package/src/components/Video/index.tsx +4 -1
  71. package/src/components/YoutubeVideo/index.tsx +4 -1
  72. package/src/stories/Clip.stories.tsx +3 -2
  73. package/src/stories/Expander.stories.scss +3 -0
  74. package/src/stories/Expander.stories.tsx +159 -0
  75. package/tsconfig.tsbuildinfo +1 -1
@@ -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
+ })
@@ -0,0 +1,73 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-nocheck
3
+ import React from 'react'
4
+ import renderer from 'react-test-renderer'
5
+ import Expander, { ExpanderProps } from '../index'
6
+
7
+ describe('Expander Snapshot', () => {
8
+ describe('component rendered on server', () => {
9
+ it('default render', () => {
10
+ const props: ExpanderProps = {
11
+ id: 'test-id',
12
+ }
13
+ const tree = renderer
14
+ .create(
15
+ <Expander {...props}>
16
+ <div>Children 1</div>
17
+ <div>Children 2</div>
18
+ </Expander>
19
+ )
20
+ .toJSON()
21
+ expect(tree).toMatchSnapshot()
22
+ })
23
+
24
+ it('only on mobile', () => {
25
+ const props: ExpanderProps = {
26
+ id: 'test-id',
27
+ onlyMobile: true,
28
+ }
29
+ const tree = renderer
30
+ .create(
31
+ <Expander {...props}>
32
+ <div>Children 1</div>
33
+ <div>Children 2</div>
34
+ </Expander>
35
+ )
36
+ .toJSON()
37
+ expect(tree).toMatchSnapshot()
38
+ })
39
+
40
+ it('with different labels', () => {
41
+ const props: ExpanderProps = {
42
+ id: 'test-id',
43
+ collapseLabel: 'Close',
44
+ expandLabel: 'Open',
45
+ }
46
+ const tree = renderer
47
+ .create(
48
+ <Expander {...props}>
49
+ <div>Children 1</div>
50
+ <div>Children 2</div>
51
+ </Expander>
52
+ )
53
+ .toJSON()
54
+ expect(tree).toMatchSnapshot()
55
+ })
56
+
57
+ it('with different state', () => {
58
+ const props: ExpanderProps = {
59
+ id: 'test-id',
60
+ state: 'expanded',
61
+ }
62
+ const tree = renderer
63
+ .create(
64
+ <Expander {...props}>
65
+ <div>Children 1</div>
66
+ <div>Children 2</div>
67
+ </Expander>
68
+ )
69
+ .toJSON()
70
+ expect(tree).toMatchSnapshot()
71
+ })
72
+ })
73
+ })
@@ -212,6 +212,7 @@ export default function ImageSet(
212
212
  'n-content-image'
213
213
  }
214
214
  style={figureWidth(imageSet.picture)}
215
+ data-component="image-set"
215
216
  >
216
217
  <picture>
217
218
  <Sources images={imageSet.picture.images} />
@@ -0,0 +1,9 @@
1
+ import { ExpanderClient } from '../../Expander/client'
2
+
3
+ export class LiveBlogPostClient {
4
+ static init() {
5
+ return ExpanderClient.init({ trackingData: { category: 'live-blog-post' } })
6
+ }
7
+ }
8
+
9
+ export default LiveBlogPostClient
@@ -2,10 +2,13 @@ import React from 'react'
2
2
  import ShareButtons from './ShareButtons'
3
3
  import Timestamp from './Timestamp'
4
4
  import RichText from '../RichText'
5
+ import Expander from '../Expander'
5
6
  import classnames from 'classnames'
6
7
  import Headshot from '../Headshot'
7
8
  import Byline from '../Byline'
8
9
  import { StructuredTreeFragment } from '@financial-times/cp-content-pipeline-client'
10
+ import parse from 'html-react-parser'
11
+
9
12
  /* eslint-disable @typescript-eslint/no-explicit-any */
10
13
  //TODO: CI-1975 remove "any" types
11
14
  // this has been ported from x-dash, and a lot of what is expected into these arguments will take a lot of digging
@@ -14,6 +17,26 @@ type indicators = {
14
17
  isOpinion?: boolean
15
18
  }
16
19
 
20
+ const TruncatedPost = ({ id, children }: { id: string; children: any }) => {
21
+ return (
22
+ <div
23
+ data-trackable="truncated-post"
24
+ data-trackable-context-post={id}
25
+ data-trackable-category="live-blog"
26
+ className="x-live-blog-post__body n-content-body article--body"
27
+ >
28
+ <Expander
29
+ expandLabel="Expand post"
30
+ collapseLabel="Collapse post"
31
+ onlyMobile={true}
32
+ id={`truncated-${id}`}
33
+ >
34
+ {children}
35
+ </Expander>
36
+ </div>
37
+ )
38
+ }
39
+
17
40
  export type LiveBlogPostProps = {
18
41
  id: string
19
42
  postId: string // Remove once wordpress is no longer in use
@@ -39,23 +62,6 @@ export type LiveBlogPostProps = {
39
62
  authors: Array<any>
40
63
  }
41
64
 
42
- const truncatedSelector = () => {
43
- const prefix = '.x-live-blog-post__body >'
44
- const selectors = [
45
- 'p',
46
- 'blockquote',
47
- 'ul',
48
- '.o-table-container',
49
- '.n-content-recommended--single-story',
50
- "[data-layout-name='card']",
51
- '.n-content-big-number',
52
- 'hr',
53
- '.n-content-tweet',
54
- "[data-layout-name='timeline']",
55
- ]
56
- return selectors.map((item) => `${prefix} ${item}`).join(',')
57
- }
58
-
59
65
  const LiveBlogPost = ({
60
66
  id,
61
67
  postId, // Remove once wordpress is no longer in use
@@ -82,18 +88,15 @@ const LiveBlogPost = ({
82
88
  if (body && 'structured' in body) {
83
89
  // Content comes from cp-content-pipeline-api
84
90
  postBody = (
85
- <div className="x-live-blog-post__body n-content-body article--body">
91
+ <TruncatedPost id={id}>
86
92
  <RichText structuredContent={body.structured} />
87
- </div>
93
+ </TruncatedPost>
88
94
  )
89
95
  } else {
96
+ const elements = parse(bodyHTML || content)
97
+
90
98
  // Content comes from next-es or wordpress
91
- postBody = (
92
- <div
93
- className="x-live-blog-post__body n-content-body article--body"
94
- dangerouslySetInnerHTML={{ __html: bodyHTML || content }}
95
- />
96
- )
99
+ postBody = <TruncatedPost id={id}>{elements}</TruncatedPost>
97
100
  }
98
101
 
99
102
  const author = authors?.[0] ?? null
@@ -155,23 +158,7 @@ const LiveBlogPost = ({
155
158
  <div className="x-live-blog-post__breaking-news">Breaking news</div>
156
159
  )}
157
160
  {title && <h2 className="x-live-blog-post__title">{title}</h2>}
158
- {isPinned ? (
159
- <div
160
- data-o-component="o-expander"
161
- className="o-expander"
162
- data-o-expander-shrink-to="1"
163
- data-o-expander-item-selector={truncatedSelector()}
164
- data-o-expander-collapsed-toggle-text={'Expand post'}
165
- data-o-expander-expanded-toggle-text={'Collapse post'}
166
- >
167
- <div className="o-expander__content">{postBody}</div>
168
- <a className="o-expander__toggle o-expander__text--custom">
169
- <span className="o-expander__visually-hidden">&nbsp;</span>
170
- </a>
171
- </div>
172
- ) : (
173
- postBody
174
- )}
161
+ {postBody}
175
162
  <div className="x-live-blog-post__controls">
176
163
  {showShareButtons && (
177
164
  <ShareButtons
@@ -193,6 +193,7 @@ class BaseLiveBlogWrapper extends Component<LiveBlogWrapperTypes, stateTypes> {
193
193
  className="x-live-blog-wrapper"
194
194
  data-live-blog-wrapper-id={id}
195
195
  ref={liveBlogWrapperElementRef}
196
+ data-component="live-blog-wrapper"
196
197
  >
197
198
  {postElements}
198
199
  </div>
@@ -25,6 +25,7 @@ export default function Recommended({
25
25
  className={classnames('n-content-recommended--single-story', {
26
26
  'n-content-recommended--inset': !isInLiveBlog,
27
27
  })}
28
+ data-component="recommended"
28
29
  >
29
30
  {!isInLiveBlog && (
30
31
  <p className="n-content-recommended__title">{heading}</p>
@@ -22,6 +22,7 @@ export default function Table({
22
22
  'o-table-container--contracted': Boolean(collapseAfterHowManyRows),
23
23
  })}
24
24
  data-layout-width={layoutWidth}
25
+ data-component="table"
25
26
  >
26
27
  <div
27
28
  className={classNames('o-table-overlay-wrapper', {
@@ -8,7 +8,10 @@ export default function Video({
8
8
  title,
9
9
  }: VideoFragment & ContentTreeWorkarounds.Video) {
10
10
  return (
11
- <div className="n-content-video n-content-video--internal">
11
+ <div
12
+ className="n-content-video n-content-video--internal"
13
+ data-component="video"
14
+ >
12
15
  <div
13
16
  className="n-content-video__placeholder"
14
17
  data-o-component="o-video"
@@ -13,7 +13,10 @@ export default function YoutubeVideo({
13
13
  }
14
14
 
15
15
  return (
16
- <div className="n-content-video n-content-video--youtube">
16
+ <div
17
+ className="n-content-video n-content-video--youtube"
18
+ data-component="youtube-video"
19
+ >
17
20
  <div className="n-content-video__placeholder">
18
21
  <iframe
19
22
  className="n-content-video__embedded"
@@ -1,8 +1,9 @@
1
+ import ClipServer from '../components/Clip'
2
+ import ClipClient from '../components/Clip/client'
1
3
  import React, { useEffect, ReactNode } from 'react'
2
4
  import oTracking from '@financial-times/o-tracking/main'
3
5
  import './Clip.stories.scss'
4
- import ClipClient from '../components/Clip/client'
5
- import ClipServer, { ClipProps } from '../components/Clip/template/component'
6
+ import { ClipProps } from '../components/Clip/template/component'
6
7
 
7
8
  // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction
8
9
  export default {
@@ -0,0 +1,3 @@
1
+ $system-code: "cp-expander";
2
+ @import "./article-page.scss";
3
+ @import "../components/Expander/client/main.scss";
@@ -0,0 +1,159 @@
1
+ import { ExpanderServer, ExpanderProps } from '../components/Expander'
2
+ import { ExpanderClient } from '../components/Expander/client'
3
+ import React, { useEffect } from 'react'
4
+ import oTracking from '@financial-times/o-tracking/main'
5
+ import './Expander.stories.scss'
6
+ import ClipClient from '../components/Clip/client'
7
+ import './Clip.stories.scss'
8
+ import RichText from '../components/RichText'
9
+ import { ContentTree } from '@financial-times/content-tree'
10
+ import { ClipSet } from '@financial-times/cp-content-pipeline-schema/src/resolvers/content-tree/Workarounds'
11
+
12
+ const structuredContent: ContentTree.Body = {
13
+ type: 'body',
14
+ version: 1,
15
+ children: [
16
+ {
17
+ type: 'paragraph',
18
+ children: [
19
+ {
20
+ type: 'text',
21
+ value:
22
+ 'Mike Johnson has survived an attempt to oust him as speaker of the House of Representatives by Marjorie Taylor Greene, a hardline Republican congresswoman from Georgia. ',
23
+ },
24
+ ],
25
+ } as ContentTree.Paragraph,
26
+ {
27
+ type: 'paragraph',
28
+ children: [
29
+ {
30
+ type: 'text',
31
+ value:
32
+ 'In a vote on Wednesday night, the lower chamber of Congress rejected Greene’s bid with overwhelming support from Democrats as well as Republicans. ',
33
+ },
34
+ ],
35
+ } as ContentTree.Paragraph,
36
+ ,
37
+ {
38
+ type: 'paragraph',
39
+ children: [
40
+ {
41
+ type: 'text',
42
+ value:
43
+ 'The vote all but ensures that Johnson will remain in his post until after the November election, and will put a lid on a debate over his political future that has lasted for weeks among Republicans in Congress.  ',
44
+ },
45
+ ],
46
+ } as ContentTree.Paragraph,
47
+ {
48
+ type: 'clip-set',
49
+ id: 'http://api.ft.com/content/23a00095-d9fc-4cac-ad7c-477e61e3c159',
50
+ autoplay: false,
51
+ loop: false,
52
+ muted: false,
53
+ dataLayout: 'in-line',
54
+ data: {
55
+ referenceIndex: 3,
56
+ },
57
+ } as ClipSet,
58
+ ] as ContentTree.Body['children'],
59
+ }
60
+ const storyArgs: ExpanderProps = {
61
+ expandLabel: 'Open',
62
+ collapseLabel: 'Close',
63
+ onlyMobile: false,
64
+ id: '111232323-12123-2323',
65
+ }
66
+
67
+ export default {
68
+ title: 'Expander',
69
+ component: ExpanderServer,
70
+ tags: ['autodocs'],
71
+ }
72
+
73
+ const LiveBLogWrapper: React.FC<ExpanderProps & { classNames?: string }> = (
74
+ args
75
+ ) => {
76
+ const { classNames } = args
77
+
78
+ return (
79
+ <div className={classNames}>
80
+ <article
81
+ id="site-content"
82
+ role="main"
83
+ className="article article-grid article-grid--no-full-width-graphics js enhanced"
84
+ data-article-type="no-full-width-graphics"
85
+ >
86
+ <div
87
+ className="article__content"
88
+ data-trackable="article-body"
89
+ data-component="article-body"
90
+ style={{ position: 'relative' }}
91
+ >
92
+ <div
93
+ className="article__content-body n-content-body js-article__content-body"
94
+ data-attribute="article-content-body"
95
+ >
96
+ <LiveBlogPostWrapper {...args} id="111"></LiveBlogPostWrapper>
97
+ </div>
98
+ </div>
99
+ <div className="article__right "></div>
100
+ </article>
101
+ </div>
102
+ )
103
+ }
104
+
105
+ const LiveBlogPostWrapper = (args: ExpanderProps) => {
106
+ useEffect(() => {
107
+ oTracking.init({
108
+ context: { product: 'next' },
109
+ test: true,
110
+ })
111
+
112
+ const clips = ClipClient.init(null, {})
113
+
114
+ return () => {
115
+ clips.forEach((clip) => clip.unload())
116
+ }
117
+ }, [])
118
+ return (
119
+ <article id={args.id}>
120
+ <div className="n-content-body">
121
+ <div
122
+ data-trackable="truncated-post"
123
+ data-trackable-context-post="1234"
124
+ data-component="example-boundary"
125
+ >
126
+ <ExpanderServer {...args} id={`${args.id}_expander`}>
127
+ <RichText structuredContent={{ tree: structuredContent }} />
128
+ </ExpanderServer>
129
+ </div>
130
+ </div>
131
+ </article>
132
+ )
133
+ }
134
+
135
+ export const OnlyServer = (args: ExpanderProps) => {
136
+ return <LiveBLogWrapper {...args} />
137
+ }
138
+
139
+ OnlyServer.args = { ...storyArgs }
140
+
141
+ export const WithClient = (args: ExpanderProps) => {
142
+ useEffect(() => {
143
+ const clips = ClipClient.init(null, {})
144
+ const expanders = ExpanderClient.init()
145
+ return () => {
146
+ clips.forEach((clip) => clip.unload())
147
+ expanders.forEach((expander) => expander?.destroy())
148
+ }
149
+ }, [])
150
+ return <LiveBLogWrapper {...args} />
151
+ }
152
+
153
+ WithClient.args = { ...storyArgs }
154
+
155
+ export const OnlyMobileWithClient = WithClient
156
+ OnlyMobileWithClient.args = { ...storyArgs, onlyMobile: true }
157
+
158
+ export const OnlyMobileServer = OnlyServer
159
+ OnlyMobileServer.args = { ...storyArgs, onlyMobile: true }