@ndla/ui 6.2.2 → 8.0.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.
- package/es/Masthead/Masthead.js +7 -2
- package/es/MessageBox/MessageBox.js +26 -12
- package/es/Notion/FigureNotion.js +0 -1
- package/es/Notion/Notion.js +13 -14
- package/es/Notion/NotionVisualElement.js +1 -1
- package/lib/Masthead/Masthead.d.ts +9 -3
- package/lib/Masthead/Masthead.js +7 -2
- package/lib/MessageBox/MessageBox.d.ts +3 -2
- package/lib/MessageBox/MessageBox.js +25 -11
- package/lib/Notion/FigureNotion.js +0 -1
- package/lib/Notion/Notion.d.ts +1 -2
- package/lib/Notion/Notion.js +13 -14
- package/lib/Notion/NotionVisualElement.js +1 -1
- package/package.json +3 -2
- package/src/Masthead/Masthead.tsx +15 -2
- package/src/MessageBox/MessageBox.tsx +22 -2
- package/src/Notion/FigureNotion.tsx +0 -1
- package/src/Notion/Notion.tsx +3 -15
- package/src/Notion/NotionVisualElement.tsx +1 -1
|
@@ -40,13 +40,20 @@ const MastheadInfo = ({ children }: MastheadInfoProps) => (
|
|
|
40
40
|
</div>
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
+
interface Alert {
|
|
44
|
+
content: string;
|
|
45
|
+
closable?: boolean;
|
|
46
|
+
number: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
interface Props {
|
|
44
50
|
children?: ReactNode;
|
|
45
51
|
fixed?: boolean;
|
|
46
52
|
infoContent?: ReactNode;
|
|
47
53
|
ndlaFilm?: boolean;
|
|
48
54
|
skipToMainContentId?: string;
|
|
49
|
-
messages?:
|
|
55
|
+
messages?: Alert[];
|
|
56
|
+
onCloseAlert?: (id: number) => void;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
export const Masthead = ({
|
|
@@ -56,6 +63,7 @@ export const Masthead = ({
|
|
|
56
63
|
ndlaFilm,
|
|
57
64
|
skipToMainContentId,
|
|
58
65
|
messages,
|
|
66
|
+
onCloseAlert,
|
|
59
67
|
t,
|
|
60
68
|
}: Props & WithTranslation) => {
|
|
61
69
|
const mastheadRef = useRef<HTMLDivElement>(null);
|
|
@@ -87,7 +95,12 @@ export const Masthead = ({
|
|
|
87
95
|
)}
|
|
88
96
|
<div id="masthead" {...classes('', { fixed: !!fixed, infoContent: !!infoContent, ndlaFilm: !!ndlaFilm })}>
|
|
89
97
|
{messages?.map((message) => (
|
|
90
|
-
<MessageBox
|
|
98
|
+
<MessageBox
|
|
99
|
+
type={MessageBoxType.masthead}
|
|
100
|
+
showCloseButton={message.closable}
|
|
101
|
+
onClose={() => onCloseAlert?.(message.number)}>
|
|
102
|
+
{message.content}
|
|
103
|
+
</MessageBox>
|
|
91
104
|
))}
|
|
92
105
|
{infoContent && (
|
|
93
106
|
<DisplayOnPageYOffset yOffsetMin={0} yOffsetMax={90}>
|
|
@@ -12,6 +12,9 @@ import Sticky from 'react-sticky-el';
|
|
|
12
12
|
import { breakpoints, fonts, mq, spacing } from '@ndla/core';
|
|
13
13
|
import { InformationOutline, HumanMaleBoard } from '@ndla/icons/common';
|
|
14
14
|
import { WithTranslation, withTranslation } from 'react-i18next';
|
|
15
|
+
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import { Remarkable } from 'remarkable';
|
|
15
18
|
import { CloseButton } from '../CloseButton';
|
|
16
19
|
|
|
17
20
|
export enum MessageBoxType {
|
|
@@ -45,6 +48,7 @@ const StyleByType = (type: WrapperProps['boxType']) => {
|
|
|
45
48
|
styles.width = '100vw';
|
|
46
49
|
styles.position = 'relative';
|
|
47
50
|
styles.left = '50%';
|
|
51
|
+
styles.padding = '0';
|
|
48
52
|
styles.transform = 'translateX(-50%)';
|
|
49
53
|
break;
|
|
50
54
|
case 'medium':
|
|
@@ -102,6 +106,9 @@ const TextWrapper = styled.div<WrapperProps>`
|
|
|
102
106
|
line-height: 24px;
|
|
103
107
|
font-size: 16px;
|
|
104
108
|
}
|
|
109
|
+
& p {
|
|
110
|
+
margin: 0;
|
|
111
|
+
}
|
|
105
112
|
`;
|
|
106
113
|
|
|
107
114
|
const IconWrapper = styled.div<WrapperProps>`
|
|
@@ -152,12 +159,25 @@ type Props = {
|
|
|
152
159
|
children?: string;
|
|
153
160
|
links?: LinkProps[];
|
|
154
161
|
showCloseButton?: boolean;
|
|
162
|
+
onClose?: () => void;
|
|
155
163
|
};
|
|
156
164
|
|
|
157
|
-
|
|
165
|
+
const markdown = new Remarkable({ breaks: true });
|
|
166
|
+
markdown.inline.ruler.enable(['sub', 'sup']);
|
|
167
|
+
markdown.block.ruler.disable(['list', 'table']);
|
|
168
|
+
|
|
169
|
+
export const MessageBox = ({
|
|
170
|
+
type,
|
|
171
|
+
sticky = false,
|
|
172
|
+
children = '',
|
|
173
|
+
links,
|
|
174
|
+
showCloseButton,
|
|
175
|
+
onClose,
|
|
176
|
+
}: Props & WithTranslation) => {
|
|
158
177
|
const [hideMessageBox, setHideMessageBox] = useState(false);
|
|
159
178
|
const onCloseMessageBox = () => {
|
|
160
179
|
setHideMessageBox(true);
|
|
180
|
+
onClose?.();
|
|
161
181
|
};
|
|
162
182
|
const Icon = type === 'ghost' ? HumanMaleBoard : InformationOutline;
|
|
163
183
|
return (
|
|
@@ -168,7 +188,7 @@ export const MessageBox = ({ type, sticky = false, children, links, t, showClose
|
|
|
168
188
|
<IconWrapper boxType={type}>
|
|
169
189
|
<Icon style={{ width: '24px', height: '24px' }} />
|
|
170
190
|
</IconWrapper>
|
|
171
|
-
<TextWrapper
|
|
191
|
+
<TextWrapper dangerouslySetInnerHTML={{ __html: markdown.render(children) }}></TextWrapper>
|
|
172
192
|
</InfoWrapper>
|
|
173
193
|
{showCloseButton && (
|
|
174
194
|
<CloseButtonWrapper>
|
package/src/Notion/Notion.tsx
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import styled from '@emotion/styled';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
|
-
import
|
|
11
|
+
import { parseMarkdown } from '@ndla/util';
|
|
12
12
|
import React, { Fragment, ReactNode } from 'react';
|
|
13
13
|
import { keyframes } from '@emotion/core';
|
|
14
14
|
import Button from '@ndla/button';
|
|
@@ -174,7 +174,6 @@ type VisualElementProps = {
|
|
|
174
174
|
export type NotionProps = {
|
|
175
175
|
id: string | number;
|
|
176
176
|
labels?: string[];
|
|
177
|
-
renderMarkdown?: (text: string) => string;
|
|
178
177
|
text: ReactNode;
|
|
179
178
|
title: string;
|
|
180
179
|
visualElement?: VisualElementProps;
|
|
@@ -182,16 +181,7 @@ export type NotionProps = {
|
|
|
182
181
|
children?: ReactNode;
|
|
183
182
|
};
|
|
184
183
|
|
|
185
|
-
const Notion = ({
|
|
186
|
-
id,
|
|
187
|
-
labels = [],
|
|
188
|
-
renderMarkdown,
|
|
189
|
-
text,
|
|
190
|
-
title,
|
|
191
|
-
visualElement,
|
|
192
|
-
imageElement,
|
|
193
|
-
children,
|
|
194
|
-
}: NotionProps) => {
|
|
184
|
+
const Notion = ({ id, labels = [], text, title, visualElement, imageElement, children }: NotionProps) => {
|
|
195
185
|
const { t } = useTranslation();
|
|
196
186
|
|
|
197
187
|
return (
|
|
@@ -224,9 +214,7 @@ const Notion = ({
|
|
|
224
214
|
</ImageWrapper>
|
|
225
215
|
)}
|
|
226
216
|
<TextWrapper hasVisualElement={!!(imageElement || visualElement?.metaImage)}>
|
|
227
|
-
{
|
|
228
|
-
renderMarkdown ? renderMarkdown(`**${title}** \u2013 ${text}`) : `<b>${title}</b> \u2013 ${text}`,
|
|
229
|
-
)}
|
|
217
|
+
{parseMarkdown(`**${title}** \u2013 ${text}`, 'body')}
|
|
230
218
|
{!!labels.length && (
|
|
231
219
|
<LabelsContainer>
|
|
232
220
|
{t('searchPage.resultType.notionLabels')}
|
|
@@ -24,7 +24,7 @@ interface Props {
|
|
|
24
24
|
visualElement: NotionVisualElementType;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const supportedEmbedTypes = ['brightcove', 'h5p'];
|
|
27
|
+
const supportedEmbedTypes = ['brightcove', 'h5p', 'iframe', 'external'];
|
|
28
28
|
const NotionVisualElement = ({ visualElement }: Props) => {
|
|
29
29
|
const id = '1';
|
|
30
30
|
const figureId = 'figure-1';
|