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

Add label and valueText props to EuiProgress #3661

Merged
merged 15 commits into from
Jul 6, 2020
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Added `gutterSize` prop to `EuiFacetGroup` ([#3639](https://github.com/elastic/eui/pull/3639))
- Updated props of `EuiCode` and `EuiCodeBlock` to reflect only functional props ([#3647](https://github.com/elastic/eui/pull/3647))
- Updated `EuiResizableContainer` `onPanelWidthChange` callback method to include all panel widths ([#3630](https://github.com/elastic/eui/pull/3630))
- Add `label`, `labelProps` and `valueText` props to `EuiProgress` ([#3661](https://github.com/elastic/eui/pull/3661))

**Bug fixes**

Expand Down
47 changes: 47 additions & 0 deletions src-docs/src/views/progress/progress_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { Fragment } from 'react';

import { EuiProgress, EuiSpacer } from '../../../../src/components';

const data = [
{ label: "Men's Clothing", value: '80' },
{ label: "Women's Clothing", value: '60' },
{ label: "Women's Shoes", value: '45' },
{ label: "Men's Shoes", value: '40' },
{ label: "Women's Accessories", value: '24' },
];

export default () => (
<Fragment>
<div style={{ maxWidth: 140 }}>
{data.map(item => (
<>
<EuiProgress
label={item.label}
valueText={true}
value={item.value}
max={100}
color="secondary"
size="s"
/>
<EuiSpacer size="s" />
</>
))}
</div>
<EuiSpacer size="m" />
<div style={{ maxWidth: 200 }}>
{data.map(item => (
<>
<EuiProgress
label={item.label}
valueText={true}
value={item.value}
max={100}
color="primary"
size="m"
/>
<EuiSpacer size="s" />
</>
))}
</div>
</Fragment>
);
49 changes: 49 additions & 0 deletions src-docs/src/views/progress/progress_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ const progressFixedSnippet = `<!-- Position at top of parent container -->
import ProgressSizeColor from './progress_size_color';
const progressSizeColorSource = require('!!raw-loader!./progress_size_color');
const progressSizeColorHtml = renderToHtml(ProgressSizeColor);
const progressSizeColorSnippet = `<EuiProgress
value={20}
max={100}
size="s"
color="accent"
/>`;

import ProgressChart from './progress_chart';
const progressChartSource = require('!!raw-loader!./progress_chart');
const progressChartHtml = renderToHtml(ProgressChart);
const progressChartSnippet = `<EuiProgress
value={20}
valueText={true}
label={label}
max={100}
/>`;

export const ProgressExample = {
title: 'Progress',
Expand Down Expand Up @@ -139,6 +155,39 @@ export const ProgressExample = {
</p>
),
demo: <ProgressSizeColor />,
snippet: progressSizeColorSnippet,
},
{
title: 'Progress for charts',
source: [
{
type: GuideSectionTypes.JS,
code: progressChartSource,
},
{
type: GuideSectionTypes.HTML,
code: progressChartHtml,
},
],
text: (
<div>
<p>
Determinate progress bar can be used as simple bar charts. Use them
with the <EuiCode>label</EuiCode> and <EuiCode>valueText</EuiCode>{' '}
props to show the data corresponding to each bar. The{' '}
<EuiCode>valueText</EuiCode> renders as the same color as the{' '}
<strong>EuiProgress</strong>.
</p>
<p>
Setting <EuiCode language="ts">{'valueText={true}'}</EuiCode> will
add a % sign next to the<EuiCode>value</EuiCode> passed. If you want
to display a custom <EuiCode>valueText</EuiCode>, you can pass a
node instead.
</p>
</div>
),
demo: <ProgressChart />,
snippet: progressChartSnippet,
},
],
};
73 changes: 73 additions & 0 deletions src/components/progress/__snapshots__/progress.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiProgress has labelProps 1`] = `
Array [
<div
class="euiProgress__data euiProgress__data--secondary"
>
<span
class="euiProgress__valueText"
>
150
</span>
</div>,
<progress
aria-hidden="false"
aria-label="aria-label"
class="euiProgress euiProgress--native euiProgress--m euiProgress--secondary testClass1 testClass2"
data-test-subj="test subject string"
max="100"
value="50"
/>,
]
`;

exports[`EuiProgress has max 1`] = `
<progress
aria-hidden="false"
aria-label="aria-label"
class="euiProgress euiProgress--native euiProgress--m euiProgress--secondary testClass1 testClass2"
data-test-subj="test subject string"
Expand All @@ -17,8 +40,36 @@ exports[`EuiProgress has value 1`] = `
/>
`;

exports[`EuiProgress has valueText and label 1`] = `
Array [
<div
class="euiProgress__data euiProgress__data--secondary"
>
<span
class="euiProgress__label"
>
Label
</span>
<span
class="euiProgress__valueText"
>
150
</span>
</div>,
<progress
aria-hidden="true"
aria-label="aria-label"
class="euiProgress euiProgress--native euiProgress--m euiProgress--secondary testClass1 testClass2"
data-test-subj="test subject string"
max="100"
value="50"
/>,
]
`;

exports[`EuiProgress is determinate 1`] = `
<progress
aria-hidden="false"
aria-label="aria-label"
class="euiProgress euiProgress--native euiProgress--m euiProgress--secondary testClass1 testClass2"
data-test-subj="test subject string"
Expand All @@ -42,3 +93,25 @@ exports[`EuiProgress is rendered 1`] = `
data-test-subj="test subject string"
/>
`;

exports[`EuiProgress valueText is true 1`] = `
Array [
<div
class="euiProgress__data euiProgress__data--secondary"
>
<span
class="euiProgress__valueText"
>
50%
</span>
</div>,
<progress
aria-hidden="false"
aria-label="aria-label"
class="euiProgress euiProgress--native euiProgress--m euiProgress--secondary testClass1 testClass2"
data-test-subj="test subject string"
max="100"
value="50"
/>,
]
`;
35 changes: 35 additions & 0 deletions src/components/progress/_progress.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ $euiProgressColors: (
}
}
}

.euiProgress__data--#{$name} {
.euiProgress__valueText {
color: $color;
}
}
}

@keyframes euiProgress {
Expand All @@ -128,3 +134,32 @@ $euiProgressColors: (
transform: scaleX(1) translateX(100%);
}
}

.euiProgress__data {
display: flex;
justify-content: space-between;

.euiProgress__label {
@include euiTextTruncate;
flex-basis: 80%;
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
}

.euiProgress__valueText {
@include euiTextTruncate;
margin-left: auto;
}
}

.euiProgress__label,
.euiProgress__valueText {
@include euiText;
@include euiFontSize;
@include fontSize($euiFontSizeXS);
}

.euiProgress__data--l {
.euiProgress__label,
.euiProgress__valueText {
@include fontSize($euiFontSizeS);
}
}
36 changes: 36 additions & 0 deletions src/components/progress/progress.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,40 @@ describe('EuiProgress', () => {

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

test('has valueText and label', () => {
andreadelrio marked this conversation as resolved.
Show resolved Hide resolved
const component = render(
<EuiProgress
valueText="150"
label="Label"
value={50}
max={100}
{...requiredProps}
/>
);

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

test('valueText is true', () => {
const component = render(
<EuiProgress valueText={true} value={50} max={100} {...requiredProps} />
);

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

test('has labelProps', () => {
const component = render(
<EuiProgress
max={100}
value={50}
labelProps={{ title: 'Custom title' }}
valueText="150"
{...requiredProps}
/>
);

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