Skip to content

Commit

Permalink
Revert "[EuiStat] Allow customizing the render of the title and descr…
Browse files Browse the repository at this point in the history
…iption HTML tags (elastic#3693)"

This reverts commit 14dda39.
  • Loading branch information
anishagg17 committed Jul 20, 2020
1 parent 1f2261c commit bc3a1fe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 105 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `titleElement` and `descriptionElement` props to `EuiStat` ([#3693](https://github.com/elastic/eui/pull/3693))
- Updated `securityAnalyticsApp` app icon ([#3720](https://github.com/elastic/eui/pull/3720))
- Removed `src/test` and `@types/enzyme` references from `eui.d.ts` ([#3715](https://github.com/elastic/eui/pull/3715))
- Added `index.d.ts` file to `lib/test` and `es/test` ([#3715](https://github.com/elastic/eui/pull/3715))
Expand Down
49 changes: 0 additions & 49 deletions src/components/stat/__snapshots__/stat.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -302,55 +302,6 @@ exports[`EuiStat props primary is rendered 1`] = `
</div>
`;

exports[`EuiStat props render with custom description element 1`] = `
<div
class="euiStat euiStat--leftAligned"
>
<div
class="euiText euiText--small euiStat__description"
>
<div
aria-hidden="true"
>
<div>
description
</div>
</div>
</div>
<p
aria-hidden="true"
class="euiTitle euiTitle--large euiStat__title"
style="color:#EB1919"
>
title
</p>
</div>
`;

exports[`EuiStat props render with custom title element 1`] = `
<div
class="euiStat euiStat--leftAligned"
>
<div
class="euiText euiText--small euiStat__description"
>
<p
aria-hidden="true"
>
description
</p>
</div>
<div
aria-hidden="true"
class="euiTitle euiTitle--large euiStat__title"
>
<div>
title
</div>
</div>
</div>
`;

exports[`EuiStat props right is rendered 1`] = `
<div
class="euiStat euiStat--rightAligned"
Expand Down
25 changes: 0 additions & 25 deletions src/components/stat/stat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,6 @@ describe('EuiStat', () => {
expect(component).toMatchSnapshot();
});

test('render with custom description element', () => {
const component = render(
<EuiStat
title="title"
description={<div>description</div>}
descriptionElement="div"
titleColor="#EB1919"
/>
);

expect(component).toMatchSnapshot();
});

test('render with custom title element', () => {
const component = render(
<EuiStat
title={<div>title</div>}
titleElement="div"
description="description"
/>
);

expect(component).toMatchSnapshot();
});

TITLE_SIZES.forEach(size => {
test(`${size} is rendered`, () => {
const component = render(
Expand Down
36 changes: 6 additions & 30 deletions src/components/stat/stat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import React, {
HTMLAttributes,
FunctionComponent,
ReactNode,
createElement,
} from 'react';
import { CommonProps, keysOf } from '../common';
import classNames from 'classnames';
Expand Down Expand Up @@ -83,14 +82,6 @@ export interface EuiStatProps {
* Size of the title. See EuiTitle for options ('s', 'm', 'l'... etc)
*/
titleSize?: EuiTitleSize;
/**
* HTML Element to be used for title
*/
titleElement?: string;
/**
* HTML Element to be used for description
*/
descriptionElement?: string;
}

export const EuiStat: FunctionComponent<
Expand All @@ -105,8 +96,6 @@ export const EuiStat: FunctionComponent<
title,
titleColor = 'default',
titleSize = 'l',
titleElement = 'p',
descriptionElement = 'p',
...rest
}) => {
const classes = classNames(
Expand All @@ -123,32 +112,21 @@ export const EuiStat: FunctionComponent<
}
);

const commonProps = {
'aria-hidden': true,
};

const descriptionDisplay = (
<EuiText size="s" className="euiStat__description">
{createElement(descriptionElement, commonProps, description)}
<p aria-hidden="true">{description}</p>
</EuiText>
);

const titlePropsWithColor = {
'aria-hidden': true,
style: {
color: `${titleColor}`,
},
};

const titleChildren = isLoading ? '--' : title;

const titleDisplay = isColorClass(titleColor) ? (
<EuiTitle size={titleSize} className={titleClasses}>
{createElement(titleElement, commonProps, titleChildren)}
<p aria-hidden="true">{isLoading ? '--' : title}</p>
</EuiTitle>
) : (
<EuiTitle size={titleSize} className={titleClasses}>
{createElement(titleElement, titlePropsWithColor, titleChildren)}
<p aria-hidden="true" style={{ color: `${titleColor}` }}>
{isLoading ? '--' : title}
</p>
</EuiTitle>
);

Expand All @@ -171,9 +149,7 @@ export const EuiStat: FunctionComponent<
{!reverse && descriptionDisplay}
{titleDisplay}
{reverse && descriptionDisplay}
{typeof title === 'string' &&
typeof description === 'string' &&
screenReader}
{screenReader}
</Fragment>
);

Expand Down

0 comments on commit bc3a1fe

Please sign in to comment.