@ndla/ui 3.2.1-alpha.8 → 3.2.1

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 (159) hide show
  1. package/es/AuthorInfo/AuthorInfo.js +1 -2
  2. package/lib/BackgroundImage/BackgroundImage.d.ts +11 -0
  3. package/{es/BackgroundImage/index.js → lib/BackgroundImage/index.d.ts} +1 -1
  4. package/lib/ContentLoader/index.d.ts +20 -0
  5. package/lib/Dialog/Dialog.d.ts +23 -0
  6. package/{es/Dialog/index.js → lib/Dialog/index.d.ts} +1 -1
  7. package/lib/Figure/Figure.d.ts +50 -0
  8. package/lib/Figure/FigureExpandButton.d.ts +16 -0
  9. package/lib/Figure/FigureLicense.d.ts +33 -0
  10. package/lib/Figure/FigureLicenseDialog.d.ts +29 -0
  11. package/{es/Figure/index.js → lib/Figure/index.d.ts} +1 -1
  12. package/lib/FileList/File.d.ts +7 -0
  13. package/lib/FileList/FileList.d.ts +17 -0
  14. package/{es/FileList/index.js → lib/FileList/index.d.ts} +1 -1
  15. package/lib/Hero/Hero.d.ts +26 -0
  16. package/{es/Hero/index.js → lib/Hero/index.d.ts} +1 -1
  17. package/lib/Image/Image.d.ts +25 -0
  18. package/lib/Image/ImageLink.d.ts +18 -0
  19. package/lib/Image/LazyLoadImage.d.ts +17 -0
  20. package/{es/Image/index.js → lib/Image/index.d.ts} +1 -1
  21. package/lib/InfoBox/InfoBox.d.ts +6 -0
  22. package/{src/InfoBox/index.js → lib/InfoBox/index.d.ts} +0 -0
  23. package/lib/InfoWidget/InfoWidget.d.ts +19 -0
  24. package/{es/InfoWidget/index.js → lib/InfoWidget/index.d.ts} +1 -1
  25. package/lib/Logo/Logo.d.ts +24 -0
  26. package/lib/Logo/SvgLogo.d.ts +14 -0
  27. package/{es/Logo/index.js → lib/Logo/index.d.ts} +1 -1
  28. package/lib/Masthead/Masthead.d.ts +27 -0
  29. package/{es/Masthead/index.js → lib/Masthead/index.d.ts} +1 -1
  30. package/lib/NoContentBox/NoContentBox.d.ts +14 -0
  31. package/{es/NoContentBox/index.js → lib/NoContentBox/index.d.ts} +1 -1
  32. package/lib/Portrait/Portrait.d.ts +15 -0
  33. package/{es/Portrait/index.js → lib/Portrait/index.d.ts} +1 -1
  34. package/lib/Topic/Topic.d.ts +3 -2
  35. package/lib/Translation/Translation.d.ts +14 -0
  36. package/lib/Translation/TranslationBox.d.ts +10 -0
  37. package/lib/Translation/TranslationLine.d.ts +16 -0
  38. package/{src/Translation/index.js → lib/Translation/index.d.ts} +0 -0
  39. package/lib/index.d.ts +14 -0
  40. package/lib/locale/messages-en.d.ts +4 -0
  41. package/lib/locale/messages-nb.d.ts +4 -0
  42. package/lib/locale/messages-nn.d.ts +4 -0
  43. package/lib/types.d.ts +10 -0
  44. package/package.json +6 -6
  45. package/src/Article/ArticleAuthorContent.tsx +0 -1
  46. package/src/AuthorInfo/AuthorInfo.tsx +0 -1
  47. package/src/BackgroundImage/BackgroundImage.tsx +32 -0
  48. package/src/BackgroundImage/{index.js → index.ts} +0 -0
  49. package/src/ContentLoader/{index.js → index.tsx} +20 -30
  50. package/src/Dialog/{Dialog.jsx → Dialog.tsx} +20 -32
  51. package/src/Dialog/{index.js → index.ts} +0 -0
  52. package/src/Figure/{Figure.js → Figure.tsx} +44 -54
  53. package/src/Figure/{FigureExpandButton.js → FigureExpandButton.tsx} +8 -9
  54. package/src/Figure/{FigureLicense.js → FigureLicense.tsx} +32 -30
  55. package/src/Figure/{FigureLicenseDialog.js → FigureLicenseDialog.tsx} +22 -22
  56. package/src/Figure/{index.js → index.ts} +0 -0
  57. package/src/FileList/{File.jsx → File.tsx} +8 -18
  58. package/src/FileList/FileList.tsx +36 -0
  59. package/src/FileList/{index.js → index.ts} +0 -0
  60. package/src/Hero/Hero.tsx +56 -0
  61. package/src/Hero/{index.js → index.ts} +0 -0
  62. package/src/Image/{Image.jsx → Image.tsx} +30 -30
  63. package/src/Image/{ImageLink.js → ImageLink.tsx} +11 -12
  64. package/src/Image/LazyLoadImage.tsx +40 -0
  65. package/src/Image/__tests__/__snapshots__/Image-test.jsx.snap +4 -3
  66. package/src/Image/{index.js → index.ts} +0 -0
  67. package/src/InfoBox/InfoBox.tsx +11 -0
  68. package/src/InfoBox/index.ts +1 -0
  69. package/src/InfoWidget/{InfoWidget.jsx → InfoWidget.tsx} +19 -26
  70. package/src/InfoWidget/{index.js → index.ts} +0 -0
  71. package/src/Logo/{Logo.jsx → Logo.tsx} +21 -28
  72. package/src/Logo/{SvgLogo.jsx → SvgLogo.tsx} +8 -14
  73. package/src/Logo/{index.js → index.ts} +0 -0
  74. package/src/Masthead/{Masthead.jsx → Masthead.tsx} +33 -35
  75. package/src/Masthead/{index.js → index.ts} +0 -0
  76. package/src/NoContentBox/{NoContentBox.jsx → NoContentBox.tsx} +7 -13
  77. package/src/NoContentBox/{index.js → index.ts} +0 -0
  78. package/src/Portrait/{Portrait.jsx → Portrait.tsx} +8 -14
  79. package/src/Portrait/{index.js → index.ts} +0 -0
  80. package/src/Topic/Topic.tsx +3 -2
  81. package/src/Translation/{Translation.jsx → Translation.tsx} +7 -8
  82. package/src/Translation/TranslationBox.tsx +20 -0
  83. package/src/Translation/{TranslationLine.jsx → TranslationLine.tsx} +11 -18
  84. package/{es/Translation/index.js → src/Translation/index.ts} +1 -1
  85. package/src/index-javascript.js +0 -29
  86. package/src/index.ts +35 -0
  87. package/src/locale/messages-en.ts +4 -0
  88. package/src/locale/messages-nb.ts +5 -1
  89. package/src/locale/messages-nn.ts +5 -1
  90. package/src/types.ts +12 -0
  91. package/es/BackgroundImage/BackgroundImage.js +0 -37
  92. package/es/ContentLoader/index.js +0 -96
  93. package/es/Dialog/Dialog.js +0 -82
  94. package/es/Figure/Figure.js +0 -125
  95. package/es/Figure/FigureExpandButton.js +0 -37
  96. package/es/Figure/FigureLicense.js +0 -74
  97. package/es/Figure/FigureLicenseDialog.js +0 -61
  98. package/es/FileList/File.js +0 -61
  99. package/es/FileList/FileList.js +0 -33
  100. package/es/Hero/Hero.js +0 -70
  101. package/es/Image/Image.js +0 -119
  102. package/es/Image/ImageLink.js +0 -55
  103. package/es/Image/LazyLoadImage.js +0 -56
  104. package/es/Image/shapes.js +0 -18
  105. package/es/InfoBox/InfoBox.js +0 -15
  106. package/es/InfoBox/index.js +0 -1
  107. package/es/InfoWidget/InfoWidget.js +0 -76
  108. package/es/Logo/Logo.js +0 -67
  109. package/es/Logo/SvgLogo.js +0 -62
  110. package/es/Masthead/Masthead.js +0 -88
  111. package/es/NoContentBox/NoContentBox.js +0 -35
  112. package/es/Portrait/Portrait.js +0 -41
  113. package/es/Translation/Translation.js +0 -27
  114. package/es/Translation/TranslationBox.js +0 -13
  115. package/es/Translation/TranslationLine.js +0 -48
  116. package/lib/BackgroundImage/BackgroundImage.js +0 -52
  117. package/lib/BackgroundImage/index.js +0 -13
  118. package/lib/ContentLoader/index.js +0 -102
  119. package/lib/Dialog/Dialog.js +0 -90
  120. package/lib/Dialog/index.js +0 -24
  121. package/lib/Figure/Figure.js +0 -139
  122. package/lib/Figure/FigureExpandButton.js +0 -52
  123. package/lib/Figure/FigureLicense.js +0 -88
  124. package/lib/Figure/FigureLicenseDialog.js +0 -69
  125. package/lib/Figure/index.js +0 -49
  126. package/lib/FileList/File.js +0 -77
  127. package/lib/FileList/FileList.js +0 -48
  128. package/lib/FileList/index.js +0 -21
  129. package/lib/Hero/Hero.js +0 -108
  130. package/lib/Hero/index.js +0 -55
  131. package/lib/Image/Image.js +0 -129
  132. package/lib/Image/ImageLink.js +0 -62
  133. package/lib/Image/LazyLoadImage.js +0 -61
  134. package/lib/Image/index.js +0 -38
  135. package/lib/Image/shapes.js +0 -33
  136. package/lib/InfoBox/InfoBox.js +0 -29
  137. package/lib/InfoBox/index.js +0 -15
  138. package/lib/InfoWidget/InfoWidget.js +0 -93
  139. package/lib/InfoWidget/index.js +0 -13
  140. package/lib/Logo/Logo.js +0 -93
  141. package/lib/Logo/SvgLogo.js +0 -68
  142. package/lib/Logo/index.js +0 -20
  143. package/lib/Masthead/Masthead.js +0 -106
  144. package/lib/Masthead/index.js +0 -30
  145. package/lib/NoContentBox/NoContentBox.js +0 -53
  146. package/lib/NoContentBox/index.js +0 -20
  147. package/lib/Portrait/Portrait.js +0 -55
  148. package/lib/Portrait/index.js +0 -20
  149. package/lib/Translation/Translation.js +0 -41
  150. package/lib/Translation/TranslationBox.js +0 -25
  151. package/lib/Translation/TranslationLine.js +0 -60
  152. package/lib/Translation/index.js +0 -31
  153. package/src/BackgroundImage/BackgroundImage.jsx +0 -39
  154. package/src/FileList/FileList.jsx +0 -36
  155. package/src/Hero/Hero.jsx +0 -38
  156. package/src/Image/LazyLoadImage.jsx +0 -39
  157. package/src/Image/shapes.js +0 -21
  158. package/src/InfoBox/InfoBox.jsx +0 -13
  159. package/src/Translation/TranslationBox.jsx +0 -12
