@bonniernews/dn-design-system-web 3.0.0-alpha.91 → 3.0.0-alpha.92
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
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.0-alpha.92](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@3.0.0-alpha.91...@bonniernews/dn-design-system-web@3.0.0-alpha.92) (2023-06-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **web:** add js-rendered teaser-standard ([#873](https://github.com/BonnierNews/dn-design-system/issues/873)) ([4cabd62](https://github.com/BonnierNews/dn-design-system/commit/4cabd6242afd5e717fd2a6758724e92d68340130))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
6
15
|
## [3.0.0-alpha.91](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@3.0.0-alpha.90...@bonniernews/dn-design-system-web@3.0.0-alpha.91) (2023-06-07)
|
|
7
16
|
|
|
8
17
|
|
|
@@ -29,11 +29,9 @@
|
|
|
29
29
|
|~forcePx~ | | | | | Not supported |
|
|
30
30
|
|
|
31
31
|
## Minimum requirement example
|
|
32
|
-
|
|
33
|
-
### Nunjucks
|
|
34
|
-
|
|
35
32
|
These are copy paste friendly examples to quickliy get started using a component.
|
|
36
33
|
|
|
34
|
+
### Nunjucks
|
|
37
35
|
```html
|
|
38
36
|
{% from '@bonniernews/dn-design-system-web/components/teaser-standard/teaser-standard.njk' import TeaserStandard %}
|
|
39
37
|
|
|
@@ -48,3 +46,20 @@ These are copy paste friendly examples to quickliy get started using a component
|
|
|
48
46
|
```scss
|
|
49
47
|
@use "@bonniernews/dn-design-system-web/components/teaser-standard/teaser-standard" as *;
|
|
50
48
|
```
|
|
49
|
+
|
|
50
|
+
### Javascript
|
|
51
|
+
This version is rarely used to render a teaser dynamically in the browser. For example, it is used to render reserv-teasers in failover. This version **ONLY** supports the `title`, `text`, `targetLink`, `classNames` and `attributes` parameters.
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
import { dsTeaserStandard } from "@bonniernews/dn-design-system-web/components/teaser-standard/teaser-standard";
|
|
55
|
+
|
|
56
|
+
// NB: javascript only supports a subset of all parameters
|
|
57
|
+
const parameters = {
|
|
58
|
+
title: "Upp på börsen",
|
|
59
|
+
text: "Det ser ganska normalt ut på Stockholmsbörsen",
|
|
60
|
+
targetLink: "https://www.dn.se/ekonomi/",
|
|
61
|
+
attributes: { "data-test" : "test-value" }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const teaserStandardHtml = dsTeaserStandard(parameters);
|
|
65
|
+
```
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export {
|
|
2
|
+
dsTeaserStandard,
|
|
3
|
+
dsTeaserStandardStory
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
function dsTeaserStandard(params = {}) {
|
|
7
|
+
const teaser = document.createElement("a");
|
|
8
|
+
// NOTE: this should match output of teaser-standard.njk for a subset of the parameters
|
|
9
|
+
teaser.innerHTML = `
|
|
10
|
+
<div class="ds-teaser__content">
|
|
11
|
+
<div class="ds-teaser__title"></div>
|
|
12
|
+
<p class="ds-teaser__text">
|
|
13
|
+
<span class="ds-teaser-dot"></span>
|
|
14
|
+
</p>
|
|
15
|
+
</div>`;
|
|
16
|
+
teaser.classList.add("ds-teaser");
|
|
17
|
+
teaser.classList.add("ds-teaser--standard");
|
|
18
|
+
|
|
19
|
+
if (params.targetLink) {
|
|
20
|
+
teaser.setAttribute("href", params.targetLink)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (params.title) {
|
|
24
|
+
const titleEl = teaser.getElementsByClassName("ds-teaser__title")[0];
|
|
25
|
+
titleEl.textContent = params.title;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (params.text) {
|
|
29
|
+
const textEl = teaser.getElementsByClassName("ds-teaser__text")[0];
|
|
30
|
+
textEl.appendChild(document.createTextNode(params.text))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (params.classNames) {
|
|
34
|
+
teaser.classList.add(params.classNames);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (params.attributes) {
|
|
38
|
+
for (const [key, value] of Object.entries(params.attributes)) {
|
|
39
|
+
teaser.setAttribute(key, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return teaser;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** only use in storybook */
|
|
47
|
+
function dsTeaserStandardStory() {
|
|
48
|
+
const jsTeasers = Array.from(document.getElementsByClassName("js-ds-teaser-standard-story"));
|
|
49
|
+
jsTeasers.forEach((teaserEl) => {
|
|
50
|
+
const params = JSON.parse(teaserEl.getAttribute("data-params"));
|
|
51
|
+
teaserEl.replaceWith(dsTeaserStandard(params));
|
|
52
|
+
});
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonniernews/dn-design-system-web",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.92",
|
|
4
4
|
"description": "DN design system for web.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"homepage": "https://github.com/BonnierNews/dn-design-system/tree/main/web/src#readme",
|