saagie-ui
Version:
Saagie UI from Saagie Design System
64 lines (57 loc) • 1.49 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { modifierCSS } from '../../../helpers';
import { Icon } from '../icon/Icon';
const propTypes = {
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
tag: PropTypes.elementType,
children: PropTypes.node.isRequired,
defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
className: PropTypes.string,
color: PropTypes.oneOf(['', 'warning', 'danger', 'success']),
};
const defaultProps = {
tag: 'div',
defaultClassName: 'sui-a-form-feedback',
className: '',
color: '',
};
export const FormFeedback = ({
tag: Tag,
defaultClassName,
children,
className,
color,
...attributes
}) => {
const classes = classnames(
defaultClassName,
modifierCSS(color),
className
);
const renderIconName = () => {
switch (color) {
case 'danger':
return 'fa-warning';
case 'warning':
return 'fa-warning';
case 'success':
return 'fa-check-circle';
default:
return 'fa-info-circle';
}
};
const { id } = attributes;
return (
<Tag {...attributes} data-testid={id} className={classes}>
<Icon name={renderIconName()} aria-label={`${renderIconName()} icon`} position="start" />
{children}
</Tag>
);
};
FormFeedback.propTypes = propTypes;
FormFeedback.defaultProps = defaultProps;