| 1 |
import { css } from '@patternfly/react-styles'; |
| 2 |
import styles from '@patternfly/react-styles/css/components/Alert/alert'; |
| 3 |
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; |
| 4 |
import RhUiErrorFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-error-fill-icon'; |
| 5 |
import RhUiWarningFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-warning-fill-icon'; |
| 6 |
import RhUiInformationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-information-fill-icon'; |
| 7 |
import RhUiNotificationFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-notification-fill-icon'; |
| 8 |
|
| 9 |
export const variantIcons = { |
| 10 |
success: RhUiCheckCircleFillIcon, |
| 11 |
danger: RhUiErrorFillIcon, |
| 12 |
warning: RhUiWarningFillIcon, |
| 13 |
info: RhUiInformationFillIcon, |
| 14 |
custom: RhUiNotificationFillIcon |
| 15 |
}; |
| 16 |
|
| 17 |
export interface AlertIconProps extends React.HTMLProps<HTMLDivElement> { |
| 18 |
/** Additional class names added to the alert icon. */ |
| 19 |
className?: string; |
| 20 |
/** A custom icon. If not set the icon is set according to the variant. */ |
| 21 |
customIcon?: React.ReactNode; |
| 22 |
/** Variant of the alert icon. */ |
| 23 |
variant: 'success' | 'danger' | 'warning' | 'info' | 'custom'; |
| 24 |
} |
| 25 |
|
| 26 |
export const AlertIcon = ({ variant, customIcon, className = '', ...props }: AlertIconProps) => { |
| 27 |
const Icon = variantIcons[variant]; |
| 28 |
return Icon ? ( |
| 29 |
<div {...props} className={css(styles.alertIcon, className)}> |
| 30 |
{customIcon || <Icon />} |
| 31 |
</div> |
| 32 |
) : null; |
| 33 |
}; |