@react-fabric/searchbar 1.0.0-beta.1 → 1.0.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/filterbar/FilterForm.js +107 -79
- package/dist/cjs/filterbar/FilterTag.js +6 -2
- package/dist/cjs/filterbar/QueryForm.js +5 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/searchbar/SearchBar.js +19 -6
- package/dist/cjs/types/index.js +1 -1
- package/dist/esm/filterbar/FilterForm.js +109 -81
- package/dist/esm/filterbar/FilterTag.js +6 -2
- package/dist/esm/filterbar/QueryForm.js +5 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/searchbar/SearchBar.js +20 -7
- package/dist/esm/types/index.js +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/searchbar/SearchBar.d.ts +1 -1
- package/dist/types/types/index.d.ts +16 -13
- package/package.json +7 -7
- package/src/filterbar/FilterForm.tsx +96 -71
- package/src/filterbar/FilterTag.tsx +10 -3
- package/src/filterbar/QueryForm.tsx +13 -2
- package/src/index.ts +2 -6
- package/src/searchbar/SearchBar.tsx +21 -10
- package/src/types/index.ts +27 -18
|
@@ -5,16 +5,17 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
5
5
|
import { useFloatingTree } from '@floating-ui/react';
|
|
6
6
|
import { Row, Col, Button } from '@react-fabric/core';
|
|
7
7
|
import { Field, Controller, Switch, Select, Input, Number, Form } from '@react-fabric/form';
|
|
8
|
-
import { yup, shortHash } from '@react-fabric/utilities';
|
|
8
|
+
import { yup, shortHash, isArray } from '@react-fabric/utilities';
|
|
9
9
|
import { useRef, useState, useEffect, useMemo, useCallback } from 'react';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
|
-
import { OPERATOR, TypeOperators
|
|
11
|
+
import { FIELD_TYPE, OPERATOR, TypeOperators } from '../types/index.js';
|
|
12
12
|
import { useFilterContext } from './Context.js';
|
|
13
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
15
|
var FilterSchema = new yup.ObjectSchema({
|
|
16
16
|
id: yup.string().required(),
|
|
17
17
|
field: yup.string().required(),
|
|
18
|
+
type: yup.string().required().oneOf(Object.values(FIELD_TYPE)),
|
|
18
19
|
operator: yup.string().required().oneOf(Object.values(OPERATOR)),
|
|
19
20
|
negate: yup["boolean"](),
|
|
20
21
|
label: yup.string(),
|
|
@@ -57,10 +58,12 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
57
58
|
values = _useState2[0],
|
|
58
59
|
setValues = _useState2[1];
|
|
59
60
|
useEffect(function () {
|
|
60
|
-
|
|
61
|
-
setValues(
|
|
61
|
+
var _formRef$current, _formRef$current2;
|
|
62
|
+
if (filter && "field" in filter && filter.field) return (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.setValues(filter);
|
|
63
|
+
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValues({
|
|
62
64
|
id: shortHash(),
|
|
63
65
|
field: "",
|
|
66
|
+
type: FIELD_TYPE.NONE,
|
|
64
67
|
operator: OPERATOR.EXISTS
|
|
65
68
|
});
|
|
66
69
|
}, [filter]);
|
|
@@ -77,22 +80,38 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
77
80
|
});
|
|
78
81
|
}, [values]);
|
|
79
82
|
var operators = useMemo(function () {
|
|
80
|
-
var _formRef$
|
|
83
|
+
var _formRef$current3;
|
|
81
84
|
if (field == null) return [OPERATOR.EXISTS];
|
|
82
|
-
(_formRef$
|
|
85
|
+
(_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.setValue("operator", TypeOperators[field.type][0]);
|
|
83
86
|
return _toConsumableArray(TypeOperators[field.type]);
|
|
84
87
|
}, [field]);
|
|
85
|
-
|
|
88
|
+
var valueInput = useMemo(function () {
|
|
86
89
|
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.EXISTS && (values === null || values === void 0 ? void 0 : values.value) !== undefined) {
|
|
87
|
-
var _formRef$
|
|
88
|
-
(_formRef$
|
|
90
|
+
var _formRef$current4;
|
|
91
|
+
(_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 || _formRef$current4.setValue("value", undefined);
|
|
92
|
+
}
|
|
93
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.STRING) {
|
|
94
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IN) {
|
|
95
|
+
var _formRef$current5;
|
|
96
|
+
!isArray(values.value) && ((_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setValue("value", []));
|
|
97
|
+
} else {
|
|
98
|
+
var _formRef$current6;
|
|
99
|
+
isArray(values.value) && ((_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.setValue("value", undefined));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.NUMBER || (field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.DECIMAL) {
|
|
103
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.BETWEEN) {
|
|
104
|
+
var _formRef$current7;
|
|
105
|
+
!isArray(values.value) && ((_formRef$current7 = formRef.current) === null || _formRef$current7 === void 0 ? void 0 : _formRef$current7.setValue("value", []));
|
|
106
|
+
} else {
|
|
107
|
+
var _formRef$current8;
|
|
108
|
+
isArray(values.value) && ((_formRef$current8 = formRef.current) === null || _formRef$current8 === void 0 ? void 0 : _formRef$current8.setValue("value", undefined));
|
|
109
|
+
}
|
|
89
110
|
}
|
|
90
111
|
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN && (values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.IS && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
|
|
91
|
-
var _formRef$
|
|
92
|
-
(_formRef$
|
|
112
|
+
var _formRef$current9;
|
|
113
|
+
(_formRef$current9 = formRef.current) === null || _formRef$current9 === void 0 || _formRef$current9.setValue("value", false);
|
|
93
114
|
}
|
|
94
|
-
}, [values, field]);
|
|
95
|
-
var valueInput = useMemo(function () {
|
|
96
115
|
if (field == null || !(values !== null && values !== void 0 && values.operator)) return null;
|
|
97
116
|
if ((values === null || values === void 0 ? void 0 : values.operator) === OPERATOR.EXISTS) return null;
|
|
98
117
|
if ((field === null || field === void 0 ? void 0 : field.type) === FIELD_TYPE.BOOLEAN) {
|
|
@@ -112,6 +131,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
112
131
|
name: "value",
|
|
113
132
|
children: /*#__PURE__*/jsx(Select, {
|
|
114
133
|
multiple: true,
|
|
134
|
+
searchable: true,
|
|
115
135
|
allowCreate: true,
|
|
116
136
|
allowClear: true,
|
|
117
137
|
options: (_field$values = field.values) !== null && _field$values !== void 0 ? _field$values : [],
|
|
@@ -142,7 +162,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
142
162
|
})
|
|
143
163
|
}), /*#__PURE__*/jsx("span", {
|
|
144
164
|
className: "p-2 text-muted",
|
|
145
|
-
children: "
|
|
165
|
+
children: "\u2277"
|
|
146
166
|
}), /*#__PURE__*/jsx(Controller, {
|
|
147
167
|
name: "value[1]",
|
|
148
168
|
children: /*#__PURE__*/jsx(Number, {
|
|
@@ -167,6 +187,7 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
167
187
|
var filter = {
|
|
168
188
|
id: model.id,
|
|
169
189
|
field: model.field,
|
|
190
|
+
type: model.type,
|
|
170
191
|
negate: model.negate,
|
|
171
192
|
operator: model.operator,
|
|
172
193
|
value: model.value,
|
|
@@ -175,87 +196,94 @@ var FilterForm = function FilterForm(_ref) {
|
|
|
175
196
|
onChange === null || onChange === void 0 || onChange(filter);
|
|
176
197
|
tree === null || tree === void 0 || tree.events.emit("close");
|
|
177
198
|
}, [onChange]);
|
|
178
|
-
return /*#__PURE__*/
|
|
199
|
+
return /*#__PURE__*/jsx(Form, {
|
|
179
200
|
formRef: formRef,
|
|
180
201
|
schema: FilterSchema,
|
|
181
202
|
defaultValues: values,
|
|
182
203
|
onChange: setValues,
|
|
183
204
|
onSubmit: handleSubmit,
|
|
184
|
-
children:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
children: /*#__PURE__*/jsx(
|
|
188
|
-
|
|
189
|
-
children: /*#__PURE__*/jsx(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
206
|
+
className: "w-[32rem]",
|
|
207
|
+
children: [/*#__PURE__*/jsxs(Row, {
|
|
208
|
+
children: [/*#__PURE__*/jsx(Col, {
|
|
209
|
+
flex: "fill",
|
|
210
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
211
|
+
name: "field",
|
|
212
|
+
children: /*#__PURE__*/jsx(Select, {
|
|
213
|
+
required: true,
|
|
214
|
+
ref: inputRef,
|
|
215
|
+
label: t("label.field"),
|
|
216
|
+
options: fields,
|
|
217
|
+
labelProperty: "label",
|
|
218
|
+
valueProperty: "field",
|
|
219
|
+
groupProperty: "type",
|
|
220
|
+
onSelect: function onSelect(field) {
|
|
221
|
+
var _formRef$current10;
|
|
222
|
+
return (_formRef$current10 = formRef.current) === null || _formRef$current10 === void 0 ? void 0 : _formRef$current10.setValue("type", field.type);
|
|
223
|
+
}
|
|
224
|
+
})
|
|
197
225
|
})
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
226
|
+
}), /*#__PURE__*/jsxs(Col, {
|
|
227
|
+
flex: "auto",
|
|
228
|
+
className: "text-center",
|
|
229
|
+
children: [/*#__PURE__*/jsx("label", {
|
|
230
|
+
className: "block py-0.5 text-sm",
|
|
231
|
+
children: t("label.exclude")
|
|
232
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
233
|
+
name: "negate",
|
|
234
|
+
children: /*#__PURE__*/jsx(Switch, {
|
|
235
|
+
color: "danger"
|
|
236
|
+
})
|
|
237
|
+
})]
|
|
238
|
+
}), /*#__PURE__*/jsx(Col, {
|
|
239
|
+
flex: "auto",
|
|
240
|
+
className: "basis-28",
|
|
241
|
+
children: /*#__PURE__*/jsx(Controller, {
|
|
242
|
+
name: "operator",
|
|
243
|
+
children: /*#__PURE__*/jsx(Select, {
|
|
244
|
+
label: t("label.operator"),
|
|
245
|
+
options: operators,
|
|
246
|
+
renderer: function renderer(v) {
|
|
247
|
+
return t("operator.".concat(v));
|
|
248
|
+
}
|
|
249
|
+
})
|
|
209
250
|
})
|
|
210
251
|
})]
|
|
211
|
-
}), /*#__PURE__*/jsx(
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
renderer: function renderer(v) {
|
|
220
|
-
return t("operator.".concat(v));
|
|
221
|
-
}
|
|
252
|
+
}), /*#__PURE__*/jsx("br", {}), valueInput, /*#__PURE__*/jsx("br", {}), /*#__PURE__*/jsx(Controller, {
|
|
253
|
+
name: "label",
|
|
254
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
255
|
+
label: t("label.label"),
|
|
256
|
+
placeholder: t("label.label"),
|
|
257
|
+
decorateEnd: !(filter !== null && filter !== void 0 && filter.label) && /*#__PURE__*/jsx("span", {
|
|
258
|
+
className: "text-sm opacity-65 pe-4",
|
|
259
|
+
children: "Optional"
|
|
222
260
|
})
|
|
223
261
|
})
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
children: [onRemove && /*#__PURE__*/jsx("div", {
|
|
238
|
-
className: "flex-1",
|
|
239
|
-
children: /*#__PURE__*/jsx(Button, {
|
|
262
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
263
|
+
className: "flex pt-4 justify-end gap-1",
|
|
264
|
+
children: [onRemove && /*#__PURE__*/jsx("div", {
|
|
265
|
+
className: "flex-1",
|
|
266
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
267
|
+
"data-dropdown-dismiss": "true",
|
|
268
|
+
variant: "link",
|
|
269
|
+
size: "sm",
|
|
270
|
+
color: "danger",
|
|
271
|
+
onClick: onRemove,
|
|
272
|
+
children: t("label.remove")
|
|
273
|
+
})
|
|
274
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
240
275
|
"data-dropdown-dismiss": "true",
|
|
241
276
|
variant: "link",
|
|
242
277
|
size: "sm",
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
size: "sm",
|
|
251
|
-
children: t("label.cancel")
|
|
252
|
-
}), /*#__PURE__*/jsx(Button, {
|
|
253
|
-
type: "submit",
|
|
254
|
-
variant: "solid",
|
|
255
|
-
size: "sm",
|
|
256
|
-
children: t("label.apply")
|
|
278
|
+
children: t("label.cancel")
|
|
279
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
280
|
+
type: "submit",
|
|
281
|
+
variant: "solid",
|
|
282
|
+
size: "sm",
|
|
283
|
+
children: t("label.apply")
|
|
284
|
+
})]
|
|
257
285
|
})]
|
|
258
|
-
})
|
|
286
|
+
})
|
|
259
287
|
});
|
|
260
288
|
};
|
|
261
289
|
|
|
@@ -51,7 +51,8 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
51
51
|
});
|
|
52
52
|
}, [filter]);
|
|
53
53
|
var color = useMemo(function () {
|
|
54
|
-
|
|
54
|
+
var _filter$color;
|
|
55
|
+
return (_filter$color = filter.color) !== null && _filter$color !== void 0 ? _filter$color : filter.negate ? excludedColor : includedColor;
|
|
55
56
|
}, [filter, includedColor, excludedColor]);
|
|
56
57
|
var icon = useMemo(function () {
|
|
57
58
|
if (filter.canDisable === false) return undefined;
|
|
@@ -71,13 +72,16 @@ var FilterTag = function FilterTag(_ref) {
|
|
|
71
72
|
disabled: !filter.disabled
|
|
72
73
|
})), e.stopPropagation()];
|
|
73
74
|
},
|
|
75
|
+
"data-testid": "filter-tag",
|
|
76
|
+
"data-test-value": filter.id,
|
|
74
77
|
stopPropagation: true,
|
|
75
78
|
onRemove: filter.required ? undefined : function () {
|
|
76
79
|
return onRemove();
|
|
77
80
|
},
|
|
78
81
|
children: /*#__PURE__*/jsxs("div", {
|
|
79
|
-
className: classNames("flex gap-1", filter.disabled && "line-through opacity-65"),
|
|
82
|
+
className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
|
|
80
83
|
children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
|
|
84
|
+
className: "flex-content",
|
|
81
85
|
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
|
|
82
86
|
}), label]
|
|
83
87
|
})
|
|
@@ -95,8 +95,12 @@ var QueryForm = function QueryForm(_ref) {
|
|
|
95
95
|
className: classNames("block px-2", invalid && "text-danger-600"),
|
|
96
96
|
children: t("label.query")
|
|
97
97
|
}), /*#__PURE__*/jsx("div", {
|
|
98
|
-
className: "h-[
|
|
98
|
+
className: "h-[24rem] w-[36rem] grid outline place-content-start",
|
|
99
|
+
style: {
|
|
100
|
+
gridTemplate: '"content" 1fr/1fr'
|
|
101
|
+
},
|
|
99
102
|
children: /*#__PURE__*/jsx(CodeEditor, _objectSpread(_objectSpread({
|
|
103
|
+
language: "json",
|
|
100
104
|
minimal: true,
|
|
101
105
|
required: true
|
|
102
106
|
}, field), {}, {
|
package/dist/esm/index.js
CHANGED
|
@@ -7,12 +7,12 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
|
|
|
7
7
|
import { useLocalStorage, useDebounce, Button } from '@react-fabric/core';
|
|
8
8
|
import { Field, AutoComplete } from '@react-fabric/form';
|
|
9
9
|
import { EMPTY_ARRAY, isArray, dedupe } from '@react-fabric/utilities';
|
|
10
|
-
import { useState, useMemo, useReducer } from 'react';
|
|
10
|
+
import { useState, useMemo, useReducer, useEffect } from 'react';
|
|
11
11
|
import { useTranslation } from 'react-i18next';
|
|
12
12
|
import { FilterBar } from '../filterbar/FilterBar.js';
|
|
13
13
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
16
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
var SearchBar = function SearchBar(_ref) {
|
|
@@ -25,14 +25,14 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
25
25
|
append = _ref.append,
|
|
26
26
|
decorateEnd = _ref.decorateEnd,
|
|
27
27
|
decorateStart = _ref.decorateStart,
|
|
28
|
-
|
|
28
|
+
children = _ref.children,
|
|
29
29
|
hideFilters = _ref.hideFilters,
|
|
30
30
|
_ref$defaultCollapsed = _ref.defaultCollapsed,
|
|
31
31
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
32
32
|
_ref.disabled;
|
|
33
33
|
_ref.onCollapsed;
|
|
34
|
-
|
|
35
|
-
onSearch = _ref.onSearch,
|
|
34
|
+
_ref.onQuery;
|
|
35
|
+
var onSearch = _ref.onSearch,
|
|
36
36
|
query = _ref.query,
|
|
37
37
|
multiple = _ref.multiple,
|
|
38
38
|
_ref$filters = _ref.filters,
|
|
@@ -58,6 +58,12 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
58
58
|
});
|
|
59
59
|
}, []);
|
|
60
60
|
var _useReducer = useReducer(function (state, action) {
|
|
61
|
+
if (action.type === "reset") {
|
|
62
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
|
+
query: action.query,
|
|
64
|
+
filters: action.filters
|
|
65
|
+
});
|
|
66
|
+
}
|
|
61
67
|
if (action.type === "dirty") {
|
|
62
68
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
69
|
dirty: action.dirty
|
|
@@ -88,6 +94,13 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
88
94
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
89
95
|
state = _useReducer2[0],
|
|
90
96
|
dispatch = _useReducer2[1];
|
|
97
|
+
useEffect(function () {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: "reset",
|
|
100
|
+
filters: filters,
|
|
101
|
+
query: query
|
|
102
|
+
});
|
|
103
|
+
}, [filters, query]);
|
|
91
104
|
var updateHistory = function updateHistory(value) {
|
|
92
105
|
var historyEntry = isArray(value) ? value : [value];
|
|
93
106
|
setHistory(dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
|
|
@@ -131,7 +144,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
131
144
|
});
|
|
132
145
|
},
|
|
133
146
|
onSelect: updateHistory,
|
|
134
|
-
|
|
147
|
+
"data-testid": "searchbar-input",
|
|
135
148
|
onEnterPressed: function onEnterPressed() {
|
|
136
149
|
return fireSearch(state.query, state.filters);
|
|
137
150
|
}
|
|
@@ -143,7 +156,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
143
156
|
},
|
|
144
157
|
children: t(state.dirty ? "label.update" : "label.refresh")
|
|
145
158
|
})]
|
|
146
|
-
}),
|
|
159
|
+
}), children]
|
|
147
160
|
}), !hideFilters && !collapsed && /*#__PURE__*/jsx(FilterBar, _objectSpread(_objectSpread({}, filterProps), {}, {
|
|
148
161
|
filters: state.filters,
|
|
149
162
|
onFilterChanged: handleFilterChange
|
package/dist/esm/types/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
54
54
|
/**
|
|
55
55
|
* @internal
|
|
56
56
|
*/
|
|
57
|
-
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
57
|
+
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS, OPERATOR.IN]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.IN, OPERATOR.INCLUDES, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.IS]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* @internal
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
|
+
export { FilterBar } from "./filterbar/FilterBar";
|
|
2
3
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
3
|
-
export { FIELD_TYPE, OPERATOR, type FilterObject
|
|
4
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type FilterBarProps, type SearchBarProps } from "../types";
|
|
2
|
-
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart,
|
|
2
|
+
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart, children, hideFilters, defaultCollapsed, disabled, onCollapsed, onQuery, onSearch, query, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
1
2
|
import { type ReactElement } from "react";
|
|
2
3
|
export declare enum FIELD_TYPE {
|
|
3
4
|
ID = "ID",
|
|
@@ -42,6 +43,7 @@ interface BaseFilter {
|
|
|
42
43
|
icon?: string;
|
|
43
44
|
label?: string;
|
|
44
45
|
group?: string;
|
|
46
|
+
color?: string;
|
|
45
47
|
value?: FilterValue;
|
|
46
48
|
pinned?: boolean;
|
|
47
49
|
negate?: boolean;
|
|
@@ -54,7 +56,7 @@ interface BaseFilter {
|
|
|
54
56
|
}
|
|
55
57
|
export type FilterObject = BaseFilter & ({
|
|
56
58
|
field: string;
|
|
57
|
-
type
|
|
59
|
+
type: FIELD_TYPE;
|
|
58
60
|
operator: OPERATOR;
|
|
59
61
|
value?: FilterValue;
|
|
60
62
|
query?: never;
|
|
@@ -65,8 +67,8 @@ export type FilterObject = BaseFilter & ({
|
|
|
65
67
|
label: string;
|
|
66
68
|
query: string;
|
|
67
69
|
});
|
|
68
|
-
export interface SearchObject {
|
|
69
|
-
query?:
|
|
70
|
+
export interface SearchObject<T = string> {
|
|
71
|
+
query?: T;
|
|
70
72
|
filters: FilterObject[];
|
|
71
73
|
}
|
|
72
74
|
export type FieldValue = string | {
|
|
@@ -82,7 +84,7 @@ export interface FilterField {
|
|
|
82
84
|
defaultOperator?: OPERATOR;
|
|
83
85
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
84
86
|
}
|
|
85
|
-
interface BaseSearchBarProps {
|
|
87
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
86
88
|
/**
|
|
87
89
|
* Query string
|
|
88
90
|
*/
|
|
@@ -109,10 +111,6 @@ interface BaseSearchBarProps {
|
|
|
109
111
|
* Add-on after search input
|
|
110
112
|
*/
|
|
111
113
|
append?: ReactElement;
|
|
112
|
-
/**
|
|
113
|
-
* Additional actions menu
|
|
114
|
-
*/
|
|
115
|
-
actions?: ReactElement;
|
|
116
114
|
/**
|
|
117
115
|
* Hide filter bar
|
|
118
116
|
*/
|
|
@@ -139,11 +137,6 @@ interface BaseSearchBarProps {
|
|
|
139
137
|
* @param collapsed
|
|
140
138
|
*/
|
|
141
139
|
onCollapsed?: (collapsed: boolean) => void;
|
|
142
|
-
/**
|
|
143
|
-
* On search event
|
|
144
|
-
* @param queryObject
|
|
145
|
-
*/
|
|
146
|
-
onSearch?: (queryObject: SearchObject) => void;
|
|
147
140
|
/**
|
|
148
141
|
* On query string change event
|
|
149
142
|
* @param query
|
|
@@ -153,9 +146,19 @@ interface BaseSearchBarProps {
|
|
|
153
146
|
export type SearchBarProps = BaseSearchBarProps & ({
|
|
154
147
|
multiple: true;
|
|
155
148
|
query?: string[];
|
|
149
|
+
/**
|
|
150
|
+
* On search event
|
|
151
|
+
* @param queryObject
|
|
152
|
+
*/
|
|
153
|
+
onSearch?: (queryObject: SearchObject<string[]>) => void;
|
|
156
154
|
} | {
|
|
157
155
|
multiple?: never | false;
|
|
158
156
|
query?: string;
|
|
157
|
+
/**
|
|
158
|
+
* On search event
|
|
159
|
+
* @param queryObject
|
|
160
|
+
*/
|
|
161
|
+
onSearch?: (queryObject: SearchObject) => void;
|
|
159
162
|
});
|
|
160
163
|
export interface FilterBarProps {
|
|
161
164
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-fabric/searchbar",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@floating-ui/react": "0.26.24",
|
|
37
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/date": "^1.0.0-beta.
|
|
39
|
-
"@react-fabric/form": "^1.0.0-beta.
|
|
40
|
-
"@react-fabric/monaco": "^1.0.0-beta.
|
|
41
|
-
"@react-fabric/utilities": "^1.0.0-beta.
|
|
37
|
+
"@react-fabric/core": "^1.0.0-beta.11",
|
|
38
|
+
"@react-fabric/date": "^1.0.0-beta.11",
|
|
39
|
+
"@react-fabric/form": "^1.0.0-beta.11",
|
|
40
|
+
"@react-fabric/monaco": "^1.0.0-beta.11",
|
|
41
|
+
"@react-fabric/utilities": "^1.0.0-beta.11",
|
|
42
42
|
"classnames": "^2.5.1",
|
|
43
43
|
"react-hook-form": "^7.52.1"
|
|
44
44
|
},
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"node": ">=18.12.0",
|
|
53
53
|
"npm": ">=8.19.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c113890832384265335f0572bfad9438e811917f"
|
|
56
56
|
}
|