@ndla/ui 45.0.16 → 46.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/es/Article/Article.js +3 -3
  2. package/es/AudioPlayer/index.js +0 -2
  3. package/es/Embed/conceptComponents.js +15 -8
  4. package/es/Figure/Figure.js +11 -89
  5. package/es/Figure/index.js +1 -3
  6. package/es/Notion/index.js +1 -3
  7. package/es/all.css +1 -1
  8. package/es/index.js +3 -4
  9. package/es/locale/messages-en.js +7 -2
  10. package/es/locale/messages-nb.js +7 -2
  11. package/es/locale/messages-nn.js +7 -2
  12. package/es/locale/messages-se.js +7 -2
  13. package/es/locale/messages-sma.js +7 -2
  14. package/lib/Article/Article.js +3 -3
  15. package/lib/AudioPlayer/index.d.ts +0 -2
  16. package/lib/AudioPlayer/index.js +0 -7
  17. package/lib/Embed/conceptComponents.js +17 -10
  18. package/lib/Figure/Figure.d.ts +0 -38
  19. package/lib/Figure/Figure.js +20 -96
  20. package/lib/Figure/index.d.ts +1 -3
  21. package/lib/Figure/index.js +2 -17
  22. package/lib/Notion/index.d.ts +0 -4
  23. package/lib/Notion/index.js +0 -14
  24. package/lib/all.css +1 -1
  25. package/lib/index.d.ts +3 -5
  26. package/lib/index.js +1 -32
  27. package/lib/locale/messages-en.d.ts +5 -0
  28. package/lib/locale/messages-en.js +7 -2
  29. package/lib/locale/messages-nb.d.ts +5 -0
  30. package/lib/locale/messages-nb.js +7 -2
  31. package/lib/locale/messages-nn.d.ts +5 -0
  32. package/lib/locale/messages-nn.js +7 -2
  33. package/lib/locale/messages-se.d.ts +5 -0
  34. package/lib/locale/messages-se.js +7 -2
  35. package/lib/locale/messages-sma.d.ts +5 -0
  36. package/lib/locale/messages-sma.js +7 -2
  37. package/package.json +18 -22
  38. package/src/Article/Article.tsx +1 -1
  39. package/src/AudioPlayer/AudiPlayer.stories.tsx +88 -0
  40. package/src/AudioPlayer/index.ts +0 -2
  41. package/src/Embed/IframeEmbed.stories.tsx +15 -0
  42. package/src/Embed/ImageEmbed.stories.tsx +169 -2
  43. package/src/Embed/RelatedContentEmbed.stories.tsx +438 -0
  44. package/src/Embed/conceptComponents.tsx +13 -1
  45. package/src/Figure/Figure.tsx +1 -120
  46. package/src/Figure/index.ts +1 -3
  47. package/src/Notion/index.ts +0 -4
  48. package/src/index.ts +3 -13
  49. package/src/locale/messages-en.ts +7 -2
  50. package/src/locale/messages-nb.ts +7 -2
  51. package/src/locale/messages-nn.ts +7 -2
  52. package/src/locale/messages-se.ts +7 -2
  53. package/src/locale/messages-sma.ts +7 -2
  54. package/src/main.scss +0 -1
  55. package/es/Animation/Fade.js +0 -62
  56. package/es/Animation/index.js +0 -1
  57. package/es/AudioPlayer/initAudioPlayers.js +0 -60
  58. package/es/Dialog/Dialog.js +0 -70
  59. package/es/Dialog/index.js +0 -11
  60. package/es/Figure/FigureLicense.js +0 -72
  61. package/es/Figure/FigureLicenseDialog.js +0 -54
  62. package/es/Notion/ConceptNotion.js +0 -135
  63. package/es/Notion/FigureNotion.js +0 -93
  64. package/es/Notion/NotionVisualElement.js +0 -68
  65. package/es/utils/createUniversalPortal.js +0 -25
  66. package/lib/Animation/Fade.d.ts +0 -17
  67. package/lib/Animation/Fade.js +0 -70
  68. package/lib/Animation/index.d.ts +0 -1
  69. package/lib/Animation/index.js +0 -13
  70. package/lib/AudioPlayer/initAudioPlayers.d.ts +0 -11
  71. package/lib/AudioPlayer/initAudioPlayers.js +0 -69
  72. package/lib/Dialog/Dialog.d.ts +0 -23
  73. package/lib/Dialog/Dialog.js +0 -75
  74. package/lib/Dialog/index.d.ts +0 -10
  75. package/lib/Dialog/index.js +0 -22
  76. package/lib/Figure/FigureLicense.d.ts +0 -33
  77. package/lib/Figure/FigureLicense.js +0 -76
  78. package/lib/Figure/FigureLicenseDialog.d.ts +0 -29
  79. package/lib/Figure/FigureLicenseDialog.js +0 -57
  80. package/lib/Notion/ConceptNotion.d.ts +0 -24
  81. package/lib/Notion/ConceptNotion.js +0 -141
  82. package/lib/Notion/FigureNotion.d.ts +0 -27
  83. package/lib/Notion/FigureNotion.js +0 -97
  84. package/lib/Notion/NotionVisualElement.d.ts +0 -22
  85. package/lib/Notion/NotionVisualElement.js +0 -75
  86. package/lib/utils/createUniversalPortal.d.ts +0 -9
  87. package/lib/utils/createUniversalPortal.js +0 -32
  88. package/src/Animation/Fade.tsx +0 -46
  89. package/src/Animation/index.ts +0 -1
  90. package/src/AudioPlayer/initAudioPlayers.tsx +0 -57
  91. package/src/Dialog/Dialog.tsx +0 -80
  92. package/src/Dialog/component.dialog.scss +0 -144
  93. package/src/Dialog/index.ts +0 -13
  94. package/src/Figure/FigureLicense.tsx +0 -75
  95. package/src/Figure/FigureLicenseDialog.tsx +0 -51
  96. package/src/Notion/ConceptNotion.tsx +0 -170
  97. package/src/Notion/FigureNotion.tsx +0 -104
  98. package/src/Notion/NotionVisualElement.tsx +0 -80
  99. package/src/utils/createUniversalPortal.tsx +0 -23
