@newskit-render/core 1.44.2 → 1.48.2

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 (41) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/__tests__/pages/[articleSlug].test.tsx +59 -18
  3. package/__tests__/pages/__snapshots__/home.test.tsx.snap +769 -1261
  4. package/components/article/Highlights.tsx +4 -33
  5. package/components/article/RelatedArticles.tsx +4 -53
  6. package/components/article/__tests__/__snapshots__/index.test.tsx.snap +53 -43
  7. package/components/section/ArticleSlice.tsx +17 -43
  8. package/components/section/CollectionBlock.tsx +38 -6
  9. package/components/section/__tests__/ArticleSlice.test.tsx +37 -51
  10. package/components/section/__tests__/CollectionBlock.test.tsx +63 -13
  11. package/components/section/__tests__/pageBlock.test.tsx +8 -4
  12. package/components/section/index.tsx +17 -12
  13. package/components/section/layouts/Lead.tsx +36 -15
  14. package/components/section/layouts/Rows.tsx +67 -0
  15. package/components/section/layouts/{SectionRow.tsx → SectionTitle.tsx} +24 -52
  16. package/components/section/layouts/__tests__/Lead.test.tsx +31 -6
  17. package/components/section/layouts/__tests__/Rows.test.tsx +28 -0
  18. package/components/section/layouts/__tests__/SectionTitle.test.tsx +36 -0
  19. package/components/section/layouts/__tests__/__snapshots__/Lead.test.tsx.snap +274 -315
  20. package/components/section/layouts/__tests__/__snapshots__/SectionTitle.test.tsx.snap +942 -0
  21. package/components/section/layouts/gridUtils.ts +12 -9
  22. package/components/section/layouts/index.tsx +2 -1
  23. package/components/section/layouts/types.ts +5 -1
  24. package/components/section/{pageBlock.ts → pageBlock.tsx} +5 -2
  25. package/components/teaser/index.tsx +7 -6
  26. package/components/teaser/teaserVariants.ts +2 -0
  27. package/components/teaser/variants/horizontal.ts +14 -0
  28. package/cypress/e2e/account/account-page.spec.js +27 -1
  29. package/cypress/e2e/account/account-subscription.spec.js +2 -2
  30. package/cypress/e2e/account/main-api.spec.js +4 -4
  31. package/cypress/support/commands.js +4 -4
  32. package/helpers/mocks/getPageMock.ts +2 -59
  33. package/next.config.js +4 -0
  34. package/package.json +8 -7
  35. package/pages/[section]/[articleId]/[articleSlug].tsx +14 -3
  36. package/pages/api/feed.ts +19 -0
  37. package/pages/api/news-sitemap.ts +10 -2
  38. package/pages/api/sitemap.ts +10 -6
  39. package/components/section/layouts/Row.tsx +0 -28
  40. package/components/section/layouts/__tests__/SectionRow.test.tsx +0 -56
  41. package/components/section/layouts/__tests__/__snapshots__/SectionRow.test.tsx.snap +0 -4542
@@ -12,6 +12,7 @@ import {
12
12
  Visible,
13
13
  TitleBar,
14
14
  } from 'newskit'
15
+ import { ArticleRecommendation } from '@newskit-render/standalone-components'
15
16
  import ViewMoreButton from '../common/ViewMoreButton'
16
17
 
