From 4984ed85e54f442998a335db70618d6184fa397e Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 4 Aug 2016 19:53:55 +0800 Subject: 2.x :boom: --- src/Panel.jsx | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/Panel.jsx (limited to 'src/Panel.jsx') diff --git a/src/Panel.jsx b/src/Panel.jsx new file mode 100644 index 0000000..f70cf38 --- /dev/null +++ b/src/Panel.jsx @@ -0,0 +1,136 @@ +import React, { PropTypes } from 'react'; +import Header from './Header'; +import Combobox from './Combobox'; +import moment from 'moment'; + +function noop() { +} + +function generateOptions(length, disabledOptions, hideDisabledOptions) { + const arr = []; + for (let value = 0; value < length; value++) { + if (!disabledOptions || disabledOptions.indexOf(value) < 0 || !hideDisabledOptions) { + arr.push(value); + } + } + return arr; +} + +const Panel = React.createClass({ + propTypes: { + clearText: PropTypes.string, + prefixCls: PropTypes.string, + defaultOpenValue: PropTypes.object, + value: PropTypes.object, + placeholder: PropTypes.string, + format: PropTypes.string, + disabledHours: PropTypes.func, + disabledMinutes: PropTypes.func, + disabledSeconds: PropTypes.func, + hideDisabledOptions: PropTypes.bool, + onChange: PropTypes.func, + onEsc: PropTypes.func, + allowEmpty: PropTypes.bool, + showHour: PropTypes.bool, + showSecond: PropTypes.bool, + onClear: PropTypes.func, + }, + + getDefaultProps() { + return { + prefixCls: 'rc-time-picker-panel', + onChange: noop, + onClear: noop, + defaultOpenValue: moment(), + }; + }, + + getInitialState() { + return { + value: this.props.value, + selectionRange: [], + }; + }, + + componentWillReceiveProps(nextProps) { + const value = nextProps.value; + if (value) { + this.setState({ + value, + }); + } + }, + + onChange(newValue) { + this.setState({ value: newValue }); + this.props.onChange(newValue); + }, + + onClear() { + this.props.onClear(); + }, + + onCurrentSelectPanelChange(currentSelectPanel) { + this.setState({ currentSelectPanel }); + }, + + render() { + const { + prefixCls, placeholder, disabledHours, disabledMinutes, + disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, + format, defaultOpenValue, clearText, onEsc, + } = this.props; + const { + value, currentSelectPanel, + } = this.state; + const disabledHourOptions = disabledHours(); + const disabledMinuteOptions = disabledMinutes(value ? value.hour() : null); + const disabledSecondOptions = disabledSeconds(value ? value.hour() : null, + value ? value.minute() : null); + const hourOptions = generateOptions(24, disabledHourOptions, hideDisabledOptions); + const minuteOptions = generateOptions(60, disabledMinuteOptions, hideDisabledOptions); + const secondOptions = generateOptions(60, disabledSecondOptions, hideDisabledOptions); + + return ( +
+
+ +
+ ); + }, +}); + +export default Panel; -- cgit v1.2.3