Skip to content

Commit

Permalink
Migrate EuiFacetGroup, EuiKeyPadMenu and EuiCallOut to TS (elas…
Browse files Browse the repository at this point in the history
…tic#2382)

Migrate EuiFacetGroup, EuiKeyPadMenu and EuiCallOut to TypeScript.
  • Loading branch information
pugnascotia authored and snide committed Oct 10, 2019
1 parent cf5dadb commit e93627e
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 201 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Set `textOnly={true}` for expanded rows in `EuiBasicTable` ([#2376](https://github.com/elastic/eui/pull/2376))
- Added `visAreaStacked`, `visBarVerticalStacked`, and `visBarHorizontalStacked` icons to glyph set ([#2379](https://github.com/elastic/eui/pull/2379))
- Adjusted style of beta badge on `EuiKeyPadMenuItem` ([#2375](https://github.com/elastic/eui/pull/2375))
- Migrate `EuiFacetGroup`, `EuiKeyPadMenu` and `EuiCallOut` to TS ([#2382](https://github.com/elastic/eui/pull/2382))

**Bug fixes**

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent, HTMLAttributes, ReactNode } from 'react';

import classNames from 'classnames';

import { IconPropType, EuiIcon } from '../icon';
import { CommonProps, Omit, keysOf } from '../common';
import { IconType, EuiIcon } from '../icon';

import { EuiText } from '../text';

const colorToClassNameMap = {
type Color = 'primary' | 'success' | 'warning' | 'danger';
type Size = 's' | 'm';

export type EuiCallOutProps = CommonProps &
Omit<HTMLAttributes<HTMLDivElement>, 'title'> & {
title?: ReactNode;
iconType?: IconType;
color?: Color;
size?: Size;
};

const colorToClassNameMap: { [color in Color]: string } = {
primary: 'euiCallOut--primary',
success: 'euiCallOut--success',
warning: 'euiCallOut--warning',
danger: 'euiCallOut--danger',
};

export const COLORS = Object.keys(colorToClassNameMap);
export const COLORS = keysOf(colorToClassNameMap);

const sizeToClassNameMap = {
const sizeToClassNameMap: { [size in Size]: string } = {
s: 'euiCallOut--small',
m: '',
};

export const SIZES = Object.keys(sizeToClassNameMap);

export const EuiCallOut = ({
export const EuiCallOut: FunctionComponent<EuiCallOutProps> = ({
title,
color,
size,
color = 'primary',
size = 'm',
iconType,
children,
className,
Expand Down Expand Up @@ -71,17 +80,3 @@ export const EuiCallOut = ({
</div>
);
};

EuiCallOut.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
title: PropTypes.node,
iconType: IconPropType,
color: PropTypes.oneOf(COLORS),
size: PropTypes.oneOf(SIZES),
};

EuiCallOut.defaultProps = {
color: 'primary',
size: 'm',
};
28 changes: 0 additions & 28 deletions src/components/call_out/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/components/call_out/index.js

This file was deleted.

1 change: 1 addition & 0 deletions src/components/call_out/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EuiCallOut, EuiCallOutProps } from './call_out';
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { CommonProps } from '../common';
import { EuiFlexGroup } from '../flex';

const layoutToClassNameMap = {
type FacetGroupLayout = 'vertical' | 'horizontal';

const layoutToClassNameMap: { [layout in FacetGroupLayout]: string } = {
vertical: 'euiFacetGroup--vertical',
horizontal: 'euiFacetGroup--horizontal',
};

export const LAYOUTS = Object.keys(layoutToClassNameMap);
export type EuiFacetGroupProps = CommonProps &
HTMLAttributes<HTMLDivElement> & {
layout?: FacetGroupLayout;
};

export const EuiFacetGroup = ({ children, className, layout, ...rest }) => {
export const EuiFacetGroup: FunctionComponent<EuiFacetGroupProps> = ({
children,
className,
layout = 'vertical',
...rest
}) => {
const classes = classNames(
'euiFacetGroup',
layoutToClassNameMap[layout],
Expand All @@ -30,13 +41,3 @@ export const EuiFacetGroup = ({ children, className, layout, ...rest }) => {
</EuiFlexGroup>
);
};

EuiFacetGroup.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
layout: PropTypes.oneOf(LAYOUTS),
};

EuiFacetGroup.defaultProps = {
layout: 'vertical',
};
34 changes: 0 additions & 34 deletions src/components/facet/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/facet/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions src/components/facet/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { EuiFacetButton, EuiFacetButtonProps } from './facet_button';

export { EuiFacetGroup, EuiFacetGroupProps } from './facet_group';
3 changes: 0 additions & 3 deletions src/components/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/// <reference path="./call_out/index.d.ts" />
/// <reference path="./code/index.d.ts" />
/// <reference path="./card/index.d.ts" />
/// <reference path="./combo_box/index.d.ts" />
/// <reference path="./date_picker/index.d.ts" />
/// <reference path="./empty_prompt/index.d.ts" />
/// <reference path="./error_boundary/index.d.ts" />
/// <reference path="./facet/index.d.ts" />
/// <reference path="./filter_group/index.d.ts" />
/// <reference path="./flyout/index.d.ts" />
/// <reference path="./form/index.d.ts" />
/// <reference path="./header/index.d.ts" />
/// <reference path="./key_pad_menu/index.d.ts" />
/// <reference path="./link/index.d.ts" />
/// <reference path="./modal/index.d.ts" />
/// <reference path="./page/index.d.ts" />
Expand Down
35 changes: 0 additions & 35 deletions src/components/key_pad_menu/index.d.ts

This file was deleted.

File renamed without changes.
18 changes: 0 additions & 18 deletions src/components/key_pad_menu/key_pad_menu.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/components/key_pad_menu/key_pad_menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { FunctionComponent, HTMLAttributes } from 'react';
import classNames from 'classnames';

import { CommonProps } from '../common';

export type EuiKeyPadMenuProps = CommonProps & HTMLAttributes<HTMLDivElement>;

export const EuiKeyPadMenu: FunctionComponent<EuiKeyPadMenuProps> = ({
children,
className,
...rest
}) => {
const classes = classNames('euiKeyPadMenu', className);

return (
<div className={classes} role="menu" {...rest}>
{children}
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { render, shallow } from 'enzyme';
import sinon from 'sinon';
import { requiredProps } from '../../test/required_props';
import { requiredProps } from '../../test';

import {
EuiKeyPadMenuItem,
Expand Down Expand Up @@ -43,19 +42,19 @@ describe('EuiKeyPadMenuItemButton', () => {

describe('onClick', () => {
test("isn't called upon instantiation", () => {
const onClickHandler = sinon.stub();
const onClickHandler = jest.fn();

shallow(
<EuiKeyPadMenuItemButton label="Label" onClick={onClickHandler}>
Icon
</EuiKeyPadMenuItemButton>
);

sinon.assert.notCalled(onClickHandler);
expect(onClickHandler).not.toBeCalled();
});

test('is called when the button is clicked', () => {
const onClickHandler = sinon.stub();
const onClickHandler = jest.fn();

const $button = shallow(
<EuiKeyPadMenuItemButton label="Label" onClick={onClickHandler}>
Expand All @@ -65,7 +64,7 @@ describe('EuiKeyPadMenuItemButton', () => {

$button.simulate('click');

sinon.assert.calledOnce(onClickHandler);
expect(onClickHandler).toBeCalledTimes(1);
});
});
});
Loading

0 comments on commit e93627e

Please sign in to comment.