@ndla/ui 24.2.2 → 25.0.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 (91) hide show
  1. package/es/CompetenceGoals/CompetenceGoalsDialog.js +15 -23
  2. package/es/CompetenceGoals/index.js +1 -4
  3. package/es/Filter/FilterButtons.js +10 -11
  4. package/es/Filter/FilterList.js +82 -152
  5. package/es/Filter/FilterListPhone.js +180 -271
  6. package/es/Filter/ToggleItem.js +6 -25
  7. package/es/Frontpage/FrontpageAllSubjects.js +8 -9
  8. package/es/Frontpage/FrontpageSearch.js +3 -4
  9. package/es/Masthead/Masthead.js +65 -41
  10. package/es/Masthead/MastheadSearchModal.js +4 -5
  11. package/es/Masthead/SkipToMainContent.js +24 -0
  12. package/es/Masthead/index.js +2 -1
  13. package/es/SearchTypeResult/PopupFilter.js +8 -9
  14. package/es/SearchTypeResult/SearchFilterContent.js +3 -4
  15. package/es/SectionHeading/SectionHeading.js +24 -17
  16. package/es/Subject/index.js +0 -1
  17. package/es/all.css +1 -1
  18. package/es/index-javascript.js +1 -4
  19. package/es/index.js +5 -2
  20. package/lib/CompetenceGoals/CompetenceGoalsDialog.d.ts +19 -0
  21. package/lib/CompetenceGoals/CompetenceGoalsDialog.js +13 -24
  22. package/lib/CompetenceGoals/index.d.ts +1 -0
  23. package/lib/CompetenceGoals/index.js +1 -33
  24. package/lib/Filter/FilterButtons.js +9 -9
  25. package/lib/Filter/FilterList.d.ts +25 -0
  26. package/lib/Filter/FilterList.js +85 -155
  27. package/lib/Filter/FilterListPhone.d.ts +32 -0
  28. package/lib/Filter/FilterListPhone.js +176 -269
  29. package/lib/Filter/ToggleItem.d.ts +15 -0
  30. package/lib/Filter/ToggleItem.js +6 -32
  31. package/lib/Filter/filterClasses.d.ts +2 -0
  32. package/lib/Filter/index.d.ts +12 -0
  33. package/lib/Frontpage/FrontpageAllSubjects.js +7 -7
  34. package/lib/Frontpage/FrontpageSearch.js +2 -3
  35. package/lib/Masthead/Masthead.d.ts +4 -8
  36. package/lib/Masthead/Masthead.js +65 -49
  37. package/lib/Masthead/MastheadSearchModal.js +3 -4
  38. package/lib/Masthead/SkipToMainContent.d.ts +6 -0
  39. package/lib/Masthead/SkipToMainContent.js +38 -0
  40. package/lib/Masthead/index.d.ts +2 -1
  41. package/lib/Masthead/index.js +10 -0
  42. package/lib/SearchTypeResult/PopupFilter.js +7 -7
  43. package/lib/SearchTypeResult/SearchFilterContent.js +2 -2
  44. package/lib/SectionHeading/SectionHeading.d.ts +1 -13
  45. package/lib/SectionHeading/SectionHeading.js +23 -19
  46. package/lib/Subject/index.d.ts +0 -1
  47. package/lib/Subject/index.js +0 -8
  48. package/lib/all.css +1 -1
  49. package/lib/index-javascript.js +1 -63
  50. package/lib/index.d.ts +5 -2
  51. package/lib/index.js +48 -7
  52. package/package.json +11 -11
  53. package/src/CompetenceGoals/{CompetenceGoalsDialog.jsx → CompetenceGoalsDialog.tsx} +34 -26
  54. package/src/CompetenceGoals/index.ts +1 -0
  55. package/src/Filter/FilterButtons.tsx +0 -1
  56. package/src/Filter/FilterList.tsx +135 -0
  57. package/src/Filter/FilterListPhone.tsx +275 -0
  58. package/src/Filter/ToggleItem.tsx +58 -0
  59. package/src/Filter/{filterClasses.js → filterClasses.ts} +0 -0
  60. package/src/Filter/{index.js → index.ts} +0 -0
  61. package/src/Frontpage/FrontpageAllSubjects.tsx +0 -1
  62. package/src/Frontpage/FrontpageSearch.tsx +0 -1
  63. package/src/Masthead/Masthead.tsx +85 -45
  64. package/src/Masthead/MastheadSearchModal.tsx +0 -1
  65. package/src/Masthead/SkipToMainContent.tsx +48 -0
  66. package/src/Masthead/index.ts +2 -1
  67. package/src/SearchTypeResult/PopupFilter.tsx +0 -1
  68. package/src/SearchTypeResult/SearchFilterContent.tsx +0 -1
  69. package/src/SectionHeading/SectionHeading.tsx +29 -16
  70. package/src/Subject/index.ts +0 -1
  71. package/src/index-javascript.js +0 -10
  72. package/src/index.ts +7 -2
  73. package/src/main.scss +0 -3
  74. package/es/CompetenceGoals/CompetenceGoalList.js +0 -58
  75. package/es/CompetenceGoals/CompetenceGoals.js +0 -159
  76. package/es/Subject/SubjectFilter.js +0 -42
  77. package/lib/CompetenceGoals/CompetenceGoalList.js +0 -78
  78. package/lib/CompetenceGoals/CompetenceGoals.js +0 -184
  79. package/lib/Subject/SubjectFilter.d.ts +0 -27
  80. package/lib/Subject/SubjectFilter.js +0 -58
  81. package/src/.DS_Store +0 -0
  82. package/src/CompetenceGoals/CompetenceGoalList.jsx +0 -51
  83. package/src/CompetenceGoals/CompetenceGoals.jsx +0 -152
  84. package/src/CompetenceGoals/component.competence-goals.scss +0 -161
  85. package/src/CompetenceGoals/index.js +0 -6
  86. package/src/Filter/FilterList.jsx +0 -167
  87. package/src/Filter/FilterListPhone.jsx +0 -328
  88. package/src/Filter/ToggleItem.jsx +0 -71
  89. package/src/Masthead/component.masthead.scss +0 -146
  90. package/src/SectionHeading/component.section-heading.scss +0 -17
  91. package/src/Subject/SubjectFilter.tsx +0 -48
