Skip to content

Commit

Permalink
extract getNodeClassName and getAnchorClassName
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Feb 6, 2017
1 parent 84f5f46 commit f3ed1dc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 75 deletions.
27 changes: 2 additions & 25 deletions src/angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,11 @@ export class NodeComponent {
doubleClick = new common.DoubleClick();

get nodeClassName() {
const values = ["jstree-node"];
if (this.data.children && this.data.children.length > 0) {
if (this.data.state.opened) {
values.push("jstree-open");
} else {
values.push("jstree-closed");
}
} else {
values.push("jstree-leaf");
}
if (this.last) {
values.push("jstree-last");
}
return values.join(" ");
return common.getNodeClassName(this.data, this.last);
}

get anchorClassName() {
const values = ["jstree-anchor"];
if (this.data.state.selected) {
values.push("jstree-clicked");
}
if (this.data.state.disabled) {
values.push("jstree-disabled");
}
if (this.hovered) {
values.push("jstree-hovered");
}
return values.join(" ");
return common.getAnchorClassName(this.data, this.hovered);
}

hover(hovered: boolean) {
Expand Down
31 changes: 31 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,34 @@ export class DoubleClick {
}
}
}

export function getNodeClassName(data: TreeData, last: boolean) {
const values = ["jstree-node"];
if (data.children && data.children.length > 0) {
if (data.state.opened) {
values.push("jstree-open");
} else {
values.push("jstree-closed");
}
} else {
values.push("jstree-leaf");
}
if (last) {
values.push("jstree-last");
}
return values.join(" ");
}

export function getAnchorClassName(data: TreeData, hovered: boolean) {
const values = ["jstree-anchor"];
if (data.state.selected) {
values.push("jstree-clicked");
}
if (data.state.disabled) {
values.push("jstree-disabled");
}
if (hovered) {
values.push("jstree-hovered");
}
return values.join(" ");
}
27 changes: 2 additions & 25 deletions src/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,11 @@ class Node extends React.Component<{
}

get nodeClassName() {
const values = ["jstree-node"];
if (this.props.data.children && this.props.data.children.length > 0) {
if (this.props.data.state.opened) {
values.push("jstree-open");
} else {
values.push("jstree-closed");
}
} else {
values.push("jstree-leaf");
}
if (this.props.last) {
values.push("jstree-last");
}
return values.join(" ");
return common.getNodeClassName(this.props.data, this.props.last);
}

get anchorClassName() {
const values = ["jstree-anchor"];
if (this.props.data.state.selected) {
values.push("jstree-clicked");
}
if (this.props.data.state.disabled) {
values.push("jstree-disabled");
}
if (this.hovered) {
values.push("jstree-hovered");
}
return values.join(" ");
return common.getAnchorClassName(this.props.data, this.hovered);
}

hover(hovered: boolean) {
Expand Down
27 changes: 2 additions & 25 deletions src/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,11 @@ class Node extends Vue {
doubleClick = new common.DoubleClick();

get nodeClassName() {
const values = ["jstree-node"];
if (this.data.children && this.data.children.length > 0) {
if (this.data.state.opened) {
values.push("jstree-open");
} else {
values.push("jstree-closed");
}
} else {
values.push("jstree-leaf");
}
if (this.last) {
values.push("jstree-last");
}
return values.join(" ");
return common.getNodeClassName(this.data, this.last);
}

get anchorClassName() {
const values = ["jstree-anchor"];
if (this.data.state.selected) {
values.push("jstree-clicked");
}
if (this.data.state.disabled) {
values.push("jstree-disabled");
}
if (this.hovered) {
values.push("jstree-hovered");
}
return values.join(" ");
return common.getAnchorClassName(this.data, this.hovered);
}

hover(hovered: boolean) {
Expand Down

0 comments on commit f3ed1dc

Please sign in to comment.