@hsu-react/ui 0.0.9 → 0.0.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.
Files changed (88) hide show
  1. package/README.md +2 -2
  2. package/es/components/FormItem/ItemContainer/index.d.ts +2 -0
  3. package/es/components/FormItem/ItemContainer/index.js +4 -15
  4. package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
  5. package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
  6. package/es/components/Search/SearchAdvanced/index.js +26 -148
  7. package/es/components/Search/SearchCard/index.js +1 -1
  8. package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
  9. package/es/components/Search/SearchCollapsible/index.js +17 -138
  10. package/es/components/Search/SearchWithFilter/index.js +4 -143
  11. package/es/components/Search/SearchWithMore/index.js +11 -142
  12. package/es/components/Search/_components/FilterDropdown/index.js +5 -6
  13. package/es/components/Search/_components/SearchBase/index.d.ts +32 -0
  14. package/es/components/Search/_components/SearchBase/index.js +185 -0
  15. package/es/components/Search/_hooks/useSearchCommon.js +5 -11
  16. package/es/components/Search/_hooks/useSearchExpand.js +4 -13
  17. package/es/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +3 -10
  18. package/es/components/Search/_utils/calculateVisibleItems.js +4 -5
  19. package/es/components/Search/_utils/index.d.ts +2 -0
  20. package/es/components/Search/_utils/index.js +3 -1
  21. package/es/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
  22. package/es/components/Search/_utils/measureButtonGroupWidth.js +18 -0
  23. package/es/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
  24. package/es/components/Search/_utils/shouldDisplayExtraItem.js +13 -0
  25. package/es/components/Search/index.d.ts +4 -0
  26. package/es/components/Search/index.js +6 -133
  27. package/es/components/Table/_hooks/useEllipsisTooltip.js +4 -2
  28. package/es/components/Table/_hooks/useTableColumns.d.ts +1 -0
  29. package/es/components/Table/_hooks/useTableColumns.js +35 -2
  30. package/es/components/Table/index.js +2 -1
  31. package/es/components/TextEllipsis/index.js +32 -14
  32. package/lib/components/FormItem/ItemContainer/index.d.ts +2 -0
  33. package/lib/components/FormItem/ItemContainer/index.js +2 -5
  34. package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
  35. package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
  36. package/lib/components/Search/SearchAdvanced/index.js +19 -134
  37. package/lib/components/Search/SearchCard/index.js +1 -1
  38. package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
  39. package/lib/components/Search/SearchCollapsible/index.js +12 -124
  40. package/lib/components/Search/SearchWithFilter/index.js +5 -129
  41. package/lib/components/Search/SearchWithMore/index.js +7 -126
  42. package/lib/components/Search/_components/FilterDropdown/index.js +5 -6
  43. package/lib/components/Search/_components/SearchBase/index.d.ts +32 -0
  44. package/lib/components/Search/_components/SearchBase/index.js +169 -0
  45. package/lib/components/Search/_hooks/useSearchCommon.js +4 -6
  46. package/lib/components/Search/_hooks/useSearchExpand.js +2 -13
  47. package/lib/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +2 -10
  48. package/lib/components/Search/_utils/calculateVisibleItems.js +3 -5
  49. package/lib/components/Search/_utils/index.d.ts +2 -0
  50. package/lib/components/Search/_utils/index.js +15 -1
  51. package/lib/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
  52. package/lib/components/Search/_utils/measureButtonGroupWidth.js +24 -0
  53. package/lib/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
  54. package/lib/components/Search/_utils/shouldDisplayExtraItem.js +19 -0
  55. package/lib/components/Search/index.d.ts +4 -0
  56. package/lib/components/Search/index.js +8 -119
  57. package/lib/components/Table/_hooks/useEllipsisTooltip.js +3 -1
  58. package/lib/components/Table/_hooks/useTableColumns.d.ts +1 -0
  59. package/lib/components/Table/_hooks/useTableColumns.js +31 -2
  60. package/lib/components/Table/index.js +2 -1
  61. package/lib/components/TextEllipsis/index.js +27 -14
  62. package/package.json +1 -1
  63. package/src/components/FormItem/ItemContainer/index.tsx +4 -7
  64. package/src/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.tsx +6 -6
  65. package/src/components/Search/SearchAdvanced/index.tsx +25 -164
  66. package/src/components/Search/SearchCard/index.tsx +1 -1
  67. package/src/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.tsx +2 -2
  68. package/src/components/Search/SearchCollapsible/index.tsx +13 -162
  69. package/src/components/Search/SearchWithFilter/index.tsx +2 -164
  70. package/src/components/Search/SearchWithMore/index.tsx +9 -161
  71. package/src/components/Search/_components/FilterDropdown/index.tsx +5 -6
  72. package/src/components/Search/_components/SearchBase/index.tsx +224 -0
  73. package/src/components/Search/_hooks/useSearchCommon.ts +10 -13
  74. package/src/components/Search/_hooks/useSearchExpand.ts +3 -13
  75. package/src/components/Search/_utils/calculateButtonGroupAndColumnWidth.ts +2 -10
  76. package/src/components/Search/_utils/calculateVisibleItems.ts +10 -11
  77. package/src/components/Search/_utils/index.ts +2 -0
  78. package/src/components/Search/_utils/measureButtonGroupWidth.ts +23 -0
  79. package/src/components/Search/_utils/shouldDisplayExtraItem.ts +23 -0
  80. package/src/components/Search/index.tsx +7 -153
  81. package/src/components/Table/_hooks/useEllipsisTooltip.ts +2 -4
  82. package/src/components/Table/_hooks/useTableColumns.tsx +41 -1
  83. package/src/components/Table/index.md +2 -0
  84. package/src/components/Table/index.tsx +1 -0
  85. package/src/components/TextEllipsis/index.md +1 -1
  86. package/src/components/TextEllipsis/index.tsx +33 -18
  87. /package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
  88. /package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
