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

Allowed user to use any colour in EuiStat #3617

Merged
merged 6 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
- Added `side` prop to `EuiGlobalToastList` for choosing which window side to display toasts ([#3600](https://github.com/elastic/eui/pull/3600))
- Default `titleSize` get's implicitly set to 'm' for `EuiEmptyPrompt` ([#3598](https://github.com/elastic/eui/pull/3598))
- Updated `logoElastic` to meet brand guidelines ([#3613](https://github.com/elastic/eui/pull/3613))
- Allowed user to enter hexcode for colors in `EuiStat` ([#3617](https://github.com/elastic/eui/pull/3617))
- Extended `CommonProps` in `EuiColorPalettePickerPaletteTextProps`, `EuiColorPalettePickerPaletteFixedProps` and `EuiColorPalettePickerPaletteGradientProps` types ([#3616](https://github.com/elastic/eui/pull/3616))


**Bug fixes**

- Added `display` prop to `EuiDataGridColumnSortingDraggable` to pass` displayAsText` prop correctly to the column sorting popover.([#3574](https://github.com/elastic/eui/pull/3574))
Expand Down
31 changes: 28 additions & 3 deletions src/components/stat/__snapshots__/stat.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ exports[`EuiStat is rendered 1`] = `
</div>
`;



exports[`EuiStat props accent is rendered 1`] = `
<div
class="euiStat euiStat--leftAligned"
Expand Down Expand Up @@ -139,6 +137,34 @@ exports[`EuiStat props default is rendered 1`] = `
</div>
`;

exports[`EuiStat props hexcode colors are rendered 1`] = `
<div
class="euiStat euiStat--leftAligned"
>
<div
class="euiText euiText--small euiStat__description"
>
<p
aria-hidden="true"
>
description
</p>
</div>
<p
aria-hidden="true"
class="euiTitle euiTitle--large euiStat__title"
style="color:#EB1919"
>
title
</p>
<p
class="euiScreenReaderOnly"
>
description title
</p>
</div>
`;

exports[`EuiStat props l is rendered 1`] = `
<div
class="euiStat euiStat--leftAligned"
Expand Down Expand Up @@ -411,7 +437,6 @@ exports[`EuiStat props title and description are reversed 1`] = `
</div>
`;


exports[`EuiStat props xs is rendered 1`] = `
<div
class="euiStat euiStat--leftAligned"
Expand Down
8 changes: 8 additions & 0 deletions src/components/stat/stat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ describe('EuiStat', () => {
});
});

test('hexcode colors are rendered', () => {
const component = render(
<EuiStat title="title" description="description" titleColor="#EB1919" />
);

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

TITLE_SIZES.forEach(size => {
test(`${size} is rendered`, () => {
const component = render(
Expand Down
16 changes: 13 additions & 3 deletions src/components/stat/stat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const textAlignToClassNameMap = {
right: 'euiStat--rightAligned',
};

export const isColorClass = (input: string): input is keyof typeof colorToClassNameMap => {
return colorToClassNameMap.hasOwnProperty(input);
};

export const ALIGNMENTS = keysOf(textAlignToClassNameMap);

export interface EuiStatProps {
Expand All @@ -71,7 +75,7 @@ export interface EuiStatProps {
/**
* The color of the title text
*/
titleColor?: keyof typeof colorToClassNameMap;
titleColor?: keyof typeof colorToClassNameMap | string;
/**
* Size of the title. See EuiTitle for options ('s', 'm', 'l'... etc)
*/
Expand Down Expand Up @@ -100,7 +104,7 @@ export const EuiStat: FunctionComponent<

const titleClasses = classNames(
'euiStat__title',
colorToClassNameMap[titleColor],
isColorClass(titleColor) ? colorToClassNameMap[titleColor] : null,
{
'euiStat__title-isLoading': isLoading,
}
Expand All @@ -112,10 +116,16 @@ export const EuiStat: FunctionComponent<
</EuiText>
);

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

const screenReader = (
Expand Down