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

Convert EuiIcon to TypeScript #1355

Merged
merged 7 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `5.5.1`.
- Convert `EuiIcon` to TypeScript ([#1355](https://github.com/elastic/eui/pull/1355))

## [`5.5.1`](https://github.com/elastic/eui/tree/v5.5.1)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint-es-fix": "eslint --fix --cache --ignore-pattern \"**/*.snap.js\" \"src/**/*.js\" \"src-docs/**/*.js\"",
"lint-sass": "sass-lint -v --max-warnings 0",
"lint-sass-fix": "sass-lint-auto-fix -c ./.sass-lint-fix.yml",
"lint-ts": "tslint -c ./tslint.yaml -p ./tsconfig.json && tsc -p ./tsconfig.json --noEmit",
"lint-ts": "tsc -p ./tsconfig.json --noEmit && tslint -c ./tslint.yaml -p ./tsconfig.json",
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
"lint-ts-fix": "tslint -c ./tslint.yaml -p ./tsconfig.json --fix",
"lint-framer": "tslint -c ./tslint.yaml -p ./src-framer/tsconfig.json",
"lint-framer-fix": "tslint -c ./tslint.yaml -p ./src-framer/tsconfig.json --fix",
Expand Down
2 changes: 1 addition & 1 deletion src/components/badge/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../icon/index.d.ts" />
import { IconType } from '../icon'
/// <reference path="../tool_tip/index.d.ts" />

import { HTMLAttributes, MouseEventHandler, SFC, ReactNode } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/button/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonProps } from '../common';
/// <reference path="../icon/index.d.ts" />
import { IconType } from '../icon'

import { SFC, ButtonHTMLAttributes, AnchorHTMLAttributes, MouseEventHandler, HTMLAttributes } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion src/components/call_out/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonProps, Omit } from '../common';
/// <reference path="../icon/index.d.ts" />
import { IconType } from '../icon'

import { SFC, ReactNode, HTMLAttributes } from 'react';

Expand Down
4 changes: 4 additions & 0 deletions src/components/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export type RefCallback<Element extends HTMLElement> = (
// utility types:

export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;

export function keysOf<T, K extends keyof T>(obj: T): K[] {
return Object.keys(obj) as K[];
}
2 changes: 1 addition & 1 deletion src/components/empty_prompt/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonProps, Omit } from '../common';
/// <reference path="../icon/index.d.ts" />
import { IconColor, IconType } from '../icon'
/// <reference path="../title/index.d.ts" />

import { SFC, ReactNode, HTMLAttributes } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/field_number/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonProps } from '../../common';
/// <reference path="../../icon/index.d.ts" />
import { IconType } from '../../icon'

import { ReactNode, SFC, InputHTMLAttributes } from 'react';

Expand Down
2 changes: 1 addition & 1 deletion src/components/health/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../icon/index.d.ts" />
import { IconColor } from '../icon'

import { SFC, HTMLAttributes } from 'react';
import { CommonProps } from '../common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ exports[`EuiIcon is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size l is rendered 1`] = `
exports[`EuiIcon props other props are passed through to the icon 1`] = `
<svg
class="euiIcon euiIcon--large"
aria-label="a custom title"
class="euiIcon euiIcon--medium"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -46,9 +47,9 @@ exports[`EuiIcon props size l is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size m is rendered 1`] = `
exports[`EuiIcon props size l is rendered 1`] = `
<svg
class="euiIcon euiIcon--medium"
class="euiIcon euiIcon--large"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -68,9 +69,9 @@ exports[`EuiIcon props size m is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size original is rendered 1`] = `
exports[`EuiIcon props size m is rendered 1`] = `
<svg
class="euiIcon"
class="euiIcon euiIcon--medium"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -90,9 +91,9 @@ exports[`EuiIcon props size original is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size s is rendered 1`] = `
exports[`EuiIcon props size original is rendered 1`] = `
<svg
class="euiIcon euiIcon--small"
class="euiIcon"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -112,9 +113,9 @@ exports[`EuiIcon props size s is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size xl is rendered 1`] = `
exports[`EuiIcon props size s is rendered 1`] = `
<svg
class="euiIcon euiIcon--xLarge"
class="euiIcon euiIcon--small"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -134,9 +135,9 @@ exports[`EuiIcon props size xl is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props size xxl is rendered 1`] = `
exports[`EuiIcon props size xl is rendered 1`] = `
<svg
class="euiIcon euiIcon--xxLarge"
class="euiIcon euiIcon--xLarge"
focusable="false"
height="16"
viewBox="0 0 16 16"
Expand All @@ -156,12 +157,11 @@ exports[`EuiIcon props size xxl is rendered 1`] = `
</svg>
`;

exports[`EuiIcon props tabIndex renders focusable="false" when -1 1`] = `
exports[`EuiIcon props size xxl is rendered 1`] = `
<svg
class="euiIcon euiIcon--medium"
class="euiIcon euiIcon--xxLarge"
focusable="false"
height="16"
tabindex="-1"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
Expand All @@ -179,11 +179,12 @@ exports[`EuiIcon props tabIndex renders focusable="false" when -1 1`] = `
</svg>
`;

exports[`EuiIcon props tabIndex renders focusable="false" when not provided 1`] = `
exports[`EuiIcon props tabIndex renders focusable="false" when -1 1`] = `
<svg
class="euiIcon euiIcon--medium"
focusable="false"
height="16"
tabindex="-1"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
Expand All @@ -201,12 +202,11 @@ exports[`EuiIcon props tabIndex renders focusable="false" when not provided 1`]
</svg>
`;

