@ndla/ui 3.2.1-alpha.5 → 3.2.3

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 (188) hide show
  1. package/es/Article/ArticleAuthorContent.js +1 -2
  2. package/es/Article/ArticleSideBar.js +42 -14
  3. package/es/AuthorInfo/AuthorInfo.js +1 -2
  4. package/es/BackgroundImage/BackgroundImage.js +5 -15
  5. package/es/ContentLoader/index.js +14 -27
  6. package/es/Dialog/Dialog.js +10 -28
  7. package/es/FactBox/FactBox.js +7 -11
  8. package/es/Figure/Figure.js +13 -41
  9. package/es/Figure/FigureExpandButton.js +2 -11
  10. package/es/Figure/FigureLicense.js +4 -24
  11. package/es/Figure/FigureLicenseDialog.js +2 -20
  12. package/es/FileList/File.js +0 -13
  13. package/es/FileList/FileList.js +0 -13
  14. package/es/Hero/Hero.js +0 -6
  15. package/es/Image/Image.js +4 -27
  16. package/es/Image/ImageLink.js +3 -12
  17. package/es/Image/LazyLoadImage.js +4 -13
  18. package/es/InfoBox/InfoBox.js +0 -4
  19. package/es/InfoWidget/InfoWidget.js +2 -21
  20. package/es/Logo/Logo.js +6 -22
  21. package/es/Logo/SvgLogo.js +4 -12
  22. package/es/Masthead/Masthead.js +12 -33
  23. package/es/NoContentBox/NoContentBox.js +2 -11
  24. package/es/Portrait/Portrait.js +0 -11
  25. package/es/RelatedArticleList/RelatedArticleList.js +4 -23
  26. package/es/ResourcesWrapper/ResourcesTitle.js +0 -4
  27. package/es/ResourcesWrapper/ResourcesTopicTitle.js +12 -25
  28. package/es/ResourcesWrapper/ResourcesWrapper.js +2 -11
  29. package/es/Topic/Topic.js +21 -22
  30. package/es/Translation/Translation.js +0 -5
  31. package/es/Translation/TranslationBox.js +7 -3
  32. package/es/Translation/TranslationLine.js +4 -15
  33. package/es/index-javascript.js +1 -19
  34. package/es/index.js +18 -0
  35. package/es/locale/messages-en.js +4 -0
  36. package/es/locale/messages-nb.js +5 -1
  37. package/es/locale/messages-nn.js +5 -1
  38. package/lib/Article/ArticleSideBar.d.ts +2 -1
  39. package/lib/Article/ArticleSideBar.js +43 -14
  40. package/lib/BackgroundImage/BackgroundImage.d.ts +11 -0
  41. package/lib/BackgroundImage/BackgroundImage.js +5 -17
  42. package/lib/BackgroundImage/index.d.ts +2 -0
  43. package/lib/ContentLoader/index.d.ts +20 -0
  44. package/lib/ContentLoader/index.js +14 -28
  45. package/lib/Dialog/Dialog.d.ts +23 -0
  46. package/lib/Dialog/Dialog.js +9 -29
  47. package/lib/Dialog/index.d.ts +10 -0
  48. package/lib/FactBox/FactBox.d.ts +16 -0
  49. package/lib/FactBox/FactBox.js +5 -11
  50. package/lib/FactBox/index.d.ts +2 -0
  51. package/lib/Figure/Figure.d.ts +49 -0
  52. package/lib/Figure/Figure.js +11 -41
  53. package/lib/Figure/FigureExpandButton.d.ts +16 -0
  54. package/lib/Figure/FigureExpandButton.js +2 -13
  55. package/lib/Figure/FigureLicense.d.ts +33 -0
  56. package/lib/Figure/FigureLicense.js +5 -27
  57. package/lib/Figure/FigureLicenseDialog.d.ts +29 -0
  58. package/lib/Figure/FigureLicenseDialog.js +1 -22
  59. package/lib/Figure/index.d.ts +12 -0
  60. package/lib/FileList/File.d.ts +7 -0
  61. package/lib/FileList/File.js +0 -14
  62. package/lib/FileList/FileList.d.ts +17 -0
  63. package/lib/FileList/FileList.js +0 -14
  64. package/lib/FileList/index.d.ts +3 -0
  65. package/lib/Hero/Hero.d.ts +27 -0
  66. package/lib/Hero/Hero.js +0 -8
  67. package/lib/Hero/index.d.ts +9 -0
  68. package/lib/Image/Image.d.ts +34 -0
  69. package/lib/Image/Image.js +4 -28
  70. package/lib/Image/ImageLink.d.ts +18 -0
  71. package/lib/Image/ImageLink.js +3 -15
  72. package/lib/Image/LazyLoadImage.d.ts +17 -0
  73. package/lib/Image/LazyLoadImage.js +3 -13
  74. package/lib/Image/index.d.ts +12 -0
  75. package/lib/InfoBox/InfoBox.d.ts +6 -0
  76. package/lib/InfoBox/InfoBox.js +0 -5
  77. package/{src/InfoBox/index.js → lib/InfoBox/index.d.ts} +0 -0
  78. package/lib/InfoWidget/InfoWidget.d.ts +19 -0
  79. package/lib/InfoWidget/InfoWidget.js +2 -22
  80. package/lib/InfoWidget/index.d.ts +2 -0
  81. package/lib/Logo/Logo.d.ts +24 -0
  82. package/lib/Logo/Logo.js +6 -29
  83. package/lib/Logo/SvgLogo.d.ts +14 -0
  84. package/lib/Logo/SvgLogo.js +4 -13
  85. package/lib/Logo/index.d.ts +9 -0
  86. package/lib/Masthead/Masthead.d.ts +27 -0
  87. package/lib/Masthead/Masthead.js +10 -34
  88. package/lib/Masthead/index.d.ts +10 -0
  89. package/lib/NoContentBox/NoContentBox.d.ts +14 -0
  90. package/lib/NoContentBox/NoContentBox.js +1 -11
  91. package/lib/NoContentBox/index.d.ts +9 -0
  92. package/lib/Portrait/Portrait.d.ts +15 -0
  93. package/lib/Portrait/Portrait.js +0 -12
  94. package/lib/Portrait/index.d.ts +9 -0
  95. package/lib/RelatedArticleList/RelatedArticleList.d.ts +25 -0
  96. package/lib/RelatedArticleList/RelatedArticleList.js +2 -23
  97. package/lib/RelatedArticleList/index.d.ts +10 -0
  98. package/lib/ResourcesWrapper/ResourcesTitle.d.ts +13 -0
  99. package/lib/ResourcesWrapper/ResourcesTitle.js +0 -5
  100. package/lib/ResourcesWrapper/ResourcesTopicTitle.d.ts +13 -0
  101. package/lib/ResourcesWrapper/ResourcesTopicTitle.js +11 -26
  102. package/lib/ResourcesWrapper/ResourcesWrapper.d.ts +18 -0
  103. package/lib/ResourcesWrapper/ResourcesWrapper.js +2 -12
  104. package/lib/ResourcesWrapper/index.d.ts +11 -0
  105. package/lib/Topic/Topic.d.ts +3 -2
  106. package/lib/Topic/Topic.js +20 -20
  107. package/lib/Translation/Translation.d.ts +14 -0
  108. package/lib/Translation/Translation.js +0 -6
  109. package/lib/Translation/TranslationBox.d.ts +10 -0
  110. package/lib/Translation/TranslationBox.js +6 -2
  111. package/lib/Translation/TranslationLine.d.ts +16 -0
  112. package/lib/Translation/TranslationLine.js +4 -22
  113. package/{src/Translation/index.js → lib/Translation/index.d.ts} +0 -0
  114. package/lib/index-javascript.js +0 -250
  115. package/lib/index.d.ts +18 -0
  116. package/lib/index.js +286 -0
  117. package/lib/locale/messages-en.d.ts +4 -0
  118. package/lib/locale/messages-en.js +4 -0
  119. package/lib/locale/messages-nb.d.ts +4 -0
  120. package/lib/locale/messages-nb.js +5 -1
  121. package/lib/locale/messages-nn.d.ts +4 -0
  122. package/lib/locale/messages-nn.js +5 -1
  123. package/lib/utils/createUniversalPortal.d.ts +9 -0
  124. package/package.json +6 -6
  125. package/src/Article/ArticleAuthorContent.tsx +0 -1
  126. package/src/Article/ArticleSideBar.tsx +31 -3
  127. package/src/AuthorInfo/AuthorInfo.tsx +0 -1
  128. package/src/BackgroundImage/BackgroundImage.tsx +32 -0
  129. package/src/BackgroundImage/{index.js → index.ts} +0 -0
  130. package/src/ContentLoader/{index.js → index.tsx} +20 -30
  131. package/src/Dialog/{Dialog.jsx → Dialog.tsx} +20 -32
  132. package/src/Dialog/{index.js → index.ts} +0 -0
  133. package/src/FactBox/{FactBox.jsx → FactBox.tsx} +12 -14
  134. package/src/FactBox/{index.js → index.ts} +0 -0
  135. package/src/Figure/{Figure.js → Figure.tsx} +46 -53
  136. package/src/Figure/{FigureExpandButton.js → FigureExpandButton.tsx} +8 -9
  137. package/src/Figure/{FigureLicense.js → FigureLicense.tsx} +32 -30
  138. package/src/Figure/{FigureLicenseDialog.js → FigureLicenseDialog.tsx} +22 -22
  139. package/src/Figure/{index.js → index.ts} +0 -0
  140. package/src/FileList/{File.jsx → File.tsx} +8 -18
  141. package/src/FileList/FileList.tsx +36 -0
  142. package/src/FileList/{index.js → index.ts} +0 -0
  143. package/src/Hero/Hero.tsx +58 -0
  144. package/src/Hero/{index.js → index.ts} +2 -0
  145. package/src/Image/{Image.jsx → Image.tsx} +40 -30
  146. package/src/Image/{ImageLink.js → ImageLink.tsx} +11 -12
  147. package/src/Image/LazyLoadImage.tsx +40 -0
  148. package/src/Image/__tests__/__snapshots__/Image-test.jsx.snap +4 -3
  149. package/src/Image/{index.js → index.ts} +1 -0
  150. package/src/InfoBox/InfoBox.tsx +11 -0
  151. package/src/InfoBox/index.ts +1 -0
  152. package/src/InfoWidget/{InfoWidget.jsx → InfoWidget.tsx} +19 -26
  153. package/src/InfoWidget/{index.js → index.ts} +0 -0
  154. package/src/Logo/{Logo.jsx → Logo.tsx} +21 -28
  155. package/src/Logo/{SvgLogo.jsx → SvgLogo.tsx} +8 -14
  156. package/src/Logo/{index.js → index.ts} +0 -0
  157. package/src/Masthead/{Masthead.jsx → Masthead.tsx} +33 -35
  158. package/src/Masthead/{index.js → index.ts} +0 -0
  159. package/src/NoContentBox/{NoContentBox.jsx → NoContentBox.tsx} +7 -13
  160. package/src/NoContentBox/{index.js → index.ts} +0 -0
  161. package/src/Portrait/{Portrait.jsx → Portrait.tsx} +8 -14
  162. package/src/Portrait/{index.js → index.ts} +0 -0
  163. package/src/RelatedArticleList/{RelatedArticleList.jsx → RelatedArticleList.tsx} +43 -30
  164. package/src/RelatedArticleList/{index.js → index.ts} +0 -0
  165. package/src/ResourcesWrapper/{ResourcesTitle.jsx → ResourcesTitle.tsx} +5 -7
  166. package/src/ResourcesWrapper/{ResourcesTopicTitle.jsx → ResourcesTopicTitle.tsx} +23 -22
  167. package/src/ResourcesWrapper/{ResourcesWrapper.jsx → ResourcesWrapper.tsx} +9 -14
  168. package/src/ResourcesWrapper/{index.js → index.ts} +0 -0
  169. package/src/Topic/Topic.tsx +3 -4
  170. package/src/Translation/{Translation.jsx → Translation.tsx} +7 -8
  171. package/src/Translation/TranslationBox.tsx +20 -0
  172. package/src/Translation/{TranslationLine.jsx → TranslationLine.tsx} +11 -18
  173. package/src/Translation/index.ts +3 -0
  174. package/src/index-javascript.js +0 -33
  175. package/src/index.ts +43 -0
  176. package/src/locale/messages-en.ts +4 -0
  177. package/src/locale/messages-nb.ts +5 -1
  178. package/src/locale/messages-nn.ts +5 -1
  179. package/src/utils/{createUniversalPortal.jsx → createUniversalPortal.tsx} +3 -3
  180. package/es/Image/shapes.js +0 -18
  181. package/lib/Image/shapes.js +0 -33
  182. package/src/BackgroundImage/BackgroundImage.jsx +0 -39
  183. package/src/FileList/FileList.jsx +0 -36
  184. package/src/Hero/Hero.jsx +0 -38
  185. package/src/Image/LazyLoadImage.jsx +0 -39
  186. package/src/Image/shapes.js +0 -21
  187. package/src/InfoBox/InfoBox.jsx +0 -13
  188. package/src/Translation/TranslationBox.jsx +0 -12
