@times-components/ts-components 1.20.0 → 1.22.1

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 (48) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +1 -1
  3. package/dist/components/article-flag/ArticleFlag.d.ts +17 -6
  4. package/dist/components/article-flag/ArticleFlag.js +28 -20
  5. package/dist/components/article-flag/ArticleFlag.stories.js +21 -3
  6. package/dist/components/article-flag/LiveArticleFlag.js +13 -6
  7. package/dist/components/article-flag/__tests__/ArticleFlag.test.js +35 -1
  8. package/dist/components/article-flag/styles.d.ts +1 -0
  9. package/dist/components/article-flag/styles.js +6 -1
  10. package/dist/components/in-article-puff/InArticlePuff.d.ts +1 -1
  11. package/dist/components/in-article-puff/InArticlePuff.js +6 -6
  12. package/dist/components/in-article-puff/InArticlePuff.stories.js +3 -3
  13. package/dist/components/updated-timestamp/UpdatedTimestamp.d.ts +4 -0
  14. package/dist/components/updated-timestamp/UpdatedTimestamp.js +21 -0
  15. package/dist/components/updated-timestamp/UpdatedTimestamp.stories.d.ts +1 -0
  16. package/dist/components/updated-timestamp/UpdatedTimestamp.stories.js +13 -0
  17. package/dist/components/updated-timestamp/__tests__/UpdatedTimestamp.test.d.ts +1 -0
  18. package/dist/components/updated-timestamp/__tests__/UpdatedTimestamp.test.js +34 -0
  19. package/dist/components/updated-timestamp/styles.d.ts +2 -0
  20. package/dist/components/updated-timestamp/styles.js +14 -0
  21. package/dist/helpers/time/UpdatedTimeProvider.d.ts +5 -0
  22. package/dist/helpers/time/UpdatedTimeProvider.js +9 -0
  23. package/dist/helpers/time/__tests__/UpdatedTimeProvider.test.d.ts +1 -0
  24. package/dist/helpers/time/__tests__/UpdatedTimeProvider.test.js +17 -0
  25. package/dist/helpers/tracking/TrackingContextProvider.js +9 -1
  26. package/dist/index.d.ts +2 -0
  27. package/dist/index.js +3 -1
  28. package/package.json +6 -5
  29. package/rnw.js +1 -1
  30. package/src/components/article-flag/ArticleFlag.stories.tsx +28 -2
  31. package/src/components/article-flag/ArticleFlag.tsx +39 -31
  32. package/src/components/article-flag/LiveArticleFlag.tsx +19 -9
  33. package/src/components/article-flag/__tests__/ArticleFlag.test.tsx +56 -0
  34. package/src/components/article-flag/__tests__/__snapshots__/ArticleFlag.test.tsx.snap +273 -47
  35. package/src/components/article-flag/__tests__/__snapshots__/LiveArticleFlag.test.tsx.snap +39 -27
  36. package/src/components/article-flag/styles.ts +6 -0
  37. package/src/components/article-header/__tests__/__snapshots__/ArticleHeader.test.tsx.snap +13 -9
  38. package/src/components/in-article-puff/InArticlePuff.stories.tsx +2 -2
  39. package/src/components/in-article-puff/InArticlePuff.tsx +6 -6
  40. package/src/components/updated-timestamp/UpdatedTimestamp.stories.tsx +18 -0
  41. package/src/components/updated-timestamp/UpdatedTimestamp.tsx +38 -0
  42. package/src/components/updated-timestamp/__tests__/UpdatedTimestamp.test.tsx +50 -0
  43. package/src/components/updated-timestamp/__tests__/__snapshots__/UpdatedTimestamp.test.tsx.snap +11 -0
  44. package/src/components/updated-timestamp/styles.ts +15 -0
  45. package/src/helpers/time/UpdatedTimeProvider.tsx +17 -0
  46. package/src/helpers/time/__tests__/UpdatedTimeProvider.test.tsx +23 -0
  47. package/src/helpers/tracking/TrackingContextProvider.tsx +10 -0
  48. package/src/index.ts +6 -0
@@ -11,7 +11,7 @@ import {
11
11
  } from './styles';
12
12
  import getActiveFlags from './getActiveFlags';
13
13
 
