| 1 |
import styles from '@patternfly/react-styles/css/components/FormControl/form-control'; |
| 2 |
import { css } from '@patternfly/react-styles'; |
| 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 |
|
| 7 |
export const statusIcons = { |
| 8 |
success: RhUiCheckCircleFillIcon, |
| 9 |
error: RhUiErrorFillIcon, |
| 10 |
warning: RhUiWarningFillIcon |
| 11 |
}; |
| 12 |
|
| 13 |
export interface FormControlIconProps extends React.HTMLProps<HTMLDivElement> { |
| 14 |
/** Additional class names added to the text input icon wrapper. */ |
| 15 |
className?: string; |
| 16 |
/** A custom icon to render instead of a status icon. */ |
| 17 |
customIcon?: React.ReactNode; |
| 18 |
/** The status icon to render. */ |
| 19 |
status?: 'success' | 'error' | 'warning'; |
| 20 |
} |
| 21 |
|
| 22 |
export const FormControlIcon = ({ status, customIcon, className, ...props }: FormControlIconProps) => { |
| 23 |
const StatusIcon = status && statusIcons[status]; |
| 24 |
|
| 25 |
return ( |
| 26 |
<span className={css(styles.formControlIcon, status && styles.modifiers.status, className)} {...props}> |
| 27 |
{customIcon || <StatusIcon />} |
| 28 |
</span> |
| 29 |
); |
| 30 |
}; |