左侧树折叠效果

# 背景

折叠左侧,多余空间用于列表操作;收缩还添加了动画功能;

image-20211020172038740image-20211020172051406

# 实践

# js部分

<div
  className={classNames(styles.left, 'left', expaned ? styles.expaned : styles.retract)}
  >
  <div
    className={classNames(styles.expandBtn, 'pointer')}
    onClick={this.handleToggleExpand}
    >
    <MyIcon type={expaned ? 'iconcaret-left' : 'iconcaret-right'} />
  </div>
  <div className={styles.leftTree}>
    <CategoryTree
      treeData={treeData}
      shouldUpdateProps={['treeData']}
      onSelectCallBack={this.onSelectCallBack}
      renderLineIcon={this.getOptionButtons}
      renderSearchIcon={this.renderSearchIcon}
      />
  </div>
</div>
<div className={classNames(styles.right, 'right')}></div>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# css部分

.content {
  height: 100%;
  .left {
    height: 100%;
    // overflow: auto;
    background: #fff;
    border-right: 1px solid @border-color-base;
    display: flex;
    flex-direction: column;
    position: relative;
    &.retract {
      width: 0;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
      border-right: 0;
    }
    &.expaned {
      width: 230px;
      min-width: 230px;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
    }
    .expandBtn {
      position: absolute;
      top: calc(50% - 20px);
      right: -16px;
      width: 17px;
      display: block;
      background: #fff;
      box-shadow: 4px 2px 8px 0 rgba(0, 0, 0, 0.15); // 浮层阴影
      padding: 16px 0;
      border-radius: 0 @border-radius-base @border-radius-base 0;
      -webkit-transition: all 0.3s;
      transition: all 0.3s;
      z-index: 9;
    }
    .leftTree {
      height: 100%;
      overflow: auto;
      :global {
        li .ant-tree-node-content-wrapper:hover {
          :local .more {
            display: inline-block;
          }
        }

        .ant-tree li .ant-tree-node-content-wrapper.ant-tree-node-selected {
          :local .more {
            display: inline-block;
          }
        }
      }
    }
  }
  .right {
    height: 100%;
    // display: flex;
    // flex-direction: column;
    overflow: auto;
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
上次更新: 2022/04/15, 05:41:26
×