package/lib/types.d.ts CHANGED
@@ -37,6 +37,16 @@ export interface Contributor {
37
37
  export interface License {
38
38
  license: string;
39
39
  }
40
+ export interface ImageCrop {
41
+ startX: number;
42
+ startY: number;
43
+ endX: number;
44
+ endY: number;
45
+ }
46
+ export interface ImageFocalPoint {
47
+ x: number;
48
+ y: number;
49
+ }
40
50
  export interface Copyright {
41
51
  license: License;
42
52
  creators: Array<Contributor>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/ui",
3
- "version": "3.2.1-alpha.8+dbf0f57f4",
3
+ "version": "3.2.1",
4
4
  "description": "UI component library for NDLA.",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -31,17 +31,17 @@
31
31
  "types"
32
32
  ],
33
33
  "dependencies": {
34
- "@ndla/button": "^1.0.7-alpha.31+dbf0f57f4",
34
+ "@ndla/button": "^1.1.0",
35
35
  "@ndla/carousel": "^1.0.6",
36
36
  "@ndla/core": "^0.7.2",
37
37
  "@ndla/hooks": "^1.0.6",
38
38
  "@ndla/icons": "^1.3.1",
39
39
  "@ndla/licenses": "^1.0.7",
40
- "@ndla/modal": "^1.1.12-alpha.28+dbf0f57f4",
40
+ "@ndla/modal": "^1.1.12",
41
41
  "@ndla/safelink": "^1.0.5",
42
42
  "@ndla/switch": "^0.0.32",
43
- "@ndla/tabs": "^1.0.8",
44
- "@ndla/tooltip": "^0.2.47",
43
+ "@ndla/tabs": "^1.0.9",
44
+ "@ndla/tooltip": "^0.2.48",
45
45
  "@ndla/util": "^2.0.0",
46
46
  "@reach/menu-button": "^0.12.1",
47
47
  "@reach/slider": "^0.12.1",
@@ -92,5 +92,5 @@
92
92
  "publishConfig": {
93
93
  "access": "public"
94
94
  },
95
- "gitHead": "dbf0f57f403ab8964c5fd14f4c8405cf5ab5d0e1"
95
+ "gitHead": "e2135297c1f57072515a122173674a211b541752"
96
96
  }
@@ -12,7 +12,6 @@ import { useTranslation } from 'react-i18next';
12
12
  // @ts-ignore
13
13
  import Button from '@ndla/button';
14
14
  import SafeLink from '@ndla/safelink';
15
- // @ts-ignore
16
15
  import Portrait from '../Portrait';
17
16
 
18
17
  const classes = new BEMHelper({
@@ -10,7 +10,6 @@ import React from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import BEMHelper from 'react-bem-helper';
12
12
  import SafeLink from '@ndla/safelink';
13
- // @ts-ignore
14
13
  import Portrait from '../Portrait';
15
14
 
16
15
  const classes = new BEMHelper({
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import BEMHelper from 'react-bem-helper';
3
+
4
+ const classes = BEMHelper('c-background-image');
5
+
6
+ type ImageType = 'mobile' | 'tablet' | 'desktop' | 'wide';
7
+
8
+ interface Props {
9
+ showOverlay?: boolean;
10
+ className?: string;
11
+ images: {
12
+ url: string;
13
+ types: ImageType[];
14
+ }[];
15
+ }
16
+
17
+ const BackgroundImage = ({ images, showOverlay = false }: Props) => (
18
+ <div {...classes('', { showOverlay })}>
19
+ {images &&
20
+ images.map((image) =>
21
+ image.types.map((type) => (
22
+ <div
23
+ key={`${image.url}${type}`}
24
+ {...classes('background', type)}
25
+ style={{ backgroundImage: `url(${image.url})` }}
26
+ />
27
+ )),
28
+ )}
29
+ </div>
30
+ );
31
+
32
+ export default BackgroundImage;
File without changes
@@ -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
@@ -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