Skip to content

Commit

Permalink
WIP - Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pugnascotia committed Dec 8, 2018
1 parent d2337ce commit 0658cb4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
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[];
}
6 changes: 2 additions & 4 deletions src/components/icon/icon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { requiredProps } from '../../test/required_props';

import {
EuiIcon,
IconSize,
IconType,
SIZES,
TYPES,
} from './icon';
Expand All @@ -31,7 +29,7 @@ describe('EuiIcon', () => {
});

describe('size', () => {
(SIZES as IconSize[]).forEach(size => {
SIZES.forEach(size => {
test(`${size} is rendered`, () => {
const component = render(
<EuiIcon type="search" size={size} />
Expand All @@ -43,7 +41,7 @@ describe('EuiIcon', () => {
});

describe('type', () => {
(TYPES as IconType[]).forEach(type => {
TYPES.forEach(type => {
test(`${type} is rendered`, () => {
const component = render(
<EuiIcon type={type} />
Expand Down
10 changes: 5 additions & 5 deletions src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { SFC, SVGAttributes } from 'react';
import classNames from 'classnames';

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

import addDataApp from './assets/app_add_data.svg';
import advancedSettingsApp from './assets/app_advanced_settings.svg';
Expand Down Expand Up @@ -549,7 +549,7 @@ const typeToIconMap = {
tokenFile,
};

export const TYPES = Object.keys(typeToIconMap);
export const TYPES: IconType[] = keysOf(typeToIconMap);

export type IconType = keyof typeof typeToIconMap;

Expand All @@ -568,7 +568,7 @@ const colorToClassMap: ColorToClassMap = {
ghost: 'euiIcon--ghost',
};

export const COLORS = Object.keys(colorToClassMap);
export const COLORS: IconColor[] = keysOf(colorToClassMap);

// We accept arbitrary color strings, which are impossible to type.
export type IconColor = string | keyof typeof colorToClassMap;
Expand All @@ -582,7 +582,7 @@ const sizeToClassNameMap = {
xxl: 'euiIcon--xxLarge',
};

export const SIZES = Object.keys(sizeToClassNameMap);
export const SIZES: IconSize[] = keysOf(sizeToClassNameMap);

export type IconSize = keyof typeof sizeToClassNameMap;

Expand All @@ -592,7 +592,7 @@ export interface EuiIconProps {
size?: IconSize;
}

type Props = CommonProps & SVGAttributes<SVGAElement> & EuiIconProps;
type Props = CommonProps & SVGAttributes<SVGElement> & EuiIconProps;

export const EuiIcon: SFC<Props> = ({
type,
Expand Down

0 comments on commit 0658cb4

Please sign in to comment.