@ndla/ui 47.4.1 → 49.0.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 (294) hide show
  1. package/es/BlogPost/BlogPost.js +6 -6
  2. package/es/CampaignBlock/CampaignBlock.js +8 -8
  3. package/es/CopyParagraphButton/CopyParagraphButton.js +30 -58
  4. package/es/CopyParagraphButton/index.js +1 -3
  5. package/es/Embed/RelatedContentEmbed.js +3 -3
  6. package/es/FactBox/FactBox.js +64 -19
  7. package/es/FactBox/index.js +0 -1
  8. package/es/Figure/index.js +0 -2
  9. package/es/FileList/File.js +46 -24
  10. package/es/FileList/FileList.js +18 -14
  11. package/es/FileList/index.js +0 -2
  12. package/es/LinkBlock/LinkBlock.js +7 -7
  13. package/es/Messages/index.js +1 -2
  14. package/es/Navigation/index.js +1 -2
  15. package/es/RelatedArticleList/RelatedArticleList.js +80 -35
  16. package/es/RelatedArticleList/index.js +2 -3
  17. package/es/Search/SearchField.js +4 -9
  18. package/es/Search/index.js +0 -1
  19. package/es/Subject/index.js +1 -4
  20. package/es/all.css +1 -1
  21. package/es/i18n/i18n.js +2 -1
  22. package/es/index.js +10 -17
  23. package/es/utils/relativeUrl.js +17 -2
  24. package/lib/BlogPost/BlogPost.js +5 -5
  25. package/lib/CampaignBlock/CampaignBlock.js +7 -7
  26. package/lib/CopyParagraphButton/CopyParagraphButton.d.ts +5 -4
  27. package/lib/CopyParagraphButton/CopyParagraphButton.js +29 -57
  28. package/lib/CopyParagraphButton/index.d.ts +1 -3
  29. package/lib/CopyParagraphButton/index.js +0 -14
  30. package/lib/Embed/RelatedContentEmbed.js +3 -3
  31. package/lib/FactBox/FactBox.d.ts +1 -4
  32. package/lib/FactBox/FactBox.js +72 -27
  33. package/lib/FactBox/index.d.ts +0 -1
  34. package/lib/FactBox/index.js +0 -7
  35. package/lib/Figure/index.d.ts +0 -2
  36. package/lib/Figure/index.js +0 -14
  37. package/lib/FileList/File.d.ts +22 -3
  38. package/lib/FileList/File.js +45 -25
  39. package/lib/FileList/FileList.d.ts +10 -14
  40. package/lib/FileList/FileList.js +17 -15
  41. package/lib/FileList/index.d.ts +0 -2
  42. package/lib/FileList/index.js +0 -14
  43. package/lib/LinkBlock/LinkBlock.js +6 -6
  44. package/lib/Messages/index.d.ts +1 -2
  45. package/lib/Messages/index.js +0 -7
  46. package/lib/Navigation/index.d.ts +1 -2
  47. package/lib/Navigation/index.js +0 -7
  48. package/lib/RelatedArticleList/RelatedArticleList.d.ts +16 -17
  49. package/lib/RelatedArticleList/RelatedArticleList.js +78 -35
  50. package/lib/RelatedArticleList/index.d.ts +2 -3
  51. package/lib/RelatedArticleList/index.js +2 -12
  52. package/lib/Search/SearchField.d.ts +1 -2
  53. package/lib/Search/SearchField.js +4 -9
  54. package/lib/Search/index.d.ts +0 -1
  55. package/lib/Search/index.js +0 -7
  56. package/lib/Subject/index.d.ts +0 -3
  57. package/lib/Subject/index.js +0 -63
  58. package/lib/all.css +1 -1
  59. package/lib/i18n/i18n.d.ts +1 -0
  60. package/lib/i18n/i18n.js +4 -2
  61. package/lib/index.d.ts +10 -17
  62. package/lib/index.js +9 -232
  63. package/lib/utils/relativeUrl.d.ts +1 -1
  64. package/lib/utils/relativeUrl.js +19 -4
  65. package/package.json +8 -8
  66. package/src/BlogPost/BlogPost.tsx +2 -2
  67. package/src/CampaignBlock/CampaignBlock.tsx +2 -2
  68. package/src/CopyParagraphButton/CopyParagraphButton.tsx +24 -46
  69. package/src/CopyParagraphButton/index.tsx +1 -3
  70. package/src/Embed/RelatedContentEmbed.stories.tsx +9 -9
  71. package/src/Embed/RelatedContentEmbed.tsx +3 -3
  72. package/src/FactBox/FactBox.tsx +29 -16
  73. package/src/FactBox/Factbox.stories.tsx +4 -4
  74. package/src/FactBox/index.ts +0 -2
  75. package/src/Figure/index.ts +0 -2
  76. package/src/FileList/File.tsx +62 -32
  77. package/src/FileList/FileList.stories.tsx +15 -15
  78. package/src/FileList/FileList.tsx +21 -27
  79. package/src/FileList/index.ts +0 -2
  80. package/src/LinkBlock/LinkBlock.tsx +2 -2
  81. package/src/Messages/index.ts +1 -2
  82. package/src/Navigation/index.ts +1 -2
  83. package/src/RelatedArticleList/RelatedArticleList.tsx +53 -47
  84. package/src/RelatedArticleList/index.ts +2 -3
  85. package/src/Search/SearchField.tsx +1 -5
  86. package/src/Search/index.ts +0 -1
  87. package/src/Subject/index.ts +0 -13
  88. package/src/i18n/i18n.ts +2 -1
  89. package/src/index.ts +12 -46
  90. package/src/main.scss +0 -1
  91. package/src/utils/__tests__/relativeUrl-test.tsx +72 -0
  92. package/src/utils/relativeUrl.ts +19 -2
  93. package/es/BlogPosts/BlogPost.js +0 -96
  94. package/es/BlogPosts/BlogPostWrapper.js +0 -28
  95. package/es/BlogPosts/index.js +0 -11
  96. package/es/CopyParagraphButton/CopyParagraphButtonV2.js +0 -87
  97. package/es/CopyParagraphButton/initCopyParagraphButtons.js +0 -29
  98. package/es/FactBox/FactBoxV2.js +0 -93
  99. package/es/Figure/FigureBylineExpandButton.js +0 -29
  100. package/es/Figure/FigureExpandButton.js +0 -30
  101. package/es/FileList/FileListV2.js +0 -47
  102. package/es/FileList/FileV2.js +0 -32
  103. package/es/Frontpage/FrontpageFilm.js +0 -66
  104. package/es/Frontpage/FrontpageHeader.js +0 -50
  105. package/es/Frontpage/FrontpageInfo.js +0 -23
  106. package/es/Frontpage/FrontpageMultidisciplinarySubject.js +0 -99
  107. package/es/Frontpage/FrontpageProgramMenu.js +0 -86
  108. package/es/Frontpage/FrontpageSearch.js +0 -157
  109. package/es/Frontpage/FrontpageToolbox.js +0 -57
  110. package/es/Frontpage/illustrations/Fellesfag.js +0 -99
  111. package/es/Frontpage/illustrations/FrontpageHeaderIllustration.js +0 -113
  112. package/es/Frontpage/illustrations/FrontpageIllustrations.js +0 -21
  113. package/es/Frontpage/illustrations/FrontpageSubjectIllustration.js +0 -184
  114. package/es/Frontpage/illustrations/MenuFellesfag.js +0 -80
  115. package/es/Frontpage/illustrations/MenuStudiespesialiserende.js +0 -77
  116. package/es/Frontpage/illustrations/MenuYrkesfag.js +0 -107
  117. package/es/Frontpage/illustrations/Studiespesialiserende.js +0 -87
  118. package/es/Frontpage/illustrations/Yrkesfag.js +0 -118
  119. package/es/Frontpage/illustrations/index.js +0 -18
  120. package/es/Frontpage/index.js +0 -9
  121. package/es/Frontpage/sortCategories.js +0 -25
  122. package/es/InfoBlock/InfoBlock.js +0 -58
  123. package/es/InfoBlock/index.js +0 -1
  124. package/es/InfoBox/InfoBox.js +0 -16
  125. package/es/InfoBox/index.js +0 -1
  126. package/es/InfoWidget/InfoWidget.js +0 -103
  127. package/es/InfoWidget/index.js +0 -2
  128. package/es/Masthead/MastheadSearchModal.js +0 -82
  129. package/es/Messages/MessageBoxTag.js +0 -33
  130. package/es/MultidisciplinarySubject/List.js +0 -52
  131. package/es/MultidisciplinarySubject/ListItem.js +0 -90
  132. package/es/MultidisciplinarySubject/MultidisciplinarySubject.js +0 -125
  133. package/es/MultidisciplinarySubject/index.js +0 -10
  134. package/es/Navigation/NavigationTopicAbout.js +0 -164
  135. package/es/RelatedArticleList/RelatedArticleV2.js +0 -125
  136. package/es/Search/ToggleSearchButton.js +0 -51
  137. package/es/Subject/Subject.js +0 -143
  138. package/es/Subject/SubjectNewContent.js +0 -102
  139. package/es/Subject/SubjectSocial.js +0 -33
  140. package/es/Translation/Translation.js +0 -33
  141. package/es/Translation/TranslationLine.js +0 -47
  142. package/es/Translation/index.js +0 -2
  143. package/lib/BlogPosts/BlogPost.d.ts +0 -22
  144. package/lib/BlogPosts/BlogPost.js +0 -103
  145. package/lib/BlogPosts/BlogPostWrapper.d.ts +0 -14
  146. package/lib/BlogPosts/BlogPostWrapper.js +0 -37
  147. package/lib/BlogPosts/index.d.ts +0 -10
  148. package/lib/BlogPosts/index.js +0 -20
  149. package/lib/CopyParagraphButton/CopyParagraphButtonV2.d.ts +0 -15
  150. package/lib/CopyParagraphButton/CopyParagraphButtonV2.js +0 -92
  151. package/lib/CopyParagraphButton/initCopyParagraphButtons.d.ts +0 -2
  152. package/lib/CopyParagraphButton/initCopyParagraphButtons.js +0 -38
  153. package/lib/FactBox/FactBoxV2.d.ts +0 -13
  154. package/lib/FactBox/FactBoxV2.js +0 -98
  155. package/lib/Figure/FigureBylineExpandButton.d.ts +0 -16
  156. package/lib/Figure/FigureBylineExpandButton.js +0 -35
  157. package/lib/Figure/FigureExpandButton.d.ts +0 -16
  158. package/lib/Figure/FigureExpandButton.js +0 -35
  159. package/lib/FileList/FileListV2.d.ts +0 -13
  160. package/lib/FileList/FileListV2.js +0 -52
  161. package/lib/FileList/FileV2.d.ts +0 -15
  162. package/lib/FileList/FileV2.js +0 -40
  163. package/lib/Frontpage/FrontpageFilm.d.ts +0 -6
  164. package/lib/Frontpage/FrontpageFilm.js +0 -73
  165. package/lib/Frontpage/FrontpageHeader.d.ts +0 -8
  166. package/lib/Frontpage/FrontpageHeader.js +0 -57
  167. package/lib/Frontpage/FrontpageInfo.d.ts +0 -6
  168. package/lib/Frontpage/FrontpageInfo.js +0 -31
  169. package/lib/Frontpage/FrontpageMultidisciplinarySubject.d.ts +0 -33
  170. package/lib/Frontpage/FrontpageMultidisciplinarySubject.js +0 -114
  171. package/lib/Frontpage/FrontpageProgramMenu.d.ts +0 -9
  172. package/lib/Frontpage/FrontpageProgramMenu.js +0 -93
  173. package/lib/Frontpage/FrontpageSearch.d.ts +0 -21
  174. package/lib/Frontpage/FrontpageSearch.js +0 -164
  175. package/lib/Frontpage/FrontpageToolbox.d.ts +0 -8
  176. package/lib/Frontpage/FrontpageToolbox.js +0 -64
  177. package/lib/Frontpage/illustrations/Fellesfag.d.ts +0 -9
  178. package/lib/Frontpage/illustrations/Fellesfag.js +0 -105
  179. package/lib/Frontpage/illustrations/FrontpageHeaderIllustration.d.ts +0 -9
  180. package/lib/Frontpage/illustrations/FrontpageHeaderIllustration.js +0 -119
  181. package/lib/Frontpage/illustrations/FrontpageIllustrations.d.ts +0 -9
  182. package/lib/Frontpage/illustrations/FrontpageIllustrations.js +0 -30
  183. package/lib/Frontpage/illustrations/FrontpageSubjectIllustration.d.ts +0 -9
  184. package/lib/Frontpage/illustrations/FrontpageSubjectIllustration.js +0 -188
  185. package/lib/Frontpage/illustrations/MenuFellesfag.d.ts +0 -9
  186. package/lib/Frontpage/illustrations/MenuFellesfag.js +0 -86
  187. package/lib/Frontpage/illustrations/MenuStudiespesialiserende.d.ts +0 -9
  188. package/lib/Frontpage/illustrations/MenuStudiespesialiserende.js +0 -83
  189. package/lib/Frontpage/illustrations/MenuYrkesfag.d.ts +0 -9
  190. package/lib/Frontpage/illustrations/MenuYrkesfag.js +0 -113
  191. package/lib/Frontpage/illustrations/Studiespesialiserende.d.ts +0 -9
  192. package/lib/Frontpage/illustrations/Studiespesialiserende.js +0 -93
  193. package/lib/Frontpage/illustrations/Yrkesfag.d.ts +0 -9
  194. package/lib/Frontpage/illustrations/Yrkesfag.js +0 -124
  195. package/lib/Frontpage/illustrations/index.d.ts +0 -18
  196. package/lib/Frontpage/illustrations/index.js +0 -68
  197. package/lib/Frontpage/index.d.ts +0 -9
  198. package/lib/Frontpage/index.js +0 -99
  199. package/lib/Frontpage/sortCategories.d.ts +0 -9
  200. package/lib/Frontpage/sortCategories.js +0 -32
  201. package/lib/InfoBlock/InfoBlock.d.ts +0 -8
  202. package/lib/InfoBlock/InfoBlock.js +0 -64
  203. package/lib/InfoBlock/index.d.ts +0 -1
  204. package/lib/InfoBlock/index.js +0 -12
  205. package/lib/InfoBox/InfoBox.d.ts +0 -6
  206. package/lib/InfoBox/InfoBox.js +0 -24
  207. package/lib/InfoBox/index.d.ts +0 -1
  208. package/lib/InfoBox/index.js +0 -13
  209. package/lib/InfoWidget/InfoWidget.d.ts +0 -21
  210. package/lib/InfoWidget/InfoWidget.js +0 -110
  211. package/lib/InfoWidget/index.d.ts +0 -2
  212. package/lib/InfoWidget/index.js +0 -10
  213. package/lib/Masthead/MastheadSearchModal.d.ts +0 -8
  214. package/lib/Masthead/MastheadSearchModal.js +0 -89
  215. package/lib/Messages/MessageBoxTag.d.ts +0 -12
  216. package/lib/Messages/MessageBoxTag.js +0 -40
  217. package/lib/MultidisciplinarySubject/List.d.ts +0 -7
  218. package/lib/MultidisciplinarySubject/List.js +0 -59
  219. package/lib/MultidisciplinarySubject/ListItem.d.ts +0 -10
  220. package/lib/MultidisciplinarySubject/ListItem.js +0 -97
  221. package/lib/MultidisciplinarySubject/MultidisciplinarySubject.d.ts +0 -13
  222. package/lib/MultidisciplinarySubject/MultidisciplinarySubject.js +0 -135
  223. package/lib/MultidisciplinarySubject/index.d.ts +0 -9
  224. package/lib/MultidisciplinarySubject/index.js +0 -17
  225. package/lib/Navigation/NavigationTopicAbout.d.ts +0 -13
  226. package/lib/Navigation/NavigationTopicAbout.js +0 -171
  227. package/lib/RelatedArticleList/RelatedArticleV2.d.ts +0 -26
  228. package/lib/RelatedArticleList/RelatedArticleV2.js +0 -131
  229. package/lib/Search/ToggleSearchButton.d.ts +0 -14
  230. package/lib/Search/ToggleSearchButton.js +0 -57
  231. package/lib/Subject/Subject.d.ts +0 -32
  232. package/lib/Subject/Subject.js +0 -156
  233. package/lib/Subject/SubjectNewContent.d.ts +0 -13
  234. package/lib/Subject/SubjectNewContent.js +0 -109
  235. package/lib/Subject/SubjectSocial.d.ts +0 -12
  236. package/lib/Subject/SubjectSocial.js +0 -41
  237. package/lib/Translation/Translation.d.ts +0 -14
  238. package/lib/Translation/Translation.js +0 -38
  239. package/lib/Translation/TranslationLine.d.ts +0 -16
  240. package/lib/Translation/TranslationLine.js +0 -51
  241. package/lib/Translation/index.d.ts +0 -2
  242. package/lib/Translation/index.js +0 -20
  243. package/src/BlogPosts/BlogPost.tsx +0 -192
  244. package/src/BlogPosts/BlogPostWrapper.tsx +0 -49
  245. package/src/BlogPosts/index.ts +0 -12
  246. package/src/CopyParagraphButton/CopyParagraphButtonV2.tsx +0 -85
  247. package/src/CopyParagraphButton/initCopyParagraphButtons.tsx +0 -27
  248. package/src/FactBox/FactBoxV2.tsx +0 -56
  249. package/src/Figure/FigureBylineExpandButton.tsx +0 -34
  250. package/src/Figure/FigureExpandButton.tsx +0 -35
  251. package/src/FileList/FileListV2.tsx +0 -58
  252. package/src/FileList/FileV2.tsx +0 -33
  253. package/src/Frontpage/FrontpageFilm.tsx +0 -97
  254. package/src/Frontpage/FrontpageHeader.tsx +0 -72
  255. package/src/Frontpage/FrontpageInfo.tsx +0 -45
  256. package/src/Frontpage/FrontpageMultidisciplinarySubject.tsx +0 -110
  257. package/src/Frontpage/FrontpageProgramMenu.tsx +0 -86
  258. package/src/Frontpage/FrontpageSearch.tsx +0 -200
  259. package/src/Frontpage/FrontpageToolbox.tsx +0 -70
  260. package/src/Frontpage/__tests__/Frontpage-test.js +0 -158
  261. package/src/Frontpage/illustrations/Fellesfag.tsx +0 -99
  262. package/src/Frontpage/illustrations/FrontpageHeaderIllustration.tsx +0 -131
  263. package/src/Frontpage/illustrations/FrontpageIllustrations.tsx +0 -28
  264. package/src/Frontpage/illustrations/FrontpageSubjectIllustration.tsx +0 -151
  265. package/src/Frontpage/illustrations/MenuFellesfag.tsx +0 -73
  266. package/src/Frontpage/illustrations/MenuStudiespesialiserende.tsx +0 -70
  267. package/src/Frontpage/illustrations/MenuYrkesfag.tsx +0 -82
  268. package/src/Frontpage/illustrations/Studiespesialiserende.tsx +0 -79
  269. package/src/Frontpage/illustrations/Yrkesfag.tsx +0 -122
  270. package/src/Frontpage/illustrations/index.ts +0 -31
  271. package/src/Frontpage/index.ts +0 -17
  272. package/src/Frontpage/sortCategories.ts +0 -23
  273. package/src/InfoBlock/InfoBlock.tsx +0 -61
  274. package/src/InfoBlock/index.ts +0 -1
  275. package/src/InfoBox/InfoBox.tsx +0 -31
  276. package/src/InfoBox/index.ts +0 -1
  277. package/src/InfoWidget/InfoWidget.tsx +0 -127
  278. package/src/InfoWidget/index.ts +0 -3
  279. package/src/Masthead/MastheadSearchModal.tsx +0 -101
  280. package/src/Messages/MessageBoxTag.tsx +0 -34
  281. package/src/MultidisciplinarySubject/List.tsx +0 -49
  282. package/src/MultidisciplinarySubject/ListItem.tsx +0 -74
  283. package/src/MultidisciplinarySubject/MultidisciplinarySubject.tsx +0 -117
  284. package/src/MultidisciplinarySubject/index.ts +0 -11
  285. package/src/Navigation/NavigationTopicAbout.tsx +0 -171
  286. package/src/RelatedArticleList/RelatedArticleV2.tsx +0 -101
  287. package/src/Search/ToggleSearchButton.tsx +0 -64
  288. package/src/Subject/Subject.tsx +0 -199
  289. package/src/Subject/SubjectNewContent.tsx +0 -111
  290. package/src/Subject/SubjectSocial.tsx +0 -36
  291. package/src/Translation/Translation.tsx +0 -29
  292. package/src/Translation/TranslationLine.tsx +0 -42
  293. package/src/Translation/component.translation.scss +0 -53
  294. package/src/Translation/index.ts +0 -2
