@ndla/ui 3.0.13 → 3.1.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 (35) hide show
  1. package/es/Article/ArticleContent.js +2 -0
  2. package/es/CopyParagraphButton/CopyParagraphButton.js +107 -0
  3. package/es/CopyParagraphButton/index.js +11 -0
  4. package/es/CopyParagraphButton/initCopyParagraphButtons.js +30 -0
  5. package/es/ResourceGroup/ResourceItem.js +13 -13
  6. package/es/index.js +2 -1
  7. package/es/locale/messages-en.js +1 -0
  8. package/es/locale/messages-nb.js +1 -0
  9. package/es/locale/messages-nn.js +1 -0
  10. package/lib/Article/ArticleContent.js +3 -0
  11. package/lib/CopyParagraphButton/CopyParagraphButton.d.ts +12 -0
  12. package/lib/CopyParagraphButton/CopyParagraphButton.js +119 -0
  13. package/lib/CopyParagraphButton/index.d.ts +11 -0
  14. package/lib/CopyParagraphButton/index.js +34 -0
  15. package/lib/CopyParagraphButton/initCopyParagraphButtons.d.ts +2 -0
  16. package/lib/CopyParagraphButton/initCopyParagraphButtons.js +44 -0
  17. package/lib/ResourceGroup/ResourceItem.js +14 -14
  18. package/lib/index.d.ts +1 -0
  19. package/lib/index.js +10 -1
  20. package/lib/locale/messages-en.d.ts +1 -0
  21. package/lib/locale/messages-en.js +1 -0
  22. package/lib/locale/messages-nb.d.ts +1 -0
  23. package/lib/locale/messages-nb.js +1 -0
  24. package/lib/locale/messages-nn.d.ts +1 -0
  25. package/lib/locale/messages-nn.js +1 -0
  26. package/package.json +3 -3
  27. package/src/Article/ArticleContent.tsx +2 -0
  28. package/src/CopyParagraphButton/CopyParagraphButton.tsx +89 -0
  29. package/src/CopyParagraphButton/index.tsx +13 -0
  30. package/src/CopyParagraphButton/initCopyParagraphButtons.tsx +26 -0
  31. package/src/ResourceGroup/ResourceItem.tsx +2 -2
  32. package/src/index.ts +2 -0
  33. package/src/locale/messages-en.ts +1 -0
  34. package/src/locale/messages-nb.ts +1 -0
  35. 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';
package/lib/index.js CHANGED
@@ -103,7 +103,8 @@ var _exportNames = {
103
103
  SubjectSocialSection: true,
104
104
  SubjectTopics: true,
105
105
  SubjectBanner: true,
106
- ContentCard: true
106
+ ContentCard: true,
107
+ CopyParagraphButton: true
107
108
  };
