@ndla/ui 2.1.1 → 2.1.5

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.
@@ -110,7 +110,8 @@ var TopicMenu = function TopicMenu(_ref) {
110
110
  onNavigate = _ref.onNavigate,
111
111
  subjectCategories = _ref.subjectCategories,
112
112
  programmes = _ref.programmes,
113
- currentProgramme = _ref.currentProgramme;
113
+ currentProgramme = _ref.currentProgramme,
114
+ initialSelectedMenu = _ref.initialSelectedMenu;
114
115
 
115
116
  var _useTranslation = (0, _reactI18next.useTranslation)(),
116
117
  t = _useTranslation.t;
@@ -120,7 +121,9 @@ var TopicMenu = function TopicMenu(_ref) {
120
121
  isNarrowScreen = _useState2[0],
121
122
  setIsNarrowScreen = _useState2[1];
122
123
 
123
- var _useState3 = (0, _react.useState)(MENU_CURRENT_SUBJECT),
124
+ var _useState3 = (0, _react.useState)(function () {
125
+ return initialSelectedMenu || MENU_CURRENT_SUBJECT;
126
+ }),
124
127
  _useState4 = _slicedToArray(_useState3, 2),
125
128
  selectedMenu = _useState4[0],
126
129
  setSelectedMenu = _useState4[1];
@@ -219,7 +222,7 @@ var TopicMenu = function TopicMenu(_ref) {
219
222
  narrow: true
220
223
  }), (0, _core.jsx)(_safelink["default"], _extends({}, classes('back-link'), {
221
224
  to: toFrontpage()
222
- }), (0, _core.jsx)(_common.Home, classes('home-icon', '', 'c-icon--20')), t('masthead.menu.toFrontpage'))), (0, _core.jsx)("div", classes('subject'), (0, _core.jsx)("div", classes('subject__header'), (0, _core.jsx)("div", classes('subject__header__menu-filter'), (0, _core.jsx)(_button["default"], {
225
+ }), (0, _core.jsx)(_common.Home, classes('home-icon', '', 'c-icon--20')), t('masthead.menu.toFrontpage'))), (0, _core.jsx)("div", classes('subject'), (0, _core.jsx)("div", classes('subject__header'), (0, _core.jsx)("div", classes('subject__header__menu-filter'), subjectTitle && (0, _core.jsx)(_button["default"], {
223
226
  onClick: function onClick() {
224
227
  return setSelectedMenu(MENU_CURRENT_SUBJECT);
225
228
  },
@@ -328,11 +331,11 @@ exports.TopicMenu = TopicMenu;
328
331
  TopicMenu.propTypes = {
329
332
  topics: _propTypes["default"].arrayOf(_shapes.TopicShape).isRequired,
330
333
  toFrontpage: _propTypes["default"].func.isRequired,
331
- toTopic: _propTypes["default"].func.isRequired,
332
- toSubject: _propTypes["default"].func.isRequired,
334
+ toTopic: _propTypes["default"].func,
335
+ toSubject: _propTypes["default"].func,
333
336
  close: _propTypes["default"].func,
334
337
  defaultCount: _propTypes["default"].number,
335
- subjectTitle: _propTypes["default"].string.isRequired,
338
+ subjectTitle: _propTypes["default"].string,
336
339
  resourceToLinkProps: _propTypes["default"].func.isRequired,
337
340
  onNavigate: _propTypes["default"].func.isRequired,
338
341
  expandedTopicId: _propTypes["default"].string,
@@ -364,7 +367,8 @@ TopicMenu.propTypes = {
364
367
  }))
365
368
  })).isRequired,
366
369
  selectedGradeIndex: _propTypes["default"].number
367
- })
370
+ }),
371
+ initialSelectedMenu: _propTypes["default"].oneOf([MENU_CURRENT_SUBJECT, MENU_CURRENT_PROGRAMME, MENU_PROGRAMMES, MENU_ALL_SUBJECTS])
368
372
  };