14
- const ArticleFlag: React.FC<{ color: string; title: string }> = ({
14
+ const ArticleFlag: React.FC<{ color?: string; title: string }> = ({
15
15
  color = colours.functional.primary,
16
16
  title
17
17
  }) => (
@@ -27,51 +27,58 @@ const ArticleFlag: React.FC<{ color: string; title: string }> = ({
27
27
  </ArticleFlagContainer>
28
28
  );
29
29
 
30
- const NewArticleFlag: React.FC = () => (
31
- <ArticleFlag color={colours.functional.articleFlagNew} title="new" />
32
- );
30
+ const NewArticleFlag: React.FC<{ color?: string }> = ({
31
+ color = colours.functional.articleFlagNew
32
+ }) => <ArticleFlag color={color} title="new" />;
33
33
 
34
- const UpdatedArticleFlag: React.FC = () => (
35
- <ArticleFlag color={colours.functional.articleFlagUpdated} title="updated" />
36
- );
34
+ const UpdatedArticleFlag: React.FC<{ color?: string }> = ({
35
+ color = colours.functional.articleFlagUpdated
36
+ }) => <ArticleFlag color={color} title="updated" />;
37
37
 
38
- const ExclusiveArticleFlag: React.FC = () => (
39
- <ArticleFlag
40
- color={colours.functional.articleFlagExclusive}
41
- title="exclusive"
42
- />
43
- );
38
+ const ExclusiveArticleFlag: React.FC<{ color?: string }> = ({
39
+ color = colours.functional.articleFlagExclusive
40
+ }) => <ArticleFlag color={color} title="exclusive" />;
44
41
 
45
- const SponsoredArticleFlag: React.FC = () => (
46
- <ArticleFlag color={colours.functional.tertiary} title="sponsored" />
47
- );
42
+ const SponsoredArticleFlag: React.FC<{ color?: string }> = ({
43
+ color = colours.functional.tertiary
44
+ }) => <ArticleFlag color={color} title="sponsored" />;
48
45
 
49
- const LongReadArticleFlag: React.FC = () => (
50
- <ArticleFlag color={colours.functional.secondary} title="long read" />
51
- );
46
+ const LongReadArticleFlag: React.FC<{ color?: string }> = ({
47
+ color = colours.functional.secondary
48
+ }) => <ArticleFlag color={color} title="long read" />;
52
49
 
53
- const flagsMapping = () =>
54
- new Map([
55
- ['NEW', <NewArticleFlag />],
50
+ const flagsMapping = (override = '') => {
51
+ let colourProp;
52
+ if (override !== '') {
53
+ colourProp = {
54
+ color: override
55
+ };
56
+ }
57
+ return new Map([
58
+ ['NEW', <NewArticleFlag {...colourProp} />],
56
59
  ['LIVE', <LiveArticleFlag />],
57
60
  ['BREAKING', <BreakingArticleFlag />],
58
- ['UPDATED', <UpdatedArticleFlag />],
59
- ['EXCLUSIVE', <ExclusiveArticleFlag />],
60
- ['SPONSORED', <SponsoredArticleFlag />],
61
- ['LONGREAD', <LongReadArticleFlag />]
61
+ ['UPDATED', <UpdatedArticleFlag {...colourProp} />],
62
+ ['EXCLUSIVE', <ExclusiveArticleFlag {...colourProp} />],
63
+ ['SPONSORED', <SponsoredArticleFlag {...colourProp} />],
64
+ ['LONGREAD', <LongReadArticleFlag {...colourProp} />]
62
65
  ]);
66
+ };
63
67
 
64
68
  export type FlagType = Array<{
65
69
  expiryTime: string | null;
66
70
  type: string;
67
71
  }>;
68
72
 
69
- const FlagsView: React.FC<{ allFlags: FlagType }> = ({ allFlags }) => {
73
+ const FlagsView: React.FC<{ allFlags: FlagType; overrideColor?: string }> = ({
74
+ allFlags,
75
+ overrideColor = ''
76
+ }) => {
70
77
  return (
71
78
  <Flags>
72
79
  {allFlags.map(flag => (
73
80
  <FlagPadding key={flag.type} allFlags={allFlags}>
74
- {flagsMapping().get(flag.type)}
81
+ {flagsMapping(overrideColor).get(flag.type)}
75
82
  </FlagPadding>
76
83
  ))}
77
84
  </Flags>
@@ -82,7 +89,8 @@ const ArticleFlags: React.FC<{
82
89
  flags: FlagType;
83
90
  longRead: boolean;
84
91
  withContainer: boolean;
85
- }> = ({ flags = [], longRead = false, withContainer = false }) => {
92
+ color?: string;
93
+ }> = ({ flags = [], longRead = false, withContainer = false, color = '' }) => {
86
94
  const activeFlags = getActiveFlags(flags);
87
95
  const allFlags = [
88
96
  ...activeFlags,
@@ -94,12 +102,12 @@ const ArticleFlags: React.FC<{
94
102
  }
95
103
 
96
104
  if (!withContainer) {
97
- return <FlagsView allFlags={allFlags} />;
105
+ return <FlagsView allFlags={allFlags} overrideColor={color} />;
98
106
  }
99
107
 
100
108
  return (
101
109
  <FlagsContainer>
102
- <FlagsView allFlags={allFlags} />
110
+ <FlagsView allFlags={allFlags} overrideColor={color} />
103
111
  </FlagsContainer>
104
112
  );
105
113
  };
@@ -2,17 +2,27 @@ import React from 'react';
2
2
  import {
3
3
  LiveArticleFlagContainer,
4
4
  LiveIconContainer,
5
- LiveArticleFlagText
5
+ LiveArticleFlagText,
6
+ LiveFlagAndTimestampContainer
6
7
  } from './styles';
8
+ import { UpdatedTimestamp } from '../updated-timestamp/UpdatedTimestamp';
9
+ import { useUpdatedTime } from '../../helpers/time/UpdatedTimeProvider';
7
10
 
8
- export const BaseLiveArticleFlag: React.FC<{ title: string }> = ({ title }) => (
9
- <LiveArticleFlagContainer>
10
- <LiveIconContainer>{'\u25a0'}</LiveIconContainer>
11
- <div>
12
- <LiveArticleFlagText>{title}</LiveArticleFlagText>
13
- </div>
14
- </LiveArticleFlagContainer>
15
- );
11
+ export const BaseLiveArticleFlag: React.FC<{ title: string }> = ({ title }) => {
12
+ const updatedTime = useUpdatedTime();
13
+
14
+ return (
15
+ <LiveFlagAndTimestampContainer>
16
+ <LiveArticleFlagContainer>
17
+ <LiveIconContainer>{'\u25a0'}</LiveIconContainer>
18
+ <div>
19
+ <LiveArticleFlagText>{title}</LiveArticleFlagText>
20
+ </div>
21
+ </LiveArticleFlagContainer>
22
+ <UpdatedTimestamp updatedTime={updatedTime} />
23
+ </LiveFlagAndTimestampContainer>
24
+ );
25
+ };
16
26
 
17
27
  export const LiveArticleFlag: React.FC = () => (
18
28
  <BaseLiveArticleFlag title="LIVE" />
@@ -71,6 +71,46 @@ describe('ArticleFlag', () => {
71
71
  expect(baseElement).toMatchSnapshot();
72
72
  });
73
73
 
74
+ it('renders the new article flag with an override colour', () => {
75
+ const { baseElement, getByText } = render(
76
+ <NewArticleFlag color="#FFFFFF" />
77
+ );
78
+ expect(getByText('new')).toBeTruthy();
79
+ expect(baseElement).toMatchSnapshot();
80
+ });
81
+
82
+ it('renders the updated article flag with an override colour', () => {
83
+ const { baseElement, getByText } = render(
84
+ <UpdatedArticleFlag color="#FFFFFF" />
85
+ );
86
+ expect(getByText('updated')).toBeTruthy();
87
+ expect(baseElement).toMatchSnapshot();
88
+ });
89
+
90
+ it('renders the exclusive article flag with an override colour', () => {
91
+ const { baseElement, getByText } = render(
92
+ <ExclusiveArticleFlag color="#FFFFFF" />
93
+ );
94
+ expect(getByText('exclusive')).toBeTruthy();
95
+ expect(baseElement).toMatchSnapshot();
96
+ });
97
+
98
+ it('renders the sponsored article flag with an override colour', () => {
99
+ const { baseElement, getByText } = render(
100
+ <SponsoredArticleFlag color="#FFFFFF" />
101
+ );
102
+ expect(getByText('sponsored')).toBeTruthy();
103
+ expect(baseElement).toMatchSnapshot();
104
+ });
105
+
106
+ it('renders the long read article flag with an override colour', () => {
107
+ const { baseElement, getByText } = render(
108
+ <LongReadArticleFlag color="#FFFFFF" />
109
+ );
110
+ expect(getByText('long read')).toBeTruthy();
111
+ expect(baseElement).toMatchSnapshot();
112
+ });
113
+
74
114
  it('renders multiple article flags', () => {
75
115
  const { baseElement } = render(
76
116
  <ArticleFlags
@@ -86,6 +126,22 @@ describe('ArticleFlag', () => {
86
126
  );
87
127
  expect(baseElement).toMatchSnapshot();
88
128
  });
129
+ it('renders multiple article flags with override colours', () => {
130
+ const { baseElement } = render(
131
+ <ArticleFlags
132
+ flags={[
133
+ { expiryTime: '2030-03-13T12:00:00.000Z', type: 'UPDATED' },
134
+ { expiryTime: '2030-03-14T12:00:00.000Z', type: 'EXCLUSIVE' },
135
+ { expiryTime: '2030-03-14T12:00:00.000Z', type: 'NEW' },
136
+ { expiryTime: '2030-03-14T12:00:00.000Z', type: 'SPONSORED' }
137
+ ]}
138
+ longRead
139
+ withContainer={false}
140
+ color="#FFFFFF"
141
+ />
142
+ );
143
+ expect(baseElement).toMatchSnapshot();
144
+ });
89
145
  it('renders multiple article flags in a container', () => {
90
146
  const { baseElement } = render(
91
147
  <ArticleFlags