@hsu-react/ui 0.0.9 → 0.0.10
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/es/components/FormItem/ItemContainer/index.d.ts +2 -0
- package/es/components/FormItem/ItemContainer/index.js +4 -15
- package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
- package/es/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
- package/es/components/Search/SearchAdvanced/index.js +26 -148
- package/es/components/Search/SearchCard/index.js +1 -1
- package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
- package/es/components/Search/SearchCollapsible/index.js +17 -138
- package/es/components/Search/SearchWithFilter/index.js +4 -143
- package/es/components/Search/SearchWithMore/index.js +11 -142
- package/es/components/Search/_components/FilterDropdown/index.js +5 -6
- package/es/components/Search/_components/SearchBase/index.d.ts +32 -0
- package/es/components/Search/_components/SearchBase/index.js +185 -0
- package/es/components/Search/_hooks/useSearchCommon.js +5 -11
- package/es/components/Search/_hooks/useSearchExpand.js +4 -13
- package/es/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +3 -10
- package/es/components/Search/_utils/calculateVisibleItems.js +4 -5
- package/es/components/Search/_utils/index.d.ts +2 -0
- package/es/components/Search/_utils/index.js +3 -1
- package/es/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
- package/es/components/Search/_utils/measureButtonGroupWidth.js +18 -0
- package/es/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
- package/es/components/Search/_utils/shouldDisplayExtraItem.js +13 -0
- package/es/components/Search/index.d.ts +4 -0
- package/es/components/Search/index.js +6 -133
- package/es/components/Table/_hooks/useTableColumns.js +11 -0
- package/lib/components/FormItem/ItemContainer/index.d.ts +2 -0
- package/lib/components/FormItem/ItemContainer/index.js +2 -5
- package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.d.ts +3 -3
- package/lib/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.js +3 -3
- package/lib/components/Search/SearchAdvanced/index.js +19 -134
- package/lib/components/Search/SearchCard/index.js +1 -1
- package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.js +2 -2
- package/lib/components/Search/SearchCollapsible/index.js +12 -124
- package/lib/components/Search/SearchWithFilter/index.js +5 -129
- package/lib/components/Search/SearchWithMore/index.js +7 -126
- package/lib/components/Search/_components/FilterDropdown/index.js +5 -6
- package/lib/components/Search/_components/SearchBase/index.d.ts +32 -0
- package/lib/components/Search/_components/SearchBase/index.js +169 -0
- package/lib/components/Search/_hooks/useSearchCommon.js +4 -6
- package/lib/components/Search/_hooks/useSearchExpand.js +2 -13
- package/lib/components/Search/_utils/calculateButtonGroupAndColumnWidth.js +2 -10
- package/lib/components/Search/_utils/calculateVisibleItems.js +3 -5
- package/lib/components/Search/_utils/index.d.ts +2 -0
- package/lib/components/Search/_utils/index.js +15 -1
- package/lib/components/Search/_utils/measureButtonGroupWidth.d.ts +6 -0
- package/lib/components/Search/_utils/measureButtonGroupWidth.js +24 -0
- package/lib/components/Search/_utils/shouldDisplayExtraItem.d.ts +11 -0
- package/lib/components/Search/_utils/shouldDisplayExtraItem.js +19 -0
- package/lib/components/Search/index.d.ts +4 -0
- package/lib/components/Search/index.js +8 -119
- package/lib/components/Table/_hooks/useTableColumns.js +11 -0
- package/package.json +1 -1
- package/src/components/FormItem/ItemContainer/index.tsx +4 -7
- package/src/components/Search/{_components → SearchAdvanced/_components}/AdvancedFiltersDrawer/index.tsx +6 -6
- package/src/components/Search/SearchAdvanced/index.tsx +25 -164
- package/src/components/Search/SearchCard/index.tsx +1 -1
- package/src/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.tsx +2 -2
- package/src/components/Search/SearchCollapsible/index.tsx +13 -162
- package/src/components/Search/SearchWithFilter/index.tsx +2 -164
- package/src/components/Search/SearchWithMore/index.tsx +9 -161
- package/src/components/Search/_components/FilterDropdown/index.tsx +5 -6
- package/src/components/Search/_components/SearchBase/index.tsx +224 -0
- package/src/components/Search/_hooks/useSearchCommon.ts +10 -13
- package/src/components/Search/_hooks/useSearchExpand.ts +3 -13
- package/src/components/Search/_utils/calculateButtonGroupAndColumnWidth.ts +2 -10
- package/src/components/Search/_utils/calculateVisibleItems.ts +10 -11
- package/src/components/Search/_utils/index.ts +2 -0
- package/src/components/Search/_utils/measureButtonGroupWidth.ts +23 -0
- package/src/components/Search/_utils/shouldDisplayExtraItem.ts +23 -0
- package/src/components/Search/index.tsx +7 -153
- package/src/components/Table/_hooks/useTableColumns.tsx +17 -0
- /package/es/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
- /package/lib/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.d.ts +0 -0
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { Form as AntdForm } from "antd";
|
|
3
|
-
import FormItem from "../../FormItem";
|
|
4
|
-
import { CSSProperties } from "react";
|
|
5
2
|
import classNames from "classnames";
|
|
6
3
|
import styles from "../index.module.scss";
|
|
7
|
-
import
|
|
4
|
+
import SearchBase from "../_components/SearchBase";
|
|
5
|
+
import { AdvancedFiltersDrawer } from "./_components/AdvancedFiltersDrawer";
|
|
8
6
|
import { ChakraButtonProps } from "../../Button";
|
|
9
7
|
import { DrawerFormProps } from "../../Form/DrawerForm";
|
|
10
|
-
import { ButtonGroup } from "../_components/ButtonGroup";
|
|
11
|
-
import { SearchButtons } from "../_components/SearchButtons";
|
|
12
|
-
import { FilterDropdown } from "../_components/FilterDropdown";
|
|
13
|
-
import { ExpandButton } from "../_components/ExpandButton";
|
|
14
|
-
import { AdvancedFiltersDrawer } from "../_components/AdvancedFiltersDrawer";
|
|
15
8
|
import { SearchPropsWithFilter } from "../_types";
|
|
16
9
|
|
|
17
10
|
export interface SearchAdvancedProps extends SearchPropsWithFilter {
|
|
@@ -28,168 +21,36 @@ export interface SearchAdvancedProps extends SearchPropsWithFilter {
|
|
|
28
21
|
*/
|
|
29
22
|
const SearchAdvanced: React.FC<SearchAdvancedProps> = (props) => {
|
|
30
23
|
const {
|
|
31
|
-
searchItems = [],
|
|
32
|
-
moreSearchItems = [],
|
|
33
24
|
className,
|
|
34
|
-
onSearch,
|
|
35
|
-
onReset,
|
|
36
|
-
externalForm,
|
|
37
|
-
hasPermi,
|
|
38
|
-
columnNum = 4,
|
|
39
|
-
beforeButtonGroup,
|
|
40
|
-
affterButtonGroup,
|
|
41
|
-
searchData,
|
|
42
25
|
advancedFiltersProps,
|
|
43
26
|
setFilter,
|
|
44
27
|
minLabelWidth,
|
|
45
|
-
|
|
46
|
-
onExpandChange,
|
|
47
|
-
autoAdaptWidth = true,
|
|
48
|
-
baseWidth,
|
|
49
|
-
onValuesChange,
|
|
50
|
-
searchDisabled = false,
|
|
51
|
-
showAllSearchItems = false,
|
|
52
|
-
searchText,
|
|
53
|
-
resetText,
|
|
54
|
-
onFilterChange,
|
|
55
|
-
columnOffsetWidth = 0,
|
|
28
|
+
...rest
|
|
56
29
|
} = props;
|
|
57
30
|
|
|
58
|
-
const [form] = AntdForm.useForm(externalForm);
|
|
59
|
-
|
|
60
|
-
const {
|
|
61
|
-
containerRef,
|
|
62
|
-
buttonGroupRef,
|
|
63
|
-
cls,
|
|
64
|
-
getLabelWidth,
|
|
65
|
-
processedSearchItems,
|
|
66
|
-
setSearchItems,
|
|
67
|
-
currentSearchItems,
|
|
68
|
-
totalColumnNum,
|
|
69
|
-
expand,
|
|
70
|
-
setExpand,
|
|
71
|
-
toggleExpand,
|
|
72
|
-
showExpandButton,
|
|
73
|
-
onSearchClick,
|
|
74
|
-
onResetClick,
|
|
75
|
-
shouldRender,
|
|
76
|
-
permitted,
|
|
77
|
-
} = useSearchCommon({
|
|
78
|
-
form,
|
|
79
|
-
searchItems,
|
|
80
|
-
moreSearchItems,
|
|
81
|
-
searchData,
|
|
82
|
-
hasPermi,
|
|
83
|
-
beforeButtonGroup,
|
|
84
|
-
affterButtonGroup,
|
|
85
|
-
columnNum,
|
|
86
|
-
autoAdaptWidth,
|
|
87
|
-
defaultExpanded,
|
|
88
|
-
onExpandChange,
|
|
89
|
-
showAllSearchItems,
|
|
90
|
-
minLabelWidth,
|
|
91
|
-
baseWidth,
|
|
92
|
-
onSearch,
|
|
93
|
-
onReset,
|
|
94
|
-
columnOffsetWidth,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (!shouldRender) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
31
|
return (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
currentSearchItems?.map((item) => {
|
|
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
|
-
label={undefined}
|
|
133
|
-
labelWidth={undefined}
|
|
134
|
-
/>
|
|
135
|
-
);
|
|
136
|
-
})}
|
|
137
|
-
{(beforeButtonGroup?.length ||
|
|
138
|
-
affterButtonGroup?.length ||
|
|
139
|
-
permitted) && (
|
|
140
|
-
<ButtonGroup
|
|
141
|
-
beforeButtonGroup={beforeButtonGroup}
|
|
142
|
-
affterButtonGroup={affterButtonGroup}
|
|
143
|
-
expandButton={
|
|
144
|
-
<ExpandButton
|
|
145
|
-
expand={expand}
|
|
146
|
-
toggleExpand={toggleExpand}
|
|
147
|
-
advancedFilters={true}
|
|
148
|
-
showExpandButton={showExpandButton}
|
|
149
|
-
showAllSearchItems={
|
|
150
|
-
showAllSearchItems || !!moreSearchItems?.length
|
|
151
|
-
}
|
|
152
|
-
/>
|
|
153
|
-
}
|
|
154
|
-
permitted={permitted}
|
|
155
|
-
ref={buttonGroupRef}
|
|
156
|
-
>
|
|
157
|
-
{currentSearchItems.length > 0 && (
|
|
158
|
-
<SearchButtons
|
|
159
|
-
onSearch={onSearchClick}
|
|
160
|
-
onReset={onResetClick}
|
|
161
|
-
searchDisabled={searchDisabled}
|
|
162
|
-
searchText={searchText}
|
|
163
|
-
resetText={resetText}
|
|
164
|
-
/>
|
|
165
|
-
)}
|
|
166
|
-
{setFilter && (
|
|
167
|
-
<FilterDropdown
|
|
168
|
-
searchItems={processedSearchItems}
|
|
169
|
-
originalSearchItems={searchItems}
|
|
170
|
-
setSearchItems={setSearchItems}
|
|
171
|
-
onFilterChange={onFilterChange}
|
|
172
|
-
/>
|
|
173
|
-
)}
|
|
174
|
-
</ButtonGroup>
|
|
175
|
-
)}
|
|
176
|
-
</AntdForm>
|
|
177
|
-
</div>
|
|
178
|
-
</div>
|
|
179
|
-
{permitted && setExpand && (
|
|
180
|
-
<AdvancedFiltersDrawer
|
|
181
|
-
expand={expand}
|
|
182
|
-
setExpand={setExpand}
|
|
183
|
-
searchItems={processedSearchItems}
|
|
184
|
-
form={form}
|
|
185
|
-
getLabelWidth={getLabelWidth}
|
|
186
|
-
minLabelWidth={minLabelWidth}
|
|
187
|
-
onSearchClick={onSearchClick}
|
|
188
|
-
onResetClick={onResetClick}
|
|
189
|
-
advancedFiltersProps={advancedFiltersProps}
|
|
190
|
-
/>
|
|
191
|
-
)}
|
|
192
|
-
</>
|
|
32
|
+
<SearchBase
|
|
33
|
+
{...rest}
|
|
34
|
+
minLabelWidth={minLabelWidth}
|
|
35
|
+
advancedFilters
|
|
36
|
+
showFilter={!!setFilter}
|
|
37
|
+
className={classNames(className, styles.advancedFilters)}
|
|
38
|
+
renderOutside={(ctx) =>
|
|
39
|
+
ctx.setExpand && (
|
|
40
|
+
<AdvancedFiltersDrawer
|
|
41
|
+
expand={ctx.expand}
|
|
42
|
+
setExpand={ctx.setExpand}
|
|
43
|
+
searchItems={ctx.processedSearchItems}
|
|
44
|
+
form={ctx.form}
|
|
45
|
+
getLabelWidth={ctx.getLabelWidth}
|
|
46
|
+
minLabelWidth={minLabelWidth}
|
|
47
|
+
onSearchClick={ctx.onSearchClick}
|
|
48
|
+
onResetClick={ctx.onResetClick}
|
|
49
|
+
advancedFiltersProps={advancedFiltersProps}
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
193
54
|
);
|
|
194
55
|
};
|
|
195
56
|
|
|
@@ -77,7 +77,7 @@ const SearchCard: React.FC<SearchCardProps> = memo((props) => {
|
|
|
77
77
|
style={
|
|
78
78
|
{
|
|
79
79
|
"--searchCard-column-gap": `${gap}px`,
|
|
80
|
-
"
|
|
80
|
+
"--searchCard-padding-left-right": `${padding}px`,
|
|
81
81
|
} as CSSProperties
|
|
82
82
|
}
|
|
83
83
|
>
|
package/src/components/Search/{_components → SearchCollapsible/_components}/CollapseToggle/index.tsx
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import Icon from "
|
|
2
|
+
import Icon from "../../../../Icon";
|
|
3
3
|
import classNames from "classnames";
|
|
4
|
-
import styles from "
|
|
4
|
+
import styles from "../../../index.module.scss";
|
|
5
5
|
|
|
6
6
|
interface CollapseToggleProps {
|
|
7
7
|
collapse: boolean;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { Form as AntdForm } from "antd";
|
|
3
|
-
import FormItem from "../../FormItem";
|
|
4
|
-
import { CSSProperties, useCallback, useState } from "react";
|
|
1
|
+
import React, { useCallback, useState } from "react";
|
|
5
2
|
import classNames from "classnames";
|
|
6
3
|
import styles from "../index.module.scss";
|
|
7
|
-
import
|
|
4
|
+
import SearchBase from "../_components/SearchBase";
|
|
5
|
+
import { CollapseToggle } from "./_components/CollapseToggle";
|
|
8
6
|
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
|
-
import { CollapseToggle } from "../_components/CollapseToggle";
|
|
14
7
|
import { SearchPropsWithFilter } from "../_types";
|
|
15
8
|
|
|
16
9
|
export interface SearchCollapsibleProps extends SearchPropsWithFilter {
|
|
@@ -27,73 +20,16 @@ export interface SearchCollapsibleProps extends SearchPropsWithFilter {
|
|
|
27
20
|
*/
|
|
28
21
|
const SearchCollapsible: React.FC<SearchCollapsibleProps> = (props) => {
|
|
29
22
|
const {
|
|
30
|
-
searchItems = [],
|
|
31
|
-
moreSearchItems = [],
|
|
32
23
|
className,
|
|
33
|
-
onSearch,
|
|
34
|
-
onReset,
|
|
35
|
-
externalForm,
|
|
36
|
-
hasPermi,
|
|
37
|
-
columnNum = 4,
|
|
38
|
-
beforeButtonGroup,
|
|
39
|
-
affterButtonGroup,
|
|
40
|
-
searchData,
|
|
41
|
-
setFilter,
|
|
42
|
-
minLabelWidth,
|
|
43
24
|
defaultExpanded = false,
|
|
44
25
|
onCollapseToggle,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
baseWidth,
|
|
48
|
-
onValuesChange,
|
|
49
|
-
searchDisabled = false,
|
|
50
|
-
showAllSearchItems = false,
|
|
51
|
-
searchText,
|
|
52
|
-
resetText,
|
|
53
|
-
onFilterChange,
|
|
54
|
-
columnOffsetWidth = 0,
|
|
26
|
+
setFilter,
|
|
27
|
+
...rest
|
|
55
28
|
} = props;
|
|
56
29
|
|
|
57
|
-
const [form] = AntdForm.useForm(externalForm);
|
|
58
30
|
// collapse 的语义是反的,所以需要取反 defaultExpanded
|
|
59
31
|
const [collapse, setCollapse] = useState(!defaultExpanded);
|
|
60
32
|
|
|
61
|
-
const {
|
|
62
|
-
containerRef,
|
|
63
|
-
buttonGroupRef,
|
|
64
|
-
cls,
|
|
65
|
-
getLabelWidth,
|
|
66
|
-
processedSearchItems,
|
|
67
|
-
setSearchItems,
|
|
68
|
-
currentSearchItems,
|
|
69
|
-
totalColumnNum,
|
|
70
|
-
expand,
|
|
71
|
-
toggleExpand,
|
|
72
|
-
showExpandButton,
|
|
73
|
-
onSearchClick,
|
|
74
|
-
onResetClick,
|
|
75
|
-
shouldRender,
|
|
76
|
-
permitted,
|
|
77
|
-
} = useSearchCommon({
|
|
78
|
-
form,
|
|
79
|
-
searchItems,
|
|
80
|
-
moreSearchItems,
|
|
81
|
-
searchData,
|
|
82
|
-
hasPermi,
|
|
83
|
-
beforeButtonGroup,
|
|
84
|
-
affterButtonGroup,
|
|
85
|
-
columnNum,
|
|
86
|
-
autoAdaptWidth,
|
|
87
|
-
defaultExpanded,
|
|
88
|
-
onExpandChange,
|
|
89
|
-
showAllSearchItems,
|
|
90
|
-
minLabelWidth,
|
|
91
|
-
baseWidth,
|
|
92
|
-
onSearch,
|
|
93
|
-
onReset,
|
|
94
|
-
columnOffsetWidth,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
33
|
// 处理折叠切换
|
|
98
34
|
const handleCollapseToggle = useCallback(() => {
|
|
99
35
|
setCollapse((prev) => {
|
|
@@ -103,103 +39,18 @@ const SearchCollapsible: React.FC<SearchCollapsibleProps> = (props) => {
|
|
|
103
39
|
});
|
|
104
40
|
}, [onCollapseToggle]);
|
|
105
41
|
|
|
106
|
-
if (!shouldRender) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
42
|
return (
|
|
111
|
-
<
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
43
|
+
<SearchBase
|
|
44
|
+
{...rest}
|
|
45
|
+
defaultExpanded={defaultExpanded}
|
|
46
|
+
showFilter={!!setFilter}
|
|
47
|
+
className={classNames(className, styles.collapseExpand, {
|
|
115
48
|
[styles.collapse]: collapse,
|
|
116
49
|
})}
|
|
117
|
-
|
|
118
|
-
{
|
|
119
|
-
"--column-number": totalColumnNum,
|
|
120
|
-
"--column-offset-width": `${columnOffsetWidth}px`,
|
|
121
|
-
} as CSSProperties
|
|
122
|
-
}
|
|
123
|
-
>
|
|
124
|
-
<div
|
|
125
|
-
className={classNames(styles.searchOption, styles[expand.toString()])}
|
|
126
|
-
>
|
|
127
|
-
<AntdForm
|
|
128
|
-
form={form}
|
|
129
|
-
className={classNames(styles.option, cls)}
|
|
130
|
-
onValuesChange={onValuesChange}
|
|
131
|
-
>
|
|
132
|
-
{permitted &&
|
|
133
|
-
currentSearchItems?.map((item, idx) => {
|
|
134
|
-
// 计算同一列的项(用于计算标签宽度)
|
|
135
|
-
const visibleCurrentItems = currentSearchItems.filter(
|
|
136
|
-
(i) => i.visible !== false
|
|
137
|
-
);
|
|
138
|
-
const columnIndex = idx % totalColumnNum;
|
|
139
|
-
const sameColumnItems = visibleCurrentItems.filter(
|
|
140
|
-
(_, _idx) => _idx % totalColumnNum === columnIndex
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
<FormItem
|
|
145
|
-
{...item}
|
|
146
|
-
key={item.name}
|
|
147
|
-
className={classNames(styles.item, item.className, {
|
|
148
|
-
[styles.unFill]: item.width !== undefined,
|
|
149
|
-
})}
|
|
150
|
-
labelWidth={
|
|
151
|
-
item.width !== undefined
|
|
152
|
-
? undefined
|
|
153
|
-
: getLabelWidth(sameColumnItems, undefined, minLabelWidth)
|
|
154
|
-
}
|
|
155
|
-
/>
|
|
156
|
-
);
|
|
157
|
-
})}
|
|
158
|
-
{(beforeButtonGroup?.length ||
|
|
159
|
-
affterButtonGroup?.length ||
|
|
160
|
-
permitted) && (
|
|
161
|
-
<ButtonGroup
|
|
162
|
-
beforeButtonGroup={beforeButtonGroup}
|
|
163
|
-
affterButtonGroup={affterButtonGroup}
|
|
164
|
-
expandButton={
|
|
165
|
-
<ExpandButton
|
|
166
|
-
expand={expand}
|
|
167
|
-
toggleExpand={toggleExpand}
|
|
168
|
-
advancedFilters={false}
|
|
169
|
-
showExpandButton={showExpandButton}
|
|
170
|
-
showAllSearchItems={
|
|
171
|
-
showAllSearchItems || !!moreSearchItems?.length
|
|
172
|
-
}
|
|
173
|
-
/>
|
|
174
|
-
}
|
|
175
|
-
permitted={permitted}
|
|
176
|
-
ref={buttonGroupRef}
|
|
177
|
-
>
|
|
178
|
-
{currentSearchItems.length > 0 && (
|
|
179
|
-
<SearchButtons
|
|
180
|
-
onSearch={onSearchClick}
|
|
181
|
-
onReset={onResetClick}
|
|
182
|
-
searchDisabled={searchDisabled}
|
|
183
|
-
searchText={searchText}
|
|
184
|
-
resetText={resetText}
|
|
185
|
-
/>
|
|
186
|
-
)}
|
|
187
|
-
{setFilter && (
|
|
188
|
-
<FilterDropdown
|
|
189
|
-
searchItems={processedSearchItems}
|
|
190
|
-
originalSearchItems={searchItems}
|
|
191
|
-
setSearchItems={setSearchItems}
|
|
192
|
-
onFilterChange={onFilterChange}
|
|
193
|
-
/>
|
|
194
|
-
)}
|
|
195
|
-
</ButtonGroup>
|
|
196
|
-
)}
|
|
197
|
-
</AntdForm>
|
|
198
|
-
</div>
|
|
199
|
-
{permitted && (
|
|
50
|
+
afterForm={
|
|
200
51
|
<CollapseToggle collapse={collapse} onToggle={handleCollapseToggle} />
|
|
201
|
-
|
|
202
|
-
|
|
52
|
+
}
|
|
53
|
+
/>
|
|
203
54
|
);
|
|
204
55
|
};
|
|
205
56
|
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
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
|
-
|
|
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;
|