Skip to content

Commit d498a01

Browse files
committed
Selector and popover are both rendering
1 parent 0247297 commit d498a01

File tree

7 files changed

+209
-100
lines changed

7 files changed

+209
-100
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["stage-0", "es2015", "react"]
2+
"presets": ["es2015", "stage-0", "react"]
33
}

.storybook/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<link rel="stylesheet" href="css/bootstrap.css" />

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"build": "babel src --out-dir dist",
88
"lint": "prettier --trailing-comma es5 --write \"{src,stories}/**/*.js\"",
99
"test": "echo \"Error: no test specified\" && exit 1",
10-
"storybook": "start-storybook -p 6006",
10+
"storybook": "start-storybook -s ./node_modules/bootstrap/dist -p 6006",
1111
"build-storybook": "build-storybook"
1212
},
1313
"author": "",
1414
"license": "ISC",
1515
"devDependencies": {
16-
"prettier": "^0.22.0",
17-
"@kadira/storybook": "^2.21.0"
16+
"@kadira/storybook": "^2.21.0",
17+
"bootstrap": "^3.3.7",
18+
"prettier": "^0.22.0"
1819
},
1920
"peerDependencies": {
2021
"react": "^15.4.2",
@@ -25,6 +26,8 @@
2526
"babel-cli": "^6.23.0",
2627
"babel-preset-es2015": "^6.22.0",
2728
"babel-preset-react": "^6.23.0",
28-
"babel-preset-stage-0": "^6.22.0"
29+
"babel-preset-stage-0": "^6.22.0",
30+
"moment": "^2.17.1",
31+
"react-bootstrap": "^0.30.8"
2932
}
3033
}

src/MonthSelector.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
2+
import React, { PropTypes } from 'react';
3+
4+
import { Glyphicon, Button } from 'react-bootstrap';
5+
import moment from 'moment';
6+
7+
const styles = {
8+
yearNav: {
9+
display: 'flex',
10+
alignItems: 'center',
11+
margin: '0 1px 5px',
12+
},
13+
14+
yearLabel: {
15+
flex: '1',
16+
textAlign: 'center',
17+
fontWeight: 'bold',
18+
margin: '0 2px',
19+
},
20+
21+
yearLabelSpan: {
22+
verticalAlign: 'middle',
23+
},
24+
25+
monthContainer: {
26+
display: 'inline-block',
27+
padding: '1px',
28+
width: '25%',
29+
boxSizing: 'border-box',
30+
},
31+
32+
monthButton: {
33+
lineHeight: '3em',
34+
textAlign: 'center',
35+
width: '100%',
36+
}
37+
};
38+
39+
class MonthSelector extends React.Component {
40+
static propTypes = {
41+
onSelect: PropTypes.func.isRequired,
42+
month: PropTypes.number.isRequired,
43+
year: PropTypes.number.isRequired,
44+
};
45+
46+
constructor(props) {
47+
super();
48+
49+
this.onNextYear = this.onNextYear.bind(this);
50+
this.onPrevYear = this.onPrevYear.bind(this);
51+
this.onResetYear = this.onResetYear.bind(this);
52+
53+
this.state = {
54+
year: props.year,
55+
};
56+
}
57+
58+
onPrevYear() {
59+
this.setState({year: this.state.year - 1});
60+
}
61+
62+
onNextYear() {
63+
this.setState({year: this.state.year + 1});
64+
}
65+
66+
onSelect(month) {
67+
this.props.onSelect({
68+
month,
69+
year: this.state.year
70+
});
71+
}
72+
73+
onResetYear() {
74+
this.setState({ year: this.props.year });
75+
}
76+
77+
renderMonth(month) {
78+
const selected =
79+
this.props.month === month &&
80+
this.props.year === this.state.year;
81+
82+
return (
83+
<div style={styles.monthContainer} key={month}>
84+
<Button
85+
bsStyle={selected ? 'complete' : 'transparent'}
86+
style={styles.monthButton}
87+
onClick={() => this.onSelect(month)}>
88+
{moment().month(month - 1).format('MMM')}
89+
</Button>
90+
</div>
91+
);
92+
}
93+
94+
render() {
95+
const months = [];
96+
for (var i = 1; i <= 12; i++) {
97+
months.push(this.renderMonth(i));
98+
}
99+
100+
return (
101+
<div style={styles.root}>
102+
<div style={styles.yearNav}>
103+
<Button bsSize="small" onClick={this.onPrevYear}>
104+
<Glyphicon glyph="chevron-left" />
105+
</Button>
106+
<Button
107+
bsSize="small"
108+
bsStyle="transparent"
109+
onClick={this.onResetYear}
110+
style={styles.yearLabel}>
111+
<span style={styles.yearLabelSpan} className="block-header">{this.state.year}</span>
112+
</Button>
113+
<Button bsSize="small" onClick={this.onNextYear}>
114+
<Glyphicon glyph="chevron-right" />
115+
</Button>
116+
</div>
117+
<div style={styles.months}>
118+
{months}
119+
</div>
120+
</div>
121+
);
122+
}
123+
}
124+
125+
export default MonthSelector;

