@ndla/ui 56.0.149-alpha.0 → 56.0.151-alpha.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/dist/panda.buildinfo.json +2 -1
- package/dist/styles.css +8 -4
- package/es/Article/Article.mjs +5 -9
- package/es/Article/Article.mjs.map +1 -1
- package/es/Article/BadgesContainer.mjs +14 -0
- package/es/Article/BadgesContainer.mjs.map +1 -0
- package/es/AudioPlayer/Controls.mjs +1 -2
- package/es/AudioPlayer/Controls.mjs.map +1 -1
- package/es/Embed/RelatedContentEmbed.mjs +5 -6
- package/es/Embed/RelatedContentEmbed.mjs.map +1 -1
- package/es/RelatedArticleList/RelatedArticleList.mjs +3 -4
- package/es/RelatedArticleList/RelatedArticleList.mjs.map +1 -1
- package/es/index.mjs +2 -2
- package/es/utils/licenseAttributes.mjs +1 -2
- package/es/utils/licenseAttributes.mjs.map +1 -1
- package/lib/Article/Article.d.ts +4 -7
- package/lib/Article/Article.js +5 -9
- package/lib/Article/Article.js.map +1 -1
- package/lib/Article/BadgesContainer.d.ts +8 -0
- package/lib/Article/BadgesContainer.js +16 -0
- package/lib/Article/BadgesContainer.js.map +1 -0
- package/lib/AudioPlayer/Controls.js +1 -2
- package/lib/AudioPlayer/Controls.js.map +1 -1
- package/lib/Embed/RelatedContentEmbed.d.ts +2 -1
- package/lib/Embed/RelatedContentEmbed.js +6 -6
- package/lib/Embed/RelatedContentEmbed.js.map +1 -1
- package/lib/RelatedArticleList/RelatedArticleList.d.ts +2 -2
- package/lib/RelatedArticleList/RelatedArticleList.js +3 -4
- package/lib/RelatedArticleList/RelatedArticleList.js.map +1 -1
- package/lib/index.js +2 -2
- package/lib/utils/licenseAttributes.js +1 -2
- package/lib/utils/licenseAttributes.js.map +1 -1
- package/package.json +2 -2
- package/src/Article/Article.tsx +8 -13
- package/src/Article/BadgesContainer.tsx +19 -0
- package/src/Embed/RelatedContentEmbed.tsx +8 -6
- package/src/RelatedArticleList/RelatedArticleList.tsx +4 -5
- package/src/index.ts +0 -3
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"flexDirection]___[value:row]___[cond:tabletWide",
|
|
37
37
|
"gap]___[value:xsmall",
|
|
38
38
|
"listStyle]___[value:none",
|
|
39
|
+
"flexDirection]___[value:row",
|
|
40
|
+
"gap]___[value:xxsmall",
|
|
39
41
|
"border]___[value:1px solid",
|
|
40
42
|
"borderColor]___[value:stroke.default",
|
|
41
43
|
"borderRadius]___[value:xsmall",
|
|
@@ -85,7 +87,6 @@
|
|
|
85
87
|
"gridArea]___[value:forwards",
|
|
86
88
|
"gridArea]___[value:backwards",
|
|
87
89
|
"flex]___[value:1",
|
|
88
|
-
"gap]___[value:xxsmall",
|
|
89
90
|
"gridArea]___[value:track",
|
|
90
91
|
"paddingInline]___[value:xsmall]___[cond:mobileDown",
|
|
91
92
|
"minWidth]___[value:xxlarge",
|
package/dist/styles.css
CHANGED
|
@@ -220,6 +220,10 @@
|
|
|
220
220
|
list-style: none;
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
+
.gap_xxsmall {
|
|
224
|
+
gap: var(--spacing-xxsmall);
|
|
225
|
+
}
|
|
226
|
+
|
|
223
227
|
.bd-c_stroke\.default {
|
|
224
228
|
border-color: var(--colors-stroke-default);
|
|
225
229
|
}
|
|
@@ -256,10 +260,6 @@
|
|
|
256
260
|
flex: 1 1 0%;
|
|
257
261
|
}
|
|
258
262
|
|
|
259
|
-
.gap_xxsmall {
|
|
260
|
-
gap: var(--spacing-xxsmall);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
263
|
.py_auto {
|
|
264
264
|
padding-block: auto;
|
|
265
265
|
}
|
|
@@ -372,6 +372,10 @@
|
|
|
372
372
|
padding-block-start: var(--spacing-xsmall);
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
+
.flex-d_row {
|
|
376
|
+
flex-direction: row;
|
|
377
|
+
}
|
|
378
|
+
|
|
375
379
|
.bx-sh_full {
|
|
376
380
|
box-shadow: var(--shadows-full);
|
|
377
381
|
}
|
package/es/Article/Article.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BadgesContainer } from "./BadgesContainer.mjs";
|
|
2
2
|
import { ArticleByline } from "./ArticleByline.mjs";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { Heading, Text } from "@ndla/primitives";
|
|
@@ -72,12 +72,9 @@ const StyledWrapper = styled("div", { base: {
|
|
|
72
72
|
flexWrap: "wrap",
|
|
73
73
|
alignItems: "center"
|
|
74
74
|
} });
|
|
75
|
-
const ArticleTitle = ({
|
|
75
|
+
const ArticleTitle = ({ badges, heartButton, title, lang, id, introduction, competenceGoals, disclaimer }) => {
|
|
76
76
|
return /* @__PURE__ */ jsxs(ArticleHeader, { children: [
|
|
77
|
-
/* @__PURE__ */ jsxs(ArticleHGroup, { children: [(!!
|
|
78
|
-
contentType,
|
|
79
|
-
children: contentTypeLabel
|
|
80
|
-
}), heartButton] }), /* @__PURE__ */ jsx(Heading, {
|
|
77
|
+
/* @__PURE__ */ jsxs(ArticleHGroup, { children: [(!!badges || !!heartButton) && /* @__PURE__ */ jsxs(InfoWrapper, { children: [!!badges && /* @__PURE__ */ jsx(BadgesContainer, { children: badges }), heartButton] }), /* @__PURE__ */ jsx(Heading, {
|
|
81
78
|
textStyle: "heading.medium",
|
|
82
79
|
id,
|
|
83
80
|
lang,
|
|
@@ -94,19 +91,18 @@ const ArticleTitle = ({ contentType, heartButton, title, lang, id, introduction,
|
|
|
94
91
|
/* @__PURE__ */ jsxs(StyledWrapper, { children: [competenceGoals, disclaimer] })
|
|
95
92
|
] });
|
|
96
93
|
};
|
|
97
|
-
const Article = ({
|
|
94
|
+
const Article = ({ badges, article, licenseBox, children, competenceGoals, id, heartButton, lang, disclaimer }) => {
|
|
98
95
|
const { title, introduction, published, content, footNotes, copyright } = article;
|
|
99
96
|
const authors = copyright?.creators.length || copyright?.rightsholders.length ? copyright.creators : copyright?.processors;
|
|
100
97
|
return /* @__PURE__ */ jsxs(ArticleWrapper, { children: [
|
|
101
98
|
/* @__PURE__ */ jsx(ArticleTitle, {
|
|
102
99
|
id,
|
|
103
|
-
|
|
100
|
+
badges,
|
|
104
101
|
heartButton,
|
|
105
102
|
title,
|
|
106
103
|
introduction,
|
|
107
104
|
competenceGoals,
|
|
108
105
|
lang,
|
|
109
|
-
contentTypeLabel,
|
|
110
106
|
disclaimer
|
|
111
107
|
}),
|
|
112
108
|
/* @__PURE__ */ jsx(ArticleContent, { children: content }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Article.mjs","names":[],"sources":["../../src/Article/Article.tsx"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { type ComponentPropsWithRef, type ReactNode, forwardRef } from \"react\";\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\";\nimport { Heading, Text } from \"@ndla/primitives\";\nimport { cx } from \"@ndla/styled-system/css\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { ArticleByline } from \"./ArticleByline\";\nimport {
|
|
1
|
+
{"version":3,"file":"Article.mjs","names":[],"sources":["../../src/Article/Article.tsx"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { type ComponentPropsWithRef, type ReactNode, forwardRef } from \"react\";\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\";\nimport { Heading, Text } from \"@ndla/primitives\";\nimport { cx } from \"@ndla/styled-system/css\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { ArticleByline } from \"./ArticleByline\";\nimport { BadgesContainer } from \"./BadgesContainer\";\nimport type { Article as ArticleType } from \"../types\";\n\nconst StyledArticleContent = styled(ark.section, {}, { baseComponent: true });\n\nexport const ArticleContent = forwardRef<HTMLElement, HTMLArkProps<\"div\"> & StyledProps>(\n ({ className, ...props }, ref) => (\n <StyledArticleContent className={cx(\"ndla-article\", className)} {...props} ref={ref} />\n ),\n);\n\nconst StyledArticleWrapper = styled(\n ark.article,\n {\n base: {\n background: \"background.default\",\n display: \"flex\",\n flexDirection: \"column\",\n color: \"text.default\",\n alignItems: \"center\",\n width: \"100%\",\n overflowWrap: \"break-word\",\n position: \"relative\",\n \"& mjx-stretchy-v > mjx-ext > mjx-c\": {\n transform: \"scaleY(100) translateY(0.075em)\",\n },\n _after: {\n content: \"\",\n display: \"table\",\n clear: \"both\",\n },\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleWrapper = forwardRef<HTMLElement, ComponentPropsWithRef<\"article\"> & StyledProps>((props, ref) => (\n <StyledArticleWrapper data-ndla-article=\"\" ref={ref} {...props} />\n));\n\nexport const ArticleHGroup = styled(\n ark.hgroup,\n {\n base: {\n display: \"flex\",\n width: \"100%\",\n flexDirection: \"column\",\n alignItems: \"flex-start\",\n \"& h1\": {\n overflowWrap: \"anywhere\",\n },\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleHeader = styled(\n ark.header,\n {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"medium\",\n alignItems: \"flex-start\",\n width: \"100%\",\n paddingBlockStart: \"xxlarge\",\n overflowWrap: \"anywhere\",\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleFooter = styled(\n ark.footer,\n {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"xxlarge\",\n width: \"100%\",\n \"& > :is(:last-child)\": {\n paddingBlockEnd: \"5xlarge\",\n },\n },\n },\n { baseComponent: true },\n);\n\nconst InfoWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: \"small\",\n width: \"100%\",\n minHeight: \"xxlarge\",\n },\n});\n\nconst StyledWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n gap: \"small\",\n flexWrap: \"wrap\",\n alignItems: \"center\",\n },\n});\n\ninterface ArticleTitleProps {\n badges?: ReactNode;\n heartButton?: ReactNode;\n competenceGoals?: ReactNode;\n id: string;\n lang?: string;\n title?: ReactNode;\n introduction?: ReactNode;\n disclaimer?: ReactNode;\n}\n\nexport const ArticleTitle = ({\n badges,\n heartButton,\n title,\n lang,\n id,\n introduction,\n competenceGoals,\n disclaimer,\n}: ArticleTitleProps) => {\n return (\n <ArticleHeader>\n <ArticleHGroup>\n {(!!badges || !!heartButton) && (\n <InfoWrapper>\n {!!badges && <BadgesContainer>{badges}</BadgesContainer>}\n {heartButton}\n </InfoWrapper>\n )}\n <Heading textStyle=\"heading.medium\" id={id} lang={lang} property=\"dct:title\">\n {title}\n </Heading>\n </ArticleHGroup>\n {!!introduction && (\n <Text lang={lang} textStyle=\"body.xlarge\" asChild consumeCss>\n <div>{introduction}</div>\n </Text>\n )}\n <StyledWrapper>\n {competenceGoals}\n {disclaimer}\n </StyledWrapper>\n </ArticleHeader>\n );\n};\n\ninterface Props {\n badges?: ReactNode;\n heartButton?: ReactNode;\n article: ArticleType;\n licenseBox?: ReactNode;\n children?: ReactNode;\n competenceGoals?: ReactNode;\n id: string;\n lang?: string;\n disclaimer?: ReactNode;\n}\n\nexport const Article = ({\n badges,\n article,\n licenseBox,\n children,\n competenceGoals,\n id,\n heartButton,\n lang,\n disclaimer,\n}: Props) => {\n const { title, introduction, published, content, footNotes, copyright } = article;\n\n const authors =\n copyright?.creators.length || copyright?.rightsholders.length ? copyright.creators : copyright?.processors;\n\n return (\n <ArticleWrapper>\n <ArticleTitle\n id={id}\n badges={badges}\n heartButton={heartButton}\n title={title}\n introduction={introduction}\n competenceGoals={competenceGoals}\n lang={lang}\n disclaimer={disclaimer}\n />\n <ArticleContent>{content}</ArticleContent>\n <ArticleFooter>\n <ArticleByline\n lang={lang}\n footnotes={footNotes}\n authors={authors}\n suppliers={copyright?.rightsholders}\n published={published}\n licenseBox={licenseBox}\n />\n {children}\n </ArticleFooter>\n </ArticleWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,uBAAuB,OAAO,IAAI,SAAS,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC;AAE7E,MAAa,iBAAiB,YAC3B,EAAE,UAAW,GAAG,SAAS,QACxB,oBAAC;CAAqB,WAAW,GAAG,gBAAgB,UAAU;CAAE,GAAI;CAAY;EAAO,CAE1F;AAED,MAAM,uBAAuB,OAC3B,IAAI,SACJ,EACE,MAAM;CACJ,YAAY;CACZ,SAAS;CACT,eAAe;CACf,OAAO;CACP,YAAY;CACZ,OAAO;CACP,cAAc;CACd,UAAU;CACV,sCAAsC,EACpC,WAAW,mCACZ;CACD,QAAQ;EACN,SAAS;EACT,SAAS;EACT,OAAO;EACR;CACF,EACF,EACD,EAAE,eAAe,MAAM,CACxB;AAED,MAAa,iBAAiB,YAAyE,OAAO,QAC5G,oBAAC;CAAqB,qBAAkB;CAAQ;CAAK,GAAI;EAAS,CAClE;AAEF,MAAa,gBAAgB,OAC3B,IAAI,QACJ,EACE,MAAM;CACJ,SAAS;CACT,OAAO;CACP,eAAe;CACf,YAAY;CACZ,QAAQ,EACN,cAAc,YACf;CACF,EACF,EACD,EAAE,eAAe,MAAM,CACxB;AAED,MAAa,gBAAgB,OAC3B,IAAI,QACJ,EACE,MAAM;CACJ,SAAS;CACT,eAAe;CACf,KAAK;CACL,YAAY;CACZ,OAAO;CACP,mBAAmB;CACnB,cAAc;CACf,EACF,EACD,EAAE,eAAe,MAAM,CACxB;AAED,MAAa,gBAAgB,OAC3B,IAAI,QACJ,EACE,MAAM;CACJ,SAAS;CACT,eAAe;CACf,KAAK;CACL,OAAO;CACP,wBAAwB,EACtB,iBAAiB,WAClB;CACF,EACF,EACD,EAAE,eAAe,MAAM,CACxB;AAED,MAAM,cAAc,OAAO,OAAO,EAChC,MAAM;CACJ,SAAS;CACT,YAAY;CACZ,gBAAgB;CAChB,KAAK;CACL,OAAO;CACP,WAAW;CACZ,EACF,CAAC;AAEF,MAAM,gBAAgB,OAAO,OAAO,EAClC,MAAM;CACJ,SAAS;CACT,KAAK;CACL,UAAU;CACV,YAAY;CACb,EACF,CAAC;AAaF,MAAa,gBAAgB,EAC3B,QACA,aACA,OACA,MACA,IACA,cACA,iBACA,iBACuB;AACvB,QACE,qBAAC;EACC,qBAAC,6BACG,CAAC,CAAC,UAAU,CAAC,CAAC,gBACd,qBAAC,0BACE,CAAC,CAAC,UAAU,oBAAC,6BAAiB,SAAyB,EACvD,eACW,EAEhB,oBAAC;GAAQ,WAAU;GAAqB;GAAU;GAAM,UAAS;aAC9D;IACO,IACI;EACf,CAAC,CAAC,gBACD,oBAAC;GAAW;GAAM,WAAU;GAAc;GAAQ;aAChD,oBAAC,mBAAK,eAAmB;IACpB;EAET,qBAAC,4BACE,iBACA,cACa;KACF;;AAgBpB,MAAa,WAAW,EACtB,QACA,SACA,YACA,UACA,iBACA,IACA,aACA,MACA,iBACW;CACX,MAAM,EAAE,OAAO,cAAc,WAAW,SAAS,WAAW,cAAc;CAE1E,MAAM,UACJ,WAAW,SAAS,UAAU,WAAW,cAAc,SAAS,UAAU,WAAW,WAAW;AAElG,QACE,qBAAC;EACC,oBAAC;GACK;GACI;GACK;GACN;GACO;GACG;GACX;GACM;IACZ;EACF,oBAAC,4BAAgB,UAAyB;EAC1C,qBAAC,4BACC,oBAAC;GACO;GACN,WAAW;GACF;GACT,WAAW,WAAW;GACX;GACC;IACZ,EACD,YACa;KACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
2
|
+
|
|
3
|
+
//#region src/Article/BadgesContainer.tsx
|
|
4
|
+
const BadgesContainer = styled("div", { base: {
|
|
5
|
+
display: "flex",
|
|
6
|
+
flexDirection: "row",
|
|
7
|
+
alignItems: "flex-start",
|
|
8
|
+
flexWrap: "wrap",
|
|
9
|
+
gap: "xxsmall"
|
|
10
|
+
} });
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { BadgesContainer };
|
|
14
|
+
//# sourceMappingURL=BadgesContainer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BadgesContainer.mjs","names":[],"sources":["../../src/Article/BadgesContainer.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nexport const BadgesContainer = styled(\"div\", {\n base: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"flex-start\",\n flexWrap: \"wrap\",\n gap: \"xxsmall\",\n },\n});\n"],"mappings":";;;AAUA,MAAa,kBAAkB,OAAO,OAAO,EAC3C,MAAM;CACJ,SAAS;CACT,eAAe;CACf,YAAY;CACZ,UAAU;CACV,KAAK;CACN,EACF,CAAC"}
|
|
@@ -66,8 +66,7 @@ const StyledPopoverContent = styled(PopoverContent, { base: { paddingInline: "sm
|
|
|
66
66
|
const formatTime = (seconds) => {
|
|
67
67
|
const minutes = Math.floor(seconds / 60);
|
|
68
68
|
const currentSeconds = seconds % 60;
|
|
69
|
-
|
|
70
|
-
return `${minutes}:${formattedSeconds}`;
|
|
69
|
+
return `${minutes}:${currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds}`;
|
|
71
70
|
};
|
|
72
71
|
const speedValues = createListCollection({ items: [
|
|
73
72
|
"0.5",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Controls.mjs","names":["currentTime"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nexport const Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime || 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration || 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </ControlsWrapper>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAsCA,MAAM,kBAAkB,OAAO,OAAO,EACpC,MAAM;CACJ,kBAAkB;CAClB,aAAa;CACb,oBAAoB;CACpB,SAAS;CACT,YAAY;CACZ,gBAAgB;CAChB,YAAY;CACZ,KAAK;CACL,cAAc;CACd,eAAe;CACf,gBAAgB;EACd,SAAS;EACT,cAAc;EACd,eAAe;EACf,qBAAqB;EACrB,mBAAmB;;;;EAIpB;CACD,gBAAgB,EACd,WAAW,WACZ;CACF,EACF,CAAC;AAEF,MAAM,aAAa,OAAO,YAAY,EACpC,MAAM,EACJ,UAAU,QACX,EACF,CAAC;AAEF,MAAM,qBAAqB,OAAO,YAAY,EAC5C,MAAM,EACJ,UAAU,YACX,EACF,CAAC;AAEF,MAAM,kBAAkB,OAAO,YAAY,EACzC,MAAM,EACJ,UAAU,aACX,EACF,CAAC;AAEF,MAAM,kBAAkB,OAAO,OAAO,EACpC,MAAM;CACJ,MAAM;CACN,SAAS;CACT,YAAY;CACZ,KAAK;CACL,UAAU;CACV,cAAc;CACd,YAAY,EACV,eAAe,UAChB;CACF,EACF,CAAC;AAEF,MAAM,aAAa,OAAO,MAAM,EAC9B,MAAM;CACJ,UAAU;CACV,YAAY;CACZ,WAAW;CACZ,EACF,CAAC;AAEF,MAAM,eAAe,OAAO,YAAY,EACtC,MAAM,EACJ,UAAU,UACX,EACF,CAAC;AAEF,MAAM,cAAc,OAAO,QAAQ,EACjC,MAAM;CACJ,cAAc;CACd,eAAe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IAChB,oBAAC,2BACE,YAAY,MAAM,KAAK,UACtB,qBAAC;KAAuB,MAAM;gBAC5B,qBAAC,6BAAgB,OAAM,OAAkB,EACzC,oBAAC,iCACC,oBAAC,cAAY,GACO;OAJP,MAKJ,CACb,GACY;;IACC,GACT;EACZ,qBAAC;GAAY,aAAa,EAAE,WAAW,OAAO;cAC5C,oBAAC;IAAe;cACd,oBAAC;KAAa,SAAQ;KAAW,cAAY,EAAE,8BAA8B;eAC3E,oBAAC,iBAAe;MACH;KACA,EACjB,oBAAC,kCACC,qBAAC;IACC,aAAY;IACZ,OAAO,CAAC,YAAY;IACpB,KAAK;IACL,KAAK;IACL,cAAc,CAAC,IAAI;IACnB,MAAM;IACN,eAAe;eAEf,oBAAC;KAAY;eAAQ,EAAE,8BAA8B;MAAe,EACpE,qBAAC,kCACC,oBAAC,yBACC,oBAAC,gBAAc,GACH,EACd,oBAAC;KAAY,OAAO;eAClB,oBAAC,sBAAoB;MACT,IACM;KACX,GACQ;IACX;KACE,IACd"}
|
|
1
|
+
{"version":3,"file":"Controls.mjs","names":["currentTime"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nexport const Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime || 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration || 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </ControlsWrapper>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;AAsCA,MAAM,kBAAkB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AAY;IACpB,KAAK;IACL,KAAK;IACL,cAAc,CAAC,IAAI;IACnB,MAAM;IACN,eAAe;eAEf,oBAAC;KAAY;eAAQ,EAAE,8BAA8B;MAAe,EACpE,qBAAC,kCACC,oBAAC,yBACC,oBAAC,gBAAc,GACH,EACd,oBAAC;KAAY,OAAO;eAClB,oBAAC,sBAAoB;MACT,IACM;KACX,GACQ;IACX;KACE,IACd"}
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { contentTypeMapping } from "../model/ContentType.mjs";
|
|
2
1
|
import { RelatedArticle } from "../RelatedArticleList/RelatedArticleList.mjs";
|
|
2
|
+
import { Badge } from "@ndla/primitives";
|
|
3
3
|
import { useTranslation } from "react-i18next";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
|
|
6
6
|
//#region src/Embed/RelatedContentEmbed.tsx
|
|
7
|
-
const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }) => {
|
|
7
|
+
const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain, language }) => {
|
|
8
8
|
const { t } = useTranslation();
|
|
9
9
|
if (embed.status === "error") return null;
|
|
10
10
|
const { data, embedData } = embed;
|
|
11
11
|
if (embedData.articleId && data) {
|
|
12
|
-
const
|
|
13
|
-
const type = typeId ? contentTypeMapping[typeId] : void 0;
|
|
12
|
+
const badges = data.resource?.resourceTypes?.map((rt) => /* @__PURE__ */ jsx(Badge, { children: rt.translations.find((t$1) => t$1.language === language)?.name ?? rt.name }, rt.id));
|
|
14
13
|
const url = (data.resource?.contexts.find((c) => c.rootId === subject))?.url ?? data.resource?.url ?? `/article/${embedData.articleId}`;
|
|
15
14
|
return /* @__PURE__ */ jsx(RelatedArticle, {
|
|
16
15
|
title: data.article.title?.title ?? "",
|
|
17
16
|
introduction: data.article.metaDescription?.metaDescription ?? "",
|
|
18
17
|
target: isOembed ? "_blank" : void 0,
|
|
19
18
|
to: `${ndlaFrontendDomain ?? ""}${url ?? ""}`,
|
|
20
|
-
|
|
19
|
+
badges
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
if (typeof embedData.url === "string") return /* @__PURE__ */ jsx(RelatedArticle, {
|
|
@@ -25,7 +24,7 @@ const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }) =
|
|
|
25
24
|
introduction: "",
|
|
26
25
|
to: embedData.url,
|
|
27
26
|
target: "_blank",
|
|
28
|
-
|
|
27
|
+
badges: /* @__PURE__ */ jsx(Badge, { children: t("contentTypes.external") }),
|
|
29
28
|
linkInfo: `${t("related.linkInfo")} ${embedData.urlDomain}`
|
|
30
29
|
});
|
|
31
30
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelatedContentEmbed.mjs","names":[],"sources":["../../src/Embed/RelatedContentEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useTranslation } from \"react-i18next\";\nimport
|
|
1
|
+
{"version":3,"file":"RelatedContentEmbed.mjs","names":["t"],"sources":["../../src/Embed/RelatedContentEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useTranslation } from \"react-i18next\";\nimport { Badge } from \"@ndla/primitives\";\nimport type { RelatedContentMetaData } from \"@ndla/types-embed\";\nimport { RelatedArticle } from \"../RelatedArticleList/RelatedArticleList\";\n\ninterface Props {\n embed: RelatedContentMetaData;\n isOembed?: boolean;\n subject?: string;\n ndlaFrontendDomain?: string;\n language?: string;\n}\n\nexport const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain, language }: Props) => {\n const { t } = useTranslation();\n if (embed.status === \"error\") {\n return null;\n }\n\n const { data, embedData } = embed;\n\n if (embedData.articleId && data) {\n const badges = data.resource?.resourceTypes?.map((rt) => (\n <Badge key={rt.id}>{rt.translations.find((t) => t.language === language)?.name ?? rt.name}</Badge>\n ));\n const context = data.resource?.contexts.find((c) => c.rootId === subject);\n const url = context?.url ?? data.resource?.url ?? `/article/${embedData.articleId}`;\n return (\n <RelatedArticle\n title={data.article.title?.title ?? \"\"}\n introduction={data.article.metaDescription?.metaDescription ?? \"\"}\n target={isOembed ? \"_blank\" : undefined}\n to={`${ndlaFrontendDomain ?? \"\"}${url ?? \"\"}`}\n badges={badges}\n />\n );\n }\n if (typeof embedData.url === \"string\") {\n return (\n <RelatedArticle\n title={embedData.title ?? \"\"}\n introduction=\"\"\n to={embedData.url}\n target=\"_blank\"\n badges={<Badge>{t(\"contentTypes.external\")}</Badge>}\n linkInfo={`${t(\"related.linkInfo\")} ${embedData.urlDomain}`}\n />\n );\n }\n return null;\n};\n"],"mappings":";;;;;;AAqBA,MAAa,uBAAuB,EAAE,OAAO,UAAU,SAAS,oBAAoB,eAAsB;CACxG,MAAM,EAAE,MAAM,gBAAgB;AAC9B,KAAI,MAAM,WAAW,QACnB,QAAO;CAGT,MAAM,EAAE,MAAM,cAAc;AAE5B,KAAI,UAAU,aAAa,MAAM;EAC/B,MAAM,SAAS,KAAK,UAAU,eAAe,KAAK,OAChD,oBAAC,mBAAmB,GAAG,aAAa,MAAM,QAAMA,IAAE,aAAa,SAAS,EAAE,QAAQ,GAAG,QAAzE,GAAG,GAAmF,CAClG;EAEF,MAAM,OADU,KAAK,UAAU,SAAS,MAAM,MAAM,EAAE,WAAW,QAAQ,GACpD,OAAO,KAAK,UAAU,OAAO,YAAY,UAAU;AACxE,SACE,oBAAC;GACC,OAAO,KAAK,QAAQ,OAAO,SAAS;GACpC,cAAc,KAAK,QAAQ,iBAAiB,mBAAmB;GAC/D,QAAQ,WAAW,WAAW;GAC9B,IAAI,GAAG,sBAAsB,KAAK,OAAO;GACjC;IACR;;AAGN,KAAI,OAAO,UAAU,QAAQ,SAC3B,QACE,oBAAC;EACC,OAAO,UAAU,SAAS;EAC1B,cAAa;EACb,IAAI,UAAU;EACd,QAAO;EACP,QAAQ,oBAAC,mBAAO,EAAE,wBAAwB,GAAS;EACnD,UAAU,GAAG,EAAE,mBAAmB,CAAC,GAAG,UAAU;GAChD;AAGN,QAAO"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ContentTypeBadge } from "../ContentTypeBadge/ContentTypeBadge.mjs";
|
|
1
|
+
import { BadgesContainer } from "../Article/BadgesContainer.mjs";
|
|
3
2
|
import { Children, useMemo, useState } from "react";
|
|
4
3
|
import { Button, CardContent, CardHeading, CardRoot, Heading, Text } from "@ndla/primitives";
|
|
5
4
|
import { styled } from "@ndla/styled-system/jsx";
|
|
@@ -14,11 +13,11 @@ const StyledSpan = styled("span", { base: {
|
|
|
14
13
|
display: "flex",
|
|
15
14
|
gap: "3xsmall"
|
|
16
15
|
} });
|
|
17
|
-
const RelatedArticle = ({ title, introduction, to, linkInfo = "", target = ""
|
|
16
|
+
const RelatedArticle = ({ title, introduction, to, badges, linkInfo = "", target = "" }) => {
|
|
18
17
|
return /* @__PURE__ */ jsx(CardRoot, {
|
|
19
18
|
"data-embed-type": "related-article",
|
|
20
19
|
children: /* @__PURE__ */ jsxs(CardContent, { children: [
|
|
21
|
-
/* @__PURE__ */ jsx(
|
|
20
|
+
!!badges && /* @__PURE__ */ jsx(BadgesContainer, { children: badges }),
|
|
22
21
|
/* @__PURE__ */ jsx(CardHeading, {
|
|
23
22
|
asChild: true,
|
|
24
23
|
consumeCss: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelatedArticleList.mjs","names":[],"sources":["../../src/RelatedArticleList/RelatedArticleList.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { Children, type ComponentPropsWithoutRef, type ReactElement, type ReactNode, useMemo, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { ExternalLinkLine } from \"@ndla/icons\";\nimport { CardContent, CardHeading, CardRoot, Text, Heading, Button } from \"@ndla/primitives\";\nimport { SafeLink } from \"@ndla/safelink\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport { linkOverlay } from \"@ndla/styled-system/patterns\";\nimport {
|
|
1
|
+
{"version":3,"file":"RelatedArticleList.mjs","names":[],"sources":["../../src/RelatedArticleList/RelatedArticleList.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { Children, type ComponentPropsWithoutRef, type ReactElement, type ReactNode, useMemo, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { ExternalLinkLine } from \"@ndla/icons\";\nimport { CardContent, CardHeading, CardRoot, Text, Heading, Button } from \"@ndla/primitives\";\nimport { SafeLink } from \"@ndla/safelink\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport { linkOverlay } from \"@ndla/styled-system/patterns\";\nimport { BadgesContainer } from \"../Article/BadgesContainer\";\nimport type { HeadingLevel } from \"../types\";\n\ninterface RelatedArticleProps {\n title: string;\n introduction: string;\n to: string;\n linkInfo?: string;\n target?: string;\n badges?: ReactNode;\n}\n\nconst StyledSpan = styled(\"span\", {\n base: {\n display: \"flex\",\n gap: \"3xsmall\",\n },\n});\n\nexport const RelatedArticle = ({\n title,\n introduction,\n to,\n badges,\n linkInfo = \"\",\n target = \"\",\n}: RelatedArticleProps) => {\n return (\n <CardRoot data-embed-type=\"related-article\">\n <CardContent>\n {!!badges && <BadgesContainer>{badges}</BadgesContainer>}\n <CardHeading asChild consumeCss>\n <span>\n <SafeLink\n unstyled\n to={to}\n target={target}\n rel={linkInfo ? \"noopener noreferrer\" : undefined}\n css={linkOverlay.raw()}\n >\n <StyledSpan>\n {title}\n {target === \"_blank\" && <ExternalLinkLine />}\n </StyledSpan>\n </SafeLink>\n </span>\n </CardHeading>\n <Text dangerouslySetInnerHTML={{ __html: introduction }} />\n <Text color=\"text.subtle\" textStyle=\"label.small\">\n {linkInfo}\n </Text>\n </CardContent>\n </CardRoot>\n );\n};\n\nconst HeadingWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n width: \"100%\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n alignSelf: \"flex-start\",\n },\n});\n\nconst ArticlesWrapper = styled(\"div\", {\n base: {\n display: \"grid\",\n width: \"100%\",\n gridTemplateColumns: \"repeat(2, 1fr)\",\n gap: \"medium\",\n tabletDown: {\n gridTemplateColumns: \"1fr\",\n },\n },\n});\n\nconst StyledSection = styled(\"section\", {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"medium\",\n clear: \"both\",\n },\n});\n\nconst StyledButton = styled(Button, {\n base: {\n marginBlockStart: \"xsmall\",\n },\n});\n\ninterface Props extends ComponentPropsWithoutRef<\"section\"> {\n children?: ReactElement[];\n articleCount?: number;\n headingLevel?: HeadingLevel;\n headingButtons?: ReactNode;\n}\n\nexport const RelatedArticleList = ({\n children = [],\n articleCount,\n headingLevel: HeadingElement = \"h2\",\n headingButtons,\n ...rest\n}: Props) => {\n const [expanded, setExpanded] = useState(false);\n const { t } = useTranslation();\n const childCount = useMemo(() => articleCount ?? Children.count(children), [children, articleCount]);\n const childrenToShow = useMemo(\n () => (childCount > 2 && !expanded ? children?.slice(0, 2) : children),\n [childCount, children, expanded],\n );\n\n return (\n <StyledSection {...rest} data-embed-type=\"related-content-list\">\n <HeadingWrapper>\n <Heading asChild consumeCss textStyle=\"title.large\" fontWeight=\"bold\">\n <HeadingElement>{t(\"related.title\")}</HeadingElement>\n </Heading>\n {headingButtons}\n </HeadingWrapper>\n <ArticlesWrapper>{childrenToShow}</ArticlesWrapper>\n {childCount > 2 ? (\n <StyledButton variant=\"secondary\" onClick={() => setExpanded((p) => !p)}>\n {t(`related.show${expanded ? \"Less\" : \"More\"}`)}\n </StyledButton>\n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gBAAgB,SAAS,MAAM,SAAS,EAAE,CAAC,UAAU,aAAa,CAAC;CACpG,MAAM,iBAAiB,cACd,aAAa,KAAK,CAAC,WAAW,UAAU,MAAM,GAAG,EAAE,GAAG,UAC7D;EAAC;EAAY;EAAU;EAAS,CACjC;AAED,QACE,qBAAC;EAAc,GAAI;EAAM,mBAAgB;;GACvC,qBAAC,6BACC,oBAAC;IAAQ;IAAQ;IAAW,WAAU;IAAc,YAAW;cAC7D,oBAAC,4BAAgB,EAAE,gBAAgB,GAAkB;KAC7C,EACT,kBACc;GACjB,oBAAC,6BAAiB,iBAAiC;GAClD,aAAa,IACZ,oBAAC;IAAa,SAAQ;IAAY,eAAe,aAAa,MAAM,CAAC,EAAE;cACpE,EAAE,eAAe,WAAW,SAAS,SAAS;KAClC,GACb;;GACU"}
|
package/es/index.mjs
CHANGED
|
@@ -13,8 +13,6 @@ import { AudioPlayer } from "./AudioPlayer/AudioPlayer.mjs";
|
|
|
13
13
|
import { AudioEmbed } from "./Embed/AudioEmbed.mjs";
|
|
14
14
|
import { FootnoteEmbed } from "./Embed/FootnoteEmbed.mjs";
|
|
15
15
|
import { ContentLinkEmbed } from "./Embed/ContentLinkEmbed.mjs";
|
|
16
|
-
import { contentTypeMapping, contentTypes, resourceEmbedTypeMapping } from "./model/ContentType.mjs";
|
|
17
|
-
import { ContentTypeBadge, contentTypeToBadgeVariantMap } from "./ContentTypeBadge/ContentTypeBadge.mjs";
|
|
18
16
|
import { RelatedArticle, RelatedArticleList } from "./RelatedArticleList/RelatedArticleList.mjs";
|
|
19
17
|
import { RelatedContentEmbed } from "./Embed/RelatedContentEmbed.mjs";
|
|
20
18
|
import { ConceptInlineTriggerButton } from "./Embed/ConceptInlineTriggerButton.mjs";
|
|
@@ -36,6 +34,7 @@ import { FileListEmbed, FileListItem, FileListWrapper } from "./FileList/FileLis
|
|
|
36
34
|
import { File, FileListElement } from "./FileList/File.mjs";
|
|
37
35
|
import { PdfFile } from "./FileList/PdfFile.mjs";
|
|
38
36
|
import { FactBox } from "./FactBox/FactBox.mjs";
|
|
37
|
+
import { contentTypeMapping, contentTypes, resourceEmbedTypeMapping } from "./model/ContentType.mjs";
|
|
39
38
|
import { subjectCategories } from "./model/SubjectCategories.mjs";
|
|
40
39
|
import { subjectTypes } from "./model/SubjectTypes.mjs";
|
|
41
40
|
import { wordClass } from "./model/WordClass.mjs";
|
|
@@ -49,6 +48,7 @@ import { HomeBreadcrumb } from "./Breadcrumb/HomeBreadcrumb.mjs";
|
|
|
49
48
|
import { formatNestedMessages } from "./i18n/formatNestedMessages.mjs";
|
|
50
49
|
import { TagSelectorClearTrigger, TagSelectorControl, TagSelectorInput, TagSelectorInputBase, TagSelectorItemInput, TagSelectorLabel, TagSelectorRoot, TagSelectorTrigger } from "./TagSelector/TagSelector.mjs";
|
|
51
50
|
import { useAudioSearchTranslations, useComboboxTranslations, useDatePickerTranslations, useImageSearchTranslations, usePaginationTranslations, useTagSelectorTranslations, useTagsInputTranslations, useVideoSearchTranslations } from "./i18n/useComponentTranslations.mjs";
|
|
51
|
+
import { ContentTypeBadge, contentTypeToBadgeVariantMap } from "./ContentTypeBadge/ContentTypeBadge.mjs";
|
|
52
52
|
import { CopyParagraphButton } from "./CopyParagraphButton/CopyParagraphButton.mjs";
|
|
53
53
|
import { Pitch } from "./Pitch/Pitch.mjs";
|
|
54
54
|
import { KeyFigure } from "./KeyFigure/KeyFigure.mjs";
|
|
@@ -2,8 +2,7 @@ import { getLicenseByAbbreviation, isCreativeCommonsLicense } from "@ndla/licens
|
|
|
2
2
|
|
|
3
3
|
//#region src/utils/licenseAttributes.ts
|
|
4
4
|
const licenseAttributes = (license, lang, url) => {
|
|
5
|
-
|
|
6
|
-
return isCreativeCommonsLicense(licenseAbbr.rights) ? {
|
|
5
|
+
return isCreativeCommonsLicense(getLicenseByAbbreviation(license ? license : "", lang).rights) ? {
|
|
7
6
|
"xmlns:cc": "https://creativecommons.org/ns#",
|
|
8
7
|
"xmlns:dct": "http://purl.org/dc/terms/",
|
|
9
8
|
about: url ?? void 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"licenseAttributes.mjs","names":[],"sources":["../../src/utils/licenseAttributes.ts"],"sourcesContent":["/**\n * Copyright (c) 2024-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { getLicenseByAbbreviation, isCreativeCommonsLicense } from \"@ndla/licenses\";\n\nexport const licenseAttributes = (license: string | undefined, lang: string | undefined, url: string | undefined) => {\n const licenseAbbr = getLicenseByAbbreviation(license ? license : \"\", lang);\n\n const licenseProps = isCreativeCommonsLicense(licenseAbbr.rights)\n ? {\n \"xmlns:cc\": \"https://creativecommons.org/ns#\",\n \"xmlns:dct\": \"http://purl.org/dc/terms/\",\n about: url ?? undefined,\n }\n : {};\n\n return licenseProps;\n};\n"],"mappings":";;;AAUA,MAAa,qBAAqB,SAA6B,MAA0B,QAA4B;
|
|
1
|
+
{"version":3,"file":"licenseAttributes.mjs","names":[],"sources":["../../src/utils/licenseAttributes.ts"],"sourcesContent":["/**\n * Copyright (c) 2024-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { getLicenseByAbbreviation, isCreativeCommonsLicense } from \"@ndla/licenses\";\n\nexport const licenseAttributes = (license: string | undefined, lang: string | undefined, url: string | undefined) => {\n const licenseAbbr = getLicenseByAbbreviation(license ? license : \"\", lang);\n\n const licenseProps = isCreativeCommonsLicense(licenseAbbr.rights)\n ? {\n \"xmlns:cc\": \"https://creativecommons.org/ns#\",\n \"xmlns:dct\": \"http://purl.org/dc/terms/\",\n about: url ?? undefined,\n }\n : {};\n\n return licenseProps;\n};\n"],"mappings":";;;AAUA,MAAa,qBAAqB,SAA6B,MAA0B,QAA4B;AAWnH,QARqB,yBAFD,yBAAyB,UAAU,UAAU,IAAI,KAAK,CAEhB,OAAO,GAC7D;EACE,YAAY;EACZ,aAAa;EACb,OAAO,OAAO;EACf,GACD,EAAE"}
|
package/lib/Article/Article.d.ts
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { type ReactNode } from "react";
|
|
9
9
|
import type { StyledProps } from "@ndla/styled-system/types";
|
|
10
|
-
import { type ContentType } from "../ContentTypeBadge/ContentTypeBadge";
|
|
11
10
|
import type { Article as ArticleType } from "../types";
|
|
12
11
|
export declare const ArticleContent: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & import("@ark-ui/react").PolymorphicProps & StyledProps & import("react").RefAttributes<HTMLElement>>;
|
|
13
12
|
export declare const ArticleWrapper: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLElement> & import("react").HTMLAttributes<HTMLElement> & StyledProps, "ref"> & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -15,9 +14,8 @@ export declare const ArticleHGroup: import("@ndla/styled-system/types").StyledCo
|
|
|
15
14
|
export declare const ArticleHeader: import("@ndla/styled-system/types").StyledComponent<import("react").ForwardRefExoticComponent<import("react").ClassAttributes<HTMLElement> & import("react").HTMLAttributes<HTMLElement> & import("@ark-ui/react").PolymorphicProps>, {}>;
|
|
16
15
|
export declare const ArticleFooter: import("@ndla/styled-system/types").StyledComponent<import("react").ForwardRefExoticComponent<import("react").ClassAttributes<HTMLElement> & import("react").HTMLAttributes<HTMLElement> & import("@ark-ui/react").PolymorphicProps>, {}>;
|
|
17
16
|
interface ArticleTitleProps {
|
|
17
|
+
badges?: ReactNode;
|
|
18
18
|
heartButton?: ReactNode;
|
|
19
|
-
contentType?: ContentType;
|
|
20
|
-
contentTypeLabel?: ReactNode;
|
|
21
19
|
competenceGoals?: ReactNode;
|
|
22
20
|
id: string;
|
|
23
21
|
lang?: string;
|
|
@@ -25,18 +23,17 @@ interface ArticleTitleProps {
|
|
|
25
23
|
introduction?: ReactNode;
|
|
26
24
|
disclaimer?: ReactNode;
|
|
27
25
|
}
|
|
28
|
-
export declare const ArticleTitle: ({
|
|
26
|
+
export declare const ArticleTitle: ({ badges, heartButton, title, lang, id, introduction, competenceGoals, disclaimer, }: ArticleTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
29
27
|
interface Props {
|
|
28
|
+
badges?: ReactNode;
|
|
30
29
|
heartButton?: ReactNode;
|
|
31
30
|
article: ArticleType;
|
|
32
31
|
licenseBox?: ReactNode;
|
|
33
|
-
contentType?: ContentType;
|
|
34
|
-
contentTypeLabel?: ReactNode;
|
|
35
32
|
children?: ReactNode;
|
|
36
33
|
competenceGoals?: ReactNode;
|
|
37
34
|
id: string;
|
|
38
35
|
lang?: string;
|
|
39
36
|
disclaimer?: ReactNode;
|
|
40
37
|
}
|
|
41
|
-
export declare const Article: ({
|
|
38
|
+
export declare const Article: ({ badges, article, licenseBox, children, competenceGoals, id, heartButton, lang, disclaimer, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
42
39
|
export {};
|
package/lib/Article/Article.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
-
const
|
|
2
|
+
const require_BadgesContainer = require('./BadgesContainer.js');
|
|
3
3
|
const require_ArticleByline = require('./ArticleByline.js');
|
|
4
4
|
let react = require("react");
|
|
5
5
|
react = require_rolldown_runtime.__toESM(react);
|
|
@@ -79,12 +79,9 @@ const StyledWrapper = (0, __ndla_styled_system_jsx.styled)("div", { base: {
|
|
|
79
79
|
flexWrap: "wrap",
|
|
80
80
|
alignItems: "center"
|
|
81
81
|
} });
|
|
82
|
-
const ArticleTitle = ({
|
|
82
|
+
const ArticleTitle = ({ badges, heartButton, title, lang, id, introduction, competenceGoals, disclaimer }) => {
|
|
83
83
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ArticleHeader, { children: [
|
|
84
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ArticleHGroup, { children: [(!!
|
|
85
|
-
contentType,
|
|
86
|
-
children: contentTypeLabel
|
|
87
|
-
}), heartButton] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.Heading, {
|
|
84
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ArticleHGroup, { children: [(!!badges || !!heartButton) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(InfoWrapper, { children: [!!badges && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BadgesContainer.BadgesContainer, { children: badges }), heartButton] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.Heading, {
|
|
88
85
|
textStyle: "heading.medium",
|
|
89
86
|
id,
|
|
90
87
|
lang,
|
|
@@ -101,19 +98,18 @@ const ArticleTitle = ({ contentType, heartButton, title, lang, id, introduction,
|
|
|
101
98
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(StyledWrapper, { children: [competenceGoals, disclaimer] })
|
|
102
99
|
] });
|
|
103
100
|
};
|
|
104
|
-
const Article = ({
|
|
101
|
+
const Article = ({ badges, article, licenseBox, children, competenceGoals, id, heartButton, lang, disclaimer }) => {
|
|
105
102
|
const { title, introduction, published, content, footNotes, copyright } = article;
|
|
106
103
|
const authors = copyright?.creators.length || copyright?.rightsholders.length ? copyright.creators : copyright?.processors;
|
|
107
104
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ArticleWrapper, { children: [
|
|
108
105
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArticleTitle, {
|
|
109
106
|
id,
|
|
110
|
-
|
|
107
|
+
badges,
|
|
111
108
|
heartButton,
|
|
112
109
|
title,
|
|
113
110
|
introduction,
|
|
114
111
|
competenceGoals,
|
|
115
112
|
lang,
|
|
116
|
-
contentTypeLabel,
|
|
117
113
|
disclaimer
|
|
118
114
|
}),
|
|
119
115
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArticleContent, { children: content }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Article.js","names":["ark","
|
|
1
|
+
{"version":3,"file":"Article.js","names":["ark","BadgesContainer","Heading","Text","ArticleByline"],"sources":["../../src/Article/Article.tsx"],"sourcesContent":["/**\n * Copyright (c) 2016-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { type ComponentPropsWithRef, type ReactNode, forwardRef } from \"react\";\nimport { ark, type HTMLArkProps } from \"@ark-ui/react\";\nimport { Heading, Text } from \"@ndla/primitives\";\nimport { cx } from \"@ndla/styled-system/css\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport type { StyledProps } from \"@ndla/styled-system/types\";\nimport { ArticleByline } from \"./ArticleByline\";\nimport { BadgesContainer } from \"./BadgesContainer\";\nimport type { Article as ArticleType } from \"../types\";\n\nconst StyledArticleContent = styled(ark.section, {}, { baseComponent: true });\n\nexport const ArticleContent = forwardRef<HTMLElement, HTMLArkProps<\"div\"> & StyledProps>(\n ({ className, ...props }, ref) => (\n <StyledArticleContent className={cx(\"ndla-article\", className)} {...props} ref={ref} />\n ),\n);\n\nconst StyledArticleWrapper = styled(\n ark.article,\n {\n base: {\n background: \"background.default\",\n display: \"flex\",\n flexDirection: \"column\",\n color: \"text.default\",\n alignItems: \"center\",\n width: \"100%\",\n overflowWrap: \"break-word\",\n position: \"relative\",\n \"& mjx-stretchy-v > mjx-ext > mjx-c\": {\n transform: \"scaleY(100) translateY(0.075em)\",\n },\n _after: {\n content: \"\",\n display: \"table\",\n clear: \"both\",\n },\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleWrapper = forwardRef<HTMLElement, ComponentPropsWithRef<\"article\"> & StyledProps>((props, ref) => (\n <StyledArticleWrapper data-ndla-article=\"\" ref={ref} {...props} />\n));\n\nexport const ArticleHGroup = styled(\n ark.hgroup,\n {\n base: {\n display: \"flex\",\n width: \"100%\",\n flexDirection: \"column\",\n alignItems: \"flex-start\",\n \"& h1\": {\n overflowWrap: \"anywhere\",\n },\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleHeader = styled(\n ark.header,\n {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"medium\",\n alignItems: \"flex-start\",\n width: \"100%\",\n paddingBlockStart: \"xxlarge\",\n overflowWrap: \"anywhere\",\n },\n },\n { baseComponent: true },\n);\n\nexport const ArticleFooter = styled(\n ark.footer,\n {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"xxlarge\",\n width: \"100%\",\n \"& > :is(:last-child)\": {\n paddingBlockEnd: \"5xlarge\",\n },\n },\n },\n { baseComponent: true },\n);\n\nconst InfoWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"space-between\",\n gap: \"small\",\n width: \"100%\",\n minHeight: \"xxlarge\",\n },\n});\n\nconst StyledWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n gap: \"small\",\n flexWrap: \"wrap\",\n alignItems: \"center\",\n },\n});\n\ninterface ArticleTitleProps {\n badges?: ReactNode;\n heartButton?: ReactNode;\n competenceGoals?: ReactNode;\n id: string;\n lang?: string;\n title?: ReactNode;\n introduction?: ReactNode;\n disclaimer?: ReactNode;\n}\n\nexport const ArticleTitle = ({\n badges,\n heartButton,\n title,\n lang,\n id,\n introduction,\n competenceGoals,\n disclaimer,\n}: ArticleTitleProps) => {\n return (\n <ArticleHeader>\n <ArticleHGroup>\n {(!!badges || !!heartButton) && (\n <InfoWrapper>\n {!!badges && <BadgesContainer>{badges}</BadgesContainer>}\n {heartButton}\n </InfoWrapper>\n )}\n <Heading textStyle=\"heading.medium\" id={id} lang={lang} property=\"dct:title\">\n {title}\n </Heading>\n </ArticleHGroup>\n {!!introduction && (\n <Text lang={lang} textStyle=\"body.xlarge\" asChild consumeCss>\n <div>{introduction}</div>\n </Text>\n )}\n <StyledWrapper>\n {competenceGoals}\n {disclaimer}\n </StyledWrapper>\n </ArticleHeader>\n );\n};\n\ninterface Props {\n badges?: ReactNode;\n heartButton?: ReactNode;\n article: ArticleType;\n licenseBox?: ReactNode;\n children?: ReactNode;\n competenceGoals?: ReactNode;\n id: string;\n lang?: string;\n disclaimer?: ReactNode;\n}\n\nexport const Article = ({\n badges,\n article,\n licenseBox,\n children,\n competenceGoals,\n id,\n heartButton,\n lang,\n disclaimer,\n}: Props) => {\n const { title, introduction, published, content, footNotes, copyright } = article;\n\n const authors =\n copyright?.creators.length || copyright?.rightsholders.length ? copyright.creators : copyright?.processors;\n\n return (\n <ArticleWrapper>\n <ArticleTitle\n id={id}\n badges={badges}\n heartButton={heartButton}\n title={title}\n introduction={introduction}\n competenceGoals={competenceGoals}\n lang={lang}\n disclaimer={disclaimer}\n />\n <ArticleContent>{content}</ArticleContent>\n <ArticleFooter>\n <ArticleByline\n lang={lang}\n footnotes={footNotes}\n authors={authors}\n suppliers={copyright?.rightsholders}\n published={published}\n licenseBox={licenseBox}\n />\n {children}\n </ArticleFooter>\n </ArticleWrapper>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAkBA,MAAM,4DAA8BA,mBAAI,SAAS,EAAE,EAAE,EAAE,eAAe,MAAM,CAAC;AAE7E,MAAa,wCACV,EAAE,UAAW,GAAG,SAAS,QACxB,2CAAC;CAAqB,4CAAc,gBAAgB,UAAU;CAAE,GAAI;CAAY;EAAO,CAE1F;AAED,MAAM,4DACJA,mBAAI,SACJ,EACE,MAAM;CACJ,YAAY;CACZ,SAAS;CACT,eAAe;CACf,OAAO;CACP,YAAY;CACZ,OAAO;CACP,cAAc;CACd,UAAU;CACV,sCAAsC,EACpC,WAAW,mCACZ;CACD,QAAQ;EACN,SAAS;EACT,SAAS;EACT,OAAO;EACR;CACF,EACF,EACD,EAAE,eAAe,MAAM,CACxB;AAED,MAAa,wCAA0F,OAAO,QAC5G,2CAAC;CAAqB,qBAAkB;CAAQ;CAAK,GAAI;EAAS,CAClE;AAEF,MAAa,qDACXA,mBAAI,QACJ,EACE,MAAM;CACJ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,SAAS,UAAU,WAAW,WAAW;AAElG,QACE,4CAAC;EACC,2CAAC;GACK;GACI;GACK;GACN;GACO;GACG;GACX;GACM;IACZ;EACF,2CAAC,4BAAgB,UAAyB;EAC1C,4CAAC,4BACC,2CAACC;GACO;GACN,WAAW;GACF;GACT,WAAW,WAAW;GACX;GACC;IACZ,EACD,YACa;KACD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare const BadgesContainer: import("@ndla/styled-system/types").StyledComponent<"div", {}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
let __ndla_styled_system_jsx = require("@ndla/styled-system/jsx");
|
|
3
|
+
__ndla_styled_system_jsx = require_rolldown_runtime.__toESM(__ndla_styled_system_jsx);
|
|
4
|
+
|
|
5
|
+
//#region src/Article/BadgesContainer.tsx
|
|
6
|
+
const BadgesContainer = (0, __ndla_styled_system_jsx.styled)("div", { base: {
|
|
7
|
+
display: "flex",
|
|
8
|
+
flexDirection: "row",
|
|
9
|
+
alignItems: "flex-start",
|
|
10
|
+
flexWrap: "wrap",
|
|
11
|
+
gap: "xxsmall"
|
|
12
|
+
} });
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.BadgesContainer = BadgesContainer;
|
|
16
|
+
//# sourceMappingURL=BadgesContainer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BadgesContainer.js","names":[],"sources":["../../src/Article/BadgesContainer.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nexport const BadgesContainer = styled(\"div\", {\n base: {\n display: \"flex\",\n flexDirection: \"row\",\n alignItems: \"flex-start\",\n flexWrap: \"wrap\",\n gap: \"xxsmall\",\n },\n});\n"],"mappings":";;;;;AAUA,MAAa,uDAAyB,OAAO,EAC3C,MAAM;CACJ,SAAS;CACT,eAAe;CACf,YAAY;CACZ,UAAU;CACV,KAAK;CACN,EACF,CAAC"}
|
|
@@ -74,8 +74,7 @@ const StyledPopoverContent = (0, __ndla_styled_system_jsx.styled)(__ndla_primiti
|
|
|
74
74
|
const formatTime = (seconds) => {
|
|
75
75
|
const minutes = Math.floor(seconds / 60);
|
|
76
76
|
const currentSeconds = seconds % 60;
|
|
77
|
-
|
|
78
|
-
return `${minutes}:${formattedSeconds}`;
|
|
77
|
+
return `${minutes}:${currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds}`;
|
|
79
78
|
};
|
|
80
79
|
const speedValues = (0, __ark_ui_react.createListCollection)({ items: [
|
|
81
80
|
"0.5",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Controls.js","names":["IconButton","Text","Button","SelectRoot","SliderControl","PopoverContent","currentTime","Replay15Line","PauseLine","PlayFill","Forward15Line","SliderRoot","SliderLabel","SliderTrack","SliderRange","SliderThumb","SliderHiddenInput","FieldRoot","SelectLabel","SelectControl","SelectTrigger","SelectContent","SelectItem","SelectItemText","SelectItemIndicator","CheckLine","PopoverRoot","PopoverTrigger","VolumeUpFill"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nexport const Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime || 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration || 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </ControlsWrapper>\n </div>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAsCA,MAAM,uDAAyB,OAAO,EACpC,MAAM;CACJ,kBAAkB;CAClB,aAAa;CACb,oBAAoB;CACpB,SAAS;CACT,YAAY;CACZ,gBAAgB;CAChB,YAAY;CACZ,KAAK;CACL,cAAc;CACd,eAAe;CACf,gBAAgB;EACd,SAAS;EACT,cAAc;EACd,eAAe;EACf,qBAAqB;EACrB,mBAAmB;;;;EAIpB;CACD,gBAAgB,EACd,WAAW,WACZ;CACF,EACF,CAAC;AAEF,MAAM,kDAAoBA,8BAAY,EACpC,MAAM,EACJ,UAAU,QACX,EACF,CAAC;AAEF,MAAM,0DAA4BA,8BAAY,EAC5C,MAAM,EACJ,UAAU,YACX,EACF,CAAC;AAEF,MAAM,uDAAyBA,8BAAY,EACzC,MAAM,EACJ,UAAU,aACX,EACF,CAAC;AAEF,MAAM,uDAAyB,OAAO,EACpC,MAAM;CACJ,MAAM;CACN,SAAS;CACT,YAAY;CACZ,KAAK;CACL,UAAU;CACV,cAAc;CACd,YAAY,EACV,eAAe,UAChB;CACF,EACF,CAAC;AAEF,MAAM,kDAAoBC,wBAAM,EAC9B,MAAM;CACJ,UAAU;CACV,YAAY;CACZ,WAAW;CACZ,EACF,CAAC;AAEF,MAAM,oDAAsBD,8BAAY,EACtC,MAAM,EACJ,UAAU,UACX,EACF,CAAC;AAEF,MAAM,mDAAqBE,0BAAQ,EACjC,MAAM;CACJ,cAAc;CACd,eAAe;CACf,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,UAAU,EACR,MAAM,KACP;CACF,EACF,CAAC;AAEF,MAAM,wDAA0BC,8B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ACC,GACT;EACZ,4CAACC;GAAY,aAAa,EAAE,WAAW,OAAO;cAC5C,2CAACC;IAAe;cACd,2CAAC;KAAa,SAAQ;KAAW,cAAY,EAAE,8BAA8B;eAC3E,2CAACC,8BAAe;MACH;KACA,EACjB,2CAAC,kCACC,4CAACjB;IACC,aAAY;IACZ,OAAO,CAAC,YAAY;IACpB,KAAK;IACL,KAAK;IACL,cAAc,CAAC,IAAI;IACnB,MAAM;IACN,eAAe;eAEf,2CAACC;KAAY;eAAQ,EAAE,8BAA8B;MAAe,EACpE,4CAAC,kCACC,2CAACC,2CACC,2CAACC,kCAAc,GACH,EACd,2CAACC;KAAY,OAAO;eAClB,2CAACC,wCAAoB;MACT,IACM;KACX,GACQ;IACX;KACE,IACd"}
|
|
1
|
+
{"version":3,"file":"Controls.js","names":["IconButton","Text","Button","SelectRoot","SliderControl","PopoverContent","currentTime","Replay15Line","PauseLine","PlayFill","Forward15Line","SliderRoot","SliderLabel","SliderTrack","SliderRange","SliderThumb","SliderHiddenInput","FieldRoot","SelectLabel","SelectControl","SelectTrigger","SelectContent","SelectItem","SelectItemText","SelectItemIndicator","CheckLine","PopoverRoot","PopoverTrigger","VolumeUpFill"],"sources":["../../src/AudioPlayer/Controls.tsx"],"sourcesContent":["/**\n * Copyright (c) 2021-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useEffect, useRef, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { type SliderValueChangeDetails, createListCollection } from \"@ark-ui/react\";\nimport { Replay15Line, Forward15Line, PlayFill, PauseLine, VolumeUpFill, CheckLine } from \"@ndla/icons\";\nimport {\n Button,\n FieldRoot,\n IconButton,\n PopoverContent,\n PopoverRoot,\n PopoverTrigger,\n SelectContent,\n SelectControl,\n SelectItem,\n SelectItemIndicator,\n SelectItemText,\n SelectLabel,\n SelectRoot,\n SelectTrigger,\n SliderControl,\n SliderHiddenInput,\n SliderLabel,\n SliderRange,\n SliderRoot,\n SliderThumb,\n SliderTrack,\n Text,\n} from \"@ndla/primitives\";\nimport { styled } from \"@ndla/styled-system/jsx\";\n\nconst ControlsWrapper = styled(\"div\", {\n base: {\n borderBlockStart: \"1px solid\",\n borderColor: \"stroke.default\",\n borderBottomRadius: \"xsmall\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"background.default\",\n gap: \"xsmall\",\n paddingBlock: \"xsmall\",\n paddingInline: \"medium\",\n tabletWideDown: {\n display: \"grid\",\n paddingBlock: \"xsmall\",\n paddingInline: \"xsmall\",\n gridTemplateColumns: \"1fr repeat(5, auto) 1fr\",\n gridTemplateAreas: `\n \"track track track track track track track\"\n \". speed backwards play forwards volume .\"\n`,\n },\n mobileWideDown: {\n columnGap: \"3xsmall\",\n },\n },\n});\n\nconst PlayButton = styled(IconButton, {\n base: {\n gridArea: \"play\",\n },\n});\n\nconst Forward15SecButton = styled(IconButton, {\n base: {\n gridArea: \"forwards\",\n },\n});\n\nconst Back15SecButton = styled(IconButton, {\n base: {\n gridArea: \"backwards\",\n },\n});\n\nconst ProgressWrapper = styled(\"div\", {\n base: {\n flex: \"1\",\n display: \"flex\",\n alignItems: \"center\",\n gap: \"xxsmall\",\n gridArea: \"track\",\n paddingBlock: \"xsmall\",\n mobileDown: {\n paddingInline: \"xsmall\",\n },\n },\n});\n\nconst StyledText = styled(Text, {\n base: {\n minWidth: \"xxlarge\",\n flexShrink: \"0\",\n textAlign: \"center\",\n },\n});\n\nconst VolumeButton = styled(IconButton, {\n base: {\n gridArea: \"volume\",\n },\n});\n\nconst SpeedButton = styled(Button, {\n base: {\n paddingBlock: \"auto\",\n paddingInline: \"auto\",\n maxWidth: \"xxlarge\",\n maxHeight: \"xxlarge\",\n minWidth: \"xxlarge\",\n minHeight: \"xxlarge\",\n \"& span\": {\n flex: \"1\",\n },\n },\n});\n\nconst StyledSelectRoot = styled(SelectRoot<string>, {\n base: {\n gridArea: \"speed\",\n },\n});\n\nconst StyledSliderControl = styled(SliderControl, {\n base: {\n height: \"surface.3xsmall\",\n minWidth: \"small\",\n },\n});\n\nconst StyledPopoverContent = styled(PopoverContent, {\n base: {\n paddingInline: \"small\",\n },\n});\n\nconst formatTime = (seconds: number) => {\n const minutes = Math.floor(seconds / 60);\n const currentSeconds = seconds % 60;\n\n const formattedSeconds = currentSeconds < 10 ? `0${currentSeconds}` : currentSeconds;\n return `${minutes}:${formattedSeconds}`;\n};\n\nconst speedValues = createListCollection({ items: [\"0.5\", \"0.75\", \"1\", \"1.25\", \"1.5\", \"1.75\", \"2\"] });\n\ninterface Props {\n src: string;\n title: string;\n}\n\nexport const Controls = ({ src, title }: Props) => {\n const { t } = useTranslation();\n const [speedValue, setSpeedValue] = useState(1);\n const [volumeValue, setVolumeValue] = useState(100);\n const [currentTime, setCurrentTime] = useState(0);\n const [remainingTime, setRemainingTime] = useState(0);\n const [playing, setPlaying] = useState(false);\n const audioRef = useRef<HTMLAudioElement>(null);\n\n useEffect(() => {\n if (audioRef.current) {\n audioRef.current.playbackRate = speedValue;\n }\n }, [speedValue]);\n\n useEffect(() => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n const handleTimeUpdate = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleLoadedMetaData = () => {\n const { currentTime, duration } = audioElement;\n setCurrentTime(Math.round(currentTime));\n setRemainingTime(Math.round(duration - currentTime));\n };\n\n const handleTimeEnded = () => {\n setPlaying(false);\n };\n\n audioElement.addEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.addEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.addEventListener(\"ended\", handleTimeEnded);\n return () => {\n audioElement.removeEventListener(\"timeupdate\", handleTimeUpdate);\n audioElement.removeEventListener(\"loadedmetadata\", handleLoadedMetaData);\n audioElement.removeEventListener(\"ended\", handleTimeEnded);\n };\n }\n }, []);\n\n const togglePlay = () => {\n if (audioRef.current) {\n const audioElement = audioRef.current;\n if (!playing) {\n audioElement.play();\n } else {\n audioElement.pause();\n }\n setPlaying(!playing);\n }\n };\n\n const onSeekSeconds = (seconds: number) => {\n if (audioRef.current) {\n audioRef.current.currentTime += seconds;\n }\n };\n\n const handleSliderChange = (details: SliderValueChangeDetails) => {\n const newValue = details.value[0];\n if (audioRef.current && newValue != null && !isNaN(newValue)) {\n audioRef.current.currentTime = details.value[0];\n }\n };\n\n const handleVolumeSliderChange = (details: SliderValueChangeDetails) => {\n if (audioRef.current) {\n audioRef.current.volume = details.value[0] / 100;\n setVolumeValue(details.value[0]);\n }\n };\n\n return (\n <div>\n {/* TODO: We should tie this up to the textual description somehow */}\n {/* eslint-disable-next-line jsx-a11y/media-has-caption */}\n <audio ref={audioRef} src={src} title={title} preload=\"metadata\" />\n <ControlsWrapper>\n <Back15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.rewind15sec\")}\n aria-label={t(\"audio.controls.rewind15sec\")}\n onClick={() => onSeekSeconds(-15)}\n >\n <Replay15Line />\n </Back15SecButton>\n <PlayButton aria-label={t(playing ? t(\"audio.pause\") : t(\"audio.play\"))} variant=\"primary\" onClick={togglePlay}>\n {playing ? <PauseLine /> : <PlayFill />}\n </PlayButton>\n <Forward15SecButton\n variant=\"tertiary\"\n title={t(\"audio.controls.forward15sec\")}\n aria-label={t(\"audio.controls.forward15sec\")}\n onClick={() => onSeekSeconds(15)}\n >\n <Forward15Line />\n </Forward15SecButton>\n <ProgressWrapper>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>{formatTime(currentTime)}</div>\n </StyledText>\n <SliderRoot\n value={[audioRef.current?.currentTime || 0]}\n defaultValue={[0]}\n step={1}\n max={Math.round(audioRef.current?.duration || 0)}\n onValueChange={handleSliderChange}\n getAriaValueText={(value) =>\n t(\"audio.valueText\", {\n start: formatTime(Math.round(value.value)),\n end: formatTime(Math.round(audioRef.current?.duration ?? 0)),\n })\n }\n >\n <SliderLabel srOnly>{t(\"audio.progressBar\")}</SliderLabel>\n <SliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </SliderControl>\n </SliderRoot>\n <StyledText textStyle=\"label.medium\" asChild consumeCss>\n <div>-{formatTime(remainingTime)}</div>\n </StyledText>\n </ProgressWrapper>\n <FieldRoot>\n <StyledSelectRoot\n collection={speedValues}\n value={[speedValue.toString()]}\n onValueChange={(details) => setSpeedValue(parseFloat(details.value[0]))}\n positioning={{ placement: \"top\" }}\n >\n <SelectLabel srOnly>{t(\"audio.controls.selectSpeed\")}</SelectLabel>\n <SelectControl>\n <SelectTrigger asChild>\n <SpeedButton\n variant=\"tertiary\"\n title={t(\"audio.controls.selectSpeed\")}\n aria-label={t(\"audio.controls.selectSpeed\")}\n >\n <span>{`${speedValue}x`}</span>\n </SpeedButton>\n </SelectTrigger>\n </SelectControl>\n <SelectContent>\n {speedValues.items.map((speed) => (\n <SelectItem key={speed} item={speed}>\n <SelectItemText>{speed}x</SelectItemText>\n <SelectItemIndicator>\n <CheckLine />\n </SelectItemIndicator>\n </SelectItem>\n ))}\n </SelectContent>\n </StyledSelectRoot>\n </FieldRoot>\n <PopoverRoot positioning={{ placement: \"top\" }}>\n <PopoverTrigger asChild>\n <VolumeButton variant=\"tertiary\" aria-label={t(\"audio.controls.adjustVolume\")}>\n <VolumeUpFill />\n </VolumeButton>\n </PopoverTrigger>\n <StyledPopoverContent>\n <SliderRoot\n orientation=\"vertical\"\n value={[volumeValue]}\n min={0}\n max={100}\n defaultValue={[100]}\n step={1}\n onValueChange={handleVolumeSliderChange}\n >\n <SliderLabel srOnly>{t(\"audio.controls.adjustVolume\")}</SliderLabel>\n <StyledSliderControl>\n <SliderTrack>\n <SliderRange />\n </SliderTrack>\n <SliderThumb index={0}>\n <SliderHiddenInput />\n </SliderThumb>\n </StyledSliderControl>\n </SliderRoot>\n </StyledPopoverContent>\n </PopoverRoot>\n </Contro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Y;IACpB,KAAK;IACL,KAAK;IACL,cAAc,CAAC,IAAI;IACnB,MAAM;IACN,eAAe;eAEf,2CAACC;KAAY;eAAQ,EAAE,8BAA8B;MAAe,EACpE,4CAAC,kCACC,2CAACC,2CACC,2CAACC,kCAAc,GACH,EACd,2CAACC;KAAY,OAAO;eAClB,2CAACC,wCAAoB;MACT,IACM;KACX,GACQ;IACX;KACE,IACd"}
|
|
@@ -11,6 +11,7 @@ interface Props {
|
|
|
11
11
|
isOembed?: boolean;
|
|
12
12
|
subject?: string;
|
|
13
13
|
ndlaFrontendDomain?: string;
|
|
14
|
+
language?: string;
|
|
14
15
|
}
|
|
15
|
-
export declare const RelatedContentEmbed: ({ embed, isOembed, subject, ndlaFrontendDomain }: Props) => import("react/jsx-runtime").JSX.Element | null;
|
|
16
|
+
export declare const RelatedContentEmbed: ({ embed, isOembed, subject, ndlaFrontendDomain, language }: Props) => import("react/jsx-runtime").JSX.Element | null;
|
|
16
17
|
export {};
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
-
const require_ContentType = require('../model/ContentType.js');
|
|
3
2
|
const require_RelatedArticleList = require('../RelatedArticleList/RelatedArticleList.js');
|
|
3
|
+
let __ndla_primitives = require("@ndla/primitives");
|
|
4
|
+
__ndla_primitives = require_rolldown_runtime.__toESM(__ndla_primitives);
|
|
4
5
|
let react_i18next = require("react-i18next");
|
|
5
6
|
react_i18next = require_rolldown_runtime.__toESM(react_i18next);
|
|
6
7
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
8
|
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
8
9
|
|
|
9
10
|
//#region src/Embed/RelatedContentEmbed.tsx
|
|
10
|
-
const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }) => {
|
|
11
|
+
const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain, language }) => {
|
|
11
12
|
const { t } = (0, react_i18next.useTranslation)();
|
|
12
13
|
if (embed.status === "error") return null;
|
|
13
14
|
const { data, embedData } = embed;
|
|
14
15
|
if (embedData.articleId && data) {
|
|
15
|
-
const
|
|
16
|
-
const type = typeId ? require_ContentType.contentTypeMapping[typeId] : void 0;
|
|
16
|
+
const badges = data.resource?.resourceTypes?.map((rt) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.Badge, { children: rt.translations.find((t$1) => t$1.language === language)?.name ?? rt.name }, rt.id));
|
|
17
17
|
const url = (data.resource?.contexts.find((c) => c.rootId === subject))?.url ?? data.resource?.url ?? `/article/${embedData.articleId}`;
|
|
18
18
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_RelatedArticleList.RelatedArticle, {
|
|
19
19
|
title: data.article.title?.title ?? "",
|
|
20
20
|
introduction: data.article.metaDescription?.metaDescription ?? "",
|
|
21
21
|
target: isOembed ? "_blank" : void 0,
|
|
22
22
|
to: `${ndlaFrontendDomain ?? ""}${url ?? ""}`,
|
|
23
|
-
|
|
23
|
+
badges
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
if (typeof embedData.url === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_RelatedArticleList.RelatedArticle, {
|
|
@@ -28,7 +28,7 @@ const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }) =
|
|
|
28
28
|
introduction: "",
|
|
29
29
|
to: embedData.url,
|
|
30
30
|
target: "_blank",
|
|
31
|
-
|
|
31
|
+
badges: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.Badge, { children: t("contentTypes.external") }),
|
|
32
32
|
linkInfo: `${t("related.linkInfo")} ${embedData.urlDomain}`
|
|
33
33
|
});
|
|
34
34
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelatedContentEmbed.js","names":["
|
|
1
|
+
{"version":3,"file":"RelatedContentEmbed.js","names":["Badge","t","RelatedArticle"],"sources":["../../src/Embed/RelatedContentEmbed.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { useTranslation } from \"react-i18next\";\nimport { Badge } from \"@ndla/primitives\";\nimport type { RelatedContentMetaData } from \"@ndla/types-embed\";\nimport { RelatedArticle } from \"../RelatedArticleList/RelatedArticleList\";\n\ninterface Props {\n embed: RelatedContentMetaData;\n isOembed?: boolean;\n subject?: string;\n ndlaFrontendDomain?: string;\n language?: string;\n}\n\nexport const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain, language }: Props) => {\n const { t } = useTranslation();\n if (embed.status === \"error\") {\n return null;\n }\n\n const { data, embedData } = embed;\n\n if (embedData.articleId && data) {\n const badges = data.resource?.resourceTypes?.map((rt) => (\n <Badge key={rt.id}>{rt.translations.find((t) => t.language === language)?.name ?? rt.name}</Badge>\n ));\n const context = data.resource?.contexts.find((c) => c.rootId === subject);\n const url = context?.url ?? data.resource?.url ?? `/article/${embedData.articleId}`;\n return (\n <RelatedArticle\n title={data.article.title?.title ?? \"\"}\n introduction={data.article.metaDescription?.metaDescription ?? \"\"}\n target={isOembed ? \"_blank\" : undefined}\n to={`${ndlaFrontendDomain ?? \"\"}${url ?? \"\"}`}\n badges={badges}\n />\n );\n }\n if (typeof embedData.url === \"string\") {\n return (\n <RelatedArticle\n title={embedData.title ?? \"\"}\n introduction=\"\"\n to={embedData.url}\n target=\"_blank\"\n badges={<Badge>{t(\"contentTypes.external\")}</Badge>}\n linkInfo={`${t(\"related.linkInfo\")} ${embedData.urlDomain}`}\n />\n );\n }\n return null;\n};\n"],"mappings":";;;;;;;;;;AAqBA,MAAa,uBAAuB,EAAE,OAAO,UAAU,SAAS,oBAAoB,eAAsB;CACxG,MAAM,EAAE,yCAAsB;AAC9B,KAAI,MAAM,WAAW,QACnB,QAAO;CAGT,MAAM,EAAE,MAAM,cAAc;AAE5B,KAAI,UAAU,aAAa,MAAM;EAC/B,MAAM,SAAS,KAAK,UAAU,eAAe,KAAK,OAChD,2CAACA,qCAAmB,GAAG,aAAa,MAAM,QAAMC,IAAE,aAAa,SAAS,EAAE,QAAQ,GAAG,QAAzE,GAAG,GAAmF,CAClG;EAEF,MAAM,OADU,KAAK,UAAU,SAAS,MAAM,MAAM,EAAE,WAAW,QAAQ,GACpD,OAAO,KAAK,UAAU,OAAO,YAAY,UAAU;AACxE,SACE,2CAACC;GACC,OAAO,KAAK,QAAQ,OAAO,SAAS;GACpC,cAAc,KAAK,QAAQ,iBAAiB,mBAAmB;GAC/D,QAAQ,WAAW,WAAW;GAC9B,IAAI,GAAG,sBAAsB,KAAK,OAAO;GACjC;IACR;;AAGN,KAAI,OAAO,UAAU,QAAQ,SAC3B,QACE,2CAACA;EACC,OAAO,UAAU,SAAS;EAC1B,cAAa;EACb,IAAI,UAAU;EACd,QAAO;EACP,QAAQ,2CAACF,qCAAO,EAAE,wBAAwB,GAAS;EACnD,UAAU,GAAG,EAAE,mBAAmB,CAAC,GAAG,UAAU;GAChD;AAGN,QAAO"}
|
|
@@ -13,9 +13,9 @@ interface RelatedArticleProps {
|
|
|
13
13
|
to: string;
|
|
14
14
|
linkInfo?: string;
|
|
15
15
|
target?: string;
|
|
16
|
-
|
|
16
|
+
badges?: ReactNode;
|
|
17
17
|
}
|
|
18
|
-
export declare const RelatedArticle: ({ title, introduction, to, linkInfo, target,
|
|
18
|
+
export declare const RelatedArticle: ({ title, introduction, to, badges, linkInfo, target, }: RelatedArticleProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
19
|
interface Props extends ComponentPropsWithoutRef<"section"> {
|
|
20
20
|
children?: ReactElement[];
|
|
21
21
|
articleCount?: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
-
const
|
|
3
|
-
const require_ContentTypeBadge = require('../ContentTypeBadge/ContentTypeBadge.js');
|
|
2
|
+
const require_BadgesContainer = require('../Article/BadgesContainer.js');
|
|
4
3
|
let react = require("react");
|
|
5
4
|
react = require_rolldown_runtime.__toESM(react);
|
|
6
5
|
let __ndla_primitives = require("@ndla/primitives");
|
|
@@ -23,11 +22,11 @@ const StyledSpan = (0, __ndla_styled_system_jsx.styled)("span", { base: {
|
|
|
23
22
|
display: "flex",
|
|
24
23
|
gap: "3xsmall"
|
|
25
24
|
} });
|
|
26
|
-
const RelatedArticle = ({ title, introduction, to, linkInfo = "", target = ""
|
|
25
|
+
const RelatedArticle = ({ title, introduction, to, badges, linkInfo = "", target = "" }) => {
|
|
27
26
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.CardRoot, {
|
|
28
27
|
"data-embed-type": "related-article",
|
|
29
28
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__ndla_primitives.CardContent, { children: [
|
|
30
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
29
|
+
!!badges && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_BadgesContainer.BadgesContainer, { children: badges }),
|
|
31
30
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__ndla_primitives.CardHeading, {
|
|
32
31
|
asChild: true,
|
|
33
32
|
consumeCss: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelatedArticleList.js","names":["
|
|
1
|
+
{"version":3,"file":"RelatedArticleList.js","names":["CardRoot","CardContent","BadgesContainer","CardHeading","SafeLink","linkOverlay","ExternalLinkLine","Text","Button","Children","Heading"],"sources":["../../src/RelatedArticleList/RelatedArticleList.tsx"],"sourcesContent":["/**\n * Copyright (c) 2023-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { Children, type ComponentPropsWithoutRef, type ReactElement, type ReactNode, useMemo, useState } from \"react\";\nimport { useTranslation } from \"react-i18next\";\nimport { ExternalLinkLine } from \"@ndla/icons\";\nimport { CardContent, CardHeading, CardRoot, Text, Heading, Button } from \"@ndla/primitives\";\nimport { SafeLink } from \"@ndla/safelink\";\nimport { styled } from \"@ndla/styled-system/jsx\";\nimport { linkOverlay } from \"@ndla/styled-system/patterns\";\nimport { BadgesContainer } from \"../Article/BadgesContainer\";\nimport type { HeadingLevel } from \"../types\";\n\ninterface RelatedArticleProps {\n title: string;\n introduction: string;\n to: string;\n linkInfo?: string;\n target?: string;\n badges?: ReactNode;\n}\n\nconst StyledSpan = styled(\"span\", {\n base: {\n display: \"flex\",\n gap: \"3xsmall\",\n },\n});\n\nexport const RelatedArticle = ({\n title,\n introduction,\n to,\n badges,\n linkInfo = \"\",\n target = \"\",\n}: RelatedArticleProps) => {\n return (\n <CardRoot data-embed-type=\"related-article\">\n <CardContent>\n {!!badges && <BadgesContainer>{badges}</BadgesContainer>}\n <CardHeading asChild consumeCss>\n <span>\n <SafeLink\n unstyled\n to={to}\n target={target}\n rel={linkInfo ? \"noopener noreferrer\" : undefined}\n css={linkOverlay.raw()}\n >\n <StyledSpan>\n {title}\n {target === \"_blank\" && <ExternalLinkLine />}\n </StyledSpan>\n </SafeLink>\n </span>\n </CardHeading>\n <Text dangerouslySetInnerHTML={{ __html: introduction }} />\n <Text color=\"text.subtle\" textStyle=\"label.small\">\n {linkInfo}\n </Text>\n </CardContent>\n </CardRoot>\n );\n};\n\nconst HeadingWrapper = styled(\"div\", {\n base: {\n display: \"flex\",\n width: \"100%\",\n justifyContent: \"space-between\",\n alignItems: \"center\",\n alignSelf: \"flex-start\",\n },\n});\n\nconst ArticlesWrapper = styled(\"div\", {\n base: {\n display: \"grid\",\n width: \"100%\",\n gridTemplateColumns: \"repeat(2, 1fr)\",\n gap: \"medium\",\n tabletDown: {\n gridTemplateColumns: \"1fr\",\n },\n },\n});\n\nconst StyledSection = styled(\"section\", {\n base: {\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"medium\",\n clear: \"both\",\n },\n});\n\nconst StyledButton = styled(Button, {\n base: {\n marginBlockStart: \"xsmall\",\n },\n});\n\ninterface Props extends ComponentPropsWithoutRef<\"section\"> {\n children?: ReactElement[];\n articleCount?: number;\n headingLevel?: HeadingLevel;\n headingButtons?: ReactNode;\n}\n\nexport const RelatedArticleList = ({\n children = [],\n articleCount,\n headingLevel: HeadingElement = \"h2\",\n headingButtons,\n ...rest\n}: Props) => {\n const [expanded, setExpanded] = useState(false);\n const { t } = useTranslation();\n const childCount = useMemo(() => articleCount ?? Children.count(children), [children, articleCount]);\n const childrenToShow = useMemo(\n () => (childCount > 2 && !expanded ? children?.slice(0, 2) : children),\n [childCount, children, expanded],\n );\n\n return (\n <StyledSection {...rest} data-embed-type=\"related-content-list\">\n <HeadingWrapper>\n <Heading asChild consumeCss textStyle=\"title.large\" fontWeight=\"bold\">\n <HeadingElement>{t(\"related.title\")}</HeadingElement>\n </Heading>\n {headingButtons}\n </HeadingWrapper>\n <ArticlesWrapper>{childrenToShow}</ArticlesWrapper>\n {childCount > 2 ? (\n <StyledButton variant=\"secondary\" onClick={() => setExpanded((p) => !p)}>\n {t(`related.show${expanded ? \"Less\" : \"More\"}`)}\n </StyledButton>\n ) : null}\n </StyledSection>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,MAAM,kDAAoB,QAAQ,EAChC,MAAM;CACJ,SAAS;CACT,KAAK;CACN,EACF,CAAC;AAEF,MAAa,kBAAkB,EAC7B,OACA,cACA,IACA,QACA,WAAW,IACX,SAAS,SACgB;AACzB,QACE,2CAACA;EAAS,mBAAgB;YACxB,4CAACC;GACE,CAAC,CAAC,UAAU,2CAACC,qDAAiB,SAAyB;GACxD,2CAACC;IAAY;IAAQ;cACnB,2CAAC,oBACC,2CAACC;KACC;KACI;KACI;KACR,KAAK,WAAW,wBAAwB;KACxC,KAAKC,0CAAY,KAAK;eAEtB,4CAAC,yBACE,OACA,WAAW,YAAY,2CAACC,kCAAmB,IACjC;MACJ,GACN;KACK;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ANGED
|
@@ -13,8 +13,6 @@ const require_AudioPlayer = require('./AudioPlayer/AudioPlayer.js');
|
|
|
13
13
|
const require_AudioEmbed = require('./Embed/AudioEmbed.js');
|
|
14
14
|
const require_FootnoteEmbed = require('./Embed/FootnoteEmbed.js');
|
|
15
15
|
const require_ContentLinkEmbed = require('./Embed/ContentLinkEmbed.js');
|
|
16
|
-
const require_ContentType = require('./model/ContentType.js');
|
|
17
|
-
const require_ContentTypeBadge = require('./ContentTypeBadge/ContentTypeBadge.js');
|
|
18
16
|
const require_RelatedArticleList = require('./RelatedArticleList/RelatedArticleList.js');
|
|
19
17
|
const require_RelatedContentEmbed = require('./Embed/RelatedContentEmbed.js');
|
|
20
18
|
const require_ConceptInlineTriggerButton = require('./Embed/ConceptInlineTriggerButton.js');
|
|
@@ -36,6 +34,7 @@ const require_FileList = require('./FileList/FileList.js');
|
|
|
36
34
|
const require_File = require('./FileList/File.js');
|
|
37
35
|
const require_PdfFile = require('./FileList/PdfFile.js');
|
|
38
36
|
const require_FactBox = require('./FactBox/FactBox.js');
|
|
37
|
+
const require_ContentType = require('./model/ContentType.js');
|
|
39
38
|
const require_SubjectCategories = require('./model/SubjectCategories.js');
|
|
40
39
|
const require_SubjectTypes = require('./model/SubjectTypes.js');
|
|
41
40
|
const require_WordClass = require('./model/WordClass.js');
|
|
@@ -49,6 +48,7 @@ const require_HomeBreadcrumb = require('./Breadcrumb/HomeBreadcrumb.js');
|
|
|
49
48
|
const require_formatNestedMessages = require('./i18n/formatNestedMessages.js');
|
|
50
49
|
const require_TagSelector = require('./TagSelector/TagSelector.js');
|
|
51
50
|
const require_useComponentTranslations = require('./i18n/useComponentTranslations.js');
|
|
51
|
+
const require_ContentTypeBadge = require('./ContentTypeBadge/ContentTypeBadge.js');
|
|
52
52
|
const require_CopyParagraphButton = require('./CopyParagraphButton/CopyParagraphButton.js');
|
|
53
53
|
const require_Pitch = require('./Pitch/Pitch.js');
|
|
54
54
|
const require_KeyFigure = require('./KeyFigure/KeyFigure.js');
|
|
@@ -4,8 +4,7 @@ __ndla_licenses = require_rolldown_runtime.__toESM(__ndla_licenses);
|
|
|
4
4
|
|
|
5
5
|
//#region src/utils/licenseAttributes.ts
|
|
6
6
|
const licenseAttributes = (license, lang, url) => {
|
|
7
|
-
|
|
8
|
-
return (0, __ndla_licenses.isCreativeCommonsLicense)(licenseAbbr.rights) ? {
|
|
7
|
+
return (0, __ndla_licenses.isCreativeCommonsLicense)((0, __ndla_licenses.getLicenseByAbbreviation)(license ? license : "", lang).rights) ? {
|
|
9
8
|
"xmlns:cc": "https://creativecommons.org/ns#",
|
|
10
9
|
"xmlns:dct": "http://purl.org/dc/terms/",
|
|
11
10
|
about: url ?? void 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"licenseAttributes.js","names":[],"sources":["../../src/utils/licenseAttributes.ts"],"sourcesContent":["/**\n * Copyright (c) 2024-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { getLicenseByAbbreviation, isCreativeCommonsLicense } from \"@ndla/licenses\";\n\nexport const licenseAttributes = (license: string | undefined, lang: string | undefined, url: string | undefined) => {\n const licenseAbbr = getLicenseByAbbreviation(license ? license : \"\", lang);\n\n const licenseProps = isCreativeCommonsLicense(licenseAbbr.rights)\n ? {\n \"xmlns:cc\": \"https://creativecommons.org/ns#\",\n \"xmlns:dct\": \"http://purl.org/dc/terms/\",\n about: url ?? undefined,\n }\n : {};\n\n return licenseProps;\n};\n"],"mappings":";;;;;AAUA,MAAa,qBAAqB,SAA6B,MAA0B,QAA4B;
|
|
1
|
+
{"version":3,"file":"licenseAttributes.js","names":[],"sources":["../../src/utils/licenseAttributes.ts"],"sourcesContent":["/**\n * Copyright (c) 2024-present, NDLA.\n *\n * This source code is licensed under the GPLv3 license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport { getLicenseByAbbreviation, isCreativeCommonsLicense } from \"@ndla/licenses\";\n\nexport const licenseAttributes = (license: string | undefined, lang: string | undefined, url: string | undefined) => {\n const licenseAbbr = getLicenseByAbbreviation(license ? license : \"\", lang);\n\n const licenseProps = isCreativeCommonsLicense(licenseAbbr.rights)\n ? {\n \"xmlns:cc\": \"https://creativecommons.org/ns#\",\n \"xmlns:dct\": \"http://purl.org/dc/terms/\",\n about: url ?? undefined,\n }\n : {};\n\n return licenseProps;\n};\n"],"mappings":";;;;;AAUA,MAAa,qBAAqB,SAA6B,MAA0B,QAA4B;AAWnH,oGAV6C,UAAU,UAAU,IAAI,KAAK,CAEhB,OAAO,GAC7D;EACE,YAAY;EACZ,aAAa;EACb,OAAO,OAAO;EACf,GACD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "56.0.
|
|
4
|
+
"version": "56.0.151-alpha.0",
|
|
5
5
|
"description": "UI component library for NDLA",
|
|
6
6
|
"license": "GPL-3.0",
|
|
7
7
|
"exports": {
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "d929f9ec2e7ebd56cbb54609beb562562add8a5b"
|
|
66
66
|
}
|
package/src/Article/Article.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import { cx } from "@ndla/styled-system/css";
|
|
|
13
13
|
import { styled } from "@ndla/styled-system/jsx";
|
|
14
14
|
import type { StyledProps } from "@ndla/styled-system/types";
|
|
15
15
|
import { ArticleByline } from "./ArticleByline";
|
|
16
|
-
import {
|
|
16
|
+
import { BadgesContainer } from "./BadgesContainer";
|
|
17
17
|
import type { Article as ArticleType } from "../types";
|
|
18
18
|
|
|
19
19
|
const StyledArticleContent = styled(ark.section, {}, { baseComponent: true });
|
|
@@ -122,9 +122,8 @@ const StyledWrapper = styled("div", {
|
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
interface ArticleTitleProps {
|
|
125
|
+
badges?: ReactNode;
|
|
125
126
|
heartButton?: ReactNode;
|
|
126
|
-
contentType?: ContentType;
|
|
127
|
-
contentTypeLabel?: ReactNode;
|
|
128
127
|
competenceGoals?: ReactNode;
|
|
129
128
|
id: string;
|
|
130
129
|
lang?: string;
|
|
@@ -134,22 +133,21 @@ interface ArticleTitleProps {
|
|
|
134
133
|
}
|
|
135
134
|
|
|
136
135
|
export const ArticleTitle = ({
|
|
137
|
-
|
|
136
|
+
badges,
|
|
138
137
|
heartButton,
|
|
139
138
|
title,
|
|
140
139
|
lang,
|
|
141
140
|
id,
|
|
142
141
|
introduction,
|
|
143
|
-
contentTypeLabel,
|
|
144
142
|
competenceGoals,
|
|
145
143
|
disclaimer,
|
|
146
144
|
}: ArticleTitleProps) => {
|
|
147
145
|
return (
|
|
148
146
|
<ArticleHeader>
|
|
149
147
|
<ArticleHGroup>
|
|
150
|
-
{(!!
|
|
148
|
+
{(!!badges || !!heartButton) && (
|
|
151
149
|
<InfoWrapper>
|
|
152
|
-
{!!
|
|
150
|
+
{!!badges && <BadgesContainer>{badges}</BadgesContainer>}
|
|
153
151
|
{heartButton}
|
|
154
152
|
</InfoWrapper>
|
|
155
153
|
)}
|
|
@@ -171,11 +169,10 @@ export const ArticleTitle = ({
|
|
|
171
169
|
};
|
|
172
170
|
|
|
173
171
|
interface Props {
|
|
172
|
+
badges?: ReactNode;
|
|
174
173
|
heartButton?: ReactNode;
|
|
175
174
|
article: ArticleType;
|
|
176
175
|
licenseBox?: ReactNode;
|
|
177
|
-
contentType?: ContentType;
|
|
178
|
-
contentTypeLabel?: ReactNode;
|
|
179
176
|
children?: ReactNode;
|
|
180
177
|
competenceGoals?: ReactNode;
|
|
181
178
|
id: string;
|
|
@@ -184,12 +181,11 @@ interface Props {
|
|
|
184
181
|
}
|
|
185
182
|
|
|
186
183
|
export const Article = ({
|
|
184
|
+
badges,
|
|
187
185
|
article,
|
|
188
|
-
contentType,
|
|
189
186
|
licenseBox,
|
|
190
187
|
children,
|
|
191
188
|
competenceGoals,
|
|
192
|
-
contentTypeLabel,
|
|
193
189
|
id,
|
|
194
190
|
heartButton,
|
|
195
191
|
lang,
|
|
@@ -204,13 +200,12 @@ export const Article = ({
|
|
|
204
200
|
<ArticleWrapper>
|
|
205
201
|
<ArticleTitle
|
|
206
202
|
id={id}
|
|
207
|
-
|
|
203
|
+
badges={badges}
|
|
208
204
|
heartButton={heartButton}
|
|
209
205
|
title={title}
|
|
210
206
|
introduction={introduction}
|
|
211
207
|
competenceGoals={competenceGoals}
|
|
212
208
|
lang={lang}
|
|
213
|
-
contentTypeLabel={contentTypeLabel}
|
|
214
209
|
disclaimer={disclaimer}
|
|
215
210
|
/>
|
|
216
211
|
<ArticleContent>{content}</ArticleContent>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { styled } from "@ndla/styled-system/jsx";
|
|
10
|
+
|
|
11
|
+
export const BadgesContainer = styled("div", {
|
|
12
|
+
base: {
|
|
13
|
+
display: "flex",
|
|
14
|
+
flexDirection: "row",
|
|
15
|
+
alignItems: "flex-start",
|
|
16
|
+
flexWrap: "wrap",
|
|
17
|
+
gap: "xxsmall",
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { useTranslation } from "react-i18next";
|
|
10
|
+
import { Badge } from "@ndla/primitives";
|
|
10
11
|
import type { RelatedContentMetaData } from "@ndla/types-embed";
|
|
11
|
-
import { contentTypeMapping } from "../model/ContentType";
|
|
12
12
|
import { RelatedArticle } from "../RelatedArticleList/RelatedArticleList";
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
@@ -16,9 +16,10 @@ interface Props {
|
|
|
16
16
|
isOembed?: boolean;
|
|
17
17
|
subject?: string;
|
|
18
18
|
ndlaFrontendDomain?: string;
|
|
19
|
+
language?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }: Props) => {
|
|
22
|
+
export const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain, language }: Props) => {
|
|
22
23
|
const { t } = useTranslation();
|
|
23
24
|
if (embed.status === "error") {
|
|
24
25
|
return null;
|
|
@@ -27,8 +28,9 @@ export const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDoma
|
|
|
27
28
|
const { data, embedData } = embed;
|
|
28
29
|
|
|
29
30
|
if (embedData.articleId && data) {
|
|
30
|
-
const
|
|
31
|
-
|
|
31
|
+
const badges = data.resource?.resourceTypes?.map((rt) => (
|
|
32
|
+
<Badge key={rt.id}>{rt.translations.find((t) => t.language === language)?.name ?? rt.name}</Badge>
|
|
33
|
+
));
|
|
32
34
|
const context = data.resource?.contexts.find((c) => c.rootId === subject);
|
|
33
35
|
const url = context?.url ?? data.resource?.url ?? `/article/${embedData.articleId}`;
|
|
34
36
|
return (
|
|
@@ -37,7 +39,7 @@ export const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDoma
|
|
|
37
39
|
introduction={data.article.metaDescription?.metaDescription ?? ""}
|
|
38
40
|
target={isOembed ? "_blank" : undefined}
|
|
39
41
|
to={`${ndlaFrontendDomain ?? ""}${url ?? ""}`}
|
|
40
|
-
|
|
42
|
+
badges={badges}
|
|
41
43
|
/>
|
|
42
44
|
);
|
|
43
45
|
}
|
|
@@ -48,7 +50,7 @@ export const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDoma
|
|
|
48
50
|
introduction=""
|
|
49
51
|
to={embedData.url}
|
|
50
52
|
target="_blank"
|
|
51
|
-
|
|
53
|
+
badges={<Badge>{t("contentTypes.external")}</Badge>}
|
|
52
54
|
linkInfo={`${t("related.linkInfo")} ${embedData.urlDomain}`}
|
|
53
55
|
/>
|
|
54
56
|
);
|
|
@@ -13,8 +13,7 @@ import { CardContent, CardHeading, CardRoot, Text, Heading, Button } from "@ndla
|
|
|
13
13
|
import { SafeLink } from "@ndla/safelink";
|
|
14
14
|
import { styled } from "@ndla/styled-system/jsx";
|
|
15
15
|
import { linkOverlay } from "@ndla/styled-system/patterns";
|
|
16
|
-
import {
|
|
17
|
-
import { contentTypes } from "../model/ContentType";
|
|
16
|
+
import { BadgesContainer } from "../Article/BadgesContainer";
|
|
18
17
|
import type { HeadingLevel } from "../types";
|
|
19
18
|
|
|
20
19
|
interface RelatedArticleProps {
|
|
@@ -23,7 +22,7 @@ interface RelatedArticleProps {
|
|
|
23
22
|
to: string;
|
|
24
23
|
linkInfo?: string;
|
|
25
24
|
target?: string;
|
|
26
|
-
|
|
25
|
+
badges?: ReactNode;
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
const StyledSpan = styled("span", {
|
|
@@ -37,14 +36,14 @@ export const RelatedArticle = ({
|
|
|
37
36
|
title,
|
|
38
37
|
introduction,
|
|
39
38
|
to,
|
|
39
|
+
badges,
|
|
40
40
|
linkInfo = "",
|
|
41
41
|
target = "",
|
|
42
|
-
type = contentTypes.SUBJECT_MATERIAL,
|
|
43
42
|
}: RelatedArticleProps) => {
|
|
44
43
|
return (
|
|
45
44
|
<CardRoot data-embed-type="related-article">
|
|
46
45
|
<CardContent>
|
|
47
|
-
<
|
|
46
|
+
{!!badges && <BadgesContainer>{badges}</BadgesContainer>}
|
|
48
47
|
<CardHeading asChild consumeCss>
|
|
49
48
|
<span>
|
|
50
49
|
<SafeLink
|
package/src/index.ts
CHANGED
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
// Ignore typescript implicit any warning and export all javascript components
|
|
10
|
-
// Move components to this file when they are migrated to typescript
|
|
11
|
-
|
|
12
9
|
export { Concept } from "./Concept/Concept";
|
|
13
10
|
|
|
14
11
|
export { ImageEmbed, getCrop, getFocalPoint } from "./Embed/ImageEmbed";
|