Skip to content

Commit e86cf84

Browse files
committed
feat(Progress): add hideStatusIcon flag
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
1 parent ce02202 commit e86cf84

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
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+
/** Hide the status icon, helpful when space is limited (such as within table cells) */
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ 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+
hideStatusIcon?: boolean;
6162
}
6263

6364
const variantToIcon = {
@@ -76,9 +77,10 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
7677
measureLocation = ProgressMeasureLocation.top,
7778
isTitleTruncated = false,
7879
tooltipPosition,
79-
helperText
80+
helperText,
81+
hideStatusIcon = false
8082
}: ProgressContainerProps) => {
81-
const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
83+
const StatusIcon = !hideStatusIcon && variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
8284
const [tooltip, setTooltip] = useState('');
8385
const titleRef = useRef(null);
8486
const updateTooltip = (event: any) => {
@@ -124,7 +126,7 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
124126
<span className={css(progressStyle.progressMeasure)}>{label || `${value}%`}</span>
125127
)}
126128
{StatusIcon && (
127-
<span className={css(progressStyle.progressStatusIcon)}>
129+
<span className={css(progressStyle.progressStatusIcon)} data-testid="progress-status-icon">
128130
<StatusIcon />
129131
</span>
130132
)}

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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,36 @@ 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+
// Should have status icon by default
117+
expect(screen.getByTestId('progress-status-icon')).toBeInTheDocument();
118+
});
119+
120+
test('hides status icon when hideStatusIcon flag is set with success variant', () => {
121+
render(<Progress id="hide-icon-success" value={100} variant="success" hideStatusIcon />);
122+
123+
expect(screen.queryByTestId('progress-status-icon')).not.toBeInTheDocument();
124+
});
125+
126+
test('hides status icon when hideStatusIcon flag is set with danger variant', () => {
127+
render(<Progress id="hide-icon-danger" value={50} variant="danger" hideStatusIcon />);
128+
129+
expect(screen.queryByTestId('progress-status-icon')).not.toBeInTheDocument();
130+
});
131+
132+
test('hides status icon when hideStatusIcon flag is set with warning variant', () => {
133+
render(<Progress id="hide-icon-warning" value={75} variant="warning" hideStatusIcon />);
134+
135+
expect(screen.queryByTestId('progress-status-icon')).not.toBeInTheDocument();
136+
});
137+
138+
test('shows status icon when hideStatusIcon is explicitly false', () => {
139+
render(<Progress id="show-icon-success" value={100} variant="success" hideStatusIcon={false} />);
140+
141+
expect(screen.getByTestId('progress-status-icon')).toBeInTheDocument();
142+
});
143+
});

0 commit comments

Comments
 (0)