@times-components/ts-components 1.72.3 → 1.74.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 (24) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.d.ts +6 -0
  3. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +55 -0
  4. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.stories.d.ts +1 -0
  5. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.stories.js +26 -0
  6. package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.d.ts +2 -0
  7. package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +39 -0
  8. package/dist/components/opta/cricket/scorecard/styles.d.ts +1 -0
  9. package/dist/components/opta/cricket/scorecard/styles.js +334 -0
  10. package/dist/components/opta/cricket/shared-styles.d.ts +6 -0
  11. package/dist/components/opta/cricket/shared-styles.js +72 -0
  12. package/dist/components/opta/utils/config.js +3 -1
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +2 -1
  15. package/package.json +3 -3
  16. package/rnw.js +1 -1
  17. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.stories.tsx +34 -0
  18. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +81 -0
  19. package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +51 -0
  20. package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +34 -0
  21. package/src/components/opta/cricket/scorecard/styles.ts +335 -0
  22. package/src/components/opta/cricket/shared-styles.ts +75 -0
  23. package/src/components/opta/utils/config.ts +3 -0
  24. package/src/index.ts +4 -0
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { showcaseConverter } from '@times-components/storybook';
3
+
4
+ import { ArticleHarness } from '../../../../fixtures/article-harness/ArticleHarness';
5
+ import { OptaCricketScorecard } from './OptaCricketScorecard';
6
+
7
+ const showcase = {
8
+ children: [
9
+ {
10
+ decorator: (storyFn: () => React.ReactNode) => (
11
+ <ArticleHarness>{storyFn()}</ArticleHarness>
12
+ ),
13
+ type: 'decorator'
14
+ },
15
+ {
16
+ component: () => (
17
+ <OptaCricketScorecard competition="2722" match="49716" />
18
+ ),
19
+ name: 'Scorecard',
20
+ type: 'story'
21
+ },
22
+ {
23
+ component: () => (
24
+ <OptaCricketScorecard competition="3071" match="55391" />
25
+ ),
26
+ name: 'Scorecard (1st inns)',
27
+ type: 'story'
28
+ }
29
+ ],
30
+ name: 'Typescript Component/In Article/Cricket/Scorecard'
31
+ };
32
+
33
+ // @ts-ignore
34
+ showcaseConverter(module, showcase);
@@ -0,0 +1,81 @@
1
+ import React, { useState, useEffect } from 'react';
2
+
3
+ import { Placeholder } from '@times-components/image';
4
+
5
+ import {
6
+ initSettings,
7
+ initStyleSheet,
8
+ initScript,
9
+ initElement,
10
+ initComponent
11
+ } from '../../utils/config';
12
+
13
+ import { Container, PlaceholderContainer } from '../shared-styles';
14
+ import { WidgetContainer } from './styles';
15
+
16
+ export const OptaCricketScorecard: React.FC<{
17
+ competition: string;
18
+ match: string;
19
+ full_width?: boolean;
20
+ }> = React.memo(({ competition, match, full_width }) => {
21
+ const ref = React.createRef<HTMLDivElement>();
22
+
23
+ const [isReady, setIsReady] = useState<boolean>(false);
24
+
25
+ useEffect(() => {
26
+ const sport = 'cricket';
27
+
28
+ initSettings();
29
+ initStyleSheet(sport);
30
+
31
+ initScript().then(() => {
32
+ if (ref.current) {
33
+ ref.current.innerHTML = initElement('opta-widget', {
34
+ sport,
35
+ widget: 'score_card',
36
+ season: '0',
37
+ competition,
38
+ match,
39
+ template: 'normal',
40
+ live: true,
41
+ show_match_header: true,
42
+ show_crests: true,
43
+ show_competition_name: true,
44
+ show_match_description: true,
45
+ show_date: true,
46
+ date_format: 'DD/MM/YYYY',
47
+ show_venue: true,
48
+ show_officials: false,
49
+ show_toss: false,
50
+ show_state_of_play: true,
51
+ navigation: 'tabs',
52
+ show_batting: true,
53
+ show_mins_batted: false,
54
+ show_fours: true,
55
+ show_sixes: true,
56
+ show_strike_rate: true,
57
+ show_bowling: true,
58
+ show_economy: true,
59
+ show_fow: true,
60
+ player_naming: 'last_name',
61
+ breakpoints: '520'
62
+ }).outerHTML;
63
+
64
+ initComponent();
65
+ setIsReady(true);
66
+ }
67
+ });
68
+ }, []);
69
+
70
+ return (
71
+ <Container border={isReady} fullWidth={full_width}>
72
+ <WidgetContainer ref={ref} />
73
+
74
+ {!isReady && (
75
+ <PlaceholderContainer>
76
+ <Placeholder />
77
+ </PlaceholderContainer>
78
+ )}
79
+ </Container>
80
+ );
81
+ });
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { render, waitForElementToBeRemoved } from '@testing-library/react';
3
+
4
+ import 'regenerator-runtime';
5
+ import '@testing-library/jest-dom';
6
+
7
+ jest.mock('@times-components/image', () => ({
8
+ Placeholder: () => <>Placeholder</>
9
+ }));
10
+
11
+ const mockInitSettings = jest.fn();
12
+ const mockInitStyleSheet = jest.fn();
13
+ const mockInitComponent = jest.fn();
14
+
15
+ const mockInitElement = () => {
16
+ const element = document.createElement('div');
17
+ element.appendChild(document.createTextNode('Widget'));
18
+ return element;
19
+ };
20
+
21
+ jest.mock('../../../utils/config', () => ({
22
+ initSettings: mockInitSettings,
23
+ initStyleSheet: mockInitStyleSheet,
24
+ initScript: () => new Promise(resolve => resolve({})),
25
+ initElement: mockInitElement,
26
+ initComponent: mockInitComponent
27
+ }));
28
+
29
+ import { OptaCricketScorecard } from '../OptaCricketScorecard';
30
+
31
+ const requiredProps = {
32
+ competition: '2722',
33
+ match: '49716'
34
+ };
35
+
36
+ describe('OptaCricketScorecard', () => {
37
+ it('should render correctly', async () => {
38
+ const { asFragment, getByText } = render(
39
+ <OptaCricketScorecard {...requiredProps} />
40
+ );
41
+ expect(asFragment()).toMatchSnapshot();
42
+
43
+ await waitForElementToBeRemoved(getByText('Placeholder'));
44
+
45
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
46
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
47
+ expect(mockInitComponent).toHaveBeenCalledTimes(1);
48
+
49
+ expect(asFragment()).toMatchSnapshot();
50
+ });
51
+ });
@@ -0,0 +1,34 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`OptaCricketScorecard should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb FnNeB"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaCricketScorecard should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb FnNeB"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -0,0 +1,335 @@
1
+ import styled from 'styled-components';
2
+ import { colours, fonts } from '@times-components/ts-styleguide';
3
+
4
+ import { WidgetContainerBase } from '../shared-styles';
5
+
6
+ export const WidgetContainer = styled(WidgetContainerBase)`
7
+ .Opta {
8
+ h2 {
9
+ margin: 20px 0 10px 0 !important;
10
+ }
11
+
12
+ .Opta-Cf {
13
+ padding: 0;
14
+ background-color: transparent;
15
+
16
+ table {
17
+ tbody {
18
+ tr {
19
+ td {
20
+ color: ${colours.functional.brandColour};
21
+ font-family: ${fonts.headline};
22
+ font-size: 18px;
23
+ line-height: 18px;
24
+ padding: 0;
25
+
26
+ &.Opta-Crest {
27
+ text-align: left;
28
+
29
+ &.Opta-Home {
30
+ text-align: right;
31
+ }
32
+
33
+ img {
34
+ height: 40px;
35
+ }
36
+ }
37
+
38
+ &.Opta-Team {
39
+ padding-left: 10px;
40
+ font-size: 18px;
41
+ line-height: 18px;
42
+
43
+ &.Opta-Home {
44
+ padding-right: 10px;
45
+ padding-left: 0;
46
+ text-align: right;
47
+ }
48
+ }
49
+ }
50
+
51
+ &.Opta-MatchHeader-Details {
52
+ div {
53
+ margin: 6px 0;
54
+ padding: 0;
55
+ color: ${colours.section.sport};
56
+ font-family: ${fonts.supporting};
57
+ font-size: 12px;
58
+ line-height: 12px;
59
+ letter-spacing: 1px;
60
+ text-transform: uppercase;
61
+ background-color: transparent;
62
+
63
+ dl {
64
+ margin: 0 6px 4px 6px;
65
+ color: inherit;
66
+ font-size: inherit;
67
+
68
+ :before {
69
+ display: none;
70
+ }
71
+
72
+ &:first-of-type,
73
+ &:last-of-type {
74
+ display: block;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+
83
+ .Opta-CricketStateOfPlay {
84
+ div {
85
+ min-height: 0;
86
+ margin: 0;
87
+ padding: 10px;
88
+ color: ${colours.functional.brandColour};
89
+ font-family: ${fonts.headline};
90
+ font-size: 18px;
91
+ font-weight: normal;
92
+ line-height: 18px;
93
+ background-color: transparent;
94
+ }
95
+ }
96
+
97
+ .Opta-scorecard {
98
+ .Opta-Tabs {
99
+ .Opta-Nav {
100
+ background-color: transparent;
101
+
102
+ ul {
103
+ display: flex;
104
+ background-color: transparent;
105
+
106
+ li {
107
+ width: 100%;
108
+
109
+ a {
110
+ width: 100%;
111
+ color: ${colours.functional.brandColour};
112
+ font-family: ${fonts.supporting};
113
+ font-size: 14px;
114
+ font-weight: normal;
115
+ text-align: center;
116
+ background-color: #dbdbdb;
117
+
118
+ &:hover {
119
+ background-color: #ededed;
120
+ }
121
+ }
122
+
123
+ &.Opta-On a {
124
+ color: white;
125
+ background-color: #008347;
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+
132
+ table.Opta-batting {
133
+ margin-bottom: 10px;
134
+
135
+ thead {
136
+ th {
137
+ width: 8%;
138
+ padding: 0;
139
+ color: ${colours.functional.primary};
140
+ font-family: ${fonts.supporting};
141
+ font-size: 12px;
142
+ line-height: 14px;
143
+ font-weight: normal;
144
+ background-color: #ededed;
145
+
146
+ &:first-of-type {
147
+ width: 64%;
148
+ padding-left: 5px;
149
+ }
150
+
151
+ &:nth-of-type(4),
152
+ &:nth-of-type(5) {
153
+ width: 6%;
154
+ }
155
+ }
156
+ }
157
+
158
+ tfoot {
159
+ th {
160
+ color: ${colours.functional.brandColour};
161
+ font-family: ${fonts.supporting};
162
+ font-size: 14px;
163
+ line-height: 14px;
164
+ font-weight: bold;
165
+ background-color: #dbdbdb;
166
+
167
+ &:first-of-type {
168
+ padding-left: 5px;
169
+ }
170
+
171
+ &:last-of-type {
172
+ padding-left: 0;
173
+ }
174
+ }
175
+ }
176
+
177
+ tbody {
178
+ tr:nth-child(2n) th,
179
+ tr:nth-child(2n) td {
180
+ background-color: #ededed;
181
+ }
182
+
183
+ tr:last-of-type td {
184
+ color: ${colours.functional.brandColour};
185
+ font-family: ${fonts.supporting};
186
+ font-size: 12px;
187
+ line-height: 14px;
188
+ font-weight: normal;
189
+ }
190
+
191
+ th {
192
+ padding: 0;
193
+ color: ${colours.functional.brandColour};
194
+ font-family: ${fonts.supporting};
195
+ font-size: 12px;
196
+ line-height: 14px;
197
+ font-weight: bold;
198
+ }
199
+
200
+ td {
201
+ padding: 0;
202
+ color: ${colours.section.sport};
203
+ font-family: ${fonts.supporting};
204
+ font-size: 12px;
205
+ line-height: 14px;
206
+ font-weight: normal;
207
+
208
+ &:first-of-type,
209
+ &:nth-of-type(2) {
210
+ padding-left: 5px;
211
+ color: ${colours.functional.brandColour};
212
+ font-family: ${fonts.headline};
213
+ font-size: 16px;
214
+ font-weight: normal;
215
+ line-height: 16px;
216
+ }
217
+ }
218
+ }
219
+ }
220
+
221
+ table.Opta-bowling {
222
+ width: calc(60% - 10px);
223
+ float: left;
224
+
225
+ thead {
226
+ th {
227
+ width: 12%;
228
+ color: ${colours.functional.brandColour};
229
+ font-family: ${fonts.supporting};
230
+ font-size: 12px;
231
+ line-height: 14px;
232
+ font-weight: normal;
233
+ text-align: center;
234
+ background-color: #ededed;
235
+
236
+ &:first-of-type {
237
+ width: 40%;
238
+ padding-left: 5px;
239
+ text-align: left;
240
+ }
241
+ }
242
+ }
243
+
244
+ tbody {
245
+ th {
246
+ padding: 0;
247
+ color: ${colours.functional.brandColour};
248
+ font-family: ${fonts.supporting};
249
+ font-size: 12px;
250
+ line-height: 14px;
251
+ font-weight: bold;
252
+ text-align: center;
253
+ }
254
+
255
+ td {
256
+ padding: 0;
257
+ color: ${colours.section.sport};
258
+ font-family: ${fonts.supporting};
259
+ font-size: 12px;
260
+ line-height: 14px;
261
+ font-weight: normal;
262
+ text-align: center;
263
+
264
+ &:first-of-type {
265
+ padding-left: 5px;
266
+ color: ${colours.functional.brandColour};
267
+ font-family: ${fonts.headline};
268
+ font-size: 16px;
269
+ font-weight: normal;
270
+ line-height: 16px;
271
+ text-align: left;
272
+ }
273
+ }
274
+ }
275
+ }
276
+
277
+ .Opta-Ranking {
278
+ table {
279
+ width: calc(40%);
280
+ float: right;
281
+
282
+ thead {
283
+ th {
284
+ color: ${colours.functional.brandColour};
285
+ font-family: ${fonts.supporting};
286
+ font-size: 12px;
287
+ line-height: 14px;
288
+ font-weight: normal;
289
+ text-align: center;
290
+ background-color: #ededed;
291
+
292
+ &:first-of-type {
293
+ padding-left: 5px;
294
+ text-align: left;
295
+ }
296
+ }
297
+ }
298
+
299
+ tbody {
300
+ th {
301
+ padding: 0;
302
+ color: ${colours.functional.brandColour};
303
+ font-family: ${fonts.supporting};
304
+ font-size: 12px;
305
+ line-height: 14px;
306
+ font-weight: bold;
307
+ text-align: center;
308
+ }
309
+
310
+ td {
311
+ padding: 0;
312
+ color: ${colours.section.sport};
313
+ font-family: ${fonts.supporting};
314
+ font-size: 12px;
315
+ line-height: 14px;
316
+ font-weight: normal;
317
+ text-align: center;
318
+
319
+ &:first-of-type {
320
+ padding-left: 5px;
321
+ color: ${colours.functional.brandColour};
322
+ font-family: ${fonts.headline};
323
+ font-size: 16px;
324
+ font-weight: normal;
325
+ line-height: 16px;
326
+ text-align: left;
327
+ }
328
+ }
329
+ }
330
+ }
331
+ }
332
+ }
333
+ }
334
+ }
335
+ `;
@@ -0,0 +1,75 @@
1
+ import styled from 'styled-components';
2
+ import { breakpoints, colours, fonts } from '@times-components/ts-styleguide';
3
+
4
+ export const Container = styled.div<{ border: boolean; fullWidth?: boolean }>`
5
+ margin: 0 auto 20px auto;
6
+ background-color: ${colours.functional.backgroundPrimary};
7
+ border-top: ${({ border }) =>
8
+ border ? `2px solid ${colours.section.sport}` : 'none'};
9
+
10
+ a {
11
+ text-decoration: none;
12
+ }
13
+
14
+ @media (min-width: ${breakpoints.medium}px) {
15
+ flex-direction: row;
16
+ width: ${({ fullWidth }) => (fullWidth ? '100%' : '80.8%')};
17
+ }
18
+
19
+ @media (min-width: ${breakpoints.wide}px) {
20
+ width: ${({ fullWidth }) => (fullWidth ? '100%' : '56.2%')};
21
+ }
22
+ `;
23
+
24
+ export const PlaceholderContainer = styled.div`
25
+ position: relative;
26
+ height: 200px;
27
+ `;
28
+
29
+ export const WidgetContainerBase = styled.div`
30
+ .Opta {
31
+ .Opta_W {
32
+ margin: 0;
33
+ background-color: transparent;
34
+
35
+ h2 {
36
+ height: auto;
37
+ margin: 20px 0;
38
+ color: ${colours.section.sport};
39
+ font-family: ${fonts.supporting};
40
+ font-size: 12px;
41
+ line-height: 14px;
42
+ font-weight: normal;
43
+ letter-spacing: 1px;
44
+ text-align: center;
45
+ text-transform: uppercase;
46
+ background-color: transparent;
47
+
48
+ span {
49
+ height: auto;
50
+ font-size: 12px;
51
+ line-height: 14px;
52
+ font-weight: normal;
53
+ }
54
+ }
55
+
56
+ table {
57
+ width: 100%;
58
+ margin: 0;
59
+ border-collapse: collapse;
60
+ border-spacing: 0;
61
+ }
62
+ }
63
+
64
+ p {
65
+ margin: 20px 0 0 0 !important;
66
+ padding: 0 0 20px 0 !important;
67
+ color: ${colours.functional.brandColour};
68
+ font-family: ${fonts.supporting};
69
+ font-size: 14px;
70
+ line-height: 14px;
71
+ text-align: center;
72
+ background: transparent !important;
73
+ }
74
+ }
75
+ `;
@@ -27,6 +27,9 @@ export const initSettings = () => {
27
27
 
28
28
  const getStyleSheetUrl = (sport: string) => {
29
29
  switch (sport) {
30
+ case 'cricket':
31
+ return 'https://secure.widget.cloud.opta.net/v3/css/v3.cricket.opta-widgets.css';
32
+
30
33
  case 'rugby':
31
34
  return 'https://secure.widget.cloud.opta.net/v3/css/v3.rugby.opta-widgets.css';
32
35
 
package/src/index.ts CHANGED
@@ -34,6 +34,10 @@ export {
34
34
  } from './components/newsletter-puff/preview-newsletter-puff/PreviewNewsletterPuff';
35
35
 
36
36
  // Sport Components
37
+ export {
38
+ OptaCricketScorecard
39
+ } from './components/opta/cricket/scorecard/OptaCricketScorecard';
40
+
37
41
  export {
38
42
  OptaFootballFixtures
39
43
  } from './components/opta/football/fixtures/OptaFootballFixtures';