@lobehub/ui 1.145.7 → 1.146.1

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.
@@ -1,6 +1,10 @@
1
- /// <reference types="react" />
1
+ import { CSSProperties } from 'react';
2
2
  import { type InputProps } from "../Input";
3
- export interface SearchBarProps extends InputProps {
3
+ export interface SearchBarProps extends Omit<InputProps, 'styles' | 'classNames'> {
4
+ classNames?: {
5
+ input?: string;
6
+ shortKey?: string;
7
+ };
4
8
  defaultValue?: string;
5
9
  /**
6
10
  * @description Whether to enable the shortcut key to focus on the input
@@ -9,16 +13,21 @@ export interface SearchBarProps extends InputProps {
9
13
  enableShortKey?: boolean;
10
14
  loading?: boolean;
11
15
  onInputChange?: (value: string) => void;
16
+ /**
17
+ * @description Whether add spotlight background
18
+ * @default false
19
+ */
20
+ onSearch?: (value: string) => void;
12
21
  /**
13
22
  * @description The shortcut key to focus on the input. Only works if `enableShortKey` is true
14
23
  * @default 'f'
15
24
  */
16
25
  shortKey?: string;
17
- /**
18
- * @description Whether add spotlight background
19
- * @default false
20
- */
21
26
  spotlight?: boolean;
27
+ styles?: {
28
+ input?: CSSProperties;
29
+ shortKey?: CSSProperties;
30
+ };
22
31
  value?: string;
23
32
  }
24
33
  declare const SearchBar: import("react").NamedExoticComponent<SearchBarProps>;
@@ -3,7 +3,7 @@
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
- var _excluded = ["defaultValue", "spotlight", "className", "value", "onInputChange", "placeholder", "enableShortKey", "shortKey", "loading"];
6
+ var _excluded = ["defaultValue", "spotlight", "className", "value", "onInputChange", "placeholder", "enableShortKey", "shortKey", "onSearch", "loading", "style", "onChange", "onBlur", "onPressEnter", "onFocus", "styles", "classNames"];
7
7
  import { LucideLoader2, Search } from 'lucide-react';
8
8
  import { memo, useEffect, useRef, useState } from 'react';
9
9
  import useControlledState from 'use-merge-value';
@@ -24,8 +24,22 @@ var SearchBar = /*#__PURE__*/memo(function (_ref) {
24
24
  enableShortKey = _ref.enableShortKey,
25
25
  _ref$shortKey = _ref.shortKey,
26
26
  shortKey = _ref$shortKey === void 0 ? 'f' : _ref$shortKey,
27
+ onSearch = _ref.onSearch,
27
28
  loading = _ref.loading,
28
- properties = _objectWithoutProperties(_ref, _excluded);
29
+ style = _ref.style,
30
+ _onChange = _ref.onChange,
31
+ _onBlur = _ref.onBlur,
32
+ _onPressEnter = _ref.onPressEnter,
33
+ _onFocus = _ref.onFocus,
34
+ _ref$styles = _ref.styles,
35
+ _ref$styles2 = _ref$styles === void 0 ? {} : _ref$styles,
36
+ inputStyle = _ref$styles2.input,
37
+ shortKeyStyle = _ref$styles2.shortKey,
38
+ _ref$classNames = _ref.classNames,
39
+ _ref$classNames2 = _ref$classNames === void 0 ? {} : _ref$classNames,
40
+ inputClassName = _ref$classNames2.input,
41
+ shortKeyClassName = _ref$classNames2.shortKey,
42
+ rest = _objectWithoutProperties(_ref, _excluded);
29
43
  var _useControlledState = useControlledState(defaultValue, {
30
44
  defaultValue: defaultValue,
31
45
  onChange: onInputChange,
@@ -67,18 +81,34 @@ var SearchBar = /*#__PURE__*/memo(function (_ref) {
67
81
  }, []);
68
82
  return /*#__PURE__*/_jsxs("div", {
69
83
  className: cx(styles.search, className),
84
+ style: style,
70
85
  children: [spotlight && /*#__PURE__*/_jsx(Spotlight, {}), /*#__PURE__*/_jsx(Input, _objectSpread({
71
86
  allowClear: true,
72
- className: styles.input,
73
- onBlur: function onBlur() {
74
- return setShowTag(true);
87
+ className: cx(styles.input, inputClassName),
88
+ onBlur: function onBlur(e) {
89
+ _onBlur === null || _onBlur === void 0 || _onBlur(e);
90
+ setInputValue(e.target.value);
91
+ if (!e.target.value) {
92
+ setShowTag(true);
93
+ }
75
94
  },
76
95
  onChange: function onChange(e) {
96
+ _onChange === null || _onChange === void 0 || _onChange(e);
77
97
  setInputValue(e.target.value);
78
- setShowTag(!e.target.value);
98
+ if (e.target.value) {
99
+ setShowTag(false);
100
+ } else {
101
+ setShowTag(true);
102
+ onSearch === null || onSearch === void 0 || onSearch(e.target.value);
103
+ }
104
+ },
105
+ onFocus: function onFocus(e) {
106
+ _onFocus === null || _onFocus === void 0 || _onFocus(e);
107
+ setShowTag(false);
79
108
  },
80
- onFocus: function onFocus() {
81
- return setShowTag(false);
109
+ onPressEnter: function onPressEnter(e) {
110
+ _onPressEnter === null || _onPressEnter === void 0 || _onPressEnter(e);
111
+ onSearch === null || onSearch === void 0 || onSearch(inputValue);
82
112
  },
83
113
  placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : 'Type keywords...',
84
114
  prefix: /*#__PURE__*/_jsx(Icon, {
@@ -91,9 +121,11 @@ var SearchBar = /*#__PURE__*/memo(function (_ref) {
91
121
  }
92
122
  }),
93
123
  ref: inputReference,
124
+ style: inputStyle,
94
125
  value: value
95
- }, properties)), enableShortKey && showTag && !inputValue && /*#__PURE__*/_jsxs(Tag, {
96
- className: styles.tag,
126
+ }, rest)), enableShortKey && showTag && !inputValue && /*#__PURE__*/_jsxs(Tag, {
127
+ className: cx(styles.tag, shortKeyClassName),
128
+ style: shortKeyStyle,
97
129
  children: [symbol, " ", shortKey.toUpperCase()]
98
130
  })]
99
131
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.145.7",
3
+ "version": "1.146.1",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",