@lemon-fe/components 0.1.90 → 0.1.95

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.
@@ -3,5 +3,6 @@ declare function Filter<T extends Record<string, any> = Record<string, any>>(pro
3
3
  declare namespace Filter {
4
4
  var setComponents: (items: ComponentOption[]) => void;
5
5
  var setStorage: <T>(getData: (storageKey: string) => T | Promise<T>, setData: <T_1>(storageKey: string, data: T_1) => void | Promise<void>) => void;
6
+ var defaultProps: Partial<FilterProps<Record<string, any>>>;
6
7
  }
7
8
  export default Filter;
@@ -111,7 +111,9 @@ function Filter(props) {
111
111
  storageKey = props.storageKey,
112
112
  onValuesChange = props.onValuesChange,
113
113
  style = props.style,
114
- simple = props.simple;
114
+ simple = props.simple,
115
+ _props$defaultCollaps = props.defaultCollapsed,
116
+ defaultCollapsed = _props$defaultCollaps === void 0 ? true : _props$defaultCollaps;
115
117
  var prefixCls = "".concat(PREFIX_CLS, "-filter");
116
118
  var defaultValue = useMemo(function () {
117
119
  return defaultValueProp || value;
@@ -172,7 +174,7 @@ function Filter(props) {
172
174
  width = _useState12[0],
173
175
  setWidth = _useState12[1];
174
176
 
175
- var _useState13 = useState(true),
177
+ var _useState13 = useState(defaultCollapsed),
176
178
  _useState14 = _slicedToArray(_useState13, 2),
177
179
  collapsed = _useState14[0],
178
180
  setCollapsed = _useState14[1];
@@ -396,7 +398,7 @@ function Filter(props) {
396
398
  var btnsWidth = simple ? 208 : 248;
397
399
  var btnsVisible = false;
398
400
  var size = 0;
399
- var end = result.length;
401
+ var end = 0;
400
402
 
401
403
  for (var i = 0; i < result.length; i++) {
402
404
  var _compMap$get;
@@ -406,20 +408,18 @@ function Filter(props) {
406
408
  size += itemWidth;
407
409
 
408
410
  if (size > width - btnsWidth) {
409
- end = i;
410
411
  btnsVisible = true;
411
412
  break;
412
413
  }
413
- }
414
414
 
415
- end = end || 1;
416
- btnsVisible = btnsVisible && result.length > 1;
415
+ end = i;
416
+ }
417
417
 
418
418
  if (!collapsed) {
419
419
  return [getSet(result), btnsVisible];
420
420
  }
421
421
 
422
- return [getSet(result.slice(0, end)), btnsVisible];
422
+ return [getSet(result.slice(0, end + 1)), btnsVisible];
423
423
  }, [data, width, collapsed, simple, activeKeys]),
424
424
  _useMemo2 = _slicedToArray(_useMemo, 2),
425
425
  cols = _useMemo2[0],
@@ -621,4 +621,5 @@ function Filter(props) {
621
621
 
622
622
  Filter.setComponents = setComponents;
623
623
  Filter.setStorage = setStorage;
624
+ Filter.defaultProps = {};
624
625
  export default Filter;
@@ -20,6 +20,7 @@ export interface FilterProps<T extends Record<string, any> = Record<string, any>
20
20
  defaultActiveKeys?: string[];
21
21
  storageKey?: string;
22
22
  style?: CSSProperties;
23
+ defaultCollapsed?: boolean;
23
24
  /**
24
25
  * @description 是否简化筛选器,简化版不包含标签以及选项保存
25
26
  */
@@ -106,6 +106,8 @@
106
106
  flex-direction: column;
107
107
  min-width: 0;
108
108
  overflow: auto;
109
+
110
+ .scrollBar(8px);
109
111
  }
110
112
 
111
113
  &-footer {
@@ -209,6 +209,7 @@ export default function Menu(props) {
209
209
  setPopover = _useState2[1];
210
210
 
211
211
  var popup = useRef(null);
212
+ var popupContainer = useRef(null);
212
213
  var drawer = useRef(null);
213
214
  var clientWidth = useRef(document.body.clientWidth);
214
215
 
@@ -275,9 +276,13 @@ export default function Menu(props) {
275
276
  }, [location.pathname, menus]);
276
277
 
277
278
  var openMenu = function openMenu(item, elm) {
278
- if (item.name === FAVORITES_POPOVER || item.children !== undefined && item.children.length > 0 || collapsed) {
279
+ var isFavorite = item.name === FAVORITES_POPOVER;
280
+
281
+ if (isFavorite || item.children !== undefined && item.children.length > 0 || collapsed) {
282
+ var _popupContainer$curre;
283
+
279
284
  setPopover(item);
280
- setTop(elm.offsetTop);
285
+ setTop(elm.offsetTop - (isFavorite ? 0 : ((_popupContainer$curre = popupContainer.current) === null || _popupContainer$curre === void 0 ? void 0 : _popupContainer$curre.scrollTop) || 0));
281
286
  setTimeout(function () {
282
287
  if (popup.current) {
283
288
  popup.current.classList.add('animated');
@@ -563,12 +568,15 @@ export default function Menu(props) {
563
568
  strokeLinejoin: "round",
564
569
  strokeDasharray: "0,0",
565
570
  transform: "translate(-274.000000, -57.000000) translate(284.000000, 67.000000) scale(-1, 1) translate(-284.000000, -67.000000) translate(274.000000, 57.000000) translate(8.535522, 10.000000) rotate(-45.000000) translate(-8.535522, -10.000000)"
566
- })))))), menus.map(function (item, index) {
571
+ })))))), /*#__PURE__*/React.createElement("div", {
572
+ className: "".concat(prefixCls, "-menu-top-items"),
573
+ ref: popupContainer
574
+ }, menus.map(function (item, index) {
567
575
  var _classNames5;
568
576
 
569
577
  return /*#__PURE__*/React.createElement("div", {
570
578
  key: index,
571
- className: classNames("".concat(prefixCls, "-menu-top-item"), (_classNames5 = {}, _defineProperty(_classNames5, "".concat(prefixCls, "-menu-top-item-active"), activeMenu !== undefined && activeMenu.path[0] === index), _defineProperty(_classNames5, "".concat(prefixCls, "-menu-top-item-popover-active"), item === popover), _classNames5)),
579
+ className: classNames("".concat(prefixCls, "-menu-top-item"), (_classNames5 = {}, _defineProperty(_classNames5, "".concat(prefixCls, "-menu-top-item-active"), (activeMenu === null || activeMenu === void 0 ? void 0 : activeMenu.path[0]) === index), _defineProperty(_classNames5, "".concat(prefixCls, "-menu-top-item-popover-active"), item === popover), _classNames5)),
572
580
  onClick: function onClick() {
573
581
  return handleClick(item);
574
582
  },
@@ -578,6 +586,8 @@ export default function Menu(props) {
578
586
  return openMenu(item, target);
579
587
  });
580
588
  }
589
+ }, /*#__PURE__*/React.createElement("div", {
590
+ className: "".concat(prefixCls, "-menu-top-item-content")
581
591
  }, typeof item.icon === 'string' ? /*#__PURE__*/React.createElement("img", {
582
592
  className: "".concat(prefixCls, "-menu-icon"),
583
593
  src: item.icon
@@ -585,8 +595,8 @@ export default function Menu(props) {
585
595
  className: "".concat(prefixCls, "-menu-icon")
586
596
  }, item.icon), /*#__PURE__*/React.createElement("div", {
587
597
  className: "".concat(prefixCls, "-menu-title")
588
- }, item.name));
589
- }), /*#__PURE__*/React.createElement("div", {
598
+ }, item.name)));
599
+ })), /*#__PURE__*/React.createElement("div", {
590
600
  className: classNames("".concat(prefixCls, "-menu-divider-div"), _defineProperty({}, "".concat(prefixCls, "-menu-divider-div-collapsed"), collapsed))
591
601
  }, /*#__PURE__*/React.createElement(Divider, {
592
602
  className: "".concat(prefixCls, "-menu-divider")
@@ -603,11 +613,13 @@ export default function Menu(props) {
603
613
  }, target);
604
614
  });
