-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/presentation): Add DayPickerInput form input component
- Loading branch information
1 parent
fc3a647
commit 744cf19
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
app/scripts/modules/core/src/presentation/forms/inputs/DayPickerInput.less
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,4 @@ | ||
/* Kludge while we figure out how to add the form-control ng-invalid classes directly to the nested day-picker input */ | ||
.DayPickerInput.ng-invalid > input { | ||
border-color: var(--color-danger); | ||
} |
33 changes: 33 additions & 0 deletions
33
app/scripts/modules/core/src/presentation/forms/inputs/DayPickerInput.tsx
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,33 @@ | ||
import * as React from 'react'; | ||
import { defaults } from 'lodash'; | ||
|
||
import { DayPickerInputProps } from 'react-day-picker'; | ||
import DayPicker from 'react-day-picker/DayPickerInput'; | ||
|
||
import { IFormInputProps } from '../interface'; | ||
import { createFakeReactSyntheticEvent, orEmptyString, validationClassName } from './utils'; | ||
|
||
import 'react-day-picker/lib/style.css'; | ||
import './DayPickerInput.less'; | ||
|
||
export function DayPickerInput(props: IFormInputProps & DayPickerInputProps) { | ||
const { validation, inputClassName, classNames, onChange, onBlur, name, ...rest } = props; | ||
const className = `${orEmptyString(inputClassName)} ${validationClassName(validation)}`; | ||
|
||
React.useEffect(() => onBlur(createFakeReactSyntheticEvent({ name, value: props.value })), []); | ||
|
||
const defaultClassNames = { container: '', overlayWrapper: '', overlay: '' }; | ||
const managedClassNames = defaults({}, classNames, defaultClassNames); | ||
managedClassNames.container = `DayPickerInput ${orEmptyString(managedClassNames.container)} ${className}`; | ||
|
||
return ( | ||
<DayPicker | ||
{...rest} | ||
classNames={managedClassNames} | ||
onDayChange={(date: Date) => { | ||
const newValue = date && date.toISOString().slice(0, 10); | ||
props.onChange(createFakeReactSyntheticEvent({ name, value: newValue })); | ||
}} | ||
/> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
app/scripts/modules/core/src/presentation/forms/inputs/index.ts
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