@times-components/ts-components 1.16.2 → 1.18.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.
- package/CHANGELOG.md +38 -0
- package/README.md +7 -0
- package/dist/components/article-flag/ArticleFlag.d.ts +22 -0
- package/dist/components/article-flag/ArticleFlag.js +43 -0
- package/dist/components/article-flag/{LiveArticleFlag.stories.d.ts → ArticleFlag.stories.d.ts} +0 -0
- package/dist/components/article-flag/ArticleFlag.stories.js +29 -0
- package/dist/components/article-flag/LiveArticleFlag.d.ts +4 -0
- package/dist/components/article-flag/LiveArticleFlag.js +7 -5
- package/dist/components/article-flag/__tests__/ArticleFlag.test.d.ts +1 -0
- package/dist/components/article-flag/__tests__/ArticleFlag.test.js +75 -0
- package/dist/components/article-flag/__tests__/LiveArticleFlag.test.js +14 -4
- package/dist/components/article-flag/__tests__/getActiveFlags.test.d.ts +1 -0
- package/dist/components/article-flag/__tests__/getActiveFlags.test.js +36 -0
- package/dist/components/article-flag/getActiveFlags.d.ts +3 -0
- package/dist/components/article-flag/getActiveFlags.js +9 -0
- package/dist/components/article-flag/styles.d.ts +12 -3
- package/dist/components/article-flag/styles.js +38 -4
- package/dist/components/inline-dialog/InlineDialog.d.ts +7 -0
- package/dist/components/inline-dialog/InlineDialog.js +7 -0
- package/dist/components/inline-dialog/InlineDialog.stories.d.ts +1 -0
- package/dist/components/inline-dialog/InlineDialog.stories.js +8 -0
- package/dist/components/inline-dialog/__tests__/InlineDialog.test.d.ts +1 -0
- package/dist/components/inline-dialog/__tests__/InlineDialog.test.js +17 -0
- package/dist/components/inline-dialog/styles.d.ts +4 -0
- package/dist/components/inline-dialog/styles.js +50 -0
- package/dist/components/inline-message/styles.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -2
- package/jest.config.js +4 -4
- package/package.json +6 -6
- package/rnw.js +1 -1
- package/src/components/article-flag/ArticleFlag.stories.tsx +48 -0
- package/src/components/article-flag/ArticleFlag.tsx +118 -0
- package/src/components/article-flag/LiveArticleFlag.tsx +17 -5
- package/src/components/article-flag/__tests__/ArticleFlag.test.tsx +111 -0
- package/src/components/article-flag/__tests__/LiveArticleFlag.test.tsx +19 -3
- package/src/components/article-flag/__tests__/__snapshots__/ArticleFlag.test.tsx.snap +394 -0
- package/src/components/article-flag/__tests__/__snapshots__/LiveArticleFlag.test.tsx.snap +46 -4
- package/src/components/article-flag/__tests__/getActiveFlags.test.ts +38 -0
- package/src/components/article-flag/getActiveFlags.ts +14 -0
- package/src/components/article-flag/styles.ts +41 -3
- package/src/components/inline-dialog/InlineDialog.stories.tsx +17 -0
- package/src/components/inline-dialog/InlineDialog.tsx +17 -0
- package/src/components/inline-dialog/__tests__/InlineDialog.test.tsx +21 -0
- package/src/components/inline-dialog/__tests__/__snapshots__/InlineDialog.test.tsx.snap +26 -0
- package/src/components/inline-dialog/styles.ts +51 -0
- package/src/components/inline-message/__tests__/__snapshots__/InlineMessage.test.tsx.snap +1 -1
- package/src/components/inline-message/styles.ts +1 -1
- package/src/components/latest-from-section/__tests__/__snapshots__/LatestFromSection.test.tsx.snap +3 -0
- package/src/components/newsletter-puff/__tests__/__snapshots__/InlineNewsletterPuff.test.tsx.snap +4 -0
- package/src/components/newsletter-puff/__tests__/__snapshots__/PreviewNewsletterPuff.test.tsx.snap +1 -0
- package/src/index.ts +15 -1
- package/src/types/externs.d.ts +1 -0
- package/dist/components/article-flag/LiveArticleFlag.stories.js +0 -7
- package/src/components/article-flag/LiveArticleFlag.stories.tsx +0 -7
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { storiesOf } from '@storybook/react';
|
|
3
|
+
import {
|
|
4
|
+
NewArticleFlag,
|
|
5
|
+
UpdatedArticleFlag,
|
|
6
|
+
ExclusiveArticleFlag,
|
|
7
|
+
SponsoredArticleFlag,
|
|
8
|
+
LongReadArticleFlag,
|
|
9
|
+
ArticleFlags
|
|
10
|
+
} from './ArticleFlag';
|
|
11
|
+
import { LiveArticleFlag, BreakingArticleFlag } from './LiveArticleFlag';
|
|
12
|
+
|
|
13
|
+
storiesOf('Typescript Component/Article Flag', module)
|
|
14
|
+
.add('Article Flag (New)', () => <NewArticleFlag />)
|
|
15
|
+
.add('Article Flag (Live)', () => <LiveArticleFlag />)
|
|
16
|
+
.add('Article Flag (Breaking)', () => <BreakingArticleFlag />)
|
|
17
|
+
.add('Article Flag (Updated)', () => <UpdatedArticleFlag />)
|
|
18
|
+
.add('Article Flag (Exclusive)', () => <ExclusiveArticleFlag />)
|
|
19
|
+
.add('Article Flag (Sponsored)', () => <SponsoredArticleFlag />)
|
|
20
|
+
.add('Article Flag (Long Read)', () => <LongReadArticleFlag />)
|
|
21
|
+
.add('Article Flags', () => (
|
|
22
|
+
<ArticleFlags
|
|
23
|
+
flags={[
|
|
24
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'LIVE' },
|
|
25
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'BREAKING' },
|
|
26
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'UPDATED' },
|
|
27
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'EXCLUSIVE' },
|
|
28
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'NEW' },
|
|
29
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'SPONSORED' }
|
|
30
|
+
]}
|
|
31
|
+
longRead
|
|
32
|
+
withContainer={false}
|
|
33
|
+
/>
|
|
34
|
+
))
|
|
35
|
+
.add('Article Flags with Container', () => (
|
|
36
|
+
<ArticleFlags
|
|
37
|
+
flags={[
|
|
38
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'LIVE' },
|
|
39
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'BREAKING' },
|
|
40
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'UPDATED' },
|
|
41
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'EXCLUSIVE' },
|
|
42
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'NEW' },
|
|
43
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'SPONSORED' }
|
|
44
|
+
]}
|
|
45
|
+
longRead
|
|
46
|
+
withContainer
|
|
47
|
+
/>
|
|
48
|
+
));
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { colours } from '@times-components/styleguide';
|
|
3
|
+
import { LiveArticleFlag, BreakingArticleFlag } from './LiveArticleFlag';
|
|
4
|
+
import {
|
|
5
|
+
ArticleFlagContainer,
|
|
6
|
+
ArticleFlagBullet,
|
|
7
|
+
ArticleFlagTextContainer,
|
|
8
|
+
FlagPadding,
|
|
9
|
+
Flags,
|
|
10
|
+
FlagsContainer
|
|
11
|
+
} from './styles';
|
|
12
|
+
import getActiveFlags from './getActiveFlags';
|
|
13
|
+
|
|
14
|
+
const ArticleFlag: React.FC<{ color: string; title: string }> = ({
|
|
15
|
+
color = colours.functional.primary,
|
|
16
|
+
title
|
|
17
|
+
}) => (
|
|
18
|
+
<ArticleFlagContainer>
|
|
19
|
+
<ArticleFlagBullet color={color} />
|
|
20
|
+
<ArticleFlagTextContainer
|
|
21
|
+
aria-label={`${title} Flag`}
|
|
22
|
+
color={color}
|
|
23
|
+
data-testid={`flag-${title}`}
|
|
24
|
+
>
|
|
25
|
+
{title.toLowerCase()}
|
|
26
|
+
</ArticleFlagTextContainer>
|
|
27
|
+
</ArticleFlagContainer>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const NewArticleFlag: React.FC = () => (
|
|
31
|
+
<ArticleFlag color={colours.functional.articleFlagNew} title="new" />
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const UpdatedArticleFlag: React.FC = () => (
|
|
35
|
+
<ArticleFlag color={colours.functional.articleFlagUpdated} title="updated" />
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const ExclusiveArticleFlag: React.FC = () => (
|
|
39
|
+
<ArticleFlag
|
|
40
|
+
color={colours.functional.articleFlagExclusive}
|
|
41
|
+
title="exclusive"
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const SponsoredArticleFlag: React.FC = () => (
|
|
46
|
+
<ArticleFlag color={colours.functional.tertiary} title="sponsored" />
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const LongReadArticleFlag: React.FC = () => (
|
|
50
|
+
<ArticleFlag color={colours.functional.secondary} title="long read" />
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const flagsMapping = () =>
|
|
54
|
+
new Map([
|
|
55
|
+
['NEW', <NewArticleFlag />],
|
|
56
|
+
['LIVE', <LiveArticleFlag />],
|
|
57
|
+
['BREAKING', <BreakingArticleFlag />],
|
|
58
|
+
['UPDATED', <UpdatedArticleFlag />],
|
|
59
|
+
['EXCLUSIVE', <ExclusiveArticleFlag />],
|
|
60
|
+
['SPONSORED', <SponsoredArticleFlag />],
|
|
61
|
+
['LONGREAD', <LongReadArticleFlag />]
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
export type FlagType = Array<{
|
|
65
|
+
expiryTime: string | null;
|
|
66
|
+
type: string;
|
|
67
|
+
}>;
|
|
68
|
+
|
|
69
|
+
const FlagsView: React.FC<{ allFlags: FlagType }> = ({ allFlags }) => {
|
|
70
|
+
return (
|
|
71
|
+
<Flags>
|
|
72
|
+
{allFlags.map(flag => (
|
|
73
|
+
<FlagPadding key={flag.type} allFlags={allFlags}>
|
|
74
|
+
{flagsMapping().get(flag.type)}
|
|
75
|
+
</FlagPadding>
|
|
76
|
+
))}
|
|
77
|
+
</Flags>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const ArticleFlags: React.FC<{
|
|
82
|
+
flags: FlagType;
|
|
83
|
+
longRead: boolean;
|
|
84
|
+
withContainer: boolean;
|
|
85
|
+
}> = ({ flags = [], longRead = false, withContainer = false }) => {
|
|
86
|
+
const activeFlags = getActiveFlags(flags);
|
|
87
|
+
const allFlags = [
|
|
88
|
+
...activeFlags,
|
|
89
|
+
...(longRead ? [{ expiryTime: null, type: 'LONGREAD' }] : [])
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
if (!allFlags.length) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!withContainer) {
|
|
97
|
+
return <FlagsView allFlags={allFlags} />;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<FlagsContainer>
|
|
102
|
+
<FlagsView allFlags={allFlags} />
|
|
103
|
+
</FlagsContainer>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default ArticleFlag;
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
getActiveFlags,
|
|
111
|
+
ArticleFlag,
|
|
112
|
+
ArticleFlags,
|
|
113
|
+
NewArticleFlag,
|
|
114
|
+
UpdatedArticleFlag,
|
|
115
|
+
ExclusiveArticleFlag,
|
|
116
|
+
SponsoredArticleFlag,
|
|
117
|
+
LongReadArticleFlag
|
|
118
|
+
};
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
LiveArticleFlagContainer,
|
|
4
|
+
LiveDiamondContainer,
|
|
5
|
+
LiveArticleFlagTextContainer
|
|
6
|
+
} from './styles';
|
|
7
|
+
|
|
8
|
+
export const BaseLiveArticleFlag: React.FC<{ title: string }> = ({ title }) => (
|
|
9
|
+
<LiveArticleFlagContainer>
|
|
10
|
+
<LiveDiamondContainer>{'\u25c6'}</LiveDiamondContainer>
|
|
11
|
+
<LiveArticleFlagTextContainer>{title}</LiveArticleFlagTextContainer>
|
|
12
|
+
</LiveArticleFlagContainer>
|
|
13
|
+
);
|
|
3
14
|
|
|
4
15
|
export const LiveArticleFlag: React.FC = () => (
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
<BaseLiveArticleFlag title="LIVE" />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const BreakingArticleFlag: React.FC = () => (
|
|
20
|
+
<BaseLiveArticleFlag title="BREAKING" />
|
|
9
21
|
);
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import {
|
|
5
|
+
ArticleFlag,
|
|
6
|
+
ArticleFlags,
|
|
7
|
+
NewArticleFlag,
|
|
8
|
+
UpdatedArticleFlag,
|
|
9
|
+
ExclusiveArticleFlag,
|
|
10
|
+
SponsoredArticleFlag,
|
|
11
|
+
LongReadArticleFlag
|
|
12
|
+
} from '../ArticleFlag';
|
|
13
|
+
import mockDate from 'mockdate';
|
|
14
|
+
|
|
15
|
+
jest.mock('@times-components/ts-components', () => ({
|
|
16
|
+
__esModule: true,
|
|
17
|
+
...jest.requireActual('@times-components/ts-components'),
|
|
18
|
+
LiveArticleFlag: 'LiveArticleFlag'
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
describe('ArticleFlag', () => {
|
|
22
|
+
// GMT: Thursday, 14 March 2019 16:22:54
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockDate.set(1552580574000);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
mockDate.reset();
|
|
29
|
+
});
|
|
30
|
+
it('renders an article flag', () => {
|
|
31
|
+
const { baseElement } = render(
|
|
32
|
+
<ArticleFlag title="No Colour" color={''} />
|
|
33
|
+
);
|
|
34
|
+
expect(baseElement).toMatchSnapshot();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('renders a red article flag', () => {
|
|
38
|
+
const { baseElement } = render(
|
|
39
|
+
<ArticleFlag color="red" title="Coloured Red" />
|
|
40
|
+
);
|
|
41
|
+
expect(baseElement).toMatchSnapshot();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('renders the new article flag', () => {
|
|
45
|
+
const { baseElement, getByText } = render(<NewArticleFlag />);
|
|
46
|
+
expect(getByText('new')).toBeTruthy();
|
|
47
|
+
expect(baseElement).toMatchSnapshot();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders the updated article flag', () => {
|
|
51
|
+
const { baseElement, getByText } = render(<UpdatedArticleFlag />);
|
|
52
|
+
expect(getByText('updated')).toBeTruthy();
|
|
53
|
+
expect(baseElement).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('renders the exclusive article flag', () => {
|
|
57
|
+
const { baseElement, getByText } = render(<ExclusiveArticleFlag />);
|
|
58
|
+
expect(getByText('exclusive')).toBeTruthy();
|
|
59
|
+
expect(baseElement).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders the sponsored article flag', () => {
|
|
63
|
+
const { baseElement, getByText } = render(<SponsoredArticleFlag />);
|
|
64
|
+
expect(getByText('sponsored')).toBeTruthy();
|
|
65
|
+
expect(baseElement).toMatchSnapshot();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders the long read article flag', () => {
|
|
69
|
+
const { baseElement, getByText } = render(<LongReadArticleFlag />);
|
|
70
|
+
expect(getByText('long read')).toBeTruthy();
|
|
71
|
+
expect(baseElement).toMatchSnapshot();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('renders multiple article flags', () => {
|
|
75
|
+
const { baseElement } = render(
|
|
76
|
+
<ArticleFlags
|
|
77
|
+
flags={[
|
|
78
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'UPDATED' },
|
|
79
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'EXCLUSIVE' },
|
|
80
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'NEW' },
|
|
81
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'SPONSORED' }
|
|
82
|
+
]}
|
|
83
|
+
longRead
|
|
84
|
+
withContainer={false}
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
expect(baseElement).toMatchSnapshot();
|
|
88
|
+
});
|
|
89
|
+
it('renders multiple article flags in a container', () => {
|
|
90
|
+
const { baseElement } = render(
|
|
91
|
+
<ArticleFlags
|
|
92
|
+
flags={[
|
|
93
|
+
{ expiryTime: '2030-03-13T12:00:00.000Z', type: 'UPDATED' },
|
|
94
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'EXCLUSIVE' },
|
|
95
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'NEW' },
|
|
96
|
+
{ expiryTime: '2030-03-14T12:00:00.000Z', type: 'SPONSORED' }
|
|
97
|
+
]}
|
|
98
|
+
longRead
|
|
99
|
+
withContainer
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
expect(baseElement).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('does not render article flags if there are none', () => {
|
|
106
|
+
const { baseElement } = render(
|
|
107
|
+
<ArticleFlags flags={[]} longRead={false} withContainer={false} />
|
|
108
|
+
);
|
|
109
|
+
expect(baseElement).toMatchSnapshot();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -2,10 +2,26 @@ import React from 'react';
|
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
3
|
import '@testing-library/jest-dom';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
BaseLiveArticleFlag,
|
|
7
|
+
BreakingArticleFlag,
|
|
8
|
+
LiveArticleFlag
|
|
9
|
+
} from '../LiveArticleFlag';
|
|
6
10
|
|
|
7
|
-
describe('
|
|
8
|
-
it('should render the
|
|
11
|
+
describe('LiveArticleFlag', () => {
|
|
12
|
+
it('should render the base live article flag', () => {
|
|
13
|
+
const { baseElement, getByText } = render(
|
|
14
|
+
<BaseLiveArticleFlag title="BASE" />
|
|
15
|
+
);
|
|
16
|
+
expect(getByText('BASE')).toBeTruthy();
|
|
17
|
+
expect(baseElement).toMatchSnapshot();
|
|
18
|
+
});
|
|
19
|
+
it('should render the breaking article flag', () => {
|
|
20
|
+
const { baseElement, getByText } = render(<BreakingArticleFlag />);
|
|
21
|
+
expect(getByText('BREAKING')).toBeTruthy();
|
|
22
|
+
expect(baseElement).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
it('should render the live article flag', () => {
|
|
9
25
|
const { baseElement, getByText } = render(<LiveArticleFlag />);
|
|
10
26
|
expect(getByText('LIVE')).toBeTruthy();
|
|
11
27
|
expect(baseElement).toMatchSnapshot();
|