Skip to content

Commit

Permalink
EuiTitle Converted to TS (#1810)
Browse files Browse the repository at this point in the history
* `EuiTitle` Converted to TS

* `EuiTitle` exported `EuiTitleTextTransform`

* `EuiTitle` code review fix

* `EuiTitle` code review fix

* `EuiTitle` fixed exported idents and refactored `EuiTitleProps`

* `EuiTitle` fixed exported idents
  • Loading branch information
theodesp authored and chandlerprall committed Apr 11, 2019
1 parent 149d8c7 commit ce003eb
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `9.9.1`.
- Converted `EuiTitle` to TS ([#1810](https://github.com/elastic/eui/pull/1810))

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

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,
className
);

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

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

0 comments on commit ce003eb

Please sign in to comment.