@@ -6,19 +6,17 @@
6
6
  *
7
7
  */
8
8
 
9
- import { useEffect, useState, MouseEvent } from 'react';
10
-
11
- import styled from '@emotion/styled';
12
- import { Link } from '@ndla/icons/common';
9
+ import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
13
10
  import { useTranslation } from 'react-i18next';
11
+ import styled from '@emotion/styled';
12
+ import { colors } from '@ndla/core';
14
13
  import Tooltip from '@ndla/tooltip';
14
+ import { Link } from '@ndla/icons/common';
15
15
  import { copyTextToClipboard } from '@ndla/util';
16
- import { colors } from '@ndla/core';
17
16
 
18
17
  const ContainerDiv = styled.div`
19
18
  position: relative;
20
19
  `;
21
-
22
20
  const IconButton = styled.button`
23
21
  position: absolute;
24
22
  left: -3em;
@@ -43,63 +41,43 @@ const IconButton = styled.button`
43
41
  `;
44
42
 
45
43
  interface Props {
46
- title?: string | null;
47
- content?: string | null;
48
- hydrate?: boolean;
49
- }
50
-
51
- interface CopyButtonProps {
52
- title: string;
53
- onClick?: (e: MouseEvent<HTMLButtonElement>) => void;
54
- tooltip: string;
55
- content?: string | null;
44
+ // What to render within the h2
45
+ children: ReactNode;
46
+ copyText: string;
47
+ lang?: string;
56
48
  }
57
-
58
- const CopyButton = ({ onClick, title, tooltip, content }: CopyButtonProps) => {
59
- return (
60
- <div>
61
- <Tooltip tooltip={tooltip}>
62
- <IconButton onClick={onClick} data-title={title} aria-label={`${tooltip}: ${content}`}>
63
- <Link title={''} />
64
- </IconButton>
65
- </Tooltip>
66
- <h2 id={title} tabIndex={-1} dangerouslySetInnerHTML={{ __html: content || '' }} />
67
- </div>
68
- );
69
- };
70
-
71
- const CopyParagraphButton = ({ title, content, hydrate }: Props) => {
72
- const { t } = useTranslation();
49
+ const CopyParagraphButton = ({ children, copyText, lang }: Props) => {
73
50
  const [hasCopied, setHasCopied] = useState(false);
51
+ const { t } = useTranslation();
52
+ const sanitizedTitle = useMemo(() => encodeURIComponent(copyText.replace(/ /g, '-')), [copyText]);
53
+
74
54
  useEffect(() => {
75
55
  if (hasCopied) {
76
56
  setTimeout(() => setHasCopied(false), 3000);
77
57
  }
78
58
  }, [hasCopied]);
79
59
 
80
- if (!title) return null;
81
-
82
- const onCopyClick = (event: MouseEvent<HTMLButtonElement>): void => {
60
+ const onCopyClick = useCallback(() => {
83
61
  setHasCopied(true);
84
- const copyId = event.currentTarget.getAttribute('data-title');
85
62
  const { location } = window;
86
- const newHash = `#${copyId}`;
63
+ const newHash = `#${sanitizedTitle}`;
87
64
  const port = location.port ? `:${location.port}` : '';