605
615
  }
616
+ }, /*#__PURE__*/React.createElement("div", {
617
+ className: "".concat(prefixCls, "-menu-top-item-content")
606
618
  }, /*#__PURE__*/React.createElement("div", {
607
619
  className: "".concat(prefixCls, "-menu-icon")
608
620
  }, favoriteIcon), /*#__PURE__*/React.createElement("div", {
609
621
  className: "".concat(prefixCls, "-menu-title")
610
- }, "\u6536\u85CF"))), false && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
622
+ }, "\u6536\u85CF")))), false && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
611
623
  className: "".concat(prefixCls, "-menu-gutter")
612
624
  }), collapsed ? /*#__PURE__*/React.createElement("div", {
613
625
  className: "".concat(prefixCls, "-menu-top-item"),
@@ -17,8 +17,11 @@
17
17
  &-bar {
18
18
  position: relative;
19
19
  z-index: 3;
20
+ display: flex;
21
+ flex-direction: column;
20
22
  box-sizing: border-box;
21
23
  width: 100%;
24
+ height: 100%;
22
25
  background: #f2f2f2;
23
26
  }
24
27
 
@@ -49,11 +52,17 @@
49
52
  left: 52px;
50
53
  }
51
54
 
55
+ &-top-items {
56
+ overflow-x: hidden;
57
+ overflow-y: auto;
58
+
59
+ .scrollBar();
60
+ }
61
+
52
62
  &-top-item {
53
- display: flex;
54
- align-items: center;
55
63
  box-sizing: border-box;
56
64
  height: 44px;
65
+ min-height: 44px;
57
66
  padding: 0 16px;
58
67
  overflow: hidden;
59
68
  color: #333;
@@ -62,6 +71,15 @@
62
71
  cursor: pointer;
63
72
  .transition();
64
73
 
74
+ &-content {
75
+ position: relative;
76
+ left: 50%;
77
+ display: flex;
78
+ align-items: center;
79
+ height: 100%;
80
+ transform: translateX(-50%);
81
+ }
82
+
65
83
  &:hover,
66
84
  &-popover-active {
67
85
  background: #e6e6e6;
@@ -84,6 +102,12 @@
84
102
  }
85
103
  }
86
104
 
105
+ &-collapsed &-top-item-content {
106
+ width: 100%;
107
+ min-width: 20px;
108
+ overflow: hidden;
109
+ }
110
+
87
111
  &-icon {
88
112
  width: 20px;
89
113
  height: 20px;
@@ -1,12 +1,17 @@
1
- import type { ReactNode } from 'react';
2
- declare type ContentType = ReactNode | null;
1
+ import type { ReactElement } from 'react';
2
+ declare type ContentType = ReactElement | null;
3
3
  declare function PortalHost(props: {
4
4
  children: ContentType;
5
5
  }): JSX.Element;
6
+ declare function PortalSlot(props: {
7
+ slot: string;
8
+ }): ContentType;
6
9
  declare function Portal(props: {
7
- children?: ContentType;
8
- }): JSX.Element | null;
10
+ children: ContentType;
11
+ slot: string;
12
+ }): null;
9
13
  declare namespace Portal {
10
14
  var Host: typeof PortalHost;
15
+ var Slot: typeof PortalSlot;
11
16
  }
