/* eslint-disable no-nested-ternary */ import { BoolPropsFromArray, GeneratedPropTypes } from '../types'; import { Box } from './Box'; import { Icon } from './Icon'; import { StateTypes, applyAlertStateColor, stateTypes } from '../helpers/applyStateColor'; import { Text } from './Typography'; import { generateProps, variations } from 'styled-gen'; import React from 'react'; import styled from 'styled-components'; // #region ====== style === const alertColorVariations = stateTypes.reduce( (results, type) => ({ ...results, [type === 'info' ? 'default' : type]: applyAlertStateColor(type) }), {} ); const AlertWrapper = styled.div<{ state?: StateTypes } & GeneratedPropTypes>` border-radius: 8px; border-style: solid; border-width: 1px; box-sizing: border-box; padding: 1rem; position: relative; width: 100%; ${variations(alertColorVariations)}; ${generateProps}; `; const AlertCloseWrapper = styled.div` position: absolute; top: 1rem; right: 1rem; `; // #endregion === style === export type AlertProps = { button?: any; icon: string; title?: string | React.ReactNode; message?: string | React.ReactNode; handleClose?: any; } & BoolPropsFromArray & GeneratedPropTypes; export const Alert: React.FC = props => { const { button, icon, title, message, handleClose, ...forwardProps } = props; const hasButton = !!button; const hasClose = !hasButton && typeof handleClose === 'function'; return ( {title && ( {title} )} {message && {message}} {hasButton && ( {button} )} {hasClose && ( )} ); };