@times-components/ts-components 1.100.1 → 1.101.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 (120) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/components/article-flag/ArticleFlag.d.ts +1 -4
  3. package/dist/components/article-flag/ArticleFlag.js +1 -1
  4. package/dist/components/article-flag/getActiveFlags.d.ts +1 -1
  5. package/dist/components/article-flag/styles.d.ts +1 -1
  6. package/dist/components/article-flag/types.d.ts +4 -0
  7. package/dist/components/article-flag/types.js +2 -0
  8. package/dist/components/banner/__tests__/banner.test.d.ts +1 -0
  9. package/dist/components/banner/__tests__/banner.test.js +11 -0
  10. package/dist/components/banner/assets/CloseIconBlack.d.ts +3 -0
  11. package/dist/components/banner/assets/CloseIconBlack.js +5 -0
  12. package/dist/components/banner/assets/EmailIcon.d.ts +3 -0
  13. package/dist/components/banner/assets/EmailIcon.js +5 -0
  14. package/dist/components/banner/banner.d.ts +8 -0
  15. package/dist/components/banner/banner.js +17 -0
  16. package/dist/components/banner/styles.d.ts +8 -0
  17. package/dist/components/banner/styles.js +73 -0
  18. package/dist/components/breadcrumb/__tests__/index.test.d.ts +1 -0
  19. package/dist/components/breadcrumb/__tests__/index.test.js +40 -0
  20. package/dist/components/breadcrumb/assets/BreadcrumbIcon.d.ts +2 -0
  21. package/dist/components/breadcrumb/assets/BreadcrumbIcon.js +5 -0
  22. package/dist/components/breadcrumb/breadcrumb.d.ts +9 -0
  23. package/dist/components/breadcrumb/breadcrumb.js +28 -0
  24. package/dist/components/breadcrumb/fixtures/breadcrumbs.json +27 -0
  25. package/dist/components/breadcrumb/styles.d.ts +13 -0
  26. package/dist/components/breadcrumb/styles.js +39 -0
  27. package/dist/components/delayed-component/__tests__/delayed-component.test.d.ts +1 -0
  28. package/dist/components/delayed-component/__tests__/delayed-component.test.js +23 -0
  29. package/dist/components/delayed-component/delayed-component.d.ts +6 -0
  30. package/dist/components/delayed-component/delayed-component.js +11 -0
  31. package/dist/components/in-article-info-card/Card.d.ts +1 -1
  32. package/dist/components/in-article-info-card/InfoCard.d.ts +0 -8
  33. package/dist/components/in-article-info-card/InfoCard.js +1 -1
  34. package/dist/components/in-article-info-card/types.d.ts +8 -0
  35. package/dist/components/in-article-info-card/types.js +2 -0
  36. package/dist/components/job-title/__tests__/index.test.d.ts +1 -0
  37. package/dist/components/job-title/__tests__/index.test.js +45 -0
  38. package/dist/components/job-title/assets/TooltipIcon.d.ts +2 -0
  39. package/dist/components/job-title/assets/TooltipIcon.js +11 -0
  40. package/dist/components/job-title/assets/close-icon.d.ts +2 -0
  41. package/dist/components/job-title/assets/close-icon.js +5 -0
  42. package/dist/components/job-title/job-title.d.ts +11 -0
  43. package/dist/components/job-title/job-title.js +31 -0
  44. package/dist/components/job-title/styles.d.ts +11 -0
  45. package/dist/components/job-title/styles.js +150 -0
  46. package/dist/components/save-star/ContentProvider.d.ts +0 -6
  47. package/dist/components/save-star/ContentProvider.js +1 -1
  48. package/dist/components/save-star/SaveStar.js +1 -1
  49. package/dist/components/save-star/SaveStarUI.d.ts +1 -4
  50. package/dist/components/save-star/SaveStarUI.js +1 -1
  51. package/dist/components/save-star/types.d.ts +8 -0
  52. package/dist/components/save-star/types.js +2 -0
  53. package/dist/components/update-button/__tests__/update-button-with-delay.test.d.ts +1 -0
  54. package/dist/components/update-button/__tests__/update-button-with-delay.test.js +24 -0
  55. package/dist/components/update-button/__tests__/update-button.test.d.ts +1 -0
  56. package/dist/components/update-button/__tests__/update-button.test.js +27 -0
  57. package/dist/components/update-button/assets/FilledArrowIcon.d.ts +3 -0
  58. package/dist/components/update-button/assets/FilledArrowIcon.js +5 -0
  59. package/dist/components/update-button/styles.d.ts +1 -0
  60. package/dist/components/update-button/styles.js +39 -0
  61. package/dist/components/update-button/update-button-with-delay.d.ts +11 -0
  62. package/dist/components/update-button/update-button-with-delay.js +27 -0
  63. package/dist/components/update-button/update-button.d.ts +6 -0
  64. package/dist/components/update-button/update-button.js +9 -0
  65. package/dist/fixtures/article-harness/__tests__/articleHarness.test.d.ts +1 -0
  66. package/dist/fixtures/article-harness/__tests__/articleHarness.test.js +11 -0
  67. package/dist/index.d.ts +7 -2
  68. package/dist/index.js +8 -3
  69. package/jest.config.js +2 -1
  70. package/package.json +4 -3
  71. package/rnw.js +1 -1
  72. package/src/components/article-flag/ArticleFlag.tsx +1 -5
  73. package/src/components/article-flag/getActiveFlags.ts +1 -1
  74. package/src/components/article-flag/styles.ts +1 -1
  75. package/src/components/article-flag/types.ts +4 -0
  76. package/src/components/banner/__tests__/__snapshots__/banner.test.tsx.snap +66 -0
  77. package/src/components/banner/__tests__/banner.test.tsx +13 -0
  78. package/src/components/banner/assets/CloseIconBlack.tsx +24 -0
  79. package/src/components/banner/assets/EmailIcon.tsx +24 -0
  80. package/src/components/banner/banner.stories.mdx +30 -0
  81. package/src/components/banner/banner.tsx +40 -0
  82. package/src/components/banner/styles.ts +80 -0
  83. package/src/components/breadcrumb/__tests__/__snapshots__/index.test.tsx.snap +64 -0
  84. package/src/components/breadcrumb/__tests__/index.test.tsx +51 -0
  85. package/src/components/breadcrumb/assets/BreadcrumbIcon.tsx +16 -0
  86. package/src/components/breadcrumb/breadcrumb.stories.mdx +47 -0
  87. package/src/components/breadcrumb/breadcrumb.tsx +84 -0
  88. package/src/components/breadcrumb/fixtures/breadcrumbs.json +27 -0
  89. package/src/components/breadcrumb/styles.ts +43 -0
  90. package/src/components/delayed-component/__tests__/delayed-component.test.tsx +30 -0
  91. package/src/components/delayed-component/delayed-component.stories.mdx +38 -0
  92. package/src/components/delayed-component/delayed-component.tsx +16 -0
  93. package/src/components/in-article-info-card/Card.tsx +1 -1
  94. package/src/components/in-article-info-card/InfoCard.tsx +1 -8
  95. package/src/components/in-article-info-card/types.ts +8 -0
  96. package/src/components/job-title/__tests__/__snapshots__/index.test.tsx.snap +271 -0
  97. package/src/components/job-title/__tests__/index.test.tsx +71 -0
  98. package/src/components/job-title/assets/TooltipIcon.tsx +37 -0
  99. package/src/components/job-title/assets/close-icon.tsx +18 -0
  100. package/src/components/job-title/job-title.stories.mdx +38 -0
  101. package/src/components/job-title/job-title.tsx +85 -0
  102. package/src/components/job-title/styles.ts +154 -0
  103. package/src/components/save-star/ContentProvider.tsx +1 -7
  104. package/src/components/save-star/SaveStar.tsx +2 -1
  105. package/src/components/save-star/SaveStarUI.tsx +1 -5
  106. package/src/components/save-star/types.ts +9 -0
  107. package/src/components/update-button/__tests__/__snapshots__/update-button-with-delay.test.tsx.snap +23 -0
  108. package/src/components/update-button/__tests__/__snapshots__/update-button.test.tsx.snap +23 -0
  109. package/src/components/update-button/__tests__/update-button-with-delay.test.tsx +67 -0
  110. package/src/components/update-button/__tests__/update-button.test.tsx +31 -0
  111. package/src/components/update-button/assets/FilledArrowIcon.tsx +17 -0
  112. package/src/components/update-button/styles.ts +40 -0
  113. package/src/components/update-button/update-button-with-delay.stories.mdx +40 -0
  114. package/src/components/update-button/update-button-with-delay.tsx +53 -0
  115. package/src/components/update-button/update-button.stories.mdx +32 -0
  116. package/src/components/update-button/update-button.tsx +17 -0
  117. package/src/fixtures/article-harness/__tests__/__snapshots__/articleHarness.test.tsx.snap +34 -0
  118. package/src/fixtures/article-harness/__tests__/articleHarness.test.tsx +11 -0
  119. package/src/index.ts +15 -7
  120. package/tsconfig.json +6 -1
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom';
3
+ import { render, waitFor } from '@testing-library/react';
4
+
5
+ import { DelayedComponent } from '../delayed-component';
6
+
7
+ describe('DelayedComponent', () => {
8
+ it('should remove the component after the specified delay when initial state is true', async () => {
9
+ const { queryByText, getByText } = render(
10
+ <DelayedComponent initialState={true} delay={800}>
11
+ <div>Children</div>
12
+ </DelayedComponent>
13
+ );
14
+ expect(getByText('Children')).toBeVisible();
15
+ await waitFor(() => {
16
+ expect(queryByText('Children')).toBeFalsy();
17
+ });
18
+ });
19
+ it('should render the component after the specified delay when initial state is false', async () => {
20
+ const { queryByText, getByText } = render(
21
+ <DelayedComponent initialState={false} delay={800}>
22
+ <div>Children</div>
23
+ </DelayedComponent>
24
+ );
25
+ expect(queryByText('Children')).toBeFalsy();
26
+ await waitFor(() => {
27
+ expect(getByText('Children')).toBeVisible();
28
+ });
29
+ });
30
+ });
@@ -0,0 +1,38 @@
1
+ import { Meta, Story, Props } from '@storybook/addon-docs'
2
+
3
+ import { DelayedComponent } from './delayed-component.tsx';
4
+
5
+ <Meta
6
+ title="Components/Misc/DelayedComponent"
7
+ component={DelayedComponent}
8
+ />
9
+
10
+ # DelayedComponent component
11
+ The `DelayedComponent` component is a helper component used to delay the mount or dismount of the children passed to the component.
12
+
13
+ This component takes in three props: `initialState`, `delay` and `children`.
14
+ initialState - This used to set the initial component state, if it is meant to be displayed initially and removed after x amount of time intialState would be true. and Vice versa.
15
+ delay - This is the time in milliseconds it takes for the component to mount or unmount.
16
+
17
+ Given the nature of this component you may need to play around with the controls so that you can see what it's doing.
18
+
19
+
20
+
21
+ ## Props
22
+ <Props of={DelayedComponent} />
23
+
24
+ ## Code Example
25
+ `<DelayedComponent initialState={true} delay={8000}><div>Hello</div></DelayedComponent>`
26
+
27
+ ## View Component
28
+ Please click the 'Canvas' tab for a better viewing experience, where you can update the props and review at the different breakpoints by clicking the preview icon and selecting from our list of pre-defined breakpoints (XS, SM, MD, LG and XL).
29
+
30
+ export const DelayedComponentStory = ({ initialState, delay }) => (
31
+ <DelayedComponent initialState={initialState} delay={delay}><div style={{ fontSize: '20px', color: 'red'}}>I am a delayed component</div></DelayedComponent>
32
+ );
33
+
34
+ <Story name="DelayedComponent"
35
+ args={{ initialState: true, delay: 8000} }
36
+ >
37
+ {DelayedComponentStory.bind({})}
38
+ </Story>
@@ -0,0 +1,16 @@
1
+ import React, { useEffect, useState } from 'react';
2
+
3
+ export const DelayedComponent: React.FC<{
4
+ delay: number;
5
+ initialState: boolean;
6
+ children: any;
7
+ }> = ({ delay, initialState, children }) => {
8
+ const [showElement, setShowElement] = useState(initialState);
9
+
10
+ useEffect(() => {
11
+ setTimeout(() => {
12
+ setShowElement(!initialState);
13
+ }, delay);
14
+ }, []);
15
+ return <>{showElement ? children : null}</>;
16
+ };
@@ -6,7 +6,7 @@ import {
6
6
  HeadlineButtonContainer
7
7
  } from './styles';
