Skip to content

Commit 01943b6

Browse files
committed
Feature frontend-collective#860 Add icon in node renderer
Implementation of the feature frontend-collective#860
1 parent 3c29cbf commit 01943b6

File tree

5 files changed

+485
-1
lines changed

5 files changed

+485
-1
lines changed

src/node-renderer-default.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
}
6666

6767
.rst__rowContents,
68+
.rst__rowIcon,
6869
.rst__rowLabel,
6970
.rst__rowToolbar,
7071
.rst__moveHandle,
@@ -85,7 +86,7 @@
8586
flex: 1 0 auto;
8687
display: flex;
8788
align-items: center;
88-
justify-content: space-between;
89+
/*justify-content: space-between;*/
8990
background-color: white;
9091
}
9192

@@ -104,6 +105,13 @@
104105
border-left: solid #bbb 1px;
105106
}
106107

108+
.rst__rowIcon {
109+
padding-right: 8px;
110+
}
111+
.rst__rowIcon img {
112+
vertical-align: middle;
113+
}
114+
107115
.rst__rowLabel {
108116
flex: 0 1 auto;
109117
padding-right: 20px;

src/node-renderer-default.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NodeRendererDefault extends Component {
1717
node,
1818
title,
1919
subtitle,
20+
icon,
2021
draggedNode,
2122
path,
2223
treeIndex,
@@ -34,6 +35,7 @@ class NodeRendererDefault extends Component {
3435
} = this.props;
3536
const nodeTitle = title || node.title;
3637
const nodeSubtitle = subtitle || node.subtitle;
38+
const nodeIcon = icon || node.icon;
3739
const rowDirectionClass = rowDirection === 'rtl' ? 'rst__rtl' : null;
3840

3941
let handle;
@@ -132,6 +134,12 @@ class NodeRendererDefault extends Component {
132134
rowDirectionClass
133135
)}
134136
>
137+
{nodeIcon && (
138+
<div className={classnames('rst__rowIcon', rowDirectionClass)}>
139+
<img alt="icon here" src={nodeIcon} />
140+
</div>
141+
)}
142+
135143
<div className={classnames('rst__rowLabel', rowDirectionClass)}>
136144
<span
137145
className={classnames(
@@ -193,13 +201,15 @@ NodeRendererDefault.defaultProps = {
193201
canDrop: false,
194202
title: null,
195203
subtitle: null,
204+
icon: null,
196205
rowDirection: 'ltr',
197206
};
198207

199208
NodeRendererDefault.propTypes = {
200209
node: PropTypes.shape({}).isRequired,
201210
title: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
202211
subtitle: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
212+
icon: PropTypes.string,
203213
path: PropTypes.arrayOf(
204214
PropTypes.oneOfType([PropTypes.string, PropTypes.number])
205215
).isRequired,

0 commit comments

Comments
 (0)