@aloudata/aloudata-design 0.2.0-beta.16 → 0.2.0-beta.19
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/Button/style/index.less +1 -1
- package/es/Input/components/Input/index.d.ts +10 -5
- package/es/Input/style/index.less +31 -2
- package/es/Navigator/components/Menu/index.js +2 -2
- package/es/Select/BaseSelect.js +0 -2
- package/es/Select/OptionsList/OptionItem/RenderLabelIcon.d.ts +1 -0
- package/es/Select/OptionsList/OptionItem/RenderLabelIcon.js +1 -0
- package/es/Select/OptionsList/index.js +12 -19
- package/es/Select/Selector/index.js +7 -5
- package/es/Select/interface.d.ts +3 -0
- package/es/Select/style/index.less +39 -7
- package/es/Table/index.d.ts +1 -1
- package/es/Table/index.js +78 -40
- package/es/Table/interface.d.ts +3 -1
- package/es/Table/style/index.less +3 -5
- package/es/Tabs/index.js +2 -1
- package/es/Tabs/style/index.less +8 -1
- package/lib/Button/style/index.less +1 -1
- package/lib/Input/components/Input/index.d.ts +10 -5
- package/lib/Input/style/index.less +31 -2
- package/lib/Navigator/components/Menu/index.js +2 -2
- package/lib/Select/BaseSelect.js +0 -2
- package/lib/Select/OptionsList/OptionItem/RenderLabelIcon.d.ts +1 -0
- package/lib/Select/OptionsList/OptionItem/RenderLabelIcon.js +2 -0
- package/lib/Select/OptionsList/index.js +11 -19
- package/lib/Select/Selector/index.js +7 -5
- package/lib/Select/interface.d.ts +3 -0
- package/lib/Select/style/index.less +39 -7
- package/lib/Table/index.d.ts +1 -1
- package/lib/Table/index.js +78 -40
- package/lib/Table/interface.d.ts +3 -1
- package/lib/Table/style/index.less +3 -5
- package/lib/Tabs/index.js +2 -1
- package/lib/Tabs/style/index.less +8 -1
- package/package.json +2 -1
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { InputProps, InputRef } from 'antd/lib/input/Input';
|
|
3
|
+
interface IShowCountProps {
|
|
4
|
+
formatter: (args: {
|
|
5
|
+
count: number;
|
|
6
|
+
maxLength?: number;
|
|
7
|
+
}) => string;
|
|
8
|
+
}
|
|
4
9
|
export declare type TSize = 'small' | 'default' | 'large';
|
|
5
|
-
export
|
|
10
|
+
export type { InputRef };
|
|
6
11
|
declare type ChangeEventHandler = (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
7
12
|
export interface IInputProps extends Omit<InputProps, 'size' | 'id' | 'prefix' | 'allowClear' | 'disabled' | 'showCount' | 'maxLength' | 'value' | 'defaultValue' | 'onPressEnter' | 'onChange'> {
|
|
8
13
|
/**
|
|
@@ -33,7 +38,7 @@ export interface IInputProps extends Omit<InputProps, 'size' | 'id' | 'prefix' |
|
|
|
33
38
|
* @default false
|
|
34
39
|
* @type boolean | { formatter: (args: { count: number; maxLength?: number; }) => string; };
|
|
35
40
|
*/
|
|
36
|
-
showCount?: boolean |
|
|
41
|
+
showCount?: boolean | IShowCountProps;
|
|
37
42
|
/**
|
|
38
43
|
* @description 最大长度
|
|
39
44
|
*/
|
|
@@ -57,5 +62,5 @@ export interface IInputProps extends Omit<InputProps, 'size' | 'id' | 'prefix' |
|
|
|
57
62
|
*/
|
|
58
63
|
onChange?: ChangeEventHandler;
|
|
59
64
|
}
|
|
60
|
-
declare const Input: React.ForwardRefExoticComponent<IInputProps & React.RefAttributes<
|
|
65
|
+
declare const Input: React.ForwardRefExoticComponent<IInputProps & React.RefAttributes<InputRef>>;
|
|
61
66
|
export default Input;
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
.ant-input {
|
|
9
9
|
color: @NL0;
|
|
10
10
|
border-radius: @border-radius-base;
|
|
11
|
+
font-size: 12px;
|
|
12
|
+
height: 28px;
|
|
11
13
|
|
|
12
14
|
&::placeholder {
|
|
13
15
|
color: @NL50;
|
|
@@ -15,6 +17,9 @@
|
|
|
15
17
|
|
|
16
18
|
&-prefix {
|
|
17
19
|
color: @NL30;
|
|
20
|
+
font-weight: 400;
|
|
21
|
+
font-size: 12px;
|
|
22
|
+
line-height: 16px;
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
&-suffix {
|
|
@@ -39,10 +44,19 @@
|
|
|
39
44
|
|
|
40
45
|
&-sm {
|
|
41
46
|
border-radius: @border-radius-sm;
|
|
47
|
+
font-size: 12px;
|
|
48
|
+
height: 24px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
&-lg {
|
|
52
|
+
height: 32px;
|
|
53
|
+
font-size: 14px;
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
&-affix-wrapper {
|
|
45
57
|
border-radius: @border-radius-base;
|
|
58
|
+
padding: 0 12px;
|
|
59
|
+
height: 28px;
|
|
46
60
|
|
|
47
61
|
&-hover,
|
|
48
62
|
&-focused,
|
|
@@ -53,10 +67,25 @@
|
|
|
53
67
|
.ant-input {
|
|
54
68
|
border-radius: 0;
|
|
55
69
|
caret-color: @B40;
|
|
70
|
+
height: 100%;
|
|
56
71
|
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.ant-input-affix-wrapper.ant-input-affix-wrapper {
|
|
76
|
+
&-lg {
|
|
77
|
+
padding: 4px 11px;
|
|
78
|
+
height: 32px;
|
|
79
|
+
font-size: 14px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&-sm {
|
|
83
|
+
border-radius: @border-radius-sm;
|
|
84
|
+
padding: 0 12px;
|
|
85
|
+
height: 24px;
|
|
57
86
|
|
|
58
|
-
|
|
59
|
-
|
|
87
|
+
.ant-input-sm {
|
|
88
|
+
height: 22px;
|
|
60
89
|
}
|
|
61
90
|
}
|
|
62
91
|
}
|
|
@@ -47,14 +47,14 @@ function Menu(props) {
|
|
|
47
47
|
|
|
48
48
|
if (isOpen) {
|
|
49
49
|
return /*#__PURE__*/React.createElement(Icon, {
|
|
50
|
-
type: "
|
|
50
|
+
type: "arrow_drop_up",
|
|
51
51
|
size: 20,
|
|
52
52
|
className: "ald-nav-menu-icon-right"
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return /*#__PURE__*/React.createElement(Icon, {
|
|
57
|
-
type: "
|
|
57
|
+
type: "arrow_drop_down",
|
|
58
58
|
size: 20,
|
|
59
59
|
className: "ald-nav-menu-icon-right"
|
|
60
60
|
});
|
package/es/Select/BaseSelect.js
CHANGED
|
@@ -48,7 +48,6 @@ export var Select = function Select(props, ref) {
|
|
|
48
48
|
label = props.label,
|
|
49
49
|
className = props.className,
|
|
50
50
|
style = props.style,
|
|
51
|
-
optionStyle = props.optionStyle,
|
|
52
51
|
groupStyle = props.groupStyle,
|
|
53
52
|
_props$allowClear = props.allowClear,
|
|
54
53
|
allowClear = _props$allowClear === void 0 ? false : _props$allowClear,
|
|
@@ -314,7 +313,6 @@ export var Select = function Select(props, ref) {
|
|
|
314
313
|
visible: visible,
|
|
315
314
|
hasGroup: hasGroup,
|
|
316
315
|
groupStyle: groupStyle,
|
|
317
|
-
optionStyle: optionStyle,
|
|
318
316
|
searchType: "no-search",
|
|
319
317
|
placeholder: placeholder,
|
|
320
318
|
data: flattenOptions,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["input", "prefixCls", "data", "groupStyle", "height", "itemHeight", "selected", "optionChecked", "tempValue", "value", "placeholder", "notFoundContent", "onValueChange", "onTempValueChange", "setTempValue", "onInputChange", "onOptionClick", "activeIndex", "multiple", "visible", "
|
|
1
|
+
var _excluded = ["input", "prefixCls", "data", "groupStyle", "height", "itemHeight", "selected", "optionChecked", "tempValue", "value", "placeholder", "notFoundContent", "onValueChange", "onTempValueChange", "setTempValue", "onInputChange", "onOptionClick", "activeIndex", "multiple", "visible", "setActiveIndex"];
|
|
2
2
|
|
|
3
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
@@ -25,17 +25,19 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
25
25
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
26
26
|
import React, { useCallback, useImperativeHandle, useMemo, useRef, useEffect } from 'react';
|
|
27
27
|
import classnames from 'classnames';
|
|
28
|
-
import
|
|
29
|
-
import { ForwardRenderGroup, ForwardRenderOption, ForwardRenderTooltip, RenderLabelIcon } from './OptionItem';
|
|
28
|
+
import { ForwardRenderOption, ForwardRenderTooltip, RenderLabelIcon } from './OptionItem';
|
|
30
29
|
var ZERO_LENGTH = 0;
|
|
31
30
|
var DEFAULT_ACTIVE_INDEX = -1;
|
|
31
|
+
var DEFAULT_LIST_HEIGHT = 256;
|
|
32
|
+
var DEFAULT_LIST_PADDING = 8;
|
|
32
33
|
|
|
33
34
|
var OptionsList = function OptionsList(props, ref) {
|
|
34
35
|
var input = props.input,
|
|
35
36
|
prefixCls = props.prefixCls,
|
|
36
37
|
data = props.data,
|
|
37
38
|
groupStyle = props.groupStyle,
|
|
38
|
-
height = props.height,
|
|
39
|
+
_props$height = props.height,
|
|
40
|
+
height = _props$height === void 0 ? DEFAULT_LIST_HEIGHT : _props$height,
|
|
39
41
|
itemHeight = props.itemHeight,
|
|
40
42
|
selected = props.selected,
|
|
41
43
|
optionChecked = props.optionChecked,
|
|
@@ -51,7 +53,6 @@ var OptionsList = function OptionsList(props, ref) {
|
|
|
51
53
|
activeIndex = props.activeIndex,
|
|
52
54
|
multiple = props.multiple,
|
|
53
55
|
visible = props.visible,
|
|
54
|
-
style = props.style,
|
|
55
56
|
setActiveIndex = props.setActiveIndex,
|
|
56
57
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
57
58
|
|
|
@@ -146,7 +147,9 @@ var OptionsList = function OptionsList(props, ref) {
|
|
|
146
147
|
|
|
147
148
|
return /*#__PURE__*/React.createElement("div", {
|
|
148
149
|
className: "".concat(prefixCls, "-list"),
|
|
149
|
-
style:
|
|
150
|
+
style: {
|
|
151
|
+
maxHeight: "".concat(height - DEFAULT_LIST_PADDING, "px")
|
|
152
|
+
},
|
|
150
153
|
ref: OptionListRef,
|
|
151
154
|
role: "list",
|
|
152
155
|
"aria-hidden": "true",
|
|
@@ -155,20 +158,10 @@ var OptionsList = function OptionsList(props, ref) {
|
|
|
155
158
|
onMouseLeave: function onMouseLeave() {
|
|
156
159
|
return setActiveIndex(DEFAULT_ACTIVE_INDEX);
|
|
157
160
|
}
|
|
158
|
-
}, multiple && renderAllOptions(), data.length > ZERO_LENGTH ?
|
|
159
|
-
|
|
160
|
-
prefixCls: prefixCls,
|
|
161
|
-
ref: VirtualListRef,
|
|
162
|
-
data: data,
|
|
163
|
-
height: height,
|
|
164
|
-
itemHeight: itemHeight
|
|
165
|
-
}, restProps), function (option, index) {
|
|
166
|
-
return option.isSelectOptGroup ? /*#__PURE__*/React.createElement(ForwardRenderGroup, {
|
|
167
|
-
option: option,
|
|
168
|
-
prefixCls: prefixCls,
|
|
169
|
-
groupStyle: groupStyle
|
|
170
|
-
}) : /*#__PURE__*/React.createElement(ForwardRenderTooltip, {
|
|
161
|
+
}, multiple && renderAllOptions(), data.length > ZERO_LENGTH ? data.map(function (option, index) {
|
|
162
|
+
return /*#__PURE__*/React.createElement(ForwardRenderTooltip, {
|
|
171
163
|
tooltip: option === null || option === void 0 ? void 0 : option.tooltip,
|
|
164
|
+
key: option === null || option === void 0 ? void 0 : option.value,
|
|
172
165
|
render: /*#__PURE__*/React.createElement(ForwardRenderOption, _objectSpread({
|
|
173
166
|
option: option,
|
|
174
167
|
prefixCls: prefixCls,
|
|
@@ -40,6 +40,8 @@ import color from '../../style/themes/default/themeColor.module.less';
|
|
|
40
40
|
var ZERO = 0;
|
|
41
41
|
var ICON_LARGE_SIZE = 20;
|
|
42
42
|
var ICON_SMALL_SIZE = 16;
|
|
43
|
+
var FIRST_INDEX = 0;
|
|
44
|
+
var REVERSE_INDEX = -1;
|
|
43
45
|
|
|
44
46
|
var defaultArrowComponent = function defaultArrowComponent(prefix, size) {
|
|
45
47
|
return /*#__PURE__*/React.createElement(Icon, {
|
|
@@ -163,17 +165,17 @@ var Selector = function Selector(props, ref) {
|
|
|
163
165
|
|
|
164
166
|
var renderMultipleValue = function renderMultipleValue() {
|
|
165
167
|
// @ts-ignore
|
|
166
|
-
var
|
|
168
|
+
var allTooltipTitleNode = value === null || value === void 0 ? void 0 : value.reduce(function (prev, curr) {
|
|
167
169
|
var item = getOptionByValue(curr);
|
|
168
170
|
|
|
169
171
|
if (item) {
|
|
170
|
-
return [].concat(_toConsumableArray(prev), [(item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.label)]);
|
|
172
|
+
return [].concat(_toConsumableArray(prev), [(item === null || item === void 0 ? void 0 : item.title) || optionLabelRenderer(curr, getOptionByValue(curr)) || (item === null || item === void 0 ? void 0 : item.label), ',']);
|
|
171
173
|
}
|
|
172
174
|
|
|
173
|
-
return [].concat(_toConsumableArray(prev), [curr]);
|
|
175
|
+
return [].concat(_toConsumableArray(prev), [curr, ',']);
|
|
174
176
|
}, []);
|
|
175
177
|
|
|
176
|
-
if (Array.isArray(value) && value.length === filteredOptions.length) {
|
|
178
|
+
if (Array.isArray(value) && value.length === filteredOptions.length && !isEmpty(value)) {
|
|
177
179
|
return /*#__PURE__*/React.createElement("span", null, "\u5168\u90E8");
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -188,7 +190,7 @@ var Selector = function Selector(props, ref) {
|
|
|
188
190
|
return !input && !isNil(value) ? /*#__PURE__*/React.createElement(Tooltip // @ts-ignore
|
|
189
191
|
, {
|
|
190
192
|
// @ts-ignore
|
|
191
|
-
title:
|
|
193
|
+
title: allTooltipTitleNode.slice(FIRST_INDEX, REVERSE_INDEX),
|
|
192
194
|
placement: "top",
|
|
193
195
|
getTooltipContainer: function getTooltipContainer() {
|
|
194
196
|
var _selectorRef$current4;
|
package/es/Select/interface.d.ts
CHANGED
|
@@ -117,6 +117,9 @@ export interface ISelectProps {
|
|
|
117
117
|
labelRenderer?: (input: string) => (option: IOption, isGroup: boolean) => React.ReactNode;
|
|
118
118
|
searchPredicate?: (input: string) => _.ListIterateeCustom<IOption, boolean>;
|
|
119
119
|
matchPredicate?: (input: string) => _.ListIterateeCustom<IOption, boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* @description 渲染选中条目对应的内容
|
|
122
|
+
*/
|
|
120
123
|
optionLabelRenderer?: (value: string | number, option?: IOption) => React.ReactNode;
|
|
121
124
|
/**
|
|
122
125
|
* @description 选中值改变时的回调
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// Base Text
|
|
36
36
|
// @text-color-base: #313e75;
|
|
37
37
|
// @text-color-disabled: #313e75;
|
|
38
|
-
@text-font-size
|
|
38
|
+
@text-font-base-size: 14px;
|
|
39
39
|
// @text-lint-height-base: 22px;
|
|
40
40
|
|
|
41
41
|
//Background Color
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
|
|
45
45
|
@ald-prefix: ~'@{component-prefix}';
|
|
46
46
|
@select-prefix-cls-legacy: ~'@{component-prefix}-select-legacy';
|
|
47
|
-
@select-input-fontSize: @text-font-size
|
|
48
|
-
@select-input-fontSize-sm: @text-font-size
|
|
47
|
+
@select-input-fontSize: @text-font-base-size;
|
|
48
|
+
@select-input-fontSize-sm: @text-font-base-size - 2px;
|
|
49
49
|
// @color-font-list-primary-normal: @palette-black-6; // $color-black-6
|
|
50
50
|
// @color-box-shadow-focused: #c0c4d3;
|
|
51
51
|
// @color-background-matchHeight: #ffcf3c;
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
overflow: hidden;
|
|
57
57
|
border: 1px solid transparent;
|
|
58
58
|
border-radius: @border-radius-base;
|
|
59
|
-
padding: 0 36px 0
|
|
59
|
+
padding: 0 36px 0 11px;
|
|
60
60
|
outline: none;
|
|
61
61
|
transition: all 0.2s;
|
|
62
62
|
cursor: pointer;
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
&-close {
|
|
142
142
|
position: absolute;
|
|
143
143
|
top: 0;
|
|
144
|
-
right:
|
|
144
|
+
right: 8px;
|
|
145
145
|
display: flex;
|
|
146
146
|
align-items: center;
|
|
147
147
|
justify-content: center;
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
|
|
163
163
|
&-text {
|
|
164
164
|
overflow: hidden;
|
|
165
|
-
font-size:
|
|
165
|
+
font-size: @select-input-fontSize-sm;
|
|
166
166
|
line-height: 22px;
|
|
167
167
|
white-space: nowrap;
|
|
168
168
|
text-overflow: ellipsis;
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
|
|
198
198
|
&-text {
|
|
199
199
|
overflow: hidden;
|
|
200
|
-
font-size:
|
|
200
|
+
font-size: @select-input-fontSize-sm;
|
|
201
201
|
line-height: 22px;
|
|
202
202
|
white-space: nowrap;
|
|
203
203
|
text-overflow: ellipsis;
|
|
@@ -209,6 +209,7 @@
|
|
|
209
209
|
top: 0;
|
|
210
210
|
left: 0;
|
|
211
211
|
color: @select-placeholder-color;
|
|
212
|
+
font-size: @select-input-fontSize-sm;
|
|
212
213
|
}
|
|
213
214
|
|
|
214
215
|
&-input {
|
|
@@ -282,7 +283,27 @@
|
|
|
282
283
|
}
|
|
283
284
|
}
|
|
284
285
|
|
|
286
|
+
&-default {
|
|
287
|
+
height: 28px;
|
|
288
|
+
.@{select-prefix-cls-legacy} {
|
|
289
|
+
&-selector {
|
|
290
|
+
height: 26px;
|
|
291
|
+
min-height: 26px;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
&-values-wrapper {
|
|
295
|
+
line-height: 26px;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
&-selector-label {
|
|
299
|
+
height: 26px;
|
|
300
|
+
font-size: 12px;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
285
305
|
&-large {
|
|
306
|
+
height: @height-lg;
|
|
286
307
|
.@{select-prefix-cls-legacy} {
|
|
287
308
|
&-selector {
|
|
288
309
|
min-height: @height-lg;
|
|
@@ -310,6 +331,14 @@
|
|
|
310
331
|
&-input-tags {
|
|
311
332
|
top: 0;
|
|
312
333
|
}
|
|
334
|
+
|
|
335
|
+
&-placeholder {
|
|
336
|
+
font-size: @select-input-fontSize;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
&-item-text {
|
|
340
|
+
font-size: @select-input-fontSize;
|
|
341
|
+
}
|
|
313
342
|
}
|
|
314
343
|
}
|
|
315
344
|
|
|
@@ -406,6 +435,8 @@
|
|
|
406
435
|
// min-width: 160px;
|
|
407
436
|
// padding: 16px 0 16px 8px;
|
|
408
437
|
outline: none;
|
|
438
|
+
overflow-y: scroll;
|
|
439
|
+
overflow-y: overlay;
|
|
409
440
|
}
|
|
410
441
|
|
|
411
442
|
.@{select-prefix-cls-legacy}-list-option {
|
|
@@ -434,6 +465,7 @@
|
|
|
434
465
|
transform: translateY(-50%);
|
|
435
466
|
left: 12px;
|
|
436
467
|
color: @B40;
|
|
468
|
+
margin-top: -2px;
|
|
437
469
|
|
|
438
470
|
&-checkbox {
|
|
439
471
|
.@{component-prefix}-checkbox-inner {
|
package/es/Table/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ITableProps } from './interface';
|
|
3
|
-
declare const _default: React.ForwardRefExoticComponent<Pick<ITableProps<Record<string, unknown>>, "onChange" | "loading" | "data" | "columns" | "total" | "renderHeaderLeft" | "renderHeaderRight" | "onRowSelected" | "loadMore" | "hasNextPage" | "sortable" | "defaultSort" | "resizeColumn" | "sortDirections" | "showHeader" | "innerScroll"> & React.RefAttributes<unknown>>;
|
|
3
|
+
declare const _default: React.ForwardRefExoticComponent<Pick<ITableProps<Record<string, unknown>>, "onChange" | "loading" | "data" | "columns" | "total" | "renderHeaderLeft" | "renderHeaderRight" | "onRowSelected" | "loadMore" | "hasNextPage" | "sortable" | "defaultSort" | "resizeColumn" | "sortDirections" | "showHeader" | "innerScroll" | "scrollThreshold" | "rowKey"> & React.RefAttributes<unknown>>;
|
|
4
4
|
export default _default;
|
package/es/Table/index.js
CHANGED
|
@@ -23,6 +23,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
23
23
|
|
|
24
24
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
25
|
|
|
26
|
+
/* eslint-disable no-unneeded-ternary */
|
|
26
27
|
/// <reference types ='./react-table-config' />
|
|
27
28
|
import _ from 'lodash';
|
|
28
29
|
import classnames from 'classnames';
|
|
@@ -31,6 +32,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
31
32
|
import usePrefixCls from '../_utils/hooks/usePrefixCls';
|
|
32
33
|
import InfiniteScroll from 'react-infinite-scroll-component';
|
|
33
34
|
import Empty from '../Empty';
|
|
35
|
+
import ResizeObserver from 'rc-resize-observer';
|
|
34
36
|
import { useTable, useBlockLayout, useRowSelect, useSortBy, useResizeColumns } from 'react-table';
|
|
35
37
|
var ARRAY_FIRST_INDEX = 0;
|
|
36
38
|
var DEFAULT_ROW_WIDTH = 0;
|
|
@@ -57,7 +59,10 @@ function Table(_ref, ref) {
|
|
|
57
59
|
_ref$onChange = _ref.onChange,
|
|
58
60
|
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
59
61
|
_ref$innerScroll = _ref.innerScroll,
|
|
60
|
-
innerScroll = _ref$innerScroll === void 0 ? false : _ref$innerScroll
|
|
62
|
+
innerScroll = _ref$innerScroll === void 0 ? false : _ref$innerScroll,
|
|
63
|
+
_ref$scrollThreshold = _ref.scrollThreshold,
|
|
64
|
+
scrollThreshold = _ref$scrollThreshold === void 0 ? '150px' : _ref$scrollThreshold,
|
|
65
|
+
rowKey = _ref.rowKey;
|
|
61
66
|
|
|
62
67
|
var _React$useState = React.useState(null),
|
|
63
68
|
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
@@ -73,11 +78,18 @@ function Table(_ref, ref) {
|
|
|
73
78
|
setTableClientWidth = _useState2[1];
|
|
74
79
|
|
|
75
80
|
var RANDOM_ID = "INNER_SCROLL_ID_".concat(Math.random());
|
|
81
|
+
|
|
82
|
+
var _useState3 = useState(DEFAULT_ROW_WIDTH),
|
|
83
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
84
|
+
width = _useState4[0],
|
|
85
|
+
setWidth = _useState4[1]; // 如果页面整体宽度变化则重新计算
|
|
86
|
+
|
|
87
|
+
|
|
76
88
|
useEffect(function () {
|
|
77
89
|
if (tableRef.current) {
|
|
78
90
|
setTableClientWidth(tableRef.current.clientWidth);
|
|
79
91
|
}
|
|
80
|
-
}, []);
|
|
92
|
+
}, [width]);
|
|
81
93
|
var initialColumnsWidthMap = useMemo(function () {
|
|
82
94
|
var map = new Map();
|
|
83
95
|
|
|
@@ -125,7 +137,12 @@ function Table(_ref, ref) {
|
|
|
125
137
|
}
|
|
126
138
|
});
|
|
127
139
|
});
|
|
128
|
-
}, [columns, sortable, initialColumnsWidthMap]);
|
|
140
|
+
}, [columns, sortable, initialColumnsWidthMap]); // 默认排序的对象
|
|
141
|
+
|
|
142
|
+
var defaultSortObject = {
|
|
143
|
+
id: newColumns[ARRAY_FIRST_INDEX].accessor,
|
|
144
|
+
desc: newColumns[ARRAY_FIRST_INDEX].sortOrder && newColumns[ARRAY_FIRST_INDEX].sortOrder === 'descend' ? true : false
|
|
145
|
+
}; // 如果支持排序 但是没有默认排序 则默认按第一列倒叙排序
|
|
129
146
|
|
|
130
147
|
var getInitialSortDirection = function getInitialSortDirection() {
|
|
131
148
|
if (defaultSort && defaultSort.id) {
|
|
@@ -133,10 +150,7 @@ function Table(_ref, ref) {
|
|
|
133
150
|
}
|
|
134
151
|
|
|
135
152
|
if (sortable) {
|
|
136
|
-
return
|
|
137
|
-
id: newColumns[ARRAY_FIRST_INDEX].accessor,
|
|
138
|
-
desc: false
|
|
139
|
-
};
|
|
153
|
+
return defaultSortObject;
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
return {
|
|
@@ -171,6 +185,9 @@ function Table(_ref, ref) {
|
|
|
171
185
|
data: data,
|
|
172
186
|
disableMultiSort: true,
|
|
173
187
|
disableSortBy: !sortable,
|
|
188
|
+
getRowId: typeof rowKey === 'string' ? function () {
|
|
189
|
+
return rowKey;
|
|
190
|
+
} : rowKey,
|
|
174
191
|
initialState: {
|
|
175
192
|
sortBy: getInitSortBy()
|
|
176
193
|
}
|
|
@@ -202,41 +219,65 @@ function Table(_ref, ref) {
|
|
|
202
219
|
}, "\u5171\u8BA1", total || len, "\u6761"), /*#__PURE__*/React.createElement("div", {
|
|
203
220
|
className: classnames("".concat(prefixCls, "-header-right"))
|
|
204
221
|
}, renderHeaderRight ? renderHeaderRight() : null));
|
|
205
|
-
};
|
|
222
|
+
}; // 排序的方向 倒叙{ id: 'xx', desc: true }、正序{ id: 'xx', desc: false }、无序 { id: '', desc: undefined }
|
|
223
|
+
// 获取排序方向以及排序的id
|
|
224
|
+
|
|
206
225
|
|
|
207
|
-
var
|
|
226
|
+
var getSortBy = function getSortBy(id) {
|
|
208
227
|
var sortDirections = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['ascend', 'descend'];
|
|
209
|
-
var
|
|
228
|
+
var // 如果传了sortDirections,则使用传入的,否则使用默认的
|
|
229
|
+
sortOrder = arguments.length > 2 ? arguments[2] : undefined;
|
|
230
|
+
var res = {
|
|
231
|
+
id: id,
|
|
232
|
+
desc: undefined // 给个默认的排序
|
|
233
|
+
|
|
234
|
+
};
|
|
235
|
+
var isSameCol = sortDirection.id === id;
|
|
210
236
|
var descMap = new Map([['ascend', false], ['descend', true]]);
|
|
211
|
-
var directions = allSortDirections || sortDirections;
|
|
237
|
+
var directions = allSortDirections || sortDirections; // 如果不是同一列 则返回默认排序 或者排序顺序的第一个
|
|
238
|
+
|
|
239
|
+
if (!isSameCol) {
|
|
240
|
+
if (sortOrder === 'ascend' || sortOrder === 'descend') {
|
|
241
|
+
res.desc = descMap.get(sortOrder);
|
|
242
|
+
} else {
|
|
243
|
+
res.desc = sortOrder ? sortOrder : descMap.get(directions[ARRAY_FIRST_INDEX]);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return res;
|
|
247
|
+
} // 如果是同一列
|
|
248
|
+
// 如果列给了默认的sortOrder则不在变化
|
|
249
|
+
|
|
212
250
|
|
|
213
251
|
if (sortOrder === 'ascend' || sortOrder === 'descend') {
|
|
214
|
-
|
|
215
|
-
|
|
252
|
+
res.desc = descMap.get(sortOrder);
|
|
253
|
+
return res;
|
|
254
|
+
} // 在所有方向上 往后取一个
|
|
216
255
|
|
|
217
|
-
if (typeof currentDesc === 'undefined') {
|
|
218
|
-
return descMap.get(directions[ARRAY_FIRST_INDEX]);
|
|
219
|
-
}
|
|
220
256
|
|
|
221
|
-
var
|
|
257
|
+
var lastSortDirection = sortDirection.desc ? 'descend' : 'ascend';
|
|
222
258
|
|
|
223
259
|
var index = _.findIndex(directions, function (item) {
|
|
224
|
-
return item ===
|
|
260
|
+
return item === lastSortDirection;
|
|
225
261
|
});
|
|
226
262
|
|
|
227
263
|
var nextIndex = index + 1;
|
|
228
|
-
|
|
264
|
+
res.desc = descMap.get(directions[nextIndex]); // 如果没有排序方向,则返回默认排序对象
|
|
265
|
+
|
|
266
|
+
if (res.desc === undefined) {
|
|
267
|
+
res.id = '';
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return res;
|
|
229
271
|
};
|
|
230
272
|
|
|
231
273
|
var getHeaderProps = function getHeaderProps(column) {
|
|
232
274
|
// @ts-ignore
|
|
233
275
|
var id = column.id,
|
|
234
|
-
isSortedDesc = column.isSortedDesc,
|
|
235
276
|
canSort = column.canSort,
|
|
236
277
|
sorter = column.sorter,
|
|
237
278
|
sortOrder = column.sortOrder,
|
|
238
279
|
sortDirections = column.sortDirections;
|
|
239
|
-
var toggleProps = column.getSortByToggleProps();
|
|
280
|
+
var toggleProps = column.getSortByToggleProps(); // 仅在Table设置sortable时,所有列的canSort为true,此时为前端排序
|
|
240
281
|
|
|
241
282
|
if (canSort) {
|
|
242
283
|
// client sort
|
|
@@ -245,19 +286,16 @@ function Table(_ref, ref) {
|
|
|
245
286
|
e.stopPropagation();
|
|
246
287
|
|
|
247
288
|
if (typeof toggleProps.onClick === 'function') {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
id: typeof desc === 'undefined' ? '' : id,
|
|
252
|
-
desc: desc
|
|
253
|
-
};
|
|
254
|
-
setSortBy(typeof desc === 'undefined' ? [] : [sortBy]);
|
|
289
|
+
var sortBy = getSortBy(id, sortDirections, sortOrder);
|
|
290
|
+
setSortBy(sortBy.desc === undefined ? [defaultSortObject] : [sortBy]); // 客户端排序时 需要重新设置排序
|
|
291
|
+
|
|
255
292
|
setSortDirection(sortBy);
|
|
256
293
|
onChange(sortBy);
|
|
257
294
|
}
|
|
258
295
|
}
|
|
259
296
|
});
|
|
260
|
-
}
|
|
297
|
+
} // 当列设置sorter属性时,则为服务端排序
|
|
298
|
+
|
|
261
299
|
|
|
262
300
|
if (sorter) {
|
|
263
301
|
// server sort
|
|
@@ -267,14 +305,8 @@ function Table(_ref, ref) {
|
|
|
267
305
|
}
|
|
268
306
|
})), {}, {
|
|
269
307
|
onClick: function onClick(e) {
|
|
270
|
-
e.stopPropagation();
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
var desc = getNextSortDesc(sortDirection.desc, sortDirections, sortOrder);
|
|
274
|
-
var sortBy = {
|
|
275
|
-
id: typeof desc === 'boolean' ? id : '',
|
|
276
|
-
desc: desc
|
|
277
|
-
};
|
|
308
|
+
e.stopPropagation();
|
|
309
|
+
var sortBy = getSortBy(id, sortDirections, sortOrder);
|
|
278
310
|
setSortDirection(sortBy);
|
|
279
311
|
onChange(sortBy);
|
|
280
312
|
}
|
|
@@ -370,11 +402,17 @@ function Table(_ref, ref) {
|
|
|
370
402
|
next: loadMore,
|
|
371
403
|
hasMore: !!hasNextPage,
|
|
372
404
|
loader: LoadingNode,
|
|
373
|
-
scrollableTarget: RANDOM_ID
|
|
405
|
+
scrollableTarget: RANDOM_ID,
|
|
406
|
+
scrollThreshold: scrollThreshold
|
|
374
407
|
}, renderRowList()) : renderRowList());
|
|
375
408
|
};
|
|
376
409
|
|
|
377
|
-
return /*#__PURE__*/React.createElement(
|
|
410
|
+
return /*#__PURE__*/React.createElement(ResizeObserver, {
|
|
411
|
+
onResize: function onResize(_ref4) {
|
|
412
|
+
var domWidth = _ref4.width;
|
|
413
|
+
setWidth(domWidth);
|
|
414
|
+
}
|
|
415
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
378
416
|
className: prefixCls,
|
|
379
417
|
ref: tableRef
|
|
380
418
|
}, showHeader && renderHeader(data.length), /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({}, getTableProps()), {}, {
|
|
@@ -415,7 +453,7 @@ function Table(_ref, ref) {
|
|
|
415
453
|
style: {
|
|
416
454
|
width: totalColumnsWidth
|
|
417
455
|
}
|
|
418
|
-
}), renderTableBody())));
|
|
456
|
+
}), renderTableBody()))));
|
|
419
457
|
}
|
|
420
458
|
|
|
421
459
|
export default /*#__PURE__*/React.forwardRef(Table);
|
package/es/Table/interface.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface ISort<T> {
|
|
|
8
8
|
export interface IColumn<T extends object> {
|
|
9
9
|
title: string | null;
|
|
10
10
|
dataIndex: string;
|
|
11
|
-
render?: (value: any, row:
|
|
11
|
+
render?: (value: any, row: any, index: number) => React.ReactNode;
|
|
12
12
|
width?: number;
|
|
13
13
|
minWidth?: number;
|
|
14
14
|
sorter?: boolean | 'string' | 'number' | 'basic' | 'datetime' | 'alphanumeric' | ((rowA: Row<T>, rowB: Row<T>, columnId: IdType<T>, desc?: boolean) => number);
|
|
@@ -34,4 +34,6 @@ export interface ITableProps<T extends object> {
|
|
|
34
34
|
showHeader?: boolean;
|
|
35
35
|
innerScroll?: boolean;
|
|
36
36
|
ref?: React.RefObject<unknown>;
|
|
37
|
+
scrollThreshold?: string | number;
|
|
38
|
+
rowKey?: string | ((row: T) => string);
|
|
37
39
|
}
|