@react-fabric/searchbar 1.0.0-beta.6 → 1.0.0-beta.60
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/FilterBar.js +10 -6
- package/dist/cjs/filterbar/FilterForm.js +141 -36
- package/dist/cjs/filterbar/FilterMenu.js +16 -4
- package/dist/cjs/filterbar/FilterTag.js +16 -8
- package/dist/cjs/filterbar/FilterView.js +6 -2
- package/dist/cjs/filterbar/QueryForm.js +9 -7
- package/dist/cjs/i18n/ar.json.js +42 -39
- package/dist/cjs/i18n/en.json.js +43 -39
- package/dist/cjs/searchbar/SearchBar.js +60 -7
- package/dist/cjs/types/index.js +12 -4
- package/dist/esm/filterbar/FilterBar.js +10 -6
- package/dist/esm/filterbar/FilterForm.js +142 -37
- package/dist/esm/filterbar/FilterMenu.js +16 -4
- package/dist/esm/filterbar/FilterTag.js +16 -8
- package/dist/esm/filterbar/FilterView.js +6 -2
- package/dist/esm/filterbar/QueryForm.js +9 -7
- package/dist/esm/i18n/ar.json.js +42 -39
- package/dist/esm/i18n/en.json.js +43 -39
- package/dist/esm/searchbar/SearchBar.js +61 -8
- package/dist/esm/types/index.js +12 -4
- package/dist/types/filterbar/Context.d.ts +2 -3
- package/dist/types/filterbar/FilterBar.d.ts +27 -1
- package/dist/types/filterbar/FilterMenu.d.ts +2 -1
- package/dist/types/filterbar/FilterTag.d.ts +2 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/searchbar/SearchBar.d.ts +35 -1
- package/dist/types/types/index.d.ts +19 -10
- package/package.json +16 -14
- package/src/filterbar/Context.tsx +4 -1
- package/src/filterbar/FilterBar.tsx +49 -7
- package/src/filterbar/FilterForm.tsx +110 -25
- package/src/filterbar/FilterMenu.tsx +30 -3
- package/src/filterbar/FilterTag.tsx +25 -9
- package/src/filterbar/FilterView.tsx +5 -2
- package/src/filterbar/QueryForm.tsx +5 -5
- package/src/i18n/ar.json +42 -39
- package/src/i18n/en.json +43 -39
- package/src/index.ts +6 -1
- package/src/searchbar/SearchBar.tsx +58 -5
- package/src/types/index.ts +57 -34
package/dist/esm/i18n/en.json.js
CHANGED
|
@@ -1,70 +1,74 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
var label = {
|
|
4
|
-
|
|
4
|
+
add: "Add Filter",
|
|
5
5
|
all_filters: "All Filters",
|
|
6
|
+
apply: "Apply",
|
|
7
|
+
basicFilter: "Basic Filter",
|
|
8
|
+
cancel: "Cancel",
|
|
9
|
+
customQuery: "Custom Query",
|
|
10
|
+
"delete": "Delete",
|
|
11
|
+
disable: "Disable",
|
|
12
|
+
disableAll: "Disable All",
|
|
13
|
+
edit: "Edit",
|
|
14
|
+
enable: "Enable",
|
|
15
|
+
enableAll: "Enable All",
|
|
16
|
+
exclude: "Exclude",
|
|
17
|
+
excludeAll: "Exclude All",
|
|
6
18
|
field: "Field",
|
|
7
|
-
|
|
8
|
-
|
|
19
|
+
filters: "Filters",
|
|
20
|
+
forAdvanced: "For advanced users only!",
|
|
21
|
+
include: "Include",
|
|
22
|
+
includeAll: "Include All",
|
|
23
|
+
invertAll: "Invert Include/Exclude",
|
|
9
24
|
label: "Label",
|
|
25
|
+
matchAll: "Match All",
|
|
26
|
+
matchAny: "Match Any",
|
|
27
|
+
operator: "Operator",
|
|
10
28
|
optional: "Optional",
|
|
11
|
-
add: "Add Filter",
|
|
12
|
-
edit: "Edit",
|
|
13
|
-
view: "View",
|
|
14
29
|
pin: "Pinned",
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
invertAll: "Invert Include/Exclude",
|
|
30
|
+
query: "Query",
|
|
31
|
+
refresh: "Refresh",
|
|
32
|
+
remove: "Remove",
|
|
19
33
|
removeAll: "Remove All",
|
|
20
|
-
enableAll: "Enable All",
|
|
21
|
-
disableAll: "Disable All",
|
|
22
34
|
toggleDisable: "Invert Disable/Enable",
|
|
23
|
-
|
|
24
|
-
enable: "Enable",
|
|
25
|
-
disable: "Disable",
|
|
26
|
-
exclude: "Exclude",
|
|
27
|
-
include: "Include",
|
|
28
|
-
refresh: "Refresh",
|
|
35
|
+
unpin: "Unpinned",
|
|
29
36
|
update: "Update",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
cancel: "Cancel",
|
|
33
|
-
"delete": "Delete",
|
|
34
|
-
basicFilter: "Basic Filter",
|
|
35
|
-
customQuery: "Custom Query",
|
|
36
|
-
forAdvanced: "For advanced users only!"
|
|
37
|
+
value: "Value",
|
|
38
|
+
view: "View"
|
|
37
39
|
};
|
|
38
40
|
var operator = {
|
|
41
|
+
ALL: "All of",
|
|
42
|
+
ANY: "Any of",
|
|
43
|
+
BETWEEN: "Between",
|
|
44
|
+
ENDS: "Ends with",
|
|
45
|
+
EQ: "=",
|
|
39
46
|
EXISTS: "Exists",
|
|
47
|
+
GT: ">",
|
|
48
|
+
GTE: "≥",
|
|
40
49
|
IS: "Is",
|
|
41
|
-
|
|
50
|
+
LIKE: "Like",
|
|
42
51
|
LT: "<",
|
|
43
|
-
GT: ">",
|
|
44
52
|
LTE: "≤",
|
|
45
|
-
GTE: "≥",
|
|
46
|
-
INCLUDES: "Includes",
|
|
47
53
|
STARTS: "Starts with",
|
|
48
|
-
|
|
49
|
-
WITHIN: "Within",
|
|
50
|
-
BETWEEN: "Between"
|
|
54
|
+
WITHIN: "Within"
|
|
51
55
|
};
|
|
52
56
|
var placeholder = "Search term...";
|
|
53
57
|
var type = {
|
|
54
|
-
STRING: "String",
|
|
55
|
-
NUMBER: "Number",
|
|
56
|
-
DECIMAL: "Decimal",
|
|
57
58
|
BOOLEAN: "Bool",
|
|
58
59
|
DATE: "Date",
|
|
59
60
|
DATETIME: "Date Time",
|
|
60
|
-
|
|
61
|
+
DECIMAL: "Decimal",
|
|
62
|
+
GEO: "GeoJSON",
|
|
63
|
+
NUMBER: "Number",
|
|
64
|
+
STRING: "String"
|
|
61
65
|
};
|
|
62
66
|
var validate = {
|
|
67
|
+
compare: "Compare field required",
|
|
63
68
|
field: "Field required",
|
|
69
|
+
label: "Label required",
|
|
64
70
|
operator: "Operator required",
|
|
65
|
-
value: "Value required"
|
|
66
|
-
compare: "Compare field required",
|
|
67
|
-
label: "Label required"
|
|
71
|
+
value: "Value required"
|
|
68
72
|
};
|
|
69
73
|
var en = {
|
|
70
74
|
label: label,
|
|
@@ -7,14 +7,48 @@ 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", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "children", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "ref", "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
|
+
/**
|
|
19
|
+
* This component provides a search input with autocomplete functionality,
|
|
20
|
+
* a button to trigger search, and an optional filter bar.
|
|
21
|
+
* It supports history of search queries, multiple selection, and custom decorations.
|
|
22
|
+
* It can be collapsed to hide filters and has options for customization.
|
|
23
|
+
*
|
|
24
|
+
* @param {SearchBarProps} props - The properties for the SearchBar component.
|
|
25
|
+
* @returns {JSX.Element} The rendered SearchBar component.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```jsx
|
|
29
|
+
* <SearchBar
|
|
30
|
+
* historyKey="myApp:searchHistory"
|
|
31
|
+
* historyCount={10}
|
|
32
|
+
* defaultQueryList={["example", "test"]}
|
|
33
|
+
* prepend={<span>Prepend</span>}
|
|
34
|
+
* append={<span>Append</span>}
|
|
35
|
+
* decorateEnd={<span>End Decoration</span>}
|
|
36
|
+
* decorateStart={<span>Start Decoration</span>}
|
|
37
|
+
* hideFilters={false}
|
|
38
|
+
* defaultCollapsed={false}
|
|
39
|
+
* disabled={false}
|
|
40
|
+
* onCollapsed={(collapsed) => console.log("Collapsed:", collapsed)}
|
|
41
|
+
* onQuery={(query) => console.log("Query:", query)}
|
|
42
|
+
* onSearch={({ query, filters }) => console.log("Search:", query, filters)}
|
|
43
|
+
* query={""}
|
|
44
|
+
* ref={searchInputRef}
|
|
45
|
+
* multiple={false}
|
|
46
|
+
* filters={[{ name: "filter1", value: "value1" }]}
|
|
47
|
+
* />
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
51
|
+
*/
|
|
18
52
|
var SearchBar = function SearchBar(_ref) {
|
|
19
53
|
var _ref$historyKey = _ref.historyKey,
|
|
20
54
|
historyKey = _ref$historyKey === void 0 ? "ruf:search" : _ref$historyKey,
|
|
@@ -31,9 +65,10 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
31
65
|
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
32
66
|
_ref.disabled;
|
|
33
67
|
_ref.onCollapsed;
|
|
34
|
-
|
|
35
|
-
onSearch = _ref.onSearch,
|
|
68
|
+
_ref.onQuery;
|
|
69
|
+
var onSearch = _ref.onSearch,
|
|
36
70
|
query = _ref.query,
|
|
71
|
+
ref = _ref.ref,
|
|
37
72
|
multiple = _ref.multiple,
|
|
38
73
|
_ref$filters = _ref.filters,
|
|
39
74
|
filters = _ref$filters === void 0 ? EMPTY_ARRAY : _ref$filters,
|
|
@@ -52,12 +87,23 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
52
87
|
return multiple ? EMPTY_ARRAY : "";
|
|
53
88
|
}, [multiple]);
|
|
54
89
|
var fireSearch = useDebounce(function (query, filters) {
|
|
90
|
+
dispatch({
|
|
91
|
+
type: "dirty",
|
|
92
|
+
dirty: false
|
|
93
|
+
});
|
|
55
94
|
onSearch === null || onSearch === void 0 || onSearch({
|
|
56
95
|
query: query,
|
|
57
96
|
filters: filters
|
|
58
97
|
});
|
|
59
98
|
}, []);
|
|
60
99
|
var _useReducer = useReducer(function (state, action) {
|
|
100
|
+
if (action.type === "reset") {
|
|
101
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
102
|
+
dirty: false,
|
|
103
|
+
query: action.query,
|
|
104
|
+
filters: action.filters
|
|
105
|
+
});
|
|
106
|
+
}
|
|
61
107
|
if (action.type === "dirty") {
|
|
62
108
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
109
|
dirty: action.dirty
|
|
@@ -67,7 +113,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
67
113
|
var _action$query, _action$query2;
|
|
68
114
|
!multiple && fireSearch((_action$query = action.query) !== null && _action$query !== void 0 ? _action$query : emptyValue, state.filters);
|
|
69
115
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
70
|
-
dirty:
|
|
116
|
+
dirty: !!multiple,
|
|
71
117
|
query: (_action$query2 = action.query) !== null && _action$query2 !== void 0 ? _action$query2 : emptyValue
|
|
72
118
|
});
|
|
73
119
|
}
|
|
@@ -88,6 +134,13 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
88
134
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
89
135
|
state = _useReducer2[0],
|
|
90
136
|
dispatch = _useReducer2[1];
|
|
137
|
+
useEffect(function () {
|
|
138
|
+
dispatch({
|
|
139
|
+
type: "reset",
|
|
140
|
+
filters: filters,
|
|
141
|
+
query: query
|
|
142
|
+
});
|
|
143
|
+
}, [filters, query]);
|
|
91
144
|
var updateHistory = function updateHistory(value) {
|
|
92
145
|
var historyEntry = isArray(value) ? value : [value];
|
|
93
146
|
setHistory(dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
|
|
@@ -119,6 +172,7 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
119
172
|
}), prepend, /*#__PURE__*/jsx(AutoComplete, {
|
|
120
173
|
allowClear: true,
|
|
121
174
|
expandOnEdit: true,
|
|
175
|
+
ref: ref,
|
|
122
176
|
multiple: multiple,
|
|
123
177
|
history: history,
|
|
124
178
|
value: state.query,
|
|
@@ -127,12 +181,11 @@ var SearchBar = function SearchBar(_ref) {
|
|
|
127
181
|
onInput: function onInput() {
|
|
128
182
|
return dispatch({
|
|
129
183
|
type: "dirty",
|
|
130
|
-
dirty:
|
|
184
|
+
dirty: !multiple
|
|
131
185
|
});
|
|
132
186
|
},
|
|
133
187
|
onSelect: updateHistory,
|
|
134
|
-
|
|
135
|
-
"data-testid": "searchbar-input",
|
|
188
|
+
"data-ref": "searchbarInput",
|
|
136
189
|
onEnterPressed: function onEnterPressed() {
|
|
137
190
|
return fireSearch(state.query, state.filters);
|
|
138
191
|
}
|
package/dist/esm/types/index.js
CHANGED
|
@@ -29,21 +29,26 @@ var _OperatorValueType;
|
|
|
29
29
|
var FIELD_TYPE = /*#__PURE__*/function (FIELD_TYPE) {
|
|
30
30
|
FIELD_TYPE["ID"] = "ID";
|
|
31
31
|
FIELD_TYPE["STRING"] = "STRING";
|
|
32
|
+
FIELD_TYPE["TEXT"] = "TEXT";
|
|
32
33
|
FIELD_TYPE["NUMBER"] = "NUMBER";
|
|
33
34
|
FIELD_TYPE["DECIMAL"] = "DECIMAL";
|
|
34
35
|
FIELD_TYPE["BOOLEAN"] = "BOOLEAN";
|
|
36
|
+
FIELD_TYPE["DATE"] = "DATE";
|
|
37
|
+
FIELD_TYPE["DATETIME"] = "DATETIME";
|
|
35
38
|
FIELD_TYPE["NONE"] = "NONE";
|
|
36
39
|
return FIELD_TYPE;
|
|
37
40
|
}({});
|
|
38
41
|
var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
39
42
|
OPERATOR["EXISTS"] = "EXISTS";
|
|
40
43
|
OPERATOR["IS"] = "IS";
|
|
41
|
-
OPERATOR["
|
|
44
|
+
OPERATOR["ALL"] = "ALL";
|
|
45
|
+
OPERATOR["ANY"] = "ANY";
|
|
46
|
+
OPERATOR["EQ"] = "EQ";
|
|
42
47
|
OPERATOR["LT"] = "LT";
|
|
43
48
|
OPERATOR["GT"] = "GT";
|
|
44
49
|
OPERATOR["LTE"] = "LTE";
|
|
45
50
|
OPERATOR["GTE"] = "GTE";
|
|
46
|
-
OPERATOR["
|
|
51
|
+
OPERATOR["LIKE"] = "LIKE";
|
|
47
52
|
OPERATOR["STARTS"] = "STARTS";
|
|
48
53
|
OPERATOR["ENDS"] = "ENDS";
|
|
49
54
|
OPERATOR["WITHIN"] = "WITHIN";
|
|
@@ -54,12 +59,15 @@ var OPERATOR = /*#__PURE__*/function (OPERATOR) {
|
|
|
54
59
|
/**
|
|
55
60
|
* @internal
|
|
56
61
|
*/
|
|
57
|
-
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS, OPERATOR.
|
|
62
|
+
var TypeOperators = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FIELD_TYPE.ID, [OPERATOR.IS, OPERATOR.ANY]), FIELD_TYPE.STRING, [OPERATOR.EXISTS, OPERATOR.IS, OPERATOR.ANY, OPERATOR.ALL]), FIELD_TYPE.TEXT, [OPERATOR.EXISTS, OPERATOR.LIKE, OPERATOR.STARTS, OPERATOR.ENDS]), FIELD_TYPE.NUMBER, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DECIMAL, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.BOOLEAN, [OPERATOR.EXISTS, OPERATOR.EQ]), FIELD_TYPE.DATE, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.DATETIME, [OPERATOR.EXISTS, OPERATOR.EQ, OPERATOR.BETWEEN, OPERATOR.LT, OPERATOR.GT, OPERATOR.LTE, OPERATOR.GTE]), FIELD_TYPE.NONE, [OPERATOR.EXISTS]);
|
|
58
63
|
|
|
59
64
|
/**
|
|
60
65
|
* @internal
|
|
66
|
+
* 0 single value
|
|
67
|
+
* 1 many values
|
|
68
|
+
* 2 two values
|
|
61
69
|
*/
|
|
62
|
-
(_OperatorValueType = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.EXISTS, 0), OPERATOR.IS, 0), OPERATOR.
|
|
70
|
+
(_OperatorValueType = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.EXISTS, 0), OPERATOR.IS, 0), OPERATOR.ANY, 1), OPERATOR.ALL, 1), OPERATOR.BETWEEN, 2), OPERATOR.WITHIN, 0), OPERATOR.STARTS, 0), OPERATOR.ENDS, 0), OPERATOR.LIKE, 0), OPERATOR.EQ, 0), _defineProperty(_defineProperty(_defineProperty(_defineProperty(_OperatorValueType, OPERATOR.LT, 0), OPERATOR.GT, 0), OPERATOR.LTE, 0), OPERATOR.GTE, 0));
|
|
63
71
|
|
|
64
72
|
/**
|
|
65
73
|
* @internal
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type FilterBarProps } from "../types";
|
|
3
|
-
export declare const FilterContext: import("react").Context<Pick<FilterBarProps, "querySchema" | "defaultQuery" | "fields">>;
|
|
4
|
-
export declare const useFilterContext: () => Pick<FilterBarProps, "querySchema" | "defaultQuery" | "fields">;
|
|
2
|
+
export declare const FilterContext: import("react").Context<Pick<FilterBarProps, "querySchema" | "queryLanguage" | "defaultQuery" | "fields">>;
|
|
3
|
+
export declare const useFilterContext: () => Pick<FilterBarProps, "querySchema" | "queryLanguage" | "defaultQuery" | "fields">;
|
|
@@ -1,2 +1,28 @@
|
|
|
1
1
|
import { type FilterBarProps } from "../types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* FilterBar component allows users to manage a list of filters.
|
|
4
|
+
* It provides options to add, remove, and modify filters,
|
|
5
|
+
* as well as to enable or disable all filters at once.
|
|
6
|
+
* It also supports toggling between included and excluded filters.
|
|
7
|
+
*
|
|
8
|
+
* @param {FilterBarProps} props - The properties for the FilterBar component.
|
|
9
|
+
* @returns {JSX.Element} The rendered FilterBar component.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```jsx
|
|
13
|
+
* <FilterBar
|
|
14
|
+
* filters={filters}
|
|
15
|
+
* allowAdd={true}
|
|
16
|
+
* fields={fields}
|
|
17
|
+
* editable={true}
|
|
18
|
+
* querySchema={querySchema}
|
|
19
|
+
* queryLanguage="lucene"
|
|
20
|
+
* defaultQuery="*"
|
|
21
|
+
* includedColor="green"
|
|
22
|
+
* excludedColor="red"
|
|
23
|
+
* onFilterChanged={(newFilters) => console.log(newFilters)}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
27
|
+
*/
|
|
28
|
+
export declare const FilterBar: ({ filters, allowAdd, fields, editable, querySchema, queryLanguage, defaultQuery, includedColor, excludedColor, onFilterChanged, }: FilterBarProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterField, type FilterObject } from "../types";
|
|
2
|
-
export declare const FilterMenu: ({ filter, fields, onChange, onRemove, }: {
|
|
2
|
+
export declare const FilterMenu: ({ filter, fields, editable, onChange, onRemove, }: {
|
|
3
3
|
fields?: FilterField[];
|
|
4
|
+
editable?: boolean;
|
|
4
5
|
filter: FilterObject;
|
|
5
6
|
onRemove: () => void;
|
|
6
7
|
onChange: (filter: FilterObject) => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FilterBarProps, type FilterObject } from "../types";
|
|
2
|
-
export declare const FilterTag: ({ filter, fields, includedColor, excludedColor, onChange, onRemove, }: {
|
|
2
|
+
export declare const FilterTag: ({ filter, fields, editable, includedColor, excludedColor, onChange, onRemove, }: {
|
|
3
3
|
filter: FilterObject;
|
|
4
|
+
editable?: boolean;
|
|
4
5
|
onRemove: () => void;
|
|
5
6
|
onChange: (filter: FilterObject) => void;
|
|
6
7
|
} & Pick<FilterBarProps, "fields" | "includedColor" | "excludedColor">) => import("react/jsx-runtime").JSX.Element;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import "./i18n";
|
|
2
2
|
export { FilterBar } from "./filterbar/FilterBar";
|
|
3
3
|
export { SearchBar } from "./searchbar/SearchBar";
|
|
4
|
-
export { FIELD_TYPE, OPERATOR, type FilterObject } from "./types";
|
|
4
|
+
export { FIELD_TYPE, OPERATOR, type FilterObject, type SearchObject, } from "./types";
|
|
@@ -1,2 +1,36 @@
|
|
|
1
1
|
import { type FilterBarProps, type SearchBarProps } from "../types";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* This component provides a search input with autocomplete functionality,
|
|
4
|
+
* a button to trigger search, and an optional filter bar.
|
|
5
|
+
* It supports history of search queries, multiple selection, and custom decorations.
|
|
6
|
+
* It can be collapsed to hide filters and has options for customization.
|
|
7
|
+
*
|
|
8
|
+
* @param {SearchBarProps} props - The properties for the SearchBar component.
|
|
9
|
+
* @returns {JSX.Element} The rendered SearchBar component.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```jsx
|
|
13
|
+
* <SearchBar
|
|
14
|
+
* historyKey="myApp:searchHistory"
|
|
15
|
+
* historyCount={10}
|
|
16
|
+
* defaultQueryList={["example", "test"]}
|
|
17
|
+
* prepend={<span>Prepend</span>}
|
|
18
|
+
* append={<span>Append</span>}
|
|
19
|
+
* decorateEnd={<span>End Decoration</span>}
|
|
20
|
+
* decorateStart={<span>Start Decoration</span>}
|
|
21
|
+
* hideFilters={false}
|
|
22
|
+
* defaultCollapsed={false}
|
|
23
|
+
* disabled={false}
|
|
24
|
+
* onCollapsed={(collapsed) => console.log("Collapsed:", collapsed)}
|
|
25
|
+
* onQuery={(query) => console.log("Query:", query)}
|
|
26
|
+
* onSearch={({ query, filters }) => console.log("Search:", query, filters)}
|
|
27
|
+
* query={""}
|
|
28
|
+
* ref={searchInputRef}
|
|
29
|
+
* multiple={false}
|
|
30
|
+
* filters={[{ name: "filter1", value: "value1" }]}
|
|
31
|
+
* />
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
35
|
+
*/
|
|
36
|
+
export declare const SearchBar: ({ historyKey, historyCount, defaultQueryList, prepend, append, decorateEnd, decorateStart, children, hideFilters, defaultCollapsed, disabled, onCollapsed, onQuery, onSearch, query, ref, multiple, filters, ...filterProps }: SearchBarProps & Omit<FilterBarProps, "onFilterChanged">) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
|
-
import { type ChildrenProp } from "@react-fabric/core/dist/types/types";
|
|
1
|
+
import { type ChildrenProp, type RefProp } from "@react-fabric/core/dist/types/types";
|
|
2
2
|
import { type ReactElement } from "react";
|
|
3
3
|
export declare enum FIELD_TYPE {
|
|
4
4
|
ID = "ID",
|
|
5
5
|
STRING = "STRING",
|
|
6
|
+
TEXT = "TEXT",
|
|
6
7
|
NUMBER = "NUMBER",
|
|
7
8
|
DECIMAL = "DECIMAL",
|
|
8
9
|
BOOLEAN = "BOOLEAN",
|
|
10
|
+
DATE = "DATE",
|
|
11
|
+
DATETIME = "DATETIME",
|
|
9
12
|
NONE = "NONE"
|
|
10
13
|
}
|
|
11
14
|
export declare enum OPERATOR {
|
|
12
15
|
EXISTS = "EXISTS",
|
|
13
16
|
IS = "IS",
|
|
14
|
-
|
|
17
|
+
ALL = "ALL",
|
|
18
|
+
ANY = "ANY",
|
|
19
|
+
EQ = "EQ",
|
|
15
20
|
LT = "LT",
|
|
16
21
|
GT = "GT",
|
|
17
22
|
LTE = "LTE",
|
|
18
23
|
GTE = "GTE",
|
|
19
|
-
|
|
24
|
+
LIKE = "LIKE",
|
|
20
25
|
STARTS = "STARTS",
|
|
21
26
|
ENDS = "ENDS",
|
|
22
27
|
WITHIN = "WITHIN",
|
|
@@ -30,6 +35,9 @@ export declare const TypeOperators: {
|
|
|
30
35
|
};
|
|
31
36
|
/**
|
|
32
37
|
* @internal
|
|
38
|
+
* 0 single value
|
|
39
|
+
* 1 many values
|
|
40
|
+
* 2 two values
|
|
33
41
|
*/
|
|
34
42
|
export declare const OperatorValueType: {
|
|
35
43
|
[key in OPERATOR]: 0 | 1 | 2;
|
|
@@ -46,25 +54,25 @@ interface BaseFilter {
|
|
|
46
54
|
color?: string;
|
|
47
55
|
value?: FilterValue;
|
|
48
56
|
pinned?: boolean;
|
|
49
|
-
negate?: boolean;
|
|
50
57
|
disabled?: boolean;
|
|
51
58
|
required?: boolean;
|
|
52
59
|
canPin?: boolean;
|
|
53
60
|
canEdit?: boolean;
|
|
54
|
-
canInvert?: boolean;
|
|
55
61
|
canDisable?: boolean;
|
|
56
62
|
}
|
|
57
63
|
export type FilterObject = BaseFilter & ({
|
|
58
64
|
field: string;
|
|
59
|
-
type?: FIELD_TYPE;
|
|
60
65
|
operator: OPERATOR;
|
|
61
66
|
value?: FilterValue;
|
|
67
|
+
negate?: boolean;
|
|
68
|
+
canInvert?: boolean;
|
|
62
69
|
query?: never;
|
|
70
|
+
type?: string;
|
|
63
71
|
} | {
|
|
64
72
|
field?: never;
|
|
65
|
-
type?: never;
|
|
66
73
|
operator?: never;
|
|
67
74
|
label: string;
|
|
75
|
+
canInvert?: false;
|
|
68
76
|
query: string;
|
|
69
77
|
});
|
|
70
78
|
export interface SearchObject<T = string> {
|
|
@@ -84,7 +92,7 @@ export interface FilterField {
|
|
|
84
92
|
defaultOperator?: OPERATOR;
|
|
85
93
|
onSearch?: (q: string) => Promise<FieldValue[]> | FieldValue[];
|
|
86
94
|
}
|
|
87
|
-
interface BaseSearchBarProps extends Partial<ChildrenProp> {
|
|
95
|
+
interface BaseSearchBarProps extends Partial<ChildrenProp>, RefProp<HTMLInputElement> {
|
|
88
96
|
/**
|
|
89
97
|
* Query string
|
|
90
98
|
*/
|
|
@@ -174,11 +182,11 @@ export interface FilterBarProps {
|
|
|
174
182
|
/**
|
|
175
183
|
* Editable filters
|
|
176
184
|
*/
|
|
177
|
-
|
|
185
|
+
editable?: boolean;
|
|
178
186
|
/**
|
|
179
187
|
* Disable component
|
|
180
188
|
*/
|
|
181
|
-
|
|
189
|
+
disabled?: boolean;
|
|
182
190
|
/**
|
|
183
191
|
* Message for empty field list
|
|
184
192
|
*/
|
|
@@ -192,6 +200,7 @@ export interface FilterBarProps {
|
|
|
192
200
|
*/
|
|
193
201
|
excludedColor?: string;
|
|
194
202
|
allowAdd?: boolean;
|
|
203
|
+
queryLanguage?: "text" | "json";
|
|
195
204
|
querySchema?: Array<{
|
|
196
205
|
uri: string;
|
|
197
206
|
schema: KeyValue;
|
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.60",
|
|
4
4
|
"description": "RUF: Searchbar with filters package",
|
|
5
5
|
"author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,24 +33,26 @@
|
|
|
33
33
|
"watch": "npm-run-all -p watch:rollup watch:dts"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@floating-ui/react": "0.
|
|
37
|
-
"@react-fabric/core": "^1.0.0-beta.
|
|
38
|
-
"@react-fabric/
|
|
39
|
-
"@react-fabric/
|
|
40
|
-
"@react-fabric/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"react-hook-form": "^7.52.1"
|
|
36
|
+
"@floating-ui/react": "~0.27.16",
|
|
37
|
+
"@react-fabric/core": "^1.0.0-beta.60",
|
|
38
|
+
"@react-fabric/form": "^1.0.0-beta.60",
|
|
39
|
+
"@react-fabric/monaco": "^1.0.0-beta.60",
|
|
40
|
+
"@react-fabric/utilities": "^1.0.0-beta.60",
|
|
41
|
+
"classnames": "~2.5.1",
|
|
42
|
+
"react-hook-form": "~7.65.0"
|
|
44
43
|
},
|
|
45
44
|
"peerDependencies": {
|
|
46
|
-
"i18next": "
|
|
47
|
-
"react": "
|
|
48
|
-
"react-dom": "
|
|
49
|
-
"react-i18next": "
|
|
45
|
+
"i18next": "~25.6.0",
|
|
46
|
+
"react": "~19.2.0",
|
|
47
|
+
"react-dom": "~19.2.0",
|
|
48
|
+
"react-i18next": "~16.2.1"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@react-fabric/superdate": "^1.0.0-beta.60"
|
|
50
52
|
},
|
|
51
53
|
"engines": {
|
|
52
54
|
"node": ">=18.12.0",
|
|
53
55
|
"npm": ">=8.19.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a79f053ee7e13422c06d7d9c35d4f0c2610cdf5d"
|
|
56
58
|
}
|
|
@@ -25,7 +25,10 @@ import { createContext, useContext } from "react";
|
|
|
25
25
|
import { type FilterBarProps } from "../types";
|
|
26
26
|
|
|
27
27
|
export const FilterContext = createContext<
|
|
28
|
-
Pick<
|
|
28
|
+
Pick<
|
|
29
|
+
FilterBarProps,
|
|
30
|
+
"querySchema" | "queryLanguage" | "defaultQuery" | "fields"
|
|
31
|
+
>
|
|
29
32
|
>({});
|
|
30
33
|
|
|
31
34
|
export const useFilterContext = () => useContext(FilterContext);
|
|
@@ -39,11 +39,39 @@ import { FilterTag } from "./FilterTag";
|
|
|
39
39
|
import classNames from "classnames";
|
|
40
40
|
import { FilterContext } from "./Context";
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* FilterBar component allows users to manage a list of filters.
|
|
44
|
+
* It provides options to add, remove, and modify filters,
|
|
45
|
+
* as well as to enable or disable all filters at once.
|
|
46
|
+
* It also supports toggling between included and excluded filters.
|
|
47
|
+
*
|
|
48
|
+
* @param {FilterBarProps} props - The properties for the FilterBar component.
|
|
49
|
+
* @returns {JSX.Element} The rendered FilterBar component.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```jsx
|
|
53
|
+
* <FilterBar
|
|
54
|
+
* filters={filters}
|
|
55
|
+
* allowAdd={true}
|
|
56
|
+
* fields={fields}
|
|
57
|
+
* editable={true}
|
|
58
|
+
* querySchema={querySchema}
|
|
59
|
+
* queryLanguage="lucene"
|
|
60
|
+
* defaultQuery="*"
|
|
61
|
+
* includedColor="green"
|
|
62
|
+
* excludedColor="red"
|
|
63
|
+
* onFilterChanged={(newFilters) => console.log(newFilters)}
|
|
64
|
+
* />
|
|
65
|
+
* ```
|
|
66
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/searchbar-searchbar--search-bar} for more details on the properties.
|
|
67
|
+
*/
|
|
42
68
|
export const FilterBar = ({
|
|
43
69
|
filters = [],
|
|
44
70
|
allowAdd,
|
|
45
71
|
fields,
|
|
72
|
+
editable,
|
|
46
73
|
querySchema,
|
|
74
|
+
queryLanguage,
|
|
47
75
|
defaultQuery,
|
|
48
76
|
includedColor,
|
|
49
77
|
excludedColor,
|
|
@@ -88,9 +116,10 @@ export const FilterBar = ({
|
|
|
88
116
|
if (type === "disableAll") filter.disabled = true;
|
|
89
117
|
if (type === "enableAll") filter.disabled = false;
|
|
90
118
|
if (type === "toggleDisable") filter.disabled = !filter.disabled;
|
|
91
|
-
if (type === "excludeAll") filter.negate = true;
|
|
92
|
-
if (type === "includeAll") filter.negate = false;
|
|
93
|
-
if (type === "invertAll"
|
|
119
|
+
if (type === "excludeAll" && filter.field) filter.negate = true;
|
|
120
|
+
if (type === "includeAll" && filter.field) filter.negate = false;
|
|
121
|
+
if (type === "invertAll" && filter.field)
|
|
122
|
+
filter.negate = !filter.negate;
|
|
94
123
|
return { ...filter };
|
|
95
124
|
}),
|
|
96
125
|
);
|
|
@@ -113,9 +142,19 @@ export const FilterBar = ({
|
|
|
113
142
|
key.someDisabled = true;
|
|
114
143
|
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled)
|
|
115
144
|
key.someEnabled = true;
|
|
116
|
-
if (
|
|
145
|
+
if (
|
|
146
|
+
filter.field &&
|
|
147
|
+
filter.negate &&
|
|
148
|
+
filter.canInvert !== false &&
|
|
149
|
+
!key.someExcluded
|
|
150
|
+
)
|
|
117
151
|
key.someExcluded = true;
|
|
118
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
filter.field &&
|
|
154
|
+
!filter.negate &&
|
|
155
|
+
filter.canInvert !== false &&
|
|
156
|
+
!key.someIncluded
|
|
157
|
+
)
|
|
119
158
|
key.someIncluded = true;
|
|
120
159
|
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
121
160
|
});
|
|
@@ -123,7 +162,9 @@ export const FilterBar = ({
|
|
|
123
162
|
}, [filters]);
|
|
124
163
|
|
|
125
164
|
return (
|
|
126
|
-
<FilterContext.Provider
|
|
165
|
+
<FilterContext.Provider
|
|
166
|
+
value={{ defaultQuery, querySchema, queryLanguage, fields }}
|
|
167
|
+
>
|
|
127
168
|
<div className="flex flex-wrap gap-1 items-center">
|
|
128
169
|
<Dropdown showArrow disabled={isEmpty(filters)}>
|
|
129
170
|
<Icon
|
|
@@ -171,6 +212,7 @@ export const FilterBar = ({
|
|
|
171
212
|
<FilterTag
|
|
172
213
|
key={idx}
|
|
173
214
|
filter={filter}
|
|
215
|
+
editable={editable}
|
|
174
216
|
includedColor={includedColor}
|
|
175
217
|
excludedColor={excludedColor}
|
|
176
218
|
onRemove={() => handleRemove(idx)}
|
|
@@ -181,7 +223,7 @@ export const FilterBar = ({
|
|
|
181
223
|
<Dropdown showArrow>
|
|
182
224
|
<Chip
|
|
183
225
|
size="sm"
|
|
184
|
-
className="
|
|
226
|
+
className="outline-dashed! outline-tint-400!"
|
|
185
227
|
icon={CoreIcons.insert}
|
|
186
228
|
>
|
|
187
229
|
{t("label.add")}
|