From 02ffc45618ab84b843856879094c7f6946eee910 Mon Sep 17 00:00:00 2001 From: Light Lin Date: Wed, 7 Sep 2016 13:14:47 +0800 Subject: [PATCH 1/4] Add label prop to have a label text in input I just update some code to make it able to have label through prop. --- DateTime.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/DateTime.js b/DateTime.js index 41eb5f3b2..8ea385dd3 100644 --- a/DateTime.js +++ b/DateTime.js @@ -28,6 +28,7 @@ var Datetime = React.createClass({ onChange: TYPES.func, locale: TYPES.string, input: TYPES.bool, + label: TYPES.string, // dateFormat: TYPES.string | TYPES.bool, // timeFormat: TYPES.string | TYPES.bool, inputProps: TYPES.object, @@ -370,15 +371,42 @@ var Datetime = React.createClass({ ; if ( this.props.input ){ - children = [ DOM.input( assign({ - key: 'i', - type:'text', - className: 'form-control', - onFocus: this.openCalendar, - onChange: this.onInputChange, - onKeyDown: this.onInputKey, - value: this.state.inputValue - }, this.props.inputProps ))]; + if ( this.props.label ) { + children = [ DOM.div({ + key: 'd', + className: 'form-group' + }, + [ DOM.span({ + className: 'input-group' + }, + [ DOM.span({ + key: 'a', + className: 'input-group-addon', + children: this.props.label + }), + DOM.input( assign({ + key: 'i', + type:'text', + className: 'form-control', + onFocus: this.openCalendar, + onChange: this.onInputChange, + onKeyDown: this.onInputKey, + value: this.state.inputValue + }, this.props.inputProps )) + ] + )] + )] + } else { + children = [ DOM.input( assign({ + key: 'i', + type:'text', + className: 'form-control', + onFocus: this.openCalendar, + onChange: this.onInputChange, + onKeyDown: this.onInputKey, + value: this.state.inputValue + }, this.props.inputProps ))]; + } } else { className += ' rdtStatic'; } From 831fe06d2115bd04197ed844e412de45e8266f2a Mon Sep 17 00:00:00 2001 From: Light Lin Date: Wed, 7 Sep 2016 13:29:20 +0800 Subject: [PATCH 2/4] Update DateTime.js Add accept prop types for label --- DateTime.js | 50 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 37 deletions(-) diff --git a/DateTime.js b/DateTime.js index 8ea385dd3..3e1872e5c 100644 --- a/DateTime.js +++ b/DateTime.js @@ -28,7 +28,10 @@ var Datetime = React.createClass({ onChange: TYPES.func, locale: TYPES.string, input: TYPES.bool, - label: TYPES.string, + label: TYPES.oneOfType([ + TYPES.string, + TYPES.element + ]), // dateFormat: TYPES.string | TYPES.bool, // timeFormat: TYPES.string | TYPES.bool, inputProps: TYPES.object, @@ -371,42 +374,15 @@ var Datetime = React.createClass({ ; if ( this.props.input ){ - if ( this.props.label ) { - children = [ DOM.div({ - key: 'd', - className: 'form-group' - }, - [ DOM.span({ - className: 'input-group' - }, - [ DOM.span({ - key: 'a', - className: 'input-group-addon', - children: this.props.label - }), - DOM.input( assign({ - key: 'i', - type:'text', - className: 'form-control', - onFocus: this.openCalendar, - onChange: this.onInputChange, - onKeyDown: this.onInputKey, - value: this.state.inputValue - }, this.props.inputProps )) - ] - )] - )] - } else { - children = [ DOM.input( assign({ - key: 'i', - type:'text', - className: 'form-control', - onFocus: this.openCalendar, - onChange: this.onInputChange, - onKeyDown: this.onInputKey, - value: this.state.inputValue - }, this.props.inputProps ))]; - } + children = [ DOM.input( assign({ + key: 'i', + type:'text', + className: 'form-control', + onFocus: this.openCalendar, + onChange: this.onInputChange, + onKeyDown: this.onInputKey, + value: this.state.inputValue + }, this.props.inputProps ))]; } else { className += ' rdtStatic'; } From 03364ab8bed305f64d043e845217c300d2da80a2 Mon Sep 17 00:00:00 2001 From: Light Lin Date: Wed, 7 Sep 2016 13:35:25 +0800 Subject: [PATCH 3/4] Update DateTime.js --- DateTime.js | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/DateTime.js b/DateTime.js index 3e1872e5c..d099478e3 100644 --- a/DateTime.js +++ b/DateTime.js @@ -374,15 +374,43 @@ var Datetime = React.createClass({ ; if ( this.props.input ){ - children = [ DOM.input( assign({ - key: 'i', - type:'text', - className: 'form-control', - onFocus: this.openCalendar, - onChange: this.onInputChange, - onKeyDown: this.onInputKey, - value: this.state.inputValue - }, this.props.inputProps ))]; + if ( this.props.label ) { + children = [ DOM.div({ + key: 'd', + className: 'form-group' + }, + [ DOM.span({ + key: 'i', + className: 'input-group' + }, + [ DOM.span({ + key: 'a', + className: 'input-group-addon', + children: this.props.label + }), + DOM.input( assign({ + key: 'i', + type:'text', + className: 'form-control', + onFocus: this.openCalendar, + onChange: this.onInputChange, + onKeyDown: this.onInputKey, + value: this.state.inputValue + }, this.props.inputProps )) + ] + )] + )] + } else { + children = [ DOM.input( assign({ + key: 'i', + type:'text', + className: 'form-control', + onFocus: this.openCalendar, + onChange: this.onInputChange, + onKeyDown: this.onInputKey, + value: this.state.inputValue + }, this.props.inputProps ))]; + } } else { className += ' rdtStatic'; } From 3f10cb396234cad22c4571580f3c5a8ef600096a Mon Sep 17 00:00:00 2001 From: Light Lin Date: Wed, 7 Sep 2016 13:45:35 +0800 Subject: [PATCH 4/4] Update DateTime.js --- DateTime.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateTime.js b/DateTime.js index d099478e3..6ce0fdaab 100644 --- a/DateTime.js +++ b/DateTime.js @@ -399,7 +399,7 @@ var Datetime = React.createClass({ }, this.props.inputProps )) ] )] - )] + )]; } else { children = [ DOM.input( assign({ key: 'i',