Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rough TS types and some doc updates for the Date Picker components #1574

Merged
merged 8 commits into from
Feb 25, 2019
2 changes: 1 addition & 1 deletion src-docs/src/views/date_picker/custom_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EuiButton,
} from '../../../../src/components';

// Should be a component because the datepicker does some ref stuff behind the scenes
// Should be a component because the date picker does some ref stuff behind the scenes
// eslint-disable-next-line react/prefer-stateless-function
class ExampleCustomInput extends React.Component {

Expand Down
8 changes: 4 additions & 4 deletions src-docs/src/views/date_picker/date_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const superDatePickerSource = require('!!raw-loader!./super_date_picker');
const superDatePickerHtml = renderToHtml(SuperDatePicker);

export const DatePickerExample = {
title: 'DatePicker',
title: 'Date Picker',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these!

sections: [{
source: [{
type: GuideSectionTypes.JS,
Expand All @@ -85,7 +85,7 @@ export const DatePickerExample = {
demo: <DatePicker />,
props: { EuiDatePicker },
}, {
title: 'Datepicker states',
title: 'Date picker states',
source: [{
type: GuideSectionTypes.JS,
code: statesSource,
Expand Down Expand Up @@ -140,7 +140,7 @@ export const DatePickerExample = {
),
demo: <Locale />,
}, {
title: 'Datepicker range',
title: 'Date picker range',
source: [{
type: GuideSectionTypes.JS,
code: rangeSource,
Expand Down Expand Up @@ -227,7 +227,7 @@ export const DatePickerExample = {
),
demo: <Utc />,
}, {
title: 'Datepicker inline',
title: 'Date picker inline',
source: [{
type: GuideSectionTypes.JS,
code: inlineSource,
Expand Down
101 changes: 101 additions & 0 deletions src/components/date_picker/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React from 'react';
import { CommonProps } from '../common';
import { Moment } from 'moment';
import { IconType } from '../icon';

declare module '@elastic/eui' {
interface OnTimeChangeProps {
start: string;
end: string;
isInvalid: boolean;
isQuickSelection: boolean;
}

interface OnRefreshChangeProps {
isPaused: boolean;
refreshInterval: number;
}

export type EuiDatePickerProps = CommonProps & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing the DefinitelyTyped defs and our component's propTypes, all of these should be optional except for onChange (In fact, we should switch the onChange propType to be .isRequired)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, yeah I just forgot to keep adding those ?, good call

calendarClassName?: string;
customInput?: React.ReactNode;
dateFormat?: string;
// not sure if this is correct
dayClassName?: (date: Moment) => string | undefined;
// not sure if this is correct
filterDates?: Moment[];
fullWidth?: boolean;
// not sure if this is correct
injectTimes?: Moment[];
// not sure what this generic value should be?
inputRef: React.Ref<HTMLInputElement>;
isInvalid: boolean;
isLoading: boolean;
locale: string;
maxDate: Moment;
maxTime: Moment;
minDate: Moment;
minTime: Moment;
// pulled from react-datepickeer definitely typed
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-datepicker/index.d.ts#L68
onChange(
date: Date | null,
event: React.SyntheticEvent<any> | undefined
): void;
openToDate: Moment;
placeholder: string;
popperClassName: string;
selected: Moment;
shadow: boolean;
shouldCloseOnSelect: boolean;
showIcon: boolean;
showTimeSelect: boolean;
showTimeSelectOnly: boolean;
timeFormat: string;
};

export const EuiDatePicker: React.SFC<EuiDatePickerProps>;

export type EuiDatePickerRangeProps = CommonProps & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startDateControl and endDateControl are required, but the rest are optional

startDateControl: typeof EuiDatePicker;
endDateControl: typeof EuiDatePicker;
iconType: boolean | IconType;
fullWidth: boolean;
isCustom: boolean;
};

export const EuiDatePickerRange: React.SFC<EuiDatePickerRangeProps>;

export interface EuiSuperDatePickerCommonRange {
start: string;
end: string;
label: string;
}

export interface EuiSuperDatePickerRecentRange {
start: string;
end: string;
}

export interface EuiSuperDatePickerQuickSelectPanel {
title: string;
content: React.ReactNode;
}

export type EuiSuperDatePickerProps = CommonProps & {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only onTimeChange is required (the last 3 should be optional)

start?: string;
end?: string;
isPaused?: boolean;
refreshInterval?: number;
onTimeChange: (props: OnTimeChangeProps) => void;
onRefreshChange?: (props: OnRefreshChangeProps) => void;
commonlyUsedRanges?: EuiSuperDatePickerCommonRange[];
dateFormat?: string;
recentlyUsedRanges?: EuiSuperDatePickerRecentRange[];
showUpdateButton: boolean;
isAutoRefreshOnly: boolean;
customQuickSelectPanels: EuiSuperDatePickerQuickSelectPanel[];
};

export const EuiSuperDatePicker: React.SFC<EuiSuperDatePickerProps>;
}