diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ace75f5b0..e2d565ed35c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/scripts/babel/proptypes-from-ts-props/index.js b/scripts/babel/proptypes-from-ts-props/index.js index 65c54fbbf9f..0bece040087 100644 --- a/scripts/babel/proptypes-from-ts-props/index.js +++ b/scripts/babel/proptypes-from-ts-props/index.js @@ -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( @@ -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; diff --git a/scripts/babel/proptypes-from-ts-props/index.test.js b/scripts/babel/proptypes-from-ts-props/index.test.js index acd0dd839f4..08958f2a429 100644 --- a/scripts/babel/proptypes-from-ts-props/index.test.js +++ b/scripts/babel/proptypes-from-ts-props/index.test.js @@ -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 = () => { + return (
Hello World
); +}`, + babelOptions + ); + + expect(result.code).toBe(`import React from 'react'; +import PropTypes from "prop-types"; + +const FooComponent = () => { + return
Hello World
; +}; + +FooComponent.propTypes = { + bar: PropTypes.oneOf(["five", null, undefined]).isRequired +};`); + }); + }); describe('array / arrayOf propTypes', () => { diff --git a/src-docs/src/views/description_list/description_list_example.js b/src-docs/src/views/description_list/description_list_example.js index a759f3b0343..cbaa0b50c7c 100644 --- a/src-docs/src/views/description_list/description_list_example.js +++ b/src-docs/src/views/description_list/description_list_example.js @@ -9,6 +9,8 @@ import { import { EuiCode, EuiDescriptionList, + EuiDescriptionListTitle, + EuiDescriptionListDescription, } from '../../../../src/components'; import DescriptionList from './description_list'; @@ -54,7 +56,7 @@ export const DescriptionListExample = { components separately to build a list manually.

), - props: { EuiDescriptionList }, + props: { EuiDescriptionList, EuiDescriptionListTitle, EuiDescriptionListDescription }, demo: , }, { title: 'Reverse style', diff --git a/src-docs/src/views/flex/component_span.js b/src-docs/src/views/flex/component_span.tsx similarity index 69% rename from src-docs/src/views/flex/component_span.js rename to src-docs/src/views/flex/component_span.tsx index cc7fb8b160d..ece04f096b8 100644 --- a/src-docs/src/views/flex/component_span.js +++ b/src-docs/src/views/flex/component_span.tsx @@ -1,12 +1,12 @@ import React from 'react'; -import { - EuiFlexGroup, - EuiFlexItem, -} from '../../../../src/components'; +import { EuiFlexGroup, EuiFlexItem } from '../../../../src/components/flex'; export default () => ( -