@newskit-render/standalone-components 0.2.1 → 0.3.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/README.md +76 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,82 @@
|
|
|
2
2
|
|
|
3
3
|
## Overview
|
|
4
4
|
|
|
5
|
-
Standalone
|
|
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
|
.
|