Skip to content

Commit

Permalink
Converted EuiFlex* docs to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
chandlerprall committed Dec 11, 2018
1 parent e6b12c5 commit d074292
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 56 deletions.
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 () => (
<button onClick={() => { window.alert('click'); }}>
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import React from 'react';

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

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

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

import {
EuiFlexGrid,
EuiFlexItem,
} from '../../../../src/components';
import { EuiFlexGrid, 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 () => (
<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 () => (
<EuiFlexGroup wrap>
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 () => (
<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,7 @@
import React from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
EuiFlexGrid,
EuiSpacer,
} from '../../../../src/components';
import { EuiFlexGrid, 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,11 +1,7 @@
import React from 'react';

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

export default () => (
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiDescriptionList is rendered 1`] = `
<dl
aria-label="aria-label"
class="euiDescriptionList euiDescriptionList--row testClass1 testClass2"
data-test-subj="test subject string"
>
Content
</dl>
`;

exports[`EuiDescriptionList props align center is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--row euiDescriptionList--center"
/>
`;

exports[`EuiDescriptionList props align left is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--row"
/>
`;

exports[`EuiDescriptionList props compressed is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--row euiDescriptionList--compressed"
/>
`;

exports[`EuiDescriptionList props listItems is rendered as strings and elements 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--row"
>
<dt
class="euiDescriptionList__title"
>
Title 1
</dt>
<dd
class="euiDescriptionList__description"
>
Description 1
</dd>
<dt
class="euiDescriptionList__title"
>
<em>
Title 2
</em>
</dt>
<dd
class="euiDescriptionList__description"
>
<code>
Description 2
</code>
</dd>
<dt
class="euiDescriptionList__title"
>
Title 3
</dt>
<dd
class="euiDescriptionList__description"
>
Description 3
</dd>
</dl>
`;

exports[`EuiDescriptionList props type column is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--column"
/>
`;

exports[`EuiDescriptionList props type inline is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--inline"
/>
`;

exports[`EuiDescriptionList props type row is rendered 1`] = `
<dl
class="euiDescriptionList euiDescriptionList--row"
/>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiDescriptionListDescription is rendered 1`] = `
<dd
aria-label="aria-label"
class="euiDescriptionList__description testClass1 testClass2"
data-test-subj="test subject string"
>
Content
</dd>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiDescriptionListTitle is rendered 1`] = `
<dt
aria-label="aria-label"
class="euiDescriptionList__title testClass1 testClass2"
data-test-subj="test subject string"
>
Content
</dt>
`;
16 changes: 16 additions & 0 deletions src/components/flex/flex_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const EuiFlexItem: SFC<
component: Component = 'div',
...rest
}) => {
validateGrowValue(grow);

const classes = classNames(
'euiFlexItem',
{
Expand All @@ -54,6 +56,20 @@ export const EuiFlexItem: SFC<
);
};

function validateGrowValue(value: EuiFlexItemProps['grow']) {
const validValues = [
null, undefined,
true, false,
...GROW_SIZES,
];

if (validValues.indexOf(value) === -1) {
throw new Error(
`Prop \`grow\` passed to \`EuiFlexItem\` must be a boolean or an integer between 1 and 10, received \`${value}\``
);
}
}

EuiFlexItem.defaultProps = {
grow: true,
component: 'div',
Expand Down

0 comments on commit d074292

Please sign in to comment.