17
18
  const Highlights: React.FC<{
@@ -60,40 +61,10 @@ const Highlights: React.FC<{
60
61
 
61
62
  <Block spaceStack="space040">
62
63
  <Grid xsMargin="space000">
63
- {highlightsArticles.map(({ title, href }) => (
64
- <Cell key={title} xs={12} sm={6} lg={12}>
64
+ {highlightsArticles.map((article) => (
65
+ <Cell key={article.title} xs={12} sm={6} lg={12}>
65
66
  <Block spaceStack="space040" data-testid="HighlightsHorizontalCard">
66
- <Card
67
- href="https://newskit.co.uk/"
68
- layout="horizontal"
69
- media={{
70
- src: href,
71
- alt: 'Card Media',
72
- loadingAspectRatio: '3:2',
73
- overrides: {
74
- width: '150px',
75
- height: '100px',
76
- },
77
- }}
78
- overrides={{
79
- stylePreset: 'cardContainer',
80
- mediaContainer: {
81
- spaceInline: 'space030',
82
- },
83
- }}
84
- >
85
- <Headline
86
- headingAs="h4"
87
- overrides={{
88
- typographyPreset: {
89
- xs: 'editorialHeadline040',
90
- xl: 'editorialHeadline020',
91
- },
92
- }}
93
- >
94
- {title}
95
- </Headline>
96
- </Card>
67
+ <ArticleRecommendation article={article} size="small" />
97
68
  </Block>
98
69
  </Cell>
99
70
  ))}
@@ -13,6 +13,7 @@ import {
13
13
  Headline,
14
14
  Visible,
15
15
  } from 'newskit'
16
+ import { ArticleRecommendation } from '@newskit-render/standalone-components'
16
17
  import ViewMoreButton from '../common/ViewMoreButton'
17
18
 
18
19
  const viewMoreButton = () => <ViewMoreButton href="/" />
@@ -48,65 +49,15 @@ const RelatedArticles: React.FC<{
48
49
  </Block>
49
50
 
50
51
  <Grid xsMargin="space000">
51
- {relatedArticles.map(({ title, href, text, tag }) => (
52
+ {relatedArticles.map((article) => (
52
53
  <Cell
53
- key={title}
54
+ key={article.title}
54
55
  xs={12}
55
56
  sm={6}
56
57
  lg={3}
57
58
  data-testid="RelatedArticlesVerticalCard"
58
59
  >
59
- <Card
60
- media={{
61
- src: href,
62
- alt: title,
63
- loadingAspectRatio: '3:2',
64
- }}
65
- overrides={{
66
- stylePreset: 'cardContainer',
67
- mediaContainer: {
68
- spaceInline: 'space030',
69
- },
70
- }}
71
- >
72
- <Block spaceStack="space060">
73
- <Block
74
- spaceStack={{
75
- xs: 'space040',
76
- md: 'space050',
77
- }}
78
- >
79
- <Headline
80
- headingAs="h6"
81
- overrides={{
82
- typographyPreset: {
83
- xs: 'editorialHeadline020',
84
- md: 'editorialHeadline030',
85
- xl: 'editorialHeadline040',
86
- },
87
- }}
88
- >
89
- {title}
90
- </Headline>
91
- </Block>
92
- <Block
93
- spaceStack={{
94
- xs: 'space040',
95
- md: 'space050',
96
- }}
97
- >
98
- <TextBlock
99
- stylePreset="inkContrast"
100
- typographyPreset={{
101
- xs: 'editorialParagraph010',
102
- md: 'editorialParagraph020',
103
- }}
104
- >
105
- {text}
106
- </TextBlock>
107
- </Block>
108
- </Block>
109
- </Card>
60
+ <ArticleRecommendation article={article} size="large" />
110
61
  </Cell>
111
62
  ))}
112
63
  <Cell xs={12}>
@@ -2747,7 +2747,7 @@ exports[`Article should render tile and sub title 1`] = `
2747
2747
  }
2748
2748
 
2749
2749
  @media screen and (max-width: 767px) {
2750
- .emotion-221 {
2750
+ .emotion-222 {
2751
2751
  font-family: "Bitter",serif;
2752
2752
  font-size: 20px;
2753
2753
  line-height: 22.5px;
@@ -2756,13 +2756,13 @@ exports[`Article should render tile and sub title 1`] = `
2756
2756
  padding: 0.5px 0px;
2757
2757
  }
2758
2758
 
2759
- .emotion-221::before {
2759
+ .emotion-222::before {
2760
2760
  content: '';
2761
2761
  margin-bottom: -0.2055em;
2762
2762
  display: block;
2763
2763
  }
2764
2764
 
2765
- .emotion-221::after {
2765
+ .emotion-222::after {
2766
2766
  content: '';
2767
2767
  margin-top: -0.2275em;
2768
2768
  display: block;
@@ -2770,7 +2770,7 @@ exports[`Article should render tile and sub title 1`] = `
2770
2770
  }
2771
2771
 
2772
2772
  @media screen and (min-width: 768px) and (max-width: 1439px) {
2773
- .emotion-221 {
2773
+ .emotion-222 {
2774
2774
  font-family: "Bitter",serif;
2775
2775
  font-size: 22px;
2776
2776
  line-height: 24.75px;
@@ -2779,13 +2779,13 @@ exports[`Article should render tile and sub title 1`] = `
2779
2779
  padding: 0.5px 0px;
2780
2780
  }
2781
2781
 
2782
- .emotion-221::before {
2782
+ .emotion-222::before {
2783
2783
  content: '';
2784
2784
  margin-bottom: -0.2055em;
2785
2785
  display: block;
2786
2786
  }
2787
2787
 
2788
- .emotion-221::after {
2788
+ .emotion-222::after {
2789
2789
  content: '';
2790
2790
  margin-top: -0.2275em;
2791
2791
  display: block;
@@ -2793,7 +2793,7 @@ exports[`Article should render tile and sub title 1`] = `
2793
2793
  }
2794
2794
 
2795
2795
  @media screen and (min-width: 1440px) {
2796
- .emotion-221 {
2796
+ .emotion-222 {
2797
2797
  font-family: "Bitter",serif;
2798
2798
  font-size: 24px;
2799
2799
  line-height: 27px;
@@ -2802,30 +2802,30 @@ exports[`Article should render tile and sub title 1`] = `
2802
2802
  padding: 0.5px 0px;
2803
2803
  }
2804
2804
 
2805
- .emotion-221::before {
2805
+ .emotion-222::before {
2806
2806
  content: '';
2807
2807
  margin-bottom: -0.2055em;
2808
2808
  display: block;
2809
2809
  }
2810
2810
 
2811
- .emotion-221::after {
2811
+ .emotion-222::after {
2812
2812
  content: '';
2813
2813
  margin-top: -0.2275em;
2814
2814
  display: block;
2815
2815
  }
2816
2816
  }
2817
2817
 
2818
- .emotion-224 {
2818
+ .emotion-225 {
2819
2819
  margin: 0;
2820
2820
  color: #0A0A0A;
2821
2821
  }
2822
2822
 
2823
- .emotion-224 svg {
2823
+ .emotion-225 svg {
2824
2824
  fill: #0A0A0A;
2825
2825
  }
2826
2826
 
2827
2827
  @media screen and (max-width: 767px) {
2828
- .emotion-224 {
2828
+ .emotion-225 {
2829
2829
  font-family: "DM Sans",sans-serif;
2830
2830
  font-size: 14px;
2831
2831
  line-height: 21px;
@@ -2834,13 +2834,13 @@ exports[`Article should render tile and sub title 1`] = `
2834
2834
  padding: 0.5px 0px;
2835
2835
  }
2836
2836
 
2837
- .emotion-224::before {
2837
+ .emotion-225::before {
2838
2838
  content: '';
2839
2839
  margin-bottom: -0.391em;
2840
2840
  display: block;
2841
2841
  }
2842
2842
 
2843
- .emotion-224::after {
2843
+ .emotion-225::after {
2844
2844
  content: '';
2845
2845
  margin-top: -0.409em;
2846
2846
  display: block;
@@ -2848,7 +2848,7 @@ exports[`Article should render tile and sub title 1`] = `
2848
2848
  }
2849
2849
 
2850
2850
  @media screen and (min-width: 768px) {
2851
- .emotion-224 {
2851
+ .emotion-225 {
2852
2852
  font-family: "DM Sans",sans-serif;
2853
2853
  font-size: 16px;
2854
2854
  line-height: 24px;
@@ -2857,13 +2857,13 @@ exports[`Article should render tile and sub title 1`] = `
2857
2857
  padding: 0.5px 0px;
2858
2858
  }
2859
2859
 
2860
- .emotion-224::before {
2860
+ .emotion-225::before {
2861
2861
  content: '';
2862
2862
  margin-bottom: -0.391em;
2863
2863
  display: block;
2864
2864
  }
2865
2865
 
2866
- .emotion-224::after {
2866
+ .emotion-225::after {
2867
2867
  content: '';
2868
2868
  margin-top: -0.409em;
2869
2869
  display: block;
@@ -2871,37 +2871,37 @@ exports[`Article should render tile and sub title 1`] = `
2871
2871
  }
2872
2872
 
2873
2873
  @media screen {
2874
- .emotion-240 {
2874
+ .emotion-242 {
2875
2875
  display: block;
2876
2876
  }
2877
2877
  }
2878
2878
 
2879
2879
  @media screen and (min-width: 480px) {
2880
- .emotion-240 {
2880
+ .emotion-242 {
2881
2881
  display: none;
2882
2882
  }
2883
2883
  }
2884
2884
 
2885
2885
  @media screen and (min-width: 768px) {
2886
- .emotion-240 {
2886
+ .emotion-242 {
2887
2887
  display: none;
2888
2888
  }
2889
2889
  }
2890
2890
 
2891
2891
  @media screen and (min-width: 1024px) {
2892
- .emotion-240 {
2892
+ .emotion-242 {
2893
2893
  display: block;
2894
2894
  }
2895
2895
  }
2896
2896
 
2897
2897
  @media screen and (min-width: 1440px) {
2898
- .emotion-240 {
2898
+ .emotion-242 {
2899
2899
  display: none;
2900
2900
  }
2901
2901
  }
2902
2902
 
2903
2903
  @media screen {
2904
- .emotion-253 {
2904
+ .emotion-255 {
2905
2905
  margin-bottom: 64px;
2906
2906
  }
2907
2907
  }
@@ -3740,7 +3740,7 @@ exports[`Article should render tile and sub title 1`] = `
3740
3740
  >
3741
3741
  <a
3742
3742
  class="nk-card-link emotion-166"
3743
- href="https://newskit.co.uk/"
3743
+ href="undefined"
3744
3744
  >
3745
3745
  <section
3746
3746
  class="emotion-167"
@@ -3791,7 +3791,7 @@ exports[`Article should render tile and sub title 1`] = `
3791
3791
  >
3792
3792
  <a
3793
3793
  class="nk-card-link emotion-166"
3794
- href="https://newskit.co.uk/"
3794
+ href="undefined"
3795
3795
  >
3796
3796
  <section
3797
3797
  class="emotion-167"
@@ -3991,21 +3991,26 @@ exports[`Article should render tile and sub title 1`] = `
3991
3991
  <div
3992
3992
  class="emotion-220"
3993
3993
  >
3994
- <section
3995
- class="emotion-221"
3994
+ <a
3995
+ class="nk-card-link emotion-166"
3996
+ href="undefined"
3996
3997
  >
3997
- <h6
3998
- class="nk-headline-heading emotion-8"
3998
+ <section
3999
+ class="emotion-222"
3999
4000
  >
4000
- Prince Harry
4001
- </h6>
4002
- </section>
4001
+ <h6
4002
+ class="nk-headline-heading emotion-168"
4003
+ >
4004
+ Prince Harry
4005
+ </h6>
4006
+ </section>
4007
+ </a>
4003
4008
  </div>
4004
4009
  <div
4005
4010
  class="emotion-220"
4006
4011
  >
4007
4012
  <p
4008
- class="emotion-224"
4013
+ class="emotion-225"
4009
4014
  >
4010
4015
  news
4011
4016
  </p>
@@ -4050,21 +4055,26 @@ exports[`Article should render tile and sub title 1`] = `
4050
4055
  <div
4051
4056
  class="emotion-220"
4052
4057
  >
4053
- <section
4054
- class="emotion-221"
4058
+ <a
4059
+ class="nk-card-link emotion-166"
4060
+ href="undefined"
4055
4061
  >
4056
- <h6
4057
- class="nk-headline-heading emotion-8"
4062
+ <section
4063
+ class="emotion-222"
4058
4064
  >
4059
- Meghan Markle
4060
- </h6>
4061
- </section>
4065
+ <h6
4066
+ class="nk-headline-heading emotion-168"
4067
+ >
4068
+ Meghan Markle
4069
+ </h6>
4070
+ </section>
4071
+ </a>
4062
4072
  </div>
4063
4073
  <div
4064
4074
  class="emotion-220"
4065
4075
  >
4066
4076
  <p
4067
- class="emotion-224"
4077
+ class="emotion-225"
4068
4078
  >
4069
4079
  news
4070
4080
  </p>
@@ -4078,7 +4088,7 @@ exports[`Article should render tile and sub title 1`] = `
4078
4088
  class="emotion-181"
4079
4089
  >
4080
4090
  <div
4081
- class="emotion-240"
4091
+ class="emotion-242"
4082
4092
  >
4083
4093
  <hr
4084
4094
  aria-hidden="true"
@@ -4148,7 +4158,7 @@ exports[`Article should render tile and sub title 1`] = `
4148
4158
  data-testid="PageLayout"
4149
4159
  >
4150
4160
  <div
4151
- class="emotion-253"
4161
+ class="emotion-255"
4152
4162
  />
4153
4163
  </div>
4154
4164
  </div>
@@ -1,46 +1,23 @@
1
1
  import React from 'react'
2
- import { Block, getColorCssFromTheme } from 'newskit'
3
- import {
4
- ArticleSlice as Slice,
5
- CollectionBlock,
6
- } from '../../helpers/global-types'
7
- import { Lead, SectionRow, FallBack } from './layouts'
8
- import { SectionContext } from './SectionContext'
2
+ import { Block } from 'newskit'
3
+ import { ArticleSlice as Slice } from '../../helpers/global-types'
4
+ import { Lead, LeadFullWidth, FallBack } from './layouts'
5
+ import { Row3, BasicRow } from './layouts/Rows'
9
6
 
10
- const sliceBlockBuilder = (slice: Slice, collection: CollectionBlock) => {
11
- const sectionURL = collection?.link?.url || '/uncategorized'
12
- /* add layout to case statments when ready */
7
+ const sliceBlockBuilder = (slice: Slice) => {
13
8
  const sliceTypes = {
9
+ LEAD_1_FULL_WIDTH: <LeadFullWidth slice={slice} />,
14
10
  SUPPLEMENT_LEAD_AND_4_STACK: <Lead slice={slice} />,
15
- SECONDARY_4: (
16
- <SectionContext.Consumer>
17
- {({ isIndexPage }) => (
18
- <SectionRow
19
- slice={slice}
20
- collection={collection}
21
- sectionURL={sectionURL}
22
- showTitle={!isIndexPage}
23
- />
24
- )}
25
- </SectionContext.Consumer>
11
+ SECONDARY_2_AND_2: (
12
+ <BasicRow slice={slice} colums={{ xs: '1fr', md: '1fr 1fr' }} />
26
13
  ),
27
- SECONDARY_4_ODD: (
28
- <SectionContext.Consumer>
29
- {({ isIndexPage }) => (
30
- <SectionRow
31
- slice={slice}
32
- collection={collection}
33
- sectionURL={sectionURL}
34
- isDarkBackground
35
- addTopSpace={isIndexPage}
36
- titleBarColour={
37
- (isIndexPage &&
38
- `${getColorCssFromTheme('color', 'transparent')}`) as string
39
- }
40
- titleBarStylePreset={(isIndexPage && 'inkContrast') as string}
41
- />
42
- )}
43
- </SectionContext.Consumer>
14
+ SECONDARY_3: <Row3 slice={slice} />,
15
+ SECONDARY_4: (
16
+ <BasicRow
17
+ slice={slice}
18
+ colums={{ xs: '1fr', md: '1fr 1fr', lg: '1fr 1fr 1fr 1fr' }}
19
+ variant="horizontal"
20
+ />
44
21
  ),
45
22
  default: <FallBack slice={slice} />,
46
23
  }
@@ -48,13 +25,10 @@ const sliceBlockBuilder = (slice: Slice, collection: CollectionBlock) => {
48
25
  return sliceTypes[slice.name] || sliceTypes.default
49
26
  }
50
27
 
51
- const ArticleSlice: React.FC<{ slice: Slice; collection: CollectionBlock }> = ({
52
- slice,
53
- collection,
54
- }) => (
28
+ const ArticleSlice: React.FC<{ slice: Slice }> = ({ slice }) => (
55
29
  <>
30
+ {sliceBlockBuilder(slice)}
56
31
  <Block spaceStack="space070" />
57
- {sliceBlockBuilder(slice, collection)}
58
32
  </>
59
33
  )
60
34
 
@@ -1,15 +1,16 @@
1
+ import { Block } from 'newskit'
1
2
  import React from 'react'
2
3
  import {
3
4
  CollectionBlock as Collection,
4
5
  ArticleSlice as Slice,
5
6
  } from '../../helpers/global-types'
6
7
  import ArticleSlice from './ArticleSlice'
8
+ import { SectionTitle } from './layouts'
9
+ import { SectionContext } from './SectionContext'
7
10
 
8
11
  const collectionSliceOptions = (type: string) => {
9
12
  const sliceTypes = {
10
- slice: (slice: Slice, collection: Collection, i: number) => (
11
- <ArticleSlice slice={slice} collection={collection} key={i} />
12
- ),
13
+ slice: (slice: Slice, i: number) => <ArticleSlice slice={slice} key={i} />,
13
14
  'topic-author-slice': () => null,
14
15
  default: () => null,
15
16
  }
@@ -17,9 +18,40 @@ const collectionSliceOptions = (type: string) => {
17
18
  return sliceTypes[type] || sliceTypes.default
18
19
  }
19
20
 
20
- const CollectionBlock = (collection: Collection) =>
21
- collection.children.map((slice, i) =>
22
- collectionSliceOptions(slice.type)(slice, collection, i)
21
+ type CollectionBlockProps = {
22
+ collection: Collection
23
+ index: number
24
+ }
25
+
26
+ const CollectionBlock: React.FC<CollectionBlockProps> = ({
27
+ collection,
28
+ index,
29
+ }) => {
30
+ const sectionURL = collection?.link?.url || '/uncategorized'
31
+ const titleBarColors = ['', 'teal050', 'purple050', 'neutral050']
32
+
33
+ return (
34
+ <>
35
+ {index !== 0 && (
36
+ <SectionContext.Consumer>
37
+ {
38
+ ({ isIndexPage }) =>
39
+ !isIndexPage && (
40
+ <SectionTitle
41
+ title={collection.title}
42
+ sectionURL={sectionURL}
43
+ titleBarColour={titleBarColors[index]}
44
+ />
45
+ )
46
+ /* eslint-disable-next-line */
47
+ }
48
+ </SectionContext.Consumer>
49
+ )}
50
+ {collection.children.map((slice, i) =>
51
+ collectionSliceOptions(slice.type)(slice, i)
52
+ )}
53
+ </>
23
54
  )
55
+ }
24
56
 
25
57
  export default CollectionBlock