@ndla/ui 6.1.1 → 6.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/ui",
3
- "version": "6.1.1",
3
+ "version": "6.2.0",
4
4
  "description": "UI component library for NDLA.",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -31,17 +31,17 @@
31
31
  "types"
32
32
  ],
33
33
  "dependencies": {
34
- "@ndla/button": "^2.1.2",
35
- "@ndla/carousel": "^1.2.2",
36
- "@ndla/core": "^2.0.0",
34
+ "@ndla/button": "^2.1.3",
35
+ "@ndla/carousel": "^1.2.3",
36
+ "@ndla/core": "^2.0.1",
37
37
  "@ndla/hooks": "^1.1.2",
38
38
  "@ndla/icons": "^1.6.1",
39
- "@ndla/licenses": "^4.0.1",
40
- "@ndla/modal": "^1.2.2",
41
- "@ndla/safelink": "^1.1.3",
42
- "@ndla/switch": "^0.1.2",
39
+ "@ndla/licenses": "^4.0.2",
40
+ "@ndla/modal": "^1.2.3",
41
+ "@ndla/safelink": "^1.1.4",
42
+ "@ndla/switch": "^0.1.3",
43
43
  "@ndla/tabs": "^1.1.2",
44
- "@ndla/tooltip": "^0.3.2",
44
+ "@ndla/tooltip": "^0.3.3",
45
45
  "@ndla/util": "^2.0.4",
46
46
  "@reach/menu-button": "^0.16.2",
47
47
  "@reach/slider": "^0.16.0",
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "fa8891f69438a94440d4fbb73c8ed7dfff867311"
84
+ "gitHead": "69b0ff1d72d2650ffbe42383bc7416d14d774d91"
85
85
  }
@@ -6,26 +6,38 @@
6
6
  *
7
7
  */
8
8
 
9
- import { useState } from 'react';
9
+ import { useEffect, useState } from 'react';
10
10
  import { resizeObserver } from '@ndla/util';
11
11
 
12
12
  export const getMastheadHeight = (): number | undefined => {
13
- const masthead = document && document.getElementById('masthead');
14
- return masthead?.getBoundingClientRect().height;
13
+ if (typeof window !== 'undefined') {
14
+ const masthead = document.getElementById('masthead');
15
+ return masthead?.getBoundingClientRect().height;
16
+ }
15
17
  };
16
18
 
