@ndla/ui 3.2.1-alpha.3 → 3.2.2

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 (172) hide show
  1. package/es/Article/ArticleAuthorContent.js +1 -2
  2. package/es/AuthorInfo/AuthorInfo.js +1 -2
  3. package/es/BackgroundImage/BackgroundImage.js +5 -15
  4. package/es/ContentLoader/index.js +14 -27
  5. package/es/Dialog/Dialog.js +10 -28
  6. package/es/FactBox/FactBox.js +7 -11
  7. package/es/Figure/Figure.js +9 -41
  8. package/es/Figure/FigureExpandButton.js +2 -11
  9. package/es/Figure/FigureLicense.js +4 -24
  10. package/es/Figure/FigureLicenseDialog.js +2 -20
  11. package/es/FileList/File.js +0 -13
  12. package/es/FileList/FileList.js +0 -13
  13. package/es/Hero/Hero.js +0 -6
  14. package/es/Image/Image.js +4 -27
  15. package/es/Image/ImageLink.js +3 -12
  16. package/es/Image/LazyLoadImage.js +4 -13
  17. package/es/InfoBox/InfoBox.js +0 -4
  18. package/es/InfoWidget/InfoWidget.js +2 -21
  19. package/es/Logo/Logo.js +6 -22
  20. package/es/Logo/SvgLogo.js +4 -12
  21. package/es/Masthead/Masthead.js +12 -33
  22. package/es/NoContentBox/NoContentBox.js +2 -11
  23. package/es/Portrait/Portrait.js +0 -11
  24. package/es/RelatedArticleList/RelatedArticleList.js +4 -23
  25. package/es/Topic/Topic.js +20 -20
  26. package/es/Translation/Translation.js +0 -5
  27. package/es/Translation/TranslationBox.js +7 -3
  28. package/es/Translation/TranslationLine.js +4 -15
  29. package/es/index-javascript.js +1 -18
  30. package/es/index.js +17 -0
  31. package/es/locale/messages-en.js +4 -0
  32. package/es/locale/messages-nb.js +5 -1
  33. package/es/locale/messages-nn.js +5 -1
  34. package/lib/BackgroundImage/BackgroundImage.d.ts +11 -0
  35. package/lib/BackgroundImage/BackgroundImage.js +5 -17
  36. package/lib/BackgroundImage/index.d.ts +2 -0
  37. package/lib/ContentLoader/index.d.ts +20 -0
  38. package/lib/ContentLoader/index.js +14 -28
  39. package/lib/Dialog/Dialog.d.ts +23 -0
  40. package/lib/Dialog/Dialog.js +9 -29
  41. package/lib/Dialog/index.d.ts +10 -0
  42. package/lib/FactBox/FactBox.d.ts +16 -0
  43. package/lib/FactBox/FactBox.js +5 -11
  44. package/lib/FactBox/index.d.ts +2 -0
  45. package/lib/Figure/Figure.d.ts +50 -0
  46. package/lib/Figure/Figure.js +7 -41
  47. package/lib/Figure/FigureExpandButton.d.ts +16 -0
  48. package/lib/Figure/FigureExpandButton.js +2 -13
  49. package/lib/Figure/FigureLicense.d.ts +33 -0
  50. package/lib/Figure/FigureLicense.js +5 -27
  51. package/lib/Figure/FigureLicenseDialog.d.ts +29 -0
  52. package/lib/Figure/FigureLicenseDialog.js +1 -22
  53. package/lib/Figure/index.d.ts +12 -0
  54. package/lib/FileList/File.d.ts +7 -0
  55. package/lib/FileList/File.js +0 -14
  56. package/lib/FileList/FileList.d.ts +17 -0
  57. package/lib/FileList/FileList.js +0 -14
  58. package/lib/FileList/index.d.ts +3 -0
  59. package/lib/Hero/Hero.d.ts +26 -0
  60. package/lib/Hero/Hero.js +0 -8
  61. package/lib/Hero/index.d.ts +8 -0
  62. package/lib/Image/Image.d.ts +25 -0
  63. package/lib/Image/Image.js +4 -28
  64. package/lib/Image/ImageLink.d.ts +18 -0
  65. package/lib/Image/ImageLink.js +3 -15
  66. package/lib/Image/LazyLoadImage.d.ts +17 -0
  67. package/lib/Image/LazyLoadImage.js +3 -13
  68. package/lib/Image/index.d.ts +11 -0
  69. package/lib/InfoBox/InfoBox.d.ts +6 -0
  70. package/lib/InfoBox/InfoBox.js +0 -5
  71. package/{src/InfoBox/index.js → lib/InfoBox/index.d.ts} +0 -0
  72. package/lib/InfoWidget/InfoWidget.d.ts +19 -0
  73. package/lib/InfoWidget/InfoWidget.js +2 -22
  74. package/lib/InfoWidget/index.d.ts +2 -0
  75. package/lib/Logo/Logo.d.ts +24 -0
  76. package/lib/Logo/Logo.js +6 -29
  77. package/lib/Logo/SvgLogo.d.ts +14 -0
  78. package/lib/Logo/SvgLogo.js +4 -13
  79. package/lib/Logo/index.d.ts +9 -0
  80. package/lib/Masthead/Masthead.d.ts +27 -0
  81. package/lib/Masthead/Masthead.js +10 -34
  82. package/lib/Masthead/index.d.ts +10 -0
  83. package/lib/NoContentBox/NoContentBox.d.ts +14 -0
  84. package/lib/NoContentBox/NoContentBox.js +1 -11
  85. package/lib/NoContentBox/index.d.ts +9 -0
  86. package/lib/Portrait/Portrait.d.ts +15 -0
  87. package/lib/Portrait/Portrait.js +0 -12
  88. package/lib/Portrait/index.d.ts +9 -0
  89. package/lib/RelatedArticleList/RelatedArticleList.d.ts +25 -0
  90. package/lib/RelatedArticleList/RelatedArticleList.js +2 -23
  91. package/lib/RelatedArticleList/index.d.ts +10 -0
  92. package/lib/Topic/Topic.d.ts +3 -2
  93. package/lib/Topic/Topic.js +20 -20
  94. package/lib/Translation/Translation.d.ts +14 -0
  95. package/lib/Translation/Translation.js +0 -6
  96. package/lib/Translation/TranslationBox.d.ts +10 -0
  97. package/lib/Translation/TranslationBox.js +6 -2
  98. package/lib/Translation/TranslationLine.d.ts +16 -0
  99. package/lib/Translation/TranslationLine.js +4 -22
  100. package/{src/Translation/index.js → lib/Translation/index.d.ts} +0 -0
  101. package/lib/index-javascript.js +0 -230
  102. package/lib/index.d.ts +17 -0
  103. package/lib/index.js +263 -0
  104. package/lib/locale/messages-en.d.ts +4 -0
  105. package/lib/locale/messages-en.js +4 -0
  106. package/lib/locale/messages-nb.d.ts +4 -0
  107. package/lib/locale/messages-nb.js +5 -1
  108. package/lib/locale/messages-nn.d.ts +4 -0
  109. package/lib/locale/messages-nn.js +5 -1
  110. package/lib/types.d.ts +10 -0
  111. package/lib/utils/createUniversalPortal.d.ts +9 -0
  112. package/package.json +6 -6
  113. package/src/Article/ArticleAuthorContent.tsx +0 -1
  114. package/src/AuthorInfo/AuthorInfo.tsx +0 -1
  115. package/src/BackgroundImage/BackgroundImage.tsx +32 -0
  116. package/src/BackgroundImage/{index.js → index.ts} +0 -0
  117. package/src/ContentLoader/{index.js → index.tsx} +20 -30
  118. package/src/Dialog/{Dialog.jsx → Dialog.tsx} +20 -32
  119. package/src/Dialog/{index.js → index.ts} +0 -0
  120. package/src/FactBox/{FactBox.jsx → FactBox.tsx} +12 -14
  121. package/src/FactBox/{index.js → index.ts} +0 -0
  122. package/src/Figure/{Figure.js → Figure.tsx} +44 -54
  123. package/src/Figure/{FigureExpandButton.js → FigureExpandButton.tsx} +8 -9
  124. package/src/Figure/{FigureLicense.js → FigureLicense.tsx} +32 -30
  125. package/src/Figure/{FigureLicenseDialog.js → FigureLicenseDialog.tsx} +22 -22
  126. package/src/Figure/{index.js → index.ts} +0 -0
  127. package/src/FileList/{File.jsx → File.tsx} +8 -18
  128. package/src/FileList/FileList.tsx +36 -0
  129. package/src/FileList/{index.js → index.ts} +0 -0
  130. package/src/Hero/Hero.tsx +56 -0
  131. package/src/Hero/{index.js → index.ts} +0 -0
  132. package/src/Image/{Image.jsx → Image.tsx} +30 -30
  133. package/src/Image/{ImageLink.js → ImageLink.tsx} +11 -12
  134. package/src/Image/LazyLoadImage.tsx +40 -0
  135. package/src/Image/__tests__/__snapshots__/Image-test.jsx.snap +4 -3
  136. package/src/Image/{index.js → index.ts} +0 -0
  137. package/src/InfoBox/InfoBox.tsx +11 -0
  138. package/src/InfoBox/index.ts +1 -0
  139. package/src/InfoWidget/{InfoWidget.jsx → InfoWidget.tsx} +19 -26
  140. package/src/InfoWidget/{index.js → index.ts} +0 -0
  141. package/src/Logo/{Logo.jsx → Logo.tsx} +21 -28
  142. package/src/Logo/{SvgLogo.jsx → SvgLogo.tsx} +8 -14
  143. package/src/Logo/{index.js → index.ts} +0 -0
  144. package/src/Masthead/{Masthead.jsx → Masthead.tsx} +33 -35
  145. package/src/Masthead/{index.js → index.ts} +0 -0
  146. package/src/NoContentBox/{NoContentBox.jsx → NoContentBox.tsx} +7 -13
  147. package/src/NoContentBox/{index.js → index.ts} +0 -0
  148. package/src/Portrait/{Portrait.jsx → Portrait.tsx} +8 -14
  149. package/src/Portrait/{index.js → index.ts} +0 -0
  150. package/src/RelatedArticleList/{RelatedArticleList.jsx → RelatedArticleList.tsx} +43 -30
  151. package/src/RelatedArticleList/{index.js → index.ts} +0 -0
  152. package/src/Topic/Topic.tsx +3 -2
  153. package/src/Translation/{Translation.jsx → Translation.tsx} +7 -8
  154. package/src/Translation/TranslationBox.tsx +20 -0
  155. package/src/Translation/{TranslationLine.jsx → TranslationLine.tsx} +11 -18
  156. package/src/Translation/index.ts +3 -0
  157. package/src/index-javascript.js +0 -32
  158. package/src/index.ts +41 -0
  159. package/src/locale/messages-en.ts +4 -0
  160. package/src/locale/messages-nb.ts +5 -1
  161. package/src/locale/messages-nn.ts +5 -1
  162. package/src/types.ts +12 -0
  163. package/src/utils/{createUniversalPortal.jsx → createUniversalPortal.tsx} +3 -3
  164. package/es/Image/shapes.js +0 -18
  165. package/lib/Image/shapes.js +0 -33
  166. package/src/BackgroundImage/BackgroundImage.jsx +0 -39
  167. package/src/FileList/FileList.jsx +0 -36
  168. package/src/Hero/Hero.jsx +0 -38
  169. package/src/Image/LazyLoadImage.jsx +0 -39
  170. package/src/Image/shapes.js +0 -21
  171. package/src/InfoBox/InfoBox.jsx +0 -13
  172. package/src/Translation/TranslationBox.jsx +0 -12
