@ndla/ui 12.0.2 → 13.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 (58) hide show
  1. package/es/Breadcrumb/Breadcrumb.js +101 -24
  2. package/es/Breadcrumb/BreadcrumbItem.js +70 -18
  3. package/es/Breadcrumb/HeaderBreadcrumb.js +82 -0
  4. package/es/Breadcrumb/HomeBreadcrumb.js +117 -0
  5. package/es/Breadcrumb/index.js +2 -1
  6. package/es/Breadcrumblist/index.js +1 -2
  7. package/es/all.css +1 -1
  8. package/es/index.js +1 -1
  9. package/es/locale/messages-en.js +55 -16
  10. package/es/locale/messages-nb.js +54 -15
  11. package/es/locale/messages-nn.js +55 -16
  12. package/es/locale/messages-se.js +52 -13
  13. package/es/locale/messages-sma.js +52 -13
  14. package/lib/Breadcrumb/Breadcrumb.d.ts +10 -12
  15. package/lib/Breadcrumb/Breadcrumb.js +104 -32
  16. package/lib/Breadcrumb/BreadcrumbItem.d.ts +15 -7
  17. package/lib/Breadcrumb/BreadcrumbItem.js +68 -20
  18. package/lib/Breadcrumb/HeaderBreadcrumb.d.ts +15 -0
  19. package/lib/Breadcrumb/HeaderBreadcrumb.js +95 -0
  20. package/lib/Breadcrumb/HomeBreadcrumb.d.ts +15 -0
  21. package/lib/Breadcrumb/HomeBreadcrumb.js +127 -0
  22. package/lib/Breadcrumb/index.d.ts +3 -1
  23. package/lib/Breadcrumb/index.js +11 -3
  24. package/lib/Breadcrumblist/index.js +0 -1
  25. package/lib/all.css +1 -1
  26. package/lib/index.d.ts +2 -1
  27. package/lib/index.js +10 -3
  28. package/lib/locale/messages-en.d.ts +39 -0
  29. package/lib/locale/messages-en.js +55 -16
  30. package/lib/locale/messages-nb.d.ts +39 -0
  31. package/lib/locale/messages-nb.js +54 -15
  32. package/lib/locale/messages-nn.d.ts +39 -0
  33. package/lib/locale/messages-nn.js +55 -16
  34. package/lib/locale/messages-se.d.ts +39 -0
  35. package/lib/locale/messages-se.js +52 -13
  36. package/lib/locale/messages-sma.d.ts +40 -1
  37. package/lib/locale/messages-sma.js +52 -13
  38. package/package.json +4 -4
  39. package/src/Breadcrumb/Breadcrumb.tsx +76 -40
  40. package/src/Breadcrumb/BreadcrumbItem.tsx +82 -18
  41. package/src/Breadcrumb/HeaderBreadcrumb.tsx +78 -0
  42. package/src/Breadcrumb/HomeBreadcrumb.tsx +88 -0
  43. package/src/Breadcrumb/index.ts +5 -1
  44. package/src/Breadcrumblist/index.tsx +0 -1
  45. package/src/index.ts +2 -1
  46. package/src/locale/__tests__/translations-test.ts +10 -0
  47. package/src/locale/messages-en.ts +51 -12
  48. package/src/locale/messages-nb.ts +50 -11
  49. package/src/locale/messages-nn.ts +52 -13
  50. package/src/locale/messages-se.ts +48 -9
  51. package/src/locale/messages-sma.ts +49 -10
  52. package/src/main.scss +0 -2
  53. package/es/Breadcrumb/BreadcrumbBlock.js +0 -90
  54. package/lib/Breadcrumb/BreadcrumbBlock.d.ts +0 -15
  55. package/lib/Breadcrumb/BreadcrumbBlock.js +0 -105
  56. package/src/Breadcrumb/BreadcrumbBlock.tsx +0 -80
  57. package/src/Breadcrumb/component.breadcrumb-block.scss +0 -98
  58. package/src/Breadcrumb/component.breadcrumb.scss +0 -104