src/RangePopover.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */
2+
import React, { PropTypes } from 'react';
3+
import { Button, Popover, OverlayTrigger } from 'react-bootstrap';
4+
import moment from 'moment';
5+
6+
import MonthSelector from './MonthSelector';
7+
8+
class RangePopover extends React.Component {
9+
static propTypes = {
10+
onSave: PropTypes.func.isRequired,
11+
onClose: PropTypes.func.isRequired,
12+
start: PropTypes.string.isRequired,
13+
end: PropTypes.string.isRequired,
14+
};
15+
16+
constructor(props) {
17+
super();
18+
19+
this.onSetStart = this.onSetStart.bind(this);
20+
this.onSetEnd = this.onSetEnd.bind(this);
21+
this.onSave = this.onSave.bind(this);
22+
23+
this.state = {
24+
start: { year: 2012, month: 1 },
25+
end: { year: 2012, month: 2 }
26+
// start: dateParts(props.start),
27+
// end: dateParts(props.end),
28+
};
29+
}
30+
31+
onSetStart(start) {
32+
this.setState({ start });
33+
}
34+
35+
onSetEnd(end) {
36+
this.setState({ end });
37+
}
38+
39+
onSave() {
40+
const { start, end } = this.state;
41+
this.props.onSave({
42+
// start: moment().year(start.year).month(start.month - 1).date(1).format(DATE_FORMAT),
43+
// end: moment().year(end.year).month(end.month).date(0).format(DATE_FORMAT),
44+
});
45+
}
46+
47+
render() {
48+
const { start, end } = this.state;
49+
50+
return (
51+
<Popover {...this.props}>
52+
<MonthSelector
53+
month={start.month}
54+
year={start.year}
55+
onSelect={this.onSetStart}
56+
/>
57+
<MonthSelector
58+
month={end.month}
59+
year={end.year}
60+
onSelect={this.onSetEnd}
61+
/>
62+
<Button bsStyle="primary" onClick={this.onSave}>Save</Button>
63+
<Button onClick={this.props.onClose}>Close</Button>
64+
</Popover>
65+
);
66+
}
67+
}
68+
69+
export default RangePopover;

stories/Welcome.js

Lines changed: 0 additions & 95 deletions
This file was deleted.

stories/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React from "react";
22
import { storiesOf, action, linkTo } from "@kadira/storybook";
33
import DatePicker from "../src";
4+
import RangePopover from "../src/RangePopover";
5+
import MonthSelector from "../src/MonthSelector";
46

57
storiesOf("Date Picker", module).add("with text", () => <DatePicker />);
8+
storiesOf("Range Popover", module).add("with text", () => <RangePopover />);
9+
storiesOf("Month Selector", module).add("with text", () => {
10+
return <MonthSelector month={1} year={2016} onSelect={result => alert(result.month + '/' + result.year)} />
11+
});

0 commit comments

Comments
 (0)