@@ -6,21 +6,31 @@
6
6
  *
7
7
  */
8
8
 
9
- import React from 'react';
10
- import PropTypes from 'prop-types';
9
+ import React, { ReactNode } from 'react';
11
10
  import { uuid } from '@ndla/util';
12
11
 
12
+ interface Props {
13
+ children?: ReactNode;
14
+ speed?: number;
15
+ width?: number;
16
+ height?: number;
17
+ primaryColor?: string;
18
+ secondaryColor?: string;
19
+ preserveAspectRatio?: string;
20
+ className?: string;
21
+ }
22
+
13
23
  const ContentLoader = ({
14
24
  children,
15
- width,
16
- height,
17
- preserveAspectRatio,
18
- className,
19
- primaryColor,
20
- secondaryColor,
21
- speed,
25
+ width = 400,
26
+ height = 130,
27
+ preserveAspectRatio = 'xMidYMid meet',
28
+ className = '',
29
+ primaryColor = '#f0f0f0',
30
+ secondaryColor = '#e0e0e0',
31
+ speed = 2,
22
32
  ...rest
23
- }) => {
33
+ }: Props) => {
24
34
  const idClip = uuid();
25
35
  const idGradient = uuid();
26
36
 
@@ -59,24 +69,4 @@ const ContentLoader = ({
59
69
  );
60
70
  };
61
71
 
62
- ContentLoader.propTypes = {
63
- children: PropTypes.node,
64
- speed: PropTypes.number,
65
- width: PropTypes.number,
66
- height: PropTypes.number,
67
- primaryColor: PropTypes.string,
68
- secondaryColor: PropTypes.string,
69
- preserveAspectRatio: PropTypes.string,
70
- className: PropTypes.string,
71
- };
72
-
73
- ContentLoader.defaultProps = {
74
- speed: 2,
75
- width: 400,
76
- height: 130,
77
- primaryColor: '#f0f0f0',
78
- secondaryColor: '#e0e0e0',
79
- preserveAspectRatio: 'xMidYMid meet',
80
- className: '',
81
- };
82
72
  export default ContentLoader;
@@ -9,10 +9,9 @@
9
9
  // N.B These component is used to render static markup serverside
10
10
  // Any interactivty is added by scripts located in the ndla-article-scripts package
11
11
 
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
12
+ import React, { ReactNode } from 'react';
14
13
  import BEMHelper from 'react-bem-helper';
15
-
14
+ //@ts-ignore
16
15
  import { createUniversalPortal } from '../utils/createUniversalPortal';
17
16
 
18
17
  const classes = new BEMHelper({
@@ -20,18 +19,32 @@ const classes = new BEMHelper({
20
19
  prefix: 'c-',
21
20
  });
22
21
 
22
+ interface Props {
23
+ id: string;
24
+ labelledby?: string;
25
+ label?: string;
26
+ hidden?: boolean;
27
+ children?: ReactNode;
28
+ messages?: {
29
+ close: string;
30
+ };
31
+ modifier?: string | string[];
32
+ disablePortal?: boolean;
33
+ onClose?: () => void;
34
+ }
35
+
23
36
  export const Dialog = ({
24
37
  children,
25
- messages,
38
+ messages = { close: 'Lukk' },
26
39
  id,
27
40
  labelledby,
28
41
  label,
29
42
  modifier,
30
- disablePortal,
31
- hidden,
43
+ disablePortal = false,
44
+ hidden = true,
32
45
  onClose,
33
46
  ...rest
34
- }) => {
47
+ }: Props) => {
35
48
  const content = (
36
49
  <div
37
50
  {...classes('', modifier)}
@@ -64,28 +77,3 @@ export const Dialog = ({
64
77
 
65
78
  return createUniversalPortal(content, 'body');
66
79
  };
67
-
68
- Dialog.propTypes = {
69
- id: PropTypes.string.isRequired,
70
- labelledby: PropTypes.string,
71
- label: PropTypes.string,
72
- hidden: PropTypes.bool,
73
- children: PropTypes.node,
74
- messages: PropTypes.shape({
75
- close: PropTypes.string.isRequired,
76
- }),
77
- modifier: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
78
- disablePortal: PropTypes.bool,
79
- onClose: PropTypes.func,
80
- };
81
-
82
- Dialog.defaultProps = {
83
- disablePortal: false,
84
- labelledby: null,
85
- label: null,
86
- hidden: true,
87
- onClose: null,
88
- messages: {
89
- close: 'Lukk',
90
- },
91
- };
File without changes
@@ -6,15 +6,15 @@
6
6
  *
7
7
  */
8
8
 
9
- import React from 'react';
10
- import PropTypes from 'prop-types';
9
+ import React, { ReactNode, MouseEvent } from 'react';
11
10
  import BEMHelper from 'react-bem-helper';
11
+ //@ts-ignore
12
12
  import Button from '@ndla/button';
13
13
 
14
- const toggleFactBox = (event) => {
15
- const button = event.target;
16
- const aside = button.previousSibling.parentNode;
17
- aside.classList.toggle('expanded');
14
+ const toggleFactBox = (event: MouseEvent<HTMLButtonElement>) => {
15
+ const button = event.currentTarget;
16
+ const aside = button?.previousSibling?.parentElement;
17
+ aside?.classList?.toggle('expanded');
18
18
  };
19
19
 
20
20
  const classes = new BEMHelper({
@@ -22,7 +22,12 @@ const classes = new BEMHelper({
22
22
  prefix: 'c-',
23
23
  });
24
24
 
25
- const FactBox = ({ children, dangerouslySetInnerHTML }) => (
25
+ interface Props {
26
+ dangerouslySetInnerHTML?: { __html: string };
27
+ children?: ReactNode;
28
+ }
29
+
30
+ const FactBox = ({ children, dangerouslySetInnerHTML }: Props) => (
26
31
  <aside {...classes()}>
27
32
  <div {...classes('content')} dangerouslySetInnerHTML={dangerouslySetInnerHTML}>
28
33
  {children}
@@ -31,11 +36,4 @@ const FactBox = ({ children, dangerouslySetInnerHTML }) => (
31
36
  </aside>
32
37
  );
33
38
 
34
- FactBox.propTypes = {
35
- dangerouslySetInnerHTML: PropTypes.shape({
36
- __html: PropTypes.string.isRequired,
37
- }),
38
- children: PropTypes.node,
39
- };
40
-
41
39
  export default FactBox;
File without changes
@@ -9,14 +9,14 @@
9
9
  // N.B These component is used to render static markup serverside
10
10
  // Any interactivty is added by scripts located in the ndla-article-scripts package
11
11
 
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
12
+ import React, { ReactNode } from 'react';
14
13
  import BEMHelper from 'react-bem-helper';
15
- import { isFunction, parseMarkdown } from '@ndla/util';
14
+ import { isFunction as isFunctionHelper, parseMarkdown } from '@ndla/util';
16
15
  import { useTranslation } from 'react-i18next';
17
16
  import { Link as LinkIcon } from '@ndla/icons/common';
18
17
  import { LicenseByline } from '@ndla/licenses';
19
18
  import SafeLink from '@ndla/safelink';
19
+ //@ts-ignore
20
20
  import Button from '@ndla/button';
21
21
 
22
22
  const classes = new BEMHelper({
@@ -36,16 +36,16 @@ export const FigureCaption = ({
36
36
  link,
37
37
  hideFigcaption,
38
38
  hasLinkedVideo,
39
- }) => {
39
+ }: FigureCaptionProps) => {
40
40
  const { t } = useTranslation();
41
41
  return (
42
- <figcaption {...classes('caption', hideFigcaption && 'hidden-caption')}>
42
+ <figcaption {...classes('caption', hideFigcaption ? 'hidden-caption' : undefined)}>
43
43
  {caption ? <div {...classes('info')}>{parseMarkdown(caption)}</div> : null}
44
44
  <footer {...classes('byline')}>
45
45
  <div {...classes('byline-licenselist')}>
46
46
  <LicenseByline licenseRights={licenseRights} locale={locale} marginRight>
47
47
  <div {...classes('byline-author-buttons')}>
48
- <span {...classes('byline-authors')}>{authors.map((author) => author.name).join(', ')}</span>
48
+ <span {...classes('byline-authors')}>{authors?.map((author) => author.name).join(', ')}</span>
49
49
  <div>
50
50
  <Button
51
51
  borderShape="rounded"
@@ -76,8 +76,8 @@ export const FigureCaption = ({
76
76
  <SafeLink
77
77
  to={link.url}
78
78
  {...classes('link')}
79
- target={link.external ? '_blank' : null}
80
- rel={link.external ? 'noopener noreferrer' : null}>
79
+ target={link.external ? '_blank' : undefined}
80
+ rel={link.external ? 'noopener noreferrer' : undefined}>
81
81
  <span {...classes('link-text')}>{link.text}</span>
82
82
  <LinkIcon />
83
83
  </SafeLink>
@@ -90,61 +90,54 @@ export const FigureCaption = ({
90
90
  );
91
91
  };
92
92
 
93
- FigureCaption.propTypes = {
94
- figureId: PropTypes.string.isRequired,
95
- id: PropTypes.string.isRequired,
96
- caption: PropTypes.string,
97
- reuseLabel: PropTypes.string.isRequired,
98
- licenseRights: PropTypes.arrayOf(PropTypes.string).isRequired,
99
- children: PropTypes.node,
100
- authors: PropTypes.arrayOf(
101
- PropTypes.shape({
102
- name: PropTypes.string.isRequired,
103
- }),
104
- ),
105
- link: PropTypes.shape({
106
- url: PropTypes.string.isRequired,
107
- text: PropTypes.string.isRequired,
108
- description: PropTypes.string,
109
- external: PropTypes.bool,
110
- }),
111
- locale: PropTypes.string,
112
- hideFigcaption: PropTypes.bool,
113
- hasLinkedVideo: PropTypes.bool,
114
- };
93
+ export interface FigureLicense {
94
+ short: string;
95
+ title: string;
96
+ userFriendlyTitle: string;
97
+ description: string;
98
+ rights: string[];
99
+ linkText?: string;
100
+ url?: string;
101
+ }
115
102
 
116
- FigureCaption.defaultProps = {
117
- link: null,
118
- };
103
+ interface FigureCaptionProps {
104
+ figureId: string;
105
+ id: string;
106
+ caption?: string;
107
+ reuseLabel: string;
108
+ licenseRights: string[];
109
+ children?: ReactNode;
110
+ authors?: { name: string }[];
111
+ link?: {
112
+ url: string;
113
+ text: string;
114
+ description?: string;
115
+ external?: boolean;
116
+ };
117
+ locale?: string;
118
+ hideFigcaption?: boolean;
119
+ hasLinkedVideo?: boolean;
120
+ }
119
121
 
120
- const Figure = ({ children, type, resizeIframe, ...rest }) => {
122
+ const Figure = ({ children, type = 'full', resizeIframe, ...rest }: Props) => {
121
123
  const typeClass = type === 'full-column' ? 'c-figure--full-column' : `u-float-${type}`;
122
124
  return (
123
- <figure data-sizetype={type} {...classes('', { resize: resizeIframe }, typeClass)} {...rest}>
125
+ <figure data-sizetype={type} {...classes('', { resize: !!resizeIframe }, typeClass)} {...rest}>
124
126
  {isFunction(children) ? children({ typeClass }) : children}
125
127
  </figure>
126
128
  );
127
129
  };
128
130
 
129
- Figure.propTypes = {
130
- id: PropTypes.string.isRequired,
131
- children: PropTypes.oneOfType([PropTypes.node.isRequired, PropTypes.func.isRequired]).isRequired,
132
- type: PropTypes.oneOf([
133
- 'full',
134
- 'full-column',
135
- 'left',
136
- 'small-left',
137
- 'right',
138
- 'small-right',
139
- 'xsmall-right',
140
- 'xsmall-left',
141
- ]),
142
- resizeIframe: PropTypes.bool,
143
- noFigcaption: PropTypes.bool,
131
+ const isFunction = (children: Function | ReactNode): children is Function => {
132
+ return isFunctionHelper(children);
144
133
  };
145
134
 
146
- Figure.defaultProps = {
147
- type: 'full',
148
- };
135
+ interface Props {
136
+ id: string;
137
+ children: ReactNode | ((params: { typeClass: string }) => ReactNode);
138
+ type: 'full' | 'full-column' | 'left' | 'small-left' | 'right' | 'small-right' | 'xsmall-right' | 'xsmall-left';
139
+ resizeIframe?: boolean;
140
+ noFigcaption?: boolean;
141
+ }
149
142
 
150
143
  export default Figure;
@@ -7,11 +7,10 @@
7
7
  */
8
8
 
9
9
  import React from 'react';
10
- import PropTypes from 'prop-types';
11
10
  import { ArrowCollapse } from '@ndla/icons/common';
12
11
  import { ExpandTwoArrows } from '@ndla/icons/action';
13
12
 
14
- export function FigureExpandButton({ children, messages, typeClass }) {
13
+ export function FigureExpandButton({ messages, typeClass }: Props) {
15
14
  return (
16
15
  <button
17
16
  className="c-figure__fullscreen-btn"
@@ -27,10 +26,10 @@ export function FigureExpandButton({ children, messages, typeClass }) {
27
26
  );
28
27
  }
29
28
 
30
- FigureExpandButton.propTypes = {
31
- messages: PropTypes.shape({
32
- zoomImageButtonLabel: PropTypes.string.isRequired,
33
- zoomOutImageButtonLabel: PropTypes.string.isRequired,
34
- }),
35
- typeClass: PropTypes.string.isRequired,
36
- };
29
+ interface Props {
30
+ messages: {
31
+ zoomImageButtonLabel: string;
32
+ zoomOutImageButtonLabel: string;
33
+ };
34
+ typeClass: string;
35
+ }
@@ -9,23 +9,34 @@
9
9
  // N.B This component is used to render static markup serverside
10
10
  // Any interactivty is added by scripts located in the ndla-article-scripts package
11
11
 
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
12
+ import React, { ReactNode } from 'react';
14
13
  import BEMHelper from 'react-bem-helper';
15
14
  import { uuid } from '@ndla/util';
16
15
  import { LicenseDescription } from '@ndla/licenses';
17
- import { ContributorShape, LicenseShape } from '../shapes';
16
+ import { FigureLicense } from './Figure';
17
+ import { Contributor } from '../types';
18
18
 
19
19
  export const classLicenses = new BEMHelper({
20
20
  name: 'figure-license',
21
21
  prefix: 'c-',
22
22
  });
23
23
 
24
- export const FigureLicenseCta = ({ children, messages, authors, origin, title }) => (
24
+ interface FigureLicenseCtaProps {
25
+ children?: ReactNode;
26
+ origin?: string;
27
+ authors?: Contributor[];
28
+ messages: {
29
+ source: string;
30
+ title: string;
31
+ };
32
+ title?: string;
33
+ }
34
+
35
+ export const FigureLicenseCta = ({ children, messages, authors, origin, title }: FigureLicenseCtaProps) => (
25
36
  <div {...classLicenses('cta-wrapper')}>
26
37
  <ul {...classLicenses('list')}>
27
38
  {title && <li {...classLicenses('item')}>{`${messages.title}: ${title}`}</li>}
28
- {authors.map((author) => (
39
+ {authors?.map((author) => (
29
40
  <li key={uuid()} {...classLicenses('item')}>{`${author.type}: ${author.name}`}</li>
30
41
  ))}
31
42
  {origin && (
@@ -45,29 +56,20 @@ export const FigureLicenseCta = ({ children, messages, authors, origin, title })
45
56
  </div>
46
57
  );
47
58
 
48
- FigureLicenseCta.propTypes = {
49
- children: PropTypes.node,
50
- origin: PropTypes.string,
51
- authors: PropTypes.arrayOf(ContributorShape),
52
- messages: PropTypes.shape({
53
- source: PropTypes.string.isRequired,
54
- title: PropTypes.string.isRequired,
55
- }).isRequired,
56
- title: PropTypes.string,
57
- };
58
-
59
- export const FigureLicenseByline = ({ messages, license, locale }) => [
60
- <LicenseDescription key="byline" highlightCC locale={locale} messages={messages} licenseRights={license.rights} />,
61
- <a key="link" {...classLicenses('link')} target="_blank" rel="noopener noreferrer" href={license.url}>
62
- {license.linkText}
63
- </a>,
64
- ];
59
+ interface Props {
60
+ messages: {
61
+ modelPremission?: string;
62
+ learnAboutLicenses: string;
63
+ };
64
+ license: FigureLicense;
65
+ locale: string;
66
+ }
65
67
 
66
- FigureLicenseByline.propTypes = {
67
- messages: PropTypes.shape({
68
- modelPremission: PropTypes.string,
69
- learnAboutLicenses: PropTypes.string.isRequired,
70
- }).isRequired,
71
- license: LicenseShape.isRequired,
72
- locale: PropTypes.string.isRequired,
73
- };
68
+ export const FigureLicenseByline = ({ messages, license, locale }: Props) => (
69
+ <>
70
+ <LicenseDescription key="byline" highlightCC locale={locale} messages={messages} licenseRights={license.rights} />,
71
+ <a key="link" {...classLicenses('link')} target="_blank" rel="noopener noreferrer" href={license.url}>
72
+ {license.linkText}
73
+ </a>
74
+ </>
75
+ );
@@ -9,14 +9,14 @@
9
9
  // N.B This component is used to render static markup serverside
10
10
  // Any interactivty is added by scripts located in the ndla-article-scripts package
11
11
 
12
- import React from 'react';
13
- import PropTypes from 'prop-types';
14
-
12
+ import React, { ReactNode } from 'react';
13
+ //@ts-ignore
15
14
  import Dialog from '../Dialog';
16
- import { ContributorShape, LicenseShape } from '../shapes';
17
15
  import { classLicenses, FigureLicenseByline, FigureLicenseCta } from './FigureLicense';
16
+ import { FigureLicense } from './Figure';
17
+ import { Contributor } from '../types';
18
18
 
19
- export const FigureLicenseDialog = ({ children, messages, id, authors, origin, title, locale, license }) => {
19
+ export const FigureLicenseDialog = ({ children, messages, id, authors, origin, title, locale, license }: Props) => {
20
20
  const headingLabelId = `heading-${id}`;
21
21
  return (
22
22
  <Dialog id={id} labelledby={headingLabelId} messages={messages}>
@@ -33,20 +33,20 @@ export const FigureLicenseDialog = ({ children, messages, id, authors, origin, t
33
33
  );
34
34
  };
35
35
 
36
- FigureLicenseDialog.propTypes = {
37
- id: PropTypes.string.isRequired,
38
- children: PropTypes.node,
39
- origin: PropTypes.string,
40
- authors: PropTypes.arrayOf(ContributorShape),
41
- messages: PropTypes.shape({
42
- modelPremission: PropTypes.string,
43
- close: PropTypes.string.isRequired,
44
- rulesForUse: PropTypes.string.isRequired,
45
- source: PropTypes.string.isRequired,
46
- learnAboutLicenses: PropTypes.string.isRequired,
47
- title: PropTypes.string.isRequired,
48
- }).isRequired,
49
- title: PropTypes.string,
50
- license: LicenseShape.isRequired,
51
- locale: PropTypes.string.isRequired,
52
- };
36
+ interface Props {
37
+ id: string;
38
+ children?: ReactNode;
39
+ origin?: string;
40
+ authors?: Contributor[];
41
+ messages: {
42
+ modelPremission?: string;
43
+ close: string;
44
+ rulesForUse: string;
45
+ source: string;
46
+ learnAboutLicenses: string;
47
+ title: string;
48
+ };
49
+ title?: string;
50
+ license: FigureLicense;
51
+ locale: string;
52
+ }
File without changes
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
  import BEMHelper from 'react-bem-helper';
4
3
  import { Download } from '@ndla/icons/common';
5
4
  import SafeLink from '@ndla/safelink';
5
+ import { FileFormat, FileType } from './FileList';
6
6
 
7
7
  const classes = BEMHelper('c-file-list');
8
8
 
9
- const renderFormat = (format, title, isPrimary, id, isDeadLink) => {
9
+ const renderFormat = (format: FileFormat, title: string, isPrimary: boolean, id: string, isDeadLink: boolean) => {
10
10
  const titleWithFormat = `${title} (${format.fileType.toUpperCase()})`;
11
11
 
12
12
  const formatId = `${id}_${format.fileType}`;
@@ -42,7 +42,12 @@ const renderFormat = (format, title, isPrimary, id, isDeadLink) => {
42
42
  );
43
43
  };
44
44
 
45
- const File = ({ file, id }) => {
45
+ interface Props {
46
+ id: string;
47
+ file: FileType;
48
+ }
49
+
50
+ const File = ({ file, id }: Props) => {
46
51
  const formatLinks = file.formats.map((format, index) =>
47
52
  renderFormat(format, file.title, index === 0, id, !file.fileExists),
48
53
  );
@@ -54,19 +59,4 @@ const File = ({ file, id }) => {
54
59
  );
55
60
  };
56
61
 
57
- File.propTypes = {
58
- id: PropTypes.string.isRequired,
59
- file: PropTypes.shape({
60
- fileExists: PropTypes.bool,
61
- title: PropTypes.string.isRequired,
62
- formats: PropTypes.arrayOf(
63
- PropTypes.shape({
64
- url: PropTypes.string.isRequired,
65
- fileType: PropTypes.string.isRequired,
66
- tooltip: PropTypes.string.isRequired,
67
- }),
68
- ).isRequired,
69
- }),
70
- };
71
-
72
62
  export default File;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import BEMHelper from 'react-bem-helper';
3
+ import File from './File';
4
+
5
+ const classes = BEMHelper('c-file-list');
6
+
7
+ export interface FileType {
8
+ title: string;
9
+ formats: FileFormat[];
10
+ fileExists?: boolean;
11
+ }
12
+
13
+ export interface FileFormat {
14
+ url: string;
15
+ fileType: string;
16
+ tooltip: string;
17
+ }
18
+
19
+ interface Props {
20
+ id: string;
21
+ heading: string;
22
+ files: FileType[];
23
+ }
24
+
25
+ const FileList = ({ files, heading, id }: Props) => (
26
+ <section {...classes()}>
27
+ <h1 {...classes('heading')}>{heading}</h1>
28
+ <ul {...classes('files')}>
29
+ {files.map((file) => (
30
+ <File key={`file-${id}-${file.title}`} file={file} id={id} />
31
+ ))}
32
+ </ul>
33
+ </section>
34
+ );
35
+
36
+ export default FileList;
File without changes
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Copyright (c) 2016-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 React, { ReactNode } from 'react';
10
+ import BEMHelper from 'react-bem-helper';
11
+
12
+ import * as contentTypes from '../model/ContentType';
13
+
14
+ const classes = new BEMHelper({
15
+ name: 'hero',
16
+ prefix: 'c-',
17
+ });
18
+
19
+ export type HeroContentType =
20
+ | 'subject-material'
21
+ | 'tasks-and-activities'
22
+ | 'assessment-resources'
23
+ | 'subject'
24
+ | 'external-learning-resources'
25
+ | 'source-material'
26
+ | 'learning-path'
27
+ | 'topic'
28
+ | 'beta'
29
+ | 'ndla-film'
30
+ | 'ndla-film has-image';
31
+
32
+ interface HeroProps {
33
+ children?: ReactNode;
34
+ contentType: HeroContentType;
35
+ }
36
+
37
+ export const Hero = ({ children, contentType }: HeroProps) => (
38
+ <div {...classes('', contentType)}>{children || null}</div>
39
+ );
40
+
41
+ interface Props {
42
+ children?: ReactNode;
43
+ }
44
+ export const SubjectMaterialHero = (props: Props) => <Hero contentType={contentTypes.SUBJECT_MATERIAL} {...props} />;
45
+ export const TasksAndActivitiesHero = (props: Props) => (
46
+ <Hero contentType={contentTypes.TASKS_AND_ACTIVITIES} {...props} />
47
+ );
48
+ export const AssessmentResourcesHero = (props: Props) => (
49
+ <Hero contentType={contentTypes.ASSESSMENT_RESOURCES} {...props} />
50
+ );
51
+ export const SubjectHero = (props: Props) => <Hero contentType={contentTypes.SUBJECT} {...props} />;
52
+ export const ExternalLearningResourcesHero = (props: Props) => (
53
+ <Hero contentType={contentTypes.EXTERNAL_LEARNING_RESOURCES} {...props} />
54
+ );
55
+ export const SourceMaterialHero = (props: Props) => <Hero contentType={contentTypes.SOURCE_MATERIAL} {...props} />;
56
+ export const NdlaFilmHero = ({ hasImage, ...rest }: Props & { hasImage?: boolean }) => (
57
+ <Hero {...rest} contentType={hasImage ? 'ndla-film has-image' : 'ndla-film'} />
58
+ );
@@ -16,3 +16,5 @@ export {
16
16
  Hero,
17
17
  NdlaFilmHero,
18
18
  } from './Hero';
19
+
20
+ export type { HeroContentType } from './Hero';