Skip to content

Commit 7ad9398

Browse files
feat(Progress): added helper text (#8307)
* feat(Progress): added helper text * enabled custom components to be passed as children of ProgressHelperText * spread props in ProgressHelperText * improved prop description * removed default isLiveRegion * marked helper text prop as beta * marked example as beta * added custom component example * refactored to make ProgressHelperText a basic wrapper component * added locally defined capitalize function
1 parent 7db1300 commit 7ad9398

File tree

11 files changed

+159
-2
lines changed

11 files changed

+159
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { HelperTextProps } from '../';
3+
4+
export const HelperText = ({ children, isLiveRegion }: HelperTextProps) => (
5+
<>
6+
<div data-testid="helper-text-children-container">{children}</div>
7+
<p>{`isLiveRegion: ${isLiveRegion}`}</p>
8+
</>
9+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { HelperTextItemProps } from '../';
3+
4+
export const HelperTextItem = ({ children, variant }: HelperTextItemProps) => (
5+
<>
6+
<div data-testid="helper-text-item-children-container">{children}</div>
7+
<p>{`variant: ${variant}`}</p>
8+
</>
9+
);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './HelperText';
2+
export * from './HelperTextItem';

packages/react-core/src/components/Progress/Progress.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export interface ProgressProps extends Omit<React.HTMLProps<HTMLDivElement>, 'si
4242
'aria-label'?: string;
4343
/** Associates the ProgressBar with it's label for accessibility purposes. Required when title not used */
4444
'aria-labelledby'?: string;
45+
/** @beta Content which can be used to convey additional information about the progress component.
46+
* We recommend the helper text component as it was designed for this purpose.
47+
*/
48+
helperText?: React.ReactNode;
4549
}
4650

4751
export class Progress extends React.Component<ProgressProps> {
@@ -85,6 +89,7 @@ export class Progress extends React.Component<ProgressProps> {
8589
tooltipPosition,
8690
'aria-label': ariaLabel,
8791
'aria-labelledby': ariaLabelledBy,
92+
helperText,
8893
...props
8994
} = this.props;
9095

@@ -137,6 +142,7 @@ export class Progress extends React.Component<ProgressProps> {
137142
progressBarAriaProps={progressBarAriaProps}
138143
isTitleTruncated={isTitleTruncated}
139144
tooltipPosition={tooltipPosition}
145+
helperText={helperText}
140146
/>
141147
</div>
142148
);

packages/react-core/src/components/Progress/ProgressContainer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle
66
import TimesCircleIcon from '@patternfly/react-icons/dist/esm/icons/times-circle-icon';
77
import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon';
88
import { AriaProps, ProgressBar } from './ProgressBar';
9+
import { ProgressHelperText } from './ProgressHelperText';
910

1011
export enum ProgressMeasureLocation {
1112
outside = 'outside',
@@ -53,6 +54,10 @@ export interface ProgressContainerProps extends Omit<React.HTMLProps<HTMLDivElem
5354
| 'left-end'
5455
| 'right-start'
5556
| 'right-end';
57+
/** @beta Content which can be used to convey additional information about the progress component.
58+
* We recommend the helper text component as it was designed for this purpose.
59+
*/
60+
helperText?: React.ReactNode;
5661
}
5762

5863
const variantToIcon = {
@@ -70,7 +75,8 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
7075
variant = null,
7176
measureLocation = ProgressMeasureLocation.top,
7277
isTitleTruncated = false,
73-
tooltipPosition
78+
tooltipPosition,
79+
helperText
7480
}: ProgressContainerProps) => {
7581
const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
7682
const [tooltip, setTooltip] = React.useState('');
@@ -117,6 +123,7 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
117123
<ProgressBar role="progressbar" progressBarAriaProps={progressBarAriaProps} value={value}>
118124
{measureLocation === ProgressMeasureLocation.inside && `${value}%`}
119125
</ProgressBar>
126+
{helperText && <ProgressHelperText>{helperText}</ProgressHelperText>}
120127
</React.Fragment>
121128
);
122129
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as React from 'react';
2+
import progressStyle from '@patternfly/react-styles/css/components/Progress/progress';
3+
4+
export interface ProgressHelperTextProps extends React.HTMLProps<HTMLDivElement> {
5+
/** Content which can be used to convey additional information about the progress component.
6+
* We recommend the helper text component as it was designed for this purpose.
7+
*/
8+
children?: React.ReactNode;
9+
}
10+
11+
export const ProgressHelperText: React.FunctionComponent<ProgressHelperTextProps> = ({
12+
children,
13+
...props
14+
}: ProgressHelperTextProps) => (
15+
<div className={progressStyle.progressHelperText} {...props}>
16+
{children}
17+
</div>
18+
);
19+
20+
ProgressHelperText.displayName = 'ProgressHelperText';

packages/react-core/src/components/Progress/__tests__/Progress.test.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { render } from '@testing-library/react';
2+
import { render, screen } from '@testing-library/react';
33
import { Progress, ProgressSize } from '../Progress';
44
import { ProgressVariant, ProgressMeasureLocation } from '../ProgressContainer';
55

@@ -97,3 +97,15 @@ test('progress component generates console warning when no accessible name is pr
9797
render(<Progress value={33} />);
9898
expect(consoleWarnMock).toHaveBeenCalled();
9999
});
100+
101+
test('Does not render helper text by default', () => {
102+
render(<Progress/>);
103+
104+
expect(screen.queryByText('Test helper text')).not.toBeInTheDocument();
105+
})
106+
107+
test('Renders passed helper text', () => {
108+
render(<Progress helperText="Test helper text" />);
109+
110+
expect(screen.getByText('Test helper text')).toBeVisible();
111+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import { ProgressHelperText } from '../ProgressHelperText';
4+
5+
test('Renders without children', () => {
6+
render(
7+
<div data-testid="container">
8+
<ProgressHelperText />
9+
</div>
10+
);
11+
expect(screen.getByTestId('container').firstChild).toBeVisible();
12+
});
13+
14+
test('Renders children', () => {
15+
render(<ProgressHelperText>Test</ProgressHelperText>);
16+
17+
expect(screen.getByText('Test')).toBeVisible();
18+
});
19+
20+
test('Renders with class pf-c-progress__helper-text on the div containing the helper text component', () => {
21+
render(<ProgressHelperText>Test</ProgressHelperText>);
22+
23+
expect(screen.getByText('Test')).toHaveClass('pf-c-progress__helper-text');
24+
});
25+
26+
test('Renders with inherited element props spread to the component', () => {
27+
render(<ProgressHelperText aria-label="Test label">Test</ProgressHelperText>);
28+
29+
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
30+
});
31+
32+
test('Matches the snapshot', () => {
33+
const { asFragment } = render(<ProgressHelperText>test</ProgressHelperText>);
34+
expect(asFragment()).toMatchSnapshot();
35+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Matches the snapshot 1`] = `
4+
<DocumentFragment>
5+
<div
6+
class="pf-c-progress__helper-text"
7+
>
8+
test
9+
</div>
10+
</DocumentFragment>
11+
`;

packages/react-core/src/components/Progress/examples/Progress.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,7 @@ propComponents: ['Progress']
7474
### Title outside of progress bar
7575
```ts file="./ProgressTitleOutsideOfProgressBar.tsx"
7676
```
77+
78+
### Helper text
79+
```ts file="./ProgressHelperText.tsx" isBeta
80+
```

0 commit comments

Comments
 (0)