@ndla/ui 50.9.7 → 50.9.9
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/es/AudioPlayer/AudioPlayer.js +34 -34
- package/es/Embed/ContentLinkEmbed.js +2 -2
- package/es/Embed/IframeEmbed.js +11 -4
- package/es/Embed/UuDisclaimerEmbed.js +75 -0
- package/es/Embed/index.js +2 -1
- package/es/ExpandableBox/ExpandableBox.js +8 -2
- package/es/Filter/ToggleItem.js +31 -9
- package/es/Filter/index.js +0 -3
- package/es/Logo/Logo.js +44 -20
- package/es/Logo/SvgLogo.js +7 -3
- package/es/Messages/MessageBox.js +6 -6
- package/es/RelatedArticleList/RelatedArticleList.js +8 -8
- package/es/all.css +1 -1
- package/es/index.js +2 -2
- package/es/locale/messages-en.js +3 -0
- package/es/locale/messages-nb.js +3 -0
- package/es/locale/messages-nn.js +3 -0
- package/es/locale/messages-se.js +3 -0
- package/es/locale/messages-sma.js +3 -0
- package/lib/AudioPlayer/AudioPlayer.js +34 -34
- package/lib/Embed/ContentLinkEmbed.js +2 -2
- package/lib/Embed/IframeEmbed.js +12 -4
- package/lib/Embed/UuDisclaimerEmbed.d.ts +15 -0
- package/lib/Embed/UuDisclaimerEmbed.js +78 -0
- package/lib/Embed/index.d.ts +1 -0
- package/lib/Embed/index.js +7 -0
- package/lib/ExpandableBox/ExpandableBox.js +8 -1
- package/lib/Filter/ToggleItem.d.ts +1 -2
- package/lib/Filter/ToggleItem.js +32 -9
- package/lib/Filter/index.d.ts +0 -3
- package/lib/Filter/index.js +0 -21
- package/lib/Logo/Logo.d.ts +0 -2
- package/lib/Logo/Logo.js +45 -22
- package/lib/Logo/SvgLogo.js +8 -3
- package/lib/Messages/MessageBox.d.ts +1 -1
- package/lib/Messages/MessageBox.js +6 -6
- package/lib/RelatedArticleList/RelatedArticleList.js +8 -8
- package/lib/all.css +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +6 -12
- package/lib/locale/messages-en.d.ts +3 -0
- package/lib/locale/messages-en.js +3 -0
- package/lib/locale/messages-nb.d.ts +3 -0
- package/lib/locale/messages-nb.js +3 -0
- package/lib/locale/messages-nn.d.ts +3 -0
- package/lib/locale/messages-nn.js +3 -0
- package/lib/locale/messages-se.d.ts +3 -0
- package/lib/locale/messages-se.js +3 -0
- package/lib/locale/messages-sma.d.ts +3 -0
- package/lib/locale/messages-sma.js +3 -0
- package/package.json +12 -12
- package/src/AudioPlayer/AudioPlayer.tsx +13 -27
- package/src/CampaignBlock/CampaignBlock.stories.tsx +15 -0
- package/src/Embed/BrightcoveEmbed.stories.tsx +1 -1
- package/src/Embed/ContentLinkEmbed.tsx +1 -1
- package/src/Embed/ExternalEmbed.stories.tsx +93 -0
- package/src/Embed/IframeEmbed.tsx +8 -3
- package/src/Embed/UuDisclaimerEmbed.stories.tsx +150 -0
- package/src/Embed/UuDisclaimerEmbed.tsx +62 -0
- package/src/Embed/index.ts +1 -0
- package/src/ExpandableBox/ExpandableBox.stories.tsx +10 -1
- package/src/ExpandableBox/ExpandableBox.tsx +11 -1
- package/src/Figure/component.figure.scss +0 -56
- package/src/Filter/ToggleItem.tsx +131 -9
- package/src/Filter/index.ts +0 -3
- package/src/Logo/Logo.tsx +36 -16
- package/src/Logo/SvgLogo.tsx +8 -9
- package/src/Messages/MessageBox.tsx +1 -1
- package/src/RelatedArticleList/RelatedArticleList.tsx +1 -1
- package/src/index.ts +2 -1
- package/src/locale/messages-en.ts +3 -0
- package/src/locale/messages-nb.ts +3 -0
- package/src/locale/messages-nn.ts +3 -0
- package/src/locale/messages-se.ts +3 -0
- package/src/locale/messages-sma.ts +3 -0
- package/src/main.scss +0 -2
- package/es/Filter/FilterList.js +0 -100
- package/es/Filter/FilterListPhone.js +0 -224
- package/es/Filter/filterClasses.js +0 -13
- package/lib/Filter/FilterList.d.ts +0 -32
- package/lib/Filter/FilterList.js +0 -105
- package/lib/Filter/FilterListPhone.d.ts +0 -38
- package/lib/Filter/FilterListPhone.js +0 -229
- package/lib/Filter/filterClasses.d.ts +0 -9
- package/lib/Filter/filterClasses.js +0 -20
- package/src/Filter/FilterList.tsx +0 -137
- package/src/Filter/FilterListPhone.tsx +0 -278
- package/src/Filter/component.filter.scss +0 -503
- package/src/Filter/filterClasses.ts +0 -14
- package/src/Logo/component.logo.scss +0 -28
package/es/Filter/FilterList.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2016-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 { useState } from "react";
|
|
10
|
-
import { ChevronDown, ChevronUp } from "@ndla/icons/common";
|
|
11
|
-
import { classes } from "./filterClasses";
|
|
12
|
-
import ToggleItem from "./ToggleItem";
|
|
13
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
14
|
-
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
15
|
-
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
16
|
-
const FilterList = _ref => {
|
|
17
|
-
let {
|
|
18
|
-
modifiers = "",
|
|
19
|
-
preid = "",
|
|
20
|
-
label = "FILTER:",
|
|
21
|
-
labelNotVisible,
|
|
22
|
-
options,
|
|
23
|
-
values = [],
|
|
24
|
-
onChange,
|
|
25
|
-
defaultVisibleCount,
|
|
26
|
-
showLabel,
|
|
27
|
-
hideLabel,
|
|
28
|
-
alignedGroup,
|
|
29
|
-
collapseMobile,
|
|
30
|
-
noFilterSelectedLabel
|
|
31
|
-
} = _ref;
|
|
32
|
-
const [visibleCount, setVisibleCount] = useState(defaultVisibleCount);
|
|
33
|
-
const showAll = defaultVisibleCount === undefined || options.length <= defaultVisibleCount;
|
|
34
|
-
const labelModifiers = [];
|
|
35
|
-
if (labelNotVisible) {
|
|
36
|
-
labelModifiers.push("hidden");
|
|
37
|
-
}
|
|
38
|
-
return _jsxs("section", {
|
|
39
|
-
...classes("list", modifiers),
|
|
40
|
-
children: [label && _jsx("h1", {
|
|
41
|
-
...classes("label", labelModifiers),
|
|
42
|
-
children: label
|
|
43
|
-
}), noFilterSelectedLabel && options.length === 0 && _jsx("span", {
|
|
44
|
-
...classes("no-filter-selected"),
|
|
45
|
-
children: noFilterSelectedLabel
|
|
46
|
-
}), _jsx("ul", {
|
|
47
|
-
...classes("item-wrapper", {
|
|
48
|
-
"aligned-grouping": !!alignedGroup,
|
|
49
|
-
"collapse-mobile": !!collapseMobile
|
|
50
|
-
}),
|
|
51
|
-
children: options.map((option, index) => {
|
|
52
|
-
const itemModifiers = [];
|
|
53
|
-
const checked = values.some(value => value === option.value);
|
|
54
|
-
if (!showAll && !checked && index + 1 > (visibleCount ?? 0)) {
|
|
55
|
-
itemModifiers.push("hidden");
|
|
56
|
-
}
|
|
57
|
-
const disabled = option.noResults || option.hits === 0;
|
|
58
|
-
if (disabled) {
|
|
59
|
-
itemModifiers.push("no-results");
|
|
60
|
-
}
|
|
61
|
-
return _jsx(ToggleItem, {
|
|
62
|
-
modifiers: itemModifiers,
|
|
63
|
-
id: preid + option.value,
|
|
64
|
-
value: option.value,
|
|
65
|
-
disabled: disabled,
|
|
66
|
-
tabIndex: disabled ? -1 : 0,
|
|
67
|
-
checked: checked,
|
|
68
|
-
label: option.title,
|
|
69
|
-
onChange: event => {
|
|
70
|
-
let newValues = null;
|
|
71
|
-
if (event.currentTarget.checked) {
|
|
72
|
-
newValues = [...values, option.value];
|
|
73
|
-
} else {
|
|
74
|
-
newValues = values.filter(value => value !== option.value);
|
|
75
|
-
}
|
|
76
|
-
if (onChange) {
|
|
77
|
-
onChange(newValues, option.value);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, option.value);
|
|
81
|
-
})
|
|
82
|
-
}), !showAll && _jsx("button", {
|
|
83
|
-
...classes("expand"),
|
|
84
|
-
type: "button",
|
|
85
|
-
onClick: () => {
|
|
86
|
-
setVisibleCount(prev => prev === defaultVisibleCount ? options.length : defaultVisibleCount);
|
|
87
|
-
},
|
|
88
|
-
children: visibleCount === defaultVisibleCount ? _jsxs(_Fragment, {
|
|
89
|
-
children: [_jsx("span", {
|
|
90
|
-
children: showLabel
|
|
91
|
-
}), " ", _jsx(ChevronDown, {})]
|
|
92
|
-
}) : _jsxs(_Fragment, {
|
|
93
|
-
children: [_jsx("span", {
|
|
94
|
-
children: hideLabel
|
|
95
|
-
}), " ", _jsx(ChevronUp, {})]
|
|
96
|
-
})
|
|
97
|
-
})]
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
export default FilterList;
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2016-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 debounce from "lodash/debounce";
|
|
10
|
-
import { useCallback, useEffect, useState } from "react";
|
|
11
|
-
import { ButtonV2 } from "@ndla/button";
|
|
12
|
-
import { ChevronDown, ChevronUp } from "@ndla/icons/common";
|
|
13
|
-
import { ModalHeader, ModalBody, ModalCloseButton, Modal, ModalTrigger, ModalContent } from "@ndla/modal";
|
|
14
|
-
import { classes } from "./filterClasses";
|
|
15
|
-
import ToggleItem from "./ToggleItem";
|
|
16
|
-
import ActiveFilters from "../Search/ActiveFilters";
|
|
17
|
-
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
18
|
-
import { jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
19
|
-
import { Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
20
|
-
const is2DArray = options => {
|
|
21
|
-
return Array.isArray(options[0]);
|
|
22
|
-
};
|
|
23
|
-
const FilterListPhone = _ref => {
|
|
24
|
-
let {
|
|
25
|
-
preid,
|
|
26
|
-
label,
|
|
27
|
-
labelNotVisible,
|
|
28
|
-
modifiers = "",
|
|
29
|
-
onChange,
|
|
30
|
-
options,
|
|
31
|
-
values = [],
|
|
32
|
-
defaultVisibleCount,
|
|
33
|
-
showLabel,
|
|
34
|
-
hideLabel,
|
|
35
|
-
alignedGroup = false,
|
|
36
|
-
collapseMobile = true,
|
|
37
|
-
activeFiltersNarrow,
|
|
38
|
-
messages,
|
|
39
|
-
viewMode = "inlineDesktop",
|
|
40
|
-
isGroupedOptions,
|
|
41
|
-
showActiveFiltersOnSmallScreen
|
|
42
|
-
} = _ref;
|
|
43
|
-
const [open, setOpen] = useState(false);
|
|
44
|
-
const [isNarrowScreen, setIsNarrowScreen] = useState(false);
|
|
45
|
-
const [visibleCount, setVisibleCount] = useState(defaultVisibleCount);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
setScreenSize(true);
|
|
48
|
-
const debounced = debounce(() => setScreenSize(false), 50);
|
|
49
|
-
window.addEventListener("resize", debounced);
|
|
50
|
-
return () => {
|
|
51
|
-
debounced.cancel();
|
|
52
|
-
window.removeEventListener("resize", debounced);
|
|
53
|
-
};
|
|
54
|
-
}, []);
|
|
55
|
-
const setScreenSize = function () {
|
|
56
|
-
let initial = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
57
|
-
const newIsNarrowScreen = (window.innerWidth || document.documentElement.clientWidth) < 768;
|
|
58
|
-
|
|
59
|
-
/* eslint react/no-did-mount-set-state: 0 */
|
|
60
|
-
if (initial && newIsNarrowScreen || !initial) {
|
|
61
|
-
setIsNarrowScreen(newIsNarrowScreen);
|
|
62
|
-
}
|
|
63
|
-
/* eslint react/no-did-mount-set-state: 1 */
|
|
64
|
-
};
|
|
65
|
-
const onClose = useCallback(() => {
|
|
66
|
-
setOpen(false);
|
|
67
|
-
}, []);
|
|
68
|
-
const handleChange = (event, option) => {
|
|
69
|
-
let newValues = null;
|
|
70
|
-
if (event.currentTarget.checked) {
|
|
71
|
-
newValues = [...values, option.value];
|
|
72
|
-
} else {
|
|
73
|
-
newValues = values.filter(value => value !== option.value);
|
|
74
|
-
}
|
|
75
|
-
if (onChange) {
|
|
76
|
-
onChange(newValues, option.value);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const showAll = defaultVisibleCount === undefined || options.length <= defaultVisibleCount;
|
|
80
|
-
const labelModifiers = [];
|
|
81
|
-
if (labelNotVisible) {
|
|
82
|
-
labelModifiers.push("hidden");
|
|
83
|
-
}
|
|
84
|
-
const groupedOptions = is2DArray(options) ? options : [options];
|
|
85
|
-
if (isNarrowScreen || viewMode === "allModal") {
|
|
86
|
-
let currentlyActiveFilters = [];
|
|
87
|
-
groupedOptions.forEach(options => {
|
|
88
|
-
const activeFilters = options.filter(option => values.some(value => value === option.value));
|
|
89
|
-
currentlyActiveFilters = [...currentlyActiveFilters, ...activeFilters];
|
|
90
|
-
});
|
|
91
|
-
const wrapperClassName = activeFiltersNarrow || viewMode === "allModal" ? classes("narrow-active-filters").className : "";
|
|
92
|
-
return _jsxs("div", {
|
|
93
|
-
className: wrapperClassName,
|
|
94
|
-
children: [currentlyActiveFilters.length > 0 && _jsx(ActiveFilters, {
|
|
95
|
-
filters: currentlyActiveFilters,
|
|
96
|
-
showOnSmallScreen: showActiveFiltersOnSmallScreen,
|
|
97
|
-
onFilterRemove: value => {
|
|
98
|
-
onChange(values.filter(option => option !== value), value);
|
|
99
|
-
}
|
|
100
|
-
}), _jsxs(Modal, {
|
|
101
|
-
open: open,
|
|
102
|
-
onOpenChange: setOpen,
|
|
103
|
-
children: [_jsx(ModalTrigger, {
|
|
104
|
-
children: _jsx(ButtonV2, {
|
|
105
|
-
variant: "outline",
|
|
106
|
-
...classes("modal-button"),
|
|
107
|
-
children: messages.openFilter
|
|
108
|
-
})
|
|
109
|
-
}), _jsxs(ModalContent, {
|
|
110
|
-
size: "full",
|
|
111
|
-
children: [_jsx(ModalHeader, {
|
|
112
|
-
children: _jsxs("div", {
|
|
113
|
-
...classes("modal-header"),
|
|
114
|
-
children: [_jsxs("div", {
|
|
115
|
-
...classes("modal-heading"),
|
|
116
|
-
children: [!isNarrowScreen && label && _jsx("h1", {
|
|
117
|
-
...classes("label"),
|
|
118
|
-
children: label
|
|
119
|
-
}), _jsx(ButtonV2, {
|
|
120
|
-
variant: "outline",
|
|
121
|
-
onClick: onClose,
|
|
122
|
-
children: messages.useFilter
|
|
123
|
-
})]
|
|
124
|
-
}), _jsx(ModalCloseButton, {
|
|
125
|
-
title: messages.closeFilter
|
|
126
|
-
})]
|
|
127
|
-
})
|
|
128
|
-
}), _jsxs(ModalBody, {
|
|
129
|
-
modifier: "no-side-padding-mobile",
|
|
130
|
-
children: [isNarrowScreen && label && _jsx("h1", {
|
|
131
|
-
...classes("label"),
|
|
132
|
-
children: label
|
|
133
|
-
}), groupedOptions.map((options, index) => _jsx("ul", {
|
|
134
|
-
...classes("item-wrapper", {
|
|
135
|
-
"aligned-grouping": !!alignedGroup,
|
|
136
|
-
"collapse-mobile": !!collapseMobile,
|
|
137
|
-
"grouped-options": !!isGroupedOptions
|
|
138
|
-
}),
|
|
139
|
-
children: options.map(option => {
|
|
140
|
-
const itemModifiers = [];
|
|
141
|
-
const checked = values.some(value => value === option.value);
|
|
142
|
-
if (option.noResults) {
|
|
143
|
-
itemModifiers.push("no-results");
|
|
144
|
-
}
|
|
145
|
-
if (option.disabled) {
|
|
146
|
-
itemModifiers.push("disabled");
|
|
147
|
-
}
|
|
148
|
-
return _jsx(ToggleItem, {
|
|
149
|
-
id: preid + option.value,
|
|
150
|
-
value: option.value,
|
|
151
|
-
checked: checked,
|
|
152
|
-
onChange: event => handleChange(event, option),
|
|
153
|
-
label: option.title,
|
|
154
|
-
disabled: option.disabled,
|
|
155
|
-
modifiers: itemModifiers
|
|
156
|
-
}, option.value);
|
|
157
|
-
})
|
|
158
|
-
}, index)), _jsx("div", {
|
|
159
|
-
...classes("usefilter-wrapper"),
|
|
160
|
-
children: _jsx(ButtonV2, {
|
|
161
|
-
variant: "outline",
|
|
162
|
-
onClick: onClose,
|
|
163
|
-
children: messages.useFilter
|
|
164
|
-
})
|
|
165
|
-
})]
|
|
166
|
-
})]
|
|
167
|
-
})]
|
|
168
|
-
})]
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
return _jsxs(_Fragment, {
|
|
172
|
-
children: [isGroupedOptions && label && _jsx("h2", {
|
|
173
|
-
...classes("label", labelModifiers),
|
|
174
|
-
children: label
|
|
175
|
-
}), groupedOptions.map((options, index) => _jsxs("section", {
|
|
176
|
-
...classes("list", modifiers),
|
|
177
|
-
children: [!isGroupedOptions && label && _jsx("h1", {
|
|
178
|
-
...classes("label", labelModifiers),
|
|
179
|
-
children: label
|
|
180
|
-
}), _jsx("ul", {
|
|
181
|
-
...classes("item-wrapper"),
|
|
182
|
-
children: options.map((option, index) => {
|
|
183
|
-
const itemModifiers = [];
|
|
184
|
-
const checked = values.some(value => value === option.value);
|
|
185
|
-
if (!showAll && !checked && !!visibleCount && index + 1 > visibleCount) {
|
|
186
|
-
itemModifiers.push("hidden");
|
|
187
|
-
}
|
|
188
|
-
if (option.noResults) {
|
|
189
|
-
itemModifiers.push("no-results");
|
|
190
|
-
}
|
|
191
|
-
if (option.disabled) {
|
|
192
|
-
itemModifiers.push("disabled");
|
|
193
|
-
}
|
|
194
|
-
return _jsx(ToggleItem, {
|
|
195
|
-
id: preid + option.value,
|
|
196
|
-
value: option.value,
|
|
197
|
-
tabIndex: option.noResults ? -1 : 0,
|
|
198
|
-
checked: checked,
|
|
199
|
-
onChange: event => handleChange(event, option),
|
|
200
|
-
label: option.title,
|
|
201
|
-
modifiers: itemModifiers,
|
|
202
|
-
disabled: option.disabled
|
|
203
|
-
}, option.value);
|
|
204
|
-
})
|
|
205
|
-
}), !showAll && _jsx("button", {
|
|
206
|
-
...classes("expand"),
|
|
207
|
-
type: "button",
|
|
208
|
-
onClick: () => {
|
|
209
|
-
setVisibleCount(prev => prev === defaultVisibleCount ? options.length : defaultVisibleCount);
|
|
210
|
-
},
|
|
211
|
-
children: visibleCount === defaultVisibleCount ? _jsxs(_Fragment, {
|
|
212
|
-
children: [_jsx("span", {
|
|
213
|
-
children: showLabel
|
|
214
|
-
}), " ", _jsx(ChevronDown, {})]
|
|
215
|
-
}) : _jsxs(_Fragment, {
|
|
216
|
-
children: [_jsx("span", {
|
|
217
|
-
children: hideLabel
|
|
218
|
-
}), " ", _jsx(ChevronUp, {})]
|
|
219
|
-
})
|
|
220
|
-
})]
|
|
221
|
-
}, index))]
|
|
222
|
-
});
|
|
223
|
-
};
|
|
224
|
-
export default FilterListPhone;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2018-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 BEMHelper from "react-bem-helper";
|
|
10
|
-
export const classes = new BEMHelper({
|
|
11
|
-
name: "filter",
|
|
12
|
-
prefix: "c-"
|
|
13
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2016-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
|
-
interface Props {
|
|
10
|
-
children?: ReactNode;
|
|
11
|
-
label?: string;
|
|
12
|
-
preid?: string;
|
|
13
|
-
labelNotVisible?: boolean;
|
|
14
|
-
modifiers?: string;
|
|
15
|
-
onChange?: Function;
|
|
16
|
-
options: {
|
|
17
|
-
title: string;
|
|
18
|
-
value: string;
|
|
19
|
-
hits?: number;
|
|
20
|
-
icon?: ReactNode;
|
|
21
|
-
noResults?: boolean;
|
|
22
|
-
}[];
|
|
23
|
-
values: string[];
|
|
24
|
-
defaultVisibleCount?: number;
|
|
25
|
-
showLabel?: string;
|
|
26
|
-
noFilterSelectedLabel?: string;
|
|
27
|
-
hideLabel?: string;
|
|
28
|
-
alignedGroup?: boolean;
|
|
29
|
-
collapseMobile?: boolean;
|
|
30
|
-
}
|
|
31
|
-
declare const FilterList: ({ modifiers, preid, label, labelNotVisible, options, values, onChange, defaultVisibleCount, showLabel, hideLabel, alignedGroup, collapseMobile, noFilterSelectedLabel, }: Props) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
32
|
-
export default FilterList;
|
package/lib/Filter/FilterList.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _common = require("@ndla/icons/common");
|
|
9
|
-
var _filterClasses = require("./filterClasses");
|
|
10
|
-
var _ToggleItem = _interopRequireDefault(require("./ToggleItem"));
|
|
11
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) 2016-present, NDLA.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const FilterList = _ref => {
|
|
22
|
-
let {
|
|
23
|
-
modifiers = "",
|
|
24
|
-
preid = "",
|
|
25
|
-
label = "FILTER:",
|
|
26
|
-
labelNotVisible,
|
|
27
|
-
options,
|
|
28
|
-
values = [],
|
|
29
|
-
onChange,
|
|
30
|
-
defaultVisibleCount,
|
|
31
|
-
showLabel,
|
|
32
|
-
hideLabel,
|
|
33
|
-
alignedGroup,
|
|
34
|
-
collapseMobile,
|
|
35
|
-
noFilterSelectedLabel
|
|
36
|
-
} = _ref;
|
|
37
|
-
const [visibleCount, setVisibleCount] = (0, _react.useState)(defaultVisibleCount);
|
|
38
|
-
const showAll = defaultVisibleCount === undefined || options.length <= defaultVisibleCount;
|
|
39
|
-
const labelModifiers = [];
|
|
40
|
-
if (labelNotVisible) {
|
|
41
|
-
labelModifiers.push("hidden");
|
|
42
|
-
}
|
|
43
|
-
return (0, _jsxRuntime.jsxs)("section", {
|
|
44
|
-
...(0, _filterClasses.classes)("list", modifiers),
|
|
45
|
-
children: [label && (0, _jsxRuntime.jsx)("h1", {
|
|
46
|
-
...(0, _filterClasses.classes)("label", labelModifiers),
|
|
47
|
-
children: label
|
|
48
|
-
}), noFilterSelectedLabel && options.length === 0 && (0, _jsxRuntime.jsx)("span", {
|
|
49
|
-
...(0, _filterClasses.classes)("no-filter-selected"),
|
|
50
|
-
children: noFilterSelectedLabel
|
|
51
|
-
}), (0, _jsxRuntime.jsx)("ul", {
|
|
52
|
-
...(0, _filterClasses.classes)("item-wrapper", {
|
|
53
|
-
"aligned-grouping": !!alignedGroup,
|
|
54
|
-
"collapse-mobile": !!collapseMobile
|
|
55
|
-
}),
|
|
56
|
-
children: options.map((option, index) => {
|
|
57
|
-
const itemModifiers = [];
|
|
58
|
-
const checked = values.some(value => value === option.value);
|
|
59
|
-
if (!showAll && !checked && index + 1 > (visibleCount ?? 0)) {
|
|
60
|
-
itemModifiers.push("hidden");
|
|
61
|
-
}
|
|
62
|
-
const disabled = option.noResults || option.hits === 0;
|
|
63
|
-
if (disabled) {
|
|
64
|
-
itemModifiers.push("no-results");
|
|
65
|
-
}
|
|
66
|
-
return (0, _jsxRuntime.jsx)(_ToggleItem.default, {
|
|
67
|
-
modifiers: itemModifiers,
|
|
68
|
-
id: preid + option.value,
|
|
69
|
-
value: option.value,
|
|
70
|
-
disabled: disabled,
|
|
71
|
-
tabIndex: disabled ? -1 : 0,
|
|
72
|
-
checked: checked,
|
|
73
|
-
label: option.title,
|
|
74
|
-
onChange: event => {
|
|
75
|
-
let newValues = null;
|
|
76
|
-
if (event.currentTarget.checked) {
|
|
77
|
-
newValues = [...values, option.value];
|
|
78
|
-
} else {
|
|
79
|
-
newValues = values.filter(value => value !== option.value);
|
|
80
|
-
}
|
|
81
|
-
if (onChange) {
|
|
82
|
-
onChange(newValues, option.value);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}, option.value);
|
|
86
|
-
})
|
|
87
|
-
}), !showAll && (0, _jsxRuntime.jsx)("button", {
|
|
88
|
-
...(0, _filterClasses.classes)("expand"),
|
|
89
|
-
type: "button",
|
|
90
|
-
onClick: () => {
|
|
91
|
-
setVisibleCount(prev => prev === defaultVisibleCount ? options.length : defaultVisibleCount);
|
|
92
|
-
},
|
|
93
|
-
children: visibleCount === defaultVisibleCount ? (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
94
|
-
children: [(0, _jsxRuntime.jsx)("span", {
|
|
95
|
-
children: showLabel
|
|
96
|
-
}), " ", (0, _jsxRuntime.jsx)(_common.ChevronDown, {})]
|
|
97
|
-
}) : (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
98
|
-
children: [(0, _jsxRuntime.jsx)("span", {
|
|
99
|
-
children: hideLabel
|
|
100
|
-
}), " ", (0, _jsxRuntime.jsx)(_common.ChevronUp, {})]
|
|
101
|
-
})
|
|
102
|
-
})]
|
|
103
|
-
});
|
|
104
|
-
};
|
|
105
|
-
var _default = exports.default = FilterList;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2016-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
|
-
interface Option {
|
|
9
|
-
title: string;
|
|
10
|
-
value: string;
|
|
11
|
-
noResults?: boolean;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
}
|
|
14
|
-
interface Props {
|
|
15
|
-
preid: string;
|
|
16
|
-
label?: string;
|
|
17
|
-
labelNotVisible?: boolean;
|
|
18
|
-
modifiers?: string;
|
|
19
|
-
onChange: (values: string[], value: string) => void;
|
|
20
|
-
options: Option[] | Option[][];
|
|
21
|
-
values?: string[];
|
|
22
|
-
defaultVisibleCount?: number;
|
|
23
|
-
showLabel?: string;
|
|
24
|
-
hideLabel?: string;
|
|
25
|
-
alignedGroup?: boolean;
|
|
26
|
-
collapseMobile?: boolean;
|
|
27
|
-
activeFiltersNarrow?: boolean;
|
|
28
|
-
messages: {
|
|
29
|
-
useFilter: string;
|
|
30
|
-
openFilter: string;
|
|
31
|
-
closeFilter: string;
|
|
32
|
-
};
|
|
33
|
-
viewMode?: "inlineDesktop" | "allModal";
|
|
34
|
-
isGroupedOptions?: boolean;
|
|
35
|
-
showActiveFiltersOnSmallScreen?: boolean;
|
|
36
|
-
}
|
|
37
|
-
declare const FilterListPhone: ({ preid, label, labelNotVisible, modifiers, onChange, options, values, defaultVisibleCount, showLabel, hideLabel, alignedGroup, collapseMobile, activeFiltersNarrow, messages, viewMode, isGroupedOptions, showActiveFiltersOnSmallScreen, }: Props) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
38
|
-
export default FilterListPhone;
|