@dtjoy/dt-design 1.1.0 → 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.
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import './style';
3
- import type { LabelTooltipType } from '../_util';
4
3
  import type { SizeType } from 'antd/es/config-provider/SizeContext';
4
+ import type { LabelTooltipType } from '../_util';
5
5
  export interface IBlockHeaderProps {
6
6
  /** id */
7
7
  id?: string;
@@ -23,7 +23,10 @@ export interface IBlockHeaderProps {
23
23
  */
24
24
  size?: SizeType;
25
25
  /** 自定义 Bottom 值 */
26
- spaceBottom?: number;
26
+ spaceBottom?: {
27
+ expand?: number;
28
+ collapse?: number;
29
+ } | number;
27
30
  /** 标题一行的样式类名 */
28
31
  className?: string;
29
32
  /** 标题的样式类名 */
@@ -12,7 +12,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
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
+ import React, { useMemo, useState } from 'react';
16
16
  import { QuestionCircleOutlined, UpOutlined } from '@ant-design/icons';
17
17
  import { Tooltip } from 'antd';
18
18
  import { globalConfig } from 'antd/es/config-provider';
@@ -34,7 +34,10 @@ var BlockHeader = function BlockHeader(props) {
34
34
  _props$size = props.size,
35
35
  size = _props$size === void 0 ? 'middle' : _props$size,
36
36
  _props$spaceBottom = props.spaceBottom,
37
- spaceBottom = _props$spaceBottom === void 0 ? 16 : _props$spaceBottom,
37
+ spaceBottom = _props$spaceBottom === void 0 ? {
38
+ expand: 16,
39
+ collapse: 16
40
+ } : _props$spaceBottom,
38
41
  _props$className = props.className,
39
42
  className = _props$className === void 0 ? '' : _props$className,
40
43
  _props$contentClassNa = props.contentClassName,
@@ -70,11 +73,18 @@ var BlockHeader = function BlockHeader(props) {
70
73
  var currentExpand = isControlled(props) ? expand !== null && expand !== void 0 ? expand : false : internalExpand;
71
74
  var showCollapse = expandable && !!children;
72
75
  var tooltipProps = toTooltipProps(tooltip);
73
- var bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
74
- marginBottom: 0
75
- } : {
76
- marginBottom: spaceBottom
77
- } : {};
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]);
78
88
  var handleExpand = function handleExpand() {
79
89
  var newExpandState = !currentExpand;
80
90
  !isControlled(props) && setInternalExpand(newExpandState);
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import './style';
3
- import type { LabelTooltipType } from '../_util';
4
3
  import type { SizeType } from 'antd/es/config-provider/SizeContext';
4
+ import type { LabelTooltipType } from '../_util';
5
5
  export interface IBlockHeaderProps {
6
6
  /** id */
7
7
  id?: string;
@@ -23,7 +23,10 @@ export interface IBlockHeaderProps {
23
23
  */
24
24
  size?: SizeType;
25
25
  /** 自定义 Bottom 值 */
26
- spaceBottom?: number;
26
+ spaceBottom?: {
27
+ expand?: number;
28
+ collapse?: number;
29
+ } | number;
27
30
  /** 标题一行的样式类名 */
28
31
  className?: string;
29
32
  /** 标题的样式类名 */
@@ -28,7 +28,10 @@ const BlockHeader = props => {
28
28
  description = '',
29
29
  tooltip,
30
30
  size = 'middle',
31
- spaceBottom = 16,
31
+ spaceBottom = {
32
+ expand: 16,
33
+ collapse: 16
34
+ },
32
35
  className = '',
33
36
  contentClassName = '',
34
37
  style = {},
@@ -51,11 +54,17 @@ const BlockHeader = props => {
51
54
  const currentExpand = isControlled(props) ? expand ?? false : internalExpand;
52
55
  const showCollapse = expandable && !!children;
53
56
  const tooltipProps = (0, _util.toTooltipProps)(tooltip);
54
- const bottomStyle = spaceBottom ? showCollapse && !currentExpand ? {
55
- marginBottom: 0
56
- } : {
57
- marginBottom: spaceBottom
58
- } : {};
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]);
59
68
  const handleExpand = () => {
60
69
  const newExpandState = !currentExpand;
61
70
  !isControlled(props) && setInternalExpand(newExpandState);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtjoy/dt-design",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "react-component",
5
5
  "author": {
6
6
  "name": "夕颜",