@financial-times/cp-content-pipeline-ui 6.9.2 → 6.10.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 (90) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/lib/components/BackToTopButton/client/index.d.ts +1 -0
  3. package/lib/components/BackToTopButton/client/index.js +7 -1
  4. package/lib/components/BackToTopButton/client/index.js.map +1 -1
  5. package/lib/components/Body/index.test.js +9 -0
  6. package/lib/components/Body/index.test.js.map +1 -1
  7. package/lib/components/Clip/client/index.d.ts +2 -0
  8. package/lib/components/Clip/client/index.js +40 -27
  9. package/lib/components/Clip/client/index.js.map +1 -1
  10. package/lib/components/Clip/components/ClipTag.js +1 -1
  11. package/lib/components/Clip/components/ClipTag.js.map +1 -1
  12. package/lib/components/Clip/components/Container.js +2 -2
  13. package/lib/components/Clip/components/Container.js.map +1 -1
  14. package/lib/components/Clip/template/index.js +0 -1
  15. package/lib/components/Clip/template/index.js.map +1 -1
  16. package/lib/components/Clip/test/index.spec.js +21 -9
  17. package/lib/components/Clip/test/index.spec.js.map +1 -1
  18. package/lib/components/Expander/client/index.d.ts +49 -0
  19. package/lib/components/Expander/client/index.js +124 -0
  20. package/lib/components/Expander/client/index.js.map +1 -0
  21. package/lib/components/Expander/index.d.ts +15 -0
  22. package/lib/components/Expander/index.js +27 -0
  23. package/lib/components/Expander/index.js.map +1 -0
  24. package/lib/components/Expander/test/client/index.spec.d.ts +1 -0
  25. package/lib/components/Expander/test/client/index.spec.js +103 -0
  26. package/lib/components/Expander/test/client/index.spec.js.map +1 -0
  27. package/lib/components/Expander/test/index.spec.d.ts +1 -0
  28. package/lib/components/Expander/test/index.spec.js +57 -0
  29. package/lib/components/Expander/test/index.spec.js.map +1 -0
  30. package/lib/components/Expander/test/snapshot.spec.d.ts +1 -0
  31. package/lib/components/Expander/test/snapshot.spec.js +63 -0
  32. package/lib/components/Expander/test/snapshot.spec.js.map +1 -0
  33. package/lib/components/ImageSet/index.js +1 -1
  34. package/lib/components/ImageSet/index.js.map +1 -1
  35. package/lib/components/LiveBlogPost/client/index.d.ts +4 -0
  36. package/lib/components/LiveBlogPost/client/index.js +19 -0
  37. package/lib/components/LiveBlogPost/client/index.js.map +1 -0
  38. package/lib/components/LiveBlogPost/index.js +9 -21
  39. package/lib/components/LiveBlogPost/index.js.map +1 -1
  40. package/lib/components/LiveBlogWrapper/index.js +1 -1
  41. package/lib/components/LiveBlogWrapper/index.js.map +1 -1
  42. package/lib/components/Recommended/index.js +1 -1
  43. package/lib/components/Recommended/index.js.map +1 -1
  44. package/lib/components/RichText/index.d.ts +1 -1
  45. package/lib/components/Table/index.js +1 -1
  46. package/lib/components/Table/index.js.map +1 -1
  47. package/lib/components/Video/index.js +1 -1
  48. package/lib/components/Video/index.js.map +1 -1
  49. package/lib/components/YoutubeVideo/index.js +1 -1
  50. package/lib/components/YoutubeVideo/index.js.map +1 -1
  51. package/lib/extensions/scrollIntoView.d.ts +10 -0
  52. package/lib/extensions/scrollIntoView.js +32 -0
  53. package/lib/extensions/scrollIntoView.js.map +1 -0
  54. package/lib/stories/Clip.stories.d.ts +2 -1
  55. package/lib/stories/Clip.stories.js +5 -5
  56. package/lib/stories/Clip.stories.js.map +1 -1
  57. package/lib/stories/Expander.stories.d.ts +54 -0
  58. package/lib/stories/Expander.stories.js +142 -0
  59. package/lib/stories/Expander.stories.js.map +1 -0
  60. package/package.json +2 -5
  61. package/src/components/BackToTopButton/client/index.tsx +8 -1
  62. package/src/components/Body/__snapshots__/index.test.tsx.snap +55 -5
  63. package/src/components/Body/index.test.tsx +9 -0
  64. package/src/components/Clip/client/index.ts +68 -26
  65. package/src/components/Clip/client/main.scss +27 -12
  66. package/src/components/Clip/components/ClipTag.tsx +0 -1
  67. package/src/components/Clip/components/Container.tsx +10 -3
  68. package/src/components/Clip/template/index.ts +0 -1
  69. package/src/components/Clip/test/__snapshots__/snapshot.spec.tsx.snap +8 -16
  70. package/src/components/Clip/test/index.spec.ts +33 -7
  71. package/src/components/Expander/client/index.ts +201 -0
  72. package/src/components/Expander/client/main.scss +162 -0
  73. package/src/components/Expander/index.tsx +74 -0
  74. package/src/components/Expander/test/__snapshots__/snapshot.spec.tsx.snap +221 -0
  75. package/src/components/Expander/test/client/index.spec.tsx +129 -0
  76. package/src/components/Expander/test/index.spec.tsx +77 -0
  77. package/src/components/Expander/test/snapshot.spec.tsx +73 -0
  78. package/src/components/ImageSet/index.tsx +1 -0
  79. package/src/components/LiveBlogPost/client/index.ts +16 -0
  80. package/src/components/LiveBlogPost/index.tsx +29 -43
  81. package/src/components/LiveBlogWrapper/index.tsx +1 -0
  82. package/src/components/Recommended/index.tsx +1 -0
  83. package/src/components/Table/index.tsx +1 -0
  84. package/src/components/Video/index.tsx +4 -1
  85. package/src/components/YoutubeVideo/index.tsx +4 -1
  86. package/src/extensions/scrollIntoView.ts +38 -0
  87. package/src/stories/Clip.stories.tsx +3 -2
  88. package/src/stories/Expander.stories.scss +3 -0
  89. package/src/stories/Expander.stories.tsx +159 -0
  90. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,38 @@
