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