yootd 0.2.10 → 0.2.12
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/dist/aside/components/SortableItem.js +40 -6
- package/dist/aside/components/SortableItem.scss +164 -0
- package/dist/aside/index.js +31 -7
- package/dist/aside/types/types.d.ts +22 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/with-search-form/index.d.ts +4 -0
- package/dist/with-search-form/index.js +135 -0
- package/dist/with-search-form/index.scss +11 -0
- package/dist/with-search-form/types/type.d.ts +3 -0
- package/package.json +2 -1
@@ -30,7 +30,11 @@ var SortableItem = function SortableItem(_ref) {
|
|
30
30
|
_onClick = _ref.onClick,
|
31
31
|
onEdit = _ref.onEdit,
|
32
32
|
onDel = _ref.onDel,
|
33
|
-
onSwitch = _ref.onSwitch
|
33
|
+
onSwitch = _ref.onSwitch,
|
34
|
+
subId = _ref.subId,
|
35
|
+
isSubNode = _ref.isSubNode,
|
36
|
+
subNode = _ref.subNode,
|
37
|
+
onSubClick = _ref.onSubClick;
|
34
38
|
var _useSortable = useSortable({
|
35
39
|
id: id
|
36
40
|
}),
|
@@ -49,12 +53,13 @@ var SortableItem = function SortableItem(_ref) {
|
|
49
53
|
zIndex: 9999
|
50
54
|
} : {});
|
51
55
|
var mb = useBem('SortableItem');
|
52
|
-
var top = mb.b('content').b('top');
|
56
|
+
var top = isSubNode === true ? mb.b('content-no-bg').b('top') : mb.b('content').b('top');
|
57
|
+
var subTop = mb.b('sub-content').b('top');
|
53
58
|
return /*#__PURE__*/React.createElement("div", {
|
54
59
|
style: style,
|
55
60
|
className: "".concat(mb)
|
56
61
|
}, /*#__PURE__*/React.createElement("div", {
|
57
|
-
className: "".concat(mb.b('content'), " ").concat(id === activeKey ? "".concat(mb.e('content-active')) : '', " ").concat(mb.b(statusColor[status !== null && status !== void 0 ? status : ''])),
|
62
|
+
className: "".concat(isSubNode === true ? "".concat(mb.b('content-no-bg')) : "".concat(mb.b('content')), " ").concat(id === activeKey && isSubNode === false ? "".concat(mb.e('content-active')) : '', " ").concat(mb.b(statusColor[status !== null && status !== void 0 ? status : ''])),
|
58
63
|
key: id,
|
59
64
|
onClick: function onClick() {
|
60
65
|
_onClick === null || _onClick === void 0 || _onClick(id, {
|
@@ -80,7 +85,7 @@ var SortableItem = function SortableItem(_ref) {
|
|
80
85
|
})), /*#__PURE__*/React.createElement("div", {
|
81
86
|
className: "".concat(top.b('top-left').b('top-title-wrap'))
|
82
87
|
}, /*#__PURE__*/React.createElement("span", {
|
83
|
-
className: "".concat(top.b('top-left').b('top-title-wrap').e('top-title')),
|
88
|
+
className: "".concat(top.b('top-left').b('top-title-wrap').e('top-title'), " ").concat(id === activeKey ? "".concat(top.b('top-left').b('top-title-wrap').e('top-title-active')) : ''),
|
84
89
|
style: {
|
85
90
|
marginRight: editBtnIcon || delBtnIcon ? '12px' : '0',
|
86
91
|
marginLeft: dragBtnIcon ? '6px' : '0'
|
@@ -150,6 +155,35 @@ var SortableItem = function SortableItem(_ref) {
|
|
150
155
|
}
|
151
156
|
}, /*#__PURE__*/React.createElement("span", {
|
152
157
|
className: "".concat(mb.b('content').b('bottom').e('extra'))
|
153
|
-
}, extra))))
|
158
|
+
}, extra))), subNode === null || subNode === void 0 ? void 0 : subNode.map(function (item, index) {
|
159
|
+
return /*#__PURE__*/React.createElement("div", {
|
160
|
+
key: index,
|
161
|
+
className: "".concat(mb.b('sub-content'), " ").concat(id === activeKey && subId === item.key ? "".concat(mb.e('sub-content-active')) : '', " ").concat(mb.b(statusColor[status !== null && status !== void 0 ? status : ''])),
|
162
|
+
onClick: function onClick() {
|
163
|
+
console.log(id, item.key, _objectSpread({}, item));
|
164
|
+
onSubClick === null || onSubClick === void 0 || onSubClick(id, item.key, _objectSpread({}, item));
|
165
|
+
}
|
166
|
+
}, /*#__PURE__*/React.createElement("div", {
|
167
|
+
className: "".concat(subTop)
|
168
|
+
}, /*#__PURE__*/React.createElement("div", {
|
169
|
+
className: "".concat(subTop.b('top-left'))
|
170
|
+
}, /*#__PURE__*/React.createElement("div", {
|
171
|
+
className: "".concat(subTop.b('top-left').b('top-title-wrap'))
|
172
|
+
}, /*#__PURE__*/React.createElement("span", {
|
173
|
+
className: "".concat(subTop.b('top-left').b('top-title-wrap').e('top-title'), " ").concat(subId === item.key ? "".concat(subTop.b('top-left').b('top-title-wrap').e('top-title-active')) : ''),
|
174
|
+
style: {
|
175
|
+
marginRight: editBtnIcon || delBtnIcon ? '12px' : '0',
|
176
|
+
marginLeft: dragBtnIcon ? '6px' : '0'
|
177
|
+
}
|
178
|
+
}, item.title)))), /*#__PURE__*/React.createElement("div", {
|
179
|
+
className: "".concat(mb.b('content').b('bottom')),
|
180
|
+
style: {
|
181
|
+
marginLeft: dragBtnIcon ? '22px' : '0'
|
182
|
+
}
|
183
|
+
}, /*#__PURE__*/React.createElement("span", {
|
184
|
+
className: "".concat(mb.b('content').b('bottom').e('extra'))
|
185
|
+
}, item.extra)));
|
186
|
+
}));
|
154
187
|
};
|
155
|
-
export default SortableItem;
|
188
|
+
export default SortableItem;
|
189
|
+
/*#__PURE__*/React.createElement("div", null);
|
@@ -66,6 +66,76 @@
|
|
66
66
|
}
|
67
67
|
}
|
68
68
|
}
|
69
|
+
&-content-no-bg {
|
70
|
+
position: relative;
|
71
|
+
padding: 12px 16px;
|
72
|
+
box-sizing: border-box;
|
73
|
+
cursor: pointer;
|
74
|
+
background-color: #fff;
|
75
|
+
&-top {
|
76
|
+
display: flex;
|
77
|
+
justify-content: space-between;
|
78
|
+
align-items: start;
|
79
|
+
&-top-left {
|
80
|
+
display: flex;
|
81
|
+
align-items: start;
|
82
|
+
&-top-drag-btn-icon {
|
83
|
+
cursor: move;
|
84
|
+
&__drag-btn-icon-svg {
|
85
|
+
display: inline-block;
|
86
|
+
vertical-align: middle;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
&-top-title-wrap {
|
90
|
+
display: flex;
|
91
|
+
align-items: center;
|
92
|
+
justify-content: center;
|
93
|
+
&__top-title {
|
94
|
+
font-size: 16px;
|
95
|
+
font-weight: 400;
|
96
|
+
line-height: 1.5em;
|
97
|
+
overflow: hidden;
|
98
|
+
display: -webkit-box; //将元素设为盒子伸缩模型显示
|
99
|
+
-webkit-box-orient: vertical; //伸缩方向设为垂直方向
|
100
|
+
-webkit-line-clamp: 2; //超出2行隐藏,并显示省略号
|
101
|
+
line-clamp: 2;
|
102
|
+
}
|
103
|
+
&__top-title-active{
|
104
|
+
font-weight: bold;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
&-top-middle {
|
109
|
+
display: flex;
|
110
|
+
align-items: center;
|
111
|
+
&-top-edit-btn-icon {
|
112
|
+
cursor: pointer;
|
113
|
+
&__edit-btn-icon-svg {
|
114
|
+
display: inline-block;
|
115
|
+
vertical-align: middle;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
&-top-del-btn-icon {
|
119
|
+
cursor: pointer;
|
120
|
+
margin-left: 12px;
|
121
|
+
&__del-btn-icon-svg {
|
122
|
+
display: inline-block;
|
123
|
+
vertical-align: middle;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
&-bottom {
|
129
|
+
text-overflow: ellipsis;
|
130
|
+
overflow: hidden;
|
131
|
+
white-space: nowrap;
|
132
|
+
&__extra {
|
133
|
+
font-size: 12px;
|
134
|
+
font-weight: 400;
|
135
|
+
color: rgba(0, 0, 0, 0.45);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
69
139
|
&-content:hover {
|
70
140
|
background-color: var(--ant-color-primary-border);
|
71
141
|
transition: all 0.05s ease;
|
@@ -108,4 +178,98 @@
|
|
108
178
|
border: 4px solid var(--ant-color-error);
|
109
179
|
z-index: 999;
|
110
180
|
}
|
181
|
+
&-sub-content {
|
182
|
+
position: relative;
|
183
|
+
padding: 12px 16px 12px 32px;
|
184
|
+
box-sizing: border-box;
|
185
|
+
cursor: pointer;
|
186
|
+
background-color: #fff;
|
187
|
+
border-bottom:1 px solid ;
|
188
|
+
&-top {
|
189
|
+
display: flex;
|
190
|
+
justify-content: space-between;
|
191
|
+
align-items: start;
|
192
|
+
&-top-left {
|
193
|
+
display: flex;
|
194
|
+
align-items: start;
|
195
|
+
&-top-drag-btn-icon {
|
196
|
+
cursor: move;
|
197
|
+
&__drag-btn-icon-svg {
|
198
|
+
display: inline-block;
|
199
|
+
vertical-align: middle;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
&-top-title-wrap {
|
203
|
+
display: flex;
|
204
|
+
align-items: center;
|
205
|
+
justify-content: center;
|
206
|
+
&__top-title {
|
207
|
+
font-size: 16px;
|
208
|
+
font-weight: 400;
|
209
|
+
line-height: 1.5em;
|
210
|
+
overflow: hidden;
|
211
|
+
display: -webkit-box; //将元素设为盒子伸缩模型显示
|
212
|
+
-webkit-box-orient: vertical; //伸缩方向设为垂直方向
|
213
|
+
-webkit-line-clamp: 2; //超出2行隐藏,并显示省略号
|
214
|
+
line-clamp: 2;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
}
|
218
|
+
&-top-middle {
|
219
|
+
display: flex;
|
220
|
+
align-items: center;
|
221
|
+
&-top-edit-btn-icon {
|
222
|
+
cursor: pointer;
|
223
|
+
&__edit-btn-icon-svg {
|
224
|
+
display: inline-block;
|
225
|
+
vertical-align: middle;
|
226
|
+
}
|
227
|
+
}
|
228
|
+
&-top-del-btn-icon {
|
229
|
+
cursor: pointer;
|
230
|
+
margin-left: 12px;
|
231
|
+
&__del-btn-icon-svg {
|
232
|
+
display: inline-block;
|
233
|
+
vertical-align: middle;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
}
|
238
|
+
&-bottom {
|
239
|
+
text-overflow: ellipsis;
|
240
|
+
overflow: hidden;
|
241
|
+
white-space: nowrap;
|
242
|
+
&__extra {
|
243
|
+
font-size: 12px;
|
244
|
+
font-weight: 400;
|
245
|
+
color: rgba(0, 0, 0, 0.45);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
}
|
249
|
+
&-sub-content:hover {
|
250
|
+
background-color: var(--ant-color-primary-border);
|
251
|
+
transition: all 0.05s ease;
|
252
|
+
}
|
253
|
+
&-sub-content::before {
|
254
|
+
content: '';
|
255
|
+
position: absolute;
|
256
|
+
bottom: -0.5px;
|
257
|
+
left: 16px;
|
258
|
+
right: 16px;
|
259
|
+
height: 1px;
|
260
|
+
background-color: #e5e5e5;
|
261
|
+
z-index: 100;
|
262
|
+
}
|
263
|
+
&__sub-content-active {
|
264
|
+
background-color: var(--ant-color-primary-border);
|
265
|
+
}
|
266
|
+
&__sub-content-active::after {
|
267
|
+
content: '';
|
268
|
+
position: absolute;
|
269
|
+
bottom: 0;
|
270
|
+
left: 0;
|
271
|
+
width: 4px;
|
272
|
+
height: 100%;
|
273
|
+
background-color: var(--ant-color-primary);
|
274
|
+
}
|
111
275
|
}
|
package/dist/aside/index.js
CHANGED
@@ -38,7 +38,10 @@ export var Aside = function Aside(_ref) {
|
|
38
38
|
onDragEnd = _ref.onDragEnd,
|
39
39
|
onScrollBottom = _ref.onScrollBottom,
|
40
40
|
_ref$bottomThreshold = _ref.bottomThreshold,
|
41
|
-
bottomThreshold = _ref$bottomThreshold === void 0 ? 50 : _ref$bottomThreshold
|
41
|
+
bottomThreshold = _ref$bottomThreshold === void 0 ? 50 : _ref$bottomThreshold,
|
42
|
+
_ref$isSubNode = _ref.isSubNode,
|
43
|
+
isSubNode = _ref$isSubNode === void 0 ? false : _ref$isSubNode,
|
44
|
+
onSubClick = _ref.onSubClick;
|
42
45
|
var mb = useBem('aside');
|
43
46
|
var asideRef = useRef(null);
|
44
47
|
// 当前选择的key
|
@@ -46,11 +49,16 @@ export var Aside = function Aside(_ref) {
|
|
46
49
|
_useState2 = _slicedToArray(_useState, 2),
|
47
50
|
key = _useState2[0],
|
48
51
|
setKey = _useState2[1];
|
49
|
-
//
|
50
|
-
var _useState3 = useState(
|
52
|
+
// 当前选择的key
|
53
|
+
var _useState3 = useState(),
|
51
54
|
_useState4 = _slicedToArray(_useState3, 2),
|
52
|
-
|
53
|
-
|
55
|
+
subKey = _useState4[0],
|
56
|
+
setSubKey = _useState4[1];
|
57
|
+
// 缓存传入的数据
|
58
|
+
var _useState5 = useState([]),
|
59
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
60
|
+
dataValue = _useState6[0],
|
61
|
+
setDataValue = _useState6[1];
|
54
62
|
var sensors = useSensors(useSensor(PointerSensor, {
|
55
63
|
activationConstraint: {
|
56
64
|
delay: 50,
|
@@ -62,10 +70,22 @@ export var Aside = function Aside(_ref) {
|
|
62
70
|
// 切换选中项
|
63
71
|
var handleClick = function handleClick(key, e) {
|
64
72
|
if (key != null) {
|
73
|
+
var _e$children$0$key, _e$children;
|
65
74
|
setKey(key);
|
75
|
+
setSubKey((_e$children$0$key = e === null || e === void 0 || (_e$children = e.children) === null || _e$children === void 0 || (_e$children = _e$children[0]) === null || _e$children === void 0 ? void 0 : _e$children.key) !== null && _e$children$0$key !== void 0 ? _e$children$0$key : '');
|
66
76
|
onClick === null || onClick === void 0 || onClick(key, e);
|
67
77
|
}
|
68
78
|
};
|
79
|
+
// 切换选中项
|
80
|
+
var handleSubClick = function handleSubClick(key, subKey, e) {
|
81
|
+
if (key != null) {
|
82
|
+
setKey(key);
|
83
|
+
if (subKey != null) {
|
84
|
+
setSubKey(subKey);
|
85
|
+
onSubClick === null || onSubClick === void 0 || onSubClick(key, subKey, e);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
};
|
69
89
|
// 添加
|
70
90
|
var handleAdd = function handleAdd() {
|
71
91
|
onAdd === null || onAdd === void 0 || onAdd();
|
@@ -188,7 +208,7 @@ export var Aside = function Aside(_ref) {
|
|
188
208
|
}),
|
189
209
|
strategy: verticalListSortingStrategy
|
190
210
|
}, dataValue === null || dataValue === void 0 ? void 0 : dataValue.map(function (item) {
|
191
|
-
var _dataValue
|
211
|
+
var _dataValue$, _item$children;
|
192
212
|
return /*#__PURE__*/React.createElement(SortableItem, {
|
193
213
|
key: item.key,
|
194
214
|
activeKey: key !== null && key !== void 0 ? key : dataValue === null || dataValue === void 0 || (_dataValue$ = dataValue[0]) === null || _dataValue$ === void 0 ? void 0 : _dataValue$.key,
|
@@ -204,8 +224,12 @@ export var Aside = function Aside(_ref) {
|
|
204
224
|
onEdit: handleEdit,
|
205
225
|
onDel: handleDel,
|
206
226
|
onSwitch: handleSwitch,
|
227
|
+
onSubClick: handleSubClick,
|
207
228
|
data: item.data,
|
208
|
-
status: item.status
|
229
|
+
status: item.status,
|
230
|
+
subId: subKey !== null && subKey !== void 0 ? subKey : (_item$children = item.children) === null || _item$children === void 0 || (_item$children = _item$children[0]) === null || _item$children === void 0 ? void 0 : _item$children.key,
|
231
|
+
isSubNode: isSubNode,
|
232
|
+
subNode: item.children
|
209
233
|
});
|
210
234
|
})))));
|
211
235
|
};
|
@@ -5,6 +5,14 @@ type IdataItem = {
|
|
5
5
|
checked?: boolean;
|
6
6
|
status?: string;
|
7
7
|
data?: any;
|
8
|
+
children?: Array<{
|
9
|
+
key: string;
|
10
|
+
title: string;
|
11
|
+
extra?: string;
|
12
|
+
checked?: boolean;
|
13
|
+
status?: string;
|
14
|
+
data?: any;
|
15
|
+
}>;
|
8
16
|
};
|
9
17
|
export type AsideProps = {
|
10
18
|
width?: number;
|
@@ -31,6 +39,8 @@ export type AsideProps = {
|
|
31
39
|
onDragEnd?: (data: IdataItem[]) => void;
|
32
40
|
onScrollBottom?: () => void;
|
33
41
|
bottomThreshold?: number;
|
42
|
+
isSubNode: boolean;
|
43
|
+
onSubClick?: (key: string, subKey: string, e: IdataItem) => void;
|
34
44
|
};
|
35
45
|
export type AsideItemProps = {
|
36
46
|
activeKey: string;
|
@@ -44,8 +54,19 @@ export type AsideItemProps = {
|
|
44
54
|
extra?: string;
|
45
55
|
status?: string;
|
46
56
|
data?: any;
|
47
|
-
onClick?: (key: string, e: IdataItem) => void;
|
57
|
+
onClick?: (key: string | undefined, e: IdataItem) => void;
|
48
58
|
onEdit?: (key: string, e: IdataItem) => void;
|
49
59
|
onDel?: (key: string, e: IdataItem) => void;
|
50
60
|
onSwitch?: (key: string, e: boolean) => void;
|
61
|
+
subId?: string;
|
62
|
+
isSubNode?: boolean;
|
63
|
+
subNode?: Array<{
|
64
|
+
key: string;
|
65
|
+
title: string;
|
66
|
+
extra?: string;
|
67
|
+
checked?: boolean;
|
68
|
+
status?: string;
|
69
|
+
data?: any;
|
70
|
+
}>;
|
71
|
+
onSubClick?: (key, subKey: string | undefined, e: IdataItem) => void;
|
51
72
|
};
|
package/dist/index.d.ts
CHANGED
@@ -171,6 +171,8 @@ export { UserDropdown } from './user-dropdown';
|
|
171
171
|
export type { UserDropdownProps } from './user-dropdown/types/types';
|
172
172
|
export { ConfigProvider } from './config-provider';
|
173
173
|
export type { ConfigProviderProps } from './config-provider';
|
174
|
+
export { WithSearchForm } from './with-search-form';
|
175
|
+
export type { WithSearchFormProps } from './with-search-form/types/type';
|
174
176
|
export { Zone } from './zones';
|
175
177
|
export { GoBack } from './go-back';
|
176
178
|
export type { GoBackProps } from './go-back';
|
package/dist/index.js
CHANGED
@@ -92,6 +92,7 @@ export { DatePicker } from "./date-picker";
|
|
92
92
|
export { Teacher } from "./teacher";
|
93
93
|
export { UserDropdown } from "./user-dropdown";
|
94
94
|
export { ConfigProvider } from "./config-provider";
|
95
|
+
export { WithSearchForm } from "./with-search-form";
|
95
96
|
export { Zone } from "./zones";
|
96
97
|
export { GoBack } from "./go-back";
|
97
98
|
export { VideoPlayer } from "./video-player";
|
@@ -0,0 +1,135 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
import { DownOutlined } from '@ant-design/icons';
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
4
|
+
import { Button, Form, Space } from "./..";
|
5
|
+
import { useBem } from "../hooks/useBem";
|
6
|
+
import "./index.scss";
|
7
|
+
export var WithSearchForm = function WithSearchForm(_ref) {
|
8
|
+
var children = _ref.children;
|
9
|
+
var mb = useBem('WithSearchForm');
|
10
|
+
// 外层dom实例
|
11
|
+
var formRef = useRef(null);
|
12
|
+
// 最后面的按钮组实例
|
13
|
+
var btnRef = useRef(null);
|
14
|
+
// 传进来的children dom数组实例
|
15
|
+
var childRefs = useRef([]);
|
16
|
+
var _useState = useState(children.length),
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
18
|
+
visibleCount = _useState2[0],
|
19
|
+
setVisibleCount = _useState2[1];
|
20
|
+
// 展开收起(true:收起,false:展开)
|
21
|
+
var _useState3 = useState(false),
|
22
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
23
|
+
isExpanded = _useState4[0],
|
24
|
+
setIsExpanded = _useState4[1];
|
25
|
+
// 计算出应该显示的children数量
|
26
|
+
var _useState5 = useState(children.length),
|
27
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
28
|
+
calculatedCount = _useState6[0],
|
29
|
+
setCalculatedCount = _useState6[1];
|
30
|
+
// 获取元素实际占用的总宽度(包括外边距)
|
31
|
+
var getElementTotalWidth = function getElementTotalWidth(element) {
|
32
|
+
var computedStyle = window.getComputedStyle(element);
|
33
|
+
var marginLeft = parseInt(computedStyle.marginLeft, 10) || 0;
|
34
|
+
var marginRight = parseInt(computedStyle.marginRight, 10) || 0;
|
35
|
+
return element.offsetWidth + marginLeft + marginRight;
|
36
|
+
};
|
37
|
+
// 计算每行可以放置的元素
|
38
|
+
var calculateVisibleItems = function calculateVisibleItems() {
|
39
|
+
if (!formRef.current || !btnRef.current) return;
|
40
|
+
// 获取容器宽度
|
41
|
+
var containerWidth = formRef.current.offsetWidth;
|
42
|
+
// 每行累计的宽度
|
43
|
+
var currentRowWidth = 0;
|
44
|
+
// 第几行
|
45
|
+
var currentRow = 1;
|
46
|
+
var itemCount = 0;
|
47
|
+
// 遍历所有子元素
|
48
|
+
for (var i = 0; i < (childRefs === null || childRefs === void 0 ? void 0 : childRefs.current.length); i++) {
|
49
|
+
var childRef = childRefs.current[i];
|
50
|
+
if (!childRef) continue;
|
51
|
+
// 获取子元素的宽度
|
52
|
+
var childWidth = getElementTotalWidth(childRef);
|
53
|
+
// 检查是否需要换行
|
54
|
+
// 第一行使用完整宽度,第二行需要减去按钮组宽度
|
55
|
+
var availableWidth = currentRow === 1 ? containerWidth : containerWidth - getElementTotalWidth(btnRef.current);
|
56
|
+
if (currentRowWidth + childWidth > availableWidth) {
|
57
|
+
currentRow++;
|
58
|
+
currentRowWidth = childWidth;
|
59
|
+
|
60
|
+
// 如果超过两行,就停止计算
|
61
|
+
if (currentRow > 2) {
|
62
|
+
break;
|
63
|
+
}
|
64
|
+
} else {
|
65
|
+
currentRowWidth += childWidth;
|
66
|
+
}
|
67
|
+
itemCount = i + 1;
|
68
|
+
}
|
69
|
+
|
70
|
+
// 保存计算出的数量
|
71
|
+
setCalculatedCount(itemCount);
|
72
|
+
// 根据展开状态设置可见数量
|
73
|
+
setVisibleCount(isExpanded ? children.length : itemCount);
|
74
|
+
};
|
75
|
+
useEffect(function () {
|
76
|
+
// 创建 ResizeObserver 实例
|
77
|
+
var resizeObserver = new ResizeObserver(function () {
|
78
|
+
calculateVisibleItems();
|
79
|
+
});
|
80
|
+
// 观察表单容器元素
|
81
|
+
if (formRef.current) {
|
82
|
+
resizeObserver.observe(formRef.current);
|
83
|
+
}
|
84
|
+
// 清理函数
|
85
|
+
return function () {
|
86
|
+
resizeObserver.disconnect();
|
87
|
+
};
|
88
|
+
}, [children, isExpanded]);
|
89
|
+
|
90
|
+
// 处理展开/收起的点击事件
|
91
|
+
var handleExpandClick = function handleExpandClick() {
|
92
|
+
setIsExpanded(!isExpanded);
|
93
|
+
setVisibleCount(!isExpanded ? children.length : calculatedCount);
|
94
|
+
};
|
95
|
+
return /*#__PURE__*/React.createElement("div", {
|
96
|
+
ref: formRef,
|
97
|
+
className: "".concat(mb.b('container'))
|
98
|
+
}, /*#__PURE__*/React.createElement("div", {
|
99
|
+
style: {
|
100
|
+
position: 'absolute',
|
101
|
+
visibility: 'hidden',
|
102
|
+
display: 'flex',
|
103
|
+
flexWrap: 'wrap',
|
104
|
+
width: '100%'
|
105
|
+
}
|
106
|
+
}, children === null || children === void 0 ? void 0 : children.map(function (child, index) {
|
107
|
+
return /*#__PURE__*/React.createElement("div", {
|
108
|
+
key: "measure-".concat(index),
|
109
|
+
ref: function ref(el) {
|
110
|
+
return childRefs.current[index] = el;
|
111
|
+
},
|
112
|
+
style: {
|
113
|
+
display: 'inline-block'
|
114
|
+
}
|
115
|
+
}, child);
|
116
|
+
})), children === null || children === void 0 ? void 0 : children.slice(0, visibleCount), /*#__PURE__*/React.createElement("div", {
|
117
|
+
ref: btnRef
|
118
|
+
}, /*#__PURE__*/React.createElement(Form.Item, {
|
119
|
+
className: "mb-4"
|
120
|
+
}, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(Button, {
|
121
|
+
type: "primary",
|
122
|
+
htmlType: "submit"
|
123
|
+
}, "\u67E5\u8BE2"), /*#__PURE__*/React.createElement(Button, {
|
124
|
+
type: "default",
|
125
|
+
htmlType: "reset"
|
126
|
+
}, "\u91CD\u7F6E"), (children === null || children === void 0 ? void 0 : children.length) > calculatedCount ? /*#__PURE__*/React.createElement("span", {
|
127
|
+
className: "".concat(mb.e('expanded')),
|
128
|
+
onClick: handleExpandClick
|
129
|
+
}, isExpanded ? '收起' : '展开', ' ', /*#__PURE__*/React.createElement(DownOutlined, {
|
130
|
+
style: {
|
131
|
+
transform: isExpanded ? 'rotate(180deg)' : 'none',
|
132
|
+
transition: 'transform 0.3s'
|
133
|
+
}
|
134
|
+
})) : null))));
|
135
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "yootd",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.12",
|
4
4
|
"description": "基于 Antd 二次开发的组件库",
|
5
5
|
"license": "MIT",
|
6
6
|
"module": "dist/index.js",
|
@@ -45,6 +45,7 @@
|
|
45
45
|
]
|
46
46
|
},
|
47
47
|
"dependencies": {
|
48
|
+
"@ant-design/icons": "^6.0.0",
|
48
49
|
"@babel/runtime": "^7.26.9"
|
49
50
|
},
|
50
51
|
"devDependencies": {
|