12
17
  export default Portal;
@@ -10,63 +10,132 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
- import React from 'react';
14
- import { createContext, memo, useContext, useEffect, useMemo, useState } from 'react';
15
- import { uniqueId } from 'lodash';
13
+ import React, { createContext, memo, useContext, useEffect, useMemo, useState } from 'react';
16
14
  var Slot = /*#__PURE__*/memo(function Content(props) {
17
- return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
15
+ return props.children;
18
16
  });
19
- var Context = /*#__PURE__*/createContext(null);
17
+ var Context = /*#__PURE__*/createContext({
18
+ set: function set() {},
19
+ delete: function _delete() {},
20
+ observable: {
21
+ subscribe: function subscribe() {
22
+ return {
23
+ unsubscribe: function unsubscribe() {}
24
+ };
25
+ },
26
+ get: function get() {
27
+ return new Map();
28
+ }
29
+ }
30
+ });
31
+
32
+ function Subject(initialData) {
33
+ var observers = [];
34
+ var data = initialData;
35
+ return {
36
+ get: function get() {
37
+ return data;
38
+ },
39
+ next: function next(state) {
40
+ data = state;
41
+ observers.forEach(function (item) {
42
+ return item.next(state);
43
+ });
44
+ },
45
+ subscribe: function subscribe(observer) {
46
+ observers.push(observer);
47
+ return {
48
+ unsubscribe: function unsubscribe() {
49
+ var index = observers.findIndex(function (item) {
50
+ return item === observer;
51
+ });
52
+
53
+ if (index >= 0) {
54
+ observers.splice(index, 1);
55
+ }
56
+ }
57
+ };
58
+ }
59
+ };
60
+ }
20
61
 