@@ -1,38 +1,24 @@
1
- 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); }
2
-
3
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); }
4
2
 
5
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
4
 
7
5
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
6
 
9
- 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); }
10
-
11
7
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
12
8
 
13
9
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
14
10
 
15
- 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; }
16
-
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
-
19
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
20
12
 
21
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
+ 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."); }
22
14
 
23
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
-
25
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
-
27
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
28
-
29
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
15
+ 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); }
30
16
 
31
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ 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; }
32
18
 
33
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
19
+ 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; }
34
20
 
35
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
22
 
37
23
  /*
38
24
  * Copyright (c) 2016-present, NDLA.
@@ -41,151 +27,95 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
41
27
  * LICENSE file in the root directory of this source tree.
42
28
  * FRI OG BEGRENSET
43
29
  */
44
- import React, { Component, Fragment } from 'react';
45
- import PropTypes from 'prop-types';
30
+ import React, { useState } from 'react';
46
31
  import { ChevronDown, ChevronUp } from '@ndla/icons/common';
47
32
  import { classes } from './filterClasses';
48
33
  import ToggleItem from './ToggleItem';
49
34
  import { jsx as ___EmotionJSX } from "@emotion/core";
50
35
 
51
- var FilterList = /*#__PURE__*/function (_Component) {
52
- _inherits(FilterList, _Component);
53
-
54
- var _super = _createSuper(FilterList);
55
-
56
- function FilterList(props) {
57
- var _this;
58
-
59
- _classCallCheck(this, FilterList);
60
-
61
- _this = _super.call(this, props);
62
- _this.state = {
63
- visibleCount: props.defaultVisibleCount
64
- };
65
- return _this;
36
+ var FilterList = function FilterList(_ref) {
37
+ var _ref$modifiers = _ref.modifiers,
38
+ modifiers = _ref$modifiers === void 0 ? '' : _ref$modifiers,
39
+ _ref$preid = _ref.preid,
40
+ preid = _ref$preid === void 0 ? '' : _ref$preid,
41
+ _ref$label = _ref.label,
42
+ label = _ref$label === void 0 ? 'FILTER:' : _ref$label,
43
+ labelNotVisible = _ref.labelNotVisible,
44
+ options = _ref.options,
45
+ _ref$values = _ref.values,
46
+ values = _ref$values === void 0 ? [] : _ref$values,
47
+ _onChange = _ref.onChange,
48
+ defaultVisibleCount = _ref.defaultVisibleCount,
49
+ showLabel = _ref.showLabel,
50
+ hideLabel = _ref.hideLabel,
51
+ alignedGroup = _ref.alignedGroup,
52
+ collapseMobile = _ref.collapseMobile,
53
+ noFilterSelectedLabel = _ref.noFilterSelectedLabel;
54
+
55
+ var _useState = useState(defaultVisibleCount),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ visibleCount = _useState2[0],
58
+ setVisibleCount = _useState2[1];
59
+
60
+ var showAll = defaultVisibleCount === undefined || options.length <= defaultVisibleCount;
61
+ var labelModifiers = [];
62
+
63
+ if (labelNotVisible) {
64
+ labelModifiers.push('hidden');
66
65
  }
67
66
 
68
- _createClass(FilterList, [{
69
- key: "render",
70
- value: function render() {
71
- var _this2 = this;
72
-
73
- var _this$props = this.props,
74
- modifiers = _this$props.modifiers,
75
- preid = _this$props.preid,
76
- label = _this$props.label,
77
- labelNotVisible = _this$props.labelNotVisible,
78
- options = _this$props.options,
79
- values = _this$props.values,
80
- _onChange = _this$props.onChange,
81
- defaultVisibleCount = _this$props.defaultVisibleCount,
82
- showLabel = _this$props.showLabel,
83
- hideLabel = _this$props.hideLabel,
84
- alignedGroup = _this$props.alignedGroup,
85
- collapseMobile = _this$props.collapseMobile;
86
- var showAll = defaultVisibleCount === null || options.length <= defaultVisibleCount;
87
- var labelModifiers = [];
88
-
89
- if (labelNotVisible) {
90
- labelModifiers.push('hidden');
91
- }
67
+ return ___EmotionJSX("section", classes('list', modifiers), label && ___EmotionJSX("h1", classes('label', labelModifiers), label), noFilterSelectedLabel && options.length === 0 && ___EmotionJSX("span", classes('no-filter-selected'), noFilterSelectedLabel), ___EmotionJSX("ul", classes('item-wrapper', {
68
+ 'aligned-grouping': !!alignedGroup,
69
+ 'collapse-mobile': !!collapseMobile
70
+ }), options.map(function (option, index) {
71
+ var itemModifiers = [];
72
+ var checked = values.some(function (value) {
73
+ return value === option.value;
74
+ });
75
+
76
+ if (!showAll && !checked && index + 1 > (visibleCount !== null && visibleCount !== void 0 ? visibleCount : 0)) {
77
+ itemModifiers.push('hidden');
78
+ }
92
79
 
93
- return ___EmotionJSX("section", classes('list', modifiers), label && ___EmotionJSX("h1", classes('label', labelModifiers), label), this.props.noFilterSelectedLabel && options.length === 0 && ___EmotionJSX("span", classes('no-filter-selected'), this.props.noFilterSelectedLabel), ___EmotionJSX("ul", classes('item-wrapper', {
94
- 'aligned-grouping': alignedGroup,
95
- 'collapse-mobile': collapseMobile
96
- }), options.map(function (option, index) {
97
- var itemModifiers = [];
98
- var checked = values.some(function (value) {
99
- return value === option.value;
100
- });
101
-
102
- if (!showAll && !checked && index + 1 > _this2.state.visibleCount) {
103
- itemModifiers.push('hidden');
104
- }
80
+ var disabled = option.noResults || option.hits === 0;
105
81
 
106
- var disabled = option.noResults || option.hits === 0;
82
+ if (disabled) {
83
+ itemModifiers.push('no-results');
84
+ }
107
85
 
108
- if (disabled) {
109
- itemModifiers.push('no-results');
86
+ return ___EmotionJSX(ToggleItem, {
87
+ modifiers: itemModifiers,
88
+ id: preid + option.value,
89
+ key: option.value,
90
+ value: option.value,
91
+ disabled: disabled,
92
+ tabIndex: disabled ? -1 : 0,
93
+ checked: checked,
94
+ label: option.title,
95
+ onChange: function onChange(event) {
96
+ var newValues = null;
97
+
98
+ if (event.currentTarget.checked) {
99
+ newValues = [].concat(_toConsumableArray(values), [option.value]);
100
+ } else {
101
+ newValues = values.filter(function (value) {
102
+ return value !== option.value;
103
+ });
110
104
  }
111
105
 
112
- return ___EmotionJSX(ToggleItem, {
113
- modifiers: itemModifiers,
114
- id: preid + option.value,
115
- key: option.value,
116
- value: option.value,
117
- disabled: disabled,
118
- tabIndex: disabled ? -1 : 0,
119
- checked: checked,
120
- icon: option.icon,
121
- label: option.title,
122
- onChange: function onChange(event) {
123
- var newValues = null;
124
-
125
- if (event.currentTarget.checked) {
126
- newValues = [].concat(_toConsumableArray(values), [option.value]);
127
- } else {
128
- newValues = values.filter(function (value) {
129
- return value !== option.value;
130
- });
131
- }
132
-
133
- if (_onChange) {
134
- _onChange(newValues, option.value);
135
- }
136
- }
137
- });
138
- })), !showAll && ___EmotionJSX("button", _extends({}, classes('expand'), {
139
- type: "button",
140
- onClick: function onClick() {
141
- _this2.setState(function (prevState) {
142
- if (prevState.visibleCount === defaultVisibleCount) {
143
- return {
144
- visibleCount: options.length
145
- };
146
- }
147
-
148
- return {
149
- visibleCount: defaultVisibleCount
150
- };
151
- });
106
+ if (_onChange) {
107
+ _onChange(newValues, option.value);
152
108
  }
153
- }), this.state.visibleCount === defaultVisibleCount ? ___EmotionJSX(Fragment, null, ___EmotionJSX("span", null, showLabel), " ", ___EmotionJSX(ChevronDown, null)) : ___EmotionJSX(Fragment, null, ___EmotionJSX("span", null, hideLabel), " ", ___EmotionJSX(ChevronUp, null))));
109
+ }
110
+ });
111
+ })), !showAll && ___EmotionJSX("button", _extends({}, classes('expand'), {
112
+ type: "button",
113
+ onClick: function onClick() {
114
+ setVisibleCount(function (prev) {
115
+ return prev === defaultVisibleCount ? options.length : defaultVisibleCount;
116
+ });
154
117
  }
155
- }]);
156
-
157
- return FilterList;
158
- }(Component);
159
-
160
- var valueShape = PropTypes.oneOfType([PropTypes.string, PropTypes.number]);
161
- FilterList.propTypes = {
162
- children: PropTypes.node,
163
- label: PropTypes.string,
164
- preid: PropTypes.string,
165
- labelNotVisible: PropTypes.bool,
166
- modifiers: PropTypes.string,
167
- onChange: PropTypes.func,
168
- // isRequired
169
- options: PropTypes.arrayOf(PropTypes.shape({
170
- title: PropTypes.string.isRequired,
171
- value: valueShape.isRequired,
172
- hits: PropTypes.number,
173
- icon: PropTypes.func,
174
- noResults: PropTypes.bool
175
- })).isRequired,
176
- values: PropTypes.arrayOf(valueShape),
177
- defaultVisibleCount: PropTypes.number,
178
- showLabel: PropTypes.string,
179
- noFilterSelectedLabel: PropTypes.string,
180
- hideLabel: PropTypes.string,
181
- alignedGroup: PropTypes.bool,
182
- collapseMobile: PropTypes.bool
183
- };
184
- FilterList.defaultProps = {
185
- label: 'FILTER:',
186
- preid: '',
187
- modifiers: '',
188
- values: [],
189
- defaultVisibleCount: null
118
+ }), visibleCount === defaultVisibleCount ? ___EmotionJSX(React.Fragment, null, ___EmotionJSX("span", null, showLabel), " ", ___EmotionJSX(ChevronDown, null)) : ___EmotionJSX(React.Fragment, null, ___EmotionJSX("span", null, hideLabel), " ", ___EmotionJSX(ChevronUp, null))));
190
119
  };
120
+
191
121
  export default FilterList;