X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fmodule%2FPanel.jsx;h=4c7eaae17048f77b747fe0c6d8544ba608c532d7;hb=a6978323930a81d983b0051ad61bcf81fb7a7235;hp=f04115823a9a914fe878847034fd07125ba14f54;hpb=63541ed7b1c9ad58348ea86c97f3e8b31830535b;p=github%2Ffretlink%2Ftime-picker.git diff --git a/src/module/Panel.jsx b/src/module/Panel.jsx index f041158..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,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,37 +69,34 @@ const Panel = React.createClass({ this.props.onClear(); }, - 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 ( -
+