@ndla/ui 55.0.12-alpha.0 → 55.0.13-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.
Files changed (192) hide show
  1. package/dist/all-aout.js +0 -0
  2. package/dist/all.css +1 -0
  3. package/dist/panda.buildinfo.json +170 -0
  4. package/dist/styles.css +686 -0
  5. package/es/Article/Article.js +3 -4
  6. package/es/Article/ArticleByline.js +9 -9
  7. package/es/Article/ArticleFootNotes.js +4 -4
  8. package/es/AudioPlayer/AudioPlayer.js +142 -163
  9. package/es/AudioPlayer/Controls.js +187 -203
  10. package/es/AudioPlayer/SpeechControl.js +13 -11
  11. package/es/BlogPost/BlogPost.js +85 -23
  12. package/es/CampaignBlock/CampaignBlock.js +3 -4
  13. package/es/CodeBlock/CodeBlock.js +88 -96
  14. package/es/ContactBlock/ContactBlock.js +54 -40
  15. package/es/ContentLoader/index.js +7 -7
  16. package/es/CopyParagraphButton/CopyParagraphButton.js +4 -4
  17. package/es/Embed/AudioEmbed.js +5 -9
  18. package/es/Embed/BrightcoveEmbed.js +12 -15
  19. package/es/Embed/CodeEmbed.js +58 -10
  20. package/es/Embed/ConceptEmbed.js +15 -20
  21. package/es/Embed/ContentLinkEmbed.js +1 -1
  22. package/es/Embed/EmbedErrorPlaceholder.js +32 -17
  23. package/es/Embed/ExternalEmbed.js +7 -10
  24. package/es/Embed/FootnoteEmbed.js +3 -3
  25. package/es/Embed/H5pEmbed.js +1 -2
  26. package/es/Embed/IframeEmbed.js +8 -9
  27. package/es/Embed/ImageEmbed.js +167 -122
  28. package/es/Embed/RelatedContentEmbed.js +8 -10
  29. package/es/Embed/UuDisclaimerEmbed.js +2 -2
  30. package/es/Embed/conceptComponents.js +9 -9
  31. package/es/ErrorMessage/ErrorMessage.js +1 -1
  32. package/es/FactBox/FactBox.js +2 -2
  33. package/es/FileList/File.js +1 -1
  34. package/es/FileList/Format.js +3 -3
  35. package/es/FrontpageArticle/FrontpageArticle.js +1 -1
  36. package/es/Gloss/Gloss.js +9 -11
  37. package/es/Gloss/GlossExample.js +3 -4
  38. package/es/Grid/Grid.js +1 -1
  39. package/es/Image/Image.js +7 -8
  40. package/es/Image/ImageLink.js +1 -1
  41. package/es/KeyFigure/KeyFigure.js +2 -2
  42. package/es/LanguageSelector/LanguageSelector.js +2 -2
  43. package/es/LetterFilter/LetterFilter.js +1 -1
  44. package/es/LicenseByline/EmbedByline.js +5 -6
  45. package/es/LicenseByline/LicenseDescription.js +1 -1
  46. package/es/LicenseByline/LicenseLink.js +1 -2
  47. package/es/Messages/MessageBox.js +1 -1
  48. package/es/Notion/Notion.js +2 -2
  49. package/es/Notion/NotionImage.js +12 -57
  50. package/es/RelatedArticleList/RelatedArticleList.js +3 -3
  51. package/es/ResourceBox/ResourceBox.js +12 -17
  52. package/es/Search/ActiveFilters.js +1 -1
  53. package/es/Search/ContentTypeResult.js +9 -6
  54. package/es/Search/ContentTypeResultStyles.js +1 -1
  55. package/es/Search/IsPathToHighlight.js +1 -1
  56. package/es/Search/SearchField.js +6 -8
  57. package/es/Search/SearchResult.js +14 -19
  58. package/es/Search/SearchResultSleeve.js +14 -16
  59. package/es/SnackBar/SnackbarProvider.js +8 -11
  60. package/es/TagSelector/TagSelector.js +1 -1
  61. package/es/TagSelector/ariaMessages.js +6 -6
  62. package/es/TreeStructure/AddFolderButton.js +4 -6
  63. package/es/TreeStructure/ComboboxButton.js +4 -7
  64. package/es/TreeStructure/FolderItem.js +12 -15
  65. package/es/TreeStructure/FolderItems.js +3 -3
  66. package/es/TreeStructure/TreeStructure.js +9 -12
  67. package/es/TreeStructure/helperFunctions.js +1 -1
  68. package/es/ZendeskButton/ZendeskButton.js +55 -0
  69. package/es/i18n/formatNestedMessages.js +1 -1
  70. package/es/index.js +2 -1
  71. package/es/locale/messages-en.js +9 -8
  72. package/es/locale/messages-nb.js +9 -8
  73. package/es/locale/messages-nn.js +9 -8
  74. package/es/locale/messages-se.js +9 -8
  75. package/es/locale/messages-sma.js +9 -8
  76. package/es/styles.css +686 -0
  77. package/es/utils/relativeUrl.js +3 -3
  78. package/lib/Article/Article.js +3 -4
  79. package/lib/Article/ArticleByline.js +9 -9
  80. package/lib/Article/ArticleFootNotes.js +4 -4
  81. package/lib/AudioPlayer/AudioPlayer.d.ts +1 -2
  82. package/lib/AudioPlayer/AudioPlayer.js +142 -162
  83. package/lib/AudioPlayer/Controls.js +190 -205
  84. package/lib/AudioPlayer/SpeechControl.js +13 -11
  85. package/lib/BlogPost/BlogPost.d.ts +2 -2
  86. package/lib/BlogPost/BlogPost.js +85 -24
  87. package/lib/CampaignBlock/CampaignBlock.js +3 -4
  88. package/lib/CodeBlock/CodeBlock.d.ts +5 -8
  89. package/lib/CodeBlock/CodeBlock.js +88 -96
  90. package/lib/ContactBlock/ContactBlock.js +55 -43
  91. package/lib/ContentLoader/index.js +7 -7
  92. package/lib/CopyParagraphButton/CopyParagraphButton.js +4 -4
  93. package/lib/Embed/AudioEmbed.js +5 -9
  94. package/lib/Embed/BrightcoveEmbed.js +12 -15
  95. package/lib/Embed/CodeEmbed.js +56 -8
  96. package/lib/Embed/ConceptEmbed.js +15 -20
  97. package/lib/Embed/ContentLinkEmbed.js +1 -1
  98. package/lib/Embed/EmbedErrorPlaceholder.d.ts +4 -3
  99. package/lib/Embed/EmbedErrorPlaceholder.js +32 -18
  100. package/lib/Embed/ExternalEmbed.js +7 -10
  101. package/lib/Embed/FootnoteEmbed.js +3 -3
  102. package/lib/Embed/H5pEmbed.js +1 -2
  103. package/lib/Embed/IframeEmbed.js +8 -9
  104. package/lib/Embed/ImageEmbed.d.ts +1 -2
  105. package/lib/Embed/ImageEmbed.js +167 -123
  106. package/lib/Embed/RelatedContentEmbed.js +8 -10
  107. package/lib/Embed/UuDisclaimerEmbed.js +2 -2
  108. package/lib/Embed/conceptComponents.js +9 -9
  109. package/lib/ErrorMessage/ErrorMessage.js +1 -1
  110. package/lib/FactBox/FactBox.js +2 -2
  111. package/lib/FileList/File.js +1 -1
  112. package/lib/FileList/Format.js +3 -3
  113. package/lib/FrontpageArticle/FrontpageArticle.js +1 -1
  114. package/lib/Gloss/Gloss.js +9 -11
  115. package/lib/Gloss/GlossExample.js +3 -4
  116. package/lib/Grid/Grid.js +1 -1
  117. package/lib/Image/Image.js +7 -8
  118. package/lib/Image/ImageLink.js +1 -1
  119. package/lib/KeyFigure/KeyFigure.js +2 -2
  120. package/lib/LanguageSelector/LanguageSelector.js +2 -2
  121. package/lib/LetterFilter/LetterFilter.js +1 -1
  122. package/lib/LicenseByline/EmbedByline.js +5 -6
  123. package/lib/LicenseByline/LicenseDescription.js +1 -1
  124. package/lib/LicenseByline/LicenseLink.js +1 -2
  125. package/lib/Messages/MessageBox.js +1 -1
  126. package/lib/Notion/Notion.js +2 -2
  127. package/lib/Notion/NotionImage.d.ts +1 -11
  128. package/lib/Notion/NotionImage.js +12 -59
  129. package/lib/RelatedArticleList/RelatedArticleList.js +3 -3
  130. package/lib/ResourceBox/ResourceBox.js +13 -18
  131. package/lib/Search/ActiveFilters.js +1 -1
  132. package/lib/Search/ContentTypeResult.js +9 -6
  133. package/lib/Search/ContentTypeResultStyles.js +1 -1
  134. package/lib/Search/IsPathToHighlight.js +1 -1
  135. package/lib/Search/SearchField.js +6 -8
  136. package/lib/Search/SearchResult.js +14 -19
  137. package/lib/Search/SearchResultSleeve.js +14 -16
  138. package/lib/SnackBar/SnackbarProvider.js +8 -11
  139. package/lib/TagSelector/TagSelector.js +1 -1
  140. package/lib/TagSelector/ariaMessages.js +6 -6
  141. package/lib/TreeStructure/AddFolderButton.js +4 -6
  142. package/lib/TreeStructure/ComboboxButton.js +4 -7
  143. package/lib/TreeStructure/FolderItem.js +12 -15
  144. package/lib/TreeStructure/FolderItems.js +3 -3
  145. package/lib/TreeStructure/TreeStructure.js +9 -12
  146. package/lib/TreeStructure/helperFunctions.js +1 -1
  147. package/lib/ZendeskButton/ZendeskButton.d.ts +19 -0
  148. package/lib/ZendeskButton/ZendeskButton.js +61 -0
  149. package/lib/i18n/formatNestedMessages.js +1 -1
  150. package/lib/index.d.ts +2 -0
  151. package/lib/index.js +7 -0
  152. package/lib/locale/messages-en.d.ts +1 -0
  153. package/lib/locale/messages-en.js +9 -8
  154. package/lib/locale/messages-nb.d.ts +1 -0
  155. package/lib/locale/messages-nb.js +9 -8
  156. package/lib/locale/messages-nn.d.ts +1 -0
  157. package/lib/locale/messages-nn.js +9 -8
  158. package/lib/locale/messages-se.d.ts +1 -0
  159. package/lib/locale/messages-se.js +9 -8
  160. package/lib/locale/messages-sma.d.ts +1 -0
  161. package/lib/locale/messages-sma.js +9 -8
  162. package/lib/styles.css +686 -0
  163. package/lib/types.d.ts +1 -0
  164. package/lib/utils/relativeUrl.js +3 -3
  165. package/package.json +17 -12
  166. package/src/AudioPlayer/AudioPlayer.tsx +139 -176
  167. package/src/AudioPlayer/Controls.tsx +210 -250
  168. package/src/AudioPlayer/SpeechControl.tsx +9 -7
  169. package/src/BlogPost/BlogPost.tsx +82 -58
  170. package/src/CodeBlock/CodeBlock.stories.tsx +0 -43
  171. package/src/CodeBlock/CodeBlock.tsx +91 -202
  172. package/src/ContactBlock/ContactBlock.tsx +10 -2
  173. package/src/Embed/CodeEmbed.stories.tsx +95 -0
  174. package/src/Embed/CodeEmbed.tsx +62 -7
  175. package/src/Embed/ConceptEmbed.tsx +1 -9
  176. package/src/Embed/EmbedErrorPlaceholder.tsx +31 -28
  177. package/src/Embed/ImageEmbed.stories.tsx +53 -11
  178. package/src/Embed/ImageEmbed.tsx +162 -166
  179. package/src/Notion/NotionImage.tsx +4 -54
  180. package/src/ResourceBox/ResourceBox.tsx +3 -15
  181. package/src/Search/ContentTypeResult.tsx +9 -3
  182. package/src/Search/SearchResultSleeve.tsx +5 -2
  183. package/src/ZendeskButton/ZendeskButton.tsx +58 -0
  184. package/src/index.ts +4 -0
  185. package/src/locale/messages-en.ts +1 -0
  186. package/src/locale/messages-nb.ts +1 -0
  187. package/src/locale/messages-nn.ts +1 -0
  188. package/src/locale/messages-se.ts +1 -0
  189. package/src/locale/messages-sma.ts +1 -0
  190. package/src/types.ts +2 -0
  191. package/src/Image/__tests__/Image-test.tsx +0 -66
  192. package/src/Image/__tests__/__snapshots__/Image-test.tsx.snap +0 -194