369
373
  TopicMenu.defaultProps = {
370
374
  defaultCount: 12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndla/ui",
3
- "version": "2.1.1",
3
+ "version": "2.1.5",
4
4
  "description": "UI component library for NDLA.",
5
5
  "license": "GPL-3.0",
6
6
  "main": "lib/index.js",
@@ -31,18 +31,18 @@
31
31
  "types"
32
32
  ],
33
33
  "dependencies": {
34
- "@ndla/button": "^1.0.1",
35
- "@ndla/carousel": "^1.0.1",
36
- "@ndla/core": "^0.7.1",
37
- "@ndla/hooks": "^1.0.2",
34
+ "@ndla/button": "^1.0.2",
35
+ "@ndla/carousel": "^1.0.2",
36
+ "@ndla/core": "^0.7.2",
37
+ "@ndla/hooks": "^1.0.3",
38
38
  "@ndla/icons": "^1.0.1",
39
- "@ndla/licenses": "^1.0.1",
40
- "@ndla/modal": "^1.1.3",
39
+ "@ndla/licenses": "^1.0.2",
40
+ "@ndla/modal": "^1.1.5",
41
41
  "@ndla/safelink": "^1.0.1",
42
- "@ndla/switch": "^0.0.31",
43
- "@ndla/tabs": "^1.0.3",
44
- "@ndla/tooltip": "^0.2.43",
45
- "@ndla/util": "^1.0.2",
42
+ "@ndla/switch": "^0.0.32",
43
+ "@ndla/tabs": "^1.0.5",
44
+ "@ndla/tooltip": "^0.2.44",
45
+ "@ndla/util": "^1.0.3",
46
46
  "@reach/menu-button": "^0.12.1",
47
47
  "@reach/slider": "^0.12.1",
48
48
  "@types/hoist-non-react-statics": "^3.3.1",
@@ -92,5 +92,5 @@
92
92
  "publishConfig": {
93
93
  "access": "public"
94
94
  },
95
- "gitHead": "936571e63638860734209e0ed83fb62e23efe016"
95
+ "gitHead": "e10a8348999df08fd71cc4959e873252395bfea9"
96
96
  }
