@ndla/ui 3.0.14 → 3.1.1-alpha.13
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/CopyParagraphButton/CopyParagraphButton.js +10 -5
- package/es/CopyParagraphButton/initCopyParagraphButtons.js +3 -1
- package/es/ResourceGroup/ResourceItem.js +13 -13
- package/es/locale/messages-en.js +1 -1
- package/es/locale/messages-nb.js +2 -2
- package/lib/CopyParagraphButton/CopyParagraphButton.d.ts +13 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js +10 -5
- package/lib/CopyParagraphButton/index.d.ts +11 -0
- package/lib/CopyParagraphButton/initCopyParagraphButtons.d.ts +2 -0
- package/lib/CopyParagraphButton/initCopyParagraphButtons.js +3 -1
- package/lib/ResourceGroup/ResourceItem.js +14 -14
- package/lib/index.d.ts +1 -0
- package/lib/locale/messages-en.d.ts +1 -0
- package/lib/locale/messages-en.js +1 -1
- package/lib/locale/messages-nb.d.ts +1 -0
- package/lib/locale/messages-nb.js +2 -2
- package/lib/locale/messages-nn.d.ts +1 -0
- package/package.json +3 -3
- package/src/Article/ArticleContent.tsx +2 -0
- package/src/CopyParagraphButton/CopyParagraphButton.tsx +88 -0
- package/src/CopyParagraphButton/index.tsx +13 -0
- package/src/CopyParagraphButton/initCopyParagraphButtons.tsx +27 -0
- package/src/ResourceGroup/ResourceItem.tsx +1 -1
- package/src/index.ts +2 -0
- package/src/locale/messages-en.ts +2 -1
- package/src/locale/messages-nb.ts +3 -2
- package/src/locale/messages-nn.ts +1 -0
package/lib/index.d.ts
CHANGED
|
@@ -46,3 +46,4 @@ export { default as ResourceGroup } from './ResourceGroup';
|
|
|
46
46
|
export { default as LayoutItem, OneColumn, PageContainer, Content } from './Layout';
|
|
47
47
|
export { SubjectAbout, SubjectArchive, SubjectCarousel, SubjectChildContent, SubjectContent, SubjectFilter, SubjectFlexChild, SubjectFlexWrapper, SubjectHeader, SubjectLinks, SubjectNewContent, SubjectSecondaryContent, SubjectSectionTitle, SubjectShortcuts, SubjectSidebarWrapper, SubjectSocialContent, SubjectSocialSection, SubjectTopics, SubjectBanner, } from './Subject';
|
|
48
48
|
export { default as ContentCard } from './ContentCard';
|
|
49
|
+
export { default as CopyParagraphButton } from './CopyParagraphButton';
|
|
@@ -137,7 +137,7 @@ var messages = _objectSpread(_objectSpread({
|
|
|
137
137
|
showingCompetenceGoalSearchPhrase: 'Showing results for competence goals {text}',
|
|
138
138
|
searchPhraseSuggestion: 'Search instead for:',
|
|
139
139
|
notionLabels: 'Used in',
|
|
140
|
-
notionsHeading: '
|
|
140
|
+
notionsHeading: 'Explanations',
|
|
141
141
|
notionsRemove: 'Remove',
|
|
142
142
|
showVideo: 'Watch video',
|
|
143
143
|
showNotion: 'Show notion'
|
|
@@ -737,8 +737,8 @@ var messages = _objectSpread(_objectSpread({
|
|
|
737
737
|
showLongerDescription: 'Vis hele emnebeskrivelsen',
|
|
738
738
|
showShorterDescription: 'Skjul emnebeskrivelsen',
|
|
739
739
|
topics: 'Emner',
|
|
740
|
-
additionalTopic: '
|
|
741
|
-
additionalTopics: '
|
|
740
|
+
additionalTopic: 'Tilleggsemne',
|
|
741
|
+
additionalTopics: 'Tilleggsemner',
|
|
742
742
|
loadingText: 'Laster emne'
|
|
743
743
|
},
|
|
744
744
|
multidisciplinarySubject: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ndla/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1-alpha.13+a107d8a2e",
|
|
4
4
|
"description": "UI component library for NDLA.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@ndla/safelink": "^1.0.5",
|
|
42
42
|
"@ndla/switch": "^0.0.32",
|
|
43
43
|
"@ndla/tabs": "^1.0.8",
|
|
44
|
-
"@ndla/tooltip": "^0.2.
|
|
44
|
+
"@ndla/tooltip": "^0.2.47",
|
|
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": "
|
|
95
|
+
"gitHead": "a107d8a2e1064e49834d15188e956bb6af67d3fb"
|
|
96
96
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
// @ts-ignore
|
|
14
14
|
} from '@ndla/article-scripts';
|
|
15
15
|
import { initAudioPlayers } from '../AudioPlayer';
|
|
16
|
+
import { initCopyParagraphButtons } from '../CopyParagraphButton';
|
|
16
17
|
import { Locale } from '../types';
|
|
17
18
|
|
|
18
19
|
type Props = {
|
|
@@ -24,6 +25,7 @@ const ArticleContent = ({ content, locale, ...rest }: Props) => {
|
|
|
24
25
|
removeEventListenerForResize();
|
|
25
26
|
initArticleScripts();
|
|
26
27
|
initAudioPlayers(locale);
|
|
28
|
+
initCopyParagraphButtons();
|
|
27
29
|
return () => {
|
|
28
30
|
removeEventListenerForResize();
|
|
29
31
|
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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, { useEffect, useState } from 'react';
|
|
10
|
+
|
|
11
|
+
import styled from '@emotion/styled';
|
|
12
|
+
import { Link } from '@ndla/icons/common';
|
|
13
|
+
import { useTranslation } from 'react-i18next';
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import Tooltip from '@ndla/tooltip';
|
|
16
|
+
import { copyTextToClipboard } from '@ndla/util';
|
|
17
|
+
|
|
18
|
+
const IconButton = styled.button`
|
|
19
|
+
float: left;
|
|
20
|
+
position: relative;
|
|
21
|
+
left: -3em;
|
|
22
|
+
top: 0.1em;
|
|
23
|
+
background: none;
|
|
24
|
+
border: 0;
|
|
25
|
+
z-index: 1;
|
|
26
|
+
transition: 0.2s;
|
|
27
|
+
opacity: 0;
|
|
28
|
+
|
|
29
|
+
& svg {
|
|
30
|
+
width: 30px;
|
|
31
|
+
height: 30px;
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const ContainerDiv = styled.div`
|
|
36
|
+
&:hover button {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
opacity: 0.5;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
& h2 {
|
|
42
|
+
position: relative;
|
|
43
|
+
left: -2em;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
interface Props {
|
|
48
|
+
title?: string | null;
|
|
49
|
+
content?: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const CopyParagraphButton = ({ title, content }: Props) => {
|
|
53
|
+
const { t } = useTranslation();
|
|
54
|
+
const [hasCopied, setHasCopied] = useState(false);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (hasCopied) {
|
|
57
|
+
setTimeout(() => setHasCopied(false), 3000);
|
|
58
|
+
}
|
|
59
|
+
}, [hasCopied]);
|
|
60
|
+
|
|
61
|
+
if (!title) return null;
|
|
62
|
+
|
|
63
|
+
const onCopyClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
|
|
64
|
+
setHasCopied(true);
|
|
65
|
+
const copyId = event.currentTarget.getAttribute('data-title');
|
|
66
|
+
const { location } = window;
|
|
67
|
+
const newHash = `#${copyId}`;
|
|
68
|
+
const port = location.port ? `:${location.port}` : '';
|
|
69
|
+
const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
|
|
70
|
+
|
|
71
|
+
copyTextToClipboard(urlToCopy);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
|
|
75
|
+
const tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
|
|
76
|
+
return (
|
|
77
|
+
<ContainerDiv data-header-copy-container data-title={title}>
|
|
78
|
+
<IconButton onClick={onCopyClick} data-title={sanitizedTitle}>
|
|
79
|
+
<Tooltip tooltip={tooltip}>
|
|
80
|
+
<Link title={''} />
|
|
81
|
+
</Tooltip>
|
|
82
|
+
</IconButton>
|
|
83
|
+
<h2 id={sanitizedTitle} tabIndex={0} dangerouslySetInnerHTML={{ __html: content || '' }}></h2>
|
|
84
|
+
</ContainerDiv>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 CopyParagraphButton from './CopyParagraphButton';
|
|
10
|
+
import initCopyParagraphButtons from './initCopyParagraphButtons';
|
|
11
|
+
|
|
12
|
+
export { CopyParagraphButton, initCopyParagraphButtons };
|
|
13
|
+
export default CopyParagraphButton;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2021-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 React from 'react';
|
|
9
|
+
import ReactDOM from 'react-dom';
|
|
10
|
+
import CopyParagraphButton from './CopyParagraphButton';
|
|
11
|
+
|
|
12
|
+
const forEachElement = (selector: string, callback: Function) => {
|
|
13
|
+
const nodeList = document.querySelectorAll(selector);
|
|
14
|
+
for (let i = 0; i < nodeList.length; i += 1) {
|
|
15
|
+
callback(nodeList[i], i);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const initCopyParagraphButtons = () => {
|
|
20
|
+
forEachElement('[data-header-copy-container]', (el: HTMLElement) => {
|
|
21
|
+
const title = el.getAttribute('data-title');
|
|
22
|
+
const content = el.innerHTML;
|
|
23
|
+
ReactDOM.hydrate(<CopyParagraphButton title={title} content={content} />, el);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default initCopyParagraphButtons;
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import React from 'react';
|
|
10
|
+
import { useTranslation } from 'react-i18next';
|
|
10
11
|
import styled from '@emotion/styled';
|
|
11
12
|
import css from '@emotion/css';
|
|
12
13
|
import { keyframes } from '@emotion/core';
|
|
13
14
|
import SafeLink from '@ndla/safelink';
|
|
14
|
-
import { useTranslation } from 'react-i18next';
|
|
15
15
|
import { Additional, Core, HumanMaleBoard } from '@ndla/icons/common';
|
|
16
16
|
import { breakpoints, colors, fonts, mq, spacing } from '@ndla/core';
|
|
17
17
|
|
package/src/index.ts
CHANGED
|
@@ -134,7 +134,7 @@ const messages = {
|
|
|
134
134
|
showingCompetenceGoalSearchPhrase: 'Showing results for competence goals {text}',
|
|
135
135
|
searchPhraseSuggestion: 'Search instead for:',
|
|
136
136
|
notionLabels: 'Used in',
|
|
137
|
-
notionsHeading: '
|
|
137
|
+
notionsHeading: 'Explanations',
|
|
138
138
|
notionsRemove: 'Remove',
|
|
139
139
|
showVideo: 'Watch video',
|
|
140
140
|
showNotion: 'Show notion',
|
|
@@ -327,6 +327,7 @@ const messages = {
|
|
|
327
327
|
multipleAuthorsLabelAriaConjunction: 'and',
|
|
328
328
|
copyPageLink: 'Copy page-link',
|
|
329
329
|
copyPageLinkCopied: 'Link copied',
|
|
330
|
+
copyHeaderLink: 'Copy link to header',
|
|
330
331
|
conjunction: 'and',
|
|
331
332
|
supplierLabel: 'Rightsholder: {{name}}',
|
|
332
333
|
multipleSuppliersLabel: 'Rightsholders: {{names}}',
|
|
@@ -326,6 +326,7 @@ const messages = {
|
|
|
326
326
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
327
327
|
copyPageLink: 'Kopier lenke til siden',
|
|
328
328
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
329
|
+
copyHeaderLink: 'Kopier lenke til overskriften',
|
|
329
330
|
conjunction: 'og',
|
|
330
331
|
supplierLabel: 'Rettighetshaver: {{name}}',
|
|
331
332
|
multipleSuppliersLabel: 'Rettighetshavere: {{names}}',
|
|
@@ -764,8 +765,8 @@ const messages = {
|
|
|
764
765
|
showLongerDescription: 'Vis hele emnebeskrivelsen',
|
|
765
766
|
showShorterDescription: 'Skjul emnebeskrivelsen',
|
|
766
767
|
topics: 'Emner',
|
|
767
|
-
additionalTopic: '
|
|
768
|
-
additionalTopics: '
|
|
768
|
+
additionalTopic: 'Tilleggsemne',
|
|
769
|
+
additionalTopics: 'Tilleggsemner',
|
|
769
770
|
loadingText: 'Laster emne',
|
|
770
771
|
},
|
|
771
772
|
multidisciplinarySubject: {
|
|
@@ -327,6 +327,7 @@ const messages = {
|
|
|
327
327
|
multipleAuthorsLabelAriaConjunction: 'og',
|
|
328
328
|
copyPageLink: 'Kopier lenke til sida',
|
|
329
329
|
copyPageLinkCopied: 'Lenke kopiert',
|
|
330
|
+
copyHeaderLink: 'Kopier lenke til overskrifta',
|
|
330
331
|
conjunction: 'og',
|
|
331
332
|
supplierLabel: 'Rettshavar: {{name}}',
|
|
332
333
|
multipleSuppliersLabel: 'Rettshavarar: {{names}}',
|