88
65
  const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
89
66
 
90
67
  copyTextToClipboard(urlToCopy);
91
- };
68
+ }, [sanitizedTitle]);
92
69
 
93
- const sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
94
70
  const tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
95
-
96
- if (hydrate) {
97
- return <CopyButton onClick={onCopyClick} title={sanitizedTitle} tooltip={tooltip} content={content} />;
98
- }
99
-
100
71
  return (
101
- <ContainerDiv data-header-copy-container data-title={title}>
102
- <CopyButton onClick={onCopyClick} title={sanitizedTitle} tooltip={tooltip} content={content} />
72
+ <ContainerDiv>
73
+ <Tooltip tooltip={tooltip}>
74
+ <IconButton onClick={onCopyClick} aria-label={`${tooltip}: ${copyText}`}>
75
+ <Link />
76
+ </IconButton>
77
+ </Tooltip>
78
+ <h2 id={sanitizedTitle} tabIndex={-1} lang={lang}>
79
+ {children}
80
+ </h2>
103
81
  </ContainerDiv>
104
82
  );
105
83
  };
@@ -7,8 +7,6 @@
7
7
  */
8
8
 
9
9
  import CopyParagraphButton from './CopyParagraphButton';
10
- import CopyParagraphButtonV2 from './CopyParagraphButtonV2';
11
- import initCopyParagraphButtons from './initCopyParagraphButtons';
12
10
 
