UNPKG

dragon-mobile-ui

Version:
126 lines (99 loc) 4.91 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _Picker = require('./Picker'); var _Picker2 = _interopRequireDefault(_Picker); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var MultiPicker = function (_Component) { _inherits(MultiPicker, _Component); function MultiPicker(props) { _classCallCheck(this, MultiPicker); var _this = _possibleConstructorReturn(this, (MultiPicker.__proto__ || Object.getPrototypeOf(MultiPicker)).call(this, props)); _this.state = { visible: props.visible || false, date: props.date || props.defaultDate || [] }; return _this; } _createClass(MultiPicker, [{ key: 'onValueChange', value: function onValueChange(index, value) { var values = this.getValue().concat(); values[index] = value; this.props.onValueChange(values, index); } }, { key: 'getValue', value: function getValue() { var _props = this.props, children = _props.children, selectedValue = _props.selectedValue; if (selectedValue && selectedValue.length) { return selectedValue; } if (!children) { return []; } return children.map(function (c) { var cc = c.props.children; return cc && cc[0] && cc[0].value; }); } }, { key: 'render', value: function render() { var _this2 = this; var props = this.props; var prefixCls = props.prefixCls, pickerPrefixCls = props.pickerPrefixCls, className = props.className, rootNativeProps = props.rootNativeProps, disabled = props.disabled, pickerItemStyle = props.pickerItemStyle, indicatorStyle = props.indicatorStyle, pure = props.pure, children = props.children; var selectedValue = this.getValue(); var colElements = children.map(function (col, i) { return _react2.default.createElement( 'div', { key: col.key || i, className: prefixCls + '-item' }, _react2.default.createElement(_Picker2.default, _extends({ itemStyle: pickerItemStyle, disabled: disabled, pure: pure, indicatorStyle: indicatorStyle, prefixCls: pickerPrefixCls, selectedValue: selectedValue[i], onValueChange: function onValueChange(value) { return _this2.onValueChange(i, value); } }, col.props)) ); }); return _react2.default.createElement( 'div', _extends({}, rootNativeProps, { className: (0, _classnames2.default)(className, prefixCls) }), colElements ); } }]); return MultiPicker; }(_react.Component); MultiPicker.defaultProps = { prefixCls: 'ui-multi-picker', pickerPrefixCls: 'ui-datepicker', onValueChange: function onValueChange() {}, disabled: false }; exports.default = MultiPicker;