108
109
  Object.defineProperty(exports, "ArticleByline", {
109
110
  enumerable: true,
@@ -693,6 +694,12 @@ Object.defineProperty(exports, "ContentCard", {
693
694
  return _ContentCard["default"];
694
695
  }
695
696
  });
697
+ Object.defineProperty(exports, "CopyParagraphButton", {
698
+ enumerable: true,
699
+ get: function get() {
700
+ return _CopyParagraphButton["default"];
701
+ }
702
+ });
696
703
 
697
704
  var _indexJavascript = require("./index-javascript");
698
705
 
@@ -781,6 +788,8 @@ var _Subject = require("./Subject");
781
788
 
782
789
  var _ContentCard = _interopRequireDefault(require("./ContentCard"));
783
790
 
791
+ var _CopyParagraphButton = _interopRequireDefault(require("./CopyParagraphButton"));
792
+
784
793
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
785
794
 
786
795
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
@@ -342,6 +342,7 @@ declare const messages: {
342
342
  multipleAuthorsLabelAriaConjunction: string;
343
343
  copyPageLink: string;
344
344
  copyPageLinkCopied: string;
345
+ copyHeaderLink: string;
345
346
  conjunction: string;
346
347
  supplierLabel: string;
347
348
  multipleSuppliersLabel: string;
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
303
303
  multipleAuthorsLabelAriaConjunction: 'and',
304
304
  copyPageLink: 'Copy page-link',
305
305
  copyPageLinkCopied: 'Link copied',
306
+ copyHeaderLink: 'Copy link to header',
306
307
  conjunction: 'and',
307
308
  supplierLabel: 'Rightsholder: {{name}}',
308
309
  multipleSuppliersLabel: 'Rightsholders: {{names}}',
@@ -342,6 +342,7 @@ declare const messages: {
342
342
  multipleAuthorsLabelAriaConjunction: string;
343
343
  copyPageLink: string;
344
344
  copyPageLinkCopied: string;
345
+ copyHeaderLink: string;
345
346
  conjunction: string;
346
347
  supplierLabel: string;
347
348
  multipleSuppliersLabel: string;
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
303
303
  multipleAuthorsLabelAriaConjunction: 'og',
304
304
  copyPageLink: 'Kopier lenke til siden',
305
305
  copyPageLinkCopied: 'Lenke kopiert',
306
+ copyHeaderLink: 'Kopier lenke til overskriften',
306
307
  conjunction: 'og',
307
308
  supplierLabel: 'Rettighetshaver: {{name}}',
308
309
  multipleSuppliersLabel: 'Rettighetshavere: {{names}}',
@@ -342,6 +342,7 @@ declare const messages: {
342
342
  multipleAuthorsLabelAriaConjunction: string;
343
343
  copyPageLink: string;
344
344
  copyPageLinkCopied: string;
345
+ copyHeaderLink: string;
345
346
  conjunction: string;
346
347
  supplierLabel: string;
347
348
  multipleSuppliersLabel: string;
@@ -303,6 +303,7 @@ var messages = _objectSpread(_objectSpread({
303
303
  multipleAuthorsLabelAriaConjunction: 'og',
304
304
  copyPageLink: 'Kopier lenke til sida',
305
305
  copyPageLinkCopied: 'Lenke kopiert',
306
+ copyHeaderLink: 'Kopier lenke til overskrifta',
306
307
  conjunction: 'og',
307
308
  supplierLabel: 'Rettshavar: {{name}}',
308
309
  multipleSuppliersLabel: 'Rettshavarar: {{names}}',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/ui",
3
- "version": "3.0.13",
3
+ "version": "3.1.0",
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.46",
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": "815d8d7d88d2a021c35f96421eb357925c0c2b6b"
95
+ "gitHead": "fa15cb6ceb74c400580f44372988b0d9d98e2f3d"
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,89 @@
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
+ }
50
+
51
+ const CopyParagraphButton = ({ title }: Props) => {
52
+ const { t } = useTranslation();
53
+ const [hasCopied, setHasCopied] = useState(false);
54
+ useEffect(() => {
55
+ if (hasCopied) {
56
+ setTimeout(() => setHasCopied(false), 3000);
57
+ }
58
+ }, [hasCopied]);
59
+
60
+ if (!title) return null;
61
+
62
+ const onCopyClick = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
63
+ setHasCopied(true);
64
+ const copyId = event.currentTarget.getAttribute('data-title');
65
+ const { location } = window;
66
+ const newHash = `#${copyId}`;
67
+ const port = location.port ? `:${location.port}` : '';
68
+ const urlToCopy = `${location.protocol}//${location.hostname}${port}${location.pathname}${location.search}${newHash}`;
69
+
70
+ copyTextToClipboard(urlToCopy);
71
+ };
72
+
73
+ const sanitizedTitle = encodeURIComponent(title.replace(/ /g, '-'));
74
+ const tooltip = hasCopied ? t('article.copyPageLinkCopied') : t('article.copyHeaderLink');
75
+ return (
76
+ <ContainerDiv data-header-copy-container data-title={title}>
77
+ <IconButton onClick={onCopyClick} data-title={sanitizedTitle}>
78
+ <Tooltip tooltip={tooltip}>
79
+ <Link title={''} />
80
+ </Tooltip>
81
+ </IconButton>
82
+ <h2 id={sanitizedTitle} tabIndex={0}>
83
+ {title}
84
+ </h2>
85
+ </ContainerDiv>
86
+ );
87
+ };
88
+
89
+ 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,26 @@
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
+ ReactDOM.hydrate(<CopyParagraphButton title={title} />, el);
23
+ });
24
+ };
25
+
26
+ 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
 
@@ -247,7 +247,7 @@ const ResourceItem = ({
247
247
  return (
248
248
  <ListElement
249
249
  contentType={contentType}
250
- hidden={hidden}
250
+ hidden={hidden && !active}
251
251
  active={active}
252
252
  additional={additional}
253
253
  extraBottomMargin={extraBottomMargin}>
package/src/index.ts CHANGED
@@ -135,3 +135,5 @@ export {
135
135
  } from './Subject';
136
136
 
137
137
  export { default as ContentCard } from './ContentCard';
138
+
139
+ export { default as CopyParagraphButton } from './CopyParagraphButton';
@@ -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}}',
@@ -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}}',