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

fix(Shield): remove Unknown question mark icon #2154

Merged
merged 1 commit into from
Feb 7, 2025
Merged
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
5 changes: 2 additions & 3 deletions packages/components/doc/shield.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ Import Shield from this package.
import React from 'react';
import { Shield } from '@redhat-cloud-services/frontend-components';

class YourCmp extends React.Component {
render() {
const YourCmp = () => {
return (
<Shield impact={'Critical'} hasTooltip={true} size={'md'} />
)
}
}
```

Expand All @@ -32,6 +30,7 @@ You can also use all the props from Patternfly Tooltip component - [Documentatio
propTypes.number
]),
hasTooltip: propTypes.bool,
disableQuestionIcon: propTypes.bool
tooltipPosition: propTypes.string, // top, (right), bottom, left
tooltipPrefix: propTypes.string,
title: propTypes.string,
Expand Down
15 changes: 13 additions & 2 deletions packages/components/src/Shield/Shield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,29 @@ export interface ShieldProps {
impact: keyof typeof impactList | 'N/A';
hasLabel?: boolean;
hasTooltip?: boolean;
disableQuestionIcon?: boolean;
size?: IconComponentProps['size'];
}

const Shield: React.FunctionComponent<ShieldProps> = ({ impact = 'N/A', hasLabel = false, size = 'md', hasTooltip = true }) => {
const Shield: React.FunctionComponent<ShieldProps> = ({
impact = 'N/A',
hasLabel = false,
size = 'md',
hasTooltip = true,
disableQuestionIcon = false,
}) => {
const attributes = impactList?.[impact as keyof typeof impactList] ?? impactList.Unknown;
const badgeProps: SVGIconProps = {
'aria-hidden': 'false',
'aria-label': attributes.title,
color: attributes.color,
};

const badge = <Icon size={size}>{attributes.title === 'Unknown' ? <QuestionIcon {...badgeProps} /> : <SecurityIcon {...badgeProps} />}</Icon>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to add a prop to show an icon and which icon, since there might be places where we actually do want to show an icon.

The default behaviour should still remain the same.

const badge = (
<Icon size={size}>
{attributes.title === 'Unknown' ? disableQuestionIcon ? null : <QuestionIcon {...badgeProps} /> : <SecurityIcon {...badgeProps} />}
</Icon>
);

const body = (
<span>
Expand Down
Loading