Skip to content
Open
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
4 changes: 4 additions & 0 deletions packages/react-core/src/components/Progress/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface ProgressProps extends Omit<React.HTMLProps<HTMLDivElement>, 'si
* We recommend the helper text component as it was designed for this purpose.
*/
helperText?: React.ReactNode;
/** 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. */
hideStatusIcon?: boolean;
}

class Progress extends Component<ProgressProps> {
Expand Down Expand Up @@ -94,6 +96,7 @@ class Progress extends Component<ProgressProps> {
'aria-labelledby': ariaLabelledBy,
'aria-describedby': ariaDescribedBy,
helperText,
hideStatusIcon,
...props
} = this.props;

Expand Down Expand Up @@ -151,6 +154,7 @@ class Progress extends Component<ProgressProps> {
isTitleTruncated={isTitleTruncated}
tooltipPosition={tooltipPosition}
helperText={helperText}
hideStatusIcon={hideStatusIcon}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export interface ProgressContainerProps extends Omit<React.HTMLProps<HTMLDivElem
* We recommend the helper text component as it was designed for this purpose.
*/
helperText?: React.ReactNode;
/** Hide the status icon, helpful when space is limited (such as within table cells) */
hideStatusIcon?: boolean;
}

const variantToIcon = {
Expand All @@ -76,9 +78,10 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
measureLocation = ProgressMeasureLocation.top,
isTitleTruncated = false,
tooltipPosition,
helperText
helperText,
hideStatusIcon = false
}: ProgressContainerProps) => {
const StatusIcon = variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
const StatusIcon = !hideStatusIcon && variantToIcon.hasOwnProperty(variant) && variantToIcon[variant];
const [tooltip, setTooltip] = useState('');
const titleRef = useRef(null);
const updateTooltip = (event: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ it('ProgressContainer should match snapshot (auto-generated)', () => {
variant={'danger'}
measureLocation={'outside'}
value={42}
hideStatusIcon={false}
/>
);
expect(asFragment()).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,35 @@ test('Renders passed helper text', () => {

expect(screen.getByText('Test helper text')).toBeVisible();
});

describe('hideStatusIcon prop behavior', () => {
test('shows status icon by default when hideStatusIcon is not set', () => {
render(<Progress id="default-status-icon-test" value={100} variant="success" />);

expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});

test('hides status icon when hideStatusIcon flag is set with success variant', () => {
render(<Progress id="hide-icon-success" value={100} variant="success" hideStatusIcon />);

expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});

test('hides status icon when hideStatusIcon flag is set with danger variant', () => {
render(<Progress id="hide-icon-danger" value={50} variant="danger" hideStatusIcon />);

expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});

test('hides status icon when hideStatusIcon flag is set with warning variant', () => {
render(<Progress id="hide-icon-warning" value={75} variant="warning" hideStatusIcon />);

expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
});

test('shows status icon when hideStatusIcon is explicitly false', () => {
render(<Progress id="show-icon-success" value={100} variant="success" hideStatusIcon={false} />);

expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
});
});
16 changes: 2 additions & 14 deletions packages/react-core/src/components/Progress/examples/Progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,8 @@ When conveying status, you should ensure:

```

### Inside success
### Interactive status icon and measure location

```ts file="./ProgressInsideSuccess.tsx"

```

### Outside failure

```ts file="./ProgressOutsideFailure.tsx"

```

### Failure without measure

```ts file="./ProgressFailureWithoutMeasure.tsx"
```ts file="./ProgressInteractiveFailure.tsx"

```

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { useState } from 'react';
import {
Progress,
ProgressMeasureLocation,
ProgressVariant,
Radio,
Checkbox,
Form,
FormGroup
} from '@patternfly/react-core';

export const ProgressInteractiveFailure: React.FunctionComponent = () => {
const [measureLocation, setMeasureLocation] = useState<ProgressMeasureLocation>(ProgressMeasureLocation.inside);
const [hideStatusIcon, setHideStatusIcon] = useState<boolean>(false);

const measureLocationOptions = [
{ value: ProgressMeasureLocation.inside, label: 'Inside' },
{ value: ProgressMeasureLocation.outside, label: 'Outside' },
{ value: ProgressMeasureLocation.top, label: 'Top' },
{ value: ProgressMeasureLocation.none, label: 'None' }
];

return (
<Form>
<FormGroup fieldId="measure-location" label="Measure location">
{measureLocationOptions.map((option) => (
<Radio
key={option.value}
id={`measure-location-${option.value}`}
name="measure-location"
label={option.label}
value={option.value}
isChecked={measureLocation === option.value}
onChange={() => setMeasureLocation(option.value)}
/>
))}
</FormGroup>
<FormGroup fieldId="hide-status-icon">
<Checkbox
id="hide-status-icon"
label="Hide status icon"
isChecked={hideStatusIcon}
onChange={(_, checked) => setHideStatusIcon(checked)}
/>
</FormGroup>
<Progress
value={33}
title="Title"
measureLocation={measureLocation}
variant={ProgressVariant.danger}
hideStatusIcon={hideStatusIcon}
/>
</Form>
);
};

This file was deleted.

Loading