UNPKG

tsp-component

Version:

提供多端和react版本的UI组件

79 lines (78 loc) 3.09 kB
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 __()); }; })(); import * as React from 'react'; import classNames from 'classnames'; import Hammmer from 'react-hammerjs'; import FormCore from '../form/core'; var prefix = 'tsp-component-Point'; var Point = (function (_super) { __extends(Point, _super); function Point(props, state) { var _this = _super.call(this, props, state) || this; _this.count = []; _this.state = { value: _this.props.defaultValue }; _this.onClick = _this.onClick.bind(_this); return _this; } Point.prototype.componentWillMount = function () { for (var i = 0; i < this.props.count; i++) { this.count.push(i); } }; Point.prototype.componentDidMount = function () { this.formCore = new FormCore({ elem: this.refs.elem, required: this.props.required, defaultValue: this.props.defaultValue.toString() }); }; Point.prototype.shouldComponentUpdate = function (nextProps, nextState) { return this.state.value !== nextState.value; }; Point.prototype.componentWillReceiveProps = function (nextProps) { if (this.props.defaultValue !== nextProps.defaultValue) { this.setState({ value: nextProps.defaultValue }); } }; Point.prototype.onClick = function (i) { if (!this.props.disabled) { this.setState({ value: i }); if (this.props.onClick) { this.props.onClick(i); } this.formCore.elem.dataset.value = i.toString(); } }; Point.prototype.render = function () { var _this = this; return (React.createElement("div", { id: this.props.id, className: classNames((_a = {}, _a[prefix] = true, _a[this.props.className] = this.props.className, _a)), ref: "elem" }, this.count.map(function (value, i) { return (React.createElement(Hammmer, { onTap: function () { return _this.onClick(i + 1); }, key: i }, React.createElement("div", { className: classNames((_a = {}, _a[prefix + "-item"] = true, _a[prefix + "-item-current"] = i < _this.state.value, _a)) }, i < _this.state.value ? _this.props.currentIcon : _this.props.icon))); var _a; }))); var _a; }; return Point; }(React.Component)); ; export default Point;