-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2695 from kravets-levko/feature/better-datetime-i…
…nputs Improve Date/DateTime type parameters
- Loading branch information
Showing
7 changed files
with
960 additions
and
4 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
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,37 @@ | ||
import moment from 'moment'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { react2angular } from 'react2angular'; | ||
import { DatePicker } from 'antd'; | ||
|
||
function DateInput({ | ||
value, | ||
onSelect, | ||
clientConfig, | ||
}) { | ||
const format = clientConfig.dateFormat || 'YYYY-MM-DD'; | ||
const defaultValue = moment(value, format); | ||
return ( | ||
<DatePicker | ||
{...(defaultValue.isValid() ? { defaultValue } : {})} | ||
format={format} | ||
placeholder="Select Date" | ||
onChange={onSelect} | ||
/> | ||
); | ||
} | ||
|
||
DateInput.propTypes = { | ||
value: PropTypes.instanceOf(Date), | ||
onSelect: PropTypes.func, | ||
}; | ||
|
||
DateInput.defaultProps = { | ||
value: Date.now(), | ||
onSelect: () => {}, | ||
}; | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('dateInput', react2angular(DateInput, null, ['clientConfig'])); | ||
} | ||
|
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,42 @@ | ||
import moment from 'moment'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { react2angular } from 'react2angular'; | ||
import { DatePicker } from 'antd'; | ||
|
||
function DateTimeInput({ | ||
value, | ||
withSeconds, | ||
onSelect, | ||
clientConfig, | ||
}) { | ||
const format = (clientConfig.dateFormat || 'YYYY-MM-DD') + | ||
(withSeconds ? ' HH:mm:ss' : ' HH:mm'); | ||
const defaultValue = moment(value, format); | ||
return ( | ||
<DatePicker | ||
showTime | ||
{...(defaultValue.isValid() ? { defaultValue } : {})} | ||
format={format} | ||
placeholder="Select Date and Time" | ||
onChange={onSelect} | ||
/> | ||
); | ||
} | ||
|
||
DateTimeInput.propTypes = { | ||
value: PropTypes.instanceOf(Date), | ||
withSeconds: PropTypes.bool, | ||
onSelect: PropTypes.func, | ||
}; | ||
|
||
DateTimeInput.defaultProps = { | ||
value: Date.now(), | ||
withSeconds: false, | ||
onSelect: () => {}, | ||
}; | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('dateTimeInput', react2angular(DateTimeInput, null, ['clientConfig'])); | ||
} | ||
|
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
Oops, something went wrong.