@dtjoy/dt-design 1.0.1 → 1.0.2
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/esm/_util/gapSize.d.ts +3 -0
- package/esm/_util/gapSize.js +10 -0
- package/esm/_util/hooks/index.d.ts +1 -0
- package/esm/_util/hooks/index.js +1 -0
- package/esm/_util/hooks/useOrientation.d.ts +2 -0
- package/esm/_util/hooks/useOrientation.js +19 -0
- package/esm/_util/isNonNullable.d.ts +2 -0
- package/esm/_util/isNonNullable.js +4 -0
- package/esm/_util/type.d.ts +2 -1
- package/esm/blockHeader/index.js +12 -11
- package/esm/blockHeader/style/index.d.ts +1 -1
- package/esm/blockHeader/style/index.js +1 -1
- package/esm/blockHeader/style/index.less +8 -7
- package/esm/button/style/index.less +60 -46
- package/esm/button/style/mixin.less +47 -0
- package/esm/collapsible/index.d.ts +97 -0
- package/esm/collapsible/index.js +234 -0
- package/esm/collapsible/style/index.d.ts +1 -0
- package/esm/collapsible/style/index.js +1 -0
- package/esm/collapsible/style/index.less +24 -0
- package/esm/collapsibleActionItems/index.d.ts +24 -0
- package/esm/collapsibleActionItems/index.js +74 -0
- package/esm/collapsibleActionItems/style/index.d.ts +2 -0
- package/esm/collapsibleActionItems/style/index.js +2 -0
- package/esm/collapsibleActionItems/style/index.less +7 -0
- package/esm/flex/index.d.ts +7 -0
- package/esm/flex/index.js +62 -0
- package/esm/flex/interface.d.ts +16 -0
- package/esm/flex/interface.js +1 -0
- package/esm/flex/style/index.d.ts +2 -0
- package/esm/flex/style/index.js +2 -0
- package/esm/flex/style/index.less +77 -0
- package/esm/flex/utils.d.ts +7 -0
- package/esm/flex/utils.js +33 -0
- package/esm/index.d.ts +9 -0
- package/esm/index.js +7 -5
- package/esm/resize/index.d.ts +8 -0
- package/esm/resize/index.js +29 -0
- package/esm/splitter/Panel.d.ts +7 -0
- package/esm/splitter/Panel.js +38 -0
- package/esm/splitter/SplitBar.d.ts +24 -0
- package/esm/splitter/SplitBar.js +185 -0
- package/esm/splitter/Splitter.d.ts +5 -0
- package/esm/splitter/Splitter.js +215 -0
- package/esm/splitter/hooks/sizeUtil.d.ts +3 -0
- package/esm/splitter/hooks/sizeUtil.js +63 -0
- package/esm/splitter/hooks/useItems.d.ts +14 -0
- package/esm/splitter/hooks/useItems.js +44 -0
- package/esm/splitter/hooks/useResizable.d.ts +10 -0
- package/esm/splitter/hooks/useResizable.js +73 -0
- package/esm/splitter/hooks/useResize.d.ts +6 -0
- package/esm/splitter/hooks/useResize.js +158 -0
- package/esm/splitter/hooks/useSizes.d.ts +4 -0
- package/esm/splitter/hooks/useSizes.js +80 -0
- package/esm/splitter/index.d.ts +8 -0
- package/esm/splitter/index.js +5 -0
- package/esm/splitter/interface.d.ts +68 -0
- package/esm/splitter/interface.js +1 -0
- package/esm/splitter/style/index.d.ts +2 -0
- package/esm/splitter/style/index.js +2 -0
- package/esm/splitter/style/index.less +312 -0
- package/esm/statusTag/index.d.ts +28 -0
- package/esm/statusTag/index.js +122 -0
- package/esm/statusTag/style/index.d.ts +2 -0
- package/esm/statusTag/style/index.js +2 -0
- package/esm/statusTag/style/index.less +70 -0
- package/esm/statusTag/style/mixin.less +39 -0
- package/esm/style/mixins/index.less +0 -0
- package/esm/style/themes/index.less +2 -1
- package/esm/style/themes/variable.less +1 -0
- package/lib/_util/gapSize.d.ts +3 -0
- package/lib/_util/gapSize.js +17 -0
- package/lib/_util/hooks/index.d.ts +1 -0
- package/lib/_util/hooks/index.js +16 -0
- package/lib/_util/hooks/useOrientation.d.ts +2 -0
- package/lib/_util/hooks/useOrientation.js +26 -0
- package/lib/_util/isNonNullable.d.ts +2 -0
- package/lib/_util/isNonNullable.js +10 -0
- package/lib/_util/type.d.ts +2 -1
- package/lib/blockHeader/index.js +12 -12
- package/lib/blockHeader/style/index.d.ts +1 -1
- package/lib/blockHeader/style/index.js +1 -1
- package/lib/blockHeader/style/index.less +8 -7
- package/lib/button/style/index.less +60 -46
- package/lib/button/style/mixin.less +47 -0
- package/lib/collapsible/index.d.ts +97 -0
- package/lib/collapsible/index.js +199 -0
- package/lib/collapsible/style/index.d.ts +1 -0
- package/lib/collapsible/style/index.js +3 -0
- package/lib/collapsible/style/index.less +24 -0
- package/lib/collapsibleActionItems/index.d.ts +24 -0
- package/lib/collapsibleActionItems/index.js +68 -0
- package/lib/collapsibleActionItems/style/index.d.ts +2 -0
- package/lib/collapsibleActionItems/style/index.js +4 -0
- package/lib/collapsibleActionItems/style/index.less +7 -0
- package/lib/flex/index.d.ts +7 -0
- package/lib/flex/index.js +60 -0
- package/lib/flex/interface.d.ts +16 -0
- package/lib/flex/interface.js +5 -0
- package/lib/flex/style/index.d.ts +2 -0
- package/lib/flex/style/index.js +4 -0
- package/lib/flex/style/index.less +77 -0
- package/lib/flex/utils.d.ts +7 -0
- package/lib/flex/utils.js +39 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +65 -0
- package/lib/resize/index.d.ts +8 -0
- package/lib/resize/index.js +38 -0
- package/lib/splitter/Panel.d.ts +7 -0
- package/lib/splitter/Panel.js +44 -0
- package/lib/splitter/SplitBar.d.ts +24 -0
- package/lib/splitter/SplitBar.js +179 -0
- package/lib/splitter/Splitter.d.ts +5 -0
- package/lib/splitter/Splitter.js +202 -0
- package/lib/splitter/hooks/sizeUtil.d.ts +3 -0
- package/lib/splitter/hooks/sizeUtil.js +56 -0
- package/lib/splitter/hooks/useItems.d.ts +14 -0
- package/lib/splitter/hooks/useItems.js +46 -0
- package/lib/splitter/hooks/useResizable.d.ts +10 -0
- package/lib/splitter/hooks/useResizable.js +83 -0
- package/lib/splitter/hooks/useResize.d.ts +6 -0
- package/lib/splitter/hooks/useResize.js +142 -0
- package/lib/splitter/hooks/useSizes.d.ts +4 -0
- package/lib/splitter/hooks/useSizes.js +62 -0
- package/lib/splitter/index.d.ts +8 -0
- package/lib/splitter/index.js +12 -0
- package/lib/splitter/interface.d.ts +68 -0
- package/lib/splitter/interface.js +5 -0
- package/lib/splitter/style/index.d.ts +2 -0
- package/lib/splitter/style/index.js +4 -0
- package/lib/splitter/style/index.less +312 -0
- package/lib/statusTag/index.d.ts +28 -0
- package/lib/statusTag/index.js +125 -0
- package/lib/statusTag/style/index.d.ts +2 -0
- package/lib/statusTag/style/index.js +4 -0
- package/lib/statusTag/style/index.less +70 -0
- package/lib/statusTag/style/mixin.less +39 -0
- package/lib/style/mixins/index.less +0 -0
- package/lib/style/themes/index.less +2 -1
- package/lib/style/themes/variable.less +1 -0
- package/package.json +142 -141
package/lib/_util/type.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
+
export declare type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
2
3
|
/** https://github.com/Microsoft/TypeScript/issues/29729 */
|
|
3
|
-
export declare type LiteralUnion<T extends string> = T | (
|
|
4
|
+
export declare type LiteralUnion<T, U extends Primitive = string> = T | (U & Record<never, never>);
|
|
4
5
|
export declare type AnyObject = Record<string, any>;
|
|
5
6
|
export declare type CustomComponent<P = AnyObject> = React.ComponentType<P> | string;
|
|
6
7
|
/**
|
package/lib/blockHeader/index.js
CHANGED
|
@@ -10,14 +10,12 @@ var _antd = require("antd");
|
|
|
10
10
|
var _configProvider = require("antd/es/config-provider");
|
|
11
11
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
12
12
|
require("./style");
|
|
13
|
-
var _index = _interopRequireDefault(require("./style/index.less"));
|
|
14
13
|
var _util = require("../_util");
|
|
14
|
+
var _collapsible = _interopRequireDefault(require("../collapsible"));
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
17
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
console.log(_index.default);
|
|
18
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
21
19
|
function isControlled(props) {
|
|
22
20
|
return props.expand !== undefined;
|
|
23
21
|
}
|
|
@@ -46,15 +44,13 @@ const BlockHeader = function (props) {
|
|
|
46
44
|
titleStyle
|
|
47
45
|
} = props;
|
|
48
46
|
const [internalExpand, setInternalExpand] = (0, _react.useState)(defaultExpand);
|
|
49
|
-
// const locale = useLocale('BlockHeader');
|
|
50
|
-
|
|
51
47
|
const currentExpand = isControlled(props) ? expand : internalExpand;
|
|
52
48
|
|
|
53
49
|
// 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
|
|
54
50
|
const showCollapse = (typeof expand === 'boolean' || typeof defaultExpand === 'boolean') && children;
|
|
55
51
|
const tooltipProps = (0, _util.toTooltipProps)(tooltip);
|
|
56
52
|
let bottomStyle;
|
|
57
|
-
if (spaceBottom) bottomStyle = showCollapse && currentExpand ? {
|
|
53
|
+
if (spaceBottom) bottomStyle = showCollapse && !currentExpand ? {
|
|
58
54
|
marginBottom: 0
|
|
59
55
|
} : {
|
|
60
56
|
marginBottom: spaceBottom
|
|
@@ -85,7 +81,9 @@ const BlockHeader = function (props) {
|
|
|
85
81
|
className: "title__text"
|
|
86
82
|
}, title), tooltipProps?.title ? /*#__PURE__*/_react.default.createElement("div", {
|
|
87
83
|
className: `title__tooltip`
|
|
88
|
-
}, /*#__PURE__*/_react.default.createElement(_antd.Tooltip,
|
|
84
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Tooltip, _extends({}, tooltipProps, {
|
|
85
|
+
className: (0, _classnames.default)(tooltipProps?.className, 'anticon')
|
|
86
|
+
}), /*#__PURE__*/_react.default.createElement(_reactIcons.QuestionOutlined, null))) : null, description ? /*#__PURE__*/_react.default.createElement("div", {
|
|
89
87
|
className: `title__description`
|
|
90
88
|
}, description) : null), addonAfter && /*#__PURE__*/_react.default.createElement("div", {
|
|
91
89
|
className: `title__addon-after`
|
|
@@ -93,16 +91,18 @@ const BlockHeader = function (props) {
|
|
|
93
91
|
className: `title__collapse`
|
|
94
92
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
95
93
|
className: "collapse__text"
|
|
96
|
-
}), /*#__PURE__*/_react.default.createElement(_reactIcons.UpOutlined, {
|
|
97
|
-
className: (0, _classnames.default)('collapse__icon', {
|
|
94
|
+
}, currentExpand ? '收起' : '展开'), /*#__PURE__*/_react.default.createElement(_reactIcons.UpOutlined, {
|
|
95
|
+
className: (0, _classnames.default)('collapse__icon', 'anticon', {
|
|
98
96
|
'collapse__icon--up': currentExpand,
|
|
99
97
|
'collapse__icon--down': !currentExpand
|
|
100
98
|
})
|
|
101
|
-
}))),
|
|
99
|
+
}))), /*#__PURE__*/_react.default.createElement(_collapsible.default, {
|
|
100
|
+
isOpen: !currentExpand
|
|
101
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
102
102
|
className: (0, _classnames.default)(`${prefixCls}__content`, contentClassName, {
|
|
103
103
|
[`${prefixCls}__content--active`]: currentExpand || !showCollapse
|
|
104
104
|
}),
|
|
105
105
|
style: contentStyle
|
|
106
|
-
}, children));
|
|
106
|
+
}, children)));
|
|
107
107
|
};
|
|
108
108
|
var _default = exports.default = BlockHeader;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import '../../style
|
|
1
|
+
import '../../style';
|
|
2
2
|
import './index.less';
|
|
@@ -129,14 +129,15 @@
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
&__content {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
padding: 16px 24px;
|
|
133
|
+
|
|
134
|
+
// opacity: 0;
|
|
135
|
+
// height: 0;
|
|
136
|
+
// overflow: hidden;
|
|
137
|
+
// transition: opacity 0.5s ease, height 0.5s ease;
|
|
136
138
|
&--active {
|
|
137
|
-
opacity: 1;
|
|
138
|
-
|
|
139
|
-
height: auto;
|
|
139
|
+
// opacity: 1;
|
|
140
|
+
// height: auto;
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
}
|
|
@@ -1,120 +1,134 @@
|
|
|
1
1
|
@import '../../style/themes/index.less';
|
|
2
|
+
@import './mixin.less';
|
|
2
3
|
|
|
3
|
-
@prefix-cls: ~'@{ant-prefix}-btn';
|
|
4
|
+
@btn-prefix-cls: ~'@{ant-prefix}-btn';
|
|
4
5
|
|
|
5
|
-
.@{prefix-cls} {
|
|
6
|
+
.@{btn-prefix-cls} {
|
|
6
7
|
display: inline-flex;
|
|
7
8
|
align-items: center;
|
|
8
9
|
justify-content: center;
|
|
9
|
-
padding: 4px 16px;
|
|
10
10
|
|
|
11
|
+
// 引用中尺寸配置(核心:先调用混入,再取值)
|
|
12
|
+
.btn-size-middle();
|
|
13
|
+
padding: @padding;
|
|
14
|
+
|
|
15
|
+
// 图标样式
|
|
11
16
|
&__icon {
|
|
12
17
|
display: inline-flex;
|
|
13
18
|
align-items: center;
|
|
14
19
|
justify-content: center;
|
|
15
20
|
font-size: inherit;
|
|
16
21
|
line-height: 0;
|
|
17
|
-
|
|
22
|
+
|
|
18
23
|
.dtstack-icon {
|
|
19
24
|
font-size: inherit;
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
// 小尺寸图标
|
|
22
28
|
&--small {
|
|
23
|
-
|
|
29
|
+
.btn-size-small();
|
|
30
|
+
font-size: @icon-font-size;
|
|
24
31
|
}
|
|
25
|
-
|
|
32
|
+
// 中尺寸图标
|
|
26
33
|
&--middle {
|
|
27
|
-
|
|
34
|
+
.btn-size-middle();
|
|
35
|
+
font-size: @icon-font-size;
|
|
28
36
|
}
|
|
29
|
-
|
|
37
|
+
// 大尺寸图标
|
|
30
38
|
&--large {
|
|
31
|
-
|
|
39
|
+
.btn-size-large();
|
|
40
|
+
font-size: @icon-font-size;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
|
-
|
|
43
|
+
// 图标与文字间距
|
|
44
|
+
& + .@{btn-prefix-cls}__text {
|
|
35
45
|
&--small {
|
|
36
|
-
|
|
46
|
+
.btn-size-small();
|
|
47
|
+
margin-left: @icon-text-margin;
|
|
37
48
|
}
|
|
38
|
-
|
|
39
49
|
&--middle {
|
|
40
|
-
|
|
50
|
+
.btn-size-middle();
|
|
51
|
+
margin-left: @icon-text-margin;
|
|
41
52
|
}
|
|
42
|
-
|
|
43
53
|
&--large {
|
|
44
|
-
|
|
54
|
+
.btn-size-large();
|
|
55
|
+
margin-left: @icon-text-margin;
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
59
|
|
|
60
|
+
// 文字样式
|
|
49
61
|
&__text {
|
|
50
62
|
display: inline-block;
|
|
51
63
|
|
|
52
64
|
&--small {
|
|
53
|
-
|
|
65
|
+
.btn-size-small();
|
|
66
|
+
font-size: @text-font-size;
|
|
54
67
|
}
|
|
55
|
-
|
|
56
68
|
&--middle {
|
|
57
|
-
|
|
69
|
+
.btn-size-middle();
|
|
70
|
+
font-size: @text-font-size;
|
|
58
71
|
}
|
|
59
|
-
|
|
60
72
|
&--large {
|
|
61
|
-
|
|
73
|
+
.btn-size-large();
|
|
74
|
+
font-size: @text-font-size;
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
|
|
78
|
+
// 尺寸变体
|
|
65
79
|
&-sm {
|
|
66
|
-
|
|
80
|
+
.btn-size-small();
|
|
81
|
+
padding: @padding;
|
|
67
82
|
}
|
|
68
|
-
|
|
69
83
|
&-lg {
|
|
70
|
-
|
|
84
|
+
.btn-size-large();
|
|
85
|
+
padding: @padding;
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
&-primary
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
// 主要按钮
|
|
89
|
+
&-primary {
|
|
90
|
+
.btn-disabled-primary();
|
|
91
|
+
.generate-btn-disabled(@bg, @color, @border);
|
|
92
|
+
|
|
93
|
+
&:hover,
|
|
94
|
+
&:focus {
|
|
95
|
+
background-color: #225fdb;
|
|
96
|
+
}
|
|
78
97
|
}
|
|
79
98
|
|
|
99
|
+
// 次要按钮
|
|
80
100
|
&-secondary {
|
|
81
101
|
border-color: @primary-color;
|
|
82
102
|
color: @primary-color;
|
|
83
103
|
|
|
84
104
|
&:hover,
|
|
85
105
|
&:focus {
|
|
86
|
-
background-color: @
|
|
106
|
+
background-color: fade(@primary-color, 10%);
|
|
87
107
|
}
|
|
108
|
+
|
|
109
|
+
.btn-disabled-secondary-tertiary();
|
|
110
|
+
.generate-btn-disabled(@bg, @color, @border);
|
|
88
111
|
}
|
|
89
112
|
|
|
113
|
+
// 三级按钮
|
|
90
114
|
&-tertiary {
|
|
91
|
-
|
|
115
|
+
background-color: #f3f3f3;
|
|
92
116
|
border-color: @border-color-base;
|
|
93
117
|
|
|
94
118
|
&:hover,
|
|
95
119
|
&:focus {
|
|
96
|
-
background-color: @
|
|
120
|
+
background-color: fade(@primary-color, 10%);
|
|
97
121
|
border-color: @primary-color;
|
|
98
122
|
color: @primary-color;
|
|
99
123
|
}
|
|
100
|
-
}
|
|
101
124
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
&[disabled],
|
|
105
|
-
&[disabled]:hover {
|
|
106
|
-
background: #f3f3f3;
|
|
107
|
-
color: @disabled-color;
|
|
108
|
-
border-color: @border-color-base;
|
|
109
|
-
}
|
|
125
|
+
.btn-disabled-secondary-tertiary();
|
|
126
|
+
.generate-btn-disabled(@bg, @color, @border);
|
|
110
127
|
}
|
|
111
128
|
|
|
129
|
+
// 默认按钮
|
|
112
130
|
&-default {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
background: transparent;
|
|
116
|
-
color: @disabled-color;
|
|
117
|
-
border-color: @border-color-base;
|
|
118
|
-
}
|
|
131
|
+
.btn-disabled-default();
|
|
132
|
+
.generate-btn-disabled(@bg, @color, @border);
|
|
119
133
|
}
|
|
120
134
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
.btn-size-small() {
|
|
2
|
+
@padding: 2px 12px;
|
|
3
|
+
@icon-font-size: 12px;
|
|
4
|
+
@text-font-size: 12px;
|
|
5
|
+
@icon-text-margin: 2px;
|
|
6
|
+
}
|
|
7
|
+
.btn-size-middle() {
|
|
8
|
+
@padding: 4px 16px;
|
|
9
|
+
@icon-font-size: 16px;
|
|
10
|
+
@text-font-size: 14px;
|
|
11
|
+
@icon-text-margin: 8px;
|
|
12
|
+
}
|
|
13
|
+
.btn-size-large() {
|
|
14
|
+
@padding: 3px 40px;
|
|
15
|
+
@icon-font-size: 18px;
|
|
16
|
+
@text-font-size: 14px;
|
|
17
|
+
@icon-text-margin: 8px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 禁用状态配置(同样用混入)
|
|
21
|
+
.btn-disabled-primary() {
|
|
22
|
+
@bg: @disabled-color;
|
|
23
|
+
@color: #F9F9F9;
|
|
24
|
+
@border: @disabled-color;
|
|
25
|
+
}
|
|
26
|
+
.btn-disabled-secondary-tertiary() {
|
|
27
|
+
@bg: @primary-color-disabled;
|
|
28
|
+
@color: @disabled-color;
|
|
29
|
+
@border: @border-color-base;
|
|
30
|
+
}
|
|
31
|
+
.btn-disabled-default() {
|
|
32
|
+
@bg: transparent;
|
|
33
|
+
@color: @disabled-color;
|
|
34
|
+
@border: @border-color-base;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// ===================== 工具混入 =====================
|
|
38
|
+
.generate-btn-disabled(@bg, @color, @border) {
|
|
39
|
+
&[disabled],
|
|
40
|
+
&[disabled]:hover {
|
|
41
|
+
background: @bg;
|
|
42
|
+
color: @color;
|
|
43
|
+
border-color: @border;
|
|
44
|
+
cursor: not-allowed;
|
|
45
|
+
opacity: 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './style';
|
|
3
|
+
interface BaseComponentProps {
|
|
4
|
+
/**
|
|
5
|
+
* 类名
|
|
6
|
+
*/
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 样式
|
|
10
|
+
*/
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
/**
|
|
13
|
+
* id
|
|
14
|
+
*/
|
|
15
|
+
id?: string;
|
|
16
|
+
'data-*'?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CollapsibleProps extends BaseComponentProps {
|
|
19
|
+
/**
|
|
20
|
+
* 是否开启动画
|
|
21
|
+
*/
|
|
22
|
+
motion?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* 子元素
|
|
25
|
+
*/
|
|
26
|
+
children?: React.ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* 是否展开内容区域
|
|
29
|
+
*/
|
|
30
|
+
isOpen?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 动画执行的时间
|
|
33
|
+
*/
|
|
34
|
+
duration?: number;
|
|
35
|
+
/**
|
|
36
|
+
* 是否保留隐藏的面板 DOM 树,默认销毁
|
|
37
|
+
*/
|
|
38
|
+
keepDOM?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 配合 keepDOM 使用,为 true 时挂载时不会渲染组件
|
|
41
|
+
*/
|
|
42
|
+
lazyRender?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 折叠高度
|
|
45
|
+
*/
|
|
46
|
+
collapseHeight?: number;
|
|
47
|
+
/**
|
|
48
|
+
* 当 reCalcKey 改变时,将重新计算子节点的高度,用于优化动态渲染时的计算
|
|
49
|
+
*/
|
|
50
|
+
reCalcKey?: number | string;
|
|
51
|
+
/**
|
|
52
|
+
* 动画结束的回调
|
|
53
|
+
*/
|
|
54
|
+
onMotionEnd?: () => void;
|
|
55
|
+
/**
|
|
56
|
+
* 是否开启淡入淡出
|
|
57
|
+
*/
|
|
58
|
+
fade?: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface CollapsibleState {
|
|
61
|
+
domInRenderTree: boolean;
|
|
62
|
+
domHeight: number;
|
|
63
|
+
visible: boolean;
|
|
64
|
+
isTransitioning: boolean;
|
|
65
|
+
cacheIsOpen: boolean;
|
|
66
|
+
}
|
|
67
|
+
declare class Collapsible extends React.Component<CollapsibleProps, CollapsibleState> {
|
|
68
|
+
static defaultProps: {
|
|
69
|
+
isOpen: boolean;
|
|
70
|
+
duration: number;
|
|
71
|
+
motion: boolean;
|
|
72
|
+
keepDOM: boolean;
|
|
73
|
+
lazyRender: boolean;
|
|
74
|
+
collapseHeight: number;
|
|
75
|
+
fade: boolean;
|
|
76
|
+
};
|
|
77
|
+
prefixCls: string;
|
|
78
|
+
foundation: any;
|
|
79
|
+
private domRef;
|
|
80
|
+
private resizeObserver;
|
|
81
|
+
private hasBeenRendered;
|
|
82
|
+
static displayName: string;
|
|
83
|
+
constructor(props: CollapsibleProps);
|
|
84
|
+
private handleResize;
|
|
85
|
+
private isChildrenInRenderTree;
|
|
86
|
+
static getEntryInfo: (entry: ResizeObserverEntry) => {
|
|
87
|
+
isShown: boolean;
|
|
88
|
+
height: number;
|
|
89
|
+
};
|
|
90
|
+
private getDataAttr;
|
|
91
|
+
componentDidMount(): void;
|
|
92
|
+
static getDerivedStateFromProps(props: CollapsibleProps, prevState: CollapsibleState): Partial<CollapsibleState>;
|
|
93
|
+
componentDidUpdate(prevProps: Readonly<CollapsibleProps>, prevState: Readonly<CollapsibleState>): void;
|
|
94
|
+
componentWillUnmount(): void;
|
|
95
|
+
render(): React.JSX.Element;
|
|
96
|
+
}
|
|
97
|
+
export default Collapsible;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _configProvider = require("antd/es/config-provider");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _lodash = require("lodash");
|
|
11
|
+
require("./style");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
14
|
+
class Collapsible extends _react.default.Component {
|
|
15
|
+
static defaultProps = {
|
|
16
|
+
isOpen: false,
|
|
17
|
+
duration: 250,
|
|
18
|
+
motion: true,
|
|
19
|
+
keepDOM: false,
|
|
20
|
+
lazyRender: false,
|
|
21
|
+
collapseHeight: 0,
|
|
22
|
+
fade: false
|
|
23
|
+
};
|
|
24
|
+
prefixCls = 'collapsible';
|
|
25
|
+
foundation;
|
|
26
|
+
domRef = /*#__PURE__*/_react.default.createRef();
|
|
27
|
+
resizeObserver = null;
|
|
28
|
+
hasBeenRendered = false;
|
|
29
|
+
static displayName;
|
|
30
|
+
// public cssClasses = {
|
|
31
|
+
// PREFIX: 'ant-collapsible',
|
|
32
|
+
// TRANSITION: 'ant-collapsible-transition',
|
|
33
|
+
// WRAPPER: 'ant-collapsible-wrapper',
|
|
34
|
+
// };
|
|
35
|
+
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super(props);
|
|
38
|
+
this.state = {
|
|
39
|
+
domInRenderTree: false,
|
|
40
|
+
domHeight: 0,
|
|
41
|
+
visible: this.props.isOpen || false,
|
|
42
|
+
isTransitioning: false,
|
|
43
|
+
cacheIsOpen: this.props.isOpen || false
|
|
44
|
+
};
|
|
45
|
+
this.prefixCls = `${(0, _configProvider.globalConfig)().getPrefixCls(this.prefixCls)}`;
|
|
46
|
+
this.foundation = {
|
|
47
|
+
updateDOMInRenderTree: val => this.setState({
|
|
48
|
+
domInRenderTree: val
|
|
49
|
+
}),
|
|
50
|
+
updateDOMHeight: val => this.setState({
|
|
51
|
+
domHeight: val
|
|
52
|
+
}),
|
|
53
|
+
updateVisible: val => this.setState({
|
|
54
|
+
visible: val
|
|
55
|
+
}),
|
|
56
|
+
updateIsTransitioning: val => this.setState({
|
|
57
|
+
isTransitioning: val
|
|
58
|
+
})
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
handleResize = entryList => {
|
|
62
|
+
const entry = entryList[0];
|
|
63
|
+
if (entry) {
|
|
64
|
+
const entryInfo = Collapsible.getEntryInfo(entry);
|
|
65
|
+
this.foundation.updateDOMHeight(entryInfo.height);
|
|
66
|
+
this.foundation.updateDOMInRenderTree(entryInfo.isShown);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
isChildrenInRenderTree = () => {
|
|
70
|
+
if (this.domRef.current) {
|
|
71
|
+
return this.domRef.current.offsetHeight > 0;
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
static getEntryInfo = entry => {
|
|
76
|
+
let inRenderTree;
|
|
77
|
+
if (entry.borderBoxSize) {
|
|
78
|
+
inRenderTree = !(entry.borderBoxSize[0].blockSize === 0 && entry.borderBoxSize[0].inlineSize === 0);
|
|
79
|
+
} else {
|
|
80
|
+
inRenderTree = !(entry.contentRect.height === 0 && entry.contentRect.width === 0);
|
|
81
|
+
}
|
|
82
|
+
let height = 0;
|
|
83
|
+
if (entry.borderBoxSize) {
|
|
84
|
+
height = Math.ceil(entry.borderBoxSize[0].blockSize);
|
|
85
|
+
} else {
|
|
86
|
+
const target = entry.target;
|
|
87
|
+
height = target.clientHeight;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
isShown: inRenderTree,
|
|
91
|
+
height
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
getDataAttr = props => {
|
|
95
|
+
const dataAttrs = {};
|
|
96
|
+
Object.keys(props).forEach(key => {
|
|
97
|
+
if (key.startsWith('data-')) {
|
|
98
|
+
dataAttrs[key] = String(props[key]);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return dataAttrs;
|
|
102
|
+
};
|
|
103
|
+
componentDidMount() {
|
|
104
|
+
this.resizeObserver = new ResizeObserver(this.handleResize);
|
|
105
|
+
if (this.domRef.current) {
|
|
106
|
+
this.resizeObserver.observe(this.domRef.current);
|
|
107
|
+
}
|
|
108
|
+
const domInRenderTree = this.isChildrenInRenderTree();
|
|
109
|
+
this.foundation.updateDOMInRenderTree(domInRenderTree);
|
|
110
|
+
if (domInRenderTree && this.domRef.current) {
|
|
111
|
+
this.foundation.updateDOMHeight(this.domRef.current.scrollHeight);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
static getDerivedStateFromProps(props, prevState) {
|
|
115
|
+
const newState = {};
|
|
116
|
+
const isOpenChanged = props.isOpen !== prevState.cacheIsOpen;
|
|
117
|
+
if (isOpenChanged) {
|
|
118
|
+
if (props.isOpen || !props.motion) {
|
|
119
|
+
newState.visible = props.isOpen;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (props.motion && isOpenChanged) {
|
|
123
|
+
newState.isTransitioning = true;
|
|
124
|
+
}
|
|
125
|
+
newState.cacheIsOpen = props.isOpen;
|
|
126
|
+
return newState;
|
|
127
|
+
}
|
|
128
|
+
componentDidUpdate(prevProps, prevState) {
|
|
129
|
+
const changedPropKeys = Object.keys((0, _lodash.pick)(this.props, ['reCalcKey'])).filter(key => !(0, _lodash.isEqual)(this.props[key], prevProps[key]));
|
|
130
|
+
const changedStateKeys = Object.keys((0, _lodash.pick)(this.state, ['domInRenderTree'])).filter(key => !(0, _lodash.isEqual)(this.state[key], prevState[key]));
|
|
131
|
+
if (changedPropKeys.includes('reCalcKey') && this.domRef.current) {
|
|
132
|
+
this.foundation.updateDOMHeight(this.domRef.current.scrollHeight);
|
|
133
|
+
}
|
|
134
|
+
if (changedStateKeys.includes('domInRenderTree') && this.state.domInRenderTree && this.domRef.current) {
|
|
135
|
+
this.foundation.updateDOMHeight(this.domRef.current.scrollHeight);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
componentWillUnmount() {
|
|
139
|
+
if (this.resizeObserver) {
|
|
140
|
+
this.resizeObserver.disconnect();
|
|
141
|
+
this.resizeObserver = null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
render() {
|
|
145
|
+
const {
|
|
146
|
+
isOpen,
|
|
147
|
+
collapseHeight,
|
|
148
|
+
fade,
|
|
149
|
+
motion,
|
|
150
|
+
duration,
|
|
151
|
+
style,
|
|
152
|
+
className,
|
|
153
|
+
id,
|
|
154
|
+
keepDOM,
|
|
155
|
+
lazyRender,
|
|
156
|
+
onMotionEnd
|
|
157
|
+
} = this.props;
|
|
158
|
+
const {
|
|
159
|
+
domHeight,
|
|
160
|
+
isTransitioning,
|
|
161
|
+
visible
|
|
162
|
+
} = this.state;
|
|
163
|
+
const wrapperStyle = {
|
|
164
|
+
overflow: 'hidden',
|
|
165
|
+
height: isOpen ? domHeight : collapseHeight,
|
|
166
|
+
opacity: isOpen || !fade || collapseHeight !== 0 ? 1 : 0,
|
|
167
|
+
transitionDuration: `${motion && isTransitioning ? duration : 0}ms`,
|
|
168
|
+
...style
|
|
169
|
+
};
|
|
170
|
+
const wrapperCls = (0, _classnames.default)(`${this.prefixCls}-wrapper`, {
|
|
171
|
+
[`${this.prefixCls}-transition`]: motion && isTransitioning
|
|
172
|
+
}, className);
|
|
173
|
+
const shouldRender = keepDOM && (lazyRender ? this.hasBeenRendered : true) || collapseHeight !== 0 || visible || isOpen;
|
|
174
|
+
if (shouldRender && !this.hasBeenRendered) {
|
|
175
|
+
this.hasBeenRendered = true;
|
|
176
|
+
}
|
|
177
|
+
return /*#__PURE__*/_react.default.createElement("div", _extends({
|
|
178
|
+
className: wrapperCls,
|
|
179
|
+
style: wrapperStyle,
|
|
180
|
+
onTransitionEnd: () => {
|
|
181
|
+
if (!isOpen) {
|
|
182
|
+
this.foundation.updateVisible(false);
|
|
183
|
+
}
|
|
184
|
+
this.foundation.updateIsTransitioning(false);
|
|
185
|
+
onMotionEnd?.();
|
|
186
|
+
}
|
|
187
|
+
}, this.getDataAttr(this.props)), /*#__PURE__*/_react.default.createElement("div", {
|
|
188
|
+
ref: this.domRef,
|
|
189
|
+
style: {
|
|
190
|
+
overflow: 'hidden'
|
|
191
|
+
},
|
|
192
|
+
id: id
|
|
193
|
+
}, shouldRender && this.props.children));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
197
|
+
Collapsible.displayName = 'Collapsible';
|
|
198
|
+
}
|
|
199
|
+
var _default = exports.default = Collapsible;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './index.less';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@import '../../style/themes/index.less';
|
|
2
|
+
|
|
3
|
+
@collapsible-prefix-cls: ~'@{ant-prefix}-collapsible';
|
|
4
|
+
|
|
5
|
+
@transition-duration-collapsible-height: 250ms;
|
|
6
|
+
@transition-function-collapsible-height: cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
7
|
+
@transition-delay-collapsible-height: 0ms;
|
|
8
|
+
|
|
9
|
+
@transition-duration-collapsible-opacity: 250ms;
|
|
10
|
+
@transition-function-collapsible-opacity: @ease-in;
|
|
11
|
+
@transition-delay-collapsible-opacity: 0ms;
|
|
12
|
+
|
|
13
|
+
// 容器基础样式
|
|
14
|
+
.@{collapsible-prefix-cls}-wrapper {
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 过渡动画样式
|
|
19
|
+
.@{collapsible-prefix-cls}-transition {
|
|
20
|
+
transition: height @transition-duration-collapsible-height
|
|
21
|
+
@transition-function-collapsible-height @transition-delay-collapsible-height,
|
|
22
|
+
opacity @transition-duration-collapsible-opacity @transition-function-collapsible-opacity
|
|
23
|
+
@transition-delay-collapsible-opacity;
|
|
24
|
+
}
|