@times-components/ts-slices 1.4.4 → 1.5.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 +30 -0
- package/dist/components/article/ArticleStandard/ArticleStandard.d.ts +9 -0
- package/dist/components/article/ArticleStandard/ArticleStandard.js +21 -0
- package/dist/components/article/ArticleStandard/__tests__/ArticleStandard.test.d.ts +1 -0
- package/dist/components/article/ArticleStandard/__tests__/ArticleStandard.test.js +32 -0
- package/dist/components/article/ArticleStandard/styles.d.ts +2 -0
- package/dist/components/article/ArticleStandard/styles.js +17 -0
- package/dist/components/slices/RelatedArticle1/RelatedArticle1.d.ts +2 -2
- package/dist/components/slices/RelatedArticle1/RelatedArticle1.js +7 -12
- package/dist/components/slices/RelatedArticle1/__tests__/RelatedArticle1.test.js +4 -4
- package/dist/components/slices/RelatedArticle1/styles.js +8 -1
- package/dist/components/slices/RelatedArticle2/RelatedArticle2.d.ts +10 -0
- package/dist/components/slices/RelatedArticle2/RelatedArticle2.js +15 -0
- package/dist/components/slices/RelatedArticle2/__tests__/RelatedArticle2.test.d.ts +1 -0
- package/dist/components/slices/RelatedArticle2/__tests__/RelatedArticle2.test.js +20 -0
- package/dist/components/slices/RelatedArticle2/styles.d.ts +7 -0
- package/dist/components/slices/RelatedArticle2/styles.js +36 -0
- package/dist/components/slices/RelatedArticle3/RelatedArticle3.d.ts +10 -0
- package/dist/components/slices/RelatedArticle3/RelatedArticle3.js +16 -0
- package/dist/components/slices/RelatedArticle3/__tests__/RelatedArticle3.test.d.ts +1 -0
- package/dist/components/slices/RelatedArticle3/__tests__/RelatedArticle3.test.js +20 -0
- package/dist/components/slices/RelatedArticle3/styles.d.ts +4 -0
- package/dist/components/slices/RelatedArticle3/styles.js +33 -0
- package/dist/components/slices/Slice.stories.js +11 -1
- package/dist/fixtures/getSlice.js +20 -5
- package/dist/utils/getDate.d.ts +1 -0
- package/dist/utils/getDate.js +29 -0
- package/dist/utils/getSlice.js +7 -1
- package/package.json +4 -4
- package/rnw.js +1 -1
- package/src/components/article/ArticleStandard/ArticleStandard.tsx +46 -0
- package/src/components/article/ArticleStandard/__tests__/ArticleStandard.test.tsx +41 -0
- package/src/components/article/ArticleStandard/__tests__/__snapshots__/ArticleStandard.test.tsx.snap +39 -0
- package/src/components/article/ArticleStandard/styles.ts +18 -0
- package/src/components/slices/RelatedArticle1/RelatedArticle1.tsx +6 -11
- package/src/components/slices/RelatedArticle1/__tests__/RelatedArticle1.test.tsx +3 -3
- package/src/components/slices/RelatedArticle1/__tests__/__snapshots__/RelatedArticle1.test.tsx.snap +2 -2
- package/src/components/slices/RelatedArticle1/styles.ts +7 -0
- package/src/components/slices/RelatedArticle2/RelatedArticle2.tsx +37 -0
- package/src/components/slices/RelatedArticle2/__tests__/RelatedArticle2.test.tsx +29 -0
- package/src/components/slices/RelatedArticle2/__tests__/__snapshots__/RelatedArticle2.test.tsx.snap +24 -0
- package/src/components/slices/RelatedArticle2/styles.ts +42 -0
- package/src/components/slices/RelatedArticle3/RelatedArticle3.tsx +38 -0
- package/src/components/slices/RelatedArticle3/__tests__/RelatedArticle3.test.tsx +29 -0
- package/src/components/slices/RelatedArticle3/__tests__/__snapshots__/RelatedArticle3.test.tsx.snap +31 -0
- package/src/components/slices/RelatedArticle3/styles.ts +35 -0
- package/src/components/slices/Slice.stories.tsx +14 -0
- package/src/fixtures/getSlice.ts +19 -4
- package/src/utils/getDate.ts +39 -0
- package/src/utils/getSlice.ts +6 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { SliceData, SliceSlot } from '../../../types/slice';
|
|
4
|
+
import { SliceStyle } from '../../../types/styles';
|
|
5
|
+
import { ClickHandlerType } from '../../../types/event';
|
|
6
|
+
import { setDisplaySchema } from '../../../utils/getArticleStyles';
|
|
7
|
+
|
|
8
|
+
import { ArticleStandard } from '../../article/ArticleStandard/ArticleStandard';
|
|
9
|
+
|
|
10
|
+
import { SliceContainer } from '../shared-styles';
|
|
11
|
+
import { SlotContainer } from './styles';
|
|
12
|
+
|
|
13
|
+
const RelatedArticle3: React.FC<{
|
|
14
|
+
slice: SliceData;
|
|
15
|
+
styles?: SliceStyle;
|
|
16
|
+
clickHandler?: ClickHandlerType;
|
|
17
|
+
}> = React.memo(({ slice, styles, clickHandler }) => (
|
|
18
|
+
<SliceContainer styles={styles}>
|
|
19
|
+
{slice.children.map((slot: SliceSlot, i: number) => (
|
|
20
|
+
<SlotContainer key={i} styles={styles}>
|
|
21
|
+
<ArticleStandard
|
|
22
|
+
article={slot.article}
|
|
23
|
+
displaySchema={setDisplaySchema({
|
|
24
|
+
sm: {
|
|
25
|
+
isImageHidden: true,
|
|
26
|
+
imageRatio: '16:9',
|
|
27
|
+
headlineFontSize: 22
|
|
28
|
+
},
|
|
29
|
+
md: { isImageHidden: false }
|
|
30
|
+
})}
|
|
31
|
+
clickHandler={clickHandler}
|
|
32
|
+
/>
|
|
33
|
+
</SlotContainer>
|
|
34
|
+
))}
|
|
35
|
+
</SliceContainer>
|
|
36
|
+
));
|
|
37
|
+
|
|
38
|
+
export default RelatedArticle3;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { getSlice } from '../../../../fixtures/getSlice';
|
|
5
|
+
|
|
6
|
+
import RelatedArticle3 from '../RelatedArticle3';
|
|
7
|
+
|
|
8
|
+
jest.mock('../../../article/ArticleStandard/ArticleStandard', () => ({
|
|
9
|
+
ArticleStandard: () => <div>ArticleStandard</div>
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
describe('<RelatedArticle3 />', () => {
|
|
13
|
+
afterAll(() => {
|
|
14
|
+
jest.clearAllMocks();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should render an RELATED_ARTICLE_3 slice correctly', () => {
|
|
18
|
+
const slice = getSlice('RELATED_ARTICLE_3');
|
|
19
|
+
|
|
20
|
+
const { asFragment, getAllByText } = render(
|
|
21
|
+
<RelatedArticle3 slice={slice} />
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const article = getAllByText('ArticleStandard');
|
|
25
|
+
expect(article.length).toBe(3);
|
|
26
|
+
|
|
27
|
+
expect(asFragment()).toMatchSnapshot();
|
|
28
|
+
});
|
|
29
|
+
});
|
package/src/components/slices/RelatedArticle3/__tests__/__snapshots__/RelatedArticle3.test.tsx.snap
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`<RelatedArticle3 /> should render an RELATED_ARTICLE_3 slice correctly 1`] = `
|
|
4
|
+
<DocumentFragment>
|
|
5
|
+
<div
|
|
6
|
+
class="sc-bdVaJa gMdRRW"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="sc-bwzfXH sc-htpNat kmrygX"
|
|
10
|
+
>
|
|
11
|
+
<div>
|
|
12
|
+
ArticleStandard
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
<div
|
|
16
|
+
class="sc-bwzfXH sc-htpNat kmrygX"
|
|
17
|
+
>
|
|
18
|
+
<div>
|
|
19
|
+
ArticleStandard
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
<div
|
|
23
|
+
class="sc-bwzfXH sc-htpNat kmrygX"
|
|
24
|
+
>
|
|
25
|
+
<div>
|
|
26
|
+
ArticleStandard
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</DocumentFragment>
|
|
31
|
+
`;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { breakpoints } from '@times-components/ts-styleguide';
|
|
3
|
+
|
|
4
|
+
import { calculateSlotWidth } from '../../../utils/getArticleStyles';
|
|
5
|
+
|
|
6
|
+
import { SlotContainer as SlotContainerBase } from '../shared-styles';
|
|
7
|
+
|
|
8
|
+
export const SlotContainer = styled(SlotContainerBase)`
|
|
9
|
+
@media (min-width: ${breakpoints.medium}px) {
|
|
10
|
+
width: ${calculateSlotWidth(33.33, 3)};
|
|
11
|
+
margin-bottom: 24px;
|
|
12
|
+
padding: 0 12px 24px 12px;
|
|
13
|
+
|
|
14
|
+
:before {
|
|
15
|
+
display: block;
|
|
16
|
+
bottom: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
:after {
|
|
20
|
+
display: block;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
&:first-of-type {
|
|
24
|
+
padding-left: 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&:last-of-type {
|
|
28
|
+
padding-right: 0;
|
|
29
|
+
|
|
30
|
+
&:before {
|
|
31
|
+
display: none;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
@@ -134,6 +134,20 @@ const showcase = {
|
|
|
134
134
|
),
|
|
135
135
|
name: 'RELATED_ARTICLE_1',
|
|
136
136
|
type: 'story'
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
component: () => (
|
|
140
|
+
<Slice slice={getSlice('RELATED_ARTICLE_2')} clickHandler={onClick} />
|
|
141
|
+
),
|
|
142
|
+
name: 'RELATED_ARTICLE_2',
|
|
143
|
+
type: 'story'
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
component: () => (
|
|
147
|
+
<Slice slice={getSlice('RELATED_ARTICLE_3')} clickHandler={onClick} />
|
|
148
|
+
),
|
|
149
|
+
name: 'RELATED_ARTICLE_3',
|
|
150
|
+
type: 'story'
|
|
137
151
|
}
|
|
138
152
|
],
|
|
139
153
|
name: 'Typescript Slices/Slices'
|
package/src/fixtures/getSlice.ts
CHANGED
|
@@ -11,10 +11,6 @@ const slices: SliceData[] = [
|
|
|
11
11
|
name: 'LEAD_1',
|
|
12
12
|
children: [{ article: getArticleWithSummary() }]
|
|
13
13
|
},
|
|
14
|
-
{
|
|
15
|
-
name: 'RELATED_ARTICLE_1',
|
|
16
|
-
children: [{ article: getArticleWithSummary() }]
|
|
17
|
-
},
|
|
18
14
|
{
|
|
19
15
|
name: 'LEAD_1_AND_1',
|
|
20
16
|
children: [{ article: getArticle() }, { article: getArticleWithSummary() }]
|
|
@@ -126,6 +122,25 @@ const slices: SliceData[] = [
|
|
|
126
122
|
{ article: getArticle() },
|
|
127
123
|
{ article: getArticle() }
|
|
128
124
|
]
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'RELATED_ARTICLE_1',
|
|
128
|
+
children: [{ article: getArticleWithSummary() }]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'RELATED_ARTICLE_2',
|
|
132
|
+
children: [
|
|
133
|
+
{ article: getArticleWithSummary() },
|
|
134
|
+
{ article: getArticleWithSummary() }
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'RELATED_ARTICLE_3',
|
|
139
|
+
children: [
|
|
140
|
+
{ article: getArticleWithSummary() },
|
|
141
|
+
{ article: getArticleWithSummary() },
|
|
142
|
+
{ article: getArticleWithSummary() }
|
|
143
|
+
]
|
|
129
144
|
}
|
|
130
145
|
];
|
|
131
146
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { format, addMinutes } from 'date-fns';
|
|
2
|
+
|
|
3
|
+
const lastSunday = (month: number, year: number) => {
|
|
4
|
+
const lastDayOfMonth = new Date(Date.UTC(year, month + 1, 0));
|
|
5
|
+
const day = lastDayOfMonth.getDay();
|
|
6
|
+
const dateOfSunday = lastDayOfMonth.getDate() - day;
|
|
7
|
+
const sunday = new Date(Date.UTC(year, month, dateOfSunday));
|
|
8
|
+
sunday.setHours(1);
|
|
9
|
+
return sunday;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const isBST = (date: Date) => {
|
|
13
|
+
const startOfBST = lastSunday(2, date.getFullYear());
|
|
14
|
+
const endOfBST = lastSunday(9, date.getFullYear());
|
|
15
|
+
const isAfterStartOfBST = date.getTime() >= startOfBST.getTime();
|
|
16
|
+
const isBeforeEndOfBST = date.getTime() < endOfBST.getTime();
|
|
17
|
+
return isAfterStartOfBST && isBeforeEndOfBST;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const getUTCTime = (date: string) => {
|
|
21
|
+
const localDate = new Date(date);
|
|
22
|
+
return new Date(
|
|
23
|
+
localDate.getUTCFullYear(),
|
|
24
|
+
localDate.getUTCMonth(),
|
|
25
|
+
localDate.getUTCDate(),
|
|
26
|
+
localDate.getUTCHours(),
|
|
27
|
+
localDate.getUTCMinutes()
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const getDate = (iso?: string) => {
|
|
32
|
+
if (iso) {
|
|
33
|
+
const utc = getUTCTime(iso);
|
|
34
|
+
const date = addMinutes(utc, isBST(utc) ? 60 : 0);
|
|
35
|
+
return format(date, 'MMMM dd yyyy, h.mmaaa');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
};
|
package/src/utils/getSlice.ts
CHANGED
|
@@ -17,6 +17,8 @@ import Secondary4 from '../components/slices/Secondary4/Secondary4';
|
|
|
17
17
|
import Secondary4Odd from '../components/slices/Secondary4Odd/Secondary4Odd';
|
|
18
18
|
import Secondary10 from '../components/slices/Secondary10/Secondary10';
|
|
19
19
|
import RelatedArticle1 from '../components/slices/RelatedArticle1/RelatedArticle1';
|
|
20
|
+
import RelatedArticle2 from '../components/slices/RelatedArticle2/RelatedArticle2';
|
|
21
|
+
import RelatedArticle3 from '../components/slices/RelatedArticle3/RelatedArticle3';
|
|
20
22
|
|
|
21
23
|
export const getSliceComponent = (
|
|
22
24
|
name: string
|
|
@@ -59,6 +61,10 @@ export const getSliceComponent = (
|
|
|
59
61
|
return Secondary10;
|
|
60
62
|
case 'RELATED_ARTICLE_1':
|
|
61
63
|
return RelatedArticle1;
|
|
64
|
+
case 'RELATED_ARTICLE_2':
|
|
65
|
+
return RelatedArticle2;
|
|
66
|
+
case 'RELATED_ARTICLE_3':
|
|
67
|
+
return RelatedArticle3;
|
|
62
68
|
|
|
63
69
|
default:
|
|
64
70
|
return () => null;
|