saagie-ui
Version:
Saagie UI from Saagie Design System
96 lines (82 loc) • 2.02 kB
JavaScript
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Icon } from '../../atoms/icon/Icon';
import { modifierCSS } from '../../../helpers';
const propTypes = {
/**
* The CallOut content.
*/
children: PropTypes.node,
/**
* The className property allows you to add more classes to the component.
*/
className: PropTypes.string,
/**
* The component default class.
*/
defaultClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
/**
* The Callout icon name used to override the default one.
*/
iconName: PropTypes.string,
/**
* The CallOut status size.
*/
size: PropTypes.oneOf(['', 'sm']),
/**
* The CallOut variant.
*/
variant: PropTypes.oneOf(['ok', 'warning', 'danger']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
tag: PropTypes.elementType,
};
const defaultProps = {
children: '',
className: '',
defaultClassName: 'sui-m-call-out',
iconName: '',
size: '',
tag: 'div',
variant: 'ok',
};
const ICON_MAP_VARIANT = {
ok: 'fa-check',
warning: 'fa-exclamation-triangle',
danger: 'fa-exclamation-triangle',
};
export const CallOut = forwardRef(({
children,
className,
defaultClassName,
variant,
size,
iconName,
tag: Tag,
...props
}, ref) => {
const classes = classnames(
defaultClassName,
className,
);
const statusClasses = classnames(
'sui-m-call-out__status',
modifierCSS(variant),
size ? `as--${size}` : '',
);
return (
<Tag className={classes} {...props} ref={ref}>
<div className={statusClasses}>
<Icon name={iconName || ICON_MAP_VARIANT[variant]} className="sui-m-call-out__status__icon" size="xl" />
</div>
<div className="sui-m-call-out__content">
{children}
</div>
</Tag>
);
});
CallOut.propTypes = propTypes;
CallOut.defaultProps = defaultProps;