@@ -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,15 +9,16 @@
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
  import { isFunction, 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
+ import { License } from '../types';
21
22
 
22
23
  const classes = new BEMHelper({
23
24
  name: 'figure',
@@ -36,16 +37,16 @@ export const FigureCaption = ({
36
37
  link,
37
38
  hideFigcaption,
38
39
  hasLinkedVideo,
39
- }) => {
40
+ }: FigureCaptionProps) => {
40
41
  const { t } = useTranslation();
41
42
  return (
42
- <figcaption {...classes('caption', hideFigcaption && 'hidden-caption')}>
43
+ <figcaption {...classes('caption', hideFigcaption ? 'hidden-caption' : undefined)}>
43
44
  {caption ? <div {...classes('info')}>{parseMarkdown(caption)}</div> : null}
44
45
  <footer {...classes('byline')}>
45
46
  <div {...classes('byline-licenselist')}>
46
47
  <LicenseByline licenseRights={licenseRights} locale={locale} marginRight>
47
48
  <div {...classes('byline-author-buttons')}>
48
- <span {...classes('byline-authors')}>{authors.map((author) => author.name).join(', ')}</span>
49
+ <span {...classes('byline-authors')}>{authors?.map((author) => author.name).join(', ')}</span>
49
50
  <div>
50
51
  <Button
51
52
  borderShape="rounded"
@@ -76,8 +77,8 @@ export const FigureCaption = ({
76
77
  <SafeLink
77
78
  to={link.url}
78
79
  {...classes('link')}
79
- target={link.external ? '_blank' : null}
80
- rel={link.external ? 'noopener noreferrer' : null}>
80
+ target={link.external ? '_blank' : undefined}
81
+ rel={link.external ? 'noopener noreferrer' : undefined}>
81
82
  <span {...classes('link-text')}>{link.text}</span>
82
83
  <LinkIcon />
83
84
  </SafeLink>
@@ -90,61 +91,50 @@ export const FigureCaption = ({
90
91
  );
91
92
  };
92
93
 
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
- };
94
+ export interface FigureLicense extends License {
95
+ short: string;
96
+ title: string;
97
+ userFriendlyTitle: string;
98
+ description: string;
99
+ rights: string[];
100
+ linkText?: string;
101
+ url?: string;
102
+ }
115
103
 
116
- FigureCaption.defaultProps = {
117
- link: null,
118
- };
104
+ interface FigureCaptionProps {
105
+ figureId: string;
106
+ id: string;
107
+ caption?: string;
108
+ reuseLabel: string;
109
+ licenseRights: string[];
110
+ children?: ReactNode;
111
+ authors?: { name: string }[];
112
+ link?: {
113
+ url: string;
114
+ text: string;
115
+ description?: string;
116
+ external?: boolean;
117
+ };
118
+ locale?: string;
119
+ hideFigcaption?: boolean;
120
+ hasLinkedVideo?: boolean;
121
+ }
119
122
 
120
- const Figure = ({ children, type, resizeIframe, ...rest }) => {
123
+ const Figure = ({ children, type = 'full', resizeIframe, ...rest }: Props) => {
121
124
  const typeClass = type === 'full-column' ? 'c-figure--full-column' : `u-float-${type}`;
122
125
  return (
123
- <figure data-sizetype={type} {...classes('', { resize: resizeIframe }, typeClass)} {...rest}>
126
+ <figure data-sizetype={type} {...classes('', { resize: !!resizeIframe }, typeClass)} {...rest}>
124
127
  {isFunction(children) ? children({ typeClass }) : children}
125
128
  </figure>
126
129
  );
127
130
  };
128
131
 
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,
144
- };
145
-
146
- Figure.defaultProps = {
147
- type: 'full',
148
- };
132
+ interface Props {
133
+ id: string;
134
+ children: (params: { typeClass: string }) => ReactNode | ReactNode;
135
+ type: 'full' | 'full-column' | 'left' | 'small-left' | 'right' | 'small-right' | 'xsmall-right' | 'xsmall-left';
136
+ resizeIframe?: boolean;
137
+ noFigcaption?: boolean;
138
+ }
149
139
 
150
140
  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,56 @@
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
+ interface HeroProps {
20
+ children?: ReactNode;
21
+ contentType:
22
+ | 'subject-material'
23
+ | 'tasks-and-activities'
24
+ | 'assessment-resources'
25
+ | 'subject'
26
+ | 'external-learning-resources'
27
+ | 'source-material'
28
+ | 'learning-path'
29
+ | 'topic'
30
+ | 'beta'
31
+ | 'ndla-film'
32
+ | 'ndla-film has-image';
33
+ }
34
+
35
+ export const Hero = ({ children, contentType }: HeroProps) => (
36
+ <div {...classes('', contentType)}>{children || null}</div>
37
+ );
38
+
39
+ interface Props {
40
+ children?: ReactNode;
41
+ }
42
+ export const SubjectMaterialHero = (props: Props) => <Hero contentType={contentTypes.SUBJECT_MATERIAL} {...props} />;
43
+ export const TasksAndActivitiesHero = (props: Props) => (
44
+ <Hero contentType={contentTypes.TASKS_AND_ACTIVITIES} {...props} />
45
+ );
46
+ export const AssessmentResourcesHero = (props: Props) => (
47
+ <Hero contentType={contentTypes.ASSESSMENT_RESOURCES} {...props} />
48
+ );
49
+ export const SubjectHero = (props: Props) => <Hero contentType={contentTypes.SUBJECT} {...props} />;
50
+ export const ExternalLearningResourcesHero = (props: Props) => (
51
+ <Hero contentType={contentTypes.EXTERNAL_LEARNING_RESOURCES} {...props} />
52
+ );
53
+ export const SourceMaterialHero = (props: Props) => <Hero contentType={contentTypes.SOURCE_MATERIAL} {...props} />;
54
+ export const NdlaFilmHero = ({ hasImage, ...rest }: Props & { hasImage?: boolean }) => (
55
+ <Hero {...rest} contentType={hasImage ? 'ndla-film has-image' : 'ndla-film'} />
56
+ );
File without changes
@@ -6,13 +6,13 @@
6
6
  *
7
7
  */
8
8
 
9
- import React from 'react';
9
+ import React, { ReactNode } from 'react';
10
10
  import defined from 'defined';
11
- import PropTypes from 'prop-types';
12
11
  import styled from '@emotion/styled';
13
12
  import LazyLoadImage from './LazyLoadImage';
13
+ import { ImageCrop, ImageFocalPoint } from '../types';
14
14
 
15
- export const makeSrcQueryString = (width, crop, focalPoint) => {
15
+ export const makeSrcQueryString = (width: number | undefined, crop?: ImageCrop, focalPoint?: ImageFocalPoint) => {
16
16
  const widthParams = width && `width=${width}`;
17
17
  const cropParams =
18
18
  crop && `cropStartX=${crop.startX}&cropEndX=${crop.endX}&cropStartY=${crop.startY}&cropEndY=${crop.endY}`;
@@ -22,7 +22,7 @@ export const makeSrcQueryString = (width, crop, focalPoint) => {
22
22
  return params;
23
23
  };
24
24
 
25
- const getSrcSet = (src, crop, focalPoint) => {
25
+ const getSrcSet = (src: string, crop: ImageCrop | undefined, focalPoint: ImageFocalPoint | undefined) => {
26
26
  const widths = [2720, 2080, 1760, 1440, 1120, 1000, 960, 800, 640, 480, 320, 240, 180];
27
27
  return widths.map((width) => `${src}?${makeSrcQueryString(width, crop, focalPoint)} ${width}w`).join(', ');
28
28
  };
@@ -31,7 +31,32 @@ const StyledImageWrapper = styled.div`
31
31
  position: relative;
32
32
  `;
33
33
 
34
- const Image = ({ alt, src, lazyLoad, lazyLoadSrc, crop, focalPoint, contentType, sizes, expandButton, ...rest }) => {
34
+ interface Props {
35
+ alt: string;
36
+ src: string;
37
+ sizes?: string;
38
+ fallbackWidth?: number;
39
+ contentType?: string;
40
+ srcSet?: string;
41
+ lazyLoad?: boolean;
42
+ lazyLoadSrc?: string;
43
+ expandButton?: ReactNode;
44
+ crop?: ImageCrop;
45
+ focalPoint?: ImageFocalPoint;
46
+ }
47
+
48
+ const Image = ({
49
+ alt,
50
+ src,
51
+ lazyLoad,
52
+ lazyLoadSrc,
53
+ crop,
54
+ focalPoint,
55
+ contentType,
56
+ sizes = '(min-width: 1024px) 1024px, 100vw',
57
+ expandButton,
58
+ ...rest
59
+ }: Props) => {
35
60
  const srcSet = defined(rest.srcSet, getSrcSet(src, crop, focalPoint));
36
61
  const fallbackWidth = defined(rest.fallbackWidth, 1024);
37
62
  const queryString = makeSrcQueryString(fallbackWidth, crop, focalPoint);
@@ -69,29 +94,4 @@ const Image = ({ alt, src, lazyLoad, lazyLoadSrc, crop, focalPoint, contentType,
69
94
  );
70
95
  };
71
96
 
72
- Image.propTypes = {
73
- alt: PropTypes.string.isRequired,
74
- src: PropTypes.string.isRequired,
75
- sizes: PropTypes.string,
76
- fallbackWidth: PropTypes.number,
77
- contentType: PropTypes.string,
78
- srcSet: PropTypes.string,
79
- lazyLoad: PropTypes.bool,
80
- lazyLoadSrc: PropTypes.string,
81
- crop: PropTypes.shape({
82
- startX: PropTypes.number.isRequired,
83
- startY: PropTypes.number.isRequired,
84
- endX: PropTypes.number.isRequired,
85
- endY: PropTypes.number.isRequired,
86
- }),
87
- focalPoint: PropTypes.shape({
88
- x: PropTypes.number.isRequired,
89
- y: PropTypes.number.isRequired,
90
- }),
91
- };
92
-
93
- Image.defaultProps = {
94
- sizes: '(min-width: 1024px) 1024px, 100vw',
95
- };
96
-
97
97
  export default Image;
@@ -6,17 +6,24 @@
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 styled from '@emotion/styled';
12
11
  import { makeSrcQueryString } from './Image';
13
- import { FocalPointShape, CropShape } from './shapes';
12
+ import { ImageCrop, ImageFocalPoint } from '../types';
14
13
 
15
14
  const StyledLink = styled.a`
16
15
  box-shadow: inset 0 0;
17
16
  `;
18
17
 
19
- export function ImageLink({ src, crop, children, ...rest }) {
18
+ interface Props {
19
+ src: string;
20
+ children: ReactNode;
21
+ sizes?: string;
22
+ crop?: ImageCrop;
23
+ focalPoint?: ImageFocalPoint;
24
+ }
25
+
26
+ export function ImageLink({ src, crop, children, ...rest }: Props) {
20
27
  return (
21
28
  <StyledLink
22
29
  target="_blank"
@@ -27,11 +34,3 @@ export function ImageLink({ src, crop, children, ...rest }) {
27
34
  </StyledLink>
28
35
  );
29
36
  }
30
-
31
- ImageLink.propTypes = {
32
- src: PropTypes.string.isRequired,
33
- children: PropTypes.node.isRequired,
34
- sizes: PropTypes.string,
35
- crop: CropShape,
36
- focalPoint: FocalPointShape,
37
- };