@@ -1,170 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-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
- import styled from '@emotion/styled';
8
-
9
- import { useEffect } from 'react';
10
- //@ts-ignore
11
- import { initArticleScripts } from '@ndla/article-scripts';
12
- import { useTranslation } from 'react-i18next';
13
- import { breakpoints, mq, spacing } from '@ndla/core';
14
- import { parseMarkdown } from '@ndla/util';
15
- import { getLicenseCredits } from '@ndla/licenses';
16
- import Notion, { NotionDialogContent, NotionDialogText, NotionDialogLicenses } from '@ndla/notion';
17
- import { Notion as UINotion } from '.';
18
- import { NotionImage } from './NotionImage';
19
- import NotionVisualElement from './NotionVisualElement';
20
- import type { NotionVisualElementType } from './NotionVisualElement';
21
- import FigureNotion from './FigureNotion';
22
- import { Copyright } from '../types';
23
- import { FigureType } from '../Figure';
24
-
25
- const ImageWrapper = styled.div`
26
- float: right;
27
- padding-left: ${spacing.normal};
28
- position: relative;
29
-
30
- ${mq.range({ until: breakpoints.tabletWide })} {
31
- width: 100%;
32
- padding-left: 0;
33
- }
34
- `;
35
-
36
- export interface ConceptNotionType {
37
- id: number;
38
- copyright?: Partial<Copyright>;
39
- title: string;
40
- text: string;
41
- visualElement?: NotionVisualElementType;
42
- source?: string;
43
- image?: {
44
- src: string;
45
- alt: string;
46
- };
47
- }
48
- interface Props {
49
- type?: 'image' | 'video' | 'h5p' | 'iframe' | 'external';
50
- concept: ConceptNotionType;
51
- disableScripts?: boolean;
52
- hideIconsAndAuthors?: boolean;
53
- figureType?: FigureType;
54
- }
55
-
56
- const ConceptNotion = ({ concept, disableScripts, type, hideIconsAndAuthors, figureType }: Props) => {
57
- const notionId = `notion-${concept.id}`;
58
- const figureId = `notion-figure-${concept.id}`;
59
- const visualElementId = `visual-element-${concept.id}`;
60
- const { t } = useTranslation();
61
-
62
- const { creators, rightsholders, processors } = getLicenseCredits(concept.copyright);
63
-
64
- const authors = (creators.length || rightsholders.length ? [...creators, ...rightsholders] : [...processors]).map(
65
- (author) => author.name,
66
- );
67
-
68
- useEffect(() => {
69
- if (!disableScripts) {
70
- initArticleScripts();
71
- }
72
- }, [disableScripts]);
73
-
74
- return (
75
- <FigureNotion
76
- resizeIframe
77
- id={figureId}
78
- title={concept.title}
79
- figureId={visualElementId}
80
- copyright={concept.copyright}
81
- licenseString={concept.copyright?.license?.license ?? ''}
82
- type="concept"
83
- hideIconsAndAuthors={hideIconsAndAuthors}
84
- figureType={figureType}
85
- >
86
- <UINotion
87
- id={notionId}
88
- title={concept.title}
89
- text={concept.text}
90
- imageElement={
91
- concept.visualElement?.resource === 'image' && concept.visualElement.image ? (
92
- <ImageWrapper>
93
- <Notion
94
- id={notionId}
95
- title={concept.title}
96
- subTitle={t('searchPage.resultType.notionsHeading')}
97
- hideBaselineIcon
98
- content={
99
- <>
100
- <NotionDialogContent>
101
- {concept.visualElement?.resource === 'image' && concept.visualElement.image ? (
102
- <NotionVisualElement visualElement={concept.visualElement} id={notionId} figureId={figureId} />
103
- ) : undefined}
104
- <NotionDialogText>{parseMarkdown(concept.text, 'body')}</NotionDialogText>
105
- </NotionDialogContent>
106
- <NotionDialogLicenses
107
- authors={authors}
108
- license={concept.copyright?.license?.license ?? ''}
109
- source={concept.source}
110
- />
111
- </>
112
- }
113
- >
114
- {concept.visualElement.image && (
115
- <NotionImage
116
- type={type}
117
- id={visualElementId}
118
- src={concept.visualElement.image.src}
119
- alt={concept.visualElement.image.alt ?? ''}
120
- />
121
- )}
122
- </Notion>
123
- </ImageWrapper>
124
- ) : undefined
125
- }
126
- visualElement={
127
- concept.visualElement && concept.visualElement.resource !== 'image' && concept.visualElement.url ? (
128
- <ImageWrapper>
129
- <Notion
130
- id={notionId}
131
- title={concept.title}
132
- hideBaselineIcon
133
- subTitle={t('searchPage.resultType.notionsHeading')}
134
- content={
135
- <>
136
- <NotionDialogContent>
137
- {concept.visualElement &&
138
- concept.visualElement?.resource !== 'image' &&
139
- concept.visualElement.url ? (
140
- <NotionVisualElement visualElement={concept.visualElement} id={notionId} figureId={figureId} />
141
- ) : undefined}
142
-
143
- <NotionDialogText>{parseMarkdown(concept.text, 'body')}</NotionDialogText>
144
- </NotionDialogContent>
145
- <NotionDialogLicenses
146
- authors={authors}
147
- license={concept.copyright?.license?.license ?? ''}
148
- source={concept.source}
149
- />
150
- </>
151
- }
152
- >
153
- {concept.image && (
154
- <NotionImage
155
- type={type}
156
- id={visualElementId}
157
- src={concept.image?.src}
158
- alt={concept.image?.alt ?? ''}
159
- />
160
- )}
161
- </Notion>
162
- </ImageWrapper>
163
- ) : undefined
164
- }
165
- ></UINotion>
166
- </FigureNotion>
167
- );
168
- };
169
-
170
- export default ConceptNotion;
@@ -1,104 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-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
- import styled from '@emotion/styled';
9
- import { colors, spacing } from '@ndla/core';
10
- import { getGroupedContributorDescriptionList, getLicenseByAbbreviation, getLicenseCredits } from '@ndla/licenses';
11
- import { ReactNode } from 'react';
12
- import { useTranslation } from 'react-i18next';
13
- import { Figure, FigureCaption, FigureLicenseDialog, FigureType } from '../Figure';
14
- import { Copyright } from '../types';
15
-
16
- const BottomBorder = styled.div`
17
- margin-top: ${spacing.normal};
18
- border-bottom: 1px solid ${colors.brand.greyLight};
19
- `;
20
-
21
- interface Props {
22
- resizeIframe?: boolean;
23
- figureId: string;
24
- children: ReactNode | ((params: { typeClass: string }) => ReactNode);
25
- id: string;
26
- title: string;
27
- copyright?: Partial<Copyright>;
28
- licenseString: string;
29
- type: 'video' | 'h5p' | 'image' | 'concept' | 'other';
30
- hideFigCaption?: boolean;
31
- hideIconsAndAuthors?: boolean;
32
- figureType?: FigureType;
33
- licenseButtons?: ReactNode;
34
- }
35
-
36
- const FigureNotion = ({
37
- resizeIframe,
38
- figureId,
39
- children,
40
- id,
41
- copyright,
42
- licenseString,
43
- title,
44
- type,
45
- hideFigCaption,
46
- hideIconsAndAuthors,
47
- figureType,
48
- licenseButtons,
49
- }: Props) => {
50
- const { t, i18n } = useTranslation();
51
- const license = getLicenseByAbbreviation(licenseString, i18n.language);
52
- const licenseCredits = getLicenseCredits(copyright);
53
- const { creators, rightsholders, processors } = licenseCredits;
54
-
55
- const authors = creators.length || rightsholders.length ? [...creators, ...rightsholders] : [...processors];
56
-
57
- const groupedAuthors = getGroupedContributorDescriptionList(licenseCredits, i18n.language).map((item) => ({
58
- name: item.description,
59
- type: item.label,
60
- }));
61
-
62
- return (
63
- <Figure resizeIframe={resizeIframe} id={figureId} type={figureType || 'full-column'}>
64
- {({ typeClass }) => (
65
- <>
66
- {typeof children === 'function' ? children({ typeClass }) : children}
67
- {copyright?.license?.license ? (
68
- <FigureCaption
69
- hideFigcaption={hideFigCaption}
70
- figureId={figureId}
71
- id={id}
72
- reuseLabel={t(`${type}.reuse`)}
73
- authors={authors}
74
- licenseRights={license.rights}
75
- hideIconsAndAuthors={hideIconsAndAuthors}
76
- >
77
- <FigureLicenseDialog
78
- id={id}
79
- authors={groupedAuthors}
80
- locale={i18n.language}
81
- title={title}
82
- origin={copyright?.origin}
83
- license={license}
84
- messages={{
85
- close: t('close'),
86
- rulesForUse: t(`license.${type}.rules`),
87
- source: t('source'),
88
- learnAboutLicenses: t('license.learnMore'),
89
- title: t('title'),
90
- }}
91
- >
92
- {licenseButtons}
93
- </FigureLicenseDialog>
94
- </FigureCaption>
95
- ) : (
96
- <BottomBorder />
97
- )}
98
- </>
99
- )}
100
- </Figure>
101
- );
102
- };
103
-
104
- export default FigureNotion;
@@ -1,80 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-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
- import { css } from '@emotion/react';
8
- import styled from '@emotion/styled';
9
- import { ReactNode } from 'react';
10
- import { Copyright } from '../types';
11
- import FigureNotion from './FigureNotion';
12
-
13
- const StyledIframe = styled.iframe<{ type: string }>`
14
- ${(props) =>
15
- props.type === 'video'
16
- ? css`
17
- min-height: 400px;
18
- `
19
- : ''}
20
- `;
21
-
22
- export type NotionVisualElementType = {
23
- element?: ReactNode;
24
- type?: 'video' | 'image' | 'h5p' | 'iframe';
25
- resource?: string;
26
- title?: string;
27
- url?: string;
28
- copyright?: Partial<Copyright>;
29
- image?: {
30
- src: string;
31
- alt?: string;
32
- };
33
- licenseButtons?: ReactNode;
34
- };
35
-
36
- interface Props {
37
- visualElement: NotionVisualElementType;
38
- id: string;
39
- figureId: string;
40
- }
41
- const supportedEmbedTypes = ['brightcove', 'h5p', 'iframe', 'external', 'image'];
42
-
43
- const getType = (resource: string) => {
44
- if (resource === 'brightcove') {
45
- return 'video';
46
- }
47
- if (resource === 'image' || resource === 'h5p') {
48
- return resource;
49
- }
50
- return 'other';
51
- };
52
-
53
- const NotionVisualElement = ({ visualElement, id, figureId }: Props) => {
54
- if (!visualElement.resource || !supportedEmbedTypes.includes(visualElement.resource)) {
55
- return <p>Embed type is not supported!</p>;
56
- }
57
-
58
- const type = getType(visualElement.resource);
59
-
60
- return (
61
- <FigureNotion
62
- resizeIframe
63
- id={id}
64
- figureId={figureId}
65
- title={visualElement.title ?? ''}
66
- copyright={visualElement.copyright}
67
- licenseString={visualElement.copyright?.license?.license ?? ''}
68
- licenseButtons={visualElement.licenseButtons}
69
- type={type}
70
- >
71
- {visualElement.image?.src ? (
72
- <img src={visualElement.image?.src} alt={visualElement.image.alt} />
73
- ) : (
74
- <StyledIframe allowFullScreen type={type} src={visualElement.url} title={visualElement.title} />
75
- )}
76
- </FigureNotion>
77
- );
78
- };
79
-
80
- export default NotionVisualElement;
@@ -1,23 +0,0 @@
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
- // N.B This helper is intended to be used in https://github.com/ndlano/article-converter. It is not a general soultion for using portals in SSR applications.
10
-
11
- import { ReactNode } from 'react';
12
- import ReactDOM from 'react-dom';
13
-
14
- function canUseDOM() {
15
- return !!(typeof window !== 'undefined' && window.document && !window.document.hidden); // window.document.hidden === jsdom check
16
- }
17
-
18
- export function createUniversalPortal(children: ReactNode, selector: string) {
19
- if (!canUseDOM()) {
20
- return <div data-react-universal-portal>{children}</div>;
21
- }
22
- return ReactDOM.createPortal(children, document.querySelector(selector) as Element);
23
- }