-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
643 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"presets": ["es2015", "react"] | ||
"presets": ["es2015", "stage-0", "react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
require('../src/less/input-moment.less'); | ||
require('./app.less'); | ||
import '../src/less/input-moment.less'; | ||
import './app.less'; | ||
|
||
var moment = require('moment'); | ||
var React = require('react'); | ||
var ReactDOM = require('react-dom'); | ||
var InputMoment = require('../src/input-moment'); | ||
var packageJson = require('../package.json'); | ||
import moment from 'moment'; | ||
import React, { Component } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import InputMoment from '../src/input-moment'; | ||
import packageJson from '../package.json'; | ||
|
||
var App = React.createClass({ | ||
displayName: 'App', | ||
class App extends Component { | ||
state = { | ||
m: moment() | ||
}; | ||
|
||
getInitialState() { | ||
return { | ||
m: moment() | ||
}; | ||
}, | ||
handleChange = m => { | ||
this.setState({ m }); | ||
}; | ||
|
||
handleSave = () => { | ||
console.log('saved', this.state.m.format('llll')); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="app"> | ||
<h1>{packageJson.name}</h1> | ||
<h2>{packageJson.description}</h2> | ||
<form> | ||
<div className="input"> | ||
<input | ||
type="text" | ||
value={this.state.m.format('llll')} | ||
readOnly | ||
<div className="input"> | ||
<input type="text" value={this.state.m.format('llll')} readOnly /> | ||
</div> | ||
<InputMoment | ||
moment={this.state.m} | ||
onChange={this.handleChange} | ||
onSave={this.handleSave} | ||
/> | ||
</div> | ||
<InputMoment | ||
moment={this.state.m} | ||
onChange={this.handleChange} | ||
onSave={this.handleSave} | ||
/> | ||
</form> | ||
</div> | ||
); | ||
}, | ||
|
||
handleChange(m) { | ||
this.setState({ m }); | ||
}, | ||
|
||
handleSave() { | ||
console.log('saved', this.state.m.format('llll')); | ||
} | ||
}); | ||
} | ||
|
||
ReactDOM.render(<App/>, document.getElementById('app')); | ||
ReactDOM.render(<App />, document.getElementById('app')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,83 @@ | ||
var cx = require('classnames'); | ||
var blacklist = require('blacklist'); | ||
var moment = require('moment'); | ||
var React = require('react'); | ||
var Calendar = require('./calendar'); | ||
var Time = require('./time'); | ||
import cx from 'classnames'; | ||
import moment from 'moment'; | ||
import React, { Component } from 'react'; | ||
import Calendar from './calendar'; | ||
import Time from './time'; | ||
|
||
module.exports = React.createClass({ | ||
displayName: 'InputMoment', | ||
export default class InputMoment extends Component { | ||
static defaultProps = { | ||
prevMonthIcon: 'ion-ios-arrow-left', | ||
nextMonthIcon: 'ion-ios-arrow-right' | ||
}; | ||
|
||
getInitialState() { | ||
return { | ||
tab: 0 | ||
}; | ||
}, | ||
state = { | ||
tab: 0 | ||
}; | ||
|
||
getDefaultProps() { | ||
return { | ||
prevMonthIcon: 'ion-ios-arrow-left', | ||
nextMonthIcon: 'ion-ios-arrow-right' | ||
}; | ||
}, | ||
handleClickTab = (tab, e) => { | ||
e.preventDefault(); | ||
this.setState({ tab: tab }); | ||
}; | ||
|
||
handleSave = e => { | ||
e.preventDefault(); | ||
if (this.props.onSave) this.props.onSave(); | ||
}; | ||
|
||
render() { | ||
var tab = this.state.tab; | ||
var m = this.props.moment; | ||
var props = blacklist(this.props, 'className', 'moment', 'prevMonthIcon', 'nextMonthIcon', 'onSave'); | ||
props.className = cx('m-input-moment', this.props.className); | ||
const { tab } = this.state; | ||
const { | ||
moment: m, | ||
className, | ||
prevMonthIcon, | ||
nextMonthIcon, | ||
onSave, | ||
...props | ||
} = this.props; | ||
const cls = cx('m-input-moment', className); | ||
|
||
return ( | ||
<div {...props}> | ||
<div className={cls} {...props}> | ||
<div className="options"> | ||
<button type="button" className={cx('ion-calendar im-btn', {'is-active': tab === 0})} onClick={this.handleClickTab.bind(null, 0)}> | ||
<button | ||
type="button" | ||
className={cx('ion-calendar im-btn', { 'is-active': tab === 0 })} | ||
onClick={() => this.handleClickTab(0)} | ||
> | ||
Date | ||
</button> | ||
<button type="button" className={cx('ion-clock im-btn', {'is-active': tab === 1})} onClick={this.handleClickTab.bind(null, 1)}> | ||
<button | ||
type="button" | ||
className={cx('ion-clock im-btn', { 'is-active': tab === 1 })} | ||
onClick={() => this.handleClickTab(1)} | ||
> | ||
Time | ||
</button> | ||
</div> | ||
|
||
<div className="tabs"> | ||
<Calendar | ||
className={cx('tab', {'is-active': tab === 0})} | ||
className={cx('tab', { 'is-active': tab === 0 })} | ||
moment={m} | ||
onChange={this.props.onChange} | ||
prevMonthIcon={this.props.prevMonthIcon} | ||
nextMonthIcon={this.props.nextMonthIcon} | ||
/> | ||
<Time | ||
className={cx('tab', {'is-active': tab === 1})} | ||
className={cx('tab', { 'is-active': tab === 1 })} | ||
moment={m} | ||
onChange={this.props.onChange} | ||
/> | ||
</div> | ||
|
||
<button type="button" className="im-btn btn-save ion-checkmark" | ||
onClick={this.handleSave}> | ||
<button | ||
type="button" | ||
className="im-btn btn-save ion-checkmark" | ||
onClick={this.handleSave} | ||
> | ||
Save | ||
</button> | ||
</div> | ||
); | ||
}, | ||
|
||
handleClickTab(tab, e) { | ||
e.preventDefault(); | ||
this.setState({tab: tab}); | ||
}, | ||
|
||
handleSave(e) { | ||
e.preventDefault(); | ||
if(this.props.onSave) this.props.onSave(); | ||
} | ||
}); | ||
} |
Oops, something went wrong.