From 3b3350d5d710a7caf14926dfcce3684d3df3aff8 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 11 Nov 2016 12:19:38 +0800 Subject: update props order --- src/TimePicker.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 358b596..99d1008 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -29,9 +29,9 @@ const Picker = React.createClass({ placeholder: PropTypes.string, format: PropTypes.string, showHour: PropTypes.bool, + showSecond: PropTypes.bool, style: PropTypes.object, className: PropTypes.string, - showSecond: PropTypes.bool, disabledHours: PropTypes.func, disabledMinutes: PropTypes.func, disabledSeconds: PropTypes.func, @@ -151,8 +151,8 @@ const Picker = React.createClass({ onClear={this.onPanelClear} defaultOpenValue={defaultOpenValue} showHour={showHour} - onEsc={this.onEsc} showSecond={showSecond} + onEsc={this.onEsc} allowEmpty={allowEmpty} format={this.getFormat()} placeholder={placeholder} -- cgit v1.2.3 From 37c36c09e0a4d693a2ec5623ff2ebc8d9ee16a06 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 11 Nov 2016 13:55:55 +0800 Subject: Add showMinute --- README.md | 1 + examples/format.html | 0 examples/format.js | 26 ++++++++++++++++++++++++++ src/Combobox.jsx | 6 +++++- src/Panel.jsx | 4 +++- src/TimePicker.jsx | 19 ++++++++++--------- 6 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 examples/format.html create mode 100644 examples/format.js diff --git a/README.md b/README.md index 5ec960c..05182c2 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ API | value | moment | null | current value | | placeholder | String | '' | time input's placeholder | | showHour | Boolean | whether show hour | | +| showMinute | Boolean | whether show minute | | | showSecond | Boolean | whether show second | | | format | String | | | | disabledHours | Function | disabled hour options | | diff --git a/examples/format.html b/examples/format.html new file mode 100644 index 0000000..e69de29 diff --git a/examples/format.js b/examples/format.js new file mode 100644 index 0000000..c9a9539 --- /dev/null +++ b/examples/format.js @@ -0,0 +1,26 @@ +import 'rc-time-picker/assets/index.less'; +import React from 'react'; +import ReactDom from 'react-dom'; +import moment from 'moment'; +import TimePicker from 'rc-time-picker'; + +const App = React.createClass({ + render() { + return ( +
+ + + + + + + +
+ ); + }, +}); + +ReactDom.render( + , + document.getElementById('__react-content') +); diff --git a/src/Combobox.jsx b/src/Combobox.jsx index 9d9da16..013617c 100644 --- a/src/Combobox.jsx +++ b/src/Combobox.jsx @@ -26,6 +26,7 @@ const Combobox = React.createClass({ value: PropTypes.object, onChange: PropTypes.func, showHour: PropTypes.bool, + showMinute: PropTypes.bool, showSecond: PropTypes.bool, hourOptions: PropTypes.array, minuteOptions: PropTypes.array, @@ -73,7 +74,10 @@ const Combobox = React.createClass({ }, getMinuteSelect(minute) { - const { prefixCls, minuteOptions, disabledMinutes, defaultOpenValue } = this.props; + const { prefixCls, minuteOptions, disabledMinutes, defaultOpenValue, showMinute } = this.props; + if (!showMinute) { + return null; + } const value = this.props.value || defaultOpenValue; const disabledOptions = disabledMinutes(value.hour()); diff --git a/src/Panel.jsx b/src/Panel.jsx index 0ed60e9..fddea1c 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -34,6 +34,7 @@ const Panel = React.createClass({ onEsc: PropTypes.func, allowEmpty: PropTypes.bool, showHour: PropTypes.bool, + showMinute: PropTypes.bool, showSecond: PropTypes.bool, onClear: PropTypes.func, addon: PropTypes.func, @@ -88,7 +89,7 @@ const Panel = React.createClass({ render() { const { prefixCls, className, placeholder, disabledHours, disabledMinutes, - disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, + disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showMinute, showSecond, format, defaultOpenValue, clearText, onEsc, addon, } = this.props; const { @@ -130,6 +131,7 @@ const Panel = React.createClass({ format={format} onChange={this.onChange} showHour={showHour} + showMinute={showMinute} showSecond={showSecond} hourOptions={hourOptions} minuteOptions={minuteOptions} diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 99d1008..e9f18a9 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -29,6 +29,7 @@ const Picker = React.createClass({ placeholder: PropTypes.string, format: PropTypes.string, showHour: PropTypes.bool, + showMinute: PropTypes.bool, showSecond: PropTypes.bool, style: PropTypes.object, className: PropTypes.string, @@ -53,6 +54,7 @@ const Picker = React.createClass({ defaultOpenValue: moment(), allowEmpty: true, showHour: true, + showMinute: true, showSecond: true, disabledHours: noop, disabledMinutes: noop, @@ -121,24 +123,22 @@ const Picker = React.createClass({ }, getFormat() { - const format = this.props.format; + const { format, showHour, showMinute, showSecond } = this.props; if (format) { return format; } - if (!this.props.showSecond) { - return 'HH:mm'; - } - if (!this.props.showHour) { - return 'mm:ss'; - } - return 'HH:mm:ss'; + return [ + showHour ? 'HH' : '', + showMinute ? 'mm' : '', + showSecond ? 'ss' : '', + ].filter(item => !!item).join(':'); }, getPanelElement() { const { prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, - allowEmpty, showHour, showSecond, defaultOpenValue, clearText, + allowEmpty, showHour, showMinute, showSecond, defaultOpenValue, clearText, addon, } = this.props; return ( @@ -151,6 +151,7 @@ const Picker = React.createClass({ onClear={this.onPanelClear} defaultOpenValue={defaultOpenValue} showHour={showHour} + showMinute={showMinute} showSecond={showSecond} onEsc={this.onEsc} allowEmpty={allowEmpty} -- cgit v1.2.3