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

EuiTitle Converted to TS #1810

Merged
merged 7 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Converted `EuiTitle` to TS ([#1810](https://github.com/elastic/eui/pull/1810))
- Re-enabled installation of `@elastic/eui` via npm ([#1811](https://github.com/elastic/eui/pull/1811))

**Bug fixes**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`EuiQuickSelect is rendered 1`] = `
<EuiFlexItem>
<EuiTitle
size="xxxs"
textTransform="none"
>
<span>
Quick select
Expand Down Expand Up @@ -201,7 +200,6 @@ exports[`EuiQuickSelect prevQuickSelect 1`] = `
<EuiFlexItem>
<EuiTitle
size="xxxs"
textTransform="none"
>
<span>
Quick select
Expand Down
4 changes: 2 additions & 2 deletions src/components/empty_prompt/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommonProps, Omit } from '../common';
import { IconColor, IconType } from '../icon'
/// <reference path="../title/index.d.ts" />
import { IconColor, IconType } from '../icon';
import { EuiTitleSize } from '../title/title';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ exports[`EuiDescribedFormGroup is rendered 1`] = `
className="euiDescribedFormGroup__title"
id="generated-id-title"
size="xs"
textTransform="none"
>
<h3>
Title
Expand Down Expand Up @@ -65,7 +64,6 @@ exports[`EuiDescribedFormGroup props description is not rendered when it's not p
className="euiDescribedFormGroup__title"
id="generated-id-title"
size="xs"
textTransform="none"
>
<h3>
Title
Expand Down Expand Up @@ -105,7 +103,6 @@ exports[`EuiDescribedFormGroup props fullWidth is rendered 1`] = `
className="euiDescribedFormGroup__title"
id="generated-id-title"
size="xs"
textTransform="none"
>
<h3>
Title
Expand Down Expand Up @@ -154,7 +151,6 @@ exports[`EuiDescribedFormGroup props gutterSize is rendered 1`] = `
className="euiDescribedFormGroup__title"
id="generated-id-title"
size="xs"
textTransform="none"
>
<h3>
Title
Expand Down Expand Up @@ -203,7 +199,6 @@ exports[`EuiDescribedFormGroup props titleSize is rendered 1`] = `
className="euiDescribedFormGroup__title"
id="generated-id-title"
size="l"
textTransform="none"
>
<h3>
Title
Expand Down Expand Up @@ -273,7 +268,6 @@ exports[`EuiDescribedFormGroup ties together parts for accessibility 1`] = `
className="euiDescribedFormGroup__title"
id="test-id-title"
size="xs"
textTransform="none"
>
<h3
className="euiTitle euiTitle--xsmall euiDescribedFormGroup__title"
Expand Down
1 change: 0 additions & 1 deletion src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
/// <reference path="./table/index.d.ts" />
/// <reference path="./tabs/index.d.ts" />
/// <reference path="./text/index.d.ts" />
/// <reference path="./title/index.d.ts" />
/// <reference path="./toast/index.d.ts" />
/// <reference path="./tool_tip/index.d.ts" />

Expand Down
21 changes: 0 additions & 21 deletions src/components/title/index.d.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/title/index.js

This file was deleted.

1 change: 1 addition & 0 deletions src/components/title/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EuiTitle } from './title';
50 changes: 0 additions & 50 deletions src/components/title/title.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../test/required_props';
import { requiredProps } from '../../test';

import { EuiTitle } from './title';

Expand All @@ -12,7 +12,6 @@ describe('EuiTitle', () => {
</EuiTitle>
);

expect(component)
.toMatchSnapshot();
expect(component).toMatchSnapshot();
});
});
51 changes: 51 additions & 0 deletions src/components/title/title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { FunctionComponent, ReactElement } from 'react';
import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';

const titleSizeToClassNameMap = {
xxxs: 'euiTitle--xxxsmall',
xxs: 'euiTitle--xxsmall',
xs: 'euiTitle--xsmall',
s: 'euiTitle--small',
m: 'euiTitle--medium',
l: 'euiTitle--large',
};

export const TITLE_SIZES = keysOf(titleSizeToClassNameMap);
export type EuiTitleSize = keyof typeof titleSizeToClassNameMap;

const textTransformToClassNameMap = {
uppercase: 'euiTitle--uppercase',
};

export const TEXT_TRANSFORM = keysOf(textTransformToClassNameMap);
export type EuiTitleTextTransform = keyof typeof textTransformToClassNameMap;

export type EuiTitleProps = CommonProps & {
children: ReactElement<any>;
className?: string;
size?: EuiTitleSize;
textTransform?: EuiTitleTextTransform;
};

export const EuiTitle: FunctionComponent<EuiTitleProps> = ({
size = 'm',
children,
className,
textTransform,
...rest
}) => {
const classes = classNames(
'euiTitle',
titleSizeToClassNameMap[size],
textTransform ? textTransformToClassNameMap[textTransform] : undefined,
cchaos marked this conversation as resolved.
Show resolved Hide resolved
className
);

const props = {
className: classes,
...rest,
};

return React.cloneElement(children, props);
};