@@ -1,15 +1,6 @@
1
1
  import React from "react";
2
- import { Form as AntdForm } from "antd";
3
- import FormItem from "../../FormItem";
4
- import { CSSProperties } from "react";
5
- import classNames from "classnames";
6
- import styles from "../index.module.scss";
7
- import { useSearchCommon } from "../_hooks";
2
+ import SearchBase from "../_components/SearchBase";
8
3
  import { ChakraButtonProps } from "../../Button";
9
- import { ButtonGroup } from "../_components/ButtonGroup";
10
- import { SearchButtons } from "../_components/SearchButtons";
11
- import { FilterDropdown } from "../_components/FilterDropdown";
12
- import { ExpandButton } from "../_components/ExpandButton";
13
4
  import { SearchPropsWithFilter } from "../_types";
14
5
 
15
6
  export interface SearchWithFilterProps extends SearchPropsWithFilter {
@@ -24,160 +15,7 @@ export interface SearchWithFilterProps extends SearchPropsWithFilter {
24
15
  * - 提供更灵活的搜索体验
25
16
  */
26
17
  const SearchWithFilter: React.FC<SearchWithFilterProps> = (props) => {
27
- const {
28
- searchItems = [],
29
- moreSearchItems = [],
30
- className,
31
- onSearch,
32
- onReset,
33
- externalForm,
34
- hasPermi,
35
- columnNum = 4,
36
- beforeButtonGroup,
37
- affterButtonGroup,
38
- searchData,
39
- minLabelWidth,
40
- defaultExpanded = false,
41
- onExpandChange,
42
- autoAdaptWidth = true,
43
- baseWidth,
44
- onValuesChange,
45
- searchDisabled = false,
46
- showAllSearchItems = false,
47
- searchText,
48
- resetText,
49
- onFilterChange,
50
- columnOffsetWidth = 0,
51
- } = props;
52
-
53
- const [form] = AntdForm.useForm(externalForm);
54
-
55
- const {
56
- containerRef,
57
- buttonGroupRef,
58
- cls,
59
- getLabelWidth,
60
- processedSearchItems,
61
- setSearchItems,
62
- currentSearchItems,
63
- totalColumnNum,
64
- expand,
65
- toggleExpand,
66
- showExpandButton,
67
- onSearchClick,
68
- onResetClick,
69
- shouldRender,
70
- permitted,
71
- } = useSearchCommon({
72
- form,
73
- searchItems,
74
- moreSearchItems,
75
- searchData,
76
- hasPermi,
77
- beforeButtonGroup,
78
- affterButtonGroup,
79
- columnNum,
80
- autoAdaptWidth,
81
- defaultExpanded,
82
- onExpandChange,
83
- showAllSearchItems,
84
- minLabelWidth,
85
- baseWidth,
86
- onSearch,
87
- onReset,
88
- columnOffsetWidth,
89
- });
90
-
91
- if (!shouldRender) {
92
- return null;
93
- }
94
-
95
- return (
96
- <div
97
- ref={containerRef}
98
- className={classNames(styles.Search, className)}
99
- style={
100
- {
101
- "--column-number": totalColumnNum,
102
- "--column-offset-width": `${columnOffsetWidth}px`,
103
- } as CSSProperties
104
- }
105
- >
106
- <div
107
- className={classNames(styles.searchOption, styles[expand.toString()])}
108
- >
109
- <AntdForm
110
- form={form}
111
- className={classNames(styles.option, cls)}
112
- onValuesChange={onValuesChange}
113
- >
114
- {permitted &&
115
- currentSearchItems?.map((item, idx) => {
116
- // 计算同一列的项(用于计算标签宽度)
117
- const visibleCurrentItems = currentSearchItems.filter(
118
- (i) => i.visible !== false
119
- );
120
- const columnIndex = idx % totalColumnNum;
121
- const sameColumnItems = visibleCurrentItems.filter(
122
- (_, _idx) => _idx % totalColumnNum === columnIndex
123
- );
124
-
125
- return (
126
- <FormItem
127
- {...item}
128
- key={item.name}
129
- className={classNames(styles.item, item.className, {
130
- [styles.unFill]: item.width !== undefined,
131
- })}
132
- labelWidth={
133
- item.width !== undefined
134
- ? undefined
135
- : getLabelWidth(sameColumnItems, undefined, minLabelWidth)
136
- }
137
- />
138
- );
139
- })}
140
- {(beforeButtonGroup?.length ||
141
- affterButtonGroup?.length ||
142
- permitted) && (
143
- <ButtonGroup
144
- beforeButtonGroup={beforeButtonGroup}
145
- affterButtonGroup={affterButtonGroup}
146
- expandButton={
147
- <ExpandButton
148
- expand={expand}
149
- toggleExpand={toggleExpand}
150
- advancedFilters={false}
151
- showExpandButton={showExpandButton}
152
- showAllSearchItems={
153
- showAllSearchItems || !!moreSearchItems?.length
154
- }
155
- />
156
- }
157
- permitted={permitted}
158
- ref={buttonGroupRef}
159
- >
160
- {currentSearchItems.length > 0 && (
161
- <SearchButtons
162
- onSearch={onSearchClick}
163
- onReset={onResetClick}
164
- searchDisabled={searchDisabled}
165
- searchText={searchText}
166
- resetText={resetText}
167
- />
168
- )}
169
- <FilterDropdown
170
- searchItems={processedSearchItems}
171
- originalSearchItems={searchItems}
172
- setSearchItems={setSearchItems}
173
- onFilterChange={onFilterChange}
174
- />
175
- </ButtonGroup>
176
- )}
177
- </AntdForm>
178
- </div>
179
- </div>
180
- );
18
+ return <SearchBase {...props} showFilter />;
181
19
  };
182
20
 
183
21
  export default SearchWithFilter;
@@ -1,15 +1,7 @@
1
1
  import React from "react";
2
- import { Form as AntdForm } from "antd";
3
- import FormItem, { FormItemProps } from "../../FormItem";
4
- import { CSSProperties } from "react";
5
- import classNames from "classnames";
6
- import styles from "../index.module.scss";
7
- import { useSearchCommon } from "../_hooks";
2
+ import { FormItemProps } from "../../FormItem";
3
+ import SearchBase from "../_components/SearchBase";
8
4
  import { ChakraButtonProps } from "../../Button";
9
- import { ButtonGroup } from "../_components/ButtonGroup";
10
- import { SearchButtons } from "../_components/SearchButtons";
11
- import { FilterDropdown } from "../_components/FilterDropdown";
12
- import { ExpandButton } from "../_components/ExpandButton";
13
5
  import { SearchPropsWithFilter } from "../_types";
14
6
 
15
7
  export interface SearchWithMoreProps
@@ -26,159 +18,15 @@ export interface SearchWithMoreProps
26
18
  * - 适合有大量搜索字段的场景
27
19
  */
28
20
  const SearchWithMore: React.FC<SearchWithMoreProps> = (props) => {
29
- const {
30
- searchItems = [],
31
- moreSearchItems,
32
- className,
33
- onSearch,
34
- onReset,
35
- externalForm,
36
- hasPermi,
37
- columnNum = 4,
38
- beforeButtonGroup,
39
- affterButtonGroup,
40
- searchData,
41
- setFilter,
42
- minLabelWidth,
43
- defaultExpanded = false,
44
- onExpandChange,
45
- autoAdaptWidth = true,
46
- baseWidth,
47
- onValuesChange,
48
- searchDisabled = false,
49
- searchText,
50
- resetText,
51
- onFilterChange,
52
- columnOffsetWidth = 0,
53
- } = props;
54
-
55
- const [form] = AntdForm.useForm(externalForm);
56
-
57
- const {
58
- containerRef,
59
- buttonGroupRef,
60
- cls,
61
- getLabelWidth,
62
- processedSearchItems,
63
- setSearchItems,
64
- currentSearchItems,
65
- totalColumnNum,
66
- expand,
67
- toggleExpand,
68
- showExpandButton,
69
- onSearchClick,
70
- onResetClick,
71
- shouldRender,
72
- permitted,
73
- } = useSearchCommon({
74
- form,
75
- searchItems,
76
- moreSearchItems,
77
- searchData,
78
- hasPermi,
79
- beforeButtonGroup,
80
- affterButtonGroup,
81
- columnNum,
82
- autoAdaptWidth,
83
- defaultExpanded,
84
- onExpandChange,
85
- showAllSearchItems: true, // SearchWithMore 始终显示所有搜索项
86
- minLabelWidth,
87
- baseWidth,
88
- onSearch,
89
- onReset,
90
- columnOffsetWidth,
91
- });
92
-
93
- if (!shouldRender) {
94
- return null;
95
- }
21
+ const { setFilter, ...rest } = props;
96
22
 
97
23
  return (
98
- <div
99
- ref={containerRef}
100
- className={classNames(styles.Search, className)}
101
- style={
102
- {
103
- "--column-number": totalColumnNum,
104
- "--column-offset-width": `${columnOffsetWidth}px`,
105
- } as CSSProperties
106
- }
107
- >
108
- <div
109
- className={classNames(styles.searchOption, styles[expand.toString()])}
110
- >
111
- <AntdForm
112
- form={form}
113
- className={classNames(styles.option, cls)}
114
- onValuesChange={onValuesChange}
115
- >
116
- {permitted &&
117
- currentSearchItems?.map((item, idx) => {
118
- // 计算同一列的项(用于计算标签宽度)
119
- const visibleCurrentItems = currentSearchItems.filter(
120
- (i) => i.visible !== false
121
- );
122
- const columnIndex = idx % totalColumnNum;
123
- const sameColumnItems = visibleCurrentItems.filter(
124
- (_, _idx) => _idx % totalColumnNum === columnIndex
125
- );
126
-
127
- return (
128
- <FormItem
129
- {...item}
130
- key={item.name}
131
- className={classNames(styles.item, item.className, {
132
- [styles.unFill]: item.width !== undefined,
133
- })}
134
- labelWidth={
135
- item.width !== undefined
136
- ? undefined
137
- : getLabelWidth(sameColumnItems, undefined, minLabelWidth)
138
- }
139
- />
140
- );
141
- })}
142
- {(beforeButtonGroup?.length ||
143
- affterButtonGroup?.length ||
144
- permitted) && (
145
- <ButtonGroup
146
- beforeButtonGroup={beforeButtonGroup}
147
- affterButtonGroup={affterButtonGroup}
148
- expandButton={
149
- <ExpandButton
150
- expand={expand}
151
- toggleExpand={toggleExpand}
152
- advancedFilters={false}
153
- showExpandButton={showExpandButton}
154
- showAllSearchItems={true}
155
- />
156
- }
157
- permitted={permitted}
158
- ref={buttonGroupRef}
159
- >
160
- {currentSearchItems.length > 0 && (
161
- <SearchButtons
162
- onSearch={onSearchClick}
163
- onReset={onResetClick}
164
- searchDisabled={searchDisabled}
165
- searchText={searchText}
166
- resetText={resetText}
167
- />
168
- )}
169
- {setFilter && (
170
- <FilterDropdown
171
- searchItems={processedSearchItems}
172
- originalSearchItems={searchItems}
173
- setSearchItems={setSearchItems}
174
- onFilterChange={onFilterChange}
175
- />
176
- )}
177
- </ButtonGroup>
178
- )}
179
- </AntdForm>
180
- </div>
181
- </div>
24
+ <SearchBase
25
+ {...rest}
26
+ // SearchWithMore 始终显示所有搜索项
27
+ showAllSearchItems
28
+ showFilter={!!setFilter}
29
+ />
182
30
  );
183
31
  };
184
32
 
@@ -22,16 +22,15 @@ export const FilterDropdown: React.FC<FilterDropdownProps> = ({
22
22
  const [open, setOpen] = useState(false);
23
23
 
24
24
  useEffect(() => {
25
- document.addEventListener("click", () => {
25
+ const handleDocumentClick = () => {
26
26
  setOpen(false);
27
- });
27
+ };
28
+ document.addEventListener("click", handleDocumentClick);
28
29
 
29
30
  return () => {
30
- document.removeEventListener("click", () => {
31
- setOpen(false);
32
- });
31
+ document.removeEventListener("click", handleDocumentClick);
33
32
  };
34
- }, [searchItems]);
33
+ }, []);
35
34
 
36
35
  return (
37
36
  <Dropdown
@@ -0,0 +1,224 @@
1
+ import React, { CSSProperties, ReactNode, useMemo } from "react";
2
+ import { Form as AntdForm, FormInstance } from "antd";
3
+ import classNames from "classnames";
4
+ import FormItem, { FormItemProps } from "../../../FormItem";
5
+ import type useLabelWidth from "../../../../hooks/useLabelWidth";
6
+ import styles from "../../index.module.scss";
7
+ import { useSearchCommon } from "../../_hooks";
8
+ import { ButtonGroup } from "../ButtonGroup";
9
+ import { SearchButtons } from "../SearchButtons";
10
+ import { ExpandButton } from "../ExpandButton";
11
+ import { FilterDropdown } from "../FilterDropdown";
12
+ import { SearchPropsWithFilter } from "../../_types";
13
+
14
+ /** 暴露给变体扩展渲染(如高级筛选抽屉)的上下文 */
15
+ export interface SearchBaseContext {
16
+ form: FormInstance;
17
+ expand: boolean;
18
+ setExpand?: (expand: boolean) => void;
19
+ processedSearchItems: FormItemProps[];
20
+ getLabelWidth: ReturnType<typeof useLabelWidth>[1];
21
+ onSearchClick: () => void;
22
+ onResetClick: () => void;
23
+ }
24
+
25
+ export interface SearchBaseProps extends SearchPropsWithFilter {
26
+ /** 高级筛选模式:搜索项不显示 label,展开按钮显示为"高级筛选" */
27
+ advancedFilters?: boolean;
28
+ /** 是否渲染 FilterDropdown(筛选器设置下拉) */
29
+ showFilter?: boolean;
30
+ /** 表单区域之后、容器之内的附加内容(如折叠开关),仅在有权限时渲染 */
31
+ afterForm?: ReactNode;
32
+ /** 容器之外的附加内容(如高级筛选抽屉),仅在有权限时渲染 */
33
+ renderOutside?: (ctx: SearchBaseContext) => ReactNode;
34
+ }
35
+
36
+ /**
37
+ * Search 各变体共享的基础实现:
38
+ * 表单渲染、列布局、展开/收起、按钮组、权限控制。
39
+ * 变体只负责自身差异(筛选器、折叠开关、高级筛选抽屉等)。
40
+ */
41
+ const SearchBase: React.FC<SearchBaseProps> = (props) => {
42
+ const {
43
+ searchItems = [],
44
+ moreSearchItems = [],
45
+ className,
46
+ onSearch,
47
+ onReset,
48
+ externalForm,
49
+ hasPermi,
50
+ columnNum = 4,
51
+ beforeButtonGroup,
52
+ affterButtonGroup,
53
+ searchData,
54
+ minLabelWidth,
55
+ defaultExpanded = false,
56
+ onExpandChange,
57
+ autoAdaptWidth = true,
58
+ baseWidth,
59
+ onValuesChange,
60
+ searchDisabled = false,
61
+ showAllSearchItems = false,
62
+ searchText,
63
+ resetText,
64
+ onFilterChange,
65
+ columnOffsetWidth = 0,
66
+ advancedFilters = false,
67
+ showFilter = false,
68
+ afterForm,
69
+ renderOutside,
70
+ } = props;
71
+
72
+ const [form] = AntdForm.useForm(externalForm);
73
+
74
+ const {
75
+ containerRef,
76
+ buttonGroupRef,
77
+ cls,
78
+ getLabelWidth,
79
+ processedSearchItems,
80
+ setSearchItems,
81
+ currentSearchItems,
82
+ totalColumnNum,
83
+ expand,
84
+ setExpand,
85
+ toggleExpand,
86
+ showExpandButton,
87
+ onSearchClick,
88
+ onResetClick,
89
+ shouldRender,
90
+ permitted,
91
+ } = useSearchCommon({
92
+ form,
93
+ searchItems,
94
+ moreSearchItems,
95
+ searchData,
96
+ hasPermi,
97
+ beforeButtonGroup,
98
+ affterButtonGroup,
99
+ columnNum,
100
+ autoAdaptWidth,
101
+ defaultExpanded,
102
+ onExpandChange,
103
+ showAllSearchItems,
104
+ minLabelWidth,
105
+ baseWidth,
106
+ onSearch,
107
+ onReset,
108
+ columnOffsetWidth,
109
+ });
110
+
111
+ // 按列分组预计算(用于对齐同列 label 宽度),避免在 map 中逐项重复 filter
112
+ const columnGroups = useMemo(() => {
113
+ const groups: FormItemProps[][] = Array.from(
114
+ { length: totalColumnNum },
115
+ () => []
116
+ );
117
+ currentSearchItems.forEach((item, idx) => {
118
+ groups[idx % totalColumnNum].push(item);
119
+ });
120
+ return groups;
121
+ }, [currentSearchItems, totalColumnNum]);
122
+
123
+ if (!shouldRender) {
124
+ return null;
125
+ }
126
+
127
+ return (
128
+ <>
129
+ <div
130
+ ref={containerRef}
131
+ className={classNames(styles.Search, className)}
132
+ style={
133
+ {
134
+ "--column-number": totalColumnNum,
135
+ "--column-offset-width": `${columnOffsetWidth}px`,
136
+ } as CSSProperties
137
+ }
138
+ >
139
+ <div
140
+ className={classNames(styles.searchOption, styles[expand.toString()])}
141
+ >
142
+ <AntdForm
143
+ form={form}
144
+ className={classNames(styles.option, cls)}
145
+ onValuesChange={onValuesChange}
146
+ >
147
+ {permitted &&
148
+ currentSearchItems.map((item, idx) => (
149
+ <FormItem
150
+ {...item}
151
+ key={item.name}
152
+ className={classNames(styles.item, item.className, {
153
+ [styles.unFill]: item.width !== undefined,
154
+ })}
155
+ label={advancedFilters ? undefined : item.label}
156
+ labelWidth={
157
+ advancedFilters || item.width !== undefined
158
+ ? undefined
159
+ : getLabelWidth(
160
+ columnGroups[idx % totalColumnNum],
161
+ undefined,
162
+ minLabelWidth
163
+ )
164
+ }
165
+ />
166
+ ))}
167
+ {(beforeButtonGroup?.length ||
168
+ affterButtonGroup?.length ||
169
+ permitted) && (
170
+ <ButtonGroup
171
+ beforeButtonGroup={beforeButtonGroup}
172
+ affterButtonGroup={affterButtonGroup}
173
+ expandButton={
174
+ <ExpandButton
175
+ expand={expand}
176
+ toggleExpand={toggleExpand}
177
+ advancedFilters={advancedFilters}
178
+ showExpandButton={showExpandButton}
179
+ showAllSearchItems={
180
+ showAllSearchItems || !!moreSearchItems?.length
181
+ }
182
+ />
183
+ }
184
+ permitted={permitted}
185
+ ref={buttonGroupRef}
186
+ >
187
+ {currentSearchItems.length > 0 && (
188
+ <SearchButtons
189
+ onSearch={onSearchClick}
190
+ onReset={onResetClick}
191
+ searchDisabled={searchDisabled}
192
+ searchText={searchText}
193
+ resetText={resetText}
194
+ />
195
+ )}
196
+ {showFilter && (
197
+ <FilterDropdown
198
+ searchItems={processedSearchItems}
199
+ originalSearchItems={searchItems}
200
+ setSearchItems={setSearchItems}
201
+ onFilterChange={onFilterChange}
202
+ />
203
+ )}
204
+ </ButtonGroup>
205
+ )}
206
+ </AntdForm>
207
+ </div>
208
+ {permitted && afterForm}
209
+ </div>
210
+ {permitted &&
211
+ renderOutside?.({
212
+ form,
213
+ expand,
214
+ setExpand,
215
+ processedSearchItems,
216
+ getLabelWidth,
217
+ onSearchClick,
218
+ onResetClick,
219
+ })}
220
+ </>
221
+ );
222
+ };
223
+
224
+ export default SearchBase;
@@ -12,6 +12,7 @@ import {
12
12
  cleanSearchData,
13
13
  calculateVisibleItems,
14
14
  calculateButtonGroupAndColumnWidth,
15
+ shouldDisplayExtraItem,
15
16
  } from "../_utils";
16
17
  import styles from "../index.module.scss";
17
18
  import { ChakraButtonProps } from "../../Button";
@@ -119,12 +120,10 @@ export const useSearchCommon = (
119
120
  }, [moreSearchItems]);
120
121
 
121
122
  // 计算可见的搜索项数量
122
- const visibleSearchItemCount = useMemo(() => {
123
- return visibleSearchItems.length;
124
- }, [visibleSearchItems]);
123
+ const visibleSearchItemCount = visibleSearchItems.length;
125
124
 
126
125
  // 计算总列数(包括按钮组)
127
- const baseTotalColumnNum = useMemo(() => columnNum + 1, [columnNum]);
126
+ const baseTotalColumnNum = columnNum + 1;
128
127
 
129
128
  // 根据容器宽度动态调整列数
130
129
  const totalColumnNum = useAdaptiveColumnNum(
@@ -138,10 +137,7 @@ export const useSearchCommon = (
138
137
  );
139
138
 
140
139
  // 计算调整后的搜索项列数(不包括按钮组)
141
- const adaptiveColumnNum = useMemo(
142
- () => Math.max(1, totalColumnNum - 1),
143
- [totalColumnNum],
144
- );
140
+ const adaptiveColumnNum = Math.max(1, totalColumnNum - 1);
145
141
 
146
142
  // 使用基于宽度的展开/收起控制
147
143
  const { expand, setExpand, toggleExpand, visibleItemCount } = useSearchExpand(
@@ -241,11 +237,12 @@ export const useSearchCommon = (
241
237
 
242
238
  // 判断按钮组宽度是否大于列宽,如果是,则显示 实际搜索项数量+1
243
239
  if (
244
- buttonGroupWidth !== undefined &&
245
- columnWidth !== undefined &&
246
- (buttonGroupWidth > columnWidth ||
247
- (buttonGroupWidth < columnWidth &&
248
- adaptiveColumnNum + 1 === visibleSearchItemCount))
240
+ shouldDisplayExtraItem(
241
+ buttonGroupWidth,
242
+ columnWidth,
243
+ adaptiveColumnNum,
244
+ visibleSearchItemCount,
245
+ )
249
246
  ) {
250
247
  return adaptiveColumnNum + 1;
251
248
  }
@@ -1,5 +1,6 @@
1
1
  import { useState, useEffect, useCallback } from "react";
2
2
  import { FormItemProps } from "../../FormItem";
3
+ import { measureButtonGroupWidth } from "../_utils";
3
4
 
4
5
  /**
5
6
  * 基于宽度自适应控制展开/收起的Hook
@@ -46,19 +47,8 @@ export function useSearchExpand(
46
47
  const availableWidth = containerWidth - 30; // 15px padding on each side
47
48
 
48
49
  // 获取按钮组的实际宽度(计算所有子元素宽度总和)
49
- let buttonGroupWidth = 0;
50
- const buttonChildren = Array.from(buttonGroupRef.current.children);
51
- if (buttonChildren.length > 0) {
52
- // 计算所有子元素的宽度总和
53
- let totalWidth = 0;
54
- buttonChildren?.forEach((child) => {
55
- totalWidth += (child as HTMLElement).offsetWidth;
56
- });
57
- // 加上子元素之间的间距(column-gap: 10px)
58
- const childGap = 5;
59
- totalWidth += (buttonChildren.length - 1) * childGap;
60
- buttonGroupWidth = totalWidth;
61
- }
50
+ const buttonGroupWidth =
51
+ measureButtonGroupWidth(buttonGroupRef.current) ?? 0;
62
52
 
63
53
  // 获取所有搜索项元素
64
54
  const items = container.querySelectorAll(`${itemClassName}`);