@times-components/ts-components 1.16.3 → 1.18.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.
- 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 +14 -14
- 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/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
|
@@ -1,18 +1,60 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[
|
|
3
|
+
exports[`LiveArticleFlag should render the base live article flag 1`] = `
|
|
4
4
|
<body>
|
|
5
5
|
<div>
|
|
6
6
|
<div
|
|
7
|
-
class="sc-
|
|
7
|
+
class="sc-bwzfXH WFEid"
|
|
8
8
|
>
|
|
9
9
|
<div
|
|
10
|
-
class="sc-
|
|
10
|
+
class="sc-bxivhb hmIbmT"
|
|
11
11
|
>
|
|
12
12
|
◆
|
|
13
13
|
</div>
|
|
14
14
|
<div
|
|
15
|
-
class="sc-
|
|
15
|
+
class="sc-EHOje jboioV"
|
|
16
|
+
>
|
|
17
|
+
BASE
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</body>
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
exports[`LiveArticleFlag should render the breaking article flag 1`] = `
|
|
25
|
+
<body>
|
|
26
|
+
<div>
|
|
27
|
+
<div
|
|
28
|
+
class="sc-bwzfXH WFEid"
|
|
29
|
+
>
|
|
30
|
+
<div
|
|
31
|
+
class="sc-bxivhb hmIbmT"
|
|
32
|
+
>
|
|
33
|
+
◆
|
|
34
|
+
</div>
|
|
35
|
+
<div
|
|
36
|
+
class="sc-EHOje jboioV"
|
|
37
|
+
>
|
|
38
|
+
BREAKING
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</body>
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`LiveArticleFlag should render the live article flag 1`] = `
|
|
46
|
+
<body>
|
|
47
|
+
<div>
|
|
48
|
+
<div
|
|
49
|
+
class="sc-bwzfXH WFEid"
|
|
50
|
+
>
|
|
51
|
+
<div
|
|
52
|
+
class="sc-bxivhb hmIbmT"
|
|
53
|
+
>
|
|
54
|
+
◆
|
|
55
|
+
</div>
|
|
56
|
+
<div
|
|
57
|
+
class="sc-EHOje jboioV"
|
|
16
58
|
>
|
|
17
59
|
LIVE
|
|
18
60
|
</div>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import mockDate from 'mockdate';
|
|
2
|
+
import getActiveFlags from '../getActiveFlags';
|
|
3
|
+
|
|
4
|
+
describe('get active flags function', () => {
|
|
5
|
+
// GMT: Thursday, 14 March 2019 16:22:54
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
mockDate.set(1552580574000);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
mockDate.reset();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('returns only active flags', () => {
|
|
15
|
+
const flags = [
|
|
16
|
+
{ expiryTime: '2020-03-13T12:00:00.000Z', type: 'UPDATED' },
|
|
17
|
+
{ expiryTime: '2019-03-14T12:00:00.000Z', type: 'EXCLUSIVE' }
|
|
18
|
+
];
|
|
19
|
+
expect(getActiveFlags(flags)).toEqual([flags[0]]);
|
|
20
|
+
});
|
|
21
|
+
it('returns no flags when all have expired', () => {
|
|
22
|
+
const flags = [
|
|
23
|
+
{ expiryTime: '2019-03-14T16:22:54.000Z', type: 'UPDATED' },
|
|
24
|
+
{ expiryTime: '2019-03-14T12:00:00.000Z', type: 'EXCLUSIVE' }
|
|
25
|
+
];
|
|
26
|
+
expect(getActiveFlags(flags)).toEqual([]);
|
|
27
|
+
});
|
|
28
|
+
it('returns flags when expiry time is null', () => {
|
|
29
|
+
const flags = [
|
|
30
|
+
{ expiryTime: null, type: 'UPDATED' },
|
|
31
|
+
{ expiryTime: null, type: 'EXCLUSIVE' }
|
|
32
|
+
];
|
|
33
|
+
expect(getActiveFlags(flags)).toEqual(flags);
|
|
34
|
+
});
|
|
35
|
+
it('returns no flags when no flags are provided', () => {
|
|
36
|
+
expect(getActiveFlags([])).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FlagType } from './ArticleFlag';
|
|
2
|
+
|
|
3
|
+
const getActiveArticleFlags: (flags: FlagType) => FlagType = flags => {
|
|
4
|
+
if (!flags) {
|
|
5
|
+
return [];
|
|
6
|
+
}
|
|
7
|
+
return flags.filter(
|
|
8
|
+
flag =>
|
|
9
|
+
flag.expiryTime === null ||
|
|
10
|
+
new Date().getTime() < new Date(flag.expiryTime).getTime()
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default getActiveArticleFlags;
|
|
@@ -1,20 +1,44 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
2
|
import { fonts } from '@times-components/styleguide';
|
|
3
|
+
import { FlagType } from './ArticleFlag';
|
|
4
|
+
import { gqlRgbaToStyle } from '@times-components/utils';
|
|
3
5
|
|
|
4
|
-
export const
|
|
6
|
+
export const ArticleFlagContainer = styled.div`
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
flex-direction: row;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const LiveArticleFlagContainer = styled.div`
|
|
5
13
|
display: flex;
|
|
6
14
|
padding: 2px 6px;
|
|
7
15
|
background-color: #9f0000;
|
|
8
16
|
align-items: baseline;
|
|
9
17
|
`;
|
|
10
18
|
|
|
11
|
-
export const
|
|
19
|
+
export const ArticleFlagBullet = styled.div`
|
|
20
|
+
border-radius: 2.5px;
|
|
21
|
+
height: 5px;
|
|
22
|
+
width: 5px;
|
|
23
|
+
background-color: ${({ color }) => gqlRgbaToStyle(color) || color};
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const LiveDiamondContainer = styled.div`
|
|
12
27
|
margin-right: 4px;
|
|
13
28
|
color: #ffffff;
|
|
14
29
|
line-height: 16px;
|
|
15
30
|
`;
|
|
16
31
|
|
|
17
|
-
export const
|
|
32
|
+
export const ArticleFlagTextContainer = styled.div`
|
|
33
|
+
font-family: TimesDigitalW04-RegularSC;
|
|
34
|
+
font-size: 12px;
|
|
35
|
+
font-weight: 400;
|
|
36
|
+
letter-spacing: 0.6px;
|
|
37
|
+
line-height: 12px;
|
|
38
|
+
margin-left: 5px;
|
|
39
|
+
color: ${({ color }) => gqlRgbaToStyle(color) || color};
|
|
40
|
+
`;
|
|
41
|
+
export const LiveArticleFlagTextContainer = styled.div`
|
|
18
42
|
font-family: ${fonts.supporting};
|
|
19
43
|
color: #ffffff;
|
|
20
44
|
font-weight: 500;
|
|
@@ -22,3 +46,17 @@ export const Title = styled.div`
|
|
|
22
46
|
letter-spacing: 0.1em;
|
|
23
47
|
line-height: 16px;
|
|
24
48
|
`;
|
|
49
|
+
|
|
50
|
+
export const FlagPadding = styled.div<{ allFlags: FlagType }>`
|
|
51
|
+
margin-right: ${({ allFlags }) => (allFlags.length > 1 ? '15px' : 0)};
|
|
52
|
+
`;
|
|
53
|
+
export const Flags = styled.div`
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: row;
|
|
56
|
+
flex-wrap: wrap;
|
|
57
|
+
margin-bottom: 10px;
|
|
58
|
+
`;
|
|
59
|
+
export const FlagsContainer = styled.div`
|
|
60
|
+
margin-bottom: 15px;
|
|
61
|
+
margin-top: 5px;
|
|
62
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { storiesOf } from '@storybook/react';
|
|
3
|
+
import { InlineDialog } from './InlineDialog';
|
|
4
|
+
import { action } from '@storybook/addon-actions';
|
|
5
|
+
|
|
6
|
+
storiesOf('Typescript Component/InlineDialog', module).add('default', () => {
|
|
7
|
+
return (
|
|
8
|
+
<InlineDialog
|
|
9
|
+
title="Join the conversation"
|
|
10
|
+
buttonText="Subscribe Now"
|
|
11
|
+
onClick={() => action('InlineDialog')('click')}
|
|
12
|
+
>
|
|
13
|
+
Commenting is only for subscribers. If you would like to comment, please
|
|
14
|
+
sign up.
|
|
15
|
+
</InlineDialog>
|
|
16
|
+
);
|
|
17
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Container, Title, Description, Button } from './styles';
|
|
3
|
+
|
|
4
|
+
export const InlineDialog: FC<{
|
|
5
|
+
title: string;
|
|
6
|
+
buttonText: string;
|
|
7
|
+
href?: string;
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
}> = ({ title, href = '#', onClick, buttonText, children }) => (
|
|
10
|
+
<Container>
|
|
11
|
+
<Title>{title}</Title>
|
|
12
|
+
<Description>{children}</Description>
|
|
13
|
+
<Button href={href} onClick={onClick}>
|
|
14
|
+
{buttonText}
|
|
15
|
+
</Button>
|
|
16
|
+
</Container>
|
|
17
|
+
);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
|
|
5
|
+
import { InlineDialog } from '../InlineDialog';
|
|
6
|
+
|
|
7
|
+
describe('<InlineDialog>', () => {
|
|
8
|
+
it('should render the component', () => {
|
|
9
|
+
const onClick = jest.fn();
|
|
10
|
+
const { baseElement, getByText } = render(
|
|
11
|
+
<InlineDialog title="Title" buttonText="Button" onClick={onClick} />
|
|
12
|
+
);
|
|
13
|
+
expect(getByText('Title')).toBeTruthy();
|
|
14
|
+
const button = getByText('Button');
|
|
15
|
+
fireEvent.click(button);
|
|
16
|
+
expect(onClick).toHaveBeenCalled();
|
|
17
|
+
expect(button).toBeTruthy();
|
|
18
|
+
|
|
19
|
+
expect(baseElement).toMatchSnapshot();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<InlineDialog> should render the component 1`] = `
|
|
4
|
+
<body>
|
|
5
|
+
<div>
|
|
6
|
+
<div
|
|
7
|
+
class="sc-bdVaJa dmvPpj"
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
class="sc-bwzfXH mYYIt"
|
|
11
|
+
>
|
|
12
|
+
Title
|
|
13
|
+
</div>
|
|
14
|
+
<div
|
|
15
|
+
class="sc-htpNat dBfnu"
|
|
16
|
+
/>
|
|
17
|
+
<a
|
|
18
|
+
class="sc-bxivhb bTkHyz"
|
|
19
|
+
href="#"
|
|
20
|
+
>
|
|
21
|
+
Button
|
|
22
|
+
</a>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
</body>
|
|
26
|
+
`;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { breakpoints, fonts } from '@times-components/styleguide';
|
|
3
|
+
|
|
4
|
+
export const Container = styled.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
align-items: center;
|
|
8
|
+
padding: 60px;
|
|
9
|
+
|
|
10
|
+
@media (min-width: ${breakpoints.medium}px) {
|
|
11
|
+
padding: 88px;
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const Title = styled.div`
|
|
16
|
+
font-family: ${fonts.headline};
|
|
17
|
+
font-size: 32px;
|
|
18
|
+
line-height: 32px;
|
|
19
|
+
letter-spacing: 0;
|
|
20
|
+
text-align: center;
|
|
21
|
+
padding: 24px;
|
|
22
|
+
`;
|
|
23
|
+
export const Description = styled.div`
|
|
24
|
+
font-family: ${fonts.body};
|
|
25
|
+
font-weight: 400;
|
|
26
|
+
font-size: 18px;
|
|
27
|
+
line-height: 28px;
|
|
28
|
+
letter-spacing: 0;
|
|
29
|
+
text-align: center;
|
|
30
|
+
max-width: 660px;
|
|
31
|
+
`;
|
|
32
|
+
export const Button = styled.a`
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
text-decoration: none;
|
|
37
|
+
|
|
38
|
+
background-color: #008387;
|
|
39
|
+
color: white;
|
|
40
|
+
font-family: ${fonts.supporting};
|
|
41
|
+
width: 127px;
|
|
42
|
+
height: 48px;
|
|
43
|
+
|
|
44
|
+
font-size: 16px;
|
|
45
|
+
font-style: normal;
|
|
46
|
+
font-weight: 500;
|
|
47
|
+
line-height: 20px;
|
|
48
|
+
letter-spacing: 0;
|
|
49
|
+
|
|
50
|
+
margin: 24px;
|
|
51
|
+
`;
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,19 @@ export {
|
|
|
6
6
|
InfoCardBulletPoints
|
|
7
7
|
} from './components/in-article-info-card-bulletpoints/InfoCardBulletPoints';
|
|
8
8
|
export { BigNumbers } from './components/in-article-big-numbers/BigNumbers';
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
BreakingArticleFlag,
|
|
11
|
+
LiveArticleFlag
|
|
12
|
+
} from './components/article-flag/LiveArticleFlag';
|
|
13
|
+
export {
|
|
14
|
+
ArticleFlag,
|
|
15
|
+
ArticleFlags,
|
|
16
|
+
NewArticleFlag,
|
|
17
|
+
UpdatedArticleFlag,
|
|
18
|
+
ExclusiveArticleFlag,
|
|
19
|
+
SponsoredArticleFlag,
|
|
20
|
+
LongReadArticleFlag
|
|
21
|
+
} from './components/article-flag/ArticleFlag';
|
|
10
22
|
|
|
11
23
|
// Newsletter Components
|
|
12
24
|
export {
|
|
@@ -69,3 +81,5 @@ export {
|
|
|
69
81
|
export { HiddenDiv } from './components/common-styles';
|
|
70
82
|
|
|
71
83
|
export { InlineMessage } from './components/inline-message/InlineMessage';
|
|
84
|
+
|
|
85
|
+
export { InlineDialog } from './components/inline-dialog/InlineDialog';
|
package/src/types/externs.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ declare module '@times-components/utils' {
|
|
|
54
54
|
|
|
55
55
|
export const capitalise: (s: string) => string;
|
|
56
56
|
export const stripTags: (input: string, replaceWith: string) => string;
|
|
57
|
+
export const gqlRgbaToStyle: (colour: string | undefined) => string | null;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
declare module '@times-components/styleguide' {
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { storiesOf } from '@storybook/react';
|
|
3
|
-
import { LiveArticleFlag } from './LiveArticleFlag';
|
|
4
|
-
storiesOf('Typescript Component/LiveArticleFlag', module).add('default', () => {
|
|
5
|
-
return React.createElement(LiveArticleFlag, null);
|
|
6
|
-
});
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTGl2ZUFydGljbGVGbGFnLnN0b3JpZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvY29tcG9uZW50cy9hcnRpY2xlLWZsYWcvTGl2ZUFydGljbGVGbGFnLnN0b3JpZXMudHN4Il0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxNQUFNLE9BQU8sQ0FBQztBQUMxQixPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFDN0MsT0FBTyxFQUFFLGVBQWUsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXBELFNBQVMsQ0FBQyxzQ0FBc0MsRUFBRSxNQUFNLENBQUMsQ0FBQyxHQUFHLENBQUMsU0FBUyxFQUFFLEdBQUcsRUFBRTtJQUM1RSxPQUFPLG9CQUFDLGVBQWUsT0FBRyxDQUFDO0FBQzdCLENBQUMsQ0FBQyxDQUFDIn0=
|