@gitlab/ui
Version:
GitLab UI Components
97 lines (86 loc) • 2.47 kB
JavaScript
import { CHECKED_STATE } from './constants';
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
var Node = /*#__PURE__*/function () {
function Node(_ref) {
var value = _ref.value,
label = _ref.label,
_ref$parent = _ref.parent,
parent = _ref$parent === void 0 ? null : _ref$parent,
_ref$children = _ref.children,
children = _ref$children === void 0 ? [] : _ref$children,
depth = _ref.depth,
isChecked = _ref.isChecked;
_classCallCheck(this, Node);
this.value = value;
this.label = label;
this.parent = parent;
this.children = children;
this.depth = depth;
this.checkedState = isChecked ? CHECKED_STATE.CHECKED : CHECKED_STATE.UNCHECKED;
}
/**
* Sets the node's checked state
* @param {number} checkedState
*/
_createClass(Node, [{
key: "setCheckedState",
value: function setCheckedState(checkedState) {
this.checkedState = checkedState;
}
}, {
key: "isChild",
get: function get() {
return this.parent !== null;
}
}, {
key: "isParent",
get: function get() {
return this.children.length > 0;
}
}, {
key: "isLeaf",
get: function get() {
return !this.isParent;
}
}, {
key: "isUnchecked",
get: function get() {
return this.checkedState === CHECKED_STATE.UNCHECKED;
}
}, {
key: "isIndeterminate",
get: function get() {
return this.checkedState === CHECKED_STATE.INDETERMINATE;
}
}, {
key: "isChecked",
get: function get() {
return this.checkedState === CHECKED_STATE.CHECKED;
}
}, {
key: "isCheckedOrIndeterminate",
get: function get() {
return this.isChecked || this.isIndeterminate;
}
}]);
return Node;
}();
export { Node };