-
Notifications
You must be signed in to change notification settings - Fork 11
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
11 changed files
with
515 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import DatePicker from 'react-datepicker'; | ||
import moment from 'moment'; | ||
import { injectGlobal } from 'emotion'; | ||
import 'react-datepicker/dist/react-datepicker.css'; | ||
|
||
import { createStyledTag, createTheme } from '../../../utils'; | ||
import { DateInputValue } from './DateInputValue'; | ||
|
||
injectGlobal(` | ||
.react-datepicker-wrapper, .react-datepicker__input-container { | ||
display: block; | ||
} | ||
`); | ||
|
||
type DateInputProps = {| | ||
onChange: (value: ?string) => void, | ||
value: string, | ||
|}; | ||
|
||
const name = 'dateInput'; | ||
|
||
const theme = createTheme(name, {}); | ||
|
||
const DateInputTag = createStyledTag(name, { | ||
display: 'flex', | ||
width: '100%', | ||
'> div': { | ||
flex: '1', | ||
}, | ||
}); | ||
|
||
class DateInput extends React.Component<DateInputProps> { | ||
onChange = (value: any) => { | ||
this.props.onChange(value ? value.format('YYYY-MM-DD') : null); | ||
}; | ||
|
||
collectProps() { | ||
const { value } = this.props; | ||
|
||
return { | ||
selected: value ? moment(value) : null, | ||
onChange: this.onChange, | ||
// $FlowFixMe | ||
customInput: <DateInputValue />, | ||
}; | ||
} | ||
|
||
render() { | ||
const collectedProps = this.collectProps(); | ||
|
||
return <DateInputTag><DatePicker { ...collectedProps } /></DateInputTag>; | ||
} | ||
} | ||
|
||
export { DateInput, theme }; |
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,14 @@ | ||
import React from 'react'; | ||
import moment from 'moment'; | ||
|
||
let value = moment().format('YYYY-MM-DD'); | ||
|
||
export default (asStory) => { | ||
asStory('ATOMS/DATA ENTRY/DateInput', module, (story, { DateInput }) => { | ||
story | ||
.add('default', () => ( | ||
<DateInput value={ value } onChange={ (val) => { value = val; } } /> | ||
)); | ||
}); | ||
}; | ||
|
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,17 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import 'react-datepicker/dist/react-datepicker.css'; | ||
|
||
import { Input } from '../Input'; | ||
|
||
type DateInputValueProps = {| | ||
onChange: (value: Object) => void, | ||
value: string, | ||
|}; | ||
|
||
const DateInputValue = ({ value, onChange, ...props }: DateInputValueProps) => ( | ||
<Input onChange={ (val) => onChange({ target: { value: val }}) } value={ value } { ...props } /> | ||
); | ||
|
||
export { DateInputValue }; |
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,3 @@ | ||
// @flow | ||
|
||
export { theme, DateInput } from './DateInput'; |
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,45 @@ | ||
import React from 'react'; | ||
|
||
import { createTheme } from '../../../utils'; | ||
import { DateInput } from '../DateInput'; | ||
import { FormField } from '../Form/FormField'; | ||
|
||
type DateInputFieldProps = {| | ||
/** field label */ | ||
label?: string, | ||
/** form input object */ | ||
input?: InputType, | ||
/** form meta object */ | ||
meta?: MetaType, | ||
|}; | ||
|
||
const name = 'DateInputField'; | ||
|
||
const theme = createTheme(name, { | ||
modifiers: { | ||
}, | ||
defaults: { | ||
}, | ||
}); | ||
|
||
function DateInputField({ | ||
label, | ||
input = {}, | ||
meta = {}, | ||
...rest | ||
}: DateInputFieldProps) { | ||
const { name, value, onChange } = input; | ||
|
||
return ( | ||
<FormField label={ label } input={ input } meta={ meta }> | ||
<DateInput | ||
{ ...rest } | ||
name={ name } | ||
value={ value } | ||
onChange={ onChange } | ||
/> | ||
</FormField> | ||
); | ||
} | ||
|
||
export { DateInputField, theme }; |
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 @@ | ||
export { DateInputField, theme } from './DateInputField'; |
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.