8
8
  import { Label } from '../common-styles';
9
- import { InfoCardData } from './InfoCard';
9
+ import { InfoCardData } from './types';
10
10
 
11
11
  export const Card: React.FC<{
12
12
  headline: string;
@@ -21,15 +21,8 @@ import { sanitiseCopy } from '../../helpers/text-formatting/SanitiseCopy';
21
21
  import { useFetch } from '../../helpers/fetch/FetchProvider';
22
22
  import { TrackingContextProvider } from '../../helpers/tracking/TrackingContextProvider';
23
23
  import { DeckData } from '../../helpers/fetch/types';
24
+ import { InfoCardData } from './types';
24
25
 
25
- export type InfoCardData = {
26
- type: string;
27
- data: {
28
- image?: string;
29
- subtitle?: string;
30
- copy: string;
31
- };
32
- };
33
26
  type InfoCardFields = { headline: string; label: string; size: Layout };
34
27
 
35
28
  type InfoCardDeckData = DeckData<InfoCardFields, InfoCardData>;
@@ -0,0 +1,8 @@
1
+ export type InfoCardData = {
2
+ type: string;
3
+ data: {
4
+ image?: string;
5
+ subtitle?: string;
6
+ copy: string;
7
+ };
8
+ };
@@ -0,0 +1,271 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`JobTitle - Larger Devices renders the Job title Tooltip on larger devices 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-EHOje cZlyCb"
7
+ >
8
+ <div
9
+ class="sc-bZQynM bJeBts"
10
+ data-testid="Tooltip-context"
11
+ >
12
+ Contractual Title
13
+ </div>
14
+ <button
15
+ aria-label="See contractual title, button"
16
+ class="sc-bdVaJa Cwdme"
17
+ data-testid="Tooltip"
18
+ >
19
+ <svg
20
+ fill="none"
21
+ height="16"
22
+ width="16"
23
+ xmlns="http://www.w3.org/2000/svg"
24
+ >
25
+ <mask
26
+ height="16"
27
+ id="a"
28
+ maskUnits="userSpaceOnUse"
29
+ style="mask-type: alpha;"
30
+ width="16"
31
+ x="0"
32
+ y="0"
33
+ >
34
+ <path
35
+ d="M7.333 4.667h1.334V6H7.334V4.667ZM7.333 7.333h1.334v4H7.334v-4Z"
36
+ fill="currentcolor"
37
+ />
38
+ <path
39
+ clip-rule="evenodd"
40
+ d="M1.333 8A6.67 6.67 0 0 1 8 1.333 6.67 6.67 0 0 1 14.667 8 6.67 6.67 0 0 1 8 14.667 6.67 6.67 0 0 1 1.333 8Zm1.334 0A5.34 5.34 0 0 0 8 13.333 5.34 5.34 0 0 0 13.334 8 5.34 5.34 0 0 0 8 2.667 5.34 5.34 0 0 0 2.667 8Z"
41
+ fill="currentcolor"
42
+ fill-rule="evenodd"
43
+ />
44
+ </mask>
45
+ <g
46
+ mask="url(#a)"
47
+ >
48
+ <path
49
+ d="M0 0h16v16H0z"
50
+ fill="currentcolor"
51
+ />
52
+ </g>
53
+ </svg>
54
+ </button>
55
+ </div>
56
+ </DocumentFragment>
57
+ `;
58
+
59
+ exports[`JobTitle - Smaller Devices renders the Job title Popover 1`] = `
60
+ <DocumentFragment>
61
+ <div
62
+ class="sc-bwzfXH byurlq"
63
+ >
64
+ <div
65
+ class="sc-htpNat eLHUjT"
66
+ data-testid="Popover-context"
67
+ >
68
+ <div
69
+ class="sc-bxivhb hWtgEz"
70
+ >
71
+ <div>
72
+ Contractual Title
73
+ </div>
74
+ <button
75
+ class="sc-ifAKCX NVIZe"
76
+ data-testid="close-button"
77
+ >
78
+ <svg
79
+ fill="none"
80
+ height="12"
81
+ viewBox="0 0 14 14"
82
+ width="12"
83
+ xmlns="http://www.w3.org/2000/svg"
84
+ >
85
+ <path
86
+ d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z"
87
+ fill="#333333"
88
+ />
89
+ </svg>
90
+ </button>
91
+ </div>
92
+ </div>
93
+ <button
94
+ aria-label="See contractual title, button"
95
+ class="sc-bdVaJa Cwdme"
96
+ data-testid="Popover"
97
+ >
98
+ <svg
99
+ fill="none"
100
+ height="16"
101
+ width="16"
102
+ xmlns="http://www.w3.org/2000/svg"
103
+ >
104
+ <mask
105
+ height="16"
106
+ id="a"
107
+ maskUnits="userSpaceOnUse"
108
+ style="mask-type: alpha;"
109
+ width="16"
110
+ x="0"
111
+ y="0"
112
+ >
113
+ <path
114
+ d="M7.333 4.667h1.334V6H7.334V4.667ZM7.333 7.333h1.334v4H7.334v-4Z"
115
+ fill="currentcolor"
116
+ />
117
+ <path
118
+ clip-rule="evenodd"
119
+ d="M1.333 8A6.67 6.67 0 0 1 8 1.333 6.67 6.67 0 0 1 14.667 8 6.67 6.67 0 0 1 8 14.667 6.67 6.67 0 0 1 1.333 8Zm1.334 0A5.34 5.34 0 0 0 8 13.333 5.34 5.34 0 0 0 13.334 8 5.34 5.34 0 0 0 8 2.667 5.34 5.34 0 0 0 2.667 8Z"
120
+ fill="currentcolor"
121
+ fill-rule="evenodd"
122
+ />
123
+ </mask>
124
+ <g
125
+ mask="url(#a)"
126
+ >
127
+ <path
128
+ d="M0 0h16v16H0z"
129
+ fill="currentcolor"
130
+ />
131
+ </g>
132
+ </svg>
133
+ </button>
134
+ </div>
135
+ </DocumentFragment>
136
+ `;
137
+
138
+ exports[`JobTitlePopover Renders the Popover when clicked 1`] = `
139
+ <DocumentFragment>
140
+ <div
141
+ class="sc-bwzfXH byurlq"
142
+ >
143
+ <div
144
+ class="sc-htpNat hegnPT"
145
+ data-testid="Popover-context"
146
+ >
147
+ <div
148
+ class="sc-bxivhb hWtgEz"
149
+ >
150
+ <div>
151
+ Contractual Title Popover
152
+ </div>
153
+ <button
154
+ class="sc-ifAKCX NVIZe"
155
+ data-testid="close-button"
156
+ >
157
+ <svg
158
+ fill="none"
159
+ height="12"
160
+ viewBox="0 0 14 14"
161
+ width="12"
162
+ xmlns="http://www.w3.org/2000/svg"
163
+ >
164
+ <path
165
+ d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z"
166
+ fill="#333333"
167
+ />
168
+ </svg>
169
+ </button>
170
+ </div>
171
+ </div>
172
+ <button
173
+ aria-label="See contractual title, button"
174
+ class="sc-bdVaJa Cwdme"
175
+ data-testid="Popover"
176
+ >
177
+ <svg
178
+ fill="none"
179
+ height="16"
180
+ width="16"
181
+ xmlns="http://www.w3.org/2000/svg"
182
+ >
183
+ <mask
184
+ height="16"
185
+ id="a"
186
+ maskUnits="userSpaceOnUse"
187
+ style="mask-type: alpha;"
188
+ width="16"
189
+ x="0"
190
+ y="0"
191
+ >
192
+ <path
193
+ d="M7.333 4.667h1.334V6H7.334V4.667ZM7.333 7.333h1.334v4H7.334v-4Z"
194
+ fill="currentcolor"
195
+ />
196
+ <path
197
+ clip-rule="evenodd"
198
+ d="M1.333 8A6.67 6.67 0 0 1 8 1.333 6.67 6.67 0 0 1 14.667 8 6.67 6.67 0 0 1 8 14.667 6.67 6.67 0 0 1 1.333 8Zm1.334 0A5.34 5.34 0 0 0 8 13.333 5.34 5.34 0 0 0 13.334 8 5.34 5.34 0 0 0 8 2.667 5.34 5.34 0 0 0 2.667 8Z"
199
+ fill="currentcolor"
200
+ fill-rule="evenodd"
201
+ />
202
+ </mask>
203
+ <g
204
+ mask="url(#a)"
205
+ >
206
+ <path
207
+ d="M0 0h16v16H0z"
208
+ fill="currentcolor"
209
+ />
210
+ </g>
211
+ </svg>
212
+ </button>
213
+ </div>
214
+ </DocumentFragment>
215
+ `;
216
+
217
+ exports[`JobTitleTooltip Renders the tooltip when clicked 1`] = `
218
+ <DocumentFragment>
219
+ <div
220
+ class="sc-EHOje cZlyCb"
221
+ >
222
+ <div
223
+ class="sc-bZQynM ldWLbn"
224
+ data-testid="Tooltip-context"
225
+ >
226
+ Contractual Title Tooltip
227
+ </div>
228
+ <button
229
+ aria-label="See contractual title, button"
230
+ class="sc-bdVaJa Cwdme"
231
+ data-testid="Tooltip"
232
+ >
233
+ <svg
234
+ fill="none"
235
+ height="16"
236
+ width="16"
237
+ xmlns="http://www.w3.org/2000/svg"
238
+ >
239
+ <mask
240
+ height="16"
241
+ id="a"
242
+ maskUnits="userSpaceOnUse"
243
+ style="mask-type: alpha;"
244
+ width="16"
245
+ x="0"
246
+ y="0"
247
+ >
248
+ <path
249
+ d="M7.333 4.667h1.334V6H7.334V4.667ZM7.333 7.333h1.334v4H7.334v-4Z"
250
+ fill="currentcolor"
251
+ />
252
+ <path
253
+ clip-rule="evenodd"
254
+ d="M1.333 8A6.67 6.67 0 0 1 8 1.333 6.67 6.67 0 0 1 14.667 8 6.67 6.67 0 0 1 8 14.667 6.67 6.67 0 0 1 1.333 8Zm1.334 0A5.34 5.34 0 0 0 8 13.333 5.34 5.34 0 0 0 13.334 8 5.34 5.34 0 0 0 8 2.667 5.34 5.34 0 0 0 2.667 8Z"
255
+ fill="currentcolor"
256
+ fill-rule="evenodd"
257
+ />
258
+ </mask>
259
+ <g
260
+ mask="url(#a)"
261
+ >
262
+ <path
263
+ d="M0 0h16v16H0z"
264
+ fill="currentcolor"
265
+ />
266
+ </g>
267
+ </svg>
268
+ </button>
269
+ </div>
270
+ </DocumentFragment>
271
+ `;
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import '@testing-library/jest-dom';
3
+ import { render, fireEvent } from '@testing-library/react';
4
+ import { JobTitleTooltip, JobTitlePopover, JobTitle } from '../job-title';
5
+ import * as ResizeObserverModule from 'resize-observer-polyfill';
6
+
7
+ (window as any).ResizeObserver = ResizeObserverModule.default;
8
+
9
+ describe('JobTitle - Smaller Devices', () => {
10
+ it('renders the Job title Popover', () => {
11
+ const { asFragment, getByTestId } = render(
12
+ <JobTitle isLargeDevice={false} contractualTitle="Contractual Title" />
13
+ );
14
+ expect(asFragment()).toMatchSnapshot();
15
+ expect(getByTestId('Popover')).toBeVisible();
16
+ });
17
+ });
18
+
19
+ describe('JobTitle - Larger Devices', () => {
20
+ it('renders the Job title Tooltip on larger devices', () => {
21
+ const { asFragment, getByTestId } = render(
22
+ <JobTitle isLargeDevice={true} contractualTitle="Contractual Title" />
23
+ );
24
+ expect(asFragment()).toMatchSnapshot();
25
+ expect(getByTestId('Tooltip')).toBeVisible();
26
+ });
27
+ });
28
+
29
+ describe('JobTitleTooltip', () => {
30
+ it('Renders the tooltip when clicked', async () => {
31
+ const {
32
+ getByRole,
33
+ asFragment,
34
+ getByTestId,
35
+ getByText,
36
+ queryByTestId,
37
+ queryByText
38
+ } = render(
39
+ <JobTitleTooltip contractualTitle="Contractual Title Tooltip" />
40
+ );
41
+ expect(queryByTestId('Tooltip-context')).not.toBeVisible();
42
+ expect(queryByText('Contractual Title Tooltip')).not.toBeVisible();
43
+ fireEvent.mouseEnter(getByRole('button'));
44
+ expect(asFragment()).toMatchSnapshot();
45
+ expect(getByTestId('Tooltip')).toBeVisible();
46
+ expect(getByText('Contractual Title Tooltip')).toBeVisible();
47
+ });
48
+ });
49
+
50
+ describe('JobTitlePopover', () => {
51
+ it('Renders the Popover when clicked', () => {
52
+ const {
53
+ asFragment,
54
+ getByRole,
55
+ getByText,
56
+ queryByText,
57
+ queryByTestId,
58
+ getByTestId
59
+ } = render(
60
+ <JobTitlePopover contractualTitle="Contractual Title Popover" />
61
+ );
62
+ expect(queryByTestId('Popover-context')).not.toBeVisible();
63
+ expect(queryByText('Contractual Title Popover')).not.toBeVisible();
64
+ fireEvent.click(getByRole('button'));
65
+ expect(asFragment()).toMatchSnapshot();
66
+ expect(getByTestId('Popover')).toBeVisible();
67
+ expect(getByText('Contractual Title Popover')).toBeVisible();
68
+ const closeButton = getByTestId('close-button');
69
+ expect(closeButton).toBeVisible();
70
+ });
71
+ });
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ const TooltipIcon = (props: any) => (
3
+ <svg
4
+ xmlns="http://www.w3.org/2000/svg"
5
+ width={16}
6
+ height={16}
7
+ fill="none"
8
+ {...props}
9
+ >
10
+ <mask
11
+ id="a"
12
+ width={16}
13
+ height={16}
14
+ x={0}
15
+ y={0}
16
+ maskUnits="userSpaceOnUse"
17
+ style={{
18
+ maskType: 'alpha'
19
+ }}
20
+ >
21
+ <path
22
+ fill="currentcolor"
23
+ d="M7.333 4.667h1.334V6H7.334V4.667ZM7.333 7.333h1.334v4H7.334v-4Z"
24
+ />
25
+ <path
26
+ fill="currentcolor"
27
+ fillRule="evenodd"
28
+ d="M1.333 8A6.67 6.67 0 0 1 8 1.333 6.67 6.67 0 0 1 14.667 8 6.67 6.67 0 0 1 8 14.667 6.67 6.67 0 0 1 1.333 8Zm1.334 0A5.34 5.34 0 0 0 8 13.333 5.34 5.34 0 0 0 13.334 8 5.34 5.34 0 0 0 8 2.667 5.34 5.34 0 0 0 2.667 8Z"
29
+ clipRule="evenodd"
30
+ />
31
+ </mask>
32
+ <g mask="url(#a)">
33
+ <path fill="currentcolor" d="M0 0h16v16H0z" />
34
+ </g>
35
+ </svg>
36
+ );
37
+ export default TooltipIcon;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+
3
+ const CloseIcon = () => (
4
+ <svg
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ width={12}
7
+ height={12}
8
+ viewBox="0 0 14 14"
9
+ fill="none"
10
+ >
11
+ <path
12
+ d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z"
13
+ fill="#333333"
14
+ />
15
+ </svg>
16
+ );
17
+
18
+ export default CloseIcon;
@@ -0,0 +1,38 @@
1
+ import { Meta, Story, Props } from '@storybook/addon-docs'
2
+
3
+ import { JobTitle } from './job-title.tsx';
4
+
5
+ <Meta
6
+ title="Components/Misc/JobTitle"
7
+ component={JobTitle}
8
+ />
9
+
10
+ # Job Title component
11
+ The `Job Title` component is not being used currently.
12
+ We will leave JobTitle implementation as it could be required in the feature. It will require adding a floating element to fix the popover being out of screen issue.
13
+ The `Job Title` component is used to show the author's contractual job title in either a Tooltip (Desktop) or a Popover (Smaller Devices).
14
+
15
+ This component takes in two props `contractualTitle` and `isLargeDevice` as below.
16
+
17
+ ## Props
18
+ <Props of={JobTitle} />
19
+
20
+ ## Code Example
21
+ `<JobTitle contractualTitle="Senior Correspondent" isLargeDevice={true}/>`
22
+
23
+ ## View Component
24
+ Please click the 'Canvas' tab for a better viewing experience, where you can update the props and review at the different breakpoints by clicking the preview icon and selecting from our list of pre-defined breakpoints (XS, SM, MD, LG and XL).
25
+
26
+ export const JobTitleStory = ({ isLargeDevice }) => (
27
+ <div style={{ paddingTop: '150px'}}>
28
+ <JobTitle contractualTitle="Senior Correspondent" isLargeDevice={isLargeDevice} />
29
+ </div>
30
+ );
31
+
32
+ <Story name="JobTitle"
33
+ args={{ isLargeDevice: true }}
34
+ argTypes={{
35
+ isLargeDevice: { control: "select", options: [true, false] }
36
+ }}>
37
+ {JobTitleStory.bind({})}
38
+ </Story>
@@ -0,0 +1,85 @@
1
+ import React from 'react';
2
+ import TooltipIcon from './assets/TooltipIcon';
3
+ import {
4
+ CloseButton,
5
+ IconButton,
6
+ Popover,
7
+ PopoverContext,
8
+ PopoverHeader,
9
+ Tooltip,
10
+ TooltipContext
11
+ } from './styles';
12
+ import CloseIcon from './assets/close-icon';
13
+
14
+ export const JobTitleTooltip: React.FC<{ contractualTitle: string }> = ({
15
+ contractualTitle
16
+ }) => {
17
+ const [tooltipOpen, setTooltipOpen] = React.useState(false);
18
+
19
+ return (
20
+ <>
21
+ <Tooltip>
22
+ <TooltipContext data-testid="Tooltip-context" isOpen={tooltipOpen}>
23
+ {contractualTitle}
24
+ </TooltipContext>
25
+ <IconButton
26
+ aria-label="See contractual title, button"
27
+ data-testid="Tooltip"
28
+ onMouseOver={() => setTooltipOpen(true)}
29
+ onMouseOut={() => setTooltipOpen(false)}
30
+ >
31
+ <TooltipIcon />
32
+ </IconButton>
33
+ </Tooltip>
34
+ </>
35
+ );
36
+ };
37
+
38
+ export const JobTitlePopover: React.FC<{ contractualTitle: string }> = ({
39
+ contractualTitle
40
+ }) => {
41
+ const [popoverOpen, setPopoverOpen] = React.useState(false);
42
+
43
+ const togglePopover = () => {
44
+ setPopoverOpen(!popoverOpen);
45
+ };
46
+
47
+ return (
48
+ <>
49
+ <Popover>
50
+ <PopoverContext data-testid="Popover-context" isOpen={popoverOpen}>
51
+ <PopoverHeader>
52
+ <div>{contractualTitle}</div>
53
+ <CloseButton data-testid="close-button" onClick={togglePopover}>
54
+ <CloseIcon />
55
+ </CloseButton>
56
+ </PopoverHeader>
57
+ </PopoverContext>
58
+ <IconButton
59
+ aria-label="See contractual title, button"
60
+ data-testid="Popover"
61
+ onClick={togglePopover}
62
+ >
63
+ <TooltipIcon />
64
+ </IconButton>
65
+ </Popover>
66
+ </>
67
+ );
68
+ };
69
+
70
+ export const JobTitle: React.FC<{
71
+ contractualTitle: string;
72
+ isLargeDevice: boolean;
73
+ }> = ({ contractualTitle, isLargeDevice }) => {
74
+ return isLargeDevice ? (
75
+ <JobTitleTooltip
76
+ contractualTitle={contractualTitle}
77
+ data-testid="Tooltip"
78
+ />
79
+ ) : (
80
+ <JobTitlePopover
81
+ contractualTitle={contractualTitle}
82
+ data-testid="Popover"
83
+ />
84
+ );
85
+ };