forked from Hacker0x01/react-datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to inject times outside of default time interval (Hacker0x01#…
…1329) * Allow specific times outside of intervals to be injected into time list * Update docs-site * Update docs * Add tests * More specs
- Loading branch information
1 parent
f715f15
commit ed55d2b
Showing
10 changed files
with
440 additions
and
257 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React from "react"; | ||
import DatePicker from "react-datepicker"; | ||
import moment from "moment"; | ||
|
||
export default class InjectTimes extends React.Component { | ||
state = { | ||
startDate: moment() | ||
.hours(16) | ||
.minutes(30) | ||
}; | ||
|
||
handleChange = date => { | ||
this.setState({ | ||
startDate: date | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="row"> | ||
<pre className="column example__code"> | ||
<code className="jsx"> | ||
{` | ||
<DatePicker | ||
selected={this.state.startDate} | ||
onChange={this.handleChange}`} | ||
<br /> | ||
<strong>{` showTimeSelect | ||
timeFormat="HH:mm" | ||
injectTimes={[moment().hours(0).minutes(1), moment().hours(12).minutes(5), moment().hours(23).minutes(59)]} | ||
dateFormat="LLL" | ||
/> | ||
`}</strong> | ||
</code> | ||
</pre> | ||
<div className="column"> | ||
<DatePicker | ||
selected={this.state.startDate} | ||
onChange={this.handleChange} | ||
showTimeSelect | ||
timeFormat="HH:mm" | ||
injectTimes={[ | ||
moment() | ||
.hours(0) | ||
.minutes(1), | ||
moment() | ||
.hours(12) | ||
.minutes(5), | ||
moment() | ||
.hours(23) | ||
.minutes(59) | ||
]} | ||
dateFormat="LLL" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from "react"; | ||
import { mount } from "enzyme"; | ||
import * as utils from "../src/date_utils"; | ||
import { setTime, cloneDate, newDate } from "../src/date_utils"; | ||
import TimeComponent from "../src/time"; | ||
|
||
function cloneDateWithTime(date, time) { | ||
return setTime(cloneDate(date), time); | ||
} | ||
|
||
describe("TimeComponent", () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.sandbox.create(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it("should show times specified in injectTimes props", () => { | ||
const today = utils.getStartOfDay(utils.newDate()); | ||
const timeComponent = mount( | ||
<TimeComponent | ||
injectTimes={[ | ||
utils.addMinutes(cloneDate(today), 1), | ||
utils.addMinutes(cloneDate(today), 725), | ||
utils.addMinutes(cloneDate(today), 1439) | ||
]} | ||
/> | ||
); | ||
|
||
const disabledItems = timeComponent.find( | ||
".react-datepicker__time-list-item--injected" | ||
); | ||
expect(disabledItems).to.have.length(3); | ||
}); | ||
|
||
it("should not affect existing time intervals", () => { | ||
const today = utils.getStartOfDay(utils.newDate()); | ||
const timeComponent = mount( | ||
<TimeComponent | ||
timeIntervals={60} | ||
injectTimes={[ | ||
utils.addMinutes(cloneDate(today), 0), | ||
utils.addMinutes(cloneDate(today), 60), | ||
utils.addMinutes(cloneDate(today), 1440) | ||
]} | ||
/> | ||
); | ||
|
||
const disabledItems = timeComponent.find( | ||
".react-datepicker__time-list-item--injected" | ||
); | ||
expect(disabledItems).to.have.length(0); | ||
}); | ||
}); |