X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fmodule%2FPanel.jsx;h=4c7eaae17048f77b747fe0c6d8544ba608c532d7;hb=a6978323930a81d983b0051ad61bcf81fb7a7235;hp=e372774af9c3786964397b9e0bbd4d5885bd4f37;hpb=96a4cefce60a06e539dfb8eacfc27f026d6c8a41;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index e372774..4c7eaae 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,9 +7,11 @@ 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({ @@ -22,11 +20,16 @@ const Panel = React.createClass({ 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,26 +46,11 @@ const Panel = React.createClass({ }, getInitialState() { - let value = this.props.value; - if (!value) { - value = new GregorianCalendar(zhCn); - value.setTime(Date.now()); - } return { - value, + 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) { @@ -81,37 +69,34 @@ const Panel = React.createClass({ this.props.onClear(); }, - showHour: true, - showSecond: true, - render() { - const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions } = this.props; + const { locale, prefixCls, placeholder, hourOptions, minuteOptions, secondOptions, allowEmpty, showHour, showSecond, formatter, gregorianCalendarLocale } = this.props; const value = this.state.value; - const cls = classnames({ 'narrow': !this.showHour || !this.showSecond }); - return ( -
+