17
19
  export const useMastheadHeight = () => {
18
20
  const [height, setHeight] = useState<number>();
19
- const masthead = document && document.getElementById('masthead');
21
+ const [mounted, setMounted] = useState(false);
20
22
 
21
- const handleHeightChange = (el: HTMLElement) => {
22
- const newHeight = el.getBoundingClientRect().height;
23
- setHeight(newHeight);
24
- };
23
+ useEffect(() => {
24
+ setMounted(true);
25
+ }, []);
25
26
 
26
- if (masthead) {
27
- resizeObserver(masthead, handleHeightChange);
28
- }
27
+ useEffect(() => {
28
+ if (mounted) {
29
+ const masthead = document.getElementById('masthead');
30
+
31
+ const handleHeightChange = (el: HTMLElement) => {
32
+ const newHeight = el.getBoundingClientRect().height;
33
+ setHeight(newHeight);
34
+ };
35
+
36
+ if (masthead) {
37
+ resizeObserver(masthead, handleHeightChange);
38
+ }
39
+ }
40
+ }, [mounted]);
29
41
 
30
42
  return {
31
43
  height,
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- import React, { useState } from 'react';
9
+ import React, { HTMLAttributes, useState } from 'react';
10
10
  import styled from '@emotion/styled';
11
11
  import Sticky from 'react-sticky-el';
12
12
  import { breakpoints, fonts, mq, spacing } from '@ndla/core';
@@ -25,13 +25,15 @@ type WrapperProps = {
25
25
  };
26
26
 
27
27
  const StyleByType = (type: WrapperProps['boxType']) => {
28
- const styles = {
28
+ const styles: HTMLAttributes<HTMLElement>['style'] = {
29
29
  margin: '1px',
30
30
  color: '#444444',
31
31
  backgroundColor: '#f9f4c8',
32
32
  border: 'none',
33
33
  display: 'flex',
34
+ padding: '10px',
34
35
  width: 'auto',
36
+ borderRadius: '5px',
35
37
  position: 'relative',
36
38
  transform: 'auto',
37
39
  left: 'auto',
@@ -56,6 +58,8 @@ const StyleByType = (type: WrapperProps['boxType']) => {
56
58
  case 'masthead':
57
59
  styles.margin = '0 auto';
58
60
  styles.display = 'none';
61
+ styles.padding = '0';
62
+ styles.borderRadius = '0';
59
63
  break;
60
64
  }
61
65
  return styles;
@@ -71,7 +75,7 @@ const Wrapper = styled.div<WrapperProps>`
71
75
  padding: ${spacing.small};
72
76
  position: ${(props) => StyleByType(props.boxType).position};
73
77
  border: ${(props) => StyleByType(props.boxType).border};
74
- border-radius: 5px;
78
+ border-radius: ${(props) => StyleByType(props.boxType).borderRadius};
75
79
  transform: ${(props) => StyleByType(props.boxType).transform};
76
80
  left: ${(props) => StyleByType(props.boxType).left};
77
81
  z-index: 10;
@@ -80,7 +84,7 @@ const Wrapper = styled.div<WrapperProps>`
80
84
 
81
85
  const InfoWrapper = styled.div<WrapperProps>`
82
86
  margin: ${(props) => StyleByType(props.boxType).margin};
83
- padding: 10px;
87
+ padding: ${(props) => StyleByType(props.boxType).padding};
84
88
  display: flex;
85
89
  ${mq.range({ until: breakpoints.tabletWide })} {
86
90
  padding: 0 90px 0 0;
@@ -28,16 +28,19 @@ export interface ConceptNotionType {
28
28
  }
29
29
  interface Props {
30
30
  concept: ConceptNotionType;
31
+ disableScripts?: boolean;
31
32
  }
32
33
 
33
- const ConceptNotion = ({ concept }: Props) => {
34
+ const ConceptNotion = ({ concept, disableScripts }: Props) => {
34
35
  const notionId = `notion-${concept.id}`;
35
36
  const figureId = `notion-figure-${concept.id}`;
36
37
  const visualElementId = `visual-element-${concept.id}`;
37
38
 
38
39
  useEffect(() => {
39
- initArticleScripts();
40
- }, []);
40
+ if (!disableScripts) {
41
+ initArticleScripts();
42
+ }
43
+ }, [disableScripts]);
41
44
  return (
42
45
  <FigureNotion
43
46
  id={figureId}
@@ -28,6 +28,7 @@ import Logo from '../Logo';
28
28
  import FrontpageAllSubjects from '../Frontpage/FrontpageAllSubjects';
29
29
  import NavigationBox from '../Navigation/NavigationBox';
30
30
  import { ProgrammeSubjects } from '../Programme';
31
+ import { MessageBox, MessageBoxType } from '../MessageBox';
31
32
 
32
33
  const classes = new BEMHelper({
33
34
  name: 'topic-menu',
@@ -72,6 +73,7 @@ export const TopicMenu = ({
72
73
  programmes,
73
74
  currentProgramme,
74
75
  initialSelectedMenu,
76
+ messages,
75
77
  }) => {
76
78
  const { t } = useTranslation();
77
79
  const [isNarrowScreen, setIsNarrowScreen] = useState(false);
@@ -148,6 +150,9 @@ export const TopicMenu = ({
148
150
 
149
151
  return (
150
152
  <nav>
153
+ {messages?.map((message) => (
154
+ <MessageBox type={MessageBoxType.masthead}>{message}</MessageBox>
155
+ ))}
151
156
  <ModalHeader modifier={['white', 'menu']}>
152
157
  <div {...classes('masthead-left')}>
153
158
  <button type="button" {...classes('close-button')} onClick={closeMenu}>