@stenajs-webui/filter 17.6.0 → 17.9.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 (34) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/features/search-filter/components/SearchFilterButton.d.ts +6 -6
  3. package/dist/features/search-filter/components/SearchFilterDrawer.d.ts +7 -7
  4. package/dist/features/search-filter/components/SearchFilterPanelHeader.d.ts +7 -7
  5. package/dist/features/search-filter/components/SearchFilterSection.d.ts +14 -14
  6. package/dist/features/search-filter/components/context/SearchFilterContext.d.ts +10 -10
  7. package/dist/features/search-filter/components/context/SearchFilterLocalStateContext.d.ts +7 -7
  8. package/dist/features/search-filter/config/SearchFilterConfig.d.ts +13 -13
  9. package/dist/features/search-filter/context/SearchFilterActionsContext.d.ts +4 -4
  10. package/dist/features/search-filter/context/SearchFilterDispatchContext.d.ts +4 -4
  11. package/dist/features/search-filter/context/SearchFilterModelContext.d.ts +3 -3
  12. package/dist/features/search-filter/context/SearchFilterStateContext.d.ts +4 -4
  13. package/dist/features/search-filter/features/chips/ChipSpacer.d.ts +5 -5
  14. package/dist/features/search-filter/features/chips/EmptyChip.d.ts +7 -7
  15. package/dist/features/search-filter/features/chips/SearchFilterChip.d.ts +10 -10
  16. package/dist/features/search-filter/features/chips/SearchFilterChips.d.ts +8 -8
  17. package/dist/features/search-filter/features/chips/SectionChips.d.ts +9 -9
  18. package/dist/features/search-filter/hooks/UseLocalSearchFilterState.d.ts +11 -11
  19. package/dist/features/search-filter/redux/SearchFilterRedux.d.ts +30 -30
  20. package/dist/features/search-filter/section-factories/boolean-record/BooleanRecordChips.d.ts +6 -6
  21. package/dist/features/search-filter/section-factories/boolean-record/BooleanRecordTypes.d.ts +6 -6
  22. package/dist/features/search-filter/section-factories/boolean-record/components/ChipMultiSelectSection.d.ts +10 -10
  23. package/dist/features/search-filter/section-factories/boolean-record/components/SimpleCheckboxListSection.d.ts +8 -8
  24. package/dist/features/search-filter/section-factories/date-range/DateRangeChips.d.ts +6 -6
  25. package/dist/features/search-filter/section-factories/date-range/DateRangePropsFactory.d.ts +2 -2
  26. package/dist/features/search-filter/section-factories/date-range/components/DateRangeCalendarSection.d.ts +13 -13
  27. package/dist/features/search-filter/types/FilterEntity.d.ts +5 -5
  28. package/dist/index.d.ts +28 -28
  29. package/dist/index.es.js +471 -385
  30. package/dist/index.es.js.map +1 -1
  31. package/dist/index.js +4 -465
  32. package/dist/index.js.map +1 -1
  33. package/package.json +14 -15
  34. package/dist/features/search-filter/stories/SearchFilter.stories.d.ts +0 -15
