import * as React from 'react'; import * as PropTypes from 'prop-types'; import { ReakitBoxProps } from '../types'; // @ts-ignore import _omit from 'lodash/omit'; import { Box, Flex } from '../primitives'; import styled, { css, space } from '../styled'; import { Omit } from '../types'; import { ButtonProps, buttonPropTypes } from '../Button/Button'; import Icon from '../Icon'; import Text from '../Text'; import _Alert from './styled'; import AlertClose, { AlertCloseProps } from './AlertClose'; import AlertTitle from './AlertTitle'; const ContentWrapper = styled(Box)<{ hasIcon?: boolean }>` padding: ${space(4)}rem; ${props => props.hasIcon && css` padding-left: 0; `}; `; const IconWrapper = styled(Flex)` padding: 0 ${space(4)}rem; `; export type LocalAlertProps = { className?: string; closeButtonProps?: Omit; children?: React.ReactNode; hasIcon?: boolean; hasTint?: boolean; onClickClose?: AlertCloseProps['onClickClose']; showCloseButton?: boolean; title?: string; type?: string; }; export type AlertProps = LocalAlertProps & ReakitBoxProps; export const Alert: React.FunctionComponent = ({ className, closeButtonProps, children, hasIcon, onClickClose, showCloseButton, title, type, ...props }) => ( <_Alert role="alert" className={className} type={type} {...props}> {hasIcon && type && ( )} {title && {title}} {typeof children === 'string' ? {children} : children} {showCloseButton && ( )} ); export const alertPropTypes = { className: PropTypes.string, closeButtonProps: PropTypes.shape(_omit(buttonPropTypes, 'children')), children: PropTypes.node, hasIcon: PropTypes.bool, hasTint: PropTypes.bool, onClickClose: PropTypes.func, showCloseButton: PropTypes.bool, title: PropTypes.string, type: PropTypes.string }; Alert.propTypes = alertPropTypes; export const alertDefaultProps: Partial = { className: undefined, closeButtonProps: {}, children: undefined, hasIcon: false, hasTint: false, onClickClose: undefined, showCloseButton: false, title: undefined, type: 'info' }; Alert.defaultProps = alertDefaultProps; const C: React.FunctionComponent = Alert; export default C;