@dtjoy/dt-design 1.0.8 → 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.
@@ -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,14 +36,20 @@ export interface IBlockHeaderProps {
37
36
  background?: boolean;
38
37
  /** 当前展开状态 */
39
38
  expand?: boolean;
40
- /** 是否默认展开内容, 默认为 undefined */
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
  /** 标题的样式 */
47
48
  titleStyle?: React.CSSProperties;
49
+ /** 是否保留 DOM 结构, 默认 false */
50
+ keepDOM?: boolean;
51
+ /** 是否懒加载, 默认 false */
52
+ lazy?: boolean;
48
53
  }
49
54
  declare const BlockHeader: React.FC<IBlockHeaderProps>;
50
55
  export default BlockHeader;
@@ -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,
@@ -54,26 +56,29 @@ var BlockHeader = function BlockHeader(props) {
54
56
  className: "addon-before--default"
55
57
  }) : _props$addonBefore,
56
58
  onExpand = props.onExpand,
57
- titleStyle = props.titleStyle;
59
+ titleStyle = props.titleStyle,
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;
58
66
  var _useState = useState(defaultExpand),
59
67
  _useState2 = _slicedToArray(_useState, 2),
60
68
  internalExpand = _useState2[0],
61
69
  setInternalExpand = _useState2[1];
62
- var currentExpand = isControlled(props) ? expand : internalExpand;
63
-
64
- // 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
65
- 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;
66
72
  var tooltipProps = toTooltipProps(tooltip);
67
- var bottomStyle = {};
68
- if (spaceBottom) bottomStyle = showCollapse && !currentExpand ? {
73
+ var bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
69
74
  marginBottom: 0
70
75
  } : {
71
76
  marginBottom: spaceBottom
72
- };
73
- var handleExpand = function handleExpand(expand) {
74
- if (!children) return;
75
- !isControlled(props) && setInternalExpand(expand);
76
- onExpand === null || onExpand === void 0 || onExpand(expand);
77
+ } : {};
78
+ var handleExpand = function handleExpand() {
79
+ var newExpandState = !currentExpand;
80
+ !isControlled(props) && setInternalExpand(newExpandState);
81
+ onExpand === null || onExpand === void 0 || onExpand(newExpandState);
77
82
  };
78
83
  return /*#__PURE__*/React.createElement("div", {
79
84
  id: id,
@@ -82,9 +87,7 @@ var BlockHeader = function BlockHeader(props) {
82
87
  }, /*#__PURE__*/React.createElement("div", {
83
88
  className: clsx(preTitleRowCls, "".concat(preTitleRowCls, "--").concat(size), _defineProperty(_defineProperty({}, "".concat(preTitleRowCls, "--background"), background), "".concat(preTitleRowCls, "--pointer"), showCollapse)),
84
89
  style: titleStyle,
85
- onClick: function onClick() {
86
- return showCollapse && handleExpand(!currentExpand);
87
- }
90
+ onClick: showCollapse ? handleExpand : undefined
88
91
  }, /*#__PURE__*/React.createElement("div", {
89
92
  className: "title__box"
90
93
  }, addonBefore ? /*#__PURE__*/React.createElement("div", {
@@ -109,7 +112,9 @@ var BlockHeader = function BlockHeader(props) {
109
112
  'collapse__icon--down': !currentExpand
110
113
  })
111
114
  }))), /*#__PURE__*/React.createElement(Collapsible, {
112
- isOpen: !currentExpand
115
+ isOpen: currentExpand,
116
+ keepDOM: keepDOM,
117
+ lazyRender: lazy
113
118
  }, /*#__PURE__*/React.createElement("div", {
114
119
  className: clsx("".concat(prefixCls, "__content"), contentClassName, _defineProperty({}, "".concat(prefixCls, "__content--active"), currentExpand || !showCollapse)),
115
120
  style: contentStyle
@@ -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,14 +36,20 @@ export interface IBlockHeaderProps {
37
36
  background?: boolean;
38
37
  /** 当前展开状态 */
39
38
  expand?: boolean;
40
- /** 是否默认展开内容, 默认为 undefined */
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
  /** 标题的样式 */
47
48
  titleStyle?: React.CSSProperties;
49
+ /** 是否保留 DOM 结构, 默认 false */
50
+ keepDOM?: boolean;
51
+ /** 是否懒加载, 默认 false */
52
+ lazy?: boolean;
48
53
  }
49
54
  declare const BlockHeader: React.FC<IBlockHeaderProps>;
50
55
  export default BlockHeader;
@@ -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 = '',
@@ -42,24 +42,24 @@ const BlockHeader = props => {
42
42
  className: "addon-before--default"
43
43
  }),
44
44
  onExpand,
45
- titleStyle
45
+ titleStyle,
46
+ keepDOM = false,
47
+ lazy = false,
48
+ expandable = true
46
49
  } = props;
47
50
  const [internalExpand, setInternalExpand] = (0, _react.useState)(defaultExpand);
48
- const currentExpand = isControlled(props) ? expand : internalExpand;
49
-
50
- // 只有在有了 children 并且设置了 expand/defaultExpand 的时候才能够展开收起
51
- const showCollapse = (typeof expand === 'boolean' || typeof defaultExpand === 'boolean') && children;
51
+ const currentExpand = isControlled(props) ? expand ?? false : internalExpand;
52
+ const showCollapse = expandable && !!children;
52
53
  const tooltipProps = (0, _util.toTooltipProps)(tooltip);
53
- let bottomStyle = {};
54
- if (spaceBottom) bottomStyle = showCollapse && !currentExpand ? {
54
+ const bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
55
55
  marginBottom: 0
56
56
  } : {
57
57
  marginBottom: spaceBottom
58
- };
59
- const handleExpand = expand => {
60
- if (!children) return;
61
- !isControlled(props) && setInternalExpand(expand);
62
- onExpand?.(expand);
58
+ } : {};
59
+ const handleExpand = () => {
60
+ const newExpandState = !currentExpand;
61
+ !isControlled(props) && setInternalExpand(newExpandState);
62
+ onExpand?.(newExpandState);
63
63
  };
64
64
  return /*#__PURE__*/_react.default.createElement("div", {
65
65
  id: id,
@@ -74,7 +74,7 @@ const BlockHeader = props => {
74
74
  [`${preTitleRowCls}--pointer`]: showCollapse
75
75
  }),
76
76
  style: titleStyle,
77
- onClick: () => showCollapse && handleExpand(!currentExpand)
77
+ onClick: showCollapse ? handleExpand : undefined
78
78
  }, /*#__PURE__*/_react.default.createElement("div", {
79
79
  className: "title__box"
80
80
  }, addonBefore ? /*#__PURE__*/_react.default.createElement("div", {
@@ -99,7 +99,9 @@ const BlockHeader = props => {
99
99
  'collapse__icon--down': !currentExpand
100
100
  })
101
101
  }))), /*#__PURE__*/_react.default.createElement(_collapsible.default, {
102
- isOpen: !currentExpand
102
+ isOpen: currentExpand,
103
+ keepDOM: keepDOM,
104
+ lazyRender: lazy
103
105
  }, /*#__PURE__*/_react.default.createElement("div", {
104
106
  className: (0, _clsx.default)(`${prefixCls}__content`, contentClassName, {
105
107
  [`${prefixCls}__content--active`]: currentExpand || !showCollapse
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtjoy/dt-design",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "react-component",
5
5
  "author": {
6
6
  "name": "夕颜",