diff --git a/CHANGELOG.md b/CHANGELOG.md
index afc59bc8836..6918478e298 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)
- Added missing `compressed` styling to `EuiSwitch` ([#2327](https://github.com/elastic/eui/pull/2327))
+- Migrate `EuiBottomBar`, `EuiHealth` and `EuiImage` to TS ([#2328](https://github.com/elastic/eui/pull/2328))
## [`14.0.0`](https://github.com/elastic/eui/tree/v14.0.0)
diff --git a/src-docs/src/i18ntokens.json b/src-docs/src/i18ntokens.json
index c388889539e..9373dc86839 100644
--- a/src-docs/src/i18ntokens.json
+++ b/src-docs/src/i18ntokens.json
@@ -85,15 +85,15 @@
"highlighting": "string",
"loc": {
"start": {
- "line": 54,
+ "line": 70,
"column": 12
},
"end": {
- "line": 57,
+ "line": 73,
"column": 14
}
},
- "filepath": "src/components/bottom_bar/bottom_bar.js"
+ "filepath": "src/components/bottom_bar/bottom_bar.tsx"
},
{
"token": "euiCardSelect.selected",
diff --git a/src/components/bottom_bar/__snapshots__/bottom_bar.test.js.snap b/src/components/bottom_bar/__snapshots__/bottom_bar.test.tsx.snap
similarity index 100%
rename from src/components/bottom_bar/__snapshots__/bottom_bar.test.js.snap
rename to src/components/bottom_bar/__snapshots__/bottom_bar.test.tsx.snap
diff --git a/src/components/bottom_bar/bottom_bar.test.js b/src/components/bottom_bar/bottom_bar.test.tsx
similarity index 81%
rename from src/components/bottom_bar/bottom_bar.test.js
rename to src/components/bottom_bar/bottom_bar.test.tsx
index 06ad975abd8..97fca8f042a 100644
--- a/src/components/bottom_bar/bottom_bar.test.js
+++ b/src/components/bottom_bar/bottom_bar.test.tsx
@@ -2,11 +2,13 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
+import { keysOf } from '../common';
-import { EuiBottomBar, PADDING_SIZES } from './bottom_bar';
+import { EuiBottomBar, paddingSizeToClassNameMap } from './bottom_bar';
// TODO: Temporary hack which we can remove once react-test-renderer supports portals.
// More info at https://github.com/facebook/react/issues/11565.
+// @ts-ignore
ReactDOM.createPortal = node => node;
describe('EuiBottomBar', () => {
@@ -20,7 +22,7 @@ describe('EuiBottomBar', () => {
describe('props', () => {
describe('paddingSize', () => {
- PADDING_SIZES.forEach(paddingSize => {
+ keysOf(paddingSizeToClassNameMap).forEach(paddingSize => {
test(`${paddingSize} is rendered`, () => {
const component = render();
diff --git a/src/components/bottom_bar/bottom_bar.js b/src/components/bottom_bar/bottom_bar.tsx
similarity index 73%
rename from src/components/bottom_bar/bottom_bar.js
rename to src/components/bottom_bar/bottom_bar.tsx
index 9ac5c915a59..67d633ac67b 100644
--- a/src/components/bottom_bar/bottom_bar.js
+++ b/src/components/bottom_bar/bottom_bar.tsx
@@ -1,23 +1,40 @@
import React, { Component } from 'react';
-import PropTypes from 'prop-types';
import classNames from 'classnames';
+import { CommonProps } from '../common';
import { EuiPortal } from '../portal';
import { EuiScreenReaderOnly } from '../accessibility';
import { EuiI18n } from '../i18n';
-const paddingSizeToClassNameMap = {
+type BottomBarPaddingSize = 'none' | 's' | 'm' | 'l';
+
+// Exported for testing
+export const paddingSizeToClassNameMap: {
+ [value in BottomBarPaddingSize]: string | null
+} = {
none: null,
s: 'euiBottomBar--paddingSmall',
m: 'euiBottomBar--paddingMedium',
l: 'euiBottomBar--paddingLarge',
};
-export const PADDING_SIZES = Object.keys(paddingSizeToClassNameMap);
+interface Props extends CommonProps {
+ /**
+ * Optional class applied to the body class
+ */
+ bodyClassName?: string;
+
+ /**
+ * Padding applied to the bar
+ */
+ paddingSize?: BottomBarPaddingSize;
+}
+
+export class EuiBottomBar extends Component {
+ private bar: HTMLDivElement | null = null;
-export class EuiBottomBar extends Component {
componentDidMount() {
- const height = this.bar.clientHeight;
+ const height = this.bar ? this.bar.clientHeight : -1;
document.body.style.paddingBottom = `${height}px`;
if (this.props.bodyClassName) {
document.body.classList.add(this.props.bodyClassName);
@@ -35,8 +52,7 @@ export class EuiBottomBar extends Component {
const {
children,
className,
- paddingSize,
- // eslint-disable-next-line no-unused-vars
+ paddingSize = 'm',
bodyClassName,
...rest
} = this.props;
@@ -69,23 +85,3 @@ export class EuiBottomBar extends Component {
);
}
}
-
-EuiBottomBar.propTypes = {
- children: PropTypes.node,
- /**
- * Optional class applied to the bar itself
- */
- className: PropTypes.string,
- /**
- * Optional class applied to the body class
- */
- bodyClassName: PropTypes.string,
- /**
- * Padding applied to the bar
- */
- paddingSize: PropTypes.oneOf(PADDING_SIZES),
-};
-
-EuiBottomBar.defaultProps = {
- paddingSize: 'm',
-};
diff --git a/src/components/bottom_bar/index.js b/src/components/bottom_bar/index.ts
similarity index 100%
rename from src/components/bottom_bar/index.js
rename to src/components/bottom_bar/index.ts
diff --git a/src/components/health/__snapshots__/health.test.js.snap b/src/components/health/__snapshots__/health.test.tsx.snap
similarity index 100%
rename from src/components/health/__snapshots__/health.test.js.snap
rename to src/components/health/__snapshots__/health.test.tsx.snap
diff --git a/src/components/health/health.test.js b/src/components/health/health.test.tsx
similarity index 100%
rename from src/components/health/health.test.js
rename to src/components/health/health.test.tsx
diff --git a/src/components/health/health.js b/src/components/health/health.tsx
similarity index 56%
rename from src/components/health/health.js
rename to src/components/health/health.tsx
index 9c59cd43eaf..1c01f05eb6f 100644
--- a/src/components/health/health.js
+++ b/src/components/health/health.tsx
@@ -1,12 +1,22 @@
-import React from 'react';
-import PropTypes from 'prop-types';
+import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';
+import { CommonProps, Omit } from '../common';
-import { EuiIcon } from '../icon';
+import { EuiIcon, IconColor } from '../icon';
import { EuiFlexGroup, EuiFlexItem } from '../flex';
-export const EuiHealth = ({ children, className, color, ...rest }) => {
+type EuiHealthProps = CommonProps &
+ Omit, 'color'> & {
+ color?: IconColor;
+ };
+
+export const EuiHealth: FunctionComponent = ({
+ children,
+ className,
+ color,
+ ...rest
+}) => {
const classes = classNames('euiHealth', className);
return (
@@ -20,8 +30,3 @@ export const EuiHealth = ({ children, className, color, ...rest }) => {
);
};
-
-EuiHealth.propTypes = {
- children: PropTypes.node,
- className: PropTypes.string,
-};
diff --git a/src/components/health/index.d.ts b/src/components/health/index.d.ts
deleted file mode 100644
index 5f57a7bb137..00000000000
--- a/src/components/health/index.d.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { IconColor } from '../icon';
-
-import { FunctionComponent, HTMLAttributes } from 'react';
-import { CommonProps } from '../common';
-
-declare module '@elastic/eui' {
- /**
- * health type defs
- *
- * @see './health.js'
- */
-
- type EuiHealthProps = CommonProps &
- HTMLAttributes & {
- color: IconColor;
- };
-
- export const EuiHealth: FunctionComponent;
-}
diff --git a/src/components/health/index.js b/src/components/health/index.ts
similarity index 100%
rename from src/components/health/index.js
rename to src/components/health/index.ts
diff --git a/src/components/image/__snapshots__/image.test.js.snap b/src/components/image/__snapshots__/image.test.tsx.snap
similarity index 94%
rename from src/components/image/__snapshots__/image.test.js.snap
rename to src/components/image/__snapshots__/image.test.tsx.snap
index 10a6524c3f6..3154b1c1983 100644
--- a/src/components/image/__snapshots__/image.test.js.snap
+++ b/src/components/image/__snapshots__/image.test.tsx.snap
@@ -12,6 +12,7 @@ exports[`EuiImage is rendered 1`] = `
diff --git a/src/components/image/image.test.js b/src/components/image/image.test.tsx
similarity index 80%
rename from src/components/image/image.test.js
rename to src/components/image/image.test.tsx
index e235f0ce345..7c1630a7494 100644
--- a/src/components/image/image.test.js
+++ b/src/components/image/image.test.tsx
@@ -7,7 +7,7 @@ import { EuiImage } from './image';
describe('EuiImage', () => {
test('is rendered', () => {
const component = render(
-
+
);
expect(component).toMatchSnapshot();
diff --git a/src/components/image/image.js b/src/components/image/image.tsx
similarity index 74%
rename from src/components/image/image.js
rename to src/components/image/image.tsx
index c31d158e84b..6bd97d271e3 100644
--- a/src/components/image/image.js
+++ b/src/components/image/image.tsx
@@ -1,7 +1,7 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
+import React, { Component, HTMLAttributes } from 'react';
import classNames from 'classnames';
+import { CommonProps } from '../common';
import { EuiOverlayMask } from '../overlay_mask';
import { EuiIcon } from '../icon';
@@ -10,7 +10,9 @@ import { EuiFocusTrap } from '../focus_trap';
import { keyCodes } from '../../services';
-const sizeToClassNameMap = {
+type ImageSize = 's' | 'm' | 'l' | 'xl' | 'fullWidth' | 'original';
+
+const sizeToClassNameMap: { [size in ImageSize]: string } = {
s: 'euiImage--small',
m: 'euiImage--medium',
l: 'euiImage--large',
@@ -21,21 +23,33 @@ const sizeToClassNameMap = {
export const SIZES = Object.keys(sizeToClassNameMap);
-const fullScreenIconColorMap = {
+type FullScreenIconColor = 'light' | 'dark';
+
+const fullScreenIconColorMap: { [color in FullScreenIconColor]: string } = {
light: 'ghost',
dark: 'default',
};
-export class EuiImage extends Component {
- constructor(props) {
- super(props);
+interface EuiImageProps extends CommonProps, HTMLAttributes {
+ alt: string;
+ size?: ImageSize;
+ fullScreenIconColor?: FullScreenIconColor;
+ url: string;
+ caption?: string;
+ hasShadow?: boolean;
+ allowFullScreen?: boolean;
+}
- this.state = {
- isFullScreen: false,
- };
- }
+interface State {
+ isFullScreen: boolean;
+}
- onKeyDown = event => {
+export class EuiImage extends Component {
+ state: State = {
+ isFullScreen: false,
+ };
+
+ onKeyDown = (event: React.KeyboardEvent) => {
if (event.keyCode === keyCodes.ESCAPE) {
event.preventDefault();
event.stopPropagation();
@@ -59,11 +73,11 @@ export class EuiImage extends Component {
const {
className,
url,
- size,
+ size = 'original',
caption,
hasShadow,
allowFullScreen,
- fullScreenIconColor,
+ fullScreenIconColor = 'light',
alt,
...rest
} = this.props;
@@ -107,11 +121,7 @@ export class EuiImage extends Component {
type="button"
onClick={this.closeFullScreen}
onKeyDown={this.onKeyDown}>
- {
- this.figure = node;
- }}
- className="euiImageFullScreen">
+
{optionalCaption}
@@ -140,14 +150,3 @@ export class EuiImage extends Component {
);
}
}
-
-EuiImage.propTypes = {
- alt: PropTypes.string.isRequired,
- size: PropTypes.string.isRequired,
- fullScreenIconColor: PropTypes.string,
-};
-
-EuiImage.defaultProps = {
- size: 'original',
- fullScreenIconColor: 'light',
-};
diff --git a/src/components/image/index.js b/src/components/image/index.ts
similarity index 100%
rename from src/components/image/index.js
rename to src/components/image/index.ts
diff --git a/src/components/index.d.ts b/src/components/index.d.ts
index 50edc2d4bb3..e9ed157e185 100644
--- a/src/components/index.d.ts
+++ b/src/components/index.d.ts
@@ -10,7 +10,6 @@
///
///
///
-///
///
///
///