@@ -29,9 +29,9 @@ const ContentLoader = _ref => {
29
29
  } = _ref;
30
30
  const idClip = (0, _util.uuid)();
31
31
  const idGradient = (0, _util.uuid)();
32
- const viewBox = viewBoxProp === undefined ? "0 0 ".concat(width, " ").concat(height) : viewBoxProp;
32
+ const viewBox = viewBoxProp === undefined ? `0 0 ${width} ${height}` : viewBoxProp;
33
33
  return (0, _jsxRuntime.jsxs)("svg", {
34
- viewBox: viewBox !== null && viewBox !== void 0 ? viewBox : undefined,
34
+ viewBox: viewBox ?? undefined,
35
35
  version: "1.1",
36
36
  preserveAspectRatio: preserveAspectRatio,
37
37
  className: className,
@@ -40,9 +40,9 @@ const ContentLoader = _ref => {
40
40
  width: typeof width === "string" ? width : undefined,
41
41
  children: [(0, _jsxRuntime.jsx)("rect", {
42
42
  style: {
43
- fill: "url(#".concat(idGradient, ")")
43
+ fill: `url(#${idGradient})`
44
44
  },
45
- clipPath: "url(#".concat(idClip, ")"),
45
+ clipPath: `url(#${idClip})`,
46
46
  x: "0",
47
47
  y: "0",
48
48
  width: width,
@@ -59,7 +59,7 @@ const ContentLoader = _ref => {
59
59
  children: (0, _jsxRuntime.jsx)("animate", {
60
60
  attributeName: "offset",
61
61
  values: "-2; 1",
62
- dur: "".concat(speed, "s"),
62
+ dur: `${speed}s`,
63
63
  repeatCount: "indefinite"
64
64
  })
65
65
  }), (0, _jsxRuntime.jsx)("stop", {
@@ -68,7 +68,7 @@ const ContentLoader = _ref => {
68
68
  children: (0, _jsxRuntime.jsx)("animate", {
69
69
  attributeName: "offset",
70
70
  values: "-1.5; 1.5",
71
- dur: "".concat(speed, "s"),
71
+ dur: `${speed}s`,
72
72
  repeatCount: "indefinite"
73
73
  })
74
74
  }), (0, _jsxRuntime.jsx)("stop", {
@@ -77,7 +77,7 @@ const ContentLoader = _ref => {
77
77
  children: (0, _jsxRuntime.jsx)("animate", {
78
78
  attributeName: "offset",
79
79
  values: "-1; 2",
80
- dur: "".concat(speed, "s"),
80
+ dur: `${speed}s`,
81
81
  repeatCount: "indefinite"
82
82
  })
83
83
  })]
@@ -57,9 +57,9 @@ const CopyParagraphButton = _ref => {
57
57
  const {
58
58
  location
59
59
  } = window;
60
- const newHash = "#".concat(sanitizedTitle);
61
- const port = location.port ? ":".concat(location.port) : "";
62
- const urlToCopy = "".concat(location.protocol, "//").concat(location.hostname).concat(port).concat(location.pathname).concat(location.search).concat(newHash);
60
+ const newHash = `#${sanitizedTitle}`;
61
+ const port = location.port ? `:${location.port}` : "";
62
+ const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
63
63
  (0, _util.copyTextToClipboard)(urlToCopy);
64
64
  }, [sanitizedTitle]);
65
65
  const tooltip = hasCopied ? t("article.copyPageLinkCopied") : t("article.copyHeaderLink");
@@ -68,7 +68,7 @@ const CopyParagraphButton = _ref => {
68
68
  tooltip: tooltip,
69
69
  children: (0, _jsxRuntime.jsx)(IconButton, {
70
70
  onClick: onCopyClick,
71
- "aria-label": "".concat(tooltip, ": ").concat(copyText),
71
+ "aria-label": `${tooltip}: ${copyText}`,
72
72
  children: (0, _jsxRuntime.jsx)(_common.Link, {})
73
73
  })
74
74
  }), (0, _jsxRuntime.jsx)("h2", {
@@ -18,13 +18,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
18
18
  *
19
19
  */
20
20
 
21
- const getFirstNonEmptyLicenseCredits = authors => {
22
- var _Object$values$find;
23
- return (_Object$values$find = Object.values(authors).find(i => i.length > 0)) !== null && _Object$values$find !== void 0 ? _Object$values$find : [];
24
- };
21
+ const getFirstNonEmptyLicenseCredits = authors => Object.values(authors).find(i => i.length > 0) ?? [];
25
22
  exports.getFirstNonEmptyLicenseCredits = getFirstNonEmptyLicenseCredits;
26
23
  const AudioEmbed = _ref => {
27
- var _data$podcastMeta, _data$podcastMeta$int, _data$podcastMeta2, _data$manuscript;
28
24
  let {
29
25
  embed,
30
26
  lang
@@ -47,9 +43,9 @@ const AudioEmbed = _ref => {
47
43
  }
48
44
  const subtitle = data.series ? {
49
45
  title: data.series.title.title,
50
- url: "/podkast/".concat(data.series.id)
46
+ url: `/podkast/${data.series.id}`
51
47
  } : undefined;
52
- const coverPhoto = (_data$podcastMeta = data.podcastMeta) === null || _data$podcastMeta === void 0 ? void 0 : _data$podcastMeta.coverPhoto;
48
+ const coverPhoto = data.podcastMeta?.coverPhoto;
53
49
  const img = coverPhoto && {
54
50
  url: coverPhoto.url,
55
51
  alt: coverPhoto.altText
@@ -58,10 +54,10 @@ const AudioEmbed = _ref => {
58
54
  type: "full",
59
55
  lang: lang,
60
56
  children: [(0, _jsxRuntime.jsx)(_AudioPlayer.default, {
61
- description: (_data$podcastMeta$int = (_data$podcastMeta2 = data.podcastMeta) === null || _data$podcastMeta2 === void 0 ? void 0 : _data$podcastMeta2.introduction) !== null && _data$podcastMeta$int !== void 0 ? _data$podcastMeta$int : "",
57
+ description: data.podcastMeta?.introduction ?? "",
62
58
  img: img,
63
59
  src: data.audioFile.url,
64
- textVersion: (_data$manuscript = data.manuscript) !== null && _data$manuscript !== void 0 && _data$manuscript.manuscript.length ? (0, _jsxRuntime.jsx)("span", {
60
+ textVersion: data.manuscript?.manuscript.length ? (0, _jsxRuntime.jsx)("span", {
65
61
  dangerouslySetInnerHTML: {
66
62
  __html: data.manuscript.manuscript
67
63
  }
@@ -43,13 +43,12 @@ const makeIframeString = function (url, width, height) {
43
43
  const strippedWidth = typeof width === "number" ? width : width.replace(/\s*px/, "");
44
44
  const strippedHeight = typeof height === "number" ? height : height.replace(/\s*px/, "");
45
45
  const urlOrTitle = title || url;
46
- return "<iframe title=\"".concat(urlOrTitle, "\" aria-label=\"").concat(urlOrTitle, "\" src=\"").concat(url, "\" width=\"").concat(strippedWidth, "\" height=\"").concat(strippedHeight, "\" allowfullscreen scrolling=\"no\" frameborder=\"0\" loading=\"lazy\"></iframe>");
46
+ return `<iframe title="${urlOrTitle}" aria-label="${urlOrTitle}" src="${url}" width="${strippedWidth}" height="${strippedHeight}" allowfullscreen scrolling="no" frameborder="0" loading="lazy"></iframe>`;
47
47
  };
48
48
  exports.makeIframeString = makeIframeString;
49
49
  const isNumeric = value => !Number.isNaN(value - Number.parseFloat(value));
50
50
  exports.isNumeric = isNumeric;
51
51
  const getIframeProps = (data, sources) => {
52
- var _source$height, _source$width;
53
52
  const {
54
53
  account,
55
54
  videoid,
@@ -57,13 +56,12 @@ const getIframeProps = (data, sources) => {
57
56
  } = data;
58
57
  const source = sources.filter(s => s.width && s.height).toSorted((a, b) => a.height - b.height)[0];
59
58
  return {
60
- src: "https://players.brightcove.net/".concat(account, "/").concat(player, "_default/index.html?videoId=").concat(videoid),
61
- height: (_source$height = source === null || source === void 0 ? void 0 : source.height) !== null && _source$height !== void 0 ? _source$height : "480",
62
- width: (_source$width = source === null || source === void 0 ? void 0 : source.width) !== null && _source$width !== void 0 ? _source$width : "640"
59
+ src: `https://players.brightcove.net/${account}/${player}_default/index.html?videoId=${videoid}`,
60
+ height: source?.height ?? "480",
61
+ width: source?.width ?? "640"
63
62
  };
64
63
  };
65
64
  const BrightcoveEmbed = _ref => {
66
- var _data$link, _data$link2, _ref2, _embedData$alt3, _ref3, _embedData$alt4;
67
65
  let {
68
66
  embed,
69
67
  isConcept,
@@ -77,7 +75,7 @@ const BrightcoveEmbed = _ref => {
77
75
  const {
78
76
  embedData
79
77
  } = embed;
80
- const fallbackTitle = "".concat(t("embed.type.video"), ": ").concat(embedData.videoid);
78
+ const fallbackTitle = `${t("embed.type.video")}: ${embedData.videoid}`;
81
79
  const parsedDescription = (0, _react.useMemo)(() => {
82
80
  if (embed.embedData.caption || renderContext === "article") {
83
81
  return embed.embedData.caption ? (0, _htmlReactParser.default)(embed.embedData.caption) : undefined;
@@ -89,19 +87,18 @@ const BrightcoveEmbed = _ref => {
89
87
  const iframe = iframeRef.current;
90
88
  if (iframe) {
91
89
  const [width, height] = [parseInt(iframe.width), parseInt(iframe.height)];
92
- iframe.style.aspectRatio = "".concat(width, "/").concat(height);
90
+ iframe.style.aspectRatio = `${width}/${height}`;
93
91
  iframe.width = "";
94
92
  iframe.height = "";
95
93
  }
96
94
  }, []);
97
95
  if (embed.status === "error") {
98
- var _embedData$alt, _embedData$alt2;
99
96
  return (0, _jsxRuntime.jsx)(_EmbedErrorPlaceholder.default, {
100
97
  type: "video",
101
98
  children: (0, _jsxRuntime.jsx)(BrightcoveIframe, {
102
99
  ref: iframeRef,
103
- title: (_embedData$alt = embedData.alt) !== null && _embedData$alt !== void 0 ? _embedData$alt : fallbackTitle,
104
- "aria-label": (_embedData$alt2 = embedData.alt) !== null && _embedData$alt2 !== void 0 ? _embedData$alt2 : fallbackTitle,
100
+ title: embedData.alt ?? fallbackTitle,
101
+ "aria-label": embedData.alt ?? fallbackTitle,
105
102
  frameBorder: "0",
106
103
  ...getIframeProps(embedData, []),
107
104
  allowFullScreen: true
@@ -111,7 +108,7 @@ const BrightcoveEmbed = _ref => {
111
108
  const {
112
109
  data
113
110
  } = embed;
114
- const linkedVideoId = isNumeric((_data$link = data.link) === null || _data$link === void 0 ? void 0 : _data$link.text) ? (_data$link2 = data.link) === null || _data$link2 === void 0 ? void 0 : _data$link2.text : undefined;
111
+ const linkedVideoId = isNumeric(data.link?.text) ? data.link?.text : undefined;
115
112
  const originalVideoProps = getIframeProps(embedData, data.sources);
116
113
  const alternativeVideoProps = linkedVideoId ? getIframeProps({
117
114
  ...embedData,
@@ -124,8 +121,8 @@ const BrightcoveEmbed = _ref => {
124
121
  children: (0, _jsxRuntime.jsx)(BrightcoveIframe, {
125
122
  ref: iframeRef,
126
123
  className: "original",
127
- title: (_ref2 = (_embedData$alt3 = embedData.alt) !== null && _embedData$alt3 !== void 0 ? _embedData$alt3 : data.name) !== null && _ref2 !== void 0 ? _ref2 : fallbackTitle,
128
- "aria-label": (_ref3 = (_embedData$alt4 = embedData.alt) !== null && _embedData$alt4 !== void 0 ? _embedData$alt4 : data.name) !== null && _ref3 !== void 0 ? _ref3 : fallbackTitle,
124
+ title: embedData.alt ?? data.name ?? fallbackTitle,
125
+ "aria-label": embedData.alt ?? data.name ?? fallbackTitle,
129
126
  frameBorder: "0",
130
127
  ...(alternativeVideoProps && !showOriginalVideo ? alternativeVideoProps : originalVideoProps),
131
128
  allowFullScreen: true
@@ -140,7 +137,7 @@ const BrightcoveEmbed = _ref => {
140
137
  shape: "pill",
141
138
  size: "small",
142
139
  onClick: () => setShowOriginalVideo(p => !p),
143
- children: t("figure.button.".concat(!showOriginalVideo ? "original" : "alternative"))
140
+ children: t(`figure.button.${!showOriginalVideo ? "original" : "alternative"}`)
144
141
  })
145
142
  })]
146
143
  });
@@ -4,8 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _react = require("react");
8
+ var _reactI18next = require("react-i18next");
9
+ var _action = require("@ndla/icons/action");
10
+ var _editor = require("@ndla/icons/editor");
11
+ var _primitives = require("@ndla/primitives");
12
+ var _jsx2 = require("@ndla/styled-system/jsx");
13
+ var _util = require("@ndla/util");
7
14
  var _CodeBlock = require("../CodeBlock");
8
- var _Figure = require("../Figure");
9
15
  var _jsxRuntime = require("@emotion/react/jsx-runtime");
10
16
  /**
11
17
  * Copyright (c) 2023-present, NDLA.
@@ -15,18 +21,60 @@ var _jsxRuntime = require("@emotion/react/jsx-runtime");
15
21
  *
16
22
  */
17
23
 
24
+ // TODO: We need an error state for this
25
+
26
+ const StyledFigCaption = (0, _jsx2.styled)("figcaption", {
27
+ base: {
28
+ textStyle: "label.large",
29
+ fontWeight: "bold"
30
+ }
31
+ });
32
+ const StyledFigure = (0, _jsx2.styled)(_primitives.Figure, {
33
+ base: {
34
+ // We apply margin here to allow for the float and size props on figure to work as intended.
35
+ "& > *:not(:where(:first-child))": {
36
+ marginBlockStart: "xsmall"
37
+ }
38
+ }
39
+ });
40
+ const getTitleFromFormat = format => {
41
+ const selectedLanguage = _CodeBlock.codeLanguageOptions.find(item => item.format === format);
42
+ if (selectedLanguage) {
43
+ return selectedLanguage.title;
44
+ }
45
+ return;
46
+ };
18
47
  const CodeEmbed = _ref => {
19
48
  let {
20
49
  embed
21
50
  } = _ref;
22
- return (0, _jsxRuntime.jsx)(_Figure.Figure, {
23
- children: (0, _jsxRuntime.jsx)(_CodeBlock.CodeBlock, {
24
- title: embed.embedData.title,
25
- code: embed.status === "success" ? embed.data.decodedContent : "",
51
+ const [isCopied, setIsCopied] = (0, _react.useState)(false);
52
+ const {
53
+ t
54
+ } = (0, _reactI18next.useTranslation)();
55
+ (0, _react.useEffect)(() => {
56
+ if (isCopied) {
57
+ const timer = setInterval(() => setIsCopied(false), 3000);
58
+ // ensure interval is cleared - also if unmounted
59
+ return () => {
60
+ clearTimeout(timer);
61
+ };
62
+ }
63
+ }, [isCopied]);
64
+ return (0, _jsxRuntime.jsxs)(StyledFigure, {
65
+ children: [(0, _jsxRuntime.jsx)(StyledFigCaption, {
66
+ children: embed.embedData.title || getTitleFromFormat(embed.embedData.codeFormat)
67
+ }), (0, _jsxRuntime.jsx)(_CodeBlock.CodeBlock, {
26
68
  highlightedCode: embed.status === "success" ? embed.data.highlightedCode : "",
27
- format: embed.embedData.codeFormat,
28
- showCopy: true
29
- })
69
+ format: embed.embedData.codeFormat
70
+ }), (0, _jsxRuntime.jsxs)(_primitives.Button, {
71
+ variant: "secondary",
72
+ onClick: () => {
73
+ (0, _util.copyTextToClipboard)(embed.status === "success" ? embed.data.decodedContent : "");
74
+ setIsCopied(true);
75
+ },
76
+ children: [isCopied ? (0, _jsxRuntime.jsx)(_editor.Done, {}) : (0, _jsxRuntime.jsx)(_action.Copy, {}), isCopied ? t("codeBlock.copiedCode") : t("codeBlock.copyCode")]
77
+ })]
30
78
  });
31
79
  };
32
80
  var _default = exports.default = CodeEmbed;