@react-fabric/searchbar 1.0.0-beta.7 → 1.0.0-beta.8

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.
@@ -81,6 +81,7 @@ var FilterTag = function FilterTag(_ref) {
81
81
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
82
82
  className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
83
83
  children: [filter.pinned && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
84
+ className: "flex-content",
84
85
  icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : core.CoreIcons.pin
85
86
  }), label]
86
87
  })
@@ -31,8 +31,8 @@ var SearchBar = function SearchBar(_ref) {
31
31
  defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
32
32
  _ref.disabled;
33
33
  _ref.onCollapsed;
34
- var onQuery = _ref.onQuery,
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 = react.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
+ react.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 = utilities.isArray(value) ? value : [value];
93
106
  setHistory(utilities.dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
@@ -131,7 +144,6 @@ var SearchBar = function SearchBar(_ref) {
131
144
  });
132
145
  },
133
146
  onSelect: updateHistory,
134
- onQuery: onQuery,
135
147
  "data-testid": "searchbar-input",
136
148
  onEnterPressed: function onEnterPressed() {
137
149
  return fireSearch(state.query, state.filters);
@@ -81,6 +81,7 @@ var FilterTag = function FilterTag(_ref) {
81
81
  children: /*#__PURE__*/jsxs("div", {
82
82
  className: classNames("flex gap-1 items-center", filter.disabled && "line-through opacity-65"),
83
83
  children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
84
+ className: "flex-content",
84
85
  icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
85
86
  }), label]
86
87
  })
@@ -7,7 +7,7 @@ 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';
@@ -31,8 +31,8 @@ var SearchBar = function SearchBar(_ref) {
31
31
  defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
32
32
  _ref.disabled;
33
33
  _ref.onCollapsed;
34
- var onQuery = _ref.onQuery,
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,6 @@ var SearchBar = function SearchBar(_ref) {
131
144
  });
132
145
  },
133
146
  onSelect: updateHistory,
134
- onQuery: onQuery,
135
147
  "data-testid": "searchbar-input",
136
148
  onEnterPressed: function onEnterPressed() {
137
149
  return fireSearch(state.query, state.filters);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/searchbar",
3
- "version": "1.0.0-beta.7",
3
+ "version": "1.0.0-beta.8",
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.7",
38
- "@react-fabric/date": "^1.0.0-beta.7",
39
- "@react-fabric/form": "^1.0.0-beta.7",
40
- "@react-fabric/monaco": "^1.0.0-beta.7",
41
- "@react-fabric/utilities": "^1.0.0-beta.7",
37
+ "@react-fabric/core": "^1.0.0-beta.8",
38
+ "@react-fabric/date": "^1.0.0-beta.8",
39
+ "@react-fabric/form": "^1.0.0-beta.8",
40
+ "@react-fabric/monaco": "^1.0.0-beta.8",
41
+ "@react-fabric/utilities": "^1.0.0-beta.8",
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": "8e6efedbbb02660c0b64140aff00e633b891bb85"
55
+ "gitHead": "9f1ede6e9629c9e79121354332cdebabad5878c5"
56
56
  }
@@ -101,7 +101,12 @@ export const FilterTag = ({
101
101
  filter.disabled && "line-through opacity-65",
102
102
  )}
103
103
  >
104
- {filter.pinned && <Icon icon={filter.icon ?? CoreIcons.pin} />}
104
+ {filter.pinned && (
105
+ <Icon
106
+ className="flex-content"
107
+ icon={filter.icon ?? CoreIcons.pin}
108
+ />
109
+ )}
105
110
  {label}
106
111
  </div>
107
112
  </Chip>
@@ -24,7 +24,7 @@
24
24
  import { Button, useDebounce, useLocalStorage } from "@react-fabric/core";
25
25
  import { AutoComplete, Field } from "@react-fabric/form";
26
26
  import { dedupe, EMPTY_ARRAY, isArray } from "@react-fabric/utilities";
27
- import { useMemo, useReducer, useState } from "react";
27
+ import { useEffect, useMemo, useReducer, useState } from "react";
28
28
  import { useTranslation } from "react-i18next";
29
29
  import { FilterBar } from "../filterbar/FilterBar";
30
30
  import {
@@ -40,6 +40,7 @@ interface SearchState {
40
40
  }
41
41
 
42
42
  type SearchActions =
43
+ | { type: "reset"; query: string | string[]; filters: FilterObject[] }
43
44
  | { type: "dirty"; dirty: boolean }
44
45
  | { type: "query"; query: string | string[] }
45
46
  | { type: "filter"; filters: FilterObject[] };
@@ -85,6 +86,9 @@ export const SearchBar = ({
85
86
 
86
87
  const [state, dispatch] = useReducer(
87
88
  (state: SearchState, action: SearchActions) => {
89
+ if (action.type === "reset") {
90
+ return { ...state, query: action.query, filters: action.filters };
91
+ }
88
92
  if (action.type === "dirty") {
89
93
  return { ...state, dirty: action.dirty };
90
94
  }
@@ -105,6 +109,10 @@ export const SearchBar = ({
105
109
  },
106
110
  );
107
111
 
112
+ useEffect(() => {
113
+ dispatch({ type: "reset", filters, query });
114
+ }, [filters, query]);
115
+
108
116
  const updateHistory = (value: string | string[]) => {
109
117
  const historyEntry = isArray(value) ? value : [value];
110
118
  setHistory(dedupe([...historyEntry, ...history]).slice(0, historyCount));
@@ -139,7 +147,6 @@ export const SearchBar = ({
139
147
  decorateStart={decorateStart}
140
148
  onInput={() => dispatch({ type: "dirty", dirty: true })}
141
149
  onSelect={updateHistory}
142
- onQuery={onQuery}
143
150
  data-testid="searchbar-input"
144
151
  onEnterPressed={() => fireSearch(state.query, state.filters)}
145
152
  />