@@ -1,90 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
-
5
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
-
9
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
-
11
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
-
13
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
-
15
- /**
16
- * Copyright (c) 2019-present, NDLA.
17
- *
18
- * This source code is licensed under the GPLv3 license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- *
21
- */
22
- import React, { useRef } from 'react';
23
- import BEMHelper from 'react-bem-helper';
24
- import { useComponentSize, useIsomorphicLayoutEffect } from '@ndla/hooks';
25
- import { useTranslation } from 'react-i18next';
26
- import BreadcrumbItem from './BreadcrumbItem';
27
- import { jsx as ___EmotionJSX } from "@emotion/core";
28
- var classes = BEMHelper({
29
- name: 'breadcrumb-block',
30
- prefix: 'c-'
31
- });
32
-
33
- var BreadcrumbBlock = function BreadcrumbBlock(_ref) {
34
- var children = _ref.children,
35
- items = _ref.items;
36
-
37
- var _useTranslation = useTranslation(),
38
- t = _useTranslation.t;
39
-
40
- var olRef = useRef();
41
- var containerRef = useRef(null); // No idiomatic way of dealing with sets of refs yet
42
- // See: https://github.com/facebook/react/issues/14072#issuecomment-446777406
43
-
44
- var breadcrumbItemRefs = useRef(new Map()).current;
45
- var size = useComponentSize(containerRef);
46
- useIsomorphicLayoutEffect(function () {
47
- // Create an array of all breadcrumb item refs
48
- var items = Array.from(breadcrumbItemRefs).map(function (_ref2) {
49
- var _ref3 = _slicedToArray(_ref2, 2),
50
- key = _ref3[0],
51
- value = _ref3[1];
52
-
53
- return value;
54
- }); // Clear max width on all items
55
-
56
- items.forEach(function (el) {
57
- el.setMaxWidth('none');
58
- }); // Set maxWidth on breadcrumb text items iteratively until
59
- // the ordered list fits on a single line. It's on a single line
60
- // if the height of the list is less then 70.
61
-
62
- items.forEach(function (el) {
63
- if (olRef.current.offsetHeight > 70) {
64
- el.setMaxWidth('40px');
65
- }
66
- });
67
- }, [size]);
68
- return ___EmotionJSX("nav", _extends({}, classes(''), {
69
- ref: containerRef,
70
- "aria-label": t('breadcrumb.breadcrumb')
71
- }), children, ___EmotionJSX("ol", _extends({}, classes('list'), {
72
- ref: olRef
73
- }), items.map(function (item, i) {
74
- return ___EmotionJSX(BreadcrumbItem, {
75
- ref: function ref(element) {
76
- return element === null || i === 0 // skip first item which is never truncated
77
- ? breadcrumbItemRefs["delete"](item.to) : breadcrumbItemRefs.set(item.to, element);
78
- },
79
- classes: classes,
80
- key: item.to,
81
- isCurrent: i === items.length - 1,
82
- to: item.to,
83
- name: item.name,
84
- home: false,
85
- invertedStyle: false
86
- }, item.name);
87
- })));
88
- };
89
-
90
- export default BreadcrumbBlock;
@@ -1,15 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-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 { ReactNode } from 'react';
9
- import { BreadcrumbItemI } from './Breadcrumb';
10
- interface Props {
11
- children?: ReactNode;
12
- items: BreadcrumbItemI[];
13
- }
14
- declare const BreadcrumbBlock: ({ children, items }: Props) => JSX.Element;
15
- export default BreadcrumbBlock;
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _reactBemHelper = _interopRequireDefault(require("react-bem-helper"));
13
-
14
- var _hooks = require("@ndla/hooks");
15
-
16
- var _reactI18next = require("react-i18next");
17
-
18
- var _BreadcrumbItem = _interopRequireDefault(require("./BreadcrumbItem"));
19
-
20
- var _core = require("@emotion/core");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
23
-
24
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
25
-
26
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
29
-
30
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
31
-
32
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
-
34
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
35
-
36
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
37
-
38
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
39
-
40
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
41
-
42
- var classes = (0, _reactBemHelper["default"])({
43
- name: 'breadcrumb-block',
44
- prefix: 'c-'
45
- });
46
-
47
- var BreadcrumbBlock = function BreadcrumbBlock(_ref) {
48
- var children = _ref.children,
49
- items = _ref.items;
50
-
51
- var _useTranslation = (0, _reactI18next.useTranslation)(),
52
- t = _useTranslation.t;
53
-
54
- var olRef = (0, _react.useRef)();
55
- var containerRef = (0, _react.useRef)(null); // No idiomatic way of dealing with sets of refs yet
56
- // See: https://github.com/facebook/react/issues/14072#issuecomment-446777406
57
-
58
- var breadcrumbItemRefs = (0, _react.useRef)(new Map()).current;
59
- var size = (0, _hooks.useComponentSize)(containerRef);
60
- (0, _hooks.useIsomorphicLayoutEffect)(function () {
61
- // Create an array of all breadcrumb item refs
62
- var items = Array.from(breadcrumbItemRefs).map(function (_ref2) {
63
- var _ref3 = _slicedToArray(_ref2, 2),
64
- key = _ref3[0],
65
- value = _ref3[1];
66
-
67
- return value;
68
- }); // Clear max width on all items
69
-
70
- items.forEach(function (el) {
71
- el.setMaxWidth('none');
72
- }); // Set maxWidth on breadcrumb text items iteratively until
73
- // the ordered list fits on a single line. It's on a single line
74
- // if the height of the list is less then 70.
75
-
76
- items.forEach(function (el) {
77
- if (olRef.current.offsetHeight > 70) {
78
- el.setMaxWidth('40px');
79
- }
80
- });
81
- }, [size]);
82
- return (0, _core.jsx)("nav", _extends({}, classes(''), {
83
- ref: containerRef,
84
- "aria-label": t('breadcrumb.breadcrumb')
85
- }), children, (0, _core.jsx)("ol", _extends({}, classes('list'), {
86
- ref: olRef
87
- }), items.map(function (item, i) {
88
- return (0, _core.jsx)(_BreadcrumbItem["default"], {
89
- ref: function ref(element) {
90
- return element === null || i === 0 // skip first item which is never truncated
91
- ? breadcrumbItemRefs["delete"](item.to) : breadcrumbItemRefs.set(item.to, element);
92
- },
93
- classes: classes,
94
- key: item.to,
95
- isCurrent: i === items.length - 1,
96
- to: item.to,
97
- name: item.name,
98
- home: false,
99
- invertedStyle: false
100
- }, item.name);
101
- })));
102
- };
103
-
104
- var _default = BreadcrumbBlock;
105
- exports["default"] = _default;
@@ -1,80 +0,0 @@
1
- /**
2
- * Copyright (c) 2019-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, { ReactNode, useRef } from 'react';
10
- import BEMHelper, { ReturnObject } from 'react-bem-helper';
11
- import { useComponentSize, useIsomorphicLayoutEffect } from '@ndla/hooks';
12
- import { useTranslation } from 'react-i18next';
13
- import BreadcrumbItem from './BreadcrumbItem';
14
- import { BreadcrumbItemI } from './Breadcrumb';
15
-
16
- const classes: BEMHelper<ReturnObject> = BEMHelper({
17
- name: 'breadcrumb-block',
18
- prefix: 'c-',
19
- });
20
-
21
- interface Props {
22
- children?: ReactNode;
23
- items: BreadcrumbItemI[];
24
- }
25
-
26
- const BreadcrumbBlock = ({ children, items }: Props) => {
27
- const { t } = useTranslation();
28
- const olRef = useRef<any>();
29
- const containerRef = useRef<HTMLDivElement>(null);
30
- // No idiomatic way of dealing with sets of refs yet
31
- // See: https://github.com/facebook/react/issues/14072#issuecomment-446777406
32
- const breadcrumbItemRefs = useRef(new Map()).current;
33
- const size = useComponentSize(containerRef);
34
-
35
- useIsomorphicLayoutEffect(() => {
36
- // Create an array of all breadcrumb item refs
37
- const items = Array.from(breadcrumbItemRefs).map(([key, value]) => value);
38
-
39
- // Clear max width on all items
40
- items.forEach((el) => {
41
- el.setMaxWidth('none');
42
- });
43
-
44
- // Set maxWidth on breadcrumb text items iteratively until
45
- // the ordered list fits on a single line. It's on a single line
46
- // if the height of the list is less then 70.
47
- items.forEach((el) => {
48
- if (olRef.current.offsetHeight > 70) {
49
- el.setMaxWidth('40px');
50
- }
51
- });
52
- }, [size]);
53
-
54
- return (
55
- <nav {...classes('')} ref={containerRef} aria-label={t('breadcrumb.breadcrumb')}>
56
- {children}
57
- <ol {...classes('list')} ref={olRef}>
58
- {items.map((item, i) => (
59
- <BreadcrumbItem
60
- ref={(element) =>
61
- element === null || i === 0 // skip first item which is never truncated
62
- ? breadcrumbItemRefs.delete(item.to)
63
- : breadcrumbItemRefs.set(item.to, element)
64
- }
65
- classes={classes}
66
- key={item.to}
67
- isCurrent={i === items.length - 1}
68
- to={item.to}
69
- name={item.name}
70
- home={false}
71
- invertedStyle={false}>
72
- {item.name}
73
- </BreadcrumbItem>
74
- ))}
75
- </ol>
76
- </nav>
77
- );
78
- };
79
-
80
- export default BreadcrumbBlock;
@@ -1,98 +0,0 @@
1
- /**
2
- ** BREADCRUMB BLOCK
3
- **
4
- ** EXAMPLE:
5
- ** <div class="c-breadcrumb-block">
6
- ** <ol class="c-breadcrumb-block__list">
7
- ** <li class="c-breadcrumb-block__item">
8
- ** <a href="#">Medieuttrykk og mediesamfunnet</a>
9
- ** </li>
10
- ** <li class="c-breadcrumb-block__item>
11
- ** <a href="#">Idéutvikling</a>
12
- ** </li>
13
- ** </ol>
14
- ** </div>
15
- **/
16
-
17
- .c-breadcrumb-block {
18
- display: none;
19
-
20
- @include mq(desktop) {
21
- display: block;
22
- }
23
- }
24
-
25
- .c-breadcrumb-block__list {
26
- padding-top: 1px;
27
- margin-left: $spacing;
28
- margin-bottom: 0;
29
- margin-top: 0;
30
- display: inline-block;
31
- list-style: none;
32
- text-align: left;
33
- }
34
- .c-breadcrumb-block__item {
35
- display: inline-block;
36
- margin-right: $spacing--small/2;
37
- margin-bottom: 0;
38
- text-transform: none;
39
- a:hover {
40
- box-shadow: none;
41
- }
42
- &:before {
43
- display: none;
44
- }
45
-
46
- .c-icon {
47
- width: 14px;
48
- height: 14px;
49
- color: $brand-color;
50
- margin-top: -1px;
51
- margin-left: $spacing--small/2;
52
- }
53
-
54
- &:first-child {
55
- .c-icon {
56
- display: none;
57
- }
58
- }
59
-
60
- &:not(:first-child) {
61
- display: inline-flex;
62
- align-items: center;
63
- a,
64
- span {
65
- text-overflow: ellipsis;
66
- white-space: nowrap;
67
- overflow: hidden;
68
- display: inline-block;
69
- }
70
- }
71
-
72
- &:last-child {
73
- .c-icon {
74
- display: none;
75
- }
76
- }
77
-
78
- span {
79
- color: $brand-color;
80
- }
81
- }
82
- .c-breadcrumb-block__item:last-child {
83
- &:after {
84
- display: none;
85
- }
86
- }
87
- .c-breadcrumb-block__item:nth-child(1) {
88
- display: block;
89
- text-align: left;
90
- @include inuit-font-size(14px);
91
- font-weight: $font-weight-bold;
92
- &:after {
93
- display: none;
94
- }
95
- }
96
- .c-breadcrumb-block__item--home {
97
- display: none;
98
- }
@@ -1,104 +0,0 @@
1
- /**
2
- ** BREADCRUMB
3
- **
4
- ** EXAMPLE:
5
- ** <div class="c-breadcrumb">
6
- ** <ol class="c-breadcrumb__list">
7
- ** <li class="c-breadcrumb__item c-breadcrumb__item--home">
8
- ** <a href="#"><svg home /></a>
9
- ** </li>
10
- ** <li class="c-breadcrumb__item">
11
- ** <a href="#">Medieuttrykk og mediesamfunnet</a>
12
- ** </li>
13
- ** </ol>
14
- ** </div>
15
- **/
16
-
17
- .c-breadcrumb {
18
- max-width: 100%;
19
- @include inuit-font-size(18px);
20
- display: block;
21
- }
22
- .c-breadcrumb__list {
23
- display: inline-block;
24
- padding-left: 0;
25
- margin-bottom: 0;
26
- margin-top: 0;
27
- list-style: none;
28
- }
29
- .c-breadcrumb__item {
30
- font-weight: $font-weight-normal;
31
- padding-right: $spacing--small / 2;
32
- margin-bottom: 0;
33
- margin-left: 0;
34
- display: block;
35
-
36
- &:not(.c-breadcrumb__item--home) {
37
- .c-icon {
38
- width: 14px;
39
- height: 14px;
40
- margin-left: $spacing--small/2;
41
- margin-top: -1px;
42
- }
43
- }
44
-
45
- @include mq(tablet) {
46
- display: inline-block;
47
- }
48
-
49
- a {
50
- text-decoration: none;
51
- color: $primary-color;
52
-
53
- &:hover,
54
- &:active,
55
- &:focus {
56
- color: $primary-color;
57
- }
58
- }
59
-
60
- &--invertedStyle {
61
- color: #fff;
62
- a {
63
- color: #fff;
64
-
65
- &:hover,
66
- &:active,
67
- &:focus {
68
- color: #fff;
69
- }
70
- }
71
- }
72
-
73
- &:before {
74
- display: none;
75
- }
76
-
77
- &:first-child {
78
- a {
79
- box-shadow: none;
80
- border-bottom: none;
81
- }
82
- }
83
- &:last-child {
84
- .c-icon {
85
- display: none;
86
- }
87
- }
88
- }
89
- .c-breadcrumb__item--home {
90
- a {
91
- border-bottom: none;
92
- }
93
-
94
- @include mq(tablet) {
95
- padding-right: $spacing--small;
96
-
97
- &:after {
98
- padding-left: $spacing--small;
99
- content: '|';
100
- @include inuit-font-size(14px);
101
- color: $primary-color;
102
- }
103
- }
104
- }