aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/value-and-defaultValue.js
diff options
context:
space:
mode:
authorafc163 <afc163@gmail.com>2016-11-11 12:10:26 +0800
committerafc163 <afc163@gmail.com>2016-11-11 12:10:26 +0800
commit614f6c90232d890984d0f4f2f13ff41fdb144b27 (patch)
treece1a9be06b3264fd9fc09b3c2b028646db03a322 /examples/value-and-defaultValue.js
parentcb5a445c75c7117c7c705d615099086274c2b254 (diff)
parentf429b4a79df25c9eadc3901e2483716835cc7de7 (diff)
downloadtime-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.tar.gz
time-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.tar.zst
time-picker-614f6c90232d890984d0f4f2f13ff41fdb144b27.zip
Merge branch 'master' of github.com:react-component/time-picker
Diffstat (limited to 'examples/value-and-defaultValue.js')
-rw-r--r--examples/value-and-defaultValue.js27
1 files changed, 11 insertions, 16 deletions
diff --git a/examples/value-and-defaultValue.js b/examples/value-and-defaultValue.js
index 1be30cc..0e1aa14 100644
--- a/examples/value-and-defaultValue.js
+++ b/examples/value-and-defaultValue.js
@@ -4,25 +4,17 @@ import 'rc-time-picker/assets/index.less';
4 4
5import React from 'react'; 5import React from 'react';
6import ReactDom from 'react-dom'; 6import ReactDom from 'react-dom';
7 7import moment from 'moment';
8import GregorianCalendar from 'gregorian-calendar';
9import DateTimeFormat from 'gregorian-calendar-format';
10import TimePicker from 'rc-time-picker'; 8import TimePicker from 'rc-time-picker';
11import TimePickerLocale from 'rc-time-picker/src/locale/zh_CN';
12
13const formatter = new DateTimeFormat('HH:mm:ss');
14
15const now = new GregorianCalendar(TimePickerLocale.calendar);
16now.setTime(Date.now());
17 9
18const App = React.createClass({ 10const App = React.createClass({
19 getInitialState() { 11 getInitialState() {
20 return { 12 return {
21 value: now, 13 value: moment(),
22 }; 14 };
23 }, 15 },
24 handleValueChange(value) { 16 handleValueChange(value) {
25 console.log(value && formatter.format(value)); 17 console.log(value && value.format('HH:mm:ss'));
26 this.setState({ value }); 18 this.setState({ value });
27 }, 19 },
28 clear() { 20 clear() {
@@ -33,11 +25,14 @@ const App = React.createClass({
33 render() { 25 render() {
34 return ( 26 return (
35 <div> 27 <div>
36 <TimePicker formatter={formatter} locale={TimePickerLocale} 28 <TimePicker
37 defaultValue={now} /> 29 defaultValue={this.state.value}
38 <TimePicker formatter={formatter} locale={TimePickerLocale} 30 onChange={this.handleValueChange}
39 value={this.state.value} 31 />
40 onChange={this.handleValueChange}/> 32 <TimePicker
33 value={this.state.value}
34 onChange={this.handleValueChange}
35 />
41 <button onClick={this.clear}>clear</button> 36 <button onClick={this.clear}>clear</button>
42 </div> 37 </div>
43 ); 38 );