From 69f7c077e2b8226aee5af3272956882ce4053b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Mon, 9 Apr 2018 12:50:27 +0200 Subject: [PATCH] Add TypeScript types for portal, text, title components, popover service (#638) --- CHANGELOG.md | 1 + src/components/index.d.ts | 3 +++ src/components/portal/index.d.ts | 14 ++++++++++++++ src/components/text/index.d.ts | 30 ++++++++++++++++++++++++++++++ src/components/title/index.d.ts | 22 ++++++++++++++++++++++ src/services/index.d.ts | 1 + src/services/popover/index.d.ts | 29 +++++++++++++++++++++++++++++ 7 files changed, 100 insertions(+) create mode 100644 src/components/portal/index.d.ts create mode 100644 src/components/text/index.d.ts create mode 100644 src/components/title/index.d.ts create mode 100644 src/services/popover/index.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f9b07a8379..2bab3697198 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # [`master`](https://github.com/elastic/eui/tree/master) - Tweaked sizing, weights, color, line-heights, and added more levels to `EuiTitle` and `EuiText` ([#627](https://github.com/elastic/eui/pull/627)) +- Add TypeScript type defitions for `EuiPortal`, `EuiText` and `EuiTitle` as well as the `calculatePopoverPosition` service ([#638](https://github.com/elastic/eui/pull/638)) **Bug fixes** diff --git a/src/components/index.d.ts b/src/components/index.d.ts index 796d8927f13..d4d01305a17 100644 --- a/src/components/index.d.ts +++ b/src/components/index.d.ts @@ -13,3 +13,6 @@ /// /// /// +/// +/// +/// diff --git a/src/components/portal/index.d.ts b/src/components/portal/index.d.ts new file mode 100644 index 00000000000..709c4edb0e3 --- /dev/null +++ b/src/components/portal/index.d.ts @@ -0,0 +1,14 @@ +declare module '@elastic/eui' { + import { SFC } from 'react'; + + /** + * portal type defs + * + * @see './portal.js' + */ + type EuiPortalProps = { + children: React.ReactNode; + }; + + export const EuiPortal: SFC; +} diff --git a/src/components/text/index.d.ts b/src/components/text/index.d.ts new file mode 100644 index 00000000000..f9a01ba4e89 --- /dev/null +++ b/src/components/text/index.d.ts @@ -0,0 +1,30 @@ +/// + +declare module '@elastic/eui' { + import { SFC, HTMLAttributes } from 'react'; + + /** + * text type defs + * + * @see './text.js' + * @see './text_color.js' + */ + type EuiTextSize = 's' | 'xs'; + + type EuiTextColor = + | 'default' + | 'subdued' + | 'secondary' + | 'accent' + | 'danger' + | 'warning' + | 'ghost'; + + type EuiTextProps = CommonProps & + HTMLAttributes & { + size?: EuiTextSize; + color?: EuiTextColor; + }; + + export const EuiText: SFC; +} diff --git a/src/components/title/index.d.ts b/src/components/title/index.d.ts new file mode 100644 index 00000000000..bef381ec733 --- /dev/null +++ b/src/components/title/index.d.ts @@ -0,0 +1,22 @@ +/// + +declare module '@elastic/eui' { + import { SFC } from 'react'; + + /** + * title type defs + * + * @see './title.js' + */ + + type EuiTitleSize = 'xxxs' | 'xxs' | 'xs' | 's' | 'm' | 'l'; + + type EuiTitleTextTransform = 'uppercase'; + + type EuiTitleProps = CommonProps & { + size?: EuiTitleSize; + textTransform?: EuiTitleTextTransform; + }; + + export const EuiTitle: SFC; +} diff --git a/src/services/index.d.ts b/src/services/index.d.ts index 4420304cc7a..42a6bb261e0 100644 --- a/src/services/index.d.ts +++ b/src/services/index.d.ts @@ -1 +1,2 @@ /// +/// diff --git a/src/services/popover/index.d.ts b/src/services/popover/index.d.ts new file mode 100644 index 00000000000..39972cd5700 --- /dev/null +++ b/src/services/popover/index.d.ts @@ -0,0 +1,29 @@ +declare module '@elastic/eui' { + type EuiToolTipPosition = 'top' | 'right' | 'bottom' | 'left'; + + type EuiPopoverAnchorRect = { + top: number; + left: number; + width: number; + height: number; + }; + + type EuiPopoverDimensions = { + width: number; + height: number; + }; + + export const calculatePopoverPosition: ( + anchorBounds: EuiPopoverAnchorRect, + popoverBounds: EuiPopoverDimensions, + requestedPosition: EuiToolTipPosition, + buffer?: number, + positions?: EuiToolTipPosition[] + ) => { + top: number; + left: number; + width: number; + height: number; + position: EuiToolTipPosition; + }; +}