@dtjoy/dt-design 1.0.9 → 1.1.1
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/blockHeader/index.d.ts +13 -9
- package/esm/blockHeader/index.js +34 -23
- package/lib/blockHeader/index.d.ts +13 -9
- package/lib/blockHeader/index.js +28 -21
- package/package.json +1 -1
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import './style';
|
|
4
|
-
import type { SizeType } from 'antd/
|
|
3
|
+
import type { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
5
4
|
import type { LabelTooltipType } from '../_util';
|
|
6
5
|
export interface IBlockHeaderProps {
|
|
7
6
|
/** id */
|
|
8
7
|
id?: string;
|
|
9
8
|
/** 标题 */
|
|
10
|
-
title: ReactNode;
|
|
9
|
+
title: React.ReactNode;
|
|
11
10
|
/** 标题前的图标,默认是一个色块 */
|
|
12
|
-
addonBefore?: ReactNode;
|
|
11
|
+
addonBefore?: React.ReactNode;
|
|
13
12
|
/** 标题后的提示说明文字 */
|
|
14
|
-
description?: ReactNode;
|
|
13
|
+
description?: React.ReactNode;
|
|
15
14
|
/** 默认展示为问号的tooltip */
|
|
16
15
|
tooltip?: LabelTooltipType;
|
|
17
16
|
/** 后缀自定义内容块 */
|
|
18
|
-
addonAfter?: ReactNode;
|
|
17
|
+
addonAfter?: React.ReactNode;
|
|
19
18
|
/**
|
|
20
19
|
* 小标题 font-size: 12px; line-height: 32px
|
|
21
20
|
* 中标题 font-size: 14px; line-height: 40px
|
|
@@ -24,7 +23,10 @@ export interface IBlockHeaderProps {
|
|
|
24
23
|
*/
|
|
25
24
|
size?: SizeType;
|
|
26
25
|
/** 自定义 Bottom 值 */
|
|
27
|
-
spaceBottom?:
|
|
26
|
+
spaceBottom?: {
|
|
27
|
+
expand?: number;
|
|
28
|
+
collapse?: number;
|
|
29
|
+
} | number;
|
|
28
30
|
/** 标题一行的样式类名 */
|
|
29
31
|
className?: string;
|
|
30
32
|
/** 标题的样式类名 */
|
|
@@ -37,10 +39,12 @@ export interface IBlockHeaderProps {
|
|
|
37
39
|
background?: boolean;
|
|
38
40
|
/** 当前展开状态 */
|
|
39
41
|
expand?: boolean;
|
|
40
|
-
/**
|
|
42
|
+
/** 是否可展开, 默认 true */
|
|
43
|
+
expandable?: boolean;
|
|
44
|
+
/** 是否默认展开内容, 默认为 false */
|
|
41
45
|
defaultExpand?: boolean;
|
|
42
46
|
/** 展开/收起的内容 */
|
|
43
|
-
children?: ReactNode;
|
|
47
|
+
children?: React.ReactNode;
|
|
44
48
|
/** 展开/收起时的回调 */
|
|
45
49
|
onExpand?: (expand: boolean) => void;
|
|
46
50
|
/** 标题的样式 */
|
package/esm/blockHeader/index.js
CHANGED
|
@@ -11,7 +11,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
11
11
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
12
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
-
|
|
14
|
+
// 优化后的代码示例
|
|
15
|
+
import React, { useMemo, useState } from 'react';
|
|
15
16
|
import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
|
|
16
17
|
import { Tooltip } from 'antd';
|
|
17
18
|
import { globalConfig } from 'antd/es/config-provider';
|
|
@@ -33,7 +34,10 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
33
34
|
_props$size = props.size,
|
|
34
35
|
size = _props$size === void 0 ? 'middle' : _props$size,
|
|
35
36
|
_props$spaceBottom = props.spaceBottom,
|
|
36
|
-
spaceBottom = _props$spaceBottom === void 0 ?
|
|
37
|
+
spaceBottom = _props$spaceBottom === void 0 ? {
|
|
38
|
+
expand: 16,
|
|
39
|
+
collapse: 16
|
|
40
|
+
} : _props$spaceBottom,
|
|
37
41
|
_props$className = props.className,
|
|
38
42
|
className = _props$className === void 0 ? '' : _props$className,
|
|
39
43
|
_props$contentClassNa = props.contentClassName,
|
|
@@ -44,7 +48,8 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
44
48
|
contentStyle = _props$contentStyle === void 0 ? {} : _props$contentStyle,
|
|
45
49
|
_props$background = props.background,
|
|
46
50
|
background = _props$background === void 0 ? true : _props$background,
|
|
47
|
-
defaultExpand = props.defaultExpand,
|
|
51
|
+
_props$defaultExpand = props.defaultExpand,
|
|
52
|
+
defaultExpand = _props$defaultExpand === void 0 ? true : _props$defaultExpand,
|
|
48
53
|
addonAfter = props.addonAfter,
|
|
49
54
|
expand = props.expand,
|
|
50
55
|
_props$children = props.children,
|
|
@@ -55,27 +60,35 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
55
60
|
}) : _props$addonBefore,
|
|
56
61
|
onExpand = props.onExpand,
|
|
57
62
|
titleStyle = props.titleStyle,
|
|
58
|
-
keepDOM = props.keepDOM,
|
|
59
|
-
|
|
63
|
+
_props$keepDOM = props.keepDOM,
|
|
64
|
+
keepDOM = _props$keepDOM === void 0 ? false : _props$keepDOM,
|
|
65
|
+
_props$lazy = props.lazy,
|
|
66
|
+
lazy = _props$lazy === void 0 ? false : _props$lazy,
|
|
67
|
+
_props$expandable = props.expandable,
|
|
68
|
+
expandable = _props$expandable === void 0 ? true : _props$expandable;
|
|
60
69
|
var _useState = useState(defaultExpand),
|
|
61
70
|
_useState2 = _slicedToArray(_useState, 2),
|
|
62
71
|
internalExpand = _useState2[0],
|
|
63
72
|
setInternalExpand = _useState2[1];
|
|
64
|
-
var currentExpand = isControlled(props) ? expand : internalExpand;
|
|
65
|
-
|
|
66
|
-
// 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
|
|
67
|
-
var showCollapse = (typeof expand === 'boolean' || typeof defaultExpand === 'boolean') && children;
|
|
73
|
+
var currentExpand = isControlled(props) ? expand !== null && expand !== void 0 ? expand : false : internalExpand;
|
|
74
|
+
var showCollapse = expandable && !!children;
|
|
68
75
|
var tooltipProps = toTooltipProps(tooltip);
|
|
69
|
-
var bottomStyle = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
var bottomStyle = useMemo(function () {
|
|
77
|
+
var _spaceBottom$key;
|
|
78
|
+
if (typeof spaceBottom === 'number') {
|
|
79
|
+
return {
|
|
80
|
+
marginBottom: spaceBottom
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var key = currentExpand ? 'expand' : 'collapse';
|
|
84
|
+
return {
|
|
85
|
+
marginBottom: (_spaceBottom$key = spaceBottom[key]) !== null && _spaceBottom$key !== void 0 ? _spaceBottom$key : 0
|
|
86
|
+
};
|
|
87
|
+
}, [spaceBottom, currentExpand]);
|
|
88
|
+
var handleExpand = function handleExpand() {
|
|
89
|
+
var newExpandState = !currentExpand;
|
|
90
|
+
!isControlled(props) && setInternalExpand(newExpandState);
|
|
91
|
+
onExpand === null || onExpand === void 0 || onExpand(newExpandState);
|
|
79
92
|
};
|
|
80
93
|
return /*#__PURE__*/React.createElement("div", {
|
|
81
94
|
id: id,
|
|
@@ -84,9 +97,7 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
84
97
|
}, /*#__PURE__*/React.createElement("div", {
|
|
85
98
|
className: clsx(preTitleRowCls, "".concat(preTitleRowCls, "--").concat(size), _defineProperty(_defineProperty({}, "".concat(preTitleRowCls, "--background"), background), "".concat(preTitleRowCls, "--pointer"), showCollapse)),
|
|
86
99
|
style: titleStyle,
|
|
87
|
-
onClick:
|
|
88
|
-
return showCollapse && handleExpand(!currentExpand);
|
|
89
|
-
}
|
|
100
|
+
onClick: showCollapse ? handleExpand : undefined
|
|
90
101
|
}, /*#__PURE__*/React.createElement("div", {
|
|
91
102
|
className: "title__box"
|
|
92
103
|
}, addonBefore ? /*#__PURE__*/React.createElement("div", {
|
|
@@ -111,7 +122,7 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
111
122
|
'collapse__icon--down': !currentExpand
|
|
112
123
|
})
|
|
113
124
|
}))), /*#__PURE__*/React.createElement(Collapsible, {
|
|
114
|
-
isOpen:
|
|
125
|
+
isOpen: currentExpand,
|
|
115
126
|
keepDOM: keepDOM,
|
|
116
127
|
lazyRender: lazy
|
|
117
128
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import './style';
|
|
4
|
-
import type { SizeType } from 'antd/
|
|
3
|
+
import type { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
5
4
|
import type { LabelTooltipType } from '../_util';
|
|
6
5
|
export interface IBlockHeaderProps {
|
|
7
6
|
/** id */
|
|
8
7
|
id?: string;
|
|
9
8
|
/** 标题 */
|
|
10
|
-
title: ReactNode;
|
|
9
|
+
title: React.ReactNode;
|
|
11
10
|
/** 标题前的图标,默认是一个色块 */
|
|
12
|
-
addonBefore?: ReactNode;
|
|
11
|
+
addonBefore?: React.ReactNode;
|
|
13
12
|
/** 标题后的提示说明文字 */
|
|
14
|
-
description?: ReactNode;
|
|
13
|
+
description?: React.ReactNode;
|
|
15
14
|
/** 默认展示为问号的tooltip */
|
|
16
15
|
tooltip?: LabelTooltipType;
|
|
17
16
|
/** 后缀自定义内容块 */
|
|
18
|
-
addonAfter?: ReactNode;
|
|
17
|
+
addonAfter?: React.ReactNode;
|
|
19
18
|
/**
|
|
20
19
|
* 小标题 font-size: 12px; line-height: 32px
|
|
21
20
|
* 中标题 font-size: 14px; line-height: 40px
|
|
@@ -24,7 +23,10 @@ export interface IBlockHeaderProps {
|
|
|
24
23
|
*/
|
|
25
24
|
size?: SizeType;
|
|
26
25
|
/** 自定义 Bottom 值 */
|
|
27
|
-
spaceBottom?:
|
|
26
|
+
spaceBottom?: {
|
|
27
|
+
expand?: number;
|
|
28
|
+
collapse?: number;
|
|
29
|
+
} | number;
|
|
28
30
|
/** 标题一行的样式类名 */
|
|
29
31
|
className?: string;
|
|
30
32
|
/** 标题的样式类名 */
|
|
@@ -37,10 +39,12 @@ export interface IBlockHeaderProps {
|
|
|
37
39
|
background?: boolean;
|
|
38
40
|
/** 当前展开状态 */
|
|
39
41
|
expand?: boolean;
|
|
40
|
-
/**
|
|
42
|
+
/** 是否可展开, 默认 true */
|
|
43
|
+
expandable?: boolean;
|
|
44
|
+
/** 是否默认展开内容, 默认为 false */
|
|
41
45
|
defaultExpand?: boolean;
|
|
42
46
|
/** 展开/收起的内容 */
|
|
43
|
-
children?: ReactNode;
|
|
47
|
+
children?: React.ReactNode;
|
|
44
48
|
/** 展开/收起时的回调 */
|
|
45
49
|
onExpand?: (expand: boolean) => void;
|
|
46
50
|
/** 标题的样式 */
|
package/lib/blockHeader/index.js
CHANGED
|
@@ -15,7 +15,7 @@ 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
|
-
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); }
|
|
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); } // 优化后的代码示例
|
|
19
19
|
function isControlled(props) {
|
|
20
20
|
return props.expand !== undefined;
|
|
21
21
|
}
|
|
@@ -28,13 +28,16 @@ const BlockHeader = props => {
|
|
|
28
28
|
description = '',
|
|
29
29
|
tooltip,
|
|
30
30
|
size = 'middle',
|
|
31
|
-
spaceBottom =
|
|
31
|
+
spaceBottom = {
|
|
32
|
+
expand: 16,
|
|
33
|
+
collapse: 16
|
|
34
|
+
},
|
|
32
35
|
className = '',
|
|
33
36
|
contentClassName = '',
|
|
34
37
|
style = {},
|
|
35
38
|
contentStyle = {},
|
|
36
39
|
background = true,
|
|
37
|
-
defaultExpand,
|
|
40
|
+
defaultExpand = true,
|
|
38
41
|
addonAfter,
|
|
39
42
|
expand,
|
|
40
43
|
children = '',
|
|
@@ -43,25 +46,29 @@ const BlockHeader = props => {
|
|
|
43
46
|
}),
|
|
44
47
|
onExpand,
|
|
45
48
|
titleStyle,
|
|
46
|
-
keepDOM,
|
|
47
|
-
lazy
|
|
49
|
+
keepDOM = false,
|
|
50
|
+
lazy = false,
|
|
51
|
+
expandable = true
|
|
48
52
|
} = props;
|
|
49
53
|
const [internalExpand, setInternalExpand] = (0, _react.useState)(defaultExpand);
|
|
50
|
-
const currentExpand = isControlled(props) ? expand : internalExpand;
|
|
51
|
-
|
|
52
|
-
// 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
|
|
53
|
-
const showCollapse = (typeof expand === 'boolean' || typeof defaultExpand === 'boolean') && children;
|
|
54
|
+
const currentExpand = isControlled(props) ? expand ?? false : internalExpand;
|
|
55
|
+
const showCollapse = expandable && !!children;
|
|
54
56
|
const tooltipProps = (0, _util.toTooltipProps)(tooltip);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
const bottomStyle = (0, _react.useMemo)(() => {
|
|
58
|
+
if (typeof spaceBottom === 'number') {
|
|
59
|
+
return {
|
|
60
|
+
marginBottom: spaceBottom
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const key = currentExpand ? 'expand' : 'collapse';
|
|
64
|
+
return {
|
|
65
|
+
marginBottom: spaceBottom[key] ?? 0
|
|
66
|
+
};
|
|
67
|
+
}, [spaceBottom, currentExpand]);
|
|
68
|
+
const handleExpand = () => {
|
|
69
|
+
const newExpandState = !currentExpand;
|
|
70
|
+
!isControlled(props) && setInternalExpand(newExpandState);
|
|
71
|
+
onExpand?.(newExpandState);
|
|
65
72
|
};
|
|
66
73
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
74
|
id: id,
|
|
@@ -76,7 +83,7 @@ const BlockHeader = props => {
|
|
|
76
83
|
[`${preTitleRowCls}--pointer`]: showCollapse
|
|
77
84
|
}),
|
|
78
85
|
style: titleStyle,
|
|
79
|
-
onClick:
|
|
86
|
+
onClick: showCollapse ? handleExpand : undefined
|
|
80
87
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
81
88
|
className: "title__box"
|
|
82
89
|
}, addonBefore ? /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -101,7 +108,7 @@ const BlockHeader = props => {
|
|
|
101
108
|
'collapse__icon--down': !currentExpand
|
|
102
109
|
})
|
|
103
110
|
}))), /*#__PURE__*/_react.default.createElement(_collapsible.default, {
|
|
104
|
-
isOpen:
|
|
111
|
+
isOpen: currentExpand,
|
|
105
112
|
keepDOM: keepDOM,
|
|
106
113
|
lazyRender: lazy
|
|
107
114
|
}, /*#__PURE__*/_react.default.createElement("div", {
|