From b86fe1d16a4ad06951bba9ac2990ec3e4563637a Mon Sep 17 00:00:00 2001 From: Artem Vasiliev Date: Thu, 20 Oct 2016 00:00:17 +0300 Subject: [PATCH] feat: 'addon' property support ..to be able to render something like OK button to timepicker: ``` { return (
panel.close()}> {__('OK')}
) }} /> ``` --- README.md | 1 + src/Panel.jsx | 9 ++++++++- src/TimePicker.jsx | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ae31aa..5ec960c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ API | disabledSeconds | Function | disabled second options | | | hideDisabledOptions | Boolean | whether hide disabled options | | | onChange | Function | null | called when select a different value | +| addon | Function | nothing | called from timepicker panel to render some addon to its bottom, like an OK button. Receives panel instance as parameter, to be able to close it like `panel.close()`.| | placement | String | bottomLeft | one of ['left','right','top','bottom', 'topLeft', 'topRight', 'bottomLeft', 'bottomRight'] | | transitionName | String | '' | | diff --git a/src/Panel.jsx b/src/Panel.jsx index 9066b03..0ed60e9 100644 --- a/src/Panel.jsx +++ b/src/Panel.jsx @@ -36,6 +36,7 @@ const Panel = React.createClass({ showHour: PropTypes.bool, showSecond: PropTypes.bool, onClear: PropTypes.func, + addon: PropTypes.func, }, getDefaultProps() { @@ -47,6 +48,7 @@ const Panel = React.createClass({ disabledMinutes: noop, disabledSeconds: noop, defaultOpenValue: moment(), + addon: noop, }; }, @@ -79,11 +81,15 @@ const Panel = React.createClass({ this.setState({ currentSelectPanel }); }, + close() { + this.props.onEsc(); + }, + render() { const { prefixCls, className, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, - format, defaultOpenValue, clearText, onEsc, + format, defaultOpenValue, clearText, onEsc, addon, } = this.props; const { value, currentSelectPanel, @@ -133,6 +139,7 @@ const Panel = React.createClass({ disabledSeconds={disabledSeconds} onCurrentSelectPanelChange={this.onCurrentSelectPanelChange} /> + {addon(this)} ); }, diff --git a/src/TimePicker.jsx b/src/TimePicker.jsx index 58f6ea1..358b596 100644 --- a/src/TimePicker.jsx +++ b/src/TimePicker.jsx @@ -39,6 +39,7 @@ const Picker = React.createClass({ onChange: PropTypes.func, onOpen: PropTypes.func, onClose: PropTypes.func, + addon: PropTypes.func, }, getDefaultProps() { @@ -61,6 +62,7 @@ const Picker = React.createClass({ onChange: noop, onOpen: noop, onClose: noop, + addon: noop, }; }, @@ -137,6 +139,7 @@ const Picker = React.createClass({ prefixCls, placeholder, disabledHours, disabledMinutes, disabledSeconds, hideDisabledOptions, allowEmpty, showHour, showSecond, defaultOpenValue, clearText, + addon, } = this.props; return ( ); }, -- 2.41.0