exports[`EuiIcon props tabIndex renders focusable="true" when 0 1`] = `
exports[`EuiIcon props tabIndex renders focusable="false" when not provided 1`] = `
<svg
class="euiIcon euiIcon--medium"
focusable="true"
focusable="false"
height="16"
tabindex="0"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
Expand All @@ -224,38 +224,12 @@ exports[`EuiIcon props tabIndex renders focusable="true" when 0 1`] = `
</svg>
`;

exports[`EuiIcon props title defaults to a humanized version of the type 1`] = `
<svg
class="euiIcon euiIcon--medium euiIcon--app"
focusable="false"
height="32"
viewBox="0 0 32 32"
width="32"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M29 9H3a3 3 0 0 1-3-3V3a3 3 0 0 1 3-3h26a3 3 0 0 1 3 3v3a3 3 0 0 1-3 3zM3 2a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h26a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1H3z"
/>
<path
class="euiIcon__fillSecondary"
d="M12 20H3a3 3 0 0 1-3-3v-3a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v3a3 3 0 0 1-3 3zm-9-7a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1H3z"
/>
<path
d="M12 31H3a3 3 0 0 1-3-3v-3a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v3a3 3 0 0 1-3 3zm-9-7a1 1 0 0 0-1 1v3a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1H3z"
/>
<path
class="euiIcon__fillSecondary"
d="M29 31h-9a3 3 0 0 1-3-3V14a3 3 0 0 1 3-3h9a3 3 0 0 1 3 3v14a3 3 0 0 1-3 3zm-9-18a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h9a1 1 0 0 0 1-1V14a1 1 0 0 0-1-1h-9z"
/>
</svg>
`;

exports[`EuiIcon props title is rendered 1`] = `
exports[`EuiIcon props tabIndex renders focusable="true" when 0 1`] = `
<svg
class="euiIcon euiIcon--medium"
focusable="false"
focusable="true"
height="16"
title="a custom title"
tabindex="0"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ describe('EuiIcon', () => {
});

describe('props', () => {
describe('title', () => {
test('defaults to a humanized version of the type', () => {
describe('other props', () => {
test('are passed through to the icon', () => {
const component = render(
<EuiIcon type="dashboardApp" />
);

expect(component).toMatchSnapshot();
});

test('is rendered', () => {
const component = render(
<EuiIcon type="search" title="a custom title" />
<EuiIcon type="search" aria-label="a custom title" />
);

expect(component).toMatchSnapshot();
Expand Down Expand Up @@ -67,12 +59,12 @@ describe('EuiIcon', () => {
});

test('renders focusable="false" when -1', () => {
const component = render(<EuiIcon type="search" tabIndex="-1" />);
const component = render(<EuiIcon type="search" tabIndex={-1} />);
expect(component).toMatchSnapshot();
});

test('renders focusable="true" when 0', () => {
const component = render(<EuiIcon type="search" tabIndex="0" />);
const component = render(<EuiIcon type="search" tabIndex={0} />);
expect(component).toMatchSnapshot();
});
});
Expand Down
Loading