|
| 1 | +import { useClassName } from '@rocket.chat/fuselage-hooks'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import React from 'react'; |
| 4 | + |
| 5 | +import { useTheme } from '../../hooks/useTheme'; |
| 6 | +import { Icon } from '../Icon'; |
| 7 | +import { StyledCallout, Wrapper, Title } from './styles'; |
| 8 | + |
| 9 | +export const Callout = React.forwardRef(function Callout({ |
| 10 | + children, |
| 11 | + className, |
| 12 | + title, |
| 13 | + type = 'info', |
| 14 | + ...props |
| 15 | +}, ref) { |
| 16 | + const classNames = { |
| 17 | + container: useClassName('rcx-callout', { type }, className), |
| 18 | + wrapper: useClassName('rcx-callout__wrapper'), |
| 19 | + title: useClassName('rcx-callout__title'), |
| 20 | + description: useClassName('rcx-callout__description'), |
| 21 | + }; |
| 22 | + const theme = useTheme(); |
| 23 | + |
| 24 | + const iconName = (type === 'info' && 'info-circled') |
| 25 | + || (type === 'success' && 'checkmark-circled') |
| 26 | + || (type === 'warning' && 'warning') |
| 27 | + || (type === 'danger' && 'ban'); |
| 28 | + |
| 29 | + return <StyledCallout className={classNames.container} ref={ref} theme={theme} type={type} {...props}> |
| 30 | + <Icon name={iconName} /> |
| 31 | + <Wrapper theme={theme}> |
| 32 | + <Title hasChildren={!!children} theme={theme}>{title}</Title> |
| 33 | + {children} |
| 34 | + </Wrapper> |
| 35 | + </StyledCallout>; |
| 36 | +}); |
| 37 | + |
| 38 | +Callout.defaultProps = { |
| 39 | + type: 'info', |
| 40 | +}; |
| 41 | + |
| 42 | +Callout.displayName = 'Callout'; |
| 43 | + |
| 44 | +Callout.propTypes = { |
| 45 | + children: PropTypes.node, |
| 46 | + invisible: PropTypes.bool, |
| 47 | + title: PropTypes.string.isRequired, |
| 48 | + type: PropTypes.oneOf(['info', 'success', 'warning', 'danger']).isRequired, |
| 49 | +}; |
0 commit comments