1
+ type HTMLElementExpanded = HTMLElement & { polyfillScrollIntoView?: boolean }
2
+ /**
3
+ * Extension for scrollIntoView of HTMLElement
4
+ * set the flag "programmaticScroll" to true on the window object when is called that last 500 ms with this value ,
5
+ * so when we listen to scroll event we can know that comes from this method
6
+ *
7
+ * The reason of this polyfill is that there is no way to know if the scroll event comes from the scrollIntoView method.
8
+ * This polyfill is a workaround to solve this problem and shouldn't affect the normal behavior of the scrollIntoView method
9
+ *
10
+ */
11
+ export default function scrollIntoViewPolyfill() {
12
+ // Check if the extension can be applied or if it is already applied to not apply it twice
13
+ const windowRef = window as Window & { polyfillScrollIntoView?: boolean }
14
+ if (!windowRef || (windowRef && windowRef?.polyfillScrollIntoView)) {
15
+ return
16
+ }
17
+
18
+ windowRef.polyfillScrollIntoView = true
19
+
20
+ const nativeScrollIntoView = window.HTMLElement.prototype.scrollIntoView
21
+
22
+ window.HTMLElement.prototype.scrollIntoView = function (
23
+ options?: ScrollIntoViewOptions | undefined
24
+ ) {
25
+ const element = this as HTMLElementExpanded
26
+
27
+ const window = element.ownerDocument.defaultView as Window & {
28
+ programmaticScroll?: boolean
29
+ }
30
+ window.programmaticScroll = true
31
+ nativeScrollIntoView.apply(element, [options])
32
+ setTimeout(() => {
33
+ window.programmaticScroll = false
34
+ }, 500)
35
+ }
36
+ }
37
+
38
+ scrollIntoViewPolyfill()
@@ -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 }