Skip to content

Commit 7019b4a

Browse files
gitdallasrebeccaalpertthatblindgeye
authored
feat(Progress): add hideStatusIcon flag (#12038)
* feat(Progress): add hideStatusIcon flag Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> * avoid using test-id Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> * interactive example for measureLocation and hideStatusIcon Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> * Update packages/react-core/src/components/Progress/ProgressContainer.tsx Co-authored-by: Rebecca Alpert <ralpert@redhat.com> * Update packages/react-core/src/components/Progress/Progress.tsx Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> --------- Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com> Co-authored-by: Rebecca Alpert <ralpert@redhat.com> Co-authored-by: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com>
1 parent f986c4f commit 7019b4a

File tree

9 files changed

+99
-41
lines changed

9 files changed

+99
-41
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface ProgressProps extends Omit<React.HTMLProps<HTMLDivElement>, 'si
4848
* We recommend the helper text component as it was designed for this purpose.
4949
*/
5050
helperText?: React.ReactNode;
51+
/** Flag indicating whether the status icon should be hidden, helpful when space is limited (such as within table cells). When set to true, you must ensure the context of the status is provided in another way, such as via the progress measure. */
52+
hideStatusIcon?: boolean;
5153
}
5254

5355
class Progress extends Component<ProgressProps> {
@@ -94,6 +96,7 @@ class Progress extends Component<ProgressProps> {
9496
'aria-labelledby': ariaLabelledBy,
9597
'aria-describedby': ariaDescribedBy,
9698
helperText,
99+
hideStatusIcon,
97100
...props
98101
} = this.props;
99102

@@ -151,6 +154,7 @@ class Progress extends Component<ProgressProps> {
151154
isTitleTruncated={isTitleTruncated}
152155
tooltipPosition={tooltipPosition}
153156
helperText={helperText}
157+
hideStatusIcon={hideStatusIcon}
154158
/>
155159
</div>
156160
);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export interface ProgressContainerProps extends Omit<React.HTMLProps<HTMLDivElem
5858
* We recommend the helper text component as it was designed for this purpose.
5959
*/
6060
helperText?: React.ReactNode;
61+
/** Hide the status icon, helpful when space is limited (such as within table cells) */
62+
hideStatusIcon?: boolean;
6163
}
6264

6365
const variantToIcon = {
@@ -76,9 +78,10 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
7678
measureLocation = ProgressMeasureLocation.top,
7779
isTitleTruncated = false,
7880
tooltipPosition,
79-
helperText
81+
helperText,
82+
hideStatusIcon = false
8083
}: ProgressContainerProps) => {
81-
const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
84+
const StatusIcon = !hideStatusIcon && variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
8285
const [tooltip, setTooltip] = useState('');
8386
const titleRef = useRef(null);
8487
const updateTooltip = (event: any) => {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ it('ProgressContainer should match snapshot (auto-generated)', () => {
1515
variant={'danger'}
1616
measureLocation={'outside'}
1717
value={42}
18+
hideStatusIcon={false}
1819
/>
1920
);
2021
expect(asFragment()).toMatchSnapshot();

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,35 @@ test('Renders passed helper text', () => {
108108

109109
expect(screen.getByText('Test helper text')).toBeVisible();
110110
});
111+
112+
describe('hideStatusIcon prop behavior', () => {
113+
test('shows status icon by default when hideStatusIcon is not set', () => {
114+
render(<Progress id="default-status-icon-test" value={100} variant="success" />);
115+
116+
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
117+
});
118+
119+
test('hides status icon when hideStatusIcon flag is set with success variant', () => {
120+
render(<Progress id="hide-icon-success" value={100} variant="success" hideStatusIcon />);
121+
122+
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
123+
});
124+
125+
test('hides status icon when hideStatusIcon flag is set with danger variant', () => {
126+
render(<Progress id="hide-icon-danger" value={50} variant="danger" hideStatusIcon />);
127+
128+
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
129+
});
130+
131+
test('hides status icon when hideStatusIcon flag is set with warning variant', () => {
132+
render(<Progress id="hide-icon-warning" value={75} variant="warning" hideStatusIcon />);
133+
134+
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
135+
});
136+
137+
test('shows status icon when hideStatusIcon is explicitly false', () => {
138+
render(<Progress id="show-icon-success" value={100} variant="success" hideStatusIcon={false} />);
139+
140+
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
141+
});
142+
});

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,8 @@ When conveying status, you should ensure:
107107

108108
```
109109

110-
### Inside success
110+
### Interactive status icon and measure location
111111

112-
```ts file="./ProgressInsideSuccess.tsx"
113-
114-
```
115-
116-
### Outside failure
117-
118-
```ts file="./ProgressOutsideFailure.tsx"
119-
120-
```
121-
122-
### Failure without measure
123-
124-
```ts file="./ProgressFailureWithoutMeasure.tsx"
112+
```ts file="./ProgressInteractiveFailure.tsx"
125113

126114
```

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

Lines changed: 0 additions & 5 deletions
This file was deleted.

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

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { useState } from 'react';
2+
import {
3+
Progress,
4+
ProgressMeasureLocation,
5+
ProgressVariant,
6+
Radio,
7+
Checkbox,
8+
Form,
9+
FormGroup
10+
} from '@patternfly/react-core';
11+
12+
export const ProgressInteractiveFailure: React.FunctionComponent = () => {
13+
const [measureLocation, setMeasureLocation] = useState<ProgressMeasureLocation>(ProgressMeasureLocation.inside);
14+
const [hideStatusIcon, setHideStatusIcon] = useState<boolean>(false);
15+
16+
const measureLocationOptions = [
17+
{ value: ProgressMeasureLocation.inside, label: 'Inside' },
18+
{ value: ProgressMeasureLocation.outside, label: 'Outside' },
19+
{ value: ProgressMeasureLocation.top, label: 'Top' },
20+
{ value: ProgressMeasureLocation.none, label: 'None' }
21+
];
22+
23+
return (
24+
<Form>
25+
<FormGroup fieldId="measure-location" label="Measure location">
26+
{measureLocationOptions.map((option) => (
27+
<Radio
28+
key={option.value}
29+
id={`measure-location-${option.value}`}
30+
name="measure-location"
31+
label={option.label}
32+
value={option.value}
33+
isChecked={measureLocation === option.value}
34+
onChange={() => setMeasureLocation(option.value)}
35+
/>
36+
))}
37+
</FormGroup>
38+
<FormGroup fieldId="hide-status-icon">
39+
<Checkbox
40+
id="hide-status-icon"
41+
label="Hide status icon"
42+
isChecked={hideStatusIcon}
43+
onChange={(_, checked) => setHideStatusIcon(checked)}
44+
/>
45+
</FormGroup>
46+
<Progress
47+
value={33}
48+
title="Title"
49+
measureLocation={measureLocation}
50+
variant={ProgressVariant.danger}
51+
hideStatusIcon={hideStatusIcon}
52+
/>
53+
</Form>
54+
);
55+
};

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

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)