Skip to content

Commit e7dceae

Browse files
author
JelteMX
committed
Add Tree lines as UI option
1 parent dacb9ac commit e7dceae

File tree

7 files changed

+45
-9
lines changed

7 files changed

+45
-9
lines changed

src/TreeView.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,20 @@ class TreeView extends Component<TreeViewContainerProps> {
109109
}
110110

111111
render(): ReactNode {
112-
const { dragIsDraggable, uiNodeIconIsGlyphicon, uiNodeIconAttr, selectionSelectOnClick } = this.props;
112+
const {
113+
dragIsDraggable,
114+
uiNodeIconIsGlyphicon,
115+
uiNodeIconAttr,
116+
selectionSelectOnClick,
117+
uiTableShowLines
118+
} = this.props;
113119
const showIcon = uiNodeIconAttr !== "";
114120
return (
115121
<TreeViewComponent
116122
className={this.props.class}
117123
searchEnabled={this.searchEnabled}
118124
holdSelection={selectionSelectOnClick}
125+
showLine={uiTableShowLines}
119126
store={this.store}
120127
showIcon={showIcon}
121128
iconIsGlyphicon={uiNodeIconIsGlyphicon}

src/TreeView.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@
167167
<description>When using icons, we default to Glyphicons from Bootstrap. This will prefix the value of the attribute with 'glyphicon glyphicon-'. If you want to use different icons, please switch off Glyphicon</description>
168168
</property>
169169
</propertyGroup>
170+
<propertyGroup caption="Other">
171+
<property key="uiTableShowLines" type="boolean" defaultValue="false">
172+
<caption>Show tree lines</caption>
173+
<description>These lines will show up in the tree structure to make it better visible</description>
174+
</property>
175+
</propertyGroup>
170176
</propertyGroup>
171177

172178
<propertyGroup caption="Drag &amp; Drop">

src/components/TreeViewComponent.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Tree as ArrayTree } from "array-to-tree";
44
import Tree, { AntTreeNode } from "antd/es/tree";
55
import Spin from "antd/es/spin";
66
import Input from "antd/es/input";
7+
import Icon from "antd/es/icon";
78
import Empty from "antd/es/empty";
89
import debounce from "debounce";
910

@@ -23,6 +24,7 @@ export interface TreeViewComponentProps {
2324
holdSelection: boolean;
2425
searchEnabled: boolean;
2526
showIcon: boolean;
27+
showLine: boolean;
2628
iconIsGlyphicon: boolean;
2729
onClickHandler: (_obj: mendix.lib.MxObject, _clickType: ClickCellType) => Promise<void>;
2830
className: string;
@@ -87,7 +89,7 @@ export class TreeViewComponent extends Component<TreeViewComponentProps> {
8789
}
8890

8991
private renderTree(): ReactNode {
90-
const { store, draggable, showIcon } = this.props;
92+
const { store, draggable, showIcon, showLine } = this.props;
9193
const { validationMessages, removeValidationMessage, expandedKeys } = store;
9294
const treeClass = classNames("treeview-widget-tree");
9395

@@ -104,6 +106,8 @@ export class TreeViewComponent extends Component<TreeViewComponentProps> {
104106
className={treeClass}
105107
expandedKeys={expandedKeys}
106108
showIcon={showIcon}
109+
showLine={showLine}
110+
switcherIcon={showLine ? <Icon type="caret-down-fill" /> : undefined}
107111
selectable={false}
108112
draggable={draggable}
109113
onDrop={this.onDrop.bind(this)}
@@ -123,7 +127,8 @@ export class TreeViewComponent extends Component<TreeViewComponentProps> {
123127
const isLeaf = !((item.children && item.children.length > 0) || item.hasChildren);
124128
const extraClass = classNames(
125129
item.highlight ? "highlight" : "",
126-
item.selected && this.props.holdSelection ? "selected" : ""
130+
item.selected && this.props.holdSelection ? "selected" : "",
131+
item.icon ? "has-icon" : ""
127132
);
128133

129134
if (item.icon) {

src/components/icons.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// This is a hack to keep Antdesign Table package small.
22
export { default as LoadingOutlined } from "@ant-design/icons/lib/outline/LoadingOutline";
33
export { default as SearchOutlined } from "@ant-design/icons/lib/outline/SearchOutline";
4-
export { default as FileOutlined } from "@ant-design/icons/lib/outline/FileOutline";
5-
export { default as MinusSquareOutlined } from "@ant-design/icons/lib/outline/MinusSquareOutline";
6-
export { default as PlusSquareOutlined } from "@ant-design/icons/lib/outline/PlusSquareOutline";
74
export { default as CaretDownFilled } from "@ant-design/icons/lib/fill/CaretDownFill";
85
export { default as CloseCircleFilled } from "@ant-design/icons/lib/fill/CloseCircleFill";

src/store/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { observable, action, configure, computed, flow } from "mobx";
22
import arrayToTree, { Tree } from "array-to-tree";
3-
// import { getObject } from "@jeltemx/mendix-react-widget-utils";
43

54
import { ValidationMessage } from "@jeltemx/mendix-react-widget-utils/lib/validation";
65
import { EntryObject, EntryObjectOptions, EntryObjectExtraOptions, TreeObject } from "./objects/entry";

src/ui/TreeView.scss

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@
574574
cursor: pointer;
575575
-webkit-transition: all 0.3s;
576576
transition: all 0.3s;
577+
// padding-right: 20px;
577578

578579
&:hover {
579580
background-color: #e6f7ff;
@@ -609,13 +610,14 @@
609610
display: inline-block;
610611
width: 24px;
611612
height: 24px;
612-
margin: 0;
613+
margin: 0 0 0 -10px;
613614
line-height: 24px;
614615
text-align: center;
615616
vertical-align: top;
616617
border: 0 none;
617618
outline: none;
618619
cursor: pointer;
620+
float: left;
619621

620622
&:empty {
621623
display: none;
@@ -895,7 +897,7 @@
895897

896898
span.ant-tree-switcher {
897899
color: rgba(0, 0, 0, 0.45);
898-
background: #fff;
900+
background: transparent;
899901
}
900902

901903
span.ant-tree-switcher.ant-tree-switcher-noop {
@@ -1873,6 +1875,25 @@
18731875
-webkit-transition: height 0.15s cubic-bezier(0.645, 0.045, 0.355, 1), opacity 0.15s cubic-bezier(0.645, 0.045, 0.355, 1) !important;
18741876
transition: height 0.15s cubic-bezier(0.645, 0.045, 0.355, 1), opacity 0.15s cubic-bezier(0.645, 0.045, 0.355, 1) !important;
18751877
}
1878+
1879+
.ant-tree-show-line {
1880+
.ant-tree-switcher {
1881+
&.ant-tree-switcher-noop {
1882+
background: transparent;
1883+
width: 1px;
1884+
margin-right: 23px;
1885+
left: 12px;
1886+
border-left: 1px solid #d9d9d9;
1887+
i.anticon.anticon-file.ant-tree-switcher-line-icon {
1888+
display: none;
1889+
}
1890+
}
1891+
}
1892+
}
1893+
1894+
li.has-icon > .ant-tree-node-content-wrapper {
1895+
padding-right: 20px;
1896+
}
18761897
}
18771898

18781899
@media all and (-ms-high-contrast: none) {

typings/TreeViewProps.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface TreeViewContainerProps extends CommonProps {
3636
uiNodeRenderAsHTML: boolean;
3737
uiNodeIconAttr: string;
3838
uiNodeIconIsGlyphicon: boolean;
39+
uiTableShowLines: boolean;
3940

4041
relationType: RelationType;
4142
relationNodeParent: string;

0 commit comments

Comments
 (0)