Skip to content

Commit a2c8347

Browse files
committed
Merge pull request quri#110 from trubens/master
Added new feature, set size. Possible to set size to lg and sm.
2 parents 565bd93 + 7c3a3bc commit a2c8347

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ DateTimeField
3636
| **inputFormat** | string | "MM/DD/YY h:mm A" | Defines the way the date is represented in the HTML input |
3737
| **onChange** | function | x => console.log(x) | Callback trigger when the date changes. `x` is the new datetime value. |
3838
| **showToday** | boolean | true | Highlights today's date |
39+
| **size** | string | "md" | Changes the size of the date picker input field. Sizes: "sm", "md", "lg" |
3940
| **daysOfWeekDisabled** | array of integer | [] | Disables clicking on some days. Goes from 0 (Sunday) to 6 (Saturday). |
4041
| **viewMode** | string or number | 'days' | The default view to display when the picker is shown. ('years', 'months', 'days') |
4142
| **inputProps** | object | undefined | Defines additional attributes for the input element of the component. |

src/Constants.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
22
MODE_DATE: "date",
33
MODE_DATETIME: "datetime",
4-
MODE_TIME: "time"
4+
MODE_TIME: "time",
5+
6+
SIZE_SMALL: "sm",
7+
SIZE_MEDIUM: "md",
8+
SIZE_LARGE: "lg"
59
};

src/DateTimeField.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default class DateTimeField extends Component {
1111
showToday: true,
1212
viewMode: "days",
1313
daysOfWeekDisabled: [],
14+
size: Constants.SIZE_MEDIUM,
1415
mode: Constants.MODE_DATETIME,
1516
onChange: (x) => {
1617
console.log(x);
@@ -45,6 +46,7 @@ export default class DateTimeField extends Component {
4546
direction: PropTypes.string,
4647
showToday: PropTypes.bool,
4748
viewMode: PropTypes.string,
49+
size: PropTypes.oneOf([Constants.SIZE_SMALL, Constants.SIZE_MEDIUM, Constants.SIZE_LARGE]),
4850
daysOfWeekDisabled: PropTypes.arrayOf(PropTypes.integer)
4951
}
5052

@@ -307,6 +309,17 @@ export default class DateTimeField extends Component {
307309
});
308310
}
309311

312+
size = () => {
313+
switch (this.props.size) {
314+
case Constants.SIZE_SMALL:
315+
return "form-group-sm";
316+
case Constants.SIZE_LARGE:
317+
return "form-group-lg";
318+
}
319+
320+
return "";
321+
}
322+
310323
renderOverlay = () => {
311324
const styles = {
312325
position: "fixed",
@@ -317,7 +330,7 @@ export default class DateTimeField extends Component {
317330
zIndex: "999"
318331
};
319332
if (this.state.showPicker) {
320-
return (<div style={styles} onClick={this.closePicker} />);
333+
return (<div onClick={this.closePicker} style={styles} />);
321334
} else {
322335
return <span />;
323336
}
@@ -327,7 +340,7 @@ export default class DateTimeField extends Component {
327340
return (
328341
<div>
329342
{this.renderOverlay()}
330-
<DateTimePicker ref="widget"
343+
<DateTimePicker
331344
addDecade={this.addDecade}
332345
addHour={this.addHour}
333346
addMinute={this.addMinute}
@@ -337,6 +350,7 @@ export default class DateTimeField extends Component {
337350
maxDate={this.props.maxDate}
338351
minDate={this.props.minDate}
339352
mode={this.props.mode}
353+
ref="widget"
340354
selectedDate={this.state.selectedDate}
341355
setSelectedDate={this.setSelectedDate}
342356
setSelectedHour={this.setSelectedHour}
@@ -358,9 +372,11 @@ export default class DateTimeField extends Component {
358372
widgetClasses={this.state.widgetClasses}
359373
widgetStyle={this.state.widgetStyle}
360374
/>
361-
<div className="input-group date" ref="datetimepicker">
362-
<input type="text" className="form-control" onChange={this.onChange} value={this.state.inputValue} {...this.props.inputProps}/>
363-
<span className="input-group-addon" onClick={this.onClick} onBlur={this.onBlur} ref="dtpbutton"><Glyphicon glyph={this.state.buttonIcon} /></span>
375+
<div className={"input-group date " + this.size()} ref="datetimepicker">
376+
<input className="form-control" onChange={this.onChange} type="text" value={this.state.inputValue} {...this.props.inputProps}/>
377+
<span className="input-group-addon" onBlur={this.onBlur} onClick={this.onClick} ref="dtpbutton">
378+
<Glyphicon glyph={this.state.buttonIcon} />
379+
</span>
364380
</div>
365381
</div>
366382
);

0 commit comments

Comments
 (0)