Skip to content

Commit

Permalink
enables typing for ReactDatePicker usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dimitropoulos committed Mar 1, 2020
1 parent a5e12fa commit 11193d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/date_picker/date_picker.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Component, MouseEventHandler } from 'react';
import React, { Component, MouseEventHandler, Ref } from 'react';
import classNames from 'classnames';

import { Moment } from 'moment'; // eslint-disable-line import/named
import { ReactDatePicker as DatePicker } from '../../../packages';
// @ts-ignore the type is provided by
import { ReactDatePicker as _ReactDatePicker } from '../../../packages';

import { EuiFormControlLayout, EuiValidatableControl } from '../form';

Expand All @@ -17,6 +18,8 @@ import { EuiFormControlLayoutIconsProps } from '../form/form_control_layout/form
export const euiDatePickerDefaultDateFormat = 'MM/DD/YYYY';
export const euiDatePickerDefaultTimeFormat = 'hh:mm A';

const DatePicker = _ReactDatePicker as typeof ReactDatePicker;

interface EuiExtendedDatePickerProps extends ReactDatePickerProps {
/**
* Applies classes to the numbered days provided. Check docs for example.
Expand All @@ -28,15 +31,10 @@ interface EuiExtendedDatePickerProps extends ReactDatePickerProps {
*/
fullWidth?: boolean;

/**
* Adds additional times to the time selector other then :30 increments
*/
injectTimes?: Moment[]; // added here because the type is missing in @types/[email protected]

/**
* Applies ref to the input
*/
inputRef?: React.Ref<typeof ReactDatePicker>;
inputRef: Ref<typeof ReactDatePicker>;

/**
* Provides styling to the input when invalid
Expand Down Expand Up @@ -81,6 +79,7 @@ export class EuiDatePicker extends Component<EuiDatePickerProps> {
adjustDateOnChange: true,
dateFormat: euiDatePickerDefaultDateFormat,
fullWidth: false,
inputRef: () => {},
isLoading: false,
shadow: true,
shouldCloseOnSelect: true,
Expand Down Expand Up @@ -229,6 +228,7 @@ export class EuiDatePicker extends Component<EuiDatePickerProps> {
openToDate={openToDate}
placeholderText={placeholder}
popperClassName={popperClassName}
// @ts-ignore this is due to `react-datepicker` (i.e. `ReactDatePicker`, this component) being a `React.ClassicComponentClass` rather than a `React.Component`.
ref={inputRef}
selected={selected}
shouldCloseOnSelect={shouldCloseOnSelect}
Expand Down
5 changes: 5 additions & 0 deletions src/components/date_picker/react-datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface ReactDatePickerProps {
includeDates?: moment.Moment[];
includeTimes?: moment.Moment[];
inline?: boolean;

/**
* Adds additional times to the time selector other then :30 increments
*/
injectTimes?: moment.Moment[]; // added here because the type is missing in @types/[email protected]
isClearable?: boolean;

/**
Expand Down

0 comments on commit 11193d6

Please sign in to comment.