X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodule%2FPanel.jsx;h=2c2f5544333c606631cb723e9b9596f3a1954fa7;hb=02d1b455617089d59a5202135eb43850f42e08a1;hp=4220da86f72a232749f9e9eb56f2dc430748f9dd;hpb=4acbf95c7d2693d73b0c8c021ad892b6529d4c06;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index 4220da8..2c2f554 100644 --- a/src/module/Panel.jsx +++ b/src/module/Panel.jsx @@ -1,8 +1,4 @@ import React, {PropTypes} from 'react'; -import classnames from 'classnames'; -import GregorianCalendar from 'gregorian-calendar'; -import zhCn from 'gregorian-calendar/lib/locale/zh_CN'; - import CommonMixin from '../mixin/CommonMixin'; import Header from './Header'; import Combobox from './Combobox'; @@ -11,22 +7,29 @@ function noop() { } function generateOptions(length) { - return Array.apply(null, {length: length}).map((item, index) => { - return index; - }); + const arr = []; + for (let i = 0; i < length; i++) { + arr.push(i); + } + return arr; } const Panel = React.createClass({ propTypes: { prefixCls: PropTypes.string, - defaultValue: PropTypes.object, + value: PropTypes.object, locale: PropTypes.object, placeholder: PropTypes.string, + gregorianCalendarLocale: PropTypes.object, formatter: PropTypes.object, hourOptions: PropTypes.array, minuteOptions: PropTypes.array, secondOptions: PropTypes.array, onChange: PropTypes.func, + onEsc: PropTypes.func, + allowEmpty: PropTypes.bool, + showHour: PropTypes.bool, + showSecond: PropTypes.bool, onClear: PropTypes.func, }, @@ -43,23 +46,17 @@ const Panel = React.createClass({ }, getInitialState() { - let defaultValue = this.props.defaultValue; - if (!defaultValue) { - defaultValue = new GregorianCalendar(zhCn); - defaultValue.setTime(Date.now()); - } return { - value: defaultValue, + value: this.props.value, }; }, - componentWillMount() { - const formatter = this.props.formatter; - const pattern = formatter.originalPattern; - if (pattern === 'HH:mm') { - this.showSecond = false; - } else if (pattern === 'mm:ss') { - this.showHour = false; + componentWillReceiveProps(nextProps) { + const value = nextProps.value; + if (value) { + this.setState({ + value, + }); } }, @@ -72,51 +69,34 @@ const Panel = React.createClass({ this.props.onClear(); }, - getPlaceholder(placeholder) { - if (placeholder) { - return placeholder; - } - - const { locale } = this.props; - if (!this.showHour) { - return locale.placeholdermmss; - } else if (!this.showSecond) { - return locale.placeholderHHmm; - } - return locale.placeholderHHmmss; - }, - - showHour: true, - showSecond: true, - render() { - const { locale, prefixCls, defaultValue, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; - const value = this.state.value || defaultValue; - const cls = classnames({ 'narrow': !this.showHour || !this.showSecond }); - + const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; + const value = this.state.value; return ( -
+