@bonniernews/dn-design-system-web 32.1.1 → 32.2.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/CHANGELOG.md +7 -0
- package/components/image-caption/README-NJK.md +39 -0
- package/components/image-caption/README.md +24 -39
- package/components/image-caption/image-caption.njk +1 -1
- package/package.json +1 -1
- package/preact/components/image-caption/image-caption.d.ts +22 -0
- package/preact/components/image-caption/image-caption.js +28 -0
- package/preact/components/image-caption/image-caption.js.map +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All changes to @bonniernews/dn-design-system-web will be documented in this file
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
## [32.2.0](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@32.1.1...@bonniernews/dn-design-system-web@32.2.0) (2025-05-12)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **web:** imagecaption tsx ([#1731](https://github.com/BonnierNews/dn-design-system/issues/1731)) ([c624840](https://github.com/BonnierNews/dn-design-system/commit/c62484032ce948d3ca12468e04467aa286d9082f))
|
|
13
|
+
|
|
7
14
|
## [32.1.1](https://github.com/BonnierNews/dn-design-system/compare/@bonniernews/dn-design-system-web@32.1.0...@bonniernews/dn-design-system-web@32.1.1) (2025-05-07)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
- GitHub: [BonnierNews/dn-design-system/../web/src/components/image-caption](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/image-caption)
|
|
2
|
+
- Storybook: [ImageCaption](https://designsystem.dn.se/?path=/docs/article-imagecaption--docs)
|
|
3
|
+
- Storybook (Latest): [ImageCaption](https://designsystem-latest.dn.se/?path=/docs/article-imagecaption--docs)
|
|
4
|
+
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
# ImageCaption
|
|
8
|
+
|
|
9
|
+
## Parameters
|
|
10
|
+
|
|
11
|
+
|parameter | type | required | options | default | description |
|
|
12
|
+
|:--- | :--- | :--- | :--- | :--- | :--- |
|
|
13
|
+
|caption | String | no | | | Ex "Detta är en bildtext" |
|
|
14
|
+
|imageType | String | no | | | Type of image. Ex "Foto" |
|
|
15
|
+
|author | String | no | | | Ex "Paul Hansen" |
|
|
16
|
+
|attributes | Object | no | | | Ex. { target: "_blank", "data-test": "lorem ipsum" } |
|
|
17
|
+
|classNames | String | no | | | Ex. "my-special-class" |
|
|
18
|
+
|forcePx | Bool | no | true, false | false | Fixed pixel value is used for typography to prevent scaling based on html font-size
|
|
19
|
+
|
|
20
|
+
## Minimum requirement example
|
|
21
|
+
|
|
22
|
+
### Nunjucks
|
|
23
|
+
|
|
24
|
+
These are copy paste friendly examples to quickliy get started using a component.
|
|
25
|
+
|
|
26
|
+
```html
|
|
27
|
+
{% from '@bonniernews/dn-design-system-web/components/image-caption/image-caption.njk' import ImageCaption %}
|
|
28
|
+
|
|
29
|
+
{{ ImageCaption({
|
|
30
|
+
caption: "En bildtext",
|
|
31
|
+
imageType: "Foto",
|
|
32
|
+
author: "Paul Hansen"
|
|
33
|
+
})}}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### SCSS
|
|
37
|
+
```scss
|
|
38
|
+
@use "@bonniernews/dn-design-system-web/components/image-caption/image-caption";
|
|
39
|
+
```
|
|
@@ -1,39 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
|
12
|
-
|
|
13
|
-
|
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```html
|
|
27
|
-
{% from '@bonniernews/dn-design-system-web/components/image-caption/image-caption.njk' import ImageCaption %}
|
|
28
|
-
|
|
29
|
-
{{ ImageCaption({
|
|
30
|
-
caption: "En bildtext",
|
|
31
|
-
imageType: "Foto",
|
|
32
|
-
author: "Paul Hansen"
|
|
33
|
-
})}}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### SCSS
|
|
37
|
-
```scss
|
|
38
|
-
@use "@bonniernews/dn-design-system-web/components/image-caption/image-caption";
|
|
39
|
-
```
|
|
1
|
+
ImageCaption
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
* GitHub: [BonnierNews/dn-design-system/../web/src/components/image-caption](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/image-caption)
|
|
5
|
+
* Storybook: [ImageCaption](https://designsystem.dn.se/?path=/docs/article-image-caption--docs)
|
|
6
|
+
|
|
7
|
+
The component will not include styling by itself. Make sure to include the right styles for the component. See example below: `@use '@bonniernews/dn-design-system-web/components/image-caption/image-caption.scss'`
|
|
8
|
+
|
|
9
|
+
| Name | Description | Default |
|
|
10
|
+
|:--- | :--- | :--- |
|
|
11
|
+
| caption | Ex "Detta är en bildtext"<br />string | \- |
|
|
12
|
+
| author | Ex "Paul Hansen"<br />string | \- |
|
|
13
|
+
| imageType | Type of image. Ex "Foto" or "Illustration"<br />string | \- |
|
|
14
|
+
| classNames | Ex. "my-special-class another-class"<br />string | \- |
|
|
15
|
+
| attributes | Ex. { target: "\_blank", "data-test": "lorem ipsum" }<br />object | \- |
|
|
16
|
+
| forcePx | Fixed pixel value is used for typography to prevent scaling based on html font-size<br />boolean | \- |
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
<ImageCaption
|
|
20
|
+
author="Paul Hansen"
|
|
21
|
+
caption="Detta är en bildtext"
|
|
22
|
+
imageType="Foto"
|
|
23
|
+
/>
|
|
24
|
+
```
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
{# Low estimate of how much will fit on tablet/desktop #}
|
|
22
22
|
{% if (authorText | length) >= 27 and (authorText | length) < 60 %}
|
|
23
23
|
{% set authorClasses = (authorClasses.push("ds-article-image__credits--nowrap-bigscreen"), authorClasses) %}
|
|
24
|
-
{# Low estimate of how much will fit on
|
|
24
|
+
{# Low estimate of how much will fit on 320px mobile #}
|
|
25
25
|
{% elif (authorText | length) < 27 %}
|
|
26
26
|
{% set authorClasses = (authorClasses.push("ds-article-image__credits--nowrap"), authorClasses) %}
|
|
27
27
|
{% endif %}
|
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ImageCaptionProps {
|
|
2
|
+
/** Ex "Detta är en bildtext" */
|
|
3
|
+
caption?: string;
|
|
4
|
+
/** Ex "Paul Hansen" */
|
|
5
|
+
author?: string;
|
|
6
|
+
/** Type of image. Ex "Foto" or "Illustration" */
|
|
7
|
+
imageType?: string;
|
|
8
|
+
/** Ex. "my-special-class another-class" */
|
|
9
|
+
classNames?: string;
|
|
10
|
+
/** Ex. { target: "_blank", "data-test": "lorem ipsum" } */
|
|
11
|
+
attributes?: object;
|
|
12
|
+
/** Fixed pixel value is used for typography to prevent scaling based on html font-size */
|
|
13
|
+
forcePx?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* - GitHub: [BonnierNews/dn-design-system/../web/src/components/image-caption](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/image-caption)
|
|
17
|
+
* - Storybook: [ImageCaption](https://designsystem.dn.se/?path=/docs/article-image-caption--docs)
|
|
18
|
+
*
|
|
19
|
+
* The component will not include styling by itself. Make sure to include the right styles for the component. See example below:
|
|
20
|
+
* `@use '@bonniernews/dn-design-system-web/components/image-caption/image-caption.scss'`
|
|
21
|
+
*/
|
|
22
|
+
export declare const ImageCaption: ({ caption, author, imageType, classNames, attributes, forcePx }: ImageCaptionProps) => import("preact").JSX.Element;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ../src/helpers/formatClassString.ts
|
|
2
|
+
var formatClassString = (classesArray) => {
|
|
3
|
+
return classesArray.filter((x) => !!x).join(" ");
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// ../src/components/image-caption/image-caption.tsx
|
|
7
|
+
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
8
|
+
var ImageCaption = ({ caption, author, imageType, classNames, attributes, forcePx }) => {
|
|
9
|
+
const classes = formatClassString([
|
|
10
|
+
"ds-image-caption",
|
|
11
|
+
forcePx && "ds-force-px",
|
|
12
|
+
classNames
|
|
13
|
+
]);
|
|
14
|
+
const authorText = imageType && author ? `${imageType.charAt(0).toUpperCase() + imageType.slice(1)}: ${author}` : author;
|
|
15
|
+
const authorClasses = [
|
|
16
|
+
"ds-article-image__credits",
|
|
17
|
+
authorText && authorText.length >= 27 && authorText.length < 60 ? "ds-article-image__credits--nowrap-bigscreen" : authorText && authorText.length < 27 ? "ds-article-image__credits--nowrap" : null
|
|
18
|
+
].filter(Boolean).join(" ");
|
|
19
|
+
return /* @__PURE__ */ jsxs("figcaption", { className: classes, "aria-hidden": "true", ...attributes, children: [
|
|
20
|
+
caption && /* @__PURE__ */ jsx("span", { dangerouslySetInnerHTML: { __html: caption } }),
|
|
21
|
+
caption && authorText && "\xA0",
|
|
22
|
+
authorText && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx("span", { className: authorClasses, children: authorText }) })
|
|
23
|
+
] });
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
ImageCaption
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=image-caption.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../helpers/formatClassString.ts", "../../../components/image-caption/image-caption.tsx"],
|
|
4
|
+
"sourcesContent": ["export const formatClassString = (classesArray: (string|undefined|false)[]): string => {\n return classesArray.filter(x => !!x).join(' ');\n}\n", "import { formatClassString } from '@bonniernews/dn-design-system-web/helpers/formatClassString.ts';\n\nexport interface ImageCaptionProps {\n /** Ex \"Detta \u00E4r en bildtext\" */\n caption?: string;\n /** Ex \"Paul Hansen\" */\n author?: string;\n /** Type of image. Ex \"Foto\" or \"Illustration\" */\n imageType?: string;\n /** Ex. \"my-special-class another-class\" */\n classNames?: string;\n /** Ex. { target: \"_blank\", \"data-test\": \"lorem ipsum\" } */\n attributes?: object;\n /** Fixed pixel value is used for typography to prevent scaling based on html font-size */\n forcePx?: boolean;\n}\n\n/**\n * - GitHub: [BonnierNews/dn-design-system/../web/src/components/image-caption](https://github.com/BonnierNews/dn-design-system/tree/main/web/src/components/image-caption)\n * - Storybook: [ImageCaption](https://designsystem.dn.se/?path=/docs/article-image-caption--docs)\n *\n * The component will not include styling by itself. Make sure to include the right styles for the component. See example below:\n * `@use '@bonniernews/dn-design-system-web/components/image-caption/image-caption.scss'`\n */\nexport const ImageCaption = ({caption, author, imageType, classNames, attributes, forcePx}: ImageCaptionProps) => {\n const classes = formatClassString([\n 'ds-image-caption',\n forcePx && 'ds-force-px',\n classNames,\n ]);\n\n const authorText = imageType && author ? `${imageType.charAt(0).toUpperCase() + imageType.slice(1)}: ${author}` : author;\n\n const authorClasses = [\n 'ds-article-image__credits',\n authorText && authorText.length >= 27 && authorText.length < 60 // Low estimate of how much will fit on tablet/desktop\n ? 'ds-article-image__credits--nowrap-bigscreen' : authorText && authorText.length < 27 // Low estimate of how much will fit on 320px mobile\n ? 'ds-article-image__credits--nowrap' : null,\n ].filter(Boolean).join(' ');\n\n return (\n <figcaption className={classes} aria-hidden=\"true\" {...attributes} >\n {caption && <span dangerouslySetInnerHTML={{ __html: caption }} />}\n\n {/* non-breaking space between the caption-span and author-span */}\n {caption && authorText && '\\u00A0'}\n\n {authorText && (\n <>\n <span className={authorClasses}>\n {authorText}\n </span>\n </>\n )}\n </figcaption>\n );\n};\n"],
|
|
5
|
+
"mappings": ";AAAO,IAAM,oBAAoB,CAAC,iBAAqD;AACrF,SAAO,aAAa,OAAO,OAAK,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG;AAC/C;;;ACuCI,SAOE,UANY,KADd;AAjBG,IAAM,eAAe,CAAC,EAAC,SAAS,QAAQ,WAAW,YAAY,YAAY,QAAO,MAAyB;AAChH,QAAM,UAAU,kBAAkB;AAAA,IAChC;AAAA,IACA,WAAW;AAAA,IACX;AAAA,EACF,CAAC;AAED,QAAM,aAAa,aAAa,SAAS,GAAG,UAAU,OAAO,CAAC,EAAE,YAAY,IAAI,UAAU,MAAM,CAAC,CAAC,KAAK,MAAM,KAAK;AAElH,QAAM,gBAAgB;AAAA,IACpB;AAAA,IACA,cAAc,WAAW,UAAU,MAAM,WAAW,SAAS,KACzD,gDAAgD,cAAc,WAAW,SAAS,KAClF,sCAAsC;AAAA,EAC5C,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAE1B,SACE,qBAAC,gBAAW,WAAW,SAAS,eAAY,QAAQ,GAAG,YACpD;AAAA,eAAW,oBAAC,UAAK,yBAAyB,EAAE,QAAQ,QAAQ,GAAG;AAAA,IAG/D,WAAW,cAAc;AAAA,IAEzB,cACD,gCACE,8BAAC,UAAK,WAAW,eACd,sBACH,GACF;AAAA,KAEF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|