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
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Converted `EuiToggle` to TypeScript ([#1570](https://github.com/elastic/eui/pull/1570))
- Added type definitions for `EuiButtonGroup`,`EuiButtonToggle`, `EuiFilterButton`, `EuiFilterGroup`, and `EuiFilterSelectItem` ([#1570](https://github.com/elastic/eui/pull/1570))
- Added `displayOnly` prop to EuiFormRow ([#1582](https://github.com/elastic/eui/pull/1582))
- Added an index.d.ts file for the date picker components, including `EuiDatePicker`, `EuiDatePickerRange`, and `EuiSuperDatePicker` ([#1574](https://github.com/elastic/eui/pull/1574))

## [`7.2.0`](https://github.com/elastic/eui/tree/v7.2.0)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@types/enzyme": "^3.1.13",
"@types/jest": "^23.3.9",
"@types/react": "^16.3.0",
"@types/react-datepicker": "1.8.0",
"@types/react-is": "~16.3.0",
"@types/react-virtualized": "^9.18.6",
"@types/uuid": "^3.4.4",
Expand Down
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
76 changes: 76 additions & 0 deletions src/components/date_picker/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from 'react';
import { CommonProps } from '../common';
import { IconType } from '../icon';
import ReactDatePicker, { ReactDatePickerProps } from 'react-datepicker';
import { Moment } from 'moment';

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

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

interface EuiExtendedDatePickerProps extends ReactDatePickerProps {
fullWidth?: boolean;
isInvalid?: boolean;
isLoading?: boolean;
injectTimes?: Moment[]; // added here because the type is missing in @types/[email protected]
inputRef?: React.Ref<typeof ReactDatePicker>;
placeholder?: string;
shadow?: boolean;
showIcon?: boolean;
}

export type EuiDatePickerProps = CommonProps & EuiExtendedDatePickerProps;
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: React.ReactElement<EuiDatePickerProps>;
endDateControl: React.ReactElement<EuiDatePickerProps>;
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>;
}
1 change: 1 addition & 0 deletions src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// <reference path="./combo_box/index.d.ts" />
/// <reference path="./combo_box/index.d.ts" />
/// <reference path="./context_menu/index.d.ts" />
/// <reference path="./date_picker/index.d.ts" />
/// <reference path="./description_list/index.d.ts" />
/// <reference path="./empty_prompt/index.d.ts" />
/// <reference path="./error_boundary/index.d.ts" />
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,15 @@
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.3.tgz#bef071852dca2a2dbb65fecdb7bfb30cedae2de2"
integrity sha512-sfjHrNF4zWRv3fJUGyZW46wVxhYJ/GeWIPdKxbnLIhY3bWR0Ncl2kIhZI7rpjY9KtUQAkDP8jWEmaGQGFFvruA==

"@types/[email protected]":
version "1.8.0"
resolved "https://registry.yarnpkg.com/@types/react-datepicker/-/react-datepicker-1.8.0.tgz#b8b4f69d3e5398500c136f5338e0746ed98d46e8"
integrity sha512-QyHMOFCOFIkcyDCXUGnL7OyM+Gj2aG95d3t18wgrLTxQJseVQXeQFTVnUeXmmF2cZxeWtGTfRl1uYPTr3/rAFg==
dependencies:
"@types/react" "*"
moment ">=2.14.0"
popper.js "^1.14.1"

"@types/react-is@~16.3.0":
version "16.3.1"
resolved "https://registry.yarnpkg.com/@types/react-is/-/react-is-16.3.1.tgz#f3e1dee9d0eb58c049825540cb061b5588022a9e"
Expand Down Expand Up @@ -8859,6 +8868,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/moment/-/moment-2.21.0.tgz#2a114b51d2a6ec9e6d83cf803f838a878d8a023a"
integrity sha512-TCZ36BjURTeFTM/CwRcViQlfkMvL1/vFISuNLO5GkcVm1+QHfbSiNqZuWeMFjj1/3+uAjXswgRk30j1kkLYJBQ==

moment@>=2.14.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"
integrity sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==

moment@^2.20.1:
version "2.20.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd"
Expand Down Expand Up @@ -10159,6 +10173,11 @@ pngjs@~2.2.0:
resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-2.2.0.tgz#649663609a0ebab87c8f08b3fe724048b51d9d7f"
integrity sha1-ZJZjYJoOurh8jwiz/nJASLUdnX8=

popper.js@^1.14.1:
version "1.14.7"
resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.7.tgz#e31ec06cfac6a97a53280c3e55e4e0c860e7738e"
integrity sha512-4q1hNvoUre/8srWsH7hnoSJ5xVmIL4qgz+s4qf2TnJIMyZFUFMGH+9vE7mXynAlHSZ/NdTmmow86muD0myUkVQ==

portfinder@^1.0.9:
version "1.0.13"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.13.tgz#bb32ecd87c27104ae6ee44b5a3ccbf0ebb1aede9"
Expand Down