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
12 changed files
with
866 additions
and
115 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
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,51 @@ | ||
// @flow | ||
|
||
import { DateTime } from 'luxon'; | ||
|
||
export const DATE_MASK = '99/99/9999'; | ||
export const DATETIME_MASK = '99/99/9999, 99:99 aa'; | ||
|
||
export const DATE_FORMAT = 'MM/dd/yyyy'; | ||
export const DATETIME_FORMAT = 'MM/dd/yyyy, hh:mm a'; | ||
|
||
export const fromISOToViewFormat = (value: ?string, withTime: ?boolean) => { | ||
if (value) { | ||
value = DateTime.fromISO(value).toFormat(withTime ? DATETIME_FORMAT : DATE_FORMAT); | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
export const fromJSDateToISO = (value: ?Date, withTime: ?boolean) => { | ||
if (value) { | ||
value = DateTime.fromJSDate(value).toISO(); | ||
|
||
if (!withTime) { | ||
value = value.slice(0, 10); | ||
} | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
export const fromViewFormatToLuxon = (value: ?string, withTime: ?boolean) => { | ||
if (value) { | ||
value = DateTime.fromFormat(value, withTime ? DATETIME_FORMAT : DATE_FORMAT); | ||
} | ||
|
||
return value; | ||
}; | ||
|
||
export const fromLuxonToISO = (value: ?Object, withTime: ?boolean) => { | ||
if (value) { | ||
value = value.toISO(); | ||
|
||
if (!withTime) { | ||
value = value.slice(0, 10); | ||
} | ||
} else { | ||
value = null; | ||
} | ||
|
||
return value; | ||
}; |
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,3 +1,3 @@ | ||
// @flow | ||
|
||
export { theme, DateInput } from './DateInput'; | ||
export { DateInput } from './DateInput'; |
35 changes: 35 additions & 0 deletions
35
src/atoms/dataEntry/DateInputField/DateInputField.stories.js
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,35 @@ | ||
import React from 'react'; | ||
|
||
export default (asStory) => { | ||
asStory('ATOMS/DATA ENTRY/DateInputField', module, (story, { DateInputField }) => { | ||
class DateInputFieldContainer extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { value: props.value }; | ||
} | ||
|
||
onChange = (value) => { | ||
// eslint-disable-next-line | ||
console.log(value); | ||
this.setState({ value }); | ||
}; | ||
|
||
render() { | ||
const { value } = this.state; | ||
|
||
return <DateInputField { ...this.props } input={{ value, onChange: this.onChange }} />; | ||
} | ||
} | ||
|
||
story | ||
.add('default', () => ( | ||
<React.Fragment> | ||
<DateInputFieldContainer label="Date" value={ null } /> | ||
<DateInputFieldContainer label="Date" value="2018-11-07" /> | ||
<DateInputFieldContainer label="Datetime" value={ null } withTime /> | ||
</React.Fragment> | ||
)); | ||
}); | ||
}; | ||
|
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.