@dtjoy/dt-design 1.0.9 → 1.1.0
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 +9 -8
- package/esm/blockHeader/index.js +19 -18
- package/lib/blockHeader/index.d.ts +9 -8
- package/lib/blockHeader/index.js +15 -17
- 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/lib/config-provider/SizeContext';
|
|
5
3
|
import type { LabelTooltipType } from '../_util';
|
|
4
|
+
import type { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
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
|
|
@@ -37,10 +36,12 @@ export interface IBlockHeaderProps {
|
|
|
37
36
|
background?: boolean;
|
|
38
37
|
/** 当前展开状态 */
|
|
39
38
|
expand?: boolean;
|
|
40
|
-
/**
|
|
39
|
+
/** 是否可展开, 默认 true */
|
|
40
|
+
expandable?: boolean;
|
|
41
|
+
/** 是否默认展开内容, 默认为 false */
|
|
41
42
|
defaultExpand?: boolean;
|
|
42
43
|
/** 展开/收起的内容 */
|
|
43
|
-
children?: ReactNode;
|
|
44
|
+
children?: React.ReactNode;
|
|
44
45
|
/** 展开/收起时的回调 */
|
|
45
46
|
onExpand?: (expand: boolean) => void;
|
|
46
47
|
/** 标题的样式 */
|
package/esm/blockHeader/index.js
CHANGED
|
@@ -11,6 +11,7 @@ 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, { useState } from 'react';
|
|
15
16
|
import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
|
|
16
17
|
import { Tooltip } from 'antd';
|
|
@@ -44,7 +45,8 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
44
45
|
contentStyle = _props$contentStyle === void 0 ? {} : _props$contentStyle,
|
|
45
46
|
_props$background = props.background,
|
|
46
47
|
background = _props$background === void 0 ? true : _props$background,
|
|
47
|
-
defaultExpand = props.defaultExpand,
|
|
48
|
+
_props$defaultExpand = props.defaultExpand,
|
|
49
|
+
defaultExpand = _props$defaultExpand === void 0 ? true : _props$defaultExpand,
|
|
48
50
|
addonAfter = props.addonAfter,
|
|
49
51
|
expand = props.expand,
|
|
50
52
|
_props$children = props.children,
|
|
@@ -55,27 +57,28 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
55
57
|
}) : _props$addonBefore,
|
|
56
58
|
onExpand = props.onExpand,
|
|
57
59
|
titleStyle = props.titleStyle,
|
|
58
|
-
keepDOM = props.keepDOM,
|
|
59
|
-
|
|
60
|
+
_props$keepDOM = props.keepDOM,
|
|
61
|
+
keepDOM = _props$keepDOM === void 0 ? false : _props$keepDOM,
|
|
62
|
+
_props$lazy = props.lazy,
|
|
63
|
+
lazy = _props$lazy === void 0 ? false : _props$lazy,
|
|
64
|
+
_props$expandable = props.expandable,
|
|
65
|
+
expandable = _props$expandable === void 0 ? true : _props$expandable;
|
|
60
66
|
var _useState = useState(defaultExpand),
|
|
61
67
|
_useState2 = _slicedToArray(_useState, 2),
|
|
62
68
|
internalExpand = _useState2[0],
|
|
63
69
|
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;
|
|
70
|
+
var currentExpand = isControlled(props) ? expand !== null && expand !== void 0 ? expand : false : internalExpand;
|
|
71
|
+
var showCollapse = expandable && !!children;
|
|
68
72
|
var tooltipProps = toTooltipProps(tooltip);
|
|
69
|
-
var bottomStyle = {
|
|
70
|
-
if (spaceBottom) bottomStyle = showCollapse && !currentExpand ? {
|
|
73
|
+
var bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
|
|
71
74
|
marginBottom: 0
|
|
72
75
|
} : {
|
|
73
76
|
marginBottom: spaceBottom
|
|
74
|
-
};
|
|
75
|
-
var handleExpand = function handleExpand(
|
|
76
|
-
|
|
77
|
-
!isControlled(props) && setInternalExpand(
|
|
78
|
-
onExpand === null || onExpand === void 0 || onExpand(
|
|
77
|
+
} : {};
|
|
78
|
+
var handleExpand = function handleExpand() {
|
|
79
|
+
var newExpandState = !currentExpand;
|
|
80
|
+
!isControlled(props) && setInternalExpand(newExpandState);
|
|
81
|
+
onExpand === null || onExpand === void 0 || onExpand(newExpandState);
|
|
79
82
|
};
|
|
80
83
|
return /*#__PURE__*/React.createElement("div", {
|
|
81
84
|
id: id,
|
|
@@ -84,9 +87,7 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
84
87
|
}, /*#__PURE__*/React.createElement("div", {
|
|
85
88
|
className: clsx(preTitleRowCls, "".concat(preTitleRowCls, "--").concat(size), _defineProperty(_defineProperty({}, "".concat(preTitleRowCls, "--background"), background), "".concat(preTitleRowCls, "--pointer"), showCollapse)),
|
|
86
89
|
style: titleStyle,
|
|
87
|
-
onClick:
|
|
88
|
-
return showCollapse && handleExpand(!currentExpand);
|
|
89
|
-
}
|
|
90
|
+
onClick: showCollapse ? handleExpand : undefined
|
|
90
91
|
}, /*#__PURE__*/React.createElement("div", {
|
|
91
92
|
className: "title__box"
|
|
92
93
|
}, addonBefore ? /*#__PURE__*/React.createElement("div", {
|
|
@@ -111,7 +112,7 @@ var BlockHeader = function BlockHeader(props) {
|
|
|
111
112
|
'collapse__icon--down': !currentExpand
|
|
112
113
|
})
|
|
113
114
|
}))), /*#__PURE__*/React.createElement(Collapsible, {
|
|
114
|
-
isOpen:
|
|
115
|
+
isOpen: currentExpand,
|
|
115
116
|
keepDOM: keepDOM,
|
|
116
117
|
lazyRender: lazy
|
|
117
118
|
}, /*#__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/lib/config-provider/SizeContext';
|
|
5
3
|
import type { LabelTooltipType } from '../_util';
|
|
4
|
+
import type { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
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
|
|
@@ -37,10 +36,12 @@ export interface IBlockHeaderProps {
|
|
|
37
36
|
background?: boolean;
|
|
38
37
|
/** 当前展开状态 */
|
|
39
38
|
expand?: boolean;
|
|
40
|
-
/**
|
|
39
|
+
/** 是否可展开, 默认 true */
|
|
40
|
+
expandable?: boolean;
|
|
41
|
+
/** 是否默认展开内容, 默认为 false */
|
|
41
42
|
defaultExpand?: boolean;
|
|
42
43
|
/** 展开/收起的内容 */
|
|
43
|
-
children?: ReactNode;
|
|
44
|
+
children?: React.ReactNode;
|
|
44
45
|
/** 展开/收起时的回调 */
|
|
45
46
|
onExpand?: (expand: boolean) => void;
|
|
46
47
|
/** 标题的样式 */
|
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
|
}
|
|
@@ -34,7 +34,7 @@ const BlockHeader = props => {
|
|
|
34
34
|
style = {},
|
|
35
35
|
contentStyle = {},
|
|
36
36
|
background = true,
|
|
37
|
-
defaultExpand,
|
|
37
|
+
defaultExpand = true,
|
|
38
38
|
addonAfter,
|
|
39
39
|
expand,
|
|
40
40
|
children = '',
|
|
@@ -43,25 +43,23 @@ const BlockHeader = props => {
|
|
|
43
43
|
}),
|
|
44
44
|
onExpand,
|
|
45
45
|
titleStyle,
|
|
46
|
-
keepDOM,
|
|
47
|
-
lazy
|
|
46
|
+
keepDOM = false,
|
|
47
|
+
lazy = false,
|
|
48
|
+
expandable = true
|
|
48
49
|
} = props;
|
|
49
50
|
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;
|
|
51
|
+
const currentExpand = isControlled(props) ? expand ?? false : internalExpand;
|
|
52
|
+
const showCollapse = expandable && !!children;
|
|
54
53
|
const tooltipProps = (0, _util.toTooltipProps)(tooltip);
|
|
55
|
-
|
|
56
|
-
if (spaceBottom) bottomStyle = showCollapse && !currentExpand ? {
|
|
54
|
+
const bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
|
|
57
55
|
marginBottom: 0
|
|
58
56
|
} : {
|
|
59
57
|
marginBottom: spaceBottom
|
|
60
|
-
};
|
|
61
|
-
const handleExpand =
|
|
62
|
-
|
|
63
|
-
!isControlled(props) && setInternalExpand(
|
|
64
|
-
onExpand?.(
|
|
58
|
+
} : {};
|
|
59
|
+
const handleExpand = () => {
|
|
60
|
+
const newExpandState = !currentExpand;
|
|
61
|
+
!isControlled(props) && setInternalExpand(newExpandState);
|
|
62
|
+
onExpand?.(newExpandState);
|
|
65
63
|
};
|
|
66
64
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
67
65
|
id: id,
|
|
@@ -76,7 +74,7 @@ const BlockHeader = props => {
|
|
|
76
74
|
[`${preTitleRowCls}--pointer`]: showCollapse
|
|
77
75
|
}),
|
|
78
76
|
style: titleStyle,
|
|
79
|
-
onClick:
|
|
77
|
+
onClick: showCollapse ? handleExpand : undefined
|
|
80
78
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
81
79
|
className: "title__box"
|
|
82
80
|
}, addonBefore ? /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -101,7 +99,7 @@ const BlockHeader = props => {
|
|
|
101
99
|
'collapse__icon--down': !currentExpand
|
|
102
100
|
})
|
|
103
101
|
}))), /*#__PURE__*/_react.default.createElement(_collapsible.default, {
|
|
104
|
-
isOpen:
|
|
102
|
+
isOpen: currentExpand,
|
|
105
103
|
keepDOM: keepDOM,
|
|
106
104
|
lazyRender: lazy
|
|
107
105
|
}, /*#__PURE__*/_react.default.createElement("div", {
|