UNPKG

tsp-component

Version:

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

100 lines (99 loc) 3.64 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 view from './view'; import PickerCore from '../picker/core'; var Picker = (function (_super) { __extends(Picker, _super); function Picker(props, state) { var _this = _super.call(this, props, state) || this; _this.onPanStart = _this.onPanStart.bind(_this); _this.onPan = _this.onPan.bind(_this); _this.onPanEnd = _this.onPanEnd.bind(_this); _this.onOk = _this.onOk.bind(_this); _this.onCancel = _this.onCancel.bind(_this); _this.onOpen = _this.onOpen.bind(_this); _this.onTransitionEnd = _this.onTransitionEnd.bind(_this); return _this; } Picker.prototype.componentDidMount = function () { var data = []; for (var i = 0; i < this.props.data.length; i++) { data[i] = []; for (var j = 0; j < this.props.data[i].length; j++) { data[i].push(this.props.data[i][j]); } } this.core = new PickerCore({ data: data, id: this.props.id, cascade: this.props.cascade, defaultValue: this.props.defaultValue, onOk: this.props.onOk, defaultLabel: this.props.defaultLabel, sliderElem: this.refs.slider, containerElem: this.refs.container['elem'], labelElem: this.refs.label, formatLabel: this.props.formatLabel, required: this.props.required }); this.core.init(); this.core.sliderElem.addEventListener('webkitTransitionEnd', this.onTransitionEnd); }; Picker.prototype.componentWillReceiveProps = function (nextProps) { this.core.componentWillReceiveProps(this.props, nextProps); }; Picker.prototype.onPanStart = function (evt) { evt.preventDefault(); this.core.panStart(evt); }; Picker.prototype.onPan = function (evt) { evt.preventDefault(); this.core.pan(evt); }; Picker.prototype.onPanEnd = function (evt) { var _this = this; evt.preventDefault(); this.core.panEnd(evt); if (this.core.isPanEnd) { this.transitionEndTimeout = setTimeout(function () { if (!_this.core.isTransitionEnd) { _this.onTransitionEnd(); } }, 300); } }; Picker.prototype.onTransitionEnd = function () { this.core.transitionEnd(this.transitionEndTimeout); }; Picker.prototype.onOk = function () { this.core.ok(); }; Picker.prototype.onCancel = function () { this.core.cancel(); }; Picker.prototype.onOpen = function () { if (!this.props.disabled) { this.core.open(); } }; Picker.prototype.render = function () { return view(this); }; Picker.defaultProps = { id: '', cascade: false, defaultValue: undefined, data: undefined, }; return Picker; }(React.Component)); export default Picker;