saagie-ui
Version:
Saagie UI from Saagie Design System
83 lines (74 loc) • 1.71 kB
JavaScript
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Icon } from '../icon/Icon';
import { modifierCSS } from '../../../helpers';
const propTypes = {
children: PropTypes.node.isRequired,
className: PropTypes.string,
color: PropTypes.oneOf(['', 'primary', 'warning', 'danger', 'success', 'light']),
defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
iconName: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
tag: PropTypes.elementType,
};
const defaultProps = {
className: '',
color: '',
defaultClassName: 'sui-a-info-text',
iconName: '',
tag: 'div',
};
export const InfoText = ({
children,
className,
color,
defaultClassName,
iconName,
tag: Tag,
...attributes
}) => {
const classes = classnames(
className,
defaultClassName,
modifierCSS(color)
);
const renderIconName = () => {
switch (color) {
case 'primary':
return '';
case 'danger':
return 'fa-warning';
case 'warning':
return 'fa-warning';
case 'success':
return 'fa-check-circle';
default:
return '';
}
};
const ContentRender = () => {
if (iconName) {
return (
<Icon name={iconName} position="start" />
);
}
if (color) {
return (
<Icon name={renderIconName()} position="start" />
);
}
return '';
};
return (
<Tag {...attributes} className={classes}>
<ContentRender />
{children}
</Tag>
);
};
InfoText.propTypes = propTypes;
InfoText.defaultProps = defaultProps;