yootd 0.2.10 → 0.2.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.
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,4 @@
1
+ import React from 'react';
2
+ import './index.scss';
3
+ import { WithSearchFormProps } from './types/type';
4
+ export declare const WithSearchForm: ({ children }: WithSearchFormProps) => React.JSX.Element;
@@ -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
+ };
@@ -0,0 +1,11 @@
1
+ .yot-WithSearchForm {
2
+ &-container {
3
+ display: flex;
4
+ flex-wrap: wrap;
5
+ }
6
+ &__expanded {
7
+ color: #4d8de2;
8
+ font-size: 14px;
9
+ cursor: pointer;
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export interface WithSearchFormProps {
2
+ children: ReactNode[];
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yootd",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
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": {