UNPKG

simple-react-ui

Version:

a simple react component library written in TypeScript+ React.js

50 lines 2.02 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var Tree = /** @class */ (function (_super) { __extends(Tree, _super); function Tree(props) { var _this = _super.call(this, props) || this; _this.state = { /** 当前选择的节点 */ currentActiveId: null, }; return _this; } Tree.prototype._toDOM = function (tree) { var _this = this; return (React.createElement("ul", { className: "tree" }, tree.map(function (i) { return (React.createElement("li", { key: i.value.id, "data-x": i.value.id }, React.createElement("a", { className: _this.state.currentActiveId == i.value.id ? "active" : "", onClick: function (e) { e.preventDefault(); e.stopPropagation(); _this.setState({ currentActiveId: i.value.id }, function () { _this.props.onClick(i.value.id); }); return false; } }, i.value.name), _this._toDOM(i.children))); }))); }; Tree.prototype.render = function () { return this._toDOM(this.props.tree); }; return Tree; }(React.Component)); exports.Tree = Tree; Tree.defaultProps = { tree: [], onClick: function (string) { }, }; exports.default = Tree; //# sourceMappingURL=index.js.map