13
- export { CopyParagraphButton, initCopyParagraphButtons, CopyParagraphButtonV2 };
11
+ export { CopyParagraphButton };
14
12
  export default CopyParagraphButton;
@@ -10,7 +10,7 @@ import { Meta, StoryObj } from '@storybook/react';
10
10
  import { RelatedContentMetaData } from '@ndla/types-embed';
11
11
  import { defaultParameters } from '../../../../stories/defaults';
12
12
  import RelatedContentEmbed from './RelatedContentEmbed';
13
- import { RelatedArticleListV2 } from '../RelatedArticleList';
13
+ import RelatedArticleList from '../RelatedArticleList';
14
14
 
15
15
  const filmResourceMeta: RelatedContentMetaData = {
16
16
  resource: 'related-content',
@@ -397,41 +397,41 @@ const linkEmbed2: RelatedContentMetaData = {
397
397
 
398
398
  export const RelatedContentStory: StoryObj<typeof RelatedContentEmbed> = {
399
399
  render: () => (
400
- <RelatedArticleListV2>
400
+ <RelatedArticleList>
401
401
  <RelatedContentEmbed embed={learningResourceMeta} />
402
402
  <RelatedContentEmbed embed={learningResourceMeta} />
403
- </RelatedArticleListV2>
403
+ </RelatedArticleList>
404
404
  ),
405
405
  };
406
406
 
407
407
  export const HideAllAboveTwo: StoryObj<typeof RelatedContentEmbed> = {
408
408
  render: () => (
409
- <RelatedArticleListV2>
409
+ <RelatedArticleList>
410
410
  <RelatedContentEmbed embed={learningResourceMeta} />
411
411
  <RelatedContentEmbed embed={filmResourceMeta} />
412
412
  <RelatedContentEmbed embed={learningResourceMeta} />
413
413
  <RelatedContentEmbed embed={filmResourceMeta} />
414
- </RelatedArticleListV2>
414
+ </RelatedArticleList>
415
415
  ),
416
416
  };
417
417
 
418
418
  export const WithLinks: StoryObj<typeof RelatedContentEmbed> = {
419
419
  render: () => (
420
- <RelatedArticleListV2>
420
+ <RelatedArticleList>
421
421
  <RelatedContentEmbed embed={linkEmbed1} />
422
422
  <RelatedContentEmbed embed={linkEmbed2} />
423
- </RelatedArticleListV2>
423
+ </RelatedArticleList>
424
424
  ),
425
425
  };
426
426
 
427
427
  export const Mixed: StoryObj<typeof RelatedContentEmbed> = {
428
428
  render: () => (
429
- <RelatedArticleListV2>
429
+ <RelatedArticleList>
430
430
  <RelatedContentEmbed embed={linkEmbed1} />
431
431
  <RelatedContentEmbed embed={learningResourceMeta} />
432
432
  <RelatedContentEmbed embed={filmResourceMeta} />
433
433
  <RelatedContentEmbed embed={linkEmbed2} />
434
- </RelatedArticleListV2>
434
+ </RelatedArticleList>
435
435
  ),
436
436
  };
437
437
 
@@ -9,7 +9,7 @@
9
9
  import { RelatedContentMetaData } from '@ndla/types-embed';
10
10
  import { useTranslation } from 'react-i18next';
11
11
  import { contentTypeMapping } from '../model/ContentType';
12
- import { RelatedArticleV2 } from '../RelatedArticleList/RelatedArticleV2';
12
+ import { RelatedArticle } from '../RelatedArticleList/RelatedArticleList';
13
13
 
14
14
  interface Props {
15
15
  embed: RelatedContentMetaData;
@@ -34,7 +34,7 @@ const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }: P
34
34
  data.resource?.path ??
35
35
  `/article/${embedData.articleId}`;
36
36
  return (
37
- <RelatedArticleV2
37
+ <RelatedArticle
38
38
  title={data.article.title?.title ?? ''}
39
39
  introduction={data.article.metaDescription?.metaDescription ?? ''}
40
40
  target={isOembed ? '_blank' : undefined}
@@ -44,7 +44,7 @@ const RelatedContentEmbed = ({ embed, isOembed, subject, ndlaFrontendDomain }: P
44
44
  );
45
45
  } else if (typeof embedData.url === 'string') {
46
46
  return (
47
- <RelatedArticleV2
47
+ <RelatedArticle
48
48
  title={embedData.title ?? ''}
49
49
  introduction=""
50
50
  to={embedData.url}
@@ -6,10 +6,12 @@
6
6
  *
7
7
  */
8
8
 
9
- import { ReactNode, MouseEvent } from 'react';
9
+ import { ReactNode, useState } from 'react';
10
10
  import BEMHelper from 'react-bem-helper';
11
- import { ButtonV2 } from '@ndla/button';
12
11
  import { useTranslation } from 'react-i18next';
12
+ import styled from '@emotion/styled';
13
+ import { IconButtonV2 } from '@ndla/button';
14
+ import { ChevronDown, ChevronUp } from '@ndla/icons/common';
13
15
 
14
16
  const classes = new BEMHelper({
15
17
  name: 'factbox',
@@ -17,26 +19,37 @@ const classes = new BEMHelper({
17
19
  });
18
20
 
19
21
  interface Props {
20
- dangerouslySetInnerHTML?: { __html: string };
21
22
  children?: ReactNode;
22
23
  }
23
24
 
24
- const toggleFactBox = (event: MouseEvent<HTMLButtonElement>) => {
25
- const button = event.currentTarget;
26
- const aside = button?.previousSibling?.parentElement;
27
- aside?.classList?.toggle('expanded');
28
- };
29
- const FactBox = ({ children, dangerouslySetInnerHTML }: Props) => {
25
+ const StyledAside = styled.aside`
26
+ display: flex;
27
+ flex-direction: column;
28
+ align-items: center;
29
+ `;
30
+
31
+ const StyledDiv = styled.div`
32
+ width: 100%;
33
+ `;
34
+
35
+ const StyledIconButton = styled(IconButtonV2)`
36
+ margin-top: -20px;
37
+ z-index: 1;
38
+ `;
39
+
40
+ const FactBox = ({ children }: Props) => {
30
41
  const { t } = useTranslation();
42
+ const [isOpen, setIsOpen] = useState(false);
43
+
44
+ const additional = isOpen ? 'expanded' : '';
31
45
 
32
46
  return (
33
- <aside {...classes()}>
34
- <div {...classes('content')} dangerouslySetInnerHTML={dangerouslySetInnerHTML}>
35
- {children}
36
- </div>
37
- <ButtonV2 {...classes('button', 'collapsed')} onClick={toggleFactBox} title={t('factbox.open')} />
38
- <ButtonV2 {...classes('button', 'open')} onClick={toggleFactBox} title={t('factbox.close')} />
39
- </aside>
47
+ <StyledAside {...classes(undefined, undefined, additional)}>
48
+ <StyledDiv {...classes('content')}>{children}</StyledDiv>
49
+ <StyledIconButton onClick={() => setIsOpen((p) => !p)} aria-label={t(`factbox.${isOpen ? 'close' : 'open'}`)}>
50
+ {isOpen ? <ChevronUp /> : <ChevronDown />}
51
+ </StyledIconButton>
52
+ </StyledAside>
40
53
  );
41
54
  };
42
55
 
@@ -10,7 +10,7 @@ import styled from '@emotion/styled';
10
10
  import { Meta, StoryObj } from '@storybook/react';
11
11
  import { spacing } from '@ndla/core';
12
12
  import { Heading, Text } from '@ndla/typography';
13
- import FactBoxV2 from './FactBoxV2';
13
+ import FactBox from './FactBox';
14
14
  import { defaultParameters } from '../../../../stories/defaults';
15
15
 
16
16
  const Wrapper = styled.div`
@@ -22,7 +22,7 @@ const Wrapper = styled.div`
22
22
  */
23
23
  export default {
24
24
  title: 'Components/FactBox',
25
- component: FactBoxV2,
25
+ component: FactBox,
26
26
  tags: ['autodocs'],
27
27
  paramemeters: {
28
28
  inlineStories: true,
@@ -57,6 +57,6 @@ export default {
57
57
  </>
58
58
  ),
59
59
  },
60
- } as Meta<typeof FactBoxV2>;
60
+ } as Meta<typeof FactBox>;
61
61
 
62
- export const Default: StoryObj<typeof FactBoxV2> = {};
62
+ export const Default: StoryObj<typeof FactBox> = {};
@@ -1,5 +1,3 @@
1
1
  import FactBox from './FactBox';
2
2
 
3
- export { default as FactBoxV2 } from './FactBoxV2';
4
-
5
3
  export default FactBox;
@@ -7,8 +7,6 @@
7
7
  */
8
8
 
9
9
  export { default as Figure } from './Figure';
10
- export { FigureExpandButton } from './FigureExpandButton';
11
- export { FigureBylineExpandButton } from './FigureBylineExpandButton';
12
10
  export { FigureOpenDialogButton } from './FigureOpenDialogButton';
13
11
 
14
12
  export type { FigureType } from './Figure';
@@ -1,9 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2023-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
+
1
9
  import styled from '@emotion/styled';
10
+ import { useTranslation } from 'react-i18next';
11
+ import SafeLink from '@ndla/safelink';
2
12
  import { breakpoints, colors, fonts, mq, spacing } from '@ndla/core';
3
13
  import { Download } from '@ndla/icons/common';
4
- import SafeLink from '@ndla/safelink';
5
- import Tooltip from '@ndla/tooltip';
6
- import { FileFormat, FileType } from './FileList';
14
+
15
+ interface Props {
16
+ title: string;
17
+ url: string;
18
+ fileExists: boolean;
19
+ fileType: string;
20
+ }
21
+
22
+ export interface FileType {
23
+ title: string;
24
+ formats: FileFormat[];
25
+ fileExists?: boolean;
26
+ }
27
+
28
+ export interface FileFormat {
29
+ url: string;
30
+ fileType: string;
31
+ tooltip: string;
32
+ }
7
33
 
8
34
  const LinkTextWrapper = styled.div`
9
35
  & > span {
@@ -31,7 +57,29 @@ const FileLink = styled(SafeLink)`
31
57
  }
32
58
  `;
33
59
 
34
- const renderFormat = (format: FileFormat, title: string, isPrimary: boolean, isDeadLink: boolean) => {
60
+ const FileListItem = styled.li`
61
+ ${fonts.sizes('18px', '26px')};
62
+ font-weight: ${fonts.weight.semibold};
63
+ min-height: 60px;
64
+ background: ${colors.brand.greyLighter};
65
+ display: flex;
66
+ align-items: center;
67
+ flex-wrap: wrap;
68
+ margin-bottom: ${spacing.xsmall};
69
+ padding: ${spacing.small};
70
+ ${mq.range({ from: breakpoints.tablet })} {
71
+ padding: ${spacing.small} ${spacing.normal};
72
+ }
73
+ `;
74
+
75
+ interface FormatProps {
76
+ format: FileFormat;
77
+ title: string;
78
+ isPrimary: boolean;
79
+ isDeadLink: boolean;
80
+ }
81
+
82
+ const Format = ({ format, title, isPrimary, isDeadLink }: FormatProps) => {
35
83
  const titleWithFormat = `${title} (${format.fileType.toUpperCase()})`;
36
84
 
37
85
  if (isDeadLink) {
@@ -46,40 +94,22 @@ const renderFormat = (format: FileFormat, title: string, isPrimary: boolean, isD
46
94
  return (
47
95
  <FileLink key={format.url} to={format.url} target="_blank" aria-label={titleWithFormat}>
48
96
  <Download />
49
- <Tooltip tooltip={format.tooltip}>
50
- <LinkTextWrapper>
51
- <span>{isPrimary ? titleWithFormat : `(${format.fileType.toUpperCase()})`}</span>
52
- </LinkTextWrapper>
53
- </Tooltip>
97
+ <LinkTextWrapper aria-label={format.tooltip}>
98
+ <span>{isPrimary ? titleWithFormat : `(${format.fileType.toUpperCase()})`}</span>
99
+ </LinkTextWrapper>
54
100
  </FileLink>
55
101
  );
56
102
  };
57
103
 
58
- interface Props {
59
- file: FileType;
60
- }
104
+ const File = ({ title, url, fileExists, fileType }: Props) => {
105
+ const { t } = useTranslation();
106
+ const tooltip = `${t('download')} ${url.split('/').pop()}`;
61
107
 
62
- const FileListItem = styled.li`
63
- ${fonts.sizes('18px', '26px')};
64
- font-weight: ${fonts.weight.semibold};
65
- min-height: 60px;
66
- background: ${colors.brand.greyLighter};
67
- display: flex;
68
- align-items: center;
69
- flex-wrap: wrap;
70
- margin-bottom: ${spacing.xsmall};
71
- padding: ${spacing.small};
72
- ${mq.range({ from: breakpoints.tablet })} {
73
- padding: ${spacing.small} ${spacing.normal};
74
- }
75
- `;
76
-
77
- const File = ({ file }: Props) => {
78
- const formatLinks = file.formats.map((format, index) =>
79
- renderFormat(format, file.title, index === 0, !file.fileExists),
108
+ return (
109
+ <FileListItem>
110
+ <Format format={{ url, fileType, tooltip }} isPrimary title={title} isDeadLink={!fileExists} />
111
+ </FileListItem>
80
112
  );
81
-
82
- return <FileListItem key={file.title}>{formatLinks}</FileListItem>;
83
113
  };
84
114
 
85
115
  export default File;
@@ -7,14 +7,14 @@
7
7
  */
8
8
 
9
9
  import { Meta, StoryObj } from '@storybook/react';
10
- import FileV2 from './FileV2';
10
+ import File from './File';
11
11
  import { defaultParameters } from '../../../../stories/defaults';
12
- import FileListV2 from './FileListV2';
12
+ import FileList from './FileList';
13
13
 
14
14
  export default {
15
15
  title: 'Components/FileList',
16
16
  tags: ['autodocs'],
17
- component: FileV2,
17
+ component: File,
18
18
  parameters: {
19
19
  inlineStories: true,
20
20
  ...defaultParameters,
@@ -26,23 +26,23 @@ export default {
26
26
  fileType: 'pdf',
27
27
  },
28
28
  render: (args) => (
29
- <FileListV2>
30
- <FileV2 {...args} />
31
- </FileListV2>
29
+ <FileList>
30
+ <File {...args} />
31
+ </FileList>
32
32
  ),
33
- } as Meta<typeof FileV2>;
33
+ } as Meta<typeof File>;
34
34
 
35
- export const FileNotFound: StoryObj<typeof FileV2> = {
35
+ export const FileNotFound: StoryObj<typeof File> = {
36
36
  args: { fileExists: false },
37
37
  };
38
38
 
39
- export const SeveralFiles: StoryObj<typeof FileV2> = {
39
+ export const SeveralFiles: StoryObj<typeof File> = {
40
40
  render: () => (
41
- <FileListV2>
42
- <FileV2 title="Fil 1" url="https://ndla.no/1" fileExists fileType="mp4" />
43
- <FileV2 title="Fil 2" url="https://ndla.no/2" fileExists={false} fileType="pdf" />
44
- <FileV2 title="Fil 3" url="https://ndla.no/3" fileExists fileType="docx" />
45
- <FileV2 title="Fil 4" url="https://ndla.no/4" fileExists fileType="docx" />
46
- </FileListV2>
41
+ <FileList>
42
+ <File title="Fil 1" url="https://ndla.no/1" fileExists fileType="mp4" />
43
+ <File title="Fil 2" url="https://ndla.no/2" fileExists={false} fileType="pdf" />
44
+ <File title="Fil 3" url="https://ndla.no/3" fileExists fileType="docx" />
45
+ <File title="Fil 4" url="https://ndla.no/4" fileExists fileType="docx" />
46
+ </FileList>
47
47
  ),
48
48
  };
@@ -1,23 +1,18 @@
1
+ /**
2
+ * Copyright (c) 2023-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
+
1
9
  import styled from '@emotion/styled';
2
10
  import { colors, fonts, spacing } from '@ndla/core';
3
- import File from './File';
4
-
5
- export interface FileType {
6
- title: string;
7
- formats: FileFormat[];
8
- fileExists?: boolean;
9
- }
10
-
11
- export interface FileFormat {
12
- url: string;
13
- fileType: string;
14
- tooltip: string;
15
- }
11
+ import { ReactNode } from 'react';
12
+ import { useTranslation } from 'react-i18next';
16
13
 
17
14
  interface Props {
18
- id: string;
19
- heading: string;
20
- files: FileType[];
15
+ children: ReactNode;
21
16
  }
22
17
 
23
18
  const FileListSection = styled.section`
@@ -35,7 +30,7 @@ const FileListSection = styled.section`
35
30
  }
36
31
  `;
37
32
 
38
- const FileListHeading = styled.h1`
33
+ const FileListHeading = styled.h3`
39
34
  ${fonts.sizes('16px', '18px')};
40
35
  letter-spacing: 0.05em;
41
36
  margin: 0 0 ${spacing.xsmall} 0;
@@ -50,15 +45,14 @@ const FilesList = styled.ul`
50
45
  padding: 0;
51
46
  `;
52
47
 
53
- const FileList = ({ files, heading, id }: Props) => (
54
- <FileListSection>
55
- <FileListHeading>{heading}</FileListHeading>
56
- <FilesList>
57
- {files.map((file) => (
58
- <File key={`file-${id}-${file.title}`} file={file} />
59
- ))}
60
- </FilesList>
61
- </FileListSection>
62
- );
48
+ const FileList = ({ children }: Props) => {
49
+ const { t } = useTranslation();
50
+ return (
51
+ <FileListSection>
52
+ <FileListHeading>{t('files')}</FileListHeading>
53
+ <FilesList>{children}</FilesList>
54
+ </FileListSection>
55
+ );
56
+ };
63
57
 
64
58
  export default FileList;
@@ -1,8 +1,6 @@
1
1
  import FileList from './FileList';
2
2
 
3
3
  export { default as File } from './File';
4
- export { default as FileListV2 } from './FileListV2';
5
4
  export { default as PdfFile } from './PdfFile';
6
- export { default as FileV2 } from './FileV2';
7
5
 
8
6
  export default FileList;
@@ -15,7 +15,7 @@ import { breakpoints, colors, spacing, mq } from '@ndla/core';
15
15
  import { LinkBlockEmbedData } from '@ndla/types-embed';
16
16
  import { useMemo } from 'react';
17
17
  import { Heading } from '@ndla/typography';
18
- import { usePossiblyRelativeUrl } from '../utils/relativeUrl';
18
+ import { getPossiblyRelativeUrl } from '../utils/relativeUrl';
19
19
 
20
20
  const StyledForward = styled(Forward)`
21
21
  margin: 0 ${spacing.nsmall};
@@ -78,7 +78,7 @@ interface Props extends Omit<LinkBlockEmbedData, 'resource'> {
78
78
  }
79
79
 
80
80
  const LinkBlock = ({ title, language, date, url, path }: Props) => {
81
- const href = usePossiblyRelativeUrl(url, path);
81
+ const href = getPossiblyRelativeUrl(url, path);
82
82
  const formattedDate = useMemo(() => {
83
83
  if (!date) return null;
84
84
  const locale = language === 'nb' ? nb : language === 'nn' ? nn : enGB;
@@ -6,8 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- import MessageBoxTag from './MessageBoxTag';
10
9
  import MessageBox from './MessageBox';
11
10
  import MessageBanner from './MessageBanner';
12
11
 
13
- export { MessageBox, MessageBoxTag, MessageBanner };
12
+ export { MessageBox, MessageBanner };
@@ -7,6 +7,5 @@
7
7
  */
8
8
 
9
9
  import NavigationBox from './NavigationBox';
10
- import NavigationTopicAbout from './NavigationTopicAbout';
11
10
 
12
- export { NavigationBox, NavigationTopicAbout };
11
+ export { NavigationBox };