Skip to content

Commit 09c4e7d

Browse files
committed
Extract Font Awesome icons into CSS
Resolves #2.
1 parent 0dcc27b commit 09c4e7d

File tree

5 files changed

+99
-45
lines changed

5 files changed

+99
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
* [#20]: Remove deprecated `title` property in `nodes` (use `label` instead)
88

9+
### New Features
10+
11+
* [#2]: Allow customization of icons via CSS
12+
913
## [v0.4.2](https://github.com/jakezatecky/react-checkbox-tree/compare/v0.4.1...v0.4.2) (2016-02-27)
1014

1115
### Bug Fixes

src/js/TreeNode.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ class TreeNode extends React.Component {
5858

5959
renderCollapseIcon() {
6060
if (!this.props.expanded) {
61-
return <i className="fa fa-chevron-right" />;
61+
return <i className="rct-icon rct-icon-expand-close" />;
6262
}
6363

64-
return <i className="fa fa-chevron-down" />;
64+
return <i className="rct-icon rct-icon-expand-open" />;
6565
}
6666

6767
renderCollapseButton() {
6868
if (this.props.rawChildren === null) {
6969
return (
7070
<span className="rct-collapse">
71-
<i className="fa" />
71+
<i className="rct-icon" />
7272
</span>
7373
);
7474
}
@@ -82,26 +82,26 @@ class TreeNode extends React.Component {
8282

8383
renderCheckboxIcon() {
8484
if (this.props.checked === 0) {
85-
return <i className="fa fa-square-o" />;
85+
return <i className="rct-icon rct-icon-uncheck" />;
8686
}
8787

8888
if (this.props.checked === 1) {
89-
return <i className="fa fa-check-square-o" />;
89+
return <i className="rct-icon rct-icon-check" />;
9090
}
9191

92-
return <i className="fa fa-check-square-o rct-half-checked" />;
92+
return <i className="rct-icon rct-icon-half-check" />;
9393
}
9494

9595
renderNodeIcon() {
9696
if (this.props.rawChildren === null) {
97-
return <i className="fa fa-file-o" />;
97+
return <i className="rct-icon rct-icon-leaf" />;
9898
}
9999

100100
if (!this.props.expanded) {
101-
return <i className="fa fa-folder-o" />;
101+
return <i className="rct-icon rct-icon-parent-close" />;
102102
}
103103

104-
return <i className="fa fa-folder-open-o" />;
104+
return <i className="rct-icon rct-icon-parent-open" />;
105105
}
106106

107107
renderChildren() {
@@ -125,7 +125,7 @@ class TreeNode extends React.Component {
125125
<span className="rct-checkbox">
126126
{this.renderCheckboxIcon()}
127127
</span>
128-
<span className="rct-icon">
128+
<span className="rct-node-icon">
129129
{this.renderNodeIcon()}
130130
</span>
131131
<span className="rct-title">

src/less/react-checkbox-tree.less

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@
3636
display: none;
3737
}
3838

39-
.fa {
39+
.rct-icon {
40+
display: inline-block;
4041
margin: 0 5px;
4142
width: 14px;
42-
}
43-
44-
.fa-folder-open-o,
45-
.fa-folder-o,
46-
.fa-file-o {
47-
color: @rct-icon-color;
43+
font-family: "FontAwesome";
44+
font-style: normal;
4845
}
4946
}
5047

@@ -65,12 +62,7 @@
6562
cursor: pointer;
6663
}
6764

68-
.fa-chevron-right,
69-
.fa-chevron-down {
70-
text-align: center;
71-
}
72-
73-
> .fa-chevron-right {
65+
> .rct-icon-expand-close {
7466
opacity: .5;
7567

7668
&:hover {
@@ -79,6 +71,39 @@
7971
}
8072
}
8173

82-
.rct-half-checked {
74+
.rct-node-icon {
75+
color: @rct-icon-color;
76+
}
77+
78+
.rct-icon-expand-close::before {
79+
content: "\f054";
80+
}
81+
82+
.rct-icon-expand-open::before {
83+
content: "\f078";
84+
}
85+
86+
.rct-icon-uncheck::before {
87+
content: "\f096";
88+
}
89+
90+
.rct-icon-check::before {
91+
content: "\f046";
92+
}
93+
94+
.rct-icon-half-check::before {
8395
opacity: .5;
96+
content: "\f046";
97+
}
98+
99+
.rct-icon-leaf::before {
100+
content: "\f016";
101+
}
102+
103+
.rct-icon-parent-open::before {
104+
content: "\f115";
105+
}
106+
107+
.rct-icon-parent-close::before {
108+
content: "\f114";
84109
}

src/sass/react-checkbox-tree.scss

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ $rct-label-hover: rgba($rct-icon-color, .1) !default;
3636
display: none;
3737
}
3838

39-
.fa {
39+
.rct-icon {
40+
display: inline-block;
4041
margin: 0 5px;
4142
width: 14px;
42-
}
43-
44-
.fa-folder-open-o,
45-
.fa-folder-o,
46-
.fa-file-o {
47-
color: $rct-icon-color;
43+
font-family: "FontAwesome";
44+
font-style: normal;
4845
}
4946
}
5047

@@ -65,12 +62,7 @@ $rct-label-hover: rgba($rct-icon-color, .1) !default;
6562
cursor: pointer;
6663
}
6764

68-
.fa-chevron-right,
69-
.fa-chevron-down {
70-
text-align: center;
71-
}
72-
73-
> .fa-chevron-right {
65+
> .rct-icon-expand-close {
7466
opacity: .5;
7567

7668
&:hover {
@@ -79,6 +71,39 @@ $rct-label-hover: rgba($rct-icon-color, .1) !default;
7971
}
8072
}
8173

82-
.rct-half-checked {
74+
.rct-node-icon {
75+
color: $rct-icon-color;
76+
}
77+
78+
.rct-icon-expand-close::before {
79+
content: "\f054";
80+
}
81+
82+
.rct-icon-expand-open::before {
83+
content: "\f078";
84+
}
85+
86+
.rct-icon-uncheck::before {
87+
content: "\f096";
88+
}
89+
90+
.rct-icon-check::before {
91+
content: "\f046";
92+
}
93+
94+
.rct-icon-half-check::before {
8395
opacity: .5;
96+
content: "\f046";
97+
}
98+
99+
.rct-icon-leaf::before {
100+
content: "\f016";
101+
}
102+
103+
.rct-icon-parent-open::before {
104+
content: "\f115";
105+
}
106+
107+
.rct-icon-parent-close::before {
108+
content: "\f114";
84109
}

test/TreeNode.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ describe('<TreeNode />', () => {
3838
describe('checked', () => {
3939
it('should render icons associated with each check state', () => {
4040
const iconMap = {
41-
0: <i className="fa fa-square-o" />,
42-
1: <i className="fa fa-check-square-o" />,
43-
2: <i className="fa fa-check-square-o rct-half-checked" />,
41+
0: <i className="rct-icon rct-icon-uncheck" />,
42+
1: <i className="rct-icon rct-icon-check" />,
43+
2: <i className="rct-icon rct-icon-half-check" />,
4444
};
4545

4646
Object.keys(iconMap).forEach((state) => {
@@ -99,17 +99,17 @@ describe('<TreeNode />', () => {
9999
<TreeNode {...baseProps} expanded rawChildren={[{ value: 'europa', label: 'Europa' }]} />,
100100
);
101101

102-
assert.isTrue(wrapper.contains(<i className="fa fa-chevron-down" />));
103-
assert.isTrue(wrapper.contains(<i className="fa fa-folder-open-o" />));
102+
assert.isTrue(wrapper.contains(<i className="rct-icon rct-icon-expand-open" />));
103+
assert.isTrue(wrapper.contains(<i className="rct-icon rct-icon-parent-open" />));
104104
});
105105

106106
it('should render collapsed icons when set to false', () => {
107107
const wrapper = shallow(
108108
<TreeNode {...baseProps} expanded={false} rawChildren={[{ value: 'europa', label: 'Europa' }]} />,
109109
);
110110

111-
assert.isTrue(wrapper.contains(<i className="fa fa-chevron-right" />));
112-
assert.isTrue(wrapper.contains(<i className="fa fa-folder-o" />));
111+
assert.isTrue(wrapper.contains(<i className="rct-icon rct-icon-expand-close" />));
112+
assert.isTrue(wrapper.contains(<i className="rct-icon rct-icon-parent-close" />));
113113
});
114114
});
115115

0 commit comments

Comments
 (0)