@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,13 +6,23 @@
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
+ export interface ImageCrop {
14
+ startX: number;
15
+ startY: number;
16
+ endX: number;
17
+ endY: number;
18
+ }
14
19
 
15
- export const makeSrcQueryString = (width, crop, focalPoint) => {
20
+ export interface ImageFocalPoint {
21
+ x: number;
22
+ y: number;
23
+ }
24
+
25
+ export const makeSrcQueryString = (width: number | undefined, crop?: ImageCrop, focalPoint?: ImageFocalPoint) => {
16
26
  const widthParams = width && `width=${width}`;
17
27
  const cropParams =
18
28
  crop && `cropStartX=${crop.startX}&cropEndX=${crop.endX}&cropStartY=${crop.startY}&cropEndY=${crop.endY}`;
@@ -22,7 +32,7 @@ export const makeSrcQueryString = (width, crop, focalPoint) => {
22
32
  return params;
23
33
  };
24
34
 
25
- const getSrcSet = (src, crop, focalPoint) => {
35
+ const getSrcSet = (src: string, crop: ImageCrop | undefined, focalPoint: ImageFocalPoint | undefined) => {
26
36
  const widths = [2720, 2080, 1760, 1440, 1120, 1000, 960, 800, 640, 480, 320, 240, 180];
27
37
  return widths.map((width) => `${src}?${makeSrcQueryString(width, crop, focalPoint)} ${width}w`).join(', ');
28
38
  };
@@ -31,7 +41,32 @@ const StyledImageWrapper = styled.div`
31
41
  position: relative;
32
42
  `;
33
43
 
34
- const Image = ({ alt, src, lazyLoad, lazyLoadSrc, crop, focalPoint, contentType, sizes, expandButton, ...rest }) => {
44
+ interface Props {
45
+ alt: string;
46
+ src: string;
47
+ sizes?: string;
48
+ fallbackWidth?: number;
49
+ contentType?: string;
50
+ srcSet?: string;
51
+ lazyLoad?: boolean;
52
+ lazyLoadSrc?: string;
53
+ expandButton?: ReactNode;
54
+ crop?: ImageCrop;
55
+ focalPoint?: ImageFocalPoint;
56
+ }
57
+
58
+ const Image = ({
59
+ alt,
60
+ src,
61
+ lazyLoad,
62
+ lazyLoadSrc,
63
+ crop,
64
+ focalPoint,
65
+ contentType,
66
+ sizes = '(min-width: 1024px) 1024px, 100vw',
67
+ expandButton,
68
+ ...rest
69
+ }: Props) => {
35
70
  const srcSet = defined(rest.srcSet, getSrcSet(src, crop, focalPoint));
36
71
  const fallbackWidth = defined(rest.fallbackWidth, 1024);
37
72
  const queryString = makeSrcQueryString(fallbackWidth, crop, focalPoint);
@@ -69,29 +104,4 @@ const Image = ({ alt, src, lazyLoad, lazyLoadSrc, crop, focalPoint, contentType,
69
104
  );
70
105
  };
71
106
 
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
107
  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 '.';
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
- };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2017-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 from 'react';
10
+
11
+ interface Props {
12
+ alt: string;
13
+ src: string;
14
+ sizes?: string;
15
+ contentType?: string;
16
+ srcSet?: string;
17
+ lazyLoadSrc?: string;
18
+ }
19
+ // Lazyload image with lazysizes (https://github.com/aFarkas/lazysizes)
20
+ const LazyLoadImage = ({ alt, src, srcSet, lazyLoadSrc, sizes, ...rest }: Props) => (
21
+ <>
22
+ <noscript key="noscript">
23
+ <img alt={alt} src={`${src}`} srcSet={srcSet} sizes={sizes} {...rest} />
24
+ </noscript>
25
+ ,
26
+ <img
27
+ alt={alt}
28
+ key="img"
29
+ style={{ width: '100%' }}
30
+ className="lazyload"
31
+ src={lazyLoadSrc}
32
+ data-src={src}
33
+ data-src-set={srcSet}
34
+ data-sizes={sizes}
35
+ {...rest}
36
+ />
37
+ </>
38
+ );
39
+
40
+ export default LazyLoadImage;
@@ -6,7 +6,7 @@ exports[`Image renderers correctly 1`] = `
6
6
  }
7
7
 
8
8
  <div
9
- className="emotion-0 emotion-1"
9
+ className="emotion-0"
10
10
  >
11
11
  <picture>
12
12
  <source
@@ -27,7 +27,7 @@ exports[`Image with crop and focalpoint props renderers correctly 1`] = `
27
27
  }
28
28
 
29
29
  <div
30
- className="emotion-0 emotion-1"
30
+ className="emotion-0"
31
31
  >
32
32
  <picture>
33
33
  <source
@@ -48,7 +48,7 @@ exports[`Lazyloaded image renderers correctly 1`] = `
48
48
  }
49
49
 
50
50
  <div
51
- className="emotion-0 emotion-1"
51
+ className="emotion-0"
52
52
  >
53
53
  <noscript>
54
54
  <img
@@ -58,6 +58,7 @@ exports[`Lazyloaded image renderers correctly 1`] = `
58
58
  srcSet="https://example.com/image.png?width=2720 2720w, https://example.com/image.png?width=2080 2080w, https://example.com/image.png?width=1760 1760w, https://example.com/image.png?width=1440 1440w, https://example.com/image.png?width=1120 1120w, https://example.com/image.png?width=1000 1000w, https://example.com/image.png?width=960 960w, https://example.com/image.png?width=800 800w, https://example.com/image.png?width=640 640w, https://example.com/image.png?width=480 480w, https://example.com/image.png?width=320 320w, https://example.com/image.png?width=240 240w, https://example.com/image.png?width=180 180w"
59
59
  />
60
60
  </noscript>
61
+ ,
61
62
  <img
62
63
  alt="example"
63
64
  className="lazyload"
@@ -9,5 +9,6 @@
9
9
  import Image from './Image';
10
10
  export { makeSrcQueryString } from './Image';
11
11
  export { ImageLink } from './ImageLink';
12
+ export type { ImageCrop, ImageFocalPoint } from './Image';
12
13
 
13
14
  export default Image;
@@ -0,0 +1,11 @@
1
+ import React, { ReactNode } from 'react';
2
+ import BEMHelper from 'react-bem-helper';
3
+
4
+ const classes = BEMHelper('c-info-box');
5
+
6
+ interface Props {
7
+ children?: ReactNode;
8
+ }
9
+ const InfoBox = ({ children }: Props) => <div {...classes()}>{children}</div>;
10
+
11
+ export default InfoBox;
@@ -0,0 +1 @@
1
+ export { default as InfoBox } from './InfoBox';
@@ -1,5 +1,4 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
1
+ import React, { ReactNode } from 'react';
3
2
  import BEMHelper from 'react-bem-helper';
4
3
  import { Forward } from '@ndla/icons/common';
5
4
 
@@ -9,7 +8,24 @@ import SectionHeading from '../SectionHeading';
9
8
 
10
9
  const classes = BEMHelper('c-info-widget');
11
10
 
12
- const InfoWidget = ({ heading, description, mainLink, iconLinks, center }) => (
11
+ interface Props {
12
+ heading: string;
13
+ description: string;
14
+ mainLink: {
15
+ name: string;
16
+ url?: string;
17
+ href?: string;
18
+ };
19
+ iconLinks: {
20
+ name: string;
21
+ url?: string;
22
+ href?: string;
23
+ icon: ReactNode;
24
+ }[];
25
+ center?: boolean;
26
+ }
27
+
28
+ const InfoWidget = ({ heading, description, mainLink, iconLinks, center = false }: Props) => (
13
29
  <section {...classes('', { center })}>
14
30
  <SectionHeading large className={classes('heading').className}>
15
31
  {heading}
@@ -55,27 +71,4 @@ const InfoWidget = ({ heading, description, mainLink, iconLinks, center }) => (
55
71
  </section>
56
72
  );
57
73
 
58
- InfoWidget.propTypes = {
59
- heading: PropTypes.string.isRequired,
60
- description: PropTypes.string.isRequired,
61
- mainLink: PropTypes.shape({
62
- name: PropTypes.string.isRequired,
63
- url: PropTypes.string,
64
- href: PropTypes.string,
65
- }).isRequired,
66
- iconLinks: PropTypes.arrayOf(
67
- PropTypes.shape({
68
- name: PropTypes.string.isRequired,
69
- url: PropTypes.string,
70
- href: PropTypes.string,
71
- icon: PropTypes.node.isRequired,
72
- }),
73
- ),
74
- center: PropTypes.bool,
75
- };
76
-
77
- InfoWidget.defaultProps = {
78
- center: false,
79
- };
80
-
81
74
  export default InfoWidget;
File without changes
@@ -7,8 +7,7 @@
7
7
  */
8
8
  /* eslint-disable max-len */
9
9
 
10
- import React, { Fragment } from 'react';
11
- import PropTypes from 'prop-types';
10
+ import React from 'react';
12
11
  import BEMHelper from 'react-bem-helper';
13
12
  import SafeLink from '@ndla/safelink';
14
13
  import SvgLogo from './SvgLogo';
@@ -18,8 +17,24 @@ export const logoClasses = new BEMHelper({
18
17
  prefix: 'c-',
19
18
  });
20
19
 
21
- export const Logo = ({ name, to, cssModifier, color, large, locale, label }) => {
22
- const modifiers = { large };
20
+ interface Props {
21
+ to?:
22
+ | string
23
+ | {
24
+ pathname: string;
25
+ search?: string;
26
+ hash?: string;
27
+ };
28
+ label: string;
29
+ locale?: string;
30
+ cssModifier?: string;
31
+ large?: boolean;
32
+ name?: boolean;
33
+ color?: string;
34
+ }
35
+
36
+ export const Logo = ({ name = true, to, cssModifier, color, large = false, locale, label }: Props) => {
37
+ const modifiers: Record<string, boolean> = { large };
23
38
 
24
39
  if (cssModifier) {
25
40
  modifiers[cssModifier] = true;
@@ -30,33 +45,11 @@ export const Logo = ({ name, to, cssModifier, color, large, locale, label }) =>
30
45
  <SvgLogo name={name} color={color} locale={locale} />
31
46
  </SafeLink>
32
47
  ) : (
33
- <Fragment>
48
+ <>
34
49
  <SvgLogo name={name} color={color} locale={locale} />
35
- </Fragment>
50
+ </>
36
51
  );
37
52
  return <div {...logoClasses('', modifiers)}>{logo}</div>;
38
53
  };
39
54
 
40
- Logo.propTypes = {
41
- to: PropTypes.oneOfType([
42
- PropTypes.string,
43
- PropTypes.shape({
44
- pathname: PropTypes.string.isRequired,
45
- search: PropTypes.string,
46
- hash: PropTypes.string,
47
- }),
48
- ]),
49
- label: PropTypes.string.isRequired,
50
- locale: PropTypes.string,
51
- cssModifier: PropTypes.string,
52
- large: PropTypes.bool,
53
- name: PropTypes.bool,
54
- color: PropTypes.string,
55
- };
56
-
57
- Logo.defaultProps = {
58
- name: true,
59
- large: false,
60
- };
61
-
62
55
  export default Logo;
@@ -8,10 +8,9 @@
8
8
  /* eslint-disable max-len */
9
9
 
10
10
  import React from 'react';
11
- import PropTypes from 'prop-types';
12
11
  import { logoClasses } from './Logo';
13
12
 
14
- const LogoText = (locale) => {
13
+ const LogoText = (locale?: string) => {
15
14
  if (locale === 'en') {
16
15
  return (
17
16
  <path
@@ -26,7 +25,13 @@ const LogoText = (locale) => {
26
25
  );
27
26
  };
28
27
 
29
- export const SvgLogo = ({ name, color, locale }) => (
28
+ interface Props {
29
+ name?: boolean;
30
+ color?: string;
31
+ locale?: string;
32
+ }
33
+
34
+ export const SvgLogo = ({ name = true, color = '#000000', locale }: Props) => (
30
35
  <svg
31
36
  {...logoClasses('graphic')}
32
37
  xmlns="http://www.w3.org/2000/svg"
@@ -41,15 +46,4 @@ export const SvgLogo = ({ name, color, locale }) => (
41
46
  </svg>
42
47
  );
43
48
 
44
- SvgLogo.propTypes = {
45
- name: PropTypes.bool,
46
- color: PropTypes.string,
47
- locale: PropTypes.string,
48
- };
49
-
50
- SvgLogo.defaultProps = {
51
- name: true,
52
- color: '#000000',
53
- };
54
-
55
49
  export default SvgLogo;
File without changes
@@ -6,11 +6,11 @@
6
6
  *
7
7
  */
8
8
 
9
- import React from 'react';
10
- import PropTypes from 'prop-types';
9
+ import React, { ReactNode } from 'react';
10
+ //@ts-ignore
11
11
  import classNames from 'classnames';
12
12
  import BEMHelper from 'react-bem-helper';
13
- import { withTranslation } from 'react-i18next';
13
+ import { WithTranslation, withTranslation } from 'react-i18next';
14
14
  import { DisplayOnPageYOffset } from '../Animation';
15
15
 
16
16
  const classes = new BEMHelper({
@@ -18,7 +18,13 @@ const classes = new BEMHelper({
18
18
  prefix: 'c-',
19
19
  });
20
20
 
21
- export const MastheadItem = ({ children, className, left, right }) => {
21
+ interface MastheadItemProps {
22
+ children?: ReactNode;
23
+ className?: string;
24
+ right?: boolean;
25
+ left?: boolean;
26
+ }
27
+ export const MastheadItem = ({ children, className, left = false, right = false }: MastheadItemProps) => {
22
28
  const itemClassNames = classNames(
23
29
  { [classes('left').className]: left },
24
30
  { [classes('right').className]: right },
@@ -28,37 +34,42 @@ export const MastheadItem = ({ children, className, left, right }) => {
28
34
  return <div className={itemClassNames}>{children}</div>;
29
35
  };
30
36
 
31
- MastheadItem.propTypes = {
32
- children: PropTypes.node,
33
- className: PropTypes.string,
34
- right: PropTypes.bool,
35
- left: PropTypes.bool,
36
- };
37
-
38
- MastheadItem.defaultProps = {
39
- right: false,
40
- left: false,
41
- };
37
+ interface MastheadInfoProps {
38
+ children?: ReactNode;
39
+ }
42
40
 
43
- const MastheadInfo = ({ children }) => (
41
+ const MastheadInfo = ({ children }: MastheadInfoProps) => (
44
42
  <div {...classes('info')}>
45
43
  <div {...classes('info-content')}>{children}</div>
46
44
  </div>
47
45
  );
48
46
 
49
- MastheadInfo.propTypes = {
50
- children: PropTypes.node.isRequired,
51
- };
47
+ interface Props {
48
+ children?: ReactNode;
49
+ fixed?: boolean;
50
+ showLoaderWhenNeeded?: boolean;
51
+ infoContent?: ReactNode;
52
+ ndlaFilm?: boolean;
53
+ skipToMainContentId?: string;
54
+ }
52
55
 
53
- export const Masthead = ({ children, fixed, infoContent, showLoaderWhenNeeded, ndlaFilm, skipToMainContentId, t }) => (
56
+ export const Masthead = ({
57
+ children,
58
+ fixed,
59
+ infoContent,
60
+ showLoaderWhenNeeded = true,
61
+ ndlaFilm,
62
+ skipToMainContentId,
63
+ t,
64
+ }: Props & WithTranslation) => (
54
65
  <>
55
66
  {skipToMainContentId && (
56
67
  <a tabIndex={0} href={`#${skipToMainContentId}`} {...classes('skip-to-main-content')}>
57
68
  {t('masthead.skipToContent')}
58
69
  </a>
59
70
  )}
60
- <div {...classes('placeholder', { infoContent })} />
61
- <div {...classes('', { fixed, infoContent, showLoaderWhenNeeded, ndlaFilm })}>
71
+ <div {...classes('placeholder', { infoContent: !!infoContent })} />
72
+ <div {...classes('', { fixed: !!fixed, infoContent: !!infoContent, showLoaderWhenNeeded, ndlaFilm: !!ndlaFilm })}>
62
73
  {infoContent && (
63
74
  <DisplayOnPageYOffset yOffsetMin={0} yOffsetMax={90}>
64
75
  <MastheadInfo>{infoContent}</MastheadInfo>
@@ -69,17 +80,4 @@ export const Masthead = ({ children, fixed, infoContent, showLoaderWhenNeeded, n
69
80
  </>
70
81
  );
71
82
 
72
- Masthead.propTypes = {
73
- children: PropTypes.node,
74
- fixed: PropTypes.bool,
75
- showLoaderWhenNeeded: PropTypes.bool,
76
- infoContent: PropTypes.node,
77
- ndlaFilm: PropTypes.bool,
78
- skipToMainContentId: PropTypes.string,
79
- };
80
-
81
- Masthead.defaultProps = {
82
- showLoaderWhenNeeded: true,
83
- };
84
-
85
83
  export default withTranslation()(Masthead);
File without changes
@@ -7,8 +7,8 @@
7
7
  */
8
8
 
9
9
  import React from 'react';
10
- import PropTypes from 'prop-types';
11
10
  import BEMHelper from 'react-bem-helper';
11
+ //@ts-ignore
12
12
  import Button from '@ndla/button';
13
13
 
14
14
  const classes = new BEMHelper({
@@ -16,7 +16,12 @@ const classes = new BEMHelper({
16
16
  prefix: 'c-',
17
17
  });
18
18
 
19
- export const NoContentBox = ({ buttonText, text, onClick }) => (
19
+ interface Props {
20
+ onClick?: () => void;
21
+ buttonText?: string;
22
+ text: string;
23
+ }
24
+ export const NoContentBox = ({ buttonText, text, onClick }: Props) => (
20
25
  <div {...classes('additional-resources-trigger')}>
21
26
  <span>
22
27
  <div>
@@ -31,15 +36,4 @@ export const NoContentBox = ({ buttonText, text, onClick }) => (
31
36
  </div>
32
37
  );
33
38
 
34
- NoContentBox.propTypes = {
35
- onClick: PropTypes.func,
36
- buttonText: PropTypes.string,
37
- text: PropTypes.string.isRequired,
38
- };
39
-
40
- NoContentBox.defaultProps = {
41
- onClick: null,
42
- buttonText: undefined,
43
- };
44
-
45
39
  export default NoContentBox;
File without changes
@@ -7,7 +7,6 @@
7
7
  */
8
8
 
9
9
  import React from 'react';
10
- import PropTypes from 'prop-types';
11
10
  import BEMHelper from 'react-bem-helper';
12
11
 
13
12
  const classes = new BEMHelper({
@@ -15,22 +14,17 @@ const classes = new BEMHelper({
15
14
  prefix: 'c-',
16
15
  });
17
16
 
18
- const Portrait = ({ src, alt, modifier, className }) => (
17
+ interface Props {
18
+ src: string;
19
+ alt: string;
20
+ className?: string;
21
+ modifier?: 'small' | 'large';
22
+ }
23
+
24
+ const Portrait = ({ src, alt, modifier, className }: Props) => (
19
25
  <div {...classes('', modifier, className)}>
20
26
  <span role="img" aria-label={alt} style={{ backgroundImage: `url(${src})` }} />
21
27
  </div>
22
28
  );
23
29
 
24
- Portrait.propTypes = {
25
- src: PropTypes.string.isRequired,
26
- alt: PropTypes.string.isRequired,
27
- className: PropTypes.string,
28
- modifier: PropTypes.oneOf(['small', 'large']),
29
- };
30
-
31
- Portrait.defaultProps = {
32
- className: null,
33
- modifier: null,
34
- };
35
-
36
30
  export default Portrait;
File without changes