Skip to content

Commit

Permalink
feat(core/presentation): Add DayPickerInput form input component
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Sep 1, 2019
1 parent fc3a647 commit 744cf19
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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);
}
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 }));
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './CheckboxInput';
export * from './ChecklistInput';
export * from './DayPickerInput';
export * from './JsonEditor';
export * from './NumberInput';
export * from './RadioButtonInput';
Expand Down

0 comments on commit 744cf19

Please sign in to comment.