@newskit-render/standalone-components 0.2.1 → 0.5.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.
Files changed (2) hide show
  1. package/README.md +76 -1
  2. package/package.json +10 -2
package/README.md CHANGED
@@ -2,7 +2,82 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Standalone components is a package that contains components, that can live with or without the Render application. You can add the package with this command `npm install @newskit-render/standalone-components` or if you use yarn `yarn add @newskit-render/standalone-components`.
5
+ The Standalone-components package contains components, that can live with or without the Render application.
6
+
7
+ ## Getting started
8
+
9
+ Install the package to start using it. Depending on your package manager, run:
10
+
11
+ For yarn:
12
+ `yarn add @newskit-render/standalone-components`
13
+
14
+ For npm:
15
+ `npm install @newskit-render/standalone-components`.
16
+
17
+ ## Components
18
+
19
+ 1. Article recommendations: this component provides two main facilities:
20
+
21
+ - recommendationsProvider: Provider function that accepts `articleId`, `publisher` and `userId`. The function will return an array of recommended articles.
22
+ - ArticleRecommendation: a component that accepts `article` and `size`, where
23
+
24
+ - `article` is an object with the following properties:
25
+ - href: string // mandatory
26
+ - title: string // mandatory
27
+ - text: string // optional
28
+ - `size` can be `large` or `small`.
29
+
30
+ # How to use
31
+
32
+ First, you need to fetch some article recommendations with the recommendationsProvider function, then iterate over the returned array and use the ArticleRecommendation component to display them.
33
+
34
+ Example of use:
35
+
36
+ ```typescript
37
+ import React from 'react'
38
+ import { Block, Grid, Cell } from 'newskit'
39
+ import {
40
+ ArticleRecommendation,
41
+ recommendationsProvider,
42
+ Article,
43
+ } from '@newskit-render/standalone-components'
44
+ import { Publisher } from '@newskit-render/api'
45
+
46
+ const Recommendations: React.FC<{
47
+ recommendations: Article[]
48
+ }> = ({ recommendations }) => (
49
+ <Block data-testid="RelatedArticles">
50
+ <Grid xsMargin="space000">
51
+ {recommendations.map((article) => (
52
+ <Cell
53
+ key={article.title}
54
+ xs={12}
55
+ sm={6}
56
+ lg={3}
57
+ data-testid="RelatedArticlesVerticalCard"
58
+ >
59
+ <ArticleRecommendation article={article} size="large" />
60
+ </Cell>
61
+ ))}
62
+ </Grid>
63
+ </Block>
64
+ )
65
+
66
+ export default Recommendations
67
+
68
+ export async function getServerSideProps(context) {
69
+ const recommendations = await recommendationsProvider({
70
+ articleId,
71
+ publisher: Publisher.SUN_UK,
72
+ })
73
+
74
+ return {
75
+ props: {
76
+ recommendations,
77
+ },
78
+ }
79
+ }
80
+ ```
6
81
 
7
82
  .
8
83
  .
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newskit-render/standalone-components",
3
- "version": "0.2.1",
3
+ "version": "0.5.0",
4
4
  "description": "Newskit Render Standalone Components",
5
5
  "author": "",
6
6
  "license": "UNLICENSED",
@@ -77,7 +77,15 @@
77
77
  },
78
78
  "dependencies": {
79
79
  "@apollo/client": "3.4.16",
80
- "@newskit-render/api": "^0.18.1",
80
+ "@newskit-render/api": "^0.21.0",
81
81
  "graphql": "15.6.0"
82
+ },
83
+ "resolutions": {
84
+ "@types/react": "^17.0.1",
85
+ "@types/react-dom": "^17.0.2"
86
+ },
87
+ "overrides": {
88
+ "@types/react": "^17.0.1",
89
+ "@types/react-dom": "^17.0.2"
82
90
  }
83
91
  }