@cloudtower/eagle 490.0.6 → 490.0.7

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.
@@ -0,0 +1,125 @@
1
+ # SearchInput
2
+
3
+ ## 简介
4
+
5
+ 搜索输入框组件,基于 Input 封装,提供防抖搜索、结果导航(上一个/下一个/计数器)和最近搜索历史功能。支持受控和非受控两种模式,宽度默认 276px。
6
+
7
+ ## 何时使用
8
+
9
+ - 表格内搜索高亮匹配结果,需要上下翻页定位
10
+ - 页面全局搜索,需要防抖避免频繁请求
11
+ - 需要保留最近搜索记录的搜索场景
12
+
13
+ 不要使用:
14
+
15
+ - 仅需要简单输入框 --> 请用 `Input`
16
+ - 下拉选择过滤 --> 请用 `Select` 的搜索模式
17
+ - 级联选择中的搜索 --> `Cascader` 已内置 SearchInput
18
+
19
+ ## 基础用法
20
+
21
+ 最简单的搜索框,仅响应输入变化并防抖处理:
22
+
23
+ ```tsx
24
+ import React, { useState } from "react";
25
+ import { SearchInput } from "@cloudtower/eagle";
26
+
27
+ const App = () => {
28
+ const [keyword, setKeyword] = useState("");
29
+
30
+ return (
31
+ <SearchInput
32
+ debounceWait={300}
33
+ onChange={(value) => setKeyword(value)}
34
+ />
35
+ );
36
+ };
37
+ ```
38
+
39
+ ## 常见模式
40
+
41
+ ### 模式一:带结果导航
42
+
43
+ 适用于搜索后需要在匹配结果之间上下翻页的场景(如表格内搜索高亮)。同时提供 `onSearchNext` 和 `onSearchPrev` 后,输入框后缀会显示 "current/total" 计数器和上下翻页按钮。按 Enter 键等同于点击"下一个"。
44
+
45
+ ```tsx
46
+ import React, { useState } from "react";
47
+ import { SearchInput } from "@cloudtower/eagle";
48
+
49
+ const VmTableSearch = () => {
50
+ const [matchedVms, setMatchedVms] = useState<string[]>([]);
51
+
52
+ return (
53
+ <SearchInput
54
+ total={matchedVms.length}
55
+ onChange={(value) => {
56
+ // 根据关键词过滤匹配的虚拟机列表
57
+ const matched = allVms.filter((vm) => vm.name.includes(value));
58
+ setMatchedVms(matched);
59
+ }}
60
+ onSearchNext={(value, current) => {
61
+ // 滚动到第 current 个匹配结果
62
+ scrollToVm(matchedVms[current - 1]);
63
+ }}
64
+ onSearchPrev={(value, current) => {
65
+ scrollToVm(matchedVms[current - 1]);
66
+ }}
67
+ />
68
+ );
69
+ };
70
+ ```
71
+
72
+ ### 模式二:受控模式(外部控制当前索引)
73
+
74
+ 适用于需要从组件外部控制当前高亮索引的场景,例如同步多个搜索结果视图。通过 `current` prop 传入索引值,组件不再内部管理位置状态。
75
+
76
+ ```tsx
77
+ import React, { useState } from "react";
78
+ import { SearchInput, Button } from "@cloudtower/eagle";
79
+
80
+ const App = () => {
81
+ const [value, setValue] = useState("");
82
+ const [current, setCurrent] = useState(1);
83
+ const total = 10;
84
+
85
+ return (
86
+ <div>
87
+ <SearchInput
88
+ value={value}
89
+ current={current}
90
+ total={total}
91
+ debounceWait={0}
92
+ onChange={(v) => setValue(v)}
93
+ onSearchNext={(v, nextCurrent) => setCurrent(nextCurrent)}
94
+ onSearchPrev={(v, prevCurrent) => setCurrent(prevCurrent)}
95
+ />
96
+ <Button onClick={() => setCurrent(1)}>回到第一个</Button>
97
+ </div>
98
+ );
99
+ };
100
+ ```
101
+
102
+ 注意:使用受控模式(传入 `value`)时,需把 `debounceWait` 设置为 0,否则输入时会有卡顿。
103
+
104
+ ### 模式三:最近搜索历史
105
+
106
+ 启用 `enableRecentSearch` 后,搜索记录会通过 localStorage 持久化存储。聚焦空输入框时自动显示最近搜索记录的下拉菜单,点击记录项可直接填入搜索。不同业务场景应使用不同的 `recentSearchLocalStorageKey` 以隔离数据。
107
+
108
+ ```tsx
109
+ import React from "react";
110
+ import { SearchInput } from "@cloudtower/eagle";
111
+
112
+ const App = () => (
113
+ <SearchInput
114
+ enableRecentSearch
115
+ recentSearchLocalStorageKey="host-search"
116
+ maxRecentCount={5}
117
+ onChange={(value) => console.log("搜索:", value)}
118
+ />
119
+ );
120
+ ```
121
+
122
+ ## 相关组件
123
+
124
+ - `Input`:基础输入框,SearchInput 基于它封装
125
+ - `Cascader`:级联选择器,内置了 SearchInput 作为搜索区域
package/docs/llms.txt CHANGED
@@ -44,7 +44,7 @@ npm 包名:@cloudtower/eagle
44
44
  - TimePicker: 时间选择器
45
45
  - Calendar: 日历面板
46
46
  - TimeZoneSelect: 时区选择器,内置全球时区数据
47
- - SearchInput: 搜索输入框,支持高亮匹配数和上下翻页
47
+ - [SearchInput](core/SearchInput/guide.md): 搜索输入框,支持防抖搜索、结果导航(上下翻页/计数器)和最近搜索历史
48
48
  - [TableForm](core/TableForm/guide.md): 表格表单,行内编辑的表格,支持批量填充、多种列类型、增删行、拖拽排序和三种校验模式
49
49
  - Fields: 表单字段集合,包含 Boolean/DateTime/Enum/Float/Int/String/TextArea 等预设字段
50
50
  - CronPlan: 定时计划配置组件,支持按天/周/月设置 cron 表达式
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudtower/eagle",
3
- "version": "490.0.6",
3
+ "version": "490.0.7",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "sync:color": "node tools/fetch-figma-color.js"
28
28
  },
29
29
  "dependencies": {
30
- "@cloudtower/icons-react": "^490.0.6",
31
- "@cloudtower/parrot": "^490.0.6",
30
+ "@cloudtower/icons-react": "^490.0.7",
31
+ "@cloudtower/parrot": "^490.0.7",
32
32
  "@cloudtower/rc-notification": "^4.6.1",
33
33
  "@linaria/core": "^4.2.2",
34
34
  "@linaria/react": "^4.3.0",
@@ -116,5 +116,5 @@
116
116
  "vite": "^4.5.1",
117
117
  "vitest": "^3.1.1"
118
118
  },
119
- "gitHead": "0b7091ede353aa33a96aa92a464f1d1e58997b29"
119
+ "gitHead": "1a6679790080e9e7795cddbdc2eea5411e0d5456"
120
120
  }