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