@@ -143,7 +143,7 @@ export const Article = ({
143
143
  const [articleRef, { entry }] = useIntersectionObserver({
144
144
  root: null,
145
145
  rootMargin: '400px',
146
- threshold: 0.25,
146
+ threshold: 0.1,
147
147
  });
148
148
  const [articlePositionRight, setArticlePositionRight] = useState(0);
149
149
  const wrapperRef = useRef<HTMLDivElement>(null);
@@ -10,7 +10,6 @@ import ReactDOM from 'react-dom';
10
10
 
11
11
  import Controls from './Controls';
12
12
  import SpeechControl from './SpeechControl';
13
- import LocaleProvider from '../locale/LocaleProvider';
14
13
  import { Locale } from '../types';
15
14
  import { truncateDescription } from './AudioPlayer';
16
15
 
@@ -28,14 +27,9 @@ const initAudioPlayers = (locale: Locale) => {
28
27
  const speech = el.getAttribute('data-speech');
29
28
  if (src && title) {
30
29
  if (speech) {
31
- ReactDOM.render(<SpeechControl src={src} title={title} />, el);
30
+ ReactDOM.hydrate(<SpeechControl src={src} title={title} />, el);
32
31
  } else {
33
- ReactDOM.render(
34
- <LocaleProvider locale={locale}>
35
- <Controls src={src} title={title} />
36
- </LocaleProvider>,
37
- el,
38
- );
32
+ ReactDOM.hydrate(<Controls src={src} title={title} />, el);
39
33
  }
40
34
  }
41
35
  });
@@ -45,8 +45,8 @@ interface Props {
45
45
  title: string;
46
46
  description?: string;
47
47
  linksTitle?: string;
48
- back: string;
49
- goToFrontPage: string;
48
+ back?: string;
49
+ goToFrontPage?: string;
50
50
  };
51
51
  illustration?: {
52
52
  url: string;
@@ -70,6 +70,7 @@ const ShowVisualElementWrapper = styled.div`
70
70
  width: 100%;
71
71
  height: 100%;
72
72
  overflow: hidden;
73
+ -webkit-mask-image: -webkit-radial-gradient(white, black); /* Safari fix */
73
74
  `;
74
75
 
75
76
  const VisualElementButton = styled(Button)`
@@ -81,7 +82,7 @@ const VisualElementButton = styled(Button)`
81
82
  const TopicHeaderImage = styled.img`
82
83
  width: 100%;
83
84
  height: 100%;
84
- object-fit: cover;
85
+ object-fit: none;
85
86
  transition: transform ${animations.durations.fast};
86
87
  ${VisualElementButton}:hover & {
87
88
  transform: scale(1.1);
@@ -95,7 +96,6 @@ const ExpandVisualElementButton = styled.span`
95
96
  bottom: -4px;
96
97
  transition: all ${animations.durations.fast};
97
98
  ${VisualElementButton}:hover & {
98
- color: ${colors.brand.primary};
99
99
  right: 10px;
100
100
  }
101
101
  ${mq.range({ from: breakpoints.mobileWide })} {
@@ -262,14 +262,14 @@ const Topic = ({
262
262
  <TopicHeaderVisualElementWrapper>
263
263
  {topic.visualElement ? (
264
264
  <>
265
- <ShowVisualElementWrapper>
266
- <Modal
267
- activateButton={
268
- <VisualElementButton
269
- stripped
270
- title={
271
- topic.visualElement.type === 'image' ? t('image.largeSize') : t('visualElement.show')
272
- }>
265
+ <Modal
266
+ activateButton={
267
+ <VisualElementButton
268
+ stripped
269
+ title={
270
+ topic.visualElement.type === 'image' ? t('image.largeSize') : t('visualElement.show')
271
+ }>
272
+ <ShowVisualElementWrapper>
273
273
  <TopicHeaderImage
274
274
  src={`${topic.image.url}?${makeSrcQueryString(
275
275
  400,
@@ -281,35 +281,35 @@ const Topic = ({
281
281
  focalPoint={topic.image.focalPoint}
282
282
  />
283
283
  <TopicHeaderOverlay />
284
- <ExpandVisualElementButton>
285
- {topic.visualElement.type === 'image' && (
286
- <ExpandTwoArrows style={{ width: '24px', height: '24px' }} />
287
- )}
288
- {topic.visualElement.type === 'video' && (
289
- <PlayCircleFilled style={{ width: '24px', height: '24px' }} />
290
- )}
291
- {topic.visualElement.type === 'other' && (
292
- <CursorClick style={{ width: '24px', height: '24px' }} />
293
- )}
294
- </ExpandVisualElementButton>
295
- </VisualElementButton>
296
- }
297
- animation="subtle"
298
- animationDuration={50}
299
- backgroundColor="white"
300
- size="large">
301
- {(onClose: () => void) => (
302
- <>
303
- <ModalHeader>
304
- <ModalCloseButton onClick={onClose} title={t('modal.closeModal')} />
305
- </ModalHeader>
306
- <ModalBody modifier="no-side-padding-mobile">
307
- {topic.visualElement && topic.visualElement.element}
308
- </ModalBody>
309
- </>
310
- )}
311
- </Modal>
312
- </ShowVisualElementWrapper>
284
+ </ShowVisualElementWrapper>
285
+ <ExpandVisualElementButton>
286
+ {topic.visualElement.type === 'image' && (
287
+ <ExpandTwoArrows style={{ width: '24px', height: '24px' }} />
288
+ )}
289
+ {topic.visualElement.type === 'video' && (
290
+ <PlayCircleFilled style={{ width: '24px', height: '24px' }} />
291
+ )}
292
+ {topic.visualElement.type === 'other' && (
293
+ <CursorClick style={{ width: '24px', height: '24px' }} />
294
+ )}
295
+ </ExpandVisualElementButton>
296
+ </VisualElementButton>
297
+ }
298
+ animation="subtle"
299
+ animationDuration={50}
300
+ backgroundColor="white"
301
+ size="large">
302
+ {(onClose: () => void) => (
303
+ <>
304
+ <ModalHeader>
305
+ <ModalCloseButton onClick={onClose} title={t('modal.closeModal')} />
306
+ </ModalHeader>
307
+ <ModalBody modifier="no-side-padding-mobile">
308
+ {topic.visualElement && topic.visualElement.element}
309
+ </ModalBody>
310
+ </>
311
+ )}
312
+ </Modal>
313
313
  </>
314
314
  ) : (
315
315
  <TopicHeaderImage
@@ -71,10 +71,11 @@ export const TopicMenu = ({
71
71
  subjectCategories,
72
72
  programmes,
73
73
  currentProgramme,
74
+ initialSelectedMenu,
74
75
  }) => {
75
76
  const { t } = useTranslation();
76
77
  const [isNarrowScreen, setIsNarrowScreen] = useState(false);
77
- const [selectedMenu, setSelectedMenu] = useState(MENU_CURRENT_SUBJECT);
78
+ const [selectedMenu, setSelectedMenu] = useState(() => initialSelectedMenu || MENU_CURRENT_SUBJECT);
78
79
 
79
80
  useEffect(() => {
80
81
  const setScreenSize = (initial = false) => {
@@ -178,13 +179,15 @@ export const TopicMenu = ({
178
179
  <div {...classes('subject')}>
179
180
  <div {...classes('subject__header')}>
180
181
  <div {...classes('subject__header__menu-filter')}>
181
- <Button
182
- onClick={() => setSelectedMenu(MENU_CURRENT_SUBJECT)}
183
- lighter={selectedMenu !== MENU_CURRENT_SUBJECT}
184
- size="small"
185
- borderShape="rounded">
186
- {subjectTitle}
187
- </Button>
182
+ {subjectTitle && (
183
+ <Button
184
+ onClick={() => setSelectedMenu(MENU_CURRENT_SUBJECT)}
185
+ lighter={selectedMenu !== MENU_CURRENT_SUBJECT}
186
+ size="small"
187
+ borderShape="rounded">
188
+ {subjectTitle}
189
+ </Button>
190
+ )}
188
191
  {currentProgramme && (
189
192
  <Button
190
193
  onClick={() => setSelectedMenu(MENU_CURRENT_PROGRAMME)}
@@ -346,11 +349,11 @@ export const TopicMenu = ({
346
349
  TopicMenu.propTypes = {
347
350
  topics: PropTypes.arrayOf(TopicShape).isRequired,
348
351
  toFrontpage: PropTypes.func.isRequired,
349
- toTopic: PropTypes.func.isRequired,
350
- toSubject: PropTypes.func.isRequired,
352
+ toTopic: PropTypes.func,
353
+ toSubject: PropTypes.func,
351
354
  close: PropTypes.func,
352
355
  defaultCount: PropTypes.number,
353
- subjectTitle: PropTypes.string.isRequired,
356
+ subjectTitle: PropTypes.string,
354
357
  resourceToLinkProps: PropTypes.func.isRequired,
355
358
  onNavigate: PropTypes.func.isRequired,
356
359
  expandedTopicId: PropTypes.string,
@@ -395,6 +398,12 @@ TopicMenu.propTypes = {
395
398
  ).isRequired,
396
399
  selectedGradeIndex: PropTypes.number,
397
400
  }),
401
+ initialSelectedMenu: PropTypes.oneOf([
402
+ MENU_CURRENT_SUBJECT,
403
+ MENU_CURRENT_PROGRAMME,
404
+ MENU_PROGRAMMES,
405
+ MENU_ALL_SUBJECTS,
406
+ ]),
398
407
  };
399
408
 
400
409
  TopicMenu.defaultProps = {