21
62
  function PortalHost(props) {
22
63
  var children = props.children;
23
64
 
24
- var _useState = useState(null),
65
+ var _useState = useState(new Map()),
25
66
  _useState2 = _slicedToArray(_useState, 2),
26
- content = _useState2[0],
27
- setContent = _useState2[1];
67
+ nodes = _useState2[0],
68
+ setNodes = _useState2[1];
28
69
 
70
+ var observable = useMemo(function () {
71
+ return Subject(nodes);
72
+ }, []);
29
73
  var portal = useMemo(function () {
30
74
  return {
31
- add: function add(key, node) {
32
- setContent({
33
- key: key,
34
- node: node
75
+ set: function set(key, node) {
76
+ setNodes(function (prev) {
77
+ var next = new Map(prev);
78
+ next.set(key, node);
79
+ return next;
35
80
  });
36
81
  },
37
- clear: function clear(key) {
38
- setContent(function (prev) {
39
- if ((prev === null || prev === void 0 ? void 0 : prev.key) === key) {
40
- return null;
41
- }
42
-
43
- return prev;
82
+ delete: function _delete(key) {
83
+ setNodes(function (prev) {
84
+ var next = new Map(prev);
85
+ next.delete(key);
86
+ return next;
44
87
  });
45
- }
88
+ },
89
+ observable: observable
46
90
  };
47
91
  }, []);
92
+ useEffect(function () {
93
+ observable.next(nodes);
94
+ }, [nodes]);
48
95
  return /*#__PURE__*/React.createElement(Context.Provider, {
49
96
  value: portal
50
- }, /*#__PURE__*/React.createElement(Slot, null, content ? content.node : null), /*#__PURE__*/React.createElement(Slot, null, children));
97
+ }, /*#__PURE__*/React.createElement(Slot, null, children));
98
+ }
99
+
100
+ function PortalSlot(props) {
101
+ var slot = props.slot;
102
+
103
+ var _useContext = useContext(Context),
104
+ observable = _useContext.observable;
105
+
106
+ var _useState3 = useState(observable.get().get(slot) || null),
107
+ _useState4 = _slicedToArray(_useState3, 2),
108
+ node = _useState4[0],
109
+ setNode = _useState4[1];
110
+
111
+ useEffect(function () {
112
+ var _observable$subscribe = observable.subscribe({
113
+ next: function next(state) {
114
+ setNode(state.get(slot) || null);
115
+ }
116
+ }),
117
+ unsubscribe = _observable$subscribe.unsubscribe;
118
+
119
+ return unsubscribe;
120
+ }, [slot]);
121
+ return node;
51
122
  }
52
123
 
53
124
  function Portal(props) {
54
- var _props$children = props.children,
55
- children = _props$children === void 0 ? null : _props$children;
125
+ var slot = props.slot,
126
+ children = props.children;
56
127
  var portal = useContext(Context);
57
- var key = useMemo(function () {
58
- return uniqueId('portal-');
59
- }, []);
60
128
  useEffect(function () {
61
- if (portal !== null) {
62
- portal.add(key, children);
63
- return function () {
64
- portal.clear(key);
65
- };
66
- }
67
- }, [portal, key, children]);
68
- return portal ? null : /*#__PURE__*/React.createElement(React.Fragment, null, children);
129
+ return function () {
130
+ portal.delete(slot);
131
+ };
132
+ }, [slot]);
133
+ useEffect(function () {
134
+ portal.set(slot, children);
135
+ }, [slot, children]);
136
+ return null;
69
137
  }
70
138
 
71
139
  Portal.Host = PortalHost;
140
+ Portal.Slot = PortalSlot;
72
141
  export default Portal;
package/es/overrides.less CHANGED
@@ -34,18 +34,7 @@ a[title='站长统计'] {
34
34
  }
35
35
 
36
36
  .ant-table-body {
37
- &::-webkit-scrollbar {
38
- width: 8px;
39
- height: 8px;
40
- }
41
-
42
- &::-webkit-scrollbar-thumb {
43
- background-color: #ddd;
44
- }
45
-
46
- &::-webkit-scrollbar-track {
47
- background-color: #fff;
48
- }
37
+ .scrollBar(8px);
49
38
  }
50
39
 
51
40
  .ant-table-tbody > tr.ant-table-row-selected > td {
package/es/utils.less CHANGED
@@ -89,3 +89,22 @@
89
89
  }
90
90
  }
91
91
  }
92
+
93
+ .scrollBar (@width: 6px) {
94
+ scrollbar-width: thin;
95
+
96
+ &::-webkit-scrollbar {
97
+ width: @width;
98
+ height: 8px;
99
+ }
100
+
101
+ &::-webkit-scrollbar-track {
102
+ background-color: #fff;
103
+ border-radius: 10px; // 滑块颜色
104
+ }
105
+
106
+ &::-webkit-scrollbar-thumb {
107
+ background-color: #ddd;
108
+ border-radius: 10px; // 滑块颜色
109
+ }
110
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "0.1.90",
3
+ "version": "0.1.95",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -39,5 +39,5 @@
39
39
  "react": "^17.0.2",
40
40
  "react-dom": "^17.0.2"
41
41
  },
42
- "gitHead": "a663b35b1cddf3fde745eaa0750d98758c08bd64"
42
+ "gitHead": "baee38c98ffbc650e0e4ad350c6d40cd96686104"
43
43
  }