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 EuiFlex* and EuiDescriptionList* to typescript #1365

Merged
merged 13 commits into from
Mar 4, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added support to `findTestSubject` for an optional `matcher` argument, which defaults to `~=`, enabling it to identify an element based on one of multiple space-separated values within its `data-test-subj` attribute ([#1587](https://github.com/elastic/eui/pull/1587))
- Converted `EuiFlexGrid`, `EuiFlexGroup`, `EuiFlexItem`, `EuiDescriptionList`, `EuiDescriptionListTitle`, and `EuiDescriptionListDescription` to TypeScript ([#1365](https://github.com/elastic/eui/pull/1365))

## [`9.0.1`](https://github.com/elastic/eui/tree/v9.0.1)

Expand Down
12 changes: 11 additions & 1 deletion scripts/babel/proptypes-from-ts-props/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ function getPropTypesForNode(node, optional, state) {

const reducedUnionTypes = tsUnionTypes.reduce(
(foundTypes, tsUnionType) => {
if (types.isLiteral(tsUnionType)) {
if (types.isLiteral(tsUnionType) || (types.isIdentifier(tsUnionType) && tsUnionType.name === 'undefined')) {
if (foundTypes.oneOfPropType == null) {
foundTypes.oneOfPropType = types.arrayExpression([]);
foundTypes.unionTypes.push(
Expand Down Expand Up @@ -691,6 +691,16 @@ function getPropTypesForNode(node, optional, state) {
optional = true; // cannot call `.isRequired` on a boolean literal
break;

case 'TSNullKeyword':
propType = types.nullLiteral();
optional = true; // cannot call `.isRequired` on a null literal
break;

case 'TSUndefinedKeyword':
propType = types.identifier('undefined');
optional = true; // cannot call `.isRequired` on an undefined literal
break;

// very helpful debugging code
// default:
// debugger;
Expand Down
23 changes: 23 additions & 0 deletions scripts/babel/proptypes-from-ts-props/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,29 @@ FooComponent.propTypes = {
};`);
});

it('treats null and undefined as literals', () => {
const result = transform(
`
import React from 'react';
interface IFooProps {bar: 'five' | null | undefined}
const FooComponent: React.SFC<IFooProps> = () => {
return (<div>Hello World</div>);
}`,
babelOptions
);

expect(result.code).toBe(`import React from 'react';
import PropTypes from "prop-types";

const FooComponent = () => {
return <div>Hello World</div>;
};

FooComponent.propTypes = {
bar: PropTypes.oneOf(["five", null, undefined]).isRequired
};`);
});

});

describe('array / arrayOf propTypes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import {
EuiCode,
EuiDescriptionList,
EuiDescriptionListTitle,
EuiDescriptionListDescription,
} from '../../../../src/components';

import DescriptionList from './description_list';
Expand Down Expand Up @@ -54,7 +56,7 @@ export const DescriptionListExample = {
components separately to build a list manually.
</p>
),
props: { EuiDescriptionList },
props: { EuiDescriptionList, EuiDescriptionListTitle, EuiDescriptionListDescription },
demo: <DescriptionList />,
}, {
title: 'Reverse style',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<button onClick={() => { window.alert('click'); }}>
<button
onClick={() => {
window.alert('click');
}}>
<EuiFlexGroup component="span">
<EuiFlexItem component="span">
These items are within a button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<EuiFlexGroup direction="column">
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/flex/flex_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const FlexExample = {
</p>
</div>
),
props: { EuiFlexGroup, EuiFlexItem },
props: { EuiFlexGroup, EuiFlexItem, EuiFlexGrid },
chandlerprall marked this conversation as resolved.
Show resolved Hide resolved
demo: <div className="guideDemo__highlightGrid"><FlexGroup /></div>,
}, {
title: 'FlexGroup can wrap its items',
Expand Down
22 changes: 0 additions & 22 deletions src-docs/src/views/flex/flex_grid.js

This file was deleted.

33 changes: 33 additions & 0 deletions src-docs/src/views/flex/flex_grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';

import { EuiFlexGrid, EuiFlexItem } from '../../../../src/components/flex';

const ITEM_STYLE = { width: '300px' };

export default () => (
<div>
<EuiFlexGrid>
<EuiFlexItem style={ITEM_STYLE}>
<div>One</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Two</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Three</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Four</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Five</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Six</div>
</EuiFlexItem>
<EuiFlexItem style={ITEM_STYLE}>
<div>Seven</div>
</EuiFlexItem>
</EuiFlexGrid>
</div>
);
20 changes: 0 additions & 20 deletions src-docs/src/views/flex/flex_grid_columns.js

This file was deleted.

31 changes: 31 additions & 0 deletions src-docs/src/views/flex/flex_grid_columns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

import { EuiFlexGrid, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<div>
<EuiFlexGrid columns={3}>
<EuiFlexItem>
<div>One</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Two</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Three</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Four</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Five</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Six</div>
</EuiFlexItem>
<EuiFlexItem>
<div>Seven</div>
</EuiFlexItem>
</EuiFlexGrid>
</div>
);
18 changes: 0 additions & 18 deletions src-docs/src/views/flex/flex_group.js

This file was deleted.

18 changes: 18 additions & 0 deletions src-docs/src/views/flex/flex_group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';
import { EuiSpacer } from '../../../../src/components/spacer';

export default () => (
<EuiFlexGroup>
<EuiFlexItem>Content grid item</EuiFlexItem>
<EuiFlexItem>
<p>Another content grid item</p>
<EuiSpacer />
<p>
Note how both of these are the same width and height despite having
different content?
</p>
</EuiFlexItem>
</EuiFlexGroup>
);
22 changes: 0 additions & 22 deletions src-docs/src/views/flex/flex_group_wrap.js

This file was deleted.

13 changes: 13 additions & 0 deletions src-docs/src/views/flex/flex_group_wrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';

import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<EuiFlexGroup wrap>
<EuiFlexItem style={{ minWidth: 300 }}>Min-width 300px</EuiFlexItem>

<EuiFlexItem style={{ minWidth: 300 }}>Min-width 300px</EuiFlexItem>

<EuiFlexItem style={{ minWidth: 300 }}>Min-width 300px</EuiFlexItem>
</EuiFlexGroup>
);
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';
import { EuiSpacer } from '../../../../src/components/spacer';

export default () => (
<div>
<EuiFlexGroup>
<EuiFlexItem grow={1}>1</EuiFlexItem>
<EuiFlexItem grow={2}>2<br />wraps content if necessary</EuiFlexItem>
<EuiFlexItem grow={3}>3<br />expands_to_fit_if_content_cannot_wrap</EuiFlexItem>
<EuiFlexItem grow={2}>
2<br />
wraps content if necessary
</EuiFlexItem>
<EuiFlexItem grow={3}>
3<br />
expands_to_fit_if_content_cannot_wrap
</EuiFlexItem>
<EuiFlexItem grow={4}>4</EuiFlexItem>
</EuiFlexGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';
import { EuiSpacer } from '../../../../src/components/spacer';

export default () => (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
} from '../../../../src/components';
import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex';

export default () => (
<EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react';

import {
EuiFlexGrid,
EuiFlexGroup,
EuiFlexItem,
EuiFlexGrid,
EuiSpacer,
} from '../../../../src/components';
} from '../../../../src/components/flex';
import { EuiSpacer } from '../../../../src/components/spacer';

export default () => (
<div>
Expand Down
Loading