package/dist/index.js CHANGED
@@ -1,466 +1,5 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var React = require('react');
6
- var modal = require('@stenajs-webui/modal');
7
- var theme = require('@stenajs-webui/theme');
8
- var core = require('@stenajs-webui/core');
9
- var elements = require('@stenajs-webui/elements');
10
- var panels = require('@stenajs-webui/panels');
11
- var lodash = require('lodash');
12
- var redux = require('redux');
13
- var redux$1 = require('@stenajs-webui/redux');
14
- var styled = require('@emotion/styled');
15
- var forms = require('@stenajs-webui/forms');
16
- var select = require('@stenajs-webui/select');
17
- var calendar = require('@stenajs-webui/calendar');
18
-
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- function _interopNamespace(e) {
22
- if (e && e.__esModule) return e;
23
- var n = Object.create(null);
24
- if (e) {
25
- Object.keys(e).forEach(function (k) {
26
- if (k !== 'default') {
27
- var d = Object.getOwnPropertyDescriptor(e, k);
28
- Object.defineProperty(n, k, d.get ? d : {
29
- enumerable: true,
30
- get: function () { return e[k]; }
31
- });
32
- }
33
- });
34
- }
35
- n["default"] = e;
36
- return Object.freeze(n);
37
- }
38
-
39
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
40
- var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
41
-
42
- /*! *****************************************************************************
43
- Copyright (c) Microsoft Corporation.
44
-
45
- Permission to use, copy, modify, and/or distribute this software for any
46
- purpose with or without fee is hereby granted.
47
-
48
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
49
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
50
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
51
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
52
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
53
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
54
- PERFORMANCE OF THIS SOFTWARE.
55
- ***************************************************************************** */
56
-
57
- var __assign = function() {
58
- __assign = Object.assign || function __assign(t) {
59
- for (var s, i = 1, n = arguments.length; i < n; i++) {
60
- s = arguments[i];
61
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
62
- }
63
- return t;
64
- };
65
- return __assign.apply(this, arguments);
66
- };
67
-
68
- function __rest(s, e) {
69
- var t = {};
70
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
71
- t[p] = s[p];
72
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
73
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
74
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
75
- t[p[i]] = s[p[i]];
76
- }
77
- return t;
78
- }
79
-
80
- function __makeTemplateObject(cooked, raw) {
81
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
82
- return cooked;
83
- }
84
-
85
- var SearchFilterPanelHeader = function (_a) {
86
- var onRequestClose = _a.onRequestClose, _b = _a.header, header = _b === void 0 ? "Filters" : _b;
87
- return (React__namespace.createElement(core.Row, { height: "56px", justifyContent: "space-between", alignItems: "center", indent: 2 },
88
- React__namespace.createElement(core.Row, { alignItems: "center" },
89
- React__namespace.createElement(elements.Icon, { icon: elements.stenaSliders, color: theme.cssColor("--lhds-color-ui-800"), size: 24 }),
90
- React__namespace.createElement(core.Indent, null),
91
- React__namespace.createElement(core.Heading, { variant: "h4" }, header)),
92
- React__namespace.createElement(elements.SecondaryButton, { leftIcon: elements.stenaTimes, onClick: onRequestClose })));
93
- };
94
-
95
- var SearchFilterStateContext = React.createContext(null);
96
- var useSearchFilterState = function () {
97
- var c = React.useContext(SearchFilterStateContext);
98
- if (!c) {
99
- throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");
100
- }
101
- return c;
102
- };
103
-
104
- var SearchFilterDispatchContext = React.createContext(null);
105
- var useSearchFilterDispatch = function () {
106
- var c = React.useContext(SearchFilterDispatchContext);
107
- if (!c) {
108
- throw new Error("Missing search filter dispatch context.");
109
- }
110
- return c;
111
- };
112
-
113
- var SearchFilterActionsContext = React.createContext(null);
114
- var useSearchFilterActions = function () {
115
- var c = React.useContext(SearchFilterActionsContext);
116
- if (!c) {
117
- throw new Error("Missing search filter actions context.");
118
- }
119
- return c;
120
- };
121
-
122
- var SearchFilterDrawer = function (_a) {
123
- var children = _a.children, header = _a.header, drawerProps = __rest(_a, ["children", "header"]);
124
- var open = useSearchFilterState().settings.open;
125
- var dispatch = useSearchFilterDispatch();
126
- var actions = useSearchFilterActions();
127
- var closeDrawer = React.useCallback(function () {
128
- dispatch(actions.closeFilters());
129
- }, [actions, dispatch]);
130
- return (React__namespace.createElement(modal.Drawer, __assign({ background: theme.cssColor("--lhds-color-ui-50"), width: "370px", isOpen: open, onRequestClose: closeDrawer }, drawerProps),
131
- React__namespace.createElement(core.Column, null,
132
- React__namespace.createElement(SearchFilterPanelHeader, { onRequestClose: closeDrawer, header: header }),
133
- React__namespace.createElement(core.SeparatorLine, null),
134
- children)));
135
- };
136
-
137
- var SearchFilterButton = function (_a) {
138
- var _b = _a.label, label = _b === void 0 ? "Filters" : _b;
139
- var dispatch = useSearchFilterDispatch();
140
- var actions = useSearchFilterActions();
141
- var onClickButton = React.useCallback(function () {
142
- dispatch(actions.openFilters());
143
- }, [actions, dispatch]);
144
- return (React__namespace.createElement(elements.SecondaryButton, { label: label, leftIcon: elements.stenaSliders, onClick: onClickButton }));
145
- };
146
-
147
- var SearchFilterSection = function SearchFilterSection(_a) {
148
- var _b;
149
- var sectionId = _a.sectionId, label = _a.label, contentLeft = _a.contentLeft, contentRight = _a.contentRight, loading = _a.loading, error = _a.error, onRetry = _a.onRetry, disableContentPadding = _a.disableContentPadding, children = _a.children;
150
- var state = useSearchFilterState();
151
- var dispatch = useSearchFilterDispatch();
152
- var actions = useSearchFilterActions();
153
- var expanded = (_b = state.expandedSections.values[sectionId]) !== null && _b !== void 0 ? _b : false;
154
- var onClickLabel = React.useCallback(function () {
155
- dispatch(actions.setSectionExpanded(sectionId, !expanded));
156
- }, [actions, dispatch, expanded, sectionId]);
157
- var activeLabel = label !== null && label !== void 0 ? label : formatColumnIdToHeaderCellLabel(sectionId);
158
- return (React__namespace.createElement(panels.Collapsible, { label: activeLabel, collapsed: !expanded, onClick: onClickLabel, contentLeft: contentLeft, contentRight: contentRight }, loading ? (React__namespace.createElement(panels.CollapsibleContent, null,
159
- React__namespace.createElement(core.Row, { spacing: true, justifyContent: "center", flex: 1 },
160
- React__namespace.createElement(elements.Spinner, { size: "small" })))) : error ? (React__namespace.createElement(elements.Banner, { variant: "error", text: error, contentRight: onRetry ? React__namespace.createElement(elements.FlatButton, { label: "Retry", onClick: onRetry }) : null })) : disableContentPadding ? (children) : (React__namespace.createElement(panels.CollapsibleContent, null, children))));
161
- };
162
- var formatColumnIdToHeaderCellLabel = function (columnId) {
163
- return lodash.upperFirst(lodash.lowerCase(columnId));
164
- };
165
-
166
- var SearchFilterModelContext = React.createContext(null);
167
- var useSearchFilterModel = function () {
168
- var c = React.useContext(SearchFilterModelContext);
169
- if (!c) {
170
- throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");
171
- }
172
- return c;
173
- };
174
-
175
- var SearchFilterContext = function SearchFilterScope(_a) {
176
- var state = _a.state, dispatch = _a.dispatch, actions = _a.actions, children = _a.children;
177
- return (React__namespace.createElement(SearchFilterDispatchContext.Provider, { value: dispatch },
178
- React__namespace.createElement(SearchFilterActionsContext.Provider, { value: actions },
179
- React__namespace.createElement(SearchFilterStateContext.Provider, { value: state },
180
- React__namespace.createElement(SearchFilterModelContext.Provider, { value: state.formModel }, children)))));
181
- };
182
-
183
- var createSearchFilterInitialState = function (initialFormModel) { return ({
184
- settings: {
185
- open: false,
186
- },
187
- formModel: initialFormModel,
188
- expandedSections: { values: {} },
189
- }); };
190
- var createSearchFilterReducer = function (reducerId, initialState) {
191
- return redux.combineReducers({
192
- expandedSections: redux$1.reducerIdGate(getReducerIdFor(reducerId, "expandedSections"), redux$1.createValueByIdReducer(initialState.expandedSections)),
193
- formModel: redux$1.reducerIdGate(getReducerIdFor(reducerId, "formModel"), redux$1.createEntityReducer(initialState.formModel)),
194
- settings: redux$1.reducerIdGate(getReducerIdFor(reducerId, "settings"), redux$1.createEntityReducer(initialState.settings)),
195
- });
196
- };
197
- var createSearchFilterActions = function (reducerId, initialFormModel) { return ({
198
- openFilters: function () {
199
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "settings"), redux$1.createEntityActions().setEntityFields({
200
- open: true,
201
- }));
202
- },
203
- closeFilters: function () {
204
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "settings"), redux$1.createEntityActions().setEntityFields({
205
- open: false,
206
- }));
207
- },
208
- setFormModelFields: function (fields) {
209
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "formModel"), redux$1.createEntityActions().setEntityFields(fields));
210
- },
211
- clearFormModel: function () {
212
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "formModel"), redux$1.createEntityActions().setEntity(initialFormModel));
213
- },
214
- expandSection: function (section) {
215
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), redux$1.createValueByIdActions().setValue(section, true));
216
- },
217
- collapseSection: function (section) {
218
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), redux$1.createValueByIdActions().setValue(section, false));
219
- },
220
- setSectionExpanded: function (section, expanded) {
221
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), redux$1.createValueByIdActions().setValue(section, expanded));
222
- },
223
- clearExpandedSections: function () {
224
- return redux$1.reducerIdGateAction(getReducerIdFor(reducerId, "expandedSections"), redux$1.createValueByIdActions().clearAllValues());
225
- },
226
- }); };
227
- var getReducerIdFor = function (reducerId, reducerIdSuffix) { return "".concat(reducerId, ".").concat(reducerIdSuffix); };
228
-
229
- var useLocalSearchFilterState = function (initialState) {
230
- var reducer = React.useState(function () {
231
- return createSearchFilterReducer("local", initialState);
232
- })[0];
233
- var actions = React.useState(function () {
234
- return createSearchFilterActions("local", initialState.formModel);
235
- })[0];
236
- var _a = React.useReducer(reducer, initialState), state = _a[0], dispatch = _a[1];
237
- return {
238
- actions: actions,
239
- state: state,
240
- dispatch: dispatch,
241
- };
242
- };
243
-
244
- var SearchFilterLocalStateContext = function SearchFilterLocalScope(_a) {
245
- var initialFormModel = _a.initialFormModel, children = _a.children;
246
- var _b = useLocalSearchFilterState(createSearchFilterInitialState(initialFormModel)), state = _b.state, actions = _b.actions, dispatch = _b.dispatch;
247
- return (React__namespace.createElement(SearchFilterContext, { state: state, actions: actions, dispatch: dispatch }, children));
248
- };
249
-
250
- var ChipSpacer = styled__default["default"].div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n padding: calc(var(--swui-metrics-spacing) / 2)\n calc(var(--swui-metrics-indent) / 2);\n"], ["\n padding: calc(var(--swui-metrics-spacing) / 2)\n calc(var(--swui-metrics-indent) / 2);\n"])));
251
- var templateObject_1;
252
-
253
- var SearchFilterChips = function (_a) {
254
- var children = _a.children, _b = _a.disableClearAllButton, disableClearAllButton = _b === void 0 ? false : _b;
255
- var dispatch = useSearchFilterDispatch();
256
- var actions = useSearchFilterActions();
257
- var onClickClearAll = React.useCallback(function () { return dispatch(actions.clearFormModel()); }, [actions, dispatch]);
258
- return (React__namespace.createElement(core.Row, { flexWrap: "wrap" },
259
- children,
260
- !disableClearAllButton && (React__namespace.createElement(ChipSpacer, null,
261
- React__namespace.createElement(elements.FlatButton, { size: "small", label: "Clear all", onClick: onClickClearAll })))));
262
- };
263
-
264
- var EmptyChip = function EmptyChip(_a) {
265
- var label = _a.label, sectionId = _a.sectionId;
266
- var dispatch = useSearchFilterDispatch();
267
- var actions = useSearchFilterActions();
268
- var onClickLabel = React.useCallback(function () {
269
- dispatch(actions.clearExpandedSections());
270
- dispatch(actions.expandSection(sectionId));
271
- dispatch(actions.openFilters());
272
- }, [actions, dispatch, sectionId]);
273
- return (React__namespace.createElement(ChipSpacer, null,
274
- React__namespace.createElement(elements.Chip, { label: label, variant: "secondary", onClick: onClickLabel })));
275
- };
276
-
277
- var SearchFilterChip = function SearchFilterChip(_a) {
278
- var sectionId = _a.sectionId, label = _a.label, value = _a.value, onClickRemove = _a.onClickRemove;
279
- var dispatch = useSearchFilterDispatch();
280
- var actions = useSearchFilterActions();
281
- var setFormModelFields = React.useCallback(function (fields) {
282
- return dispatch(actions.setFormModelFields(fields));
283
- }, [dispatch, actions]);
284
- var onClickRemoveHandler = React.useCallback(function () {
285
- onClickRemove === null || onClickRemove === void 0 ? void 0 : onClickRemove({ value: value, setFormModelFields: setFormModelFields });
286
- }, [onClickRemove, setFormModelFields, value]);
287
- var onClickLabel = React.useCallback(function () {
288
- dispatch(actions.clearExpandedSections());
289
- dispatch(actions.expandSection(sectionId));
290
- dispatch(actions.openFilters());
291
- }, [actions, dispatch, sectionId]);
292
- return (React__namespace.createElement(ChipSpacer, null,
293
- React__namespace.createElement(elements.Chip, { label: label !== null && label !== void 0 ? label : sectionId, onClick: onClickLabel, onClickRemove: onClickRemove ? onClickRemoveHandler : undefined })));
294
- };
295
-
296
- var SectionChips = function SectionChips(_a) {
297
- var sectionId = _a.sectionId, chips = _a.chips, emptyChipLabel = _a.emptyChipLabel, onClickRemoveOnChip = _a.onClickRemoveOnChip;
298
- if (!(chips === null || chips === void 0 ? void 0 : chips.length)) {
299
- if (!emptyChipLabel) {
300
- return null;
301
- }
302
- return React__namespace.createElement(EmptyChip, { sectionId: sectionId, label: emptyChipLabel });
303
- }
304
- return (React__namespace.createElement(React__namespace.Fragment, null, chips.map(function (_a) {
305
- var label = _a.label, value = _a.value;
306
- return (React__namespace.createElement(SearchFilterChip, { key: value, label: label !== null && label !== void 0 ? label : sectionId, sectionId: sectionId, onClickRemove: onClickRemoveOnChip, value: value }));
307
- })));
308
- };
309
-
310
- var createChipsPropsForBooleanRecord = function (formModel, fieldName, options) { return ({
311
- chips: createChipsForBooleanRecord(formModel[fieldName], options),
312
- onClickRemoveOnChip: createOnClickRemoveOnChipForBooleanRecord(formModel, fieldName),
313
- }); };
314
- var createChipsForBooleanRecord = function (booleanRecord, options) {
315
- return core.truthyKeysAsList(booleanRecord).map(function (key) {
316
- var _a;
317
- var option = options === null || options === void 0 ? void 0 : options.find(function (o) { return o.value === key; });
318
- return { value: key, label: (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : key };
319
- });
320
- };
321
- var createOnClickRemoveOnChipForBooleanRecord = function (formModel, fieldName) {
322
- return function (_a) {
323
- var _b;
324
- var setFormModelFields = _a.setFormModelFields, value = _a.value;
325
- var newRecord = __assign({}, formModel[fieldName]);
326
- newRecord[value] = false;
327
- setFormModelFields((_b = {},
328
- _b[fieldName] = newRecord,
329
- _b));
330
- };
331
- };
332
-
333
- var SimpleCheckboxListSection = function (_a) {
334
- var options = _a.options, value = _a.value, onValueChange = _a.onValueChange, sectionProps = __rest(_a, ["options", "value", "onValueChange"]);
335
- return (React__namespace.createElement(SearchFilterSection, __assign({ disableContentPadding: true }, sectionProps),
336
- React__namespace.createElement(core.Column, { maxHeight: "400px", overflowY: "auto", flex: 1 }, options === null || options === void 0 ? void 0 : options.map(function (d) { return (React__namespace.createElement(panels.CollapsibleClickableContent, { key: d.value, onClick: function () {
337
- var _a;
338
- if (value && onValueChange) {
339
- var sel = !value[d.value];
340
- onValueChange(__assign(__assign({}, value), (_a = {}, _a[d.value] = sel, _a)));
341
- }
342
- }, contentLeft: React__namespace.createElement(forms.Checkbox, { tabIndex: -1, value: value === null || value === void 0 ? void 0 : value[d.value] }) },
343
- React__namespace.createElement(core.Text, null, d.label))); }))));
344
- };
345
-
346
- var ChipMultiSelectSection = function (_a) {
347
- var options = _a.options, value = _a.value, noneSelectedLabel = _a.noneSelectedLabel, onValueChange = _a.onValueChange, sectionProps = __rest(_a, ["options", "value", "noneSelectedLabel", "onValueChange"]);
348
- var _b = React.useState(""), text = _b[0], setText = _b[1];
349
- var listValue = React.useMemo(function () {
350
- return value
351
- ? core.truthyKeysAsList(value).map(function (key) {
352
- var _a;
353
- var option = options === null || options === void 0 ? void 0 : options.find(function (o) { return o.value === key; });
354
- return { value: key, label: (_a = option === null || option === void 0 ? void 0 : option.label) !== null && _a !== void 0 ? _a : key };
355
- })
356
- : [];
357
- }, [options, value]);
358
- var filteredOptions = React.useMemo(function () {
359
- return options === null || options === void 0 ? void 0 : options.filter(function (p) {
360
- return p.value.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1 ||
361
- p.label.toLocaleLowerCase().indexOf(text.toLocaleLowerCase()) > -1;
362
- });
363
- }, [options, text]);
364
- var onValueChangeInternal = React.useCallback(function (value) {
365
- onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(createBooleanRecordFromValue(value));
366
- }, [onValueChange]);
367
- return (React__namespace.createElement(SearchFilterSection, __assign({}, sectionProps),
368
- React__namespace.createElement(select.ChipMultiSelect, { options: filteredOptions, value: listValue, onValueChange: onValueChangeInternal, inputValue: text, noneSelectedLabel: noneSelectedLabel, onInputChange: setText, closeMenuOnSelect: false })));
369
- };
370
- var createBooleanRecordFromValue = function (value) {
371
- return value.reduce(function (sum, item) {
372
- sum[item.value] = true;
373
- return sum;
374
- }, {});
375
- };
376
-
377
- var createChipsPropsForDateRange = function (formModel, startDateFieldName, endDateFieldName) { return ({
378
- chips: createChipsForDateRange(formModel[startDateFieldName], formModel[endDateFieldName]),
379
- onClickRemoveOnChip: createOnClickRemoveOnChipForDateRange(startDateFieldName, endDateFieldName),
380
- }); };
381
- var createChipsForDateRange = function (startDate, endDate) {
382
- if (!startDate && !endDate) {
383
- return [];
384
- }
385
- return [
386
- { value: "dateRange", label: "".concat(startDate !== null && startDate !== void 0 ? startDate : "", " - ").concat(endDate !== null && endDate !== void 0 ? endDate : "") },
387
- ];
388
- };
389
- var createOnClickRemoveOnChipForDateRange = function (startDateFieldName, endDateFieldName) {
390
- return function (_a) {
391
- var _b;
392
- var setFormModelFields = _a.setFormModelFields;
393
- setFormModelFields((_b = {},
394
- _b[startDateFieldName] = undefined,
395
- _b[endDateFieldName] = undefined,
396
- _b));
397
- };
398
- };
399
-
400
- var createDateRangeSectionProps = function (formModel, startDateFieldName, endDateFieldName) { return ({
401
- value: {
402
- startDate: formModel[startDateFieldName],
403
- endDate: formModel[endDateFieldName],
404
- },
405
- onValueChange: function (value, _a) {
406
- var _b;
407
- var dispatch = _a.dispatch, actions = _a.actions;
408
- var fields = (_b = {},
409
- _b[startDateFieldName] = value.startDate,
410
- _b[endDateFieldName] = value.endDate,
411
- _b);
412
- dispatch(actions.setFormModelFields(fields));
413
- },
414
- }); };
415
-
416
- var DateRangeCalendarSection = function (_a) {
417
- var value = _a.value, onValueChange = _a.onValueChange, sectionId = _a.sectionId, dateRangeCalendarProps = __rest(_a, ["value", "onValueChange", "sectionId"]);
418
- var dispatch = useSearchFilterDispatch();
419
- var actions = useSearchFilterActions();
420
- var options = React.useMemo(function () { return ({ dispatch: dispatch, actions: actions }); }, [actions, dispatch]);
421
- var _b = React.useState("startDate"), focusedInput = _b[0], setFocusedInput = _b[1];
422
- var dateRangeValue = React.useMemo(function () { return calendar.stringsToDateRange(value); }, [value]);
423
- var onValueChangeHandler = React.useCallback(function (value) {
424
- onValueChange(calendar.dateRangeToStrings(value), options);
425
- }, [onValueChange, options]);
426
- return (React__namespace.createElement(SearchFilterSection, { sectionId: sectionId },
427
- React__namespace.createElement(core.Box, { flex: 1, alignItems: "center" },
428
- React__namespace.createElement(core.Box, { background: "white", indent: true },
429
- React__namespace.createElement(calendar.DateRangeCalendar, __assign({ setFocusedInput: setFocusedInput, focusedInput: focusedInput, value: dateRangeValue, onValueChange: onValueChangeHandler }, dateRangeCalendarProps))))));
430
- };
431
-
432
- exports.ChipMultiSelectSection = ChipMultiSelectSection;
433
- exports.DateRangeCalendarSection = DateRangeCalendarSection;
434
- exports.EmptyChip = EmptyChip;
435
- exports.SearchFilterActionsContext = SearchFilterActionsContext;
436
- exports.SearchFilterButton = SearchFilterButton;
437
- exports.SearchFilterChip = SearchFilterChip;
438
- exports.SearchFilterChips = SearchFilterChips;
439
- exports.SearchFilterContext = SearchFilterContext;
440
- exports.SearchFilterDispatchContext = SearchFilterDispatchContext;
441
- exports.SearchFilterDrawer = SearchFilterDrawer;
442
- exports.SearchFilterLocalStateContext = SearchFilterLocalStateContext;
443
- exports.SearchFilterModelContext = SearchFilterModelContext;
444
- exports.SearchFilterPanelHeader = SearchFilterPanelHeader;
445
- exports.SearchFilterSection = SearchFilterSection;
446
- exports.SearchFilterStateContext = SearchFilterStateContext;
447
- exports.SectionChips = SectionChips;
448
- exports.SimpleCheckboxListSection = SimpleCheckboxListSection;
449
- exports.createChipsForBooleanRecord = createChipsForBooleanRecord;
450
- exports.createChipsForDateRange = createChipsForDateRange;
451
- exports.createChipsPropsForBooleanRecord = createChipsPropsForBooleanRecord;
452
- exports.createChipsPropsForDateRange = createChipsPropsForDateRange;
453
- exports.createDateRangeSectionProps = createDateRangeSectionProps;
454
- exports.createOnClickRemoveOnChipForBooleanRecord = createOnClickRemoveOnChipForBooleanRecord;
455
- exports.createOnClickRemoveOnChipForDateRange = createOnClickRemoveOnChipForDateRange;
456
- exports.createSearchFilterActions = createSearchFilterActions;
457
- exports.createSearchFilterInitialState = createSearchFilterInitialState;
458
- exports.createSearchFilterReducer = createSearchFilterReducer;
459
- exports.formatColumnIdToHeaderCellLabel = formatColumnIdToHeaderCellLabel;
460
- exports.getReducerIdFor = getReducerIdFor;
461
- exports.useLocalSearchFilterState = useLocalSearchFilterState;
462
- exports.useSearchFilterActions = useSearchFilterActions;
463
- exports.useSearchFilterDispatch = useSearchFilterDispatch;
464
- exports.useSearchFilterModel = useSearchFilterModel;
465
- exports.useSearchFilterState = useSearchFilterState;
1
+ (function(){ try {var elementStyle = document.createElement('style'); elementStyle.appendChild(document.createTextNode("")); document.head.appendChild(elementStyle);} catch(e) {console.error('vite-plugin-css-injected-by-js', e);} })();"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var o=require("react"),Q=require("@stenajs-webui/modal"),I=require("@stenajs-webui/theme"),d=require("@stenajs-webui/core"),x=require("@stenajs-webui/elements"),c=require("react/jsx-runtime"),v=require("@stenajs-webui/panels"),E=require("lodash"),U=require("redux"),i=require("@stenajs-webui/redux"),X=require("@emotion/styled"),Z=require("@stenajs-webui/forms"),N=require("@stenajs-webui/select"),b=require("@stenajs-webui/calendar");function ee(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var te=ee(X);const q=({onRequestClose:e,header:t="Filters"})=>c.jsxs(d.Row,{height:"56px",justifyContent:"space-between",alignItems:"center",indent:2,children:[c.jsxs(d.Row,{alignItems:"center",children:[c.jsx(x.Icon,{icon:x.stenaSliders,color:I.cssColor("--lhds-color-ui-800"),size:24}),c.jsx(d.Indent,{}),c.jsx(d.Heading,{variant:"h4",children:t})]}),c.jsx(x.SecondaryButton,{leftIcon:x.stenaTimes,onClick:e})]}),w=o.createContext(null),M=()=>{const e=o.useContext(w);if(!e)throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");return e},k=o.createContext(null),F=()=>{const e=o.useContext(k);if(!e)throw new Error("Missing search filter dispatch context.");return e},y=o.createContext(null),j=()=>{const e=o.useContext(y);if(!e)throw new Error("Missing search filter actions context.");return e},re=({children:e,header:t,...r})=>{const{settings:{open:n}}=M(),s=F(),a=j(),l=o.useCallback(()=>{s(a.closeFilters())},[a,s]);return c.jsx(Q.Drawer,{background:I.cssColor("--lhds-color-ui-50"),width:"370px",isOpen:n,onRequestClose:l,...r,children:c.jsxs(d.Column,{children:[c.jsx(q,{onRequestClose:l,header:t}),c.jsx(d.SeparatorLine,{}),e]})})},ne=({label:e="Filters"})=>{const t=F(),r=j(),n=o.useCallback(()=>{t(r.openFilters())},[r,t]);return c.jsx(x.SecondaryButton,{label:e,leftIcon:x.stenaSliders,onClick:n})},R=function({sectionId:t,label:r,contentLeft:n,contentRight:s,loading:a,error:l,onRetry:C,disableContentPadding:f,children:S}){var B;const u=M(),p=F(),m=j(),g=(B=u.expandedSections.values[t])!=null?B:!1,Y=o.useCallback(()=>{p(m.setSectionExpanded(t,!g))},[m,p,g,t]),J=r!=null?r:O(t);return c.jsx(v.Collapsible,{label:J,collapsed:!g,onClick:Y,contentLeft:n,contentRight:s,children:a?c.jsx(v.CollapsibleContent,{children:c.jsx(d.Row,{spacing:!0,justifyContent:"center",flex:1,children:c.jsx(x.Spinner,{size:"small"})})}):l?c.jsx(x.Banner,{variant:"error",text:l,contentRight:C?c.jsx(x.FlatButton,{label:"Retry",onClick:C}):null}):f?S:c.jsx(v.CollapsibleContent,{children:S})})},O=e=>E.upperFirst(E.lowerCase(e)),A=o.createContext(null),ce=()=>{const e=o.useContext(A);if(!e)throw new Error("Missing search filter context, wrap components with SearchFilterContext component.");return e},P=function({state:t,dispatch:r,actions:n,children:s}){return c.jsx(k.Provider,{value:r,children:c.jsx(y.Provider,{value:n,children:c.jsx(w.Provider,{value:t,children:c.jsx(A.Provider,{value:t.formModel,children:s})})})})},D=e=>({settings:{open:!1},formModel:e,expandedSections:{values:{}}}),G=(e,t)=>U.combineReducers({expandedSections:i.reducerIdGate(h(e,"expandedSections"),i.createValueByIdReducer(t.expandedSections)),formModel:i.reducerIdGate(h(e,"formModel"),i.createEntityReducer(t.formModel)),settings:i.reducerIdGate(h(e,"settings"),i.createEntityReducer(t.settings))}),V=(e,t)=>({openFilters:()=>i.reducerIdGateAction(h(e,"settings"),i.createEntityActions().setEntityFields({open:!0})),closeFilters:()=>i.reducerIdGateAction(h(e,"settings"),i.createEntityActions().setEntityFields({open:!1})),setFormModelFields:r=>i.reducerIdGateAction(h(e,"formModel"),i.createEntityActions().setEntityFields(r)),clearFormModel:()=>i.reducerIdGateAction(h(e,"formModel"),i.createEntityActions().setEntity(t)),expandSection:r=>i.reducerIdGateAction(h(e,"expandedSections"),i.createValueByIdActions().setValue(r,!0)),collapseSection:r=>i.reducerIdGateAction(h(e,"expandedSections"),i.createValueByIdActions().setValue(r,!1)),setSectionExpanded:(r,n)=>i.reducerIdGateAction(h(e,"expandedSections"),i.createValueByIdActions().setValue(r,n)),clearExpandedSections:()=>i.reducerIdGateAction(h(e,"expandedSections"),i.createValueByIdActions().clearAllValues())}),h=(e,t)=>`${e}.${t}`,H=e=>{const[t]=o.useState(()=>G("local",e)),[r]=o.useState(()=>V("local",e.formModel)),[n,s]=o.useReducer(t,e);return{actions:r,state:n,dispatch:s}},se=function({initialFormModel:t,children:r}){const{state:n,actions:s,dispatch:a}=H(D(t));return c.jsx(P,{state:n,actions:s,dispatch:a,children:r})},L=te.default.div`
2
+ padding: calc(var(--swui-metrics-spacing) / 2)
3
+ calc(var(--swui-metrics-indent) / 2);
4
+ `,ae=({children:e,disableClearAllButton:t=!1})=>{const r=F(),n=j(),s=o.useCallback(()=>r(n.clearFormModel()),[n,r]);return c.jsxs(d.Row,{flexWrap:"wrap",children:[e,!t&&c.jsx(L,{children:c.jsx(x.FlatButton,{size:"small",label:"Clear all",onClick:s})})]})},T=function({label:t,sectionId:r}){const n=F(),s=j(),a=o.useCallback(()=>{n(s.clearExpandedSections()),n(s.expandSection(r)),n(s.openFilters())},[s,n,r]);return c.jsx(L,{children:c.jsx(x.Chip,{label:t,variant:"secondary",onClick:a})})},_=function({sectionId:t,label:r,value:n,onClickRemove:s}){const a=F(),l=j(),C=o.useCallback(u=>a(l.setFormModelFields(u)),[a,l]),f=o.useCallback(()=>{s==null||s({value:n,setFormModelFields:C})},[s,C,n]),S=o.useCallback(()=>{a(l.clearExpandedSections()),a(l.expandSection(t)),a(l.openFilters())},[l,a,t]);return c.jsx(L,{children:c.jsx(x.Chip,{label:r!=null?r:t,onClick:S,onClickRemove:s?f:void 0})})},oe=function({sectionId:t,chips:r,emptyChipLabel:n,onClickRemoveOnChip:s}){return r!=null&&r.length?c.jsx(c.Fragment,{children:r.map(({label:a,value:l})=>c.jsx(_,{label:a!=null?a:t,sectionId:t,onClickRemove:s,value:l},l))}):n?c.jsx(T,{sectionId:t,label:n}):null},le=(e,t,r)=>({chips:$(e[t],r),onClickRemoveOnChip:z(e,t)}),$=(e,t)=>d.truthyKeysAsList(e).map(r=>{var s;const n=t==null?void 0:t.find(a=>a.value===r);return{value:r,label:(s=n==null?void 0:n.label)!=null?s:r}}),z=(e,t)=>({setFormModelFields:r,value:n})=>{const s={...e[t]};s[n]=!1,r({[t]:s})},ie=({options:e,value:t,onValueChange:r,...n})=>c.jsx(R,{disableContentPadding:!0,...n,children:c.jsx(d.Column,{maxHeight:"400px",overflowY:"auto",flex:1,children:e==null?void 0:e.map(s=>c.jsx(v.CollapsibleClickableContent,{onClick:()=>{if(t&&r){const a=!t[s.value];r({...t,[s.value]:a})}},contentLeft:c.jsx(Z.Checkbox,{tabIndex:-1,value:t==null?void 0:t[s.value]}),children:c.jsx(d.Text,{children:s.label})},s.value))})}),ue=({options:e,value:t,noneSelectedLabel:r,onValueChange:n,...s})=>{const[a,l]=o.useState(""),C=o.useMemo(()=>t?d.truthyKeysAsList(t).map(u=>{var m;const p=e==null?void 0:e.find(g=>g.value===u);return{value:u,label:(m=p==null?void 0:p.label)!=null?m:u}}):[],[e,t]),f=o.useMemo(()=>e==null?void 0:e.filter(u=>u.value.toLocaleLowerCase().indexOf(a.toLocaleLowerCase())>-1||u.label.toLocaleLowerCase().indexOf(a.toLocaleLowerCase())>-1),[e,a]),S=o.useCallback(u=>{n==null||n(de(u))},[n]);return c.jsx(R,{...s,children:c.jsx(N.ChipMultiSelect,{options:f,value:C,onValueChange:S,inputValue:a,noneSelectedLabel:r,onInputChange:l,closeMenuOnSelect:!1})})},de=e=>e.reduce((t,r)=>(t[r.value]=!0,t),{}),he=(e,t,r)=>({chips:K(e[t],e[r]),onClickRemoveOnChip:W(t,r)}),K=(e,t)=>!e&&!t?[]:[{value:"dateRange",label:`${e!=null?e:""} - ${t!=null?t:""}`}],W=(e,t)=>({setFormModelFields:r})=>{r({[e]:void 0,[t]:void 0})},xe=(e,t,r)=>({value:{startDate:e[t],endDate:e[r]},onValueChange:(n,{dispatch:s,actions:a})=>{const l={[t]:n.startDate,[r]:n.endDate};s(a.setFormModelFields(l))}}),Ce=({value:e,onValueChange:t,sectionId:r,...n})=>{const s=F(),a=j(),l=o.useMemo(()=>({dispatch:s,actions:a}),[a,s]),[C,f]=o.useState("startDate"),S=o.useMemo(()=>b.stringsToDateRange(e),[e]),u=o.useCallback(p=>{t(b.dateRangeToStrings(p),l)},[t,l]);return c.jsx(R,{sectionId:r,children:c.jsx(d.Box,{flex:1,alignItems:"center",children:c.jsx(d.Box,{background:"white",indent:!0,children:c.jsx(b.DateRangeCalendar,{setFocusedInput:f,focusedInput:C,value:S,onValueChange:u,...n})})})})};exports.ChipMultiSelectSection=ue;exports.DateRangeCalendarSection=Ce;exports.EmptyChip=T;exports.SearchFilterActionsContext=y;exports.SearchFilterButton=ne;exports.SearchFilterChip=_;exports.SearchFilterChips=ae;exports.SearchFilterContext=P;exports.SearchFilterDispatchContext=k;exports.SearchFilterDrawer=re;exports.SearchFilterLocalStateContext=se;exports.SearchFilterModelContext=A;exports.SearchFilterPanelHeader=q;exports.SearchFilterSection=R;exports.SearchFilterStateContext=w;exports.SectionChips=oe;exports.SimpleCheckboxListSection=ie;exports.createChipsForBooleanRecord=$;exports.createChipsForDateRange=K;exports.createChipsPropsForBooleanRecord=le;exports.createChipsPropsForDateRange=he;exports.createDateRangeSectionProps=xe;exports.createOnClickRemoveOnChipForBooleanRecord=z;exports.createOnClickRemoveOnChipForDateRange=W;exports.createSearchFilterActions=V;exports.createSearchFilterInitialState=D;exports.createSearchFilterReducer=G;exports.formatColumnIdToHeaderCellLabel=O;exports.getReducerIdFor=h;exports.useLocalSearchFilterState=H;exports.useSearchFilterActions=j;exports.useSearchFilterDispatch=F;exports.useSearchFilterModel=ce;exports.useSearchFilterState=M;
466